Skip to content

Commit 4caaee0

Browse files
committed
test+tool: [v0.9.4-consensus-m3+m5+m6] observable retry; wider staleness guard; drop unreachable sentinel
Three fixes from the consensus review of PR #1053. **m3 — cli-process.ts SQLite retry observability**: the retry was silent on the retry path, so a systematic regression from transient lock contention would keep the suite green — defeating the point of the harness. Added a `console.warn` that names the failure class and the "if you see this often, contention has moved from transient to systematic" signal, so a repeated pattern is visible in CI logs. **m5 — smoke-test-binary staleness guard walks src/ + script/**: the prior guard compared only against `script/build.ts`. That catches the rare "build logic changed" case but MISSES the common "src/ changed" case — after a `git pull` that only touches source, the guard would still say the binary is fresh and run assertions against a stale build. Rewrote `isBinaryStale()` to walk both trees, skipping `node_modules` / `.turbo` / `dist` / hidden dirs, and looking at files that actually contribute to the compiled binary (`*.ts{,x}`, `*.json`, `*.txt`, `*.md`). **m6 — sample_setup error metadata: revert suffix: -1 → 0**: the sentinel guarded a collision no consumer can reach. Error-path `output` contains no `suffix:` line at all (it's `status: error\n reason: ...\n\n${message}`), and the template branches on `status: error` first. `success: false` is the true disambiguator for metadata readers. Reverted the sentinel and updated the comment to reflect the actual disambiguation contract.
1 parent 790df9b commit 4caaee0

3 files changed

Lines changed: 77 additions & 16 deletions

File tree

‎packages/opencode/src/altimate/tools/sample-setup.ts‎

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,14 @@ export const SampleSetupTool = Tool.define("sample_setup", {
109109
`Underlying error: ${message}`
110110
return {
111111
title: "Starter sample unavailable",
112-
// `suffix: -1` (not 0) so error rows can't be confused with a success-
113-
// path fresh materialize (which reports suffix: 0 for the preferred
114-
// slot). Tech Lead flagged the shape collision during v0.9.4 review.
115-
metadata: { success: false, error: message, targetPath: "", reused: false, suffix: -1, note: "" },
112+
// `success: false` is the disambiguator for consumers reading
113+
// metadata; the `output` string separately begins `status: error`
114+
// for the template branches (which never see metadata). An earlier
115+
// version added `suffix: -1` here as a sentinel, but the error path
116+
// emits no `suffix:` line in `output`, and no downstream reader of
117+
// metadata inspects `suffix` before checking `success` — reverted
118+
// in v0.9.4 consensus review m6 to keep the shape typed.
119+
metadata: { success: false, error: message, targetPath: "", reused: false, suffix: 0, note: "" },
116120
output: `status: error\nreason: sample_source_missing\n\n${guidance}`,
117121
}
118122
}
@@ -173,10 +177,14 @@ export const SampleSetupTool = Tool.define("sample_setup", {
173177
const message = err instanceof Error ? err.message : String(err)
174178
return {
175179
title: "Starter materialization failed",
176-
// `suffix: -1` (not 0) so error rows can't be confused with a success-
177-
// path fresh materialize (which reports suffix: 0 for the preferred
178-
// slot). Tech Lead flagged the shape collision during v0.9.4 review.
179-
metadata: { success: false, error: message, targetPath: "", reused: false, suffix: -1, note: "" },
180+
// `success: false` is the disambiguator for consumers reading
181+
// metadata; the `output` string separately begins `status: error`
182+
// for the template branches (which never see metadata). An earlier
183+
// version added `suffix: -1` here as a sentinel, but the error path
184+
// emits no `suffix:` line in `output`, and no downstream reader of
185+
// metadata inspects `suffix` before checking `success` — reverted
186+
// in v0.9.4 consensus review m6 to keep the shape typed.
187+
metadata: { success: false, error: message, targetPath: "", reused: false, suffix: 0, note: "" },
180188
output: `status: error\nreason: materialize_failed\n\n${message}`,
181189
}
182190
}

‎packages/opencode/test/install/smoke-test-binary.test.ts‎

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,59 @@ function resolveNodePath(): string {
8989

9090
// altimate_change start — staleness guard.
9191
// The binary embeds NAPI .node files that get renamed as the altimate-core
92-
// hash changes; script/build.ts is the source of truth for that embed logic.
93-
// A local binary older than build.ts is guaranteed to be checked against
92+
// hash changes; both `script/` (build logic) and `src/` (compiled sources)
93+
// contribute to what the binary actually is. A local binary older than the
94+
// newest touched .ts under either tree is guaranteed to be checked against
9495
// invariants that no longer match. Skip rather than fail — the developer's
9596
// intent when running `bun test` after `git pull` is not to rebuild the binary
9697
// out-of-band, so a stale binary should surface as an actionable skip, not
9798
// a red suite that would otherwise be green.
99+
//
100+
// Consensus review m5: an earlier version compared against script/build.ts
101+
// only, which caught the rare "build logic changed" case and missed the
102+
// common "src/ changed" case. Walk both trees now; ignore node_modules and
103+
// hidden dirs so a stray watcher touch doesn't invalidate a fresh binary.
104+
function newestSourceMtime(): number {
105+
const roots = [path.join(PKG_DIR, "src"), path.join(PKG_DIR, "script")]
106+
let newest = 0
107+
const IGNORED = new Set(["node_modules", ".turbo", ".cache", "dist", "target"])
108+
const walk = (dir: string): void => {
109+
let entries: fs.Dirent[]
110+
try {
111+
entries = fs.readdirSync(dir, { withFileTypes: true })
112+
} catch {
113+
return
114+
}
115+
for (const entry of entries) {
116+
if (entry.name.startsWith(".")) continue
117+
if (IGNORED.has(entry.name)) continue
118+
const full = path.join(dir, entry.name)
119+
if (entry.isDirectory()) {
120+
walk(full)
121+
continue
122+
}
123+
// Only consider files that actually contribute to the compiled binary
124+
// — build.ts globs *.ts / *.tsx / *.json / *.txt for embedding. A
125+
// stray editor swap file (.swp) or backup shouldn't trigger a re-skip.
126+
if (!/\.(tsx?|json|txt|md)$/.test(entry.name)) continue
127+
try {
128+
const m = fs.statSync(full).mtimeMs
129+
if (m > newest) newest = m
130+
} catch {
131+
/* ignore stat errors — a missing file doesn't invalidate the guard */
132+
}
133+
}
134+
}
135+
for (const root of roots) walk(root)
136+
return newest
137+
}
138+
98139
function isBinaryStale(binaryPath: string): boolean {
99140
try {
100-
const buildScript = path.join(PKG_DIR, "script", "build.ts")
101-
if (!fs.existsSync(buildScript)) return false
102141
const binMtime = fs.statSync(binaryPath).mtimeMs
103-
const scriptMtime = fs.statSync(buildScript).mtimeMs
104-
return binMtime < scriptMtime
142+
const sourceMtime = newestSourceMtime()
143+
if (sourceMtime === 0) return false // couldn't walk sources — err on the side of running
144+
return binMtime < sourceMtime
105145
} catch {
106146
return false
107147
}
@@ -117,7 +157,7 @@ describe("compiled binary smoke test", () => {
117157
if (!binary) {
118158
test.skip("no local build found — run `bun run build:local` first", () => {})
119159
} else if (stale) {
120-
test.skip("local binary is older than script/build.ts — run `bun run build:local` to refresh", () => {})
160+
test.skip("local binary is older than the newest src/ or script/ file — run `bun run build:local` to refresh", () => {})
121161
}
122162

123163
runTest("binary starts and prints version", () => {

‎packages/opencode/test/lib/cli-process.ts‎

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,22 @@ export function withCliFixture<A, E>(
299299
const first = yield* spawn(argv, opts)
300300
if (first.exitCode === 0) return first
301301
if (!/database is locked/i.test(first.stderr)) return first
302+
// Emit a warning so a silent regression from transient → systematic
303+
// stays visible in CI logs — the retry masking the failure would
304+
// otherwise defeat the point of running the harness.
305+
// eslint-disable-next-line no-console
306+
console.warn(
307+
`[cli-process] child hit \`database is locked\` on first attempt (exit=${first.exitCode}); retrying once. ` +
308+
`If you see this often, the SQLite WAL/checkpoint contention has moved from transient to systematic.`,
309+
)
302310
const elapsed = Date.now() - startedAt
303311
const remaining = Math.max(originalTimeoutMs - elapsed, 15_000)
304-
return yield* spawn(argv, { ...opts, timeoutMs: remaining })
312+
const second = yield* spawn(argv, { ...opts, timeoutMs: remaining })
313+
// If the retry ALSO hits the lock, surface it — don't return a
314+
// succeeded-looking envelope. Bun's expectExit(second, 0) will
315+
// fire on the non-zero exit; the second attempt's stderr is
316+
// what will be logged for the debugger.
317+
return second
305318
})
306319
// altimate_change end
307320
}

0 commit comments

Comments
 (0)