Skip to content

test(opencode): wait for the v2 transform callback, not a fixed 100 ms - #1468

Merged
amiddavid merged 2 commits into
mainfrom
test/fix-opencode-v2
Nov 26, 2026
Merged

amiddavid merged 2 commits into
mainfrom
test/fix-opencode-v2

Conversation

@amiddavid

Copy link
Copy Markdown
Collaborator

Summary

What changed

  • opencode-plugin/test/v2.test.mjs: replace the sleep with waitFor on the log line setup writes after transform() resolves and the pending hooks settle. Restore console.log in a finally.
  • scripts/release/pending-timing-fixes.txt: remove the last entry. The file and header stay. approval-still-valid_test.sh passes with the empty list.

How it was tested

Tests ran on macOS, Go 1.27.4.

  • node --test in opencode-plugin: 114 pass, 0 fail, 7 skipped.
  • v2.test.mjs 10 times in a loop: 10 of 10 pass.
  • Vacuity: with the log line renamed in index.js (scratch edit, reverted), the test fails after 25 s with timed out waiting for setup to finish its pass after transform() resolved. It does not hang.
  • go test ./internal/timingguard/: pass (the guard scans Go only).

Refs #1291

The v2 late-callback test slept 100 ms and hoped setup had caught up.
It now waits for the line setup logs after transform() resolves and
the pending hooks settle. That line is the point where setup judges
the providers. The wait is bound at 25 s with a named failure message.

The pending-timing list is now empty. The file and its header stay.

Signed-off-by: DAVID AMID <[email protected]>
Assisted-By: Claude Opus 5.5
@amiddavid
amiddavid force-pushed the test/fix-opencode-v2 branch from 09868e2 to 3afc796 Compare November 26, 2026 14:21
@amiddavid

Copy link
Copy Markdown
Collaborator Author

Local tests: waived (owner rule)

If the transform callback does nothing, the test failed on a bare ENOENT
from reading install.json. It now asserts the file exists first, with a
message that names the cause.

Signed-off-by: DAVID AMID <[email protected]>
Assisted-By: Claude Opus 5.5

@amiddavid amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer Kind Started by Context Review Round Head Verdict
Reviewer 1 (glm, user of @amiddavid) GLM rits/zai-org/glm-5-3 via Claude Code 2.1.332 offload-review skill, @amiddavid's session fresh 1 of 2 1 of 2 3afc796fd8fe approve

Verdict: approve

Findings

None.

Non-blocking

  • opencode-plugin/test/v2.test.mjs:271 — if setup fails before the verdict line (for example, command registration throws), the test waits the full 25 s bound and reports "timed out waiting for setup to finish its pass", not the real error. Diagnostic quality only. The failure is still caught and named.
  • opencode-plugin/test/v2.test.mjs:275 — the guard against "no Anthropic or OpenAI provider is configured" checks a line only the v1 config hook logs (opencode-plugin/index.js:1366, through safeLog). The v2 path never prints it, so the assertion cannot fail today. Harmless as a regression guard.

What I checked

  • Read the full diff: opencode-plugin/test/v2.test.mjs and scripts/release/pending-timing-fixes.txt. One commit, test only.
  • Read the whole test file and opencode-plugin/test/helpers.mjs, including waitFor (25 s bound, 100 ms poll, named failure).
  • Read setupV2 in opencode-plugin/index.js end to end. The wait condition is deterministic: the mock's ctx.provider.transform stores the callback in run and returns, setupV2 then awaits Promise.all(pendingHooks) on an empty list and logs the verdict line at opencode-plugin/index.js:1512. run is assigned inside the transform call, before the verdict line, so it is always set when the test calls it.
  • Checked the try/finally around the wait: console.log is restored even when waitFor fails. The old code restored it only after the fixed sleep.
  • Checked that no other line matches the wait regex before the verdict point, and that no fixed-time wait remains in this test (waitUntilUnhealthy polls on a connection-refused condition).
  • Checked pending-timing-fixes.txt: the file keeps its header and is now empty of entries. The removal follows the file's own rule — a PR that fixes a listed test removes its line in the same PR. Commit e0ad5c5 (#1452) did the same for the picker test.
  • Repo rules: test-only change, so no behavior change to name, no data-dependence row, no host-boundary or client-rule question. The commit has DCO sign-off and Assisted-By attribution.

