Skip to content
Closed
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
62 changes: 62 additions & 0 deletions .github/workflows/debug-test-hang.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# TEMPORARY (debug PR, do not merge). Finds why `test/tool/webfetch.test.ts` and the
# workspace-sync tests hang for minutes on CI runners. Delete with the branch.
name: Debug test hang

on:
pull_request:
branches: [main]

permissions:
contents: read

jobs:
hang:
name: hang (${{ matrix.case }})
if: github.head_ref == 'debug/ci-test-hang'
runs-on: ubuntu-latest
timeout-minutes: 25
strategy:
fail-fast: false
matrix:
include:
- case: shard-1
args: --shard=1/4 --path-ignore-patterns=test/altimate/learn/cli.test.ts --path-ignore-patterns=test/altimate/learn/bootstrap-cli.test.ts --path-ignore-patterns=test/altimate/tool-cli/cli.test.ts --path-ignore-patterns=test/altimate/rules/host-cli.test.ts --path-ignore-patterns=test/upstream/bridge-merge-e2e.test.ts
- case: shard-2
args: --shard=2/4 --path-ignore-patterns=test/altimate/learn/cli.test.ts --path-ignore-patterns=test/altimate/learn/bootstrap-cli.test.ts --path-ignore-patterns=test/altimate/tool-cli/cli.test.ts --path-ignore-patterns=test/altimate/rules/host-cli.test.ts --path-ignore-patterns=test/upstream/bridge-merge-e2e.test.ts
- case: shard-3
args: --shard=3/4 --path-ignore-patterns=test/altimate/learn/cli.test.ts --path-ignore-patterns=test/altimate/learn/bootstrap-cli.test.ts --path-ignore-patterns=test/altimate/tool-cli/cli.test.ts --path-ignore-patterns=test/altimate/rules/host-cli.test.ts --path-ignore-patterns=test/upstream/bridge-merge-e2e.test.ts
- case: shard-4
args: --shard=4/4 --path-ignore-patterns=test/altimate/learn/cli.test.ts --path-ignore-patterns=test/altimate/learn/bootstrap-cli.test.ts --path-ignore-patterns=test/altimate/tool-cli/cli.test.ts --path-ignore-patterns=test/altimate/rules/host-cli.test.ts --path-ignore-patterns=test/upstream/bridge-merge-e2e.test.ts
steps:
- uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
with:
persist-credentials: false

- uses: oven-sh/setup-bun@ecf28ddc73e819eb6fa29df6b34ef8921c743461 # v2
with:
bun-version: "1.3.14"

- name: Cache Bun dependencies
uses: actions/cache@0057852bfaa89a56745cba8c7296529d2fc39830 # v4
with:
path: ~/.bun/install/cache
key: bun-${{ runner.os }}-${{ hashFiles('bun.lock') }}
restore-keys: |
bun-${{ runner.os }}-

- name: Configure git for tests
run: |
git config --global user.name "CI"
git config --global user.email "ci@test.local"

- name: Install dependencies
run: bun install

- name: Install merge tooling deps (script/upstream)
run: bun install
working-directory: script/upstream

- name: Run tests with stall diagnostics
working-directory: packages/opencode
shell: bash
run: bash ../../script/github/debug-test-hang.sh ${{ matrix.args }}
9 changes: 8 additions & 1 deletion packages/opencode/src/config/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,18 @@ export function needsDependencies(dir: string, plugins: readonly ConfigPluginV1.
// PURE mode skips dependency installs entirely: isolated-HOME environments and subprocess tests run
// with no package cache, so the install attempt fails, npm retries, and the process hangs past exit.
// Fold that check in here so both call sites (Config and TuiConfig) stay in sync.
/** `ALTIMATE_DISABLE_DEPENDENCY_INSTALL=1` skips the install. The test suite sets it: an install
* started by one test is not awaited, outlives the test, and runs inside the test process. */
function installDisabled(): boolean {
const v = process.env["ALTIMATE_DISABLE_DEPENDENCY_INSTALL"]?.toLowerCase()
return v === "true" || v === "1"
}

export function shouldInstallDependencies(
dir: string,
plugins: readonly ConfigPluginV1.Spec[] | undefined,
): boolean {
return !Flag.OPENCODE_PURE && needsDependencies(dir, plugins)
return !Flag.OPENCODE_PURE && !installDisabled() && needsDependencies(dir, plugins)
}
// altimate_change end

Expand Down
11 changes: 11 additions & 0 deletions packages/opencode/test/config/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1063,6 +1063,17 @@ const loadConfigDirWithDependencies = (
describe("config dir plugin dependency install", () => {
const npmIt = testEffect(Layer.mergeAll(infra, FSUtil.defaultLayer))

// The suite's preload switches the background install off. These cases check when the app
// asks for one, through a recording installer that never reaches the network.
let installOff: string | undefined
beforeEach(() => {
installOff = process.env["ALTIMATE_DISABLE_DEPENDENCY_INSTALL"]
delete process.env["ALTIMATE_DISABLE_DEPENDENCY_INSTALL"]
})
afterEach(() => {
if (installOff !== undefined) process.env["ALTIMATE_DISABLE_DEPENDENCY_INSTALL"] = installOff
})

npmIt.effect("skips the install in a bare writable config dir but still writes .gitignore", () =>
Effect.gen(function* () {
const npm = recordingNpm()
Expand Down
5 changes: 3 additions & 2 deletions packages/opencode/test/config/tui.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ const getTuiPluginOrigins = (directory: string) =>
// altimate_change start — cover the TUI call site independently from server Config.
for (const source of ["bare", "npm", "file", "tool", "node_modules", "outside"] as const) {
for (const pure of [false, true]) {
// The suite's preload switches the install off; this gate is checked through a recording installer.
it.instance(`tui dependency install gate: ${source}${pure ? " (PURE)" : ""}`, () =>
withEnv(
withEnv("ALTIMATE_DISABLE_DEPENDENCY_INSTALL", "0", withEnv(
"OPENCODE_PURE",
pure ? "1" : "0",
withCleanState(
Expand Down Expand Up @@ -130,7 +131,7 @@ for (const source of ["bare", "npm", "file", "tool", "node_modules", "outside"]
expect(installs).toEqual(!pure && ["file", "tool", "node_modules"].includes(source) ? [local] : [])
}),
),
),
)),
)
}
}
Expand Down
6 changes: 6 additions & 0 deletions packages/opencode/test/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ process.env["ALTIMATE_DISABLE_WORKSPACE"] = "1"
// keychain); tests must never write there. Credential-store tests inject a backend instead.
process.env["ALTIMATE_CODE_DISABLE_OS_CREDENTIAL_STORE"] = "1"
// altimate_change end
// altimate_change start — a test that writes a tool or plugin file into a config dir makes the
// app start a real `npm install` of `@opencode-ai/plugin` there, in this process and not awaited.
// It outlives the test: several pile up, starve the event loop, and the tests that run next time
// out. Tests that check the install itself clear this and inject an installer.
process.env["ALTIMATE_DISABLE_DEPENDENCY_INSTALL"] = "1"
// altimate_change end

// Set test home directory to isolate tests from user's actual home directory
// This prevents tests from picking up real user configs/skills from ~/.claude/skills
Expand Down
19 changes: 18 additions & 1 deletion packages/opencode/test/skill/release-v0.11.1-adversarial.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,24 @@ describe("shouldInstallDependencies — Flag.OPENCODE_PURE fold", () => {
fs.mkdirSync(path.join(dir, "node_modules"))
saved = process.env[ENV_KEY]
delete process.env[ENV_KEY]
expect(ConfigPlugin.shouldInstallDependencies(dir, undefined)).toBe(true)
// The suite's preload switches the install off; this case is about the product default.
const off = process.env["ALTIMATE_DISABLE_DEPENDENCY_INSTALL"]
delete process.env["ALTIMATE_DISABLE_DEPENDENCY_INSTALL"]
try {
expect(ConfigPlugin.shouldInstallDependencies(dir, undefined)).toBe(true)
} finally {
if (off !== undefined) process.env["ALTIMATE_DISABLE_DEPENDENCY_INSTALL"] = off
}
})

test("ALTIMATE_DISABLE_DEPENDENCY_INSTALL=1 suppresses installation, as the test suite's preload does", () => {
const dir = tmp()
fs.mkdirSync(path.join(dir, "node_modules"))
saved = process.env[ENV_KEY]
delete process.env[ENV_KEY]
expect(process.env["ALTIMATE_DISABLE_DEPENDENCY_INSTALL"]).toBe("1")
expect(ConfigPlugin.needsDependencies(dir, undefined)).toBe(true)
expect(ConfigPlugin.shouldInstallDependencies(dir, undefined)).toBe(false)
})
})

Expand Down
49 changes: 49 additions & 0 deletions script/github/debug-test-hang.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/usr/bin/env bash
# TEMPORARY (debug PR, do not merge): runs `bun test "$@"` and, whenever its output
# stops for 45s, prints what the test process is doing.
set -u
OUT=/tmp/debug-test.txt
echo "== host: $(nproc) cpus"; free -m | head -2; uptime
echo "== /etc/hosts"; cat /etc/hosts
echo "== localhost resolves to"; getent ahosts localhost | head -4
echo "== proxy env"; env | grep -i -E '^(https?|no|all)_proxy=' || echo "(none)"
echo "== date"; date -u; echo "TZ=${TZ:-unset}"

npm_cache_report() {
echo "-- npm cache: $(du -sh ~/.npm/_cacache 2>/dev/null | cut -f1), $(find ~/.npm/_cacache/index-v5 -type f 2>/dev/null | wc -l) index files"
echo "-- node_modules dirs under /tmp: $(find /tmp -maxdepth 5 -name node_modules -type d 2>/dev/null | wc -l)"
echo "-- registry requests by package (count):"
grep -rhoa '"key":"[^"]*"' ~/.npm/_cacache/index-v5 2>/dev/null | sed -E 's#"key":"make-fetch-happen:request-cache:##; s#"$##; s#https://registry.npmjs.org/##; s#/-/.*-([0-9][^/]*)\.tgz# TARBALL \1#' | sort | uniq -c | sort -rn | head -n "${1:-40}"
}

OPENCODE_SKIP_SUBPROCESS=1 bun test --timeout 90000 "$@" > "$OUT" 2>&1 &
PID=$!
dumps=0
while kill -0 "$PID" 2>/dev/null; do
sleep 15
kill -0 "$PID" 2>/dev/null || break
idle=$(( $(date +%s) - $(stat -c %Y "$OUT") ))
[ "$idle" -lt 45 ] && continue
dumps=$((dumps + 1))
echo "::group::STALL dump $dumps: no test output for ${idle}s at $(date -u +%T)"
echo "-- last test output"; tail -n 12 "$OUT"
echo "-- load / memory"; uptime; free -m | head -2
echo "-- process tree"; ps -eo pid,ppid,stat,etime,pcpu,pmem,args --forest | grep -v -E 'ps -eo|kworker|\[' | tail -n 40
npm_cache_report 25
echo "-- bun process"; grep -E 'State|Threads|VmRSS|voluntary' "/proc/$PID/status"
echo "-- sockets"; sudo ss -tunap 2>/dev/null | grep -v -E 'systemd|chronyd|sshd' | head -n 40
echo "-- open files (non-regular)"; sudo ls -l "/proc/$PID/fd" 2>/dev/null | grep -E 'socket|pipe|anon_inode|/tmp|\.db|\.lock' | tail -n 40
echo "-- syscalls for 8s"; sudo timeout 8 strace -f -p "$PID" -s 100 -e trace=network,openat,flock,fcntl,poll,epoll_wait,futex,wait4,nanosleep,clock_nanosleep 2>&1 | grep -v -E 'EAGAIN|resumed' | tail -n 60
echo "-- syscall summary for 5s"; sudo timeout 5 strace -f -c -p "$PID" 2>&1 | tail -n 25
echo "::endgroup::"
if [ "$dumps" -ge 4 ]; then echo "== stopping the run after 4 stall dumps"; kill "$PID"; sleep 3; kill -9 "$PID" 2>/dev/null; break; fi
sleep 30
done
wait "$PID"; code=$?
echo "== bun exit code $code"
echo "== tests over 10s, failures, summary"
grep -E '^\(fail\)|\[[0-9]{5,}\.[0-9]+ms\]|^ *[0-9]+ (pass|fail)$|^Ran ' "$OUT" | tail -n 40
echo "== npm cache at the end"; npm_cache_report 120
echo "== total distinct packages requested: $(grep -rhoa '"key":"[^"]*"' ~/.npm/_cacache/index-v5 2>/dev/null | sort -u | wc -l)"
echo "== kernel log tail"; sudo dmesg 2>/dev/null | tail -n 25
exit 0
Loading