Skip to content

Commit 74853e6

Browse files
anandgupta42claude
andcommitted
fix: resolve flaky CI tests — file scanner ENOENT and tui worker timeout
- file/index.ts: catch ENOENT when project directory disappears mid-scan (e.g., temp dirs from other tests cleaned up during parallel execution) - worker.test.ts: poll for worker readiness instead of fixed 3s sleep, CI runners are slower and need more time for module loading Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent ea0194e commit 74853e6

File tree

2 files changed

+39
-25
lines changed

2 files changed

+39
-25
lines changed

packages/opencode/src/file/index.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -377,19 +377,25 @@ export namespace File {
377377
}
378378

379379
const set = new Set<string>()
380-
for await (const file of Ripgrep.files({ cwd: Instance.directory })) {
381-
result.files.push(file)
382-
let current = file
383-
while (true) {
384-
const dir = path.dirname(current)
385-
if (dir === ".") break
386-
if (dir === current) break
387-
current = dir
388-
if (set.has(dir)) continue
389-
set.add(dir)
390-
result.dirs.push(dir + "/")
380+
// altimate_change start — gracefully handle directory disappearing mid-scan
381+
try {
382+
for await (const file of Ripgrep.files({ cwd: Instance.directory })) {
383+
result.files.push(file)
384+
let current = file
385+
while (true) {
386+
const dir = path.dirname(current)
387+
if (dir === ".") break
388+
if (dir === current) break
389+
current = dir
390+
if (set.has(dir)) continue
391+
set.add(dir)
392+
result.dirs.push(dir + "/")
393+
}
391394
}
395+
} catch (e: any) {
396+
if (e?.code !== "ENOENT") throw e
392397
}
398+
// altimate_change end
393399
cache = result
394400
fetching = false
395401
}

packages/opencode/test/cli/tui/worker.test.ts

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,30 @@ describe("tui worker", () => {
4848
errors.push(e.message ?? String(e))
4949
}
5050

51-
// Wait for worker to be ready
52-
await new Promise((r) => setTimeout(r, 3000))
53-
expect(errors).toEqual([])
54-
55-
// Verify RPC communication works — the worker exports a `fetch` method
51+
// Poll for worker readiness instead of a fixed sleep — CI runners
52+
// are slower and 3s is often not enough for module loading.
5653
const client = Rpc.client<typeof rpc>(worker)
57-
const result = await Promise.race([
58-
client.call("fetch", {
59-
url: "http://altimate-code.internal/health",
60-
method: "GET",
61-
headers: {},
62-
}),
63-
new Promise<never>((_, reject) => setTimeout(() => reject(new Error("RPC timeout")), 5000)),
64-
])
54+
let result: any
55+
for (let attempt = 0; attempt < 10; attempt++) {
56+
await new Promise((r) => setTimeout(r, 1000))
57+
if (errors.length > 0) break
58+
try {
59+
result = await Promise.race([
60+
client.call("fetch", {
61+
url: "http://altimate-code.internal/health",
62+
method: "GET",
63+
headers: {},
64+
}),
65+
new Promise<never>((_, reject) => setTimeout(() => reject(new Error("RPC timeout")), 3000)),
66+
])
67+
if (result?.status !== undefined) break
68+
} catch {
69+
// Worker not ready yet, retry
70+
}
71+
}
6572

73+
expect(errors).toEqual([])
6674
expect(result).toBeDefined()
6775
expect(typeof result.status).toBe("number")
68-
}, 15_000)
76+
}, 30_000)
6977
})

0 commit comments

Comments
 (0)