Skip to content

Reduce unit test waits, byte comparisons and import overhead - #25187

Merged
nwparker merged 3 commits into
mainfrom
nwparker/ci-clock-byte-ssh-fixtures-20261004
Oct 4, 2026
Merged

nwparker merged 3 commits into
mainfrom
nwparker/ci-clock-byte-ssh-fixtures-20261004

Conversation

@nwparker

@nwparker nwparker commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 16 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​609 $\color{#cf222e}{\Huge{\mathbf{−}}}$​276 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​333
Prod 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​426 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​426

ELI5

CI spends less time waiting on simulated deadlines and comparing large files byte by byte. The tests keep their original scenarios and now catch several timing and SSH-limit faults that the old assertions missed.

What Changed

Stub an unused saved-note menu import and assert it stays unused. Mock unrelated window-service registrars and assert their exact wiring. Batch OpenCode fixture writes between unchanged observation barriers. Use scoped clocks after title-send terminal setup, OpenCode TUI native import, provider child/stream readiness and in the real React delivery-hook tests. Replace deep Buffer traversal with native equality of every byte and length. Replace the expensive SSH directory population with fewer, longer real paths that cross the actual transport limit, and add 65 valid installs to exercise the 64-result limit. Check pending TUI timers before restoring its test clock, using a native two-second cleanup deadline. Isolate Muse settings from an inherited XDG_CONFIG_HOME so repeated runs cannot reuse a deleted fixture.

Why

This reduces test work without shortening production deadlines or cutting scenarios. Missing provider output still uses a real observation window; child processes, SQLite operations, encrypted-cap fixtures and SSH shell enumeration remain real. Clock boundaries and SSH output limits are more precisely checked.

Linked Issue

N/A — internal CI optimization.

Visual Proof

N/A — test code and fixtures only; application behavior is unchanged.

Testing

  • Local targeted tests, Node/web typecheck, lint and formatting pass.
  • Automated tests updated; original case names and platform outcomes retained.
  • Three alternating one-worker ARM pairs, Node 24.21.0, per workload:
Workload Complete invocation median Hosted evidence
Provider deadlines, 35 cases 35.914 → 10.142s (71.8%) 37186232658
Native-chat delivery, 15 cases 22.321 → 7.376s (67.0%) 37183731823
Six profile-byte suites, 118 cases 12.629 → 9.978s (21.0%) 37183141654
Encrypted account storage, six cases 18.277 → 0.958s (94.8%) 37184007241
SSH commands, 27 cases 6.840 → 6.078s (11.1%) 37184454532
OpenCode subscription, 28 cases 47.347 → 6.284s (86.7%) 37184858823
Window-service attachment, 31 cases 11.910 → 1.619s (86.4%) 37186340840
OpenCode 2 TUI ownership, 41 cases 16.811 → 2.429s (85.6%) 37187699312
Title-send authorization, nine cases 29.545 → 12.995s (56.0%) 37188423318
Range selection, 15 cases 9.737 → 7.130s (26.8%) 37188996198

These are focused workload measurements, not whole-shard or queue-delay claims. All case names and outcomes match between treatments. The profile cohort keeps four existing Linux skips; SSH keeps four unavailable PowerShell 5.1 skips on the hosted image. Failure controls catch six provider deadline faults, eight delivery-hook faults, nine byte/length faults and eight real SSH transport/filter/order faults. Separate OpenCode captures match 124,754,101 bytes of ordered rows, page/signal requests and subscription callbacks; all five row/frontier/cap/commit/rollback faults fail in both schemas. Two delivery faults pass the old tests and fail the new boundary assertions. Nine window wiring/order faults fail the intended assertions. TUI captures match separate ordered event and full POST streams (1,040 rows), excluding wall timestamps and cross-stream timing; eleven semantic/timer faults and four failure-restoration controls qualify. Four provider failure-path controls prove early rejection/refusal and timer restoration, including a native test timeout. Six title wrapper/guard/false-identity faults fail the exact before/at assertions; three real range/hunk/draft faults and a menu-boundary invocation control fail with mocks cleared. The teardown qualification passes both 41-case versions and all 12 controls, including interval/retry leaks that the old teardown missed, and native cleanup stalls. Separately, two repeated four-case Muse fixture runs pass against the same stale settings file; removing either the installer or refresher still fails the existing coverage assertion. Final-head required CI will qualify the complete suite before merge. The first aggregate source comparison was rejected for an incorrect serializer ledger and this reproduced configuration-isolation failure; it supplies no whole-suite speed claim. A new comparison will use the repaired common fixture and independently corrected case ledger.

Review

Clocks are scoped and restored after cleanup; provider clocks begin only after real child readiness. Buffer.equals checks complete bytes and length. SSH uses a real shell channel and the production output limiter, with platform path utilities and unchanged unavailable-shell skip rules. Production, remote execution and persistence behavior are unchanged.

Agent skill upstream boundary

  • Not applicable; no upstream skill code copied.

Checklist

  • Focused on test execution and stronger assertions.
  • Explained before/after, mechanism and alternatives.
  • N/A visual proof has a reason.
  • Reviewed clock cleanup, bytes, process barriers and SSH limits.
  • Local macOS and hosted Linux ARM verified; CI covers supported platform paths.
  • Local checks pass; required CI covers integration and packaging.

@nwparker
nwparker marked this pull request as ready for review October 4, 2026 09:56
@coderabbitai

coderabbitai Bot commented Oct 4, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c2a63b29-2220-429d-824c-47d4cfbe6f4d
📥 Commits

Reviewing files that changed from the base of the PR and between ae2e6a3 and ae22eb5.

📒 Files selected for processing (3)
  • docs/reference/ci-runner-efficiency.md
  • src/main/agent-hooks/managed-hook-script-refresh.test.ts
  • src/main/opencode/hook-plugin-opencode2-tui-ownership.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.


📝 Walkthrough

Walkthrough

The pull request updates test fixtures and assertions across session handling, OpenCode, persistence, SSH listing, window services, and range selection. Tests use explicit timer advancement for deadline and polling checks, batch SQLite fixture mutations, and compare persisted bytes with Buffer.equals. New shared fixtures support SSH listing and main-window service tests. A reference report records paired test timings and the controls and limits used in those comparisons.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to ae22e

The reported table and test-cleanup issues are fixed. No actionable merge-blocking risk is established; the complete suite still needs its normal required CI run.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 4.76% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 21 functions across 20 files. (1 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly summarizes the test-efficiency changes, including reduced waits, byte comparisons, and import overhead.
Description check ✅ Passed The description covers the required sections, explains the changes and rationale, reports testing and measurements, and marks visual proof and the upstream boundary as not applicable where appropriate…
Full details: Docstring Coverage

Explanation

Docstring coverage is 4.76% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 21 functions across 20 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 6080f576-16e9-445f-9ad2-18869defccdb
📥 Commits

Reviewing files that changed from the base of the PR and between c4e8735 and ae2e6a3.

📒 Files selected for processing (20)
  • docs/reference/ci-runner-efficiency.md
  • src/main/antigravity/native-account-store.test.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-claude-stop-ends-session.test.ts
  • src/main/native-chat/agent-session-wire/structured-agent-session-stop-deadline.test-fixture.ts
  • src/main/native-chat/transcript-opencode-subscribe.test.ts
  • src/main/opencode/hook-plugin-opencode2-tui-ownership.test.ts
  • src/main/persistence/loading-store/profile-state-sqlite-authority.test.ts
  • src/main/persistence/loading-store/profile-state-store-backups.test.ts
  • src/main/persistence/profile-state/profile-state-authority-bootstrap.test.ts
  • src/main/persistence/profile-state/profile-state-backup-worker.test.ts
  • src/main/persistence/profile-state/profile-state-database-snapshot.test.ts
  • src/main/persistence/profile-state/profile-state-database.test.ts
  • src/main/runtime/quarter-circle-title-send-authorization.test.ts
  • src/main/runtime/structured-agent-session-codex-turn-end-settlement.test.ts
  • src/main/ssh/ssh-relay-gc-listing.test-fixture.ts
  • src/main/ssh/ssh-remote-commands.test.ts
  • src/main/window/attach-main-window-services.test.ts
  • src/main/window/main-window-service-stubs.test-fixture.ts
  • src/renderer/src/components/diff-comments/useDiffCommentDecorator.range-selection.test.tsx
  • src/renderer/src/components/native-chat/NativeChatStructuredSessionDelivery.test.tsx

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

Comment thread docs/reference/ci-runner-efficiency.md Outdated
Comment on lines +64 to +71

| Window-service attachment, 31 cases | 11.910s | 1.619s | 86.4% | [37186340840](https://github.com/stablyai/orca/actions/runs/37186340840) |

| OpenCode 2 TUI ownership, 41 cases | 16.811s | 2.429s | 85.6% | [37187699312](https://github.com/stablyai/orca/actions/runs/37187699312) |

| Title-send authorization, nine cases | 29.545s | 12.995s | 56.0% | [37188423318](https://github.com/stablyai/orca/actions/runs/37188423318) |

| Range selection, 15 cases | 9.737s | 7.130s | 26.8% | [37188996198](https://github.com/stablyai/orca/actions/runs/37188996198) |

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Remove the blank lines inside the timing table.

In Markdown, a blank line ends a table. Lines 65, 67, 69 and 71 come after blank lines, so the renderer does not show them as rows of the table. Each line has no header or delimiter row, so it shows as plain text with pipes. As a result, the report loses four of its ten workloads from the table.

Proposed fix
 | OpenCode subscription, 28 cases                      | 47.347s         | 6.284s           | 86.7%     | [37184858823](https://github.com/stablyai/orca/actions/runs/37184858823) |
-
 | Window-service attachment, 31 cases | 11.910s | 1.619s | 86.4% | [37186340840](https://github.com/stablyai/orca/actions/runs/37186340840) |
-
 | OpenCode 2 TUI ownership, 41 cases | 16.811s | 2.429s | 85.6% | [37187699312](https://github.com/stablyai/orca/actions/runs/37187699312) |
-
 | Title-send authorization, nine cases | 29.545s | 12.995s | 56.0% | [37188423318](https://github.com/stablyai/orca/actions/runs/37188423318) |
-
 | Range selection, 15 cases | 9.737s | 7.130s | 26.8% | [37188996198](https://github.com/stablyai/orca/actions/runs/37188996198) |
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
| Window-service attachment, 31 cases | 11.910s | 1.619s | 86.4% | [37186340840](https://github.com/stablyai/orca/actions/runs/37186340840) |
| OpenCode 2 TUI ownership, 41 cases | 16.811s | 2.429s | 85.6% | [37187699312](https://github.com/stablyai/orca/actions/runs/37187699312) |
| Title-send authorization, nine cases | 29.545s | 12.995s | 56.0% | [37188423318](https://github.com/stablyai/orca/actions/runs/37188423318) |
| Range selection, 15 cases | 9.737s | 7.130s | 26.8% | [37188996198](https://github.com/stablyai/orca/actions/runs/37188996198) |
| Window-service attachment, 31 cases | 11.910s | 1.619s | 86.4% | [37186340840](https://github.com/stablyai/orca/actions/runs/37186340840) |
| OpenCode 2 TUI ownership, 41 cases | 16.811s | 2.429s | 85.6% | [37187699312](https://github.com/stablyai/orca/actions/runs/37187699312) |
| Title-send authorization, nine cases | 29.545s | 12.995s | 56.0% | [37188423318](https://github.com/stablyai/orca/actions/runs/37188423318) |
| Range selection, 15 cases | 9.737s | 7.130s | 26.8% | [37188996198](https://github.com/stablyai/orca/actions/runs/37188996198) |

if (vi.isFakeTimers()) {
vi.clearAllTimers()
}
vi.useRealTimers()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

sed -n '85,205p' src/main/opencode/hook-plugin-opencode2-tui-ownership.test.ts
sed -n '1,65p' src/shared/promise-timeout-fallback.ts

Repository: stablyai/orca

Length of output: 4623


🏁 Script executed:

sed -n '1,90p' src/main/opencode/hook-plugin-opencode2-tui-ownership.test.ts
rg -n '"vitest"|from .node:timers|withTimeout\\(' package.json pnpm-lock.yaml src/main/opencode src/shared -g '*.ts' -g 'package.json' -g 'pnpm-lock.yaml' | head -100

Repository: stablyai/orca

Length of output: 3228


Keep fake timers active through cleanup assertions.

afterEach starts each close wrapper, then restores real timers before await cleanup() resumes. The vi.isFakeTimers() guard is therefore false, so pending timers are not checked. Clear fixture timers before invoking cleanup, await cleanup while fake timers remain active, and restore real timers after the bounded wait. Use a captured real timer for the two-second deadline because withTimeout uses the fakeable global setTimeout.

Suggested fix
-import { withTimeout } from '../../shared/promise-timeout-fallback'
+
+const realSetTimeout = globalThis.setTimeout
+const realClearTimeout = globalThis.clearTimeout
...
   afterEach(async () => {
-    const closing = [...cleanups].map((cleanup) => cleanup())
     postDelayMs = 0
     for (const finish of delayedPosts) {
       finish()
     }
     if (vi.isFakeTimers()) {
       vi.clearAllTimers()
     }
-    vi.useRealTimers()
+    const closing = [...cleanups].map((cleanup) => cleanup())
+    let timeout: ReturnType<typeof realSetTimeout> | undefined
+    const deadline = new Promise<boolean>((resolve) => {
+      timeout = realSetTimeout(() => resolve(false), 2000)
+    })
     try {
       expect(
-        await withTimeout(
-          Promise.all(closing).then(() => true),
-          2000,
-          false
-        )
+        await Promise.race([
+          Promise.all(closing).then(() => true, () => false),
+          deadline
+        ])
       ).toBe(true)
     } finally {
+      if (timeout !== undefined) {
+        realClearTimeout(timeout)
+      }
+      vi.useRealTimers()
       cleanups.clear()

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ No new issues found.

Reviewed changes — the full diff at ae2e6a3 (test support and docs only; no production behavior changes).

  • Scoped fake clocks in deadline tests — new structured-agent-session-stop-deadline.test-fixture.ts and readAgentEvidenceAtDeadline/useProbeClock helpers advance only Date/setTimeout/clearTimeout after real child readiness, then assert before/at boundaries (6599/6600, 1049/1050, grace−1/grace, probe 999/1000).
  • Native byte comparison — readFileSync(x).toEqual(prev) replaced with .equals(prev)).toBe(true) across six profile-state suites and the Antigravity account store.
  • Batched SQLite fixture writes — transcript-opencode-subscribe.test.ts wraps uninterrupted writes in BEGIN/COMMIT between unchanged observation barriers.
  • Real SSH GC listing fixture — ssh-relay-gc-listing.test-fixture.ts drives the production execCommand limiter over a real /bin/sh shell channel and adds 63 dirs to cross the 64-result cap.
  • Window-service wiring assertions — five registrar modules are now mocked and asserted for exact args/order; shared stubs moved to main-window-service-stubs.test-fixture.ts.
  • Range-selection isolation — the unused NotesSendMenu is stubbed and asserted never to render; the 15 test bodies are unchanged.

I checked the load-bearing invariants: execCommand returns the tail of output (appendExecOutputTail slices the last MAX_EXEC_OUTPUT_CHARS), so the cap-length and truncated-valid-names assertions are sound; listRelayBaseDirsCommand's awk preserves find order, so the first-64 comparison does not depend on filesystem ordering; awaitStoppedRequestEnd resolves void, so the fixture spy does not mask a return value; and withTimeout(..., false) resolves false on a rejected cleanup, so the teardown control can fail.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ℹ️ No critical issues — one documentation note below.

Reviewed changes — the delta since the prior pullfrog review at ae2e6a3 (test support and docs only; no production behavior changes).

  • TUI teardown assertions now actually run — hook-plugin-opencode2-tui-ownership.test.ts awaits the registered cleanups while the fake clock is still active and checks vi.getTimerCount() before vi.useRealTimers(), using a native 2s deadline via captured realSetTimeout/realClearTimeout instead of withTimeout. This closes the gap carried forward from the prior review, where the timer-leak assertion was skipped on the afterEach path.
  • Managed hook refresh env isolation — the coverage test now saves, clears and restores XDG_CONFIG_HOME alongside GROK_HOME/KIMI_CODE_HOME, so a repeated run cannot reuse a deleted fixture.
  • Docs table alignment — the October 4 benchmark table in docs/reference/ci-runner-efficiency.md is padded to aligned columns.

ℹ️ Nitpicks

  • docs/reference/ci-runner-efficiency.md:136 still reads "Teardown restores real clocks before its bounded wait." The restructured afterEach now waits for cleanup first and calls vi.useRealTimers() afterward, so the sentence describes the inverse order.

Pullfrog  | Fix it ➔ | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@nwparker
nwparker merged commit 87bc51d into main Oct 4, 2026
59 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant