Repository navigation
test: fix the causes behind two disabled test families and re-enable them #4835
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c012322
0248a20
6d417ce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ import { dirname, join, resolve } from "node:path"; | |
|
|
||
| import { Database } from "bun:sqlite"; | ||
|
|
||
| import { historyBackupPathFor, setBeforeHistoryBackupConsumeForTests, setHistoryDbBusyTimeoutForTests } from "../../src/codex/history-provider"; | ||
| import { adoptHistoryDbBusyTimeout, currentHistoryDbBusyTimeoutMs, historyBackupPathFor, setBeforeHistoryBackupConsumeForTests, setHistoryDbBusyTimeoutForTests } from "../../src/codex/history-provider"; | ||
| import { | ||
| isHistoryWorkerRunMessage, | ||
| runHistoryUnitUnderLock, | ||
|
|
@@ -129,6 +129,35 @@ test("the run message is structured-clone safe and fully explicit", () => { | |
| expect(isHistoryWorkerRunMessage({ ...message, operation: "delete-everything" })).toBe(false); | ||
| }); | ||
|
|
||
| /** | ||
| * The busy timeout travels with the message because a Worker is a separate realm: without it the | ||
| * Worker opens `state_5.sqlite` with its own module default and ignores a parent that resolved a | ||
| * shorter window, which is what forced a composed acceptance case to skip on Windows. | ||
| */ | ||
| test("the run message carries the parent's busy timeout and refuses a malformed one", () => { | ||
| const fixture = makeFixture("ocx-history-worker-busy-timeout-"); | ||
| const message = runMessage(fixture); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win 🔎 Supported by static analysis🏁 Script executed: sed -n '1,190p' tests/codex-integration/codex-history-worker.test.ts
sed -n '410,465p' src/codex/history-job.ts
sed -n '100,240p' src/codex/history-worker.ts
rg -n -C 3 'runCodexHistoryJob|busyTimeoutMs|setHistoryDbBusyTimeoutForTests|state_5.sqlite|historyBusyTimeoutPreload' tests src/codexRepository: lidge-jun/opencodex Length of output: 50376 🏁 Script executed: #!/bin/bash
printf '%s\n' '--- boundary test outline ---'
ast-grep outline tests/codex-integration/codex-history-worker-boundary.test.ts
printf '%s\n' '--- boundary test ---'
cat -n tests/codex-integration/codex-history-worker-boundary.test.ts
printf '%s\n' '--- worker test test declarations and relevant remainder ---'
rg -n '^(test|describe| test)\(|runCodexHistoryJob|new Worker|busyTimeout|lock|restore|30_000|timeout' tests/codex-integration/codex-history-worker.test.ts
printf '%s\n' '--- worker test lines 190-520 ---'
sed -n '190,520p' tests/codex-integration/codex-history-worker.test.ts
printf '%s\n' '--- history job worker creation and timeout option ---'
sed -n '320,470p' src/codex/history-job.tsRepository: lidge-jun/opencodex Length of output: 25763 🏁 Script executed: #!/bin/bash
printf '%s\n' '--- all test-side runCodexHistoryJob calls ---'
rg -n -C 5 'runCodexHistoryJob' tests
printf '%s\n' '--- all composed restore/worker integration test names ---'
rg -n -C 4 'restore|Worker|busyTimeout|setHistoryDbBusyTimeoutForTests|BEGIN IMMEDIATE|transaction|lock' tests/codex-integration -g '*.test.ts' | head -n 500Repository: lidge-jun/opencodex Length of output: 50375 🏁 Script executed: #!/bin/bash
printf '%s\n' '--- history job test setup and run-worker cases ---'
sed -n '1,290p' tests/codex-integration/codex-history-job.test.ts
printf '%s\n' '--- focused timeout/lock references in history job tests ---'
rg -n -C 5 'setHistoryDbBusyTimeoutForTests|busyTimeout|BEGIN IMMEDIATE|Database|lock|restore|runCodexHistoryJob' tests/codex-integration/codex-history-job.test.ts tests/codex-integration/history-ocx-compaction-recovery.test.tsRepository: lidge-jun/opencodex Length of output: 41053 Add a lock-contention regression through Line 139 tests the message and calls Add a focused test that sets a non-default parent database timeout, holds 🤖 Prompt for AI Agents |
||
| const inherited = currentHistoryDbBusyTimeoutMs(); | ||
|
|
||
| expect(isHistoryWorkerRunMessage({ ...message, busyTimeoutMs: 0 })).toBe(true); | ||
| expect(isHistoryWorkerRunMessage({ ...message, busyTimeoutMs: inherited })).toBe(true); | ||
| for (const bad of [-1, Number.NaN, Number.POSITIVE_INFINITY, "250", null]) { | ||
| expect(isHistoryWorkerRunMessage({ ...message, busyTimeoutMs: bad })).toBe(false); | ||
| } | ||
|
|
||
| // Adoption refuses the same values rather than disabling the wait the app expects. | ||
| try { | ||
| for (const bad of [-1, Number.NaN, Number.POSITIVE_INFINITY]) { | ||
| adoptHistoryDbBusyTimeout(bad); | ||
| expect(currentHistoryDbBusyTimeoutMs()).toBe(inherited); | ||
| } | ||
| adoptHistoryDbBusyTimeout(1_234); | ||
| expect(currentHistoryDbBusyTimeoutMs()).toBe(1_234); | ||
| } finally { | ||
| adoptHistoryDbBusyTimeout(inherited); | ||
| } | ||
| }); | ||
|
|
||
| test("skip is a recorded outcome, not an absence, and writes nothing", () => { | ||
| const fixture = makeFixture("ocx-history-worker-skip-"); | ||
| const before = readFileSync(fixture.rollout, "utf8"); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| /** | ||
| * Test-only seam for a spawned `ocx` child: shorten the `state_5.sqlite` busy timeout. | ||
| * | ||
| * A test that proves cross-process SQLite contention has to hold a real lock against a real CLI | ||
| * child, and the child then pays the production busy timeout twice over — 5 s per attempt plus | ||
| * the retry delay, about 10.5 s of pure waiting. That wait is not the assertion; the JSON | ||
| * envelope is. On a contended windows-latest shard the waiting alone pushed the child past its | ||
| * watchdog, which is how the composed restore-busy case came to be skipped on Windows. | ||
| * | ||
| * In-process tests already shrink this window with `setHistoryDbBusyTimeoutForTests`. A child | ||
| * process cannot be reached that way, so it gets the same knob through `--preload`. Inert unless | ||
| * `OCX_TEST_HISTORY_BUSY_TIMEOUT_MS` is set on that child's environment, and no production | ||
| * module reads that variable or imports this file. The retry count, the lock, the failure | ||
| * classification, and the reported envelope are all untouched: only the length of a sleep changes. | ||
| */ | ||
| import { setHistoryDbBusyTimeoutForTests } from "../../src/codex/history-provider"; | ||
|
|
||
| export const HISTORY_BUSY_TIMEOUT_ENV = "OCX_TEST_HISTORY_BUSY_TIMEOUT_MS"; | ||
|
|
||
| const raw = process.env[HISTORY_BUSY_TIMEOUT_ENV]; | ||
| if (raw !== undefined) { | ||
| const ms = Number(raw); | ||
| // A malformed value must not silently leave the production 5 s in place while the test | ||
| // believes it was shortened, so it fails the child loudly instead. | ||
| if (!Number.isFinite(ms) || ms < 0) { | ||
| throw new Error(`${HISTORY_BUSY_TIMEOUT_ENV} must be a non-negative number, received: ${raw}`); | ||
| } | ||
| setHistoryDbBusyTimeoutForTests(ms); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This adds a new cross-realm history-worker protocol field and changes how the worker configures SQLite before its first database access, but the commit updates none of the architecture documents mapped to
src/codex/. The scoped repository instructions require the mapped structure documents to be updated in the same change, so the architecture source of truth currently omits this timeout-propagation invariant; update the applicablestructure/documents alongside the implementation.AGENTS.md reference: src/AGENTS.md:L10-L11
Useful? React with 👍 / 👎.