Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
16 changes: 16 additions & 0 deletions .github/workflows/desktop-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,22 @@ jobs:
npm run electron:build
npx playwright test

- name: Run real CLI e2e test (Linux)
if: runner.os == 'Linux'
working-directory: desktop
env:
REAL_CLI_EVIDENCE: ${{ runner.temp }}/real-cli-evidence-${{ github.run_id }}-${{ github.run_attempt }}
run: bash e2e/run-real-cli-linux.sh

- name: Upload real CLI evidence (Linux)
if: always() && runner.os == 'Linux'
uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9
with:
name: desktop-real-cli-linux-${{ github.run_id }}-${{ github.run_attempt }}
path: ${{ runner.temp }}/real-cli-evidence-${{ github.run_id }}-${{ github.run_attempt }}
if-no-files-found: warn
retention-days: 7

- name: Package with electron-builder
working-directory: desktop
run: npx electron-builder ${{ matrix.builder-args }} --config electron-builder.yml
Expand Down
11 changes: 10 additions & 1 deletion .github/workflows/pr-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
with:
ref: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || '' }}
fetch-depth: ${{ github.event_name == 'pull_request' && '0' || '1' }}

- uses: ./.github/actions/relocate-tmp

Expand All @@ -186,11 +189,17 @@ jobs:
with:
go-version-file: go.mod

- name: Generate complete pull request lint patch
id: lint-patch
if: github.event_name == 'pull_request'
run: go run ./hack/ci lint-patch >> "$GITHUB_OUTPUT"

- name: golangci-lint
uses: golangci/golangci-lint-action@ba0d7d2ec06a0ea1cb5fa41b2e4a3ab91d21278a # v9
with:
version: v2.14.0
only-new-issues: true
only-new-issues: ${{ github.event_name != 'pull_request' }}
args: ${{ steps.lint-patch.outputs.args }}

