Repository navigation
test(gateway): consolidate run-loop.test.ts - #166012
Conversation
Merge equivalent lifecycle cases and share scenario setup while retaining all 167 expanded cases, issue regressions, and real process/SQLite coverage. Production code is unchanged. Baseline and consolidated suite passed on Testbox; independent review is clean.
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs changes before merge. Reviewed October 6, 2026, 4:54 AM ET / 08:54 UTC (Revision 3). ClawSweeper reviewWhat this changesConsolidates Gateway startup, shutdown, and update tests through shared local setup and scenario tables while retaining distinct lifecycle outcomes. Merge readiness⛔ Needs changes before merge - 1 item remains This remains useful test maintenance beyond the merged baseline. No introduced correctness defect was found, and the earlier evidence request is addressed; the author's explicit no-merge hold remains active. Priority: P3 Review scores
Verification
How this fits togetherThe foreground Gateway run loop receives process signals and host requests, then coordinates active-work draining, cleanup, and stop or restart handoffs. These tests protect the ordering and completion of that lifecycle. flowchart TD
A[Startup and process signals] --> B[Gateway run loop]
C[Host requests] --> B
B --> D[Admission and request policy]
D --> E[Drain and cleanup]
E --> F[Stop or restart handoff]
G[Lifecycle test fixtures] --> B
F --> H[Outcome assertions]
Before merge
Agent review detailsSecurityNone. PR surfaceTests -520. Total -520 across 9 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep compact lifecycle tables and local fixture factories while preserving distinct race, persistence, and process-lifetime contracts without increasing test cost. Do we have a high-confidence way to reproduce the issue? Not applicable: this consolidates tests rather than reporting a product defect. Introduced hunks and the production owner were inspected; tests were not executed during this read-only review. Is this the best way to solve the issue? Yes: local setup reuse and scenario tables fit the existing test owner while retaining meaningful lifecycle distinctions and stronger final-outcome assertions. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against cf2388dedd72. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
History |
Remove an unused runtime binding and avoid returning a timer from a Promise executor. Fresh review is clean; changed-file lint and all 167 run-loop cases pass on Testbox. Full changed checks expose two pre-existing unused exports reproduced with the original tests.
|
Merged via squash.
|
* test(gateway): consolidate run-loop.test.ts Merge equivalent lifecycle cases and share scenario setup while retaining all 167 expanded cases, issue regressions, and real process/SQLite coverage. Production code is unchanged. Baseline and consolidated suite passed on Testbox; independent review is clean. * test(gateway): fix consolidation lint checks Remove an unused runtime binding and avoid returning a timer from a Promise executor. Fresh review is clean; changed-file lint and all 167 run-loop cases pass on Testbox. Full changed checks expose two pre-existing unused exports reproduced with the original tests.
What Problem This Solves
Consolidates repeated foreground Gateway lifecycle test setup and equivalent scenario structure in
run-loop.test.tsand its exclusive support files.User Impact
No user-visible behavior or production changes. All 167 expanded test cases remain, including issue-number regressions, startup/stop ownership races, real file-log persistence, and seven real SQLite/package/helper-process integration rows.
Why This Change Was Made
Merge queued-startup success/failure, update upgrades at close/lock release, native refusal/uncertainty, and external signal authorization into input tables. Exclusive support files consolidate EOF, cleanup deadlines, replacement during boot, captured Stop retries, and failed supervisor handoffs. Small local factories own repeated setup; existing deferred helpers replace handwritten promise bookkeeping. Remove redundant log/call assertions only where the same test still proves the effect.
The baseline already includes #165980's consolidation. This uses the requested target escape hatch: the main file shrinks 10.27%, and the file plus all exclusive supports shrinks 8.26%, below the 35% target. No meaningful case was deleted to reach a quota.
src/cli/gateway-cli/)Production LOC delta: 0, required by this test-only lane. Shared
run-loop.test-support.tsandrun-loop-mocks.test-support.tsremain unchanged because other test files import them. Two pre-existing unused-export findings are documented below; their production owners remain outside this lane.Merged cases and remaining proof
queues SIGUSR2 received before the run-loop installs its restart waiter;processes queued SIGUSR2 when restart startup fails before returning a serverprocesses SIGUSR2 queued before startup returns a server (startup fails: %s), false/true. Exact start/reset/lock counts and failure input retained.reopens a fresh generation only after a definitive native stop refusal;reports uncertain native stop without clean-stop success or in-process recoveryrecovers only after a definitive native stop refusal ($outcome), refused/uncertain. Disposal join, original detail strings, exit codes, replacement count and retired-host rejection retained.clears stale restart state before routing external SIGUSR2 through the scheduler;clears the in-flight restart token when an unauthorized SIGUSR2 is ignoredclears the SIGUSR2 token before applying external restart policy (allowed: %s), true/false. Scheduling order, no-close/no-restart, real admission state and exact deny warnings retained.upgrades an accepted restart when an update arrives during shutdown;reads an update upgrade after asynchronous lock releaseupgrades an accepted restart when an update arrives during %s, close/lock release. Original platform/process-ownership inputs retained; both now assert exact persisted update handoff.does not start a replaced runtime after awaited beginBootdoes not resume a replaced runtime during $phase (pending Stop: $pendingStop), beginBoot/false. Original error input and assertions retained.joins graceful shutdown on host EOF without consuming restart intent;stops a closing restart when the host lifeline closesjoins host EOF shutdown (closing restart=%s), false/true. Real stream EOF, close join and no successor retained.reports failure when foreground provider service cleanup times out after server close;preserves a recorded close failure when launchd final cleanup crosses the deadlinereports $supervisor cleanup timeout after server close (close failed=$closeFails), foreground/false and launchd/true. Exact timing and failure diagnostic retained.retains the restart deadline when a managed update arrives after final cleanup fails;retains $signal deadlines when $failure throws after server closeretains $signal deadlines after $failure throws (managed update=$managedUpdate), all three original rows. Exact thrown error types, update owner, cancellation, deadline and watchdog behavior retained.retains pending foreground completion until Stop retries the captured settlement;retries the captured foreground Stop operation after %s settlementretries the captured foreground Stop operation after %s settlement, pending-completion/false/reject. Original completion, cancellation and settlement inputs retained.falls back in-process when a launchd update handoff fails to spawn;keeps running when an external update restart handoff cannot be persistedfalls back in-process when $name, both original platform/failure inputs, second start and failure sentinel retained.run-loop-shutdown-budget.test.tsretains log-format coverage.bounds the file-log flush before a $signal exitnow additionally asserts no exit at timeout minus 1, followed by exact exit at timeout.preserves a real foreground successor after shared readiness reports still-startingstill requires the real child to acknowledge opening its TCP listener after parent exit, then remain alive.does not start a second active-work drain for repeated shutdown signalsstill proves exactly one held drain and closed admission.No complete behavioral case deleted. Both #83131 tests remain unchanged, and #165670 real connection-work diagnostics and #165980 authorization/supervisor tables remain covered.
Why the remaining large blocks cannot safely meet 35%
The single
runGatewayLoopdescribe delegates these families:Evidence
Provider:
blacksmith-testbox; profile:openclaw-check; final lease:tbx_01m484jqqdn4dy8nf2t85frf44; final head:bc5fbf34cd2019fa7df97a52f11e59e60127ee01. The final corrected test bytes were validated on the lease before committing, and all nine file hashes match the commit. The lease is stopped.pnpm test src/cli/gateway-cli/run-loop.test.ts --maxWorkers=1: 167/167 passed in all seven final runs (one cold baseline conditioning run, then three warm pairs). Same lease, dependency tree and production source; each baseline restores the original test bytes and each candidate restores the committed test bytes. All touched source hashes were printed before running.Median wall time decreased 3.64s (4.5%); mean decreased from 79.31s to 77.92s. Runner variation is substantial, so this establishes no measured median cost increase, not a reliable performance speedup. The cold conditioning run was 118.00s and is excluded. Real SQLite/package/helper-process and listener coverage accounts for the seconds-long integration cases; mocks cannot replace those contracts.
node scripts/run-vitest.mjs src/cli/gateway-cli/run-loop.launchd.test.ts src/cli/gateway-cli/lifecycle-import-boundary.test.ts --maxWorkers=1: 2 files / 7 tests passed (9.98s Vitest duration). These are the other importers of the unchanged shared harness.Three mutation probes each failed the corresponding consolidated rows, with the original production file restored byte-for-byte in
finallyafter each probe:clears the SIGUSR2 token before applying external restart policy (allowed: false)recovers only after a definitive native stop refusal (refused)upgrades an accepted restart when an update arrives during closeand… during lock releasefull-processinstead ofupdate-process.Each probe used
pnpm test src/cli/gateway-cli/run-loop.test.ts --maxWorkers=1 -t <case name>on the same lease. All full unfiltered runs passed 167 cases.Changed-gate gap:
node scripts/check-changed.mjspassed its preceding guards, formatting, core graph boundary and CLI test typecheck, then failed the full-tree dead-export scan on two findings outside the PR:extensions/voice-call/src/webhook/realtime-call-session-control.ts: unused exportOUTBOUND_GREETING_FALLBACK_MS(the constant is still used internally).src/agents/model-catalog.runtime.ts: unusedloadManifestModelCatalogre-export (the underlying implementation has real consumers throughmodel-catalog.ts).Baseline proof on the same lease restored all nine original test files from parent
0fdc8ac2734c12af89b0d8a29e424bf7e7110030, rannode --import ./scripts/tsx.mjs scripts/check-deadcode-exports.mts, and reproduced both exact findings with exit 1. No production changes were made to address them.The first CI run caught two attributable static errors: an unused fixture binding and a timer Promise executor's implicit return. Both are fixed in the final commit, reviewed again (scoped-clean, no actionable P0–P2 findings), and verified with the same nine-file
node scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.core.json <files>command: zero warnings/errors. The complete 167-case suite passed again on the corrected bytes (104.52s wall including fresh compiler preparation). These two lint corrections preserve behavior; the warm measurements above are from the preceding semantically identical test version.The main consolidation also received independent scoped-clean autoreview. Scoped oxfmt and
git diff --checkpassed; no local tests, typechecks or builds ran.Earlier lease
tbx_01m4839xvpk5ae2bv14rvckfc1also passed baseline and initial consolidated suites (167 cases each). A subsequent file sync timed out before tests; that lease was stopped. Queued replacementtbx_01m484221t3h9g4q5q37d3jp51was stopped when the branch head changed. No failed test result was retried to obtain green.Exact-head CI: run 37438434099, SUCCESS for
bc5fbf34cd2019fa7df97a52f11e59e60127ee01; all PR checks are complete and passing, includingopenclaw/ci-gate. Previous run 37436125142 passed every test job and failed only the two static issues corrected above (plus its aggregate CI gate). Do not merge or enable auto-merge.Successful final Node test jobs consumed 972 aggregate job-wall seconds (includes setup and the CI-selected sibling scope):
checks-node-compact-small-2106s,checks-node-changed-1194s,checks-node-changed-2133s,checks-node-compact-small-1210s,checks-node-changed-4106s,checks-node-changed-3149s,checks-node-changed-boundary74s.