@amiddavid amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer Kind Started by Context Review Round Head Verdict
Reviewer 2 (glm, user of @amiddavid) GLM rits/zai-org/glm-5-3 via Claude Code 2.1.332 offload-review skill, @amiddavid's session fresh 2 of 2 1 of 2 3afc796fd8fe approve

Verdict: approve

Findings

None.

Non-blocking

  • opencode-plugin/test/v2.test.mjs:275 — The negative assertion checks for "no Anthropic or OpenAI provider is configured". Only the v1 server path logs that line (index.js:1366, via the config hook). The v2 mock never calls that hook, so the assertion cannot fail today. It is a regression guard. Pre-existing, not changed by this PR.
  • scripts/release/pending-timing-fixes.txt — The removed entry named the test as "v2: setup waits for the host transform callback before judging providers". That title never matched the real test title ("v2: hooks work when the provider callback runs after transform() has resolved"), against the file's rule that node tests use the test title. The line is now deleted, so the mismatch is gone. No action needed.

What I checked

  • Read the full diff (2 files) and the code around each change.
  • The wait target is real: index.js:1512 logs "no Anthropic or OpenAI provider routed so far" after ctx.provider.transform(...) resolves and await Promise.all(pendingHooks) settles (index.js:1508-1512). That line is the verdict point the test needs. The regex in the test matches the log text exactly.
  • In this test, hooked is empty when the line prints: the mock stores the transform callback and does not run it, and hookProvider runs only inside that callback. So the line always appears, and it appears exactly once setup has judged the providers.
  • waitFor (helpers.mjs:121-127) is the established pattern: failopen.test.mjs:358,458,520 waits on log lines and ports the same way. It polls the condition, fails with a named message at 25 s, and does not hang.
  • The finally restores console.log even when the wait times out. The old code restored it unconditionally outside a finally, so this is stricter than before.
  • The test needs no timingOnly gating. It waits on a condition; the 25 s deadline is a safety net. CLAUDE.md says: do not gate a test that uses a long timeout as a safety net. scripts/dev/timing-tests-needed.sh also prints "skip" for this diff: no timing marker changed and v2.test.mjs holds none at head.
  • The list removal follows the file's own rule: "A PR that fixes a listed test removes its line in the same PR". After this PR the list holds only the header, as the commit message says.
  • Process checks: test-only change, so no behavior change, no data-dependence row, no host-boundary or client-rule question, no binary.
  • Live tests were not run (not approved for this review).

@amiddavid

Copy link
Copy Markdown
Collaborator Author

Round-1 follow-up: a named assertion that install.json exists. With the transform callback broken, the test now fails with "the transform callback did not start the proxy" instead of a bare ENOENT.

@amiddavid amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer Kind Started by Context Review Round Head Verdict
Reviewer 1 (glm, user of @amiddavid) GLM rits/zai-org/glm-5-3 via Claude Code 2.1.332 offload-review skill, @amiddavid's session resumed 1 of 2 2 of 2 d64bb4e186c8 approve

Verdict: approve

Findings

None.

Earlier findings

  • My round-1 non-blocking note about the 25 s waitFor burn when setup fails before the verdict line: not addressed. It stays non-blocking. The new commit does improve the naming of the other failure mode (a callback that runs but starts no proxy), which was the sharper diagnostic gap.
  • My round-1 non-blocking note about the vacuous "is configured" guard: rejected by no one, left as is. Reviewer 2 raised the same point and called it a harmless regression guard. I agree. No action needed.
  • Reviewer 2's two non-blocking notes: checked both. The pending-list title mismatch is gone with the deleted line. Agree, nothing to add.

Non-blocking

  • opencode-plugin/test/v2.test.mjs:278 — the new existence check does not rule out a stale install.json left by an earlier failed run in the same state directory. In that case the assertion passes on the old file and the test fails later, at the base-URL assertion. It still fails, so this is diagnostic quality only.

