diff --git a/.github/actions/check/action.yml b/.github/actions/check/action.yml index 22d4227ab..e1b96eb59 100644 --- a/.github/actions/check/action.yml +++ b/.github/actions/check/action.yml @@ -26,9 +26,8 @@ runs: # which need the pinned Node but no workspace packages. # Each Go check keeps its own build and module cache, so one job's save # never replaces another's. Pull requests and merge-queue builds restore - # main's latest entry; only pushes to main save. Go trims build cache - # entries unused for five days, so the restored cache does not grow - # without bound. + # main's latest entry; only pushes to main save, and a successful push + # keeps only the build cache entries its own run used. - id: plan shell: bash env: @@ -68,6 +67,16 @@ runs: restore-keys: | ${{ steps.plan.outputs.prefix }} ${{ steps.plan.outputs.app_prefix }} + # Go refreshes an entry's mtime on use only when it is over an hour old, so + # backdating everything makes the entries this run uses the only recent + # ones. The cache is content-addressed: pruning can only cause misses, + # never wrong results. + - if: github.event_name == 'push' && steps.plan.outputs.is_go == 'true' + shell: bash + run: | + if [ -d ~/.cache/go-build ]; then + find ~/.cache/go-build -type f -exec touch -m -d '2 hours ago' {} + + fi # Pinned golangci-lint and sqlc binaries; building them takes about 60 s # each. Their file names carry the tool and Go versions, and the key # hashes the files that pin both, so a version bump misses and rebuilds. @@ -90,6 +99,13 @@ runs: env: APP: ${{ inputs.app }} run: make "check-$APP" BASE="$BASE" + # A failed run saves unpruned; the next successful push prunes. + - if: success() && github.event_name == 'push' && steps.plan.outputs.is_go == 'true' + shell: bash + run: | + if [ -d ~/.cache/go-build ]; then + find ~/.cache/go-build -type f -mmin +60 -delete + fi - uses: actions/cache/save@v4 if: always() && github.event_name == 'push' && inputs.app == 'teamhub' with: diff --git a/.github/actions/setup/action.yml b/.github/actions/setup/action.yml index d854f423e..2568d6a86 100644 --- a/.github/actions/setup/action.yml +++ b/.github/actions/setup/action.yml @@ -11,6 +11,9 @@ inputs: go: description: Set up Go. Checks that build or run no Go pass false. default: "true" + save-node-modules: + description: Save the installed node_modules when no entry matched. Only one job passes true, so the other jobs never upload the same tree. + default: "false" runs: using: composite @@ -18,9 +21,14 @@ runs: # A push's `before` shares no history with HEAD after a branch's first push # (all zeros) or a force push that replaced the history. The checks then # compare HEAD with itself: the changed-file checks have nothing to check and - # every whole-tree check still runs. + # every whole-tree check still runs. Shallow checkouts belong to jobs that do + # not use BASE, so anything there that starts using it fails loudly on the + # unknown ref instead of silently comparing HEAD with itself. - shell: bash run: | + if [ "$(git rev-parse --is-shallow-repository)" = true ]; then + exit 0 + fi if ! git merge-base "$BASE" HEAD >/dev/null 2>&1; then echo "::notice::BASE $BASE shares no history with HEAD; the changed-file checks compare HEAD with itself." echo "BASE=$(git rev-parse HEAD)" >>"$GITHUB_ENV" @@ -47,6 +55,21 @@ runs: with: path: ${{ runner.tool_cache }}/go/${{ steps.versions.outputs.go }} key: toolcache-go-${{ runner.os }}-${{ runner.arch }}-${{ steps.versions.outputs.go }} + # The installed tree, keyed on everything that decides its contents. Only an + # exact match is restored: a partial tree would make the install below + # fetch without the pnpm store. The paths match pnpm-workspace.yaml's + # `packages` globs and must stay identical in the save step below, since + # the cache version hashes them. + - id: node-modules + uses: actions/cache/restore@v4 + if: inputs.install == 'true' + with: + path: | + node_modules + apps/*/node_modules + packages/*/node_modules + contracts/generated/typescript/node_modules + key: node-modules-${{ runner.os }}-${{ runner.arch }}-${{ steps.versions.outputs.node }}-${{ hashFiles('pnpm-lock.yaml', 'pnpm-workspace.yaml', '.npmrc', 'patches/**', 'package.json', 'apps/*/package.json', 'packages/*/package.json', 'contracts/generated/typescript/package.json') }} # Reads the version from packageManager in package.json. - uses: pnpm/action-setup@v4 if: inputs.install == 'true' @@ -54,7 +77,8 @@ runs: if: inputs.node == 'true' with: node-version-file: .node-version - cache: ${{ inputs.install == 'true' && 'pnpm' || '' }} + # The pnpm store is needed only when the node_modules entry missed. + cache: ${{ inputs.install == 'true' && steps.node-modules.outputs.cache-hit != 'true' && 'pnpm' || '' }} # The caller caches Go per job: setup-go's one shared entry is saved by # whichever job finishes first, often one that compiled no Go, and its key # never changes while go.sum stays the same. @@ -64,6 +88,18 @@ runs: go-version-file: apps/teamhub/go.mod cache: false # No install scripts: none of the checks that run here loads a native addon. + # On a restored tree this only verifies it against the lockfile. - shell: bash if: inputs.install == 'true' run: pnpm install --frozen-lockfile --ignore-scripts + # Saved before any check runs, so tool caches such as node_modules/.vite + # never enter the entry. + - uses: actions/cache/save@v4 + if: inputs.install == 'true' && inputs.save-node-modules == 'true' && steps.node-modules.outputs.cache-hit != 'true' + with: + path: | + node_modules + apps/*/node_modules + packages/*/node_modules + contracts/generated/typescript/node_modules + key: ${{ steps.node-modules.outputs.cache-primary-key }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6c2df6fdc..9bb913be6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,13 +2,13 @@ name: CI # The repository gate runs on every pull request and merge-queue build; each # app's fast check runs only when its paths change; the web check is split -# into a static job and sharded test jobs. An unchanged app's job is skipped, +# into a static job and two test shards. An unchanged app's job is skipped, # which GitHub reports as success for its required check; a failed path # filter makes every app check fail instead of skipping. A merge-queue build # checks the paths its whole group changes, on top of the latest main. Pushes # to main run every check. scripts/check-plan.mjs maps paths to checks, here -# and in `make check`. CI runs the -# computer daemon's Go unit tests; the rest of check-computer (TS and process +# and in `make check`. Only jobs that use BASE check out full history. CI runs +# the computer daemon's Go unit tests; the rest of check-computer (TS and process # tests) and the heavier suites (node-services, voice-runtime, integration, # containers and E2E) stay local: run `make check BASE=` and the # targets in the Makefile before you open a pull request. @@ -72,6 +72,9 @@ jobs: - uses: ./.github/actions/setup with: go: false + # Runs on every push to main, so it alone saves the node_modules + # entry the other jobs restore. + save-node-modules: ${{ github.event_name == 'push' }} - run: make check-repository-gate BASE="$BASE" web-static: @@ -88,22 +91,20 @@ jobs: - run: make check-web-static BASE="$BASE" web-tests: - name: web tests (${{ matrix.shard }}/3) + name: web tests (${{ matrix.shard }}/2) needs: changes if: needs.changes.outputs.web == 'true' runs-on: ubuntu-latest strategy: fail-fast: false matrix: - shard: [1, 2, 3] + shard: [1, 2] steps: - uses: actions/checkout@v4 - with: - fetch-depth: 0 - uses: ./.github/actions/setup with: go: false - - run: make check-web-tests SHARD=${{ matrix.shard }}/3 + - run: make check-web-tests SHARD=${{ matrix.shard }}/2 # Reports the required `check (web)` context from the split web jobs. When # web paths changed, every web job must succeed (an unexpected skip fails); @@ -147,8 +148,6 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - with: - fetch-depth: 0 - uses: ./.github/actions/check with: app: packages @@ -161,8 +160,6 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - with: - fetch-depth: 0 - uses: ./.github/actions/check with: app: teamhub-cli @@ -175,8 +172,6 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - with: - fetch-depth: 0 - uses: ./.github/actions/check with: app: installer @@ -189,8 +184,6 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - with: - fetch-depth: 0 - uses: ./.github/actions/check with: app: desktop @@ -203,8 +196,6 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - with: - fetch-depth: 0 - uses: ./.github/actions/check with: app: contracts @@ -231,8 +222,6 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - with: - fetch-depth: 0 - uses: ./.github/actions/check with: app: computer-go diff --git a/Makefile b/Makefile index 7511614a1..d490636c9 100644 --- a/Makefile +++ b/Makefile @@ -98,7 +98,7 @@ check-web: "$(WEB_TESTS)" \ "$(WEB_DOCTOR)" -# CI runs these as separate jobs (tests in shards, e.g. SHARD=2/3); +# CI runs these as separate jobs (tests in shards, e.g. SHARD=2/2); # check-web stays the local entry point. check-web-static: pnpm exec concurrently --success all --names types,lint,doctor \ diff --git a/apps/computer/local-daemon/internal/provider/codex_auth_probe_test.go b/apps/computer/local-daemon/internal/provider/codex_auth_probe_test.go index 60134dc1a..0c6086e27 100644 --- a/apps/computer/local-daemon/internal/provider/codex_auth_probe_test.go +++ b/apps/computer/local-daemon/internal/provider/codex_auth_probe_test.go @@ -15,11 +15,55 @@ import ( "github.com/simplexai-labs/linger/apps/computer/local-daemon/internal/provider/native" ) +// Scaled probe budgets keep the Linux budget regressions fast: a cold start +// takes coldStart, more than a third of the scaled cap, and still finishes +// about twice under it; three sequential cold starts exceed one stage budget. +const ( + scaledAuthProbeCap = 1500 * time.Millisecond + scaledDiscoveryStageBudget = 2 * time.Second + scaledColdStart = 800 * time.Millisecond +) + +// scaleProbeBudgets lowers the package-level probe budgets for one test. Its +// callers must not run in parallel with any test that probes a Runtime. +func scaleProbeBudgets(t *testing.T) { + t.Helper() + previousCap, previousBudget := authProbeCap, discoveryStageBudget + authProbeCap, discoveryStageBudget = scaledAuthProbeCap, scaledDiscoveryStageBudget + t.Cleanup(func() { authProbeCap, discoveryStageBudget = previousCap, previousBudget }) +} + +func TestProbeBudgetDefaults(t *testing.T) { + if got := authProbeCap; got != 15*time.Second { + t.Fatalf("authentication probe cap = %v, want 15s", got) + } + for _, scenario := range []struct { + goos string + want time.Duration + }{{"linux", 30 * time.Second}, {"windows", 30 * time.Second}, {"darwin", 15 * time.Second}} { + if got := defaultDiscoveryStageBudget(scenario.goos); got != scenario.want { + t.Fatalf("%s discovery stage budget = %v, want %v", scenario.goos, got, scenario.want) + } + } + if got := discoveryStageBudget; got != defaultDiscoveryStageBudget(runtime.GOOS) { + t.Fatalf("discovery stage budget = %v, want the %s default", got, runtime.GOOS) + } + for _, scenario := range []struct{ timeout, want time.Duration }{ + {0, 15 * time.Second}, {-time.Second, 15 * time.Second}, {30 * time.Second, 15 * time.Second}, + {15 * time.Second, 15 * time.Second}, {200 * time.Millisecond, 200 * time.Millisecond}, + } { + if got := boundedAuthTimeout(scenario.timeout); got != scenario.want { + t.Fatalf("boundedAuthTimeout(%v) = %v, want %v", scenario.timeout, got, scenario.want) + } + } +} + func TestCodexAuthenticationColdStartWithinLinuxBudget(t *testing.T) { if runtime.GOOS != "linux" { t.Skip("Linux authentication budget regression") } - executable, environment := codexAuthProbeFixture(t, `/bin/sleep 6 + scaleProbeBudgets(t) + executable, environment := codexAuthProbeFixture(t, `/bin/sleep 0.8 echo '{"id":2,"result":{"account":null,"requiresOpenaiAuth":false}}'`) current := DiscoveryResult{Diagnostics: []RuntimeDiagnostic{{Type: "codex", Status: "ready", ExecutablePath: executable}}} started := time.Now() @@ -28,8 +72,8 @@ echo '{"id":2,"result":{"account":null,"requiresOpenaiAuth":false}}'`) if err != nil { t.Fatal(err) } - if elapsed <= 5*time.Second || elapsed >= 15*time.Second { - t.Fatalf("probe duration = %v, want between 5s and 15s", elapsed) + if elapsed < scaledColdStart || elapsed >= scaledAuthProbeCap { + t.Fatalf("probe duration = %v, want between %v and %v", elapsed, scaledColdStart, scaledAuthProbeCap) } if diagnostic := result.Diagnostics[0]; diagnostic.Status != "ready" || diagnostic.Error != nil { t.Fatalf("delayed authentication = %+v", diagnostic) @@ -43,6 +87,7 @@ func TestDiscoverCodexColdInitializeWithinLinuxBudget(t *testing.T) { if runtime.GOOS != "linux" { t.Skip("Linux discovery budget regression with POSIX fixtures") } + scaleProbeBudgets(t) for _, scenario := range []struct { name string timeout, deadline time.Duration @@ -61,7 +106,7 @@ func TestDiscoverCodexColdInitializeWithinLinuxBudget(t *testing.T) { if [ "$1" = "--version" ]; then echo 'codex-cli 0.144.1'; exit 0; fi read initialize echo initialize >> "$LAUNCH_TRACE" -/bin/sleep 8 +/bin/sleep 0.8 echo '{"id":1,"result":{"userAgent":"test"}}' if read initialized && read account; then case "$account" in @@ -92,6 +137,9 @@ fi if diagnostic.Error != nil || result.Installations["codex"].Status != "ready" { t.Fatalf("slow initialize did not produce a ready installation: %+v", result) } + if elapsed := time.Since(started); elapsed <= scaledDiscoveryStageBudget { + t.Fatalf("discovery took %v, want three cold starts to exceed one stage budget %v", elapsed, scaledDiscoveryStageBudget) + } } else if diagnostic.Error == nil || diagnostic.Error.Code != "RUNTIME_DIAGNOSTIC_FAILED" || !strings.Contains(diagnostic.Error.Message, "deadline") || time.Since(started) > 5*time.Second { t.Fatalf("short discovery deadline not preserved: %+v, elapsed = %v", diagnostic, time.Since(started)) } @@ -107,6 +155,7 @@ func TestCodexAuthenticationFailureDiagnostics(t *testing.T) { if runtime.GOOS != "linux" { t.Skip("Linux authentication budget regression with POSIX fixtures") } + scaleProbeBudgets(t) const ( timeoutMessage = "Codex authentication probe timed out or was canceled" processMessage = "Codex authentication probe process or RPC failed" @@ -117,7 +166,7 @@ func TestCodexAuthenticationFailureDiagnostics(t *testing.T) { timeout, deadline time.Duration minimum time.Duration }{ - {"timeout at Linux cap", `/bin/sleep 30`, timeoutMessage, 30 * time.Second, 0, 15 * time.Second}, + {"timeout at Linux cap", `/bin/sleep 30`, timeoutMessage, 30 * time.Second, 0, scaledAuthProbeCap}, {"short caller timeout", `/bin/sleep 30`, timeoutMessage, 200 * time.Millisecond, 0, 200 * time.Millisecond}, {"short parent deadline", `/bin/sleep 30`, timeoutMessage, 15 * time.Second, 200 * time.Millisecond, 200 * time.Millisecond}, {"process exit", `exit 7`, processMessage, time.Second, 0, 0}, diff --git a/apps/computer/local-daemon/internal/provider/discovery.go b/apps/computer/local-daemon/internal/provider/discovery.go index 9e600ccc6..0e1053f53 100644 --- a/apps/computer/local-daemon/internal/provider/discovery.go +++ b/apps/computer/local-daemon/internal/provider/discovery.go @@ -105,6 +105,17 @@ func ValidateRuntimeSelection(types []string) error { return nil } +// discoveryStageBudget is each discovery stage's default budget; tests lower it +// while no discovery runs. +var discoveryStageBudget = defaultDiscoveryStageBudget(runtime.GOOS) + +func defaultDiscoveryStageBudget(goos string) time.Duration { + if goos == "windows" || goos == "linux" { + return 30 * time.Second + } + return 15 * time.Second +} + func Discover(ctx context.Context, options DiscoveryOptions) (DiscoveryResult, error) { options.Environment = terminalEnvironment(ctx, platformEnvironment(options.Environment)) return discoverResolved(ctx, options), nil @@ -113,10 +124,7 @@ func Discover(ctx context.Context, options DiscoveryOptions) (DiscoveryResult, e func discoverResolved(ctx context.Context, options DiscoveryOptions) DiscoveryResult { budget := options.Timeout if budget <= 0 { - budget = 15 * time.Second - if runtime.GOOS == "windows" || runtime.GOOS == "linux" { - budget = 30 * time.Second - } + budget = discoveryStageBudget } definitions := runtimeDefinitions if len(options.Runtimes) > 0 { diff --git a/apps/computer/local-daemon/internal/provider/native/claude_cleanup_unix_test.go b/apps/computer/local-daemon/internal/provider/native/claude_cleanup_unix_test.go index a91b873df..72a522181 100644 --- a/apps/computer/local-daemon/internal/provider/native/claude_cleanup_unix_test.go +++ b/apps/computer/local-daemon/internal/provider/native/claude_cleanup_unix_test.go @@ -48,7 +48,7 @@ func claudeWaitFile(t *testing.T, path string) { } func TestClaudeInitRejectionCleansUpTermIgnoringTree(t *testing.T) { - claudeLowerGrace(t, 300*time.Millisecond) + claudeLowerGrace(t, 150*time.Millisecond) dir := t.TempDir() profile := claudeFakeProfile(t, "signal", map[string]string{"CLAUDE_FAKE_DIR": dir, "CLAUDE_FAKE_POLICY": "ignore", "CLAUDE_FAKE_INIT": "error"}) started := time.Now() @@ -60,7 +60,7 @@ func TestClaudeInitRejectionCleansUpTermIgnoringTree(t *testing.T) { } func TestClaudeCallerCancelDuringTurn(t *testing.T) { - claudeLowerGrace(t, 300*time.Millisecond) + claudeLowerGrace(t, 150*time.Millisecond) for _, policy := range []string{"report", "normal", "ignore", "child", "completed"} { t.Run(policy, func(t *testing.T) { dir := t.TempDir() @@ -116,7 +116,7 @@ func TestClaudeFailureDiagnostics(t *testing.T) { {"success with status", []string{frame, okResult}, nil, 0, statusCompleted, func(d RuntimeFailureDiagnostics) bool { return d.empty() }}, } { t.Run(test.name, func(t *testing.T) { - claudeLowerGrace(t, 300*time.Millisecond) + claudeLowerGrace(t, 150*time.Millisecond) run := claudeStart(t, claudeFramesProfile(t, "frames", test.frames, test.env), "hello", RunSpec{Budget: test.budget}) _, outcome := claudeFinish(t, run, 10*time.Second) if outcome.Status != test.status || !test.check(outcome.Diagnostics) { diff --git a/apps/computer/local-daemon/internal/provider/native/claude_fake_test.go b/apps/computer/local-daemon/internal/provider/native/claude_fake_test.go index 2b216a58e..40c0696ac 100644 --- a/apps/computer/local-daemon/internal/provider/native/claude_fake_test.go +++ b/apps/computer/local-daemon/internal/provider/native/claude_fake_test.go @@ -20,7 +20,7 @@ const claudeFakeKey = "CLAUDE_FAKE_MODE" // claudeFakeSlowOutput is how long a resident "slow" or "late" turn holds its // output; timing assertions compare against it rather than a wall-clock guess. -const claudeFakeSlowOutput = 500 * time.Millisecond +const claudeFakeSlowOutput = 300 * time.Millisecond func init() { if mode := os.Getenv(claudeFakeKey); mode != "" { @@ -251,7 +251,7 @@ func (f *claudeFake) resident() int { signal.Notify(terms, syscall.SIGTERM) go func() { <-terms - time.Sleep(500 * time.Millisecond) + time.Sleep(200 * time.Millisecond) f.record("exits", fmt.Sprintf("%d %d", os.Getpid(), time.Now().UnixNano())) os.Exit(0) }() @@ -384,7 +384,8 @@ func (f *claudeFake) resident() int { }}}) } if strings.Contains(prompt, "pause") { - time.Sleep(time.Second) + // Long enough for a test to act 300ms into the turn. + time.Sleep(600 * time.Millisecond) } reason := "completed" if strings.Contains(prompt, "reason") { diff --git a/apps/computer/local-daemon/internal/provider/native/claude_init_unix_test.go b/apps/computer/local-daemon/internal/provider/native/claude_init_unix_test.go index d923a4357..3dc979b8b 100644 --- a/apps/computer/local-daemon/internal/provider/native/claude_init_unix_test.go +++ b/apps/computer/local-daemon/internal/provider/native/claude_init_unix_test.go @@ -188,7 +188,8 @@ func TestClaudeSteerCancelledWhileWaiting(t *testing.T) { results := make(chan result, 1) run := claudeStart(t, home.profile, "slow", RunSpec{ExposeTurnStarted: true}) _, outcome, _ := claudeTimed(t, run, func(started Event) { - ctx, cancel := context.WithTimeout(t.Context(), 200*time.Millisecond) + // Expires well inside claudeFakeSlowOutput, so the turn is still waiting. + ctx, cancel := context.WithTimeout(t.Context(), 100*time.Millisecond) defer cancel() begin := time.Now() _, err := run.Steer(ctx, SteerRequest{ExpectedTurnID: started.TurnID, Input: "go"}) diff --git a/apps/computer/local-daemon/internal/provider/native/claude_resident_unix_test.go b/apps/computer/local-daemon/internal/provider/native/claude_resident_unix_test.go index a8138e713..d125fd244 100644 --- a/apps/computer/local-daemon/internal/provider/native/claude_resident_unix_test.go +++ b/apps/computer/local-daemon/internal/provider/native/claude_resident_unix_test.go @@ -74,7 +74,8 @@ func (c *claudeLogCapture) await(t *testing.T, prefix string, n int) []claudeLog func claudeEnableResidency(t *testing.T, cap int) { t.Helper() previousGrace := claudeTerminationGrace - claudeTerminationGrace = time.Second + // Three times the slow-term fake's exit delay, so it still exits by itself. + claudeTerminationGrace = 600 * time.Millisecond withResidentCap(t, claudeResidents, cap) t.Cleanup(func() { _, _ = StopAllParkedResidents() diff --git a/apps/computer/local-daemon/internal/provider/native/codex_exit_unix_test.go b/apps/computer/local-daemon/internal/provider/native/codex_exit_unix_test.go index 68bec13d5..d06cd30f1 100644 --- a/apps/computer/local-daemon/internal/provider/native/codex_exit_unix_test.go +++ b/apps/computer/local-daemon/internal/provider/native/codex_exit_unix_test.go @@ -23,7 +23,7 @@ func TestCodexExternalLeaderExit(t *testing.T) { // The sleeper grandchild outlives the leader, and in one case holds // stdout, so a stop grace expires; newCodexFake's cleanup restores // the grace. - codexStopGrace.set(300 * time.Millisecond) + codexStopGrace.set(150 * time.Millisecond) receipt := filepath.Join(fake.root, "pids") fake.env["FAKE_GRANDCHILD"] = receipt if tc.holdStdout { diff --git a/apps/computer/local-daemon/internal/provider/native/codex_naming_test.go b/apps/computer/local-daemon/internal/provider/native/codex_naming_test.go index 0b673e278..7faa3df6e 100644 --- a/apps/computer/local-daemon/internal/provider/native/codex_naming_test.go +++ b/apps/computer/local-daemon/internal/provider/native/codex_naming_test.go @@ -27,7 +27,7 @@ func codexSetupOrder(fake *codexFake) []string { func TestCodexNamesNewThreadAfterTurnStart(t *testing.T) { // The fake holds turn/completed briefly so the deferred name request is // on the wire before the Operation ends. - turn := []codexFakeTurn{{Status: "completed", DelayMs: 200}} + turn := []codexFakeTurn{{Status: "completed", DelayMs: 100}} t.Run("slow name answer", func(t *testing.T) { fake := newCodexFake(t, turn, map[string]string{"FAKE_MODES": "name_slow"}) spec := fake.spec() @@ -80,7 +80,7 @@ func TestCodexNamesNewThreadAfterTurnStart(t *testing.T) { } func TestCodexResumeKeepsName(t *testing.T) { - fake := newCodexFake(t, []codexFakeTurn{{Status: "completed", DelayMs: 200}}, nil) + fake := newCodexFake(t, []codexFakeTurn{{Status: "completed", DelayMs: 100}}, nil) rt := fake.runtime(nil) spec := fake.spec() spec.Title = "Trip plan" diff --git a/apps/computer/local-daemon/internal/provider/native/codex_runtime_test.go b/apps/computer/local-daemon/internal/provider/native/codex_runtime_test.go index a5b666676..fba87a3a0 100644 --- a/apps/computer/local-daemon/internal/provider/native/codex_runtime_test.go +++ b/apps/computer/local-daemon/internal/provider/native/codex_runtime_test.go @@ -185,7 +185,7 @@ func TestCodexStartupStallKillsTree(t *testing.T) { fake := newCodexFake(t, nil, nil) // The fake never answers the stall, so each stop step waits out its // grace; newCodexFake's cleanup restores the grace. - codexStopGrace.set(300 * time.Millisecond) + codexStopGrace.set(150 * time.Millisecond) receipt := filepath.Join(fake.root, "pids") fake.env["FAKE_STALL"], fake.env["FAKE_GRANDCHILD"] = method, receipt spec := fake.spec() @@ -206,7 +206,7 @@ func TestCodexStartupFailureKeepsSecretsOut(t *testing.T) { fake := newCodexFake(t, nil, map[string]string{"FAKE_STDERR": "env " + secret, "FAKE_STALL": "initialize"}) // The fake never answers the stall, so each stop step waits out its // grace; newCodexFake's cleanup restores the grace. - codexStopGrace.set(300 * time.Millisecond) + codexStopGrace.set(150 * time.Millisecond) var log codexTestLog spec := fake.spec() if variant == "startup" { @@ -241,6 +241,9 @@ func TestCodexInitializeCancelUnconfirmed(t *testing.T) { var force atomic.Bool force.Store(true) codexForceUnconfirmed(&force) + // The stall makes each stop step wait out its grace; newCodexFake's + // cleanup restores the grace. + codexStopGrace.set(150 * time.Millisecond) ctx, cancel := context.WithCancel(context.Background()) run, err := fake.runtime(nil).Start(ctx, "go", fake.spec()) if err != nil { @@ -267,7 +270,7 @@ func TestCodexInitializeTimeoutRetriesOnce(t *testing.T) { fake := newCodexFake(t, nil, map[string]string{"FAKE_STALL": "initialize"}) // The fake never answers the stall, so each stop step waits out its // grace; newCodexFake's cleanup restores the grace. - codexStopGrace.set(300 * time.Millisecond) + codexStopGrace.set(150 * time.Millisecond) var log codexTestLog spec := fake.spec() spec.StartupBudget = 100 * time.Millisecond @@ -626,8 +629,8 @@ func TestCodexUsagePerTurnOnReusedProcess(t *testing.T) { func TestCodexSteering(t *testing.T) { fake := newCodexFake(t, []codexFakeTurn{{Stall: true}}, nil) spec := fake.spec() - spec.SilenceBudget = time.Second - spec.FirstProgressBudget = time.Second + spec.SilenceBudget = 400 * time.Millisecond + spec.FirstProgressBudget = 400 * time.Millisecond run, err := fake.runtime(nil).Start(context.Background(), "go", spec) if err != nil { t.Fatal(err) @@ -951,7 +954,7 @@ func TestCodexSteerNeedsConsumptionEvidence(t *testing.T) { fake := newCodexFake(t, []codexFakeTurn{{Stall: true}}, map[string]string{"FAKE_MODES": tc.mode}) fake.version = "0.166.0" spec := fake.spec() - spec.SilenceBudget = time.Second + spec.SilenceBudget = 400 * time.Millisecond spec.ExposeTurnStarted = true run, err := fake.runtime(nil).Start(context.Background(), "go", spec) if err != nil { diff --git a/apps/computer/local-daemon/internal/provider/native/pi_catalog_context_test.go b/apps/computer/local-daemon/internal/provider/native/pi_catalog_context_test.go index a0d472d16..074c44272 100644 --- a/apps/computer/local-daemon/internal/provider/native/pi_catalog_context_test.go +++ b/apps/computer/local-daemon/internal/provider/native/pi_catalog_context_test.go @@ -27,7 +27,7 @@ func TestPiCatalogPreservesContextCauseAfterChildCleanup(t *testing.T) { } ctx, cancel := context.WithCancelCause(t.Context()) defer cancel(nil) - bounded, stop := context.WithTimeout(ctx, time.Second) + bounded, stop := context.WithTimeout(ctx, 400*time.Millisecond) defer stop() done := make(chan error, 1) go func() { diff --git a/apps/computer/local-daemon/internal/provider/protocol_probe.go b/apps/computer/local-daemon/internal/provider/protocol_probe.go index 4f8f44e30..8b86e5d22 100644 --- a/apps/computer/local-daemon/internal/provider/protocol_probe.go +++ b/apps/computer/local-daemon/internal/provider/protocol_probe.go @@ -21,6 +21,10 @@ const maxProbeOutputBytes = 1024 * 1024 var errProbeOutputLimit = errors.New("Runtime probe output exceeded one MiB") +// authProbeCap bounds every authentication probe; tests lower it while no +// probe runs. +var authProbeCap = 15 * time.Second + type runtimeProbeOutcome struct { Status string Code string @@ -224,7 +228,7 @@ func boundedAuthTimeout(timeout time.Duration) time.Duration { // is busy, macOS included: a busy MacBook let `claude auth status` miss a // five second budget and flipped a working Agent to unavailable. Preserve // shorter caller budgets and the enclosing discovery context. - maximum := 15 * time.Second + maximum := authProbeCap if timeout <= 0 || timeout > maximum { return maximum } diff --git a/apps/web/AGENTS.md b/apps/web/AGENTS.md index 2a43eafc3..19f5c3eba 100644 --- a/apps/web/AGENTS.md +++ b/apps/web/AGENTS.md @@ -11,8 +11,8 @@ React Router Data Mode and TanStack Query power the active Room-first UI. before opening a pull request. If the change adds a static import on the Room or app initial graph, also run `pnpm --filter @linger/web run build:assets` to check the initial JS budget. - CI runs it as `make check-web-static` plus `make check-web-tests` in three - shards (`SHARD=1/3` and so on). + CI runs it as `make check-web-static` plus `make check-web-tests` in two + shards (`SHARD=1/2` and `SHARD=2/2`). ## Structure diff --git a/scripts/ci/app-linted-paths.txt b/scripts/ci/app-linted-paths.txt new file mode 100644 index 000000000..e2d892022 --- /dev/null +++ b/scripts/ci/app-linted-paths.txt @@ -0,0 +1,11 @@ +apps/web/src/ +apps/web/e2e/ +apps/desktop/src/ +apps/desktop/scripts/ +apps/teamhub-cli/ +apps/linger-installer/src/ +packages/document-files/ +packages/document-model/ +packages/knowledge-format/ +packages/service-kit/ +packages/local-installation/src/ diff --git a/scripts/ci/check-changed-files.sh b/scripts/ci/check-changed-files.sh index 509385bbb..0b8f89c42 100755 --- a/scripts/ci/check-changed-files.sh +++ b/scripts/ci/check-changed-files.sh @@ -8,12 +8,25 @@ set -euo pipefail # Usage: check-changed-files.sh diff two commits (the gate) # check-changed-files.sh --worktree # diff the working tree, plus untracked files (local make check) +# check-changed-files.sh +# also skip ESLint under the prefixes listed one per line in the +# file; prettier and the English-only check still cover them -if (($# != 2)); then - echo "Usage: $0 ( | --worktree)" >&2 +if (($# != 2 && $# != 3)); then + echo "Usage: $0 ( [] | --worktree)" >&2 exit 2 fi base=$1 +app_linted=() +if (($# == 3)); then + [[ "$2" != --worktree ]] || { + echo "Usage: $0 ( [] | --worktree)" >&2 + exit 2 + } + while IFS= read -r prefix; do + if [[ -n "$prefix" ]]; then app_linted+=("$prefix"); fi + done <"$3" +fi if [[ "$2" == --worktree ]]; then list_changed() { git -c core.quotePath=false diff -z --name-only --no-renames --diff-filter=ACMRT "$base" @@ -38,7 +51,16 @@ while IFS= read -r -d '' file; do ;; esac case "$file" in - *.cjs | *.cts | *.js | *.jsx | *.mjs | *.mts | *.ts | *.tsx) eslint_files+=("$file") ;; + *.cjs | *.cts | *.js | *.jsx | *.mjs | *.mts | *.ts | *.tsx) + app_lints=false + for prefix in ${app_linted[@]+"${app_linted[@]}"}; do + if [[ "$file" == "$prefix"* ]]; then + app_lints=true + break + fi + done + if [[ "$app_lints" == false ]]; then eslint_files+=("$file"); fi + ;; esac changed_files+=("$file") done < <(list_changed) diff --git a/scripts/ci/check-repository-gate.sh b/scripts/ci/check-repository-gate.sh index 29b7e697e..2691fe055 100755 --- a/scripts/ci/check-repository-gate.sh +++ b/scripts/ci/check-repository-gate.sh @@ -37,7 +37,10 @@ fi pnpm env:inventory:check # Format, lint and check the English-only rule on the files this branch adds -# or changes. -bash "$script_root/check-changed-files.sh" "$base" "$head_sha" +# or changes. ESLint skips the prefixes in app-linted-paths.txt: CI selects +# the owning app's check whenever a path under a prefix changes, and that +# check lints the whole prefix with --max-warnings=0. +bash "$script_root/check-changed-files.sh" "$base" "$head_sha" \ + "$script_root/app-linted-paths.txt" make check-scripts-fast check-docs diff --git a/scripts/ci/check-repository-gate.test.ts b/scripts/ci/check-repository-gate.test.ts index ef7871e61..50d691c59 100644 --- a/scripts/ci/check-repository-gate.test.ts +++ b/scripts/ci/check-repository-gate.test.ts @@ -13,7 +13,21 @@ import { join } from "node:path"; import { describe, expect, it } from "vitest"; +import { planChecks, readWorkspace } from "../check-plan.mjs"; + const gate = join(process.cwd(), "scripts/ci/check-repository-gate.sh"); +const changedFilesCheck = join( + process.cwd(), + "scripts/ci/check-changed-files.sh", +); +const appLintedPaths = readFileSync( + join(process.cwd(), "scripts/ci/app-linted-paths.txt"), + "utf8", +) + .split("\n") + .filter(Boolean); +// The pnpm stub fails `pnpm exec eslint` when a listed file contains this. +const lintError = "export const LINT_ERROR = 1;\n"; const cleanEnv = Object.fromEntries( Object.entries(process.env).filter(([name]) => name !== "BASE"), ); @@ -25,6 +39,8 @@ interface GateOptions { deletedPath?: string; // Pass a target branch that moved past the merge base, as a local run does. advancedTarget?: boolean; + // Run check-changed-files.sh --worktree on an uncommitted change instead. + worktree?: boolean; } // Runs the gate in a temporary repository whose pnpm and make are stubs that @@ -62,8 +78,11 @@ function runGate(options: GateOptions = {}) { join(root, changed), options.changedContent ?? "export {};\n", ); - git("add", "."); - git("commit", "-q", "-m", "head"); + if (options.worktree) git("add", "."); + else { + git("add", "."); + git("commit", "-q", "-m", "head"); + } const head = git("rev-parse", "HEAD"); let baseInput = base; if (options.advancedTarget) { @@ -80,7 +99,10 @@ function runGate(options: GateOptions = {}) { join(bin, "pnpm"), `#!/usr/bin/env bash printf 'pnpm %s\\n' "$*" >> "$COMMAND_LOG" -exit 0 +if [[ "$1 $2" == "exec eslint" ]]; then + shift 2 + ! grep -q LINT_ERROR "$@" +fi `, ); writeFileSync( @@ -94,7 +116,10 @@ exit 0 for (const command of ["pnpm", "make"]) chmodSync(join(bin, command), 0o755); - const result = spawnSync("bash", [gate], { + const command = options.worktree + ? [changedFilesCheck, base, "--worktree"] + : [gate]; + const result = spawnSync("bash", command, { cwd: root, encoding: "utf8", env: { @@ -136,7 +161,6 @@ describe("local repository gate", { timeout: 60_000 }, () => { expect.stringMatching(/^pnpm exec commitlint --from \S+ --to \S+/), "pnpm env:inventory:check", "pnpm exec prettier --check apps/web/src/example.ts", - "pnpm exec eslint apps/web/src/example.ts", "make check-scripts-fast check-docs", ]); }); @@ -180,6 +204,35 @@ describe("local repository gate", { timeout: 60_000 }, () => { ); }); + it("leaves ESLint under app-linted prefixes to the app checks", () => { + const appLinted = runGate({ + changedPath: "apps/web/src/example.ts", + changedContent: lintError, + }); + expect(appLinted.status).toBe(0); + expect(appLinted.commands).toContain( + "pnpm exec prettier --check apps/web/src/example.ts", + ); + expect(appLinted.commands.some((line) => line.includes("eslint"))).toBe( + false, + ); + + for (const changedPath of ["apps/web/vite.config.ts", "scripts/new.mjs"]) { + const gateLinted = runGate({ changedPath, changedContent: lintError }); + expect(gateLinted.status).not.toBe(0); + expect(gateLinted.commands).toContain(`pnpm exec eslint ${changedPath}`); + } + }); + + it("lints every changed file in the local worktree mode", () => { + const result = runGate({ worktree: true, changedContent: lintError }); + expect(result.status).not.toBe(0); + expect(result.commands).toEqual([ + "pnpm exec prettier --check apps/web/src/example.ts", + "pnpm exec eslint apps/web/src/example.ts", + ]); + }); + it("checks migration history only when migration SQL changed", () => { const unchanged = runGate(); expect(unchanged.stderr).not.toContain("migration"); @@ -208,3 +261,38 @@ describe("local repository gate", { timeout: 60_000 }, () => { expect(result.commands[0]).toContain(`--from ${result.base} `); }); }); + +// The gate skips ESLint under a prefix only because an app check lints it. +describe("app-linted paths", () => { + const workspace = readWorkspace(); + + it.each(appLintedPaths)("CI selects an app check for %s", (prefix) => { + const plan = planChecks([`${prefix}example.ts`], workspace); + expect(plan.all).toBe(false); + expect(plan.selected.filter((entry) => entry.ci).length).toBeGreaterThan(0); + }); + + it.each(appLintedPaths)( + "the owning package lints all of %s with no warnings", + (prefix) => { + const directory = prefix.replace(/\/$/, ""); + let packageDirectory = directory; + while (!existsSync(join(process.cwd(), packageDirectory, "package.json"))) + packageDirectory = packageDirectory.split("/").slice(0, -1).join("/"); + const relative = + directory === packageDirectory + ? "." + : directory.slice(packageDirectory.length + 1); + const manifest = JSON.parse( + readFileSync( + join(process.cwd(), packageDirectory, "package.json"), + "utf8", + ), + ) as { scripts?: { lint?: string } }; + const lint = (manifest.scripts?.lint ?? "").split(/\s+/); + expect(lint[0]).toBe("eslint"); + expect(lint).toContain("--max-warnings=0"); + expect(lint.includes(relative) || lint.includes(".")).toBe(true); + }, + ); +}); diff --git a/scripts/ci/desktop-release.test.ts b/scripts/ci/desktop-release.test.ts index 09ee0a67a..747262e80 100644 --- a/scripts/ci/desktop-release.test.ts +++ b/scripts/ci/desktop-release.test.ts @@ -262,14 +262,16 @@ describe("desktop-release.sh build", () => { }); it("keeps the archive folder's address out of the log", () => { + // A missing file:// folder fails at once; an unresolvable host would wait + // out curl's retry backoff. const result = run(["fetch-native", "linux-x64"], { LINGER_NATIVE_POSTGRES_DIR: folder(), - LINGER_NATIVE_DEPS_URL: "http://deps.invalid/private/folder", + LINGER_NATIVE_DEPS_URL: `file://${folder()}/private-deps-folder`, }); expect(result.status).toBe(1); expect(result.stderr).toContain("cannot download"); - expect(result.stdout + result.stderr).not.toContain("deps.invalid"); + expect(result.stdout + result.stderr).not.toContain("private-deps-folder"); }); });