# Native host tests: they execute the real `gh` CLI and, on macOS, the native
# keyring, so they run per host OS outside the unit tier's package list.
Expand Down
172 changes: 172 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ linters:
enable:
- cyclop
- decorder
- depguard
- dupl
- errcheck
- fatcontext
Expand All @@ -30,6 +31,7 @@ linters:
- modernize
- nestif
- revive
- sloglint
- staticcheck
- unparam
- unused
Expand All @@ -43,13 +45,183 @@ linters:
- gosec
text: "G101"
path: "pkg/telemetry/analytics/client.go"
- path: '^cmd/env_flags_test\.go$'
linters: [gosec]
text: '^G703: Path traversal via taint analysis$'
source: 'os\.WriteFile\(os\.Getenv\("DEVSY_INVALID_NO_STATUS_MARKER"\), \[\]byte\("ran"\), 0o600\)'
- path: '^cmd/env_flags_test\.go$'
linters: [gosec]
text: '^G204: Subprocess launched with a potential tainted input or cmd arguments$'
source: '^\s*child := exec\.Command\(os\.Args\[0\], noStatusSelector\)$'
- path: '^pkg/log/streamer_test\.go$'
linters: [gosec]
text: '^G204: Subprocess launched with a potential tainted input or cmd arguments$'
source: '^\s*cmd := exec\.CommandContext\(ctx, os\.Args\[0\], streamHelperSelector\)$'
- path: '^pkg/telemetry/export_test\.go$'
linters: [gosec]
text: '^G204: Subprocess launched with a potential tainted input or cmd arguments$'
source: 'exec\.Command\(os\.Args\[0\], "-test\.run=\^TestMetricsExportProcess\$"\)'
- path: '^pkg/gitcredentials/gitcredentials\.go$'
linters: [gosec]
text: '^G204: Subprocess launched with variable$'
source: 'exec\.CommandContext\(ctx, binaryPath, args\.\.\.\)'
- path: '^cmd/provider/init_environment_test\.go$'
linters: [gosec]
text: '^G101: Potential hardcoded credentials$'
source: 'const (optionSecret = "opaque-provider-secret-78153"|hostSecret = "host-provider-secret-78154")'
- path: '^cmd/workspace/exec_tty_unix_test\.go$'
linters: [gosec]
text: '^G101: Potential hardcoded credentials$'
source: 'const secret = "raw-exec-secret-92815"'
- path: '^cmd/workspace/exec_tty_unix_test\.go$'
linters: [gosec]
text: '^G306: Expect WriteFile permissions to be 0600 or less$'
source: 'os\.WriteFile\(wrapper, \[\]byte\(script\), 0o700\)'
- path: '^pkg/telemetry/export_darwin_test\.go$'
linters: [gosec]
text: '^G306: Expect WriteFile permissions to be 0600 or less$'
source: 'os\.WriteFile\(path, \[\]byte\("existing\\n"\), 0o644\)'
- path: '^pkg/telemetry/export_darwin_test\.go$'
linters: [gosec]
text: '^G302: Expect file permissions to be 0600 or less$'
source: 'os\.Chmod\(path, 0o644\)'
- path: '^pkg/envfile/envfile_test\.go$'
linters: [gosec]
text: '^G304: Potential file inclusion via variable$'
source: 'data, err := os\.ReadFile\(path\)'
- path: '^pkg/gitcredentials/credentials_server_test\.go$'
linters: [gosec]
text: '^G703: Path traversal via taint analysis$'
source: '^\s*if err := os\.WriteFile\(recordPath, record, 0o600\); err != nil \{$'
- path: '^pkg/gitcredentials/credentials_server_test\.go$'
linters: [gosec]
text: '^G304: Potential file inclusion via variable$'
source: 'data, err := os\.ReadFile\(recordPath\)'
- path: '^cmd/env_flags_test\.go$'
linters: [gosec]
text: '^G101: Potential hardcoded credentials$'
source: '^\s*const secret = "invalid-bool-secret-9471"$'
- path: '^cmd/env_flags_test\.go$'
linters: [gosec]
text: '^G204: Subprocess launched with a potential tainted input or cmd arguments$'
source: '^\s*child := exec\.Command\(os\.Args\[0\], loggingSelector\)$'
- path: '^pkg/ghcredentials/install_test\.go$'
linters: [gosec]
text: '^G304: Potential file inclusion via variable$'
source: '^\s*trace, openErr := os\.Open\(record \+ "\.trace"\)$'
- path: '^pkg/gitcredentials/gitcredentials\.go$'
linters: [gosec]
text: '^G702: Command injection via taint analysis$'
source: '^\s*cmd := exec\.CommandContext\(ctx, binaryPath, args\.\.\.\)$'
- path: '^pkg/log/streamer_test\.go$'
linters: [gosec]
text: '^G702: Command injection via taint analysis$'
source: '^\s*cmd := exec\.CommandContext\(ctx, os\.Args\[0\], streamHelperSelector\)$'
- path: '^pkg/log/writer_test\.go$'
linters: [gosec]
text: '^G101: Potential hardcoded credentials$'
source: '^const testLongSecret = "TOKEN=long-secret-value"$'
- path: '^pkg/telemetry/export_darwin_test\.go$'
linters: [gosec]
text: '^G304: Potential file inclusion via variable$'
source: '^\s*f, err := os\.OpenFile\(path, os\.O_WRONLY, 0\)$'
- path: '^pkg/telemetry/export_darwin_test\.go$'
linters: [gosec]
text: '^G304: Potential file inclusion via variable$'
source: '^\s*data, err := os\.ReadFile\(path\)$'
- path: '^pkg/telemetry/export_test\.go$'
linters: [gosec]
text: '^G702: Command injection via taint analysis$'
source: '^\s*cmd := exec\.Command\(os\.Args\[0\], "-test\.run=\^TestMetricsExportProcess\$"\)$'
- path: '^cmd/env_flags_test\.go$'
linters: [gosec]
text: '^G702: Command injection via taint analysis$'
source: '^\s*child := exec\.Command\(os\.Args\[0\], noStatusSelector\)$'
- path: '^cmd/env_flags_test\.go$'
linters: [gosec]
text: '^G702: Command injection via taint analysis$'
source: '^\s*child := exec\.Command\(os\.Args\[0\], loggingSelector\)$'
- path: '^pkg/driver/external/host_test\.go$'
linters: [gosec]
text: '^G304: Potential file inclusion via variable$'
source: '^\s*data, err := os\.ReadFile\(filepath\.Join\(directory, kind\+"-pids"\)\)$'
- path: '^pkg/telemetry/export_test\.go$'
linters: [gosec]
text: '^G304: Potential file inclusion via variable$'
source: '^\s*data, err := os\.ReadFile\(path\)$'
- path: '^pkg/telemetry/metrics_test\.go$'
linters: [gosec]
text: '^G304: Potential file inclusion via variable$'
source: '^\s*data, err := os\.ReadFile\(path\)$'
- path: '^pkg/tunnel/container_host_test\.go$'
linters: [gosec]
text: '^G304: Potential file inclusion via variable$'
source: '^\s*f, err := os\.Open\(path\)$'
- path: '^pkg/telemetry/export_linux_test\.go$'
linters: [gosec]
text: '^G306: Expect WriteFile permissions to be 0600 or less$'
source: '^\s*if err := os\.WriteFile\(path, \[\]byte\("existing\\n"\), 0o644\); err != nil \{$'
- path: '^pkg/telemetry/export_linux_test\.go$'
linters: [gosec]
text: '^G302: Expect file permissions to be 0600 or less$'
source: '^\s*if err := os\.Chmod\(path, 0o644\); err != nil \{$'
- path: '^pkg/telemetry/export_linux_test\.go$'
linters: [gosec]
text: '^G304: Potential file inclusion via variable$'
source: '^\s*f, err := os\.OpenFile\(path, os\.O_WRONLY, 0\)$'
- path: '^pkg/telemetry/export_linux_test\.go$'
linters: [gosec]
text: '^G304: Potential file inclusion via variable$'
source: '^\s*data, err := os\.ReadFile\(path\)$'
- path: '^pkg/telemetry/export_windows\.go$'
linters: [gosec]
text: '^G103: Use of unsafe calls should be audited$'
source: '^\s*descriptor := unsafe\.Slice\(\(\*byte\)\(unsafe\.Pointer\(security\)\), int\(security\.Length\(\)\)\)$'
- path: '^pkg/telemetry/export_windows\.go$'
linters: [gosec]
text: '^G103: Use of unsafe calls should be audited$'
source: '^\s*user := unsafe\.Slice\(\(\*byte\)\(unsafe\.Pointer\(sid\)\), sid\.Len\(\)\)$'
- path: "^pkg/log/(context|logger)\\.go$"
linters:
- sloglint
text: "message should be a string literal or a constant"
- path: "hack/"
linters:
- forbidigo
- gosec
settings:
cyclop:
max-complexity: 8
depguard:
rules:
logging:
files:
- $all
deny:
- pkg: go.uber.org/zap
desc: Use the standard structured logging API.
- pkg: github.com/go-logr/zapr
desc: Use the standard structured logging API.
sloglint:
attr-only: true
static-msg: true
key-naming-case: snake
custom-funcs:
- name: github.com/devsy-org/devsy/pkg/log.TraceContext
msg-pos: 1
args-pos: 2
- name: github.com/devsy-org/devsy/pkg/log.DebugContext
msg-pos: 1
args-pos: 2
- name: github.com/devsy-org/devsy/pkg/log.InfoContext
msg-pos: 1
args-pos: 2
- name: github.com/devsy-org/devsy/pkg/log.WarnContext
msg-pos: 1
args-pos: 2
- name: github.com/devsy-org/devsy/pkg/log.ErrorContext
msg-pos: 1
args-pos: 2
revive:
rules:
- name: argument-limit
Expand Down
2 changes: 2 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ Run the real VM specs on Linux with KVM before claiming parity.
- **Unit Testing**: Prefer using [testify suite](https://github.com/stretchr/testify#suite-package) (`testify/suite`) for writing unit tests.
- **Linter**: `golangci-lint` via `mise run cli:lint` (or `mise run cli:lint:fix`). Run `mise run cli:lint:ci` before pushing changes.

Use `log.*Context` with typed `slog.Attr` values for new structured diagnostics. Prefer the canonical attribute constructors, snake_case keys, and static messages. Keep secrets, environment values, command arguments, private paths, and raw backend errors out of diagnostics and telemetry. Existing `log.*f` and unstructured calls remain supported during migration. Do not add direct zap or zapr imports.

### TypeScript / Svelte Code Style

Biome formats and checks web frontend files.
Expand Down
30 changes: 18 additions & 12 deletions cmd/ci/ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
cliflags "github.com/devsy-org/devsy/pkg/flags"
"github.com/devsy-org/devsy/pkg/flags/names"
"github.com/devsy-org/devsy/pkg/log"
"github.com/devsy-org/devsy/pkg/output"
"github.com/devsy-org/devsy/pkg/provider"
"github.com/devsy-org/devsy/pkg/status"
workspace2 "github.com/devsy-org/devsy/pkg/workspace"
Expand Down Expand Up @@ -210,7 +211,11 @@ func (cmd *CICmd) execute(ctx context.Context, source string) (err error) {
// workspace.
ctx, cancel := up.WithSignals(ctx)
defer cancel()
reporter, err := newStatusReporter(os.Stderr, cmd.Verbosity > 0 || cmd.Debug, cmd.NoStatus)
mode, err := output.ResolveMode(cmd.ResultFormat)
if err != nil {
return err
}
reporter, err := newStatusReporter(mode, os.Stderr, log.InfoEnabled(), cmd.NoStatus)
if err != nil {
return err
}
Expand All @@ -226,7 +231,7 @@ func (cmd *CICmd) execute(ctx context.Context, source string) (err error) {
}
// release tears down the workspace; join error with the result.
defer func() {
err = errors.Join(err, resolved.release(reporter))
err = errors.Join(err, resolved.release(ctx, reporter))
}()
workspaceClient := resolved.client

Expand Down Expand Up @@ -256,18 +261,19 @@ func (cmd *CICmd) loadConfig() (*config.Config, error) {

type resolvedWorkspace struct {
client client.BaseWorkspaceClient
cleanup func() error
cleanup func(context.Context) error
teardown bool
}

func (r *resolvedWorkspace) release(reporter status.Reporter) error {
func (r *resolvedWorkspace) release(ctx context.Context, reporter status.Reporter) error {
ctx = context.WithoutCancel(ctx)
if !r.teardown {
return r.cleanup()
return r.cleanup(ctx)
}
return status.Run(context.Background(), reporter, status.Operation{
return status.Run(ctx, reporter, status.Operation{
Phase: status.PhaseDeletingWorkspace,
}, func(context.Context) error {
return r.cleanup()
}, func(ctx context.Context) error {
return r.cleanup(ctx)
})
}

Expand Down Expand Up @@ -310,10 +316,10 @@ func (cmd *CICmd) resolveWorkspace(
}

teardown := exists == "" && !cmd.Keep
cleanup := func() error {
cleanup := func(ctx context.Context) error {
defer cleanupSSH()
if teardown {
return cmd.teardown(workspaceClient)
return cmd.teardown(ctx, workspaceClient)
}
return nil
}
Expand All @@ -330,9 +336,9 @@ func (cmd *CICmd) runInContainer(ctx context.Context, c client.BaseWorkspaceClie
return execCmd.Run(ctx, cmd.RunCmd)
}

func (cmd *CICmd) teardown(c client.BaseWorkspaceClient) error {
func (cmd *CICmd) teardown(ctx context.Context, c client.BaseWorkspaceClient) error {
log.Debugf("tearing down workspace")
ctx, cancel := context.WithTimeout(context.Background(), teardownTimeout)
ctx, cancel := context.WithTimeout(ctx, teardownTimeout)
defer cancel()
if err := c.Delete(ctx, client.DeleteOptions{Force: true}); err != nil {
return fmt.Errorf("delete workspace: %w", err)
Expand Down
19 changes: 19 additions & 0 deletions cmd/ci/ci_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package ci

import (
"context"
"testing"

"github.com/devsy-org/devsy/cmd/flags"
Expand Down Expand Up @@ -110,3 +111,21 @@ func TestNewCICmd_Flags(t *testing.T) {
}
assert.Equal(t, "false", ciCmd.Flags().Lookup("keep").DefValue)
}

func TestReleasePreservesContextAfterCancellation(t *testing.T) {
type key struct{}
ctx, cancel := context.WithCancel(context.WithValue(context.Background(), key{}, "operation"))
cancel()
called := false
resolved := &resolvedWorkspace{
teardown: true,
cleanup: func(cleanupCtx context.Context) error {
called = true
assert.NoError(t, cleanupCtx.Err())
assert.Equal(t, "operation", cleanupCtx.Value(key{}))
return nil
},
}
require.NoError(t, resolved.release(ctx, nil))
assert.True(t, called)
}
Loading
Loading