Skip to content

Restore weakened reducer assertions and add maker runtime tests (fixes #222)#231

Merged
wjllance merged 1 commit into
mainfrom
fix-222-runtime-tests
Jul 13, 2026
Merged

Restore weakened reducer assertions and add maker runtime tests (fixes #222)#231
wjllance merged 1 commit into
mainfrom
fix-222-runtime-tests

Conversation

@wjllance

Copy link
Copy Markdown
Owner

Summary

Issue #222 flagged two gaps: commit ed849a2 (moving the reducer into core) silently weakened the reducer's test assertions, and the ~1500-line run_maker event loop has zero test coverage. This PR is test-only — no production behavior changes.

Restored the four assertions weakened by ed849a2 in crates/standx-maker/src/runtime.rs:

  • critical_events_abort_stale_work_and_clean_up now asserts the phase enters Frozen.
  • recovery_reconnects_only_after_cleanup now asserts the phase returns to Ready after RecoverySucceeded.
  • unmatched_response_overflow_fails_closed now asserts benign pushes under the threshold return empty and that a Cleanup effect is emitted on overflow.
  • coalesced_timer_replans_after_current_work re-adds the deleted assertion that MarketChanged merges (returns empty) while work is in flight.

Coverage added

New #[cfg(test)] module in crates/standx-cli/src/commands/maker/runtime.rs exercising the testable seams of run_maker:

  • apply_order_response: accepted placement stays pending, rejected placement is removed, unmatched / missing request_id reported as unmatched.
  • apply_order_responses: benign matched acks do not grow the unmatched buffer (no fail-closed freeze); a later matched ack clears a prior unmatched buffer entry.
  • apply_account_events: position mismatch recorded with correct sign (buy positive, sell negative); buffered events applied in FIFO order (last position wins); benign Connected/TradeShadow drained without fills; updates for other symbols ignored.

Still uncovered

The run_maker async event loop itself (select over timers, market feed, account/order-response streams, cycle execution, cleanup/reconnect orchestration) is not driven end-to-end here — that would require a large mock-driven integration harness and architectural change, which #222 explicitly scoped out. Coverage was added by testing the already-extracted pure/synchronous seams rather than refactoring the loop. No new helper extraction was needed. Remaining uncovered surface: the top-level select loop, snapshot/cycle pipeline wiring, and stream reconnect/backfill glue.

Test plan

  • cargo fmt -- --check — clean
  • cargo clippy --workspace --all-targets -- -D warnings — clean
  • cargo test -p standx-maker — 54 passing (4 restored reducer tests included)
  • cargo test -p standx-cli — passing (8 new runtime seam tests included)

Fixes #222

🤖 Generated with Claude Code

Restores the reducer phase/effect assertions that ed849a2 dropped and adds
synchronous-seam tests for the maker runtime loop (apply_order_response,
apply_order_responses, apply_account_events).

Rebased onto main after #218/#219/#220/#221 merged. The overflow test now
uses the cycle-carrying OrderResponseUnmatched variant introduced by #218
while keeping the restored sub-threshold-empty + Cleanup-effect assertions.

Also repairs a latent build break on main: #219 added an equity/margin
`notifier.alert(&alert, &symbol)` call while #221 changed `alert()` to take
an `await_delivery` argument; the two were green independently but do not
compile together. Updated that call site to the 3-arg form.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@wjllance wjllance force-pushed the fix-222-runtime-tests branch from ec601b3 to cf9c1d7 Compare July 13, 2026 08:08
@wjllance wjllance merged commit 7ab0353 into main Jul 13, 2026
7 checks passed
@wjllance wjllance deleted the fix-222-runtime-tests branch July 13, 2026 08:13
wjllance pushed a commit that referenced this pull request Jul 13, 2026
systemd + launchd units for the maker and uploader with Restart=on-failure,
an OnFailure notify path, and a distinct fail-safe exit code (75) so an
intentional safe shutdown is never auto-restarted (only notified). Wrapper
now supervises and relaunches the uploader; a boot/crash catch-up re-uploads
any un-ingested log tail.

Rebased onto main after #218-#221 merged. Merged the commands re-export with
#220's panic_webhook_body. Also repairs the same latent main build break that
#231 fixes: #219's equity/margin `notifier.alert(&alert, &symbol)` call did
not update to the 3-arg `await_delivery` form #221 introduced; corrected here
too so this branch compiles standalone.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
wjllance pushed a commit that referenced this pull request Jul 13, 2026
systemd + launchd units for the maker and uploader with Restart=on-failure,
an OnFailure notify path, and a distinct fail-safe exit code (75) so an
intentional safe shutdown is never auto-restarted (only notified). Wrapper
now supervises and relaunches the uploader; a boot/crash catch-up re-uploads
any un-ingested log tail.

Rebased onto main after #218-#221 merged. Merged the commands re-export with
#220's panic_webhook_body. Also repairs the same latent main build break that
#231 fixes: #219's equity/margin `notifier.alert(&alert, &symbol)` call did
not update to the 3-arg `await_delivery` form #221 introduced; corrected here
too so this branch compiles standalone.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.

[P1][Test] runtime 事件循环 ~1500 行零测试;ed849a2 削弱的 reducer 断言待恢复

2 participants