What I checked

  • Last review: round 1, 3afc796, 2026-11-26T14:24:25Z.
  • New commits read: 1 — d64bb4e1 "test(opencode): wait for the v2 transform callback, not a fixed 100 ms" (follow-up: "name the failure when the v2 callback starts no proxy").
  • Read in full: 2 reviews, 2 comments, 0 inline comments (from the three saved files).
  • New items since my last review: reviewer 2's round-1 review (agree with its two notes, both checked); the "Local tests: waived (owner rule)" comment (the interim rule's marker, present); the "Round-1 follow-up" comment naming the new assertion; the commit d64bb4e1 itself.
  • The new commit adds one line: assert.ok(existsSync(join(state, "install.json")), "the transform callback did not start the proxy") before the readFileSync. Checked that existsSync and join are already imported (v2.test.mjs:3,5). Checked the placement: after await done, so the callback has finished and the file must exist if the proxy started.
  • Re-read the changed test in full at the new head. The round-1 verdict still holds: the wait condition is the verdict line at opencode-plugin/index.js:1512, run is assigned before it, and the try/finally restores console.log.
  • Repo rules: still test-only, so no behavior change, no data-dependence row, no host-boundary or client-rule question. The new commit has DCO sign-off and Assisted-By attribution.

@amiddavid amiddavid left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewer Kind Started by Context Review Round Head Verdict
Reviewer 2 (glm, user of @amiddavid) GLM rits/zai-org/glm-5-3 via Claude Code 2.1.332 offload-review skill, @amiddavid's session resumed 2 of 2 2 of 2 d64bb4e186c8 approve

Verdict: approve

Findings

None.

Earlier findings

  • Reviewer 1, non-blocking (25 s wait can mask an early setup failure): the author fixed the narrower case in the same spirit. If the transform callback starts no proxy, the test now fails at once with a named message, not a bare ENOENT. An early setup failure still costs the 25 s bound, but that stays a diagnostic-quality point, not a defect. Accepted as fixed enough.
  • Reviewer 1, non-blocking, and my round-1 note (the "is configured" guard watches a v1-only log line): no action taken. Both reviews called it a harmless regression guard. Agreed, nothing to do.
  • My round-1 note (the removed list entry had a title that never matched the test): no action needed. The line is deleted, so the mismatch is gone.

Non-blocking

  • opencode-plugin/test/v2.test.mjs:278 — The new assertion can pass on a stale install.json left by an earlier run of the same test, because the directory /tmp/context-guru-project-v2-late is not cleaned between runs. The next assertion (baseURL equals the proxy URL) still catches that case, and the stale-file exposure predates this PR. Diagnostic quality only.

What I checked

  • Last review: round 1, 3afc796, 2026-11-26T14:25:57Z.
  • New commits read: 1 — d64bb4e "test(opencode): name the failure when the v2 callback starts no proxy".
  • Read in full: 2 reviews, 2 comments, 0 inline comments (from the three files .review-in-reviews.txt, .review-in-comments.txt, .review-in-inline.txt).
  • New items since my last review:
    • Comment by amiddavid at 2026-11-26T14:27:10Z: names the round-1 follow-up. Checked against the commit; it describes exactly what the commit does.
    • Commit d64bb4e: adds one line, assert.ok(existsSync(join(state, "install.json")), "the transform callback did not start the proxy"), before the readFileSync. Reviewed as a first review:
      • Placement is right: after await run() and await done, before the read that used to fail with ENOENT.
      • The assertion cannot false-fail: startProxy writes install.json before it returns (index.js:1135, writeAtomic(recordPath, ...) at the end of the start path), and the reuse branch returns early only when the file already exists and holds a healthy record.
      • Imports: existsSync and join are already imported in the file and used by other tests in it.
      • Test-only change: no behavior change, no data-dependence row, no host-boundary or client-rule question, no binary. Commit has DCO sign-off and Assisted-By attribution.
  • The older comment at 2026-11-26T14:21:50Z is the owner-rule waiver line ("Local tests: waived (owner rule)"), which CLAUDE.md accepts.
  • Live tests were not run (not approved for this review).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant