Skip to content
Merged
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions .github/actions/check/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
Expand All @@ -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:
Expand Down
40 changes: 38 additions & 2 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,24 @@ 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
steps:
# 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"
Expand All @@ -47,14 +55,30 @@ 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'
- uses: actions/setup-node@v4
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.
Expand All @@ -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 }}
29 changes: 9 additions & 20 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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=<target-ref>` and the
# targets in the Makefile before you open a pull request.
Expand Down Expand Up @@ -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:
Expand All @@ -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);
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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))
}
Expand All @@ -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"
Expand All @@ -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},
Expand Down
16 changes: 12 additions & 4 deletions apps/computer/local-daemon/internal/provider/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
Loading
Loading