Skip to content

test(core): share session fixtures and replace test-only hooks with three seams - #528

Merged
lg2m merged 66 commits into
mainfrom
test/shared-fixtures
Nov 1, 2026
Merged

lg2m merged 66 commits into
mainfrom
test/shared-fixtures

Conversation

@lg2m

@lg2m lg2m commented Nov 1, 2026

Copy link
Copy Markdown
Collaborator

Stacked on #525 (now merged, so this targets main).

Change

This is a test refactor with no behavior change. It covers findings E1, E2 and E5 from the test audit. The tests are the same and assert the same things, in about 4,800 fewer lines. Production behavior does not change.

E1: three seams instead of 16 ad-hoc statics

  • sessions/probe.rs adds one RuntimeProbe, a Checkpoint enum with hold/observe/hold_reporting_run. It replaces the 11 hold/observe registries plus hold_result: cancellation read, outcome read, child creation, failing reserved start, child delivery, child receipt, parent wait, execution stop, buffered tool output, drop settlement, summary admission ack, and goal-check result.
  • StoreFaults replaces fail_cancellation_reads, fail_reserved_settlements, fail_reserved_reloads and fail_child_cancellation.
  • In non-test builds both are zero-sized and every call inlines to nothing, so production call sites carry no #[cfg(test)].
  • The stats snapshot SessionRuntime::stats() returns StoreStats { catch_up_reads, retained_feeds }. hold_control_capacity and the other test-only Store methods move to store/test_api.rs.
  • The scheduling seam SessionRuntime::hold_scheduling() replaces 22 hand-rolled inner.permits acquisitions. Alongside it are idle_run_permits(), has_failed() and store(), in sessions/runtime/test_api.rs.
  • RunResources::for_run replaces the #[cfg(test)] run_id field and the for_test_run builder.
  • #[cfg(test)] blocks in non-test sessions files went from 116 to 36. The remaining ones are mod tests blocks, test-only uses, the paused-clock hook in store/worker.rs, codec::TEST_EPOCH, and waiting_for_test, which is part of the SubagentSpawner trait outside sessions. Hook-registry Mutex statics went from 16 to 0.

E2: shared builders in sessions/tests/fixtures.rs, which the file-split PR can import as is.

  • SessionFixture: open, open_with, open_at and open_in. Each one opens the runtime, resolves the workspace, creates the session and subscribes.
  • ProviderLoader, with pricing, route, max-output and context-window options, plus load_provider, load_error and test_pricing.
  • Provider script helpers: provider_script, text_reply, text_delta, completed, tool_call and provider_usage.
  • Prompt with submit, try_submit and store_command.
  • set_goal, goal_command, goal_control and identity_of.
  • The TurnCommit builder for ModelTurnCommit.
  • new_session, store_session, subscribe_after and cancel_run.
  • The seven harness structs (ScriptedRunsHarness, ApprovalHarness, SessionManagementHarness, AutoCompactHarness, SpawnHarness, OutputContractHarness and BudgetHarness) plus DeadlineSession are now SessionFixture. ApprovalHarness and SessionManagementHarness keep their one extra field through Deref.
  • In tools.rs tests, run_shell_tool and a new shell_tool replace nine 9-argument shell execute calls. StaticPolicyGate::fixed(mode) replaces 28 struct literals in lib.rs, tests/progress.rs and sessions/tests/goals.rs.
  • crate::test_support::run_worker replaces 6 hand-rolled self-re-exec workers. The orphan-server worker in shell.rs spawns rather than waits, and the soak worker is async, so both stay.

E5: .inner. reach-ins in sessions tests went from 384 to 65. Most now go through runtime.store(), store_id(), request_schedule() and the seams above. The remaining ones reach side-question permits, failed/shutdown watches, cancel/notify, child permit pools and Arc::clone(&runtime.inner) for compactor construction. None of those was cheap to move.

Measured literal counts in the sessions tests, base → head:

  • SubmitPrompt {: 158 → 23
  • "set_goal": 87 → 5
  • CommandOutcome::SessionCreated: 174 → 68
  • SessionRuntime::open(: 170 → 121
  • map_err(|error| RuntimeLoadError: 51 → 0
  • ModelTurnCommit {: 31 → 4
  • SnapshotRequest {: 68 → 5
  • .inner: 384 → 65

Hooks left in place, with reasons:

  • worker::hold_paused_clock. It changes job settlement under a paused current-thread runtime rather than pausing at a checkpoint.
  • codec::TEST_EPOCH. It is the clock seam from test(core): drive session wall time and deadlines from one clock #521.
  • waiting_for_test. It is a SubagentSpawner trait method in runtime/, which is outside sessions.
  • The crate::tools/crate::workspace hooks (hold_shell_receipt, hold_tool_apply, pause_blocking_preparation and the others). They are outside sessions production code and out of scope.

No findings were skipped. No tests were deleted or renamed.

Verification

  • cargo nextest run -p qq-core: 1357 run and 2 skipped on the base (origin/main cf07b60). The same 1357 run and 2 skipped on the head. The cargo nextest list name sets are identical (1359 names).
  • cargo xtask check passed on 0adbc12: fmt, lint (11/11 test sleeps), clippy -D warnings, and 2362/2362 tests across qq, qq-client, qq-core, qq-host, qq-server, qq-tui and xtask.
  • I stressed every test whose synchronization moved onto PROBE, FAULTS, hold_outcome_read or hold_scheduling. That is 53 tests. Each ran 50 iterations with the taskset loaded-core recipe (three spinners and nextest on core 0, --profile ci --retries 0): 50/50 and 50/50 in two halves.
  • The first stress pass caught one regression in my own change. The first hold_scheduling took every available permit. Under load, a run that had already been admitted could still hold one, so side_answer_bypasses_the_main_permit… and detached_child_refreshes_ancestor_budget… failed 5 of 50. The base passes those 50/50 under the same load. hold_scheduling now waits for exactly max_active_runs, which is what the original single-permit acquire() waited for. After the fix both tests pass 50/50, and so does the full set of 53.
  • xtask/src/legacy-sleeps.txt only moves the same 11 sleeps to their new line numbers.

Known impact

None for users. In test builds, RuntimeProbe and StoreFaults are process-global, as the old statics were. They are keyed by run, session or tool-call id, so tests running in parallel do not interfere.

lg2m added 30 commits November 1, 2026 02:29
…ne nextest profile

Tests use one thread per CPU; real-process tests share a two-thread group so
their exit confirmation is not starved, and only the ~15 slowest tests get
priority. Soak tests form a group the pull-request gate leaves out and
`cargo xtask check --full` runs.

The hand-picked test-exact steps become a nextest `platform` profile whose
selection CI diffs against .config/platform-tests/<os>.txt; the two Windows
jobs merge into one. `cargo xtask lint` requires every Windows- or
macOS-only test to be listed.

Adds a 14-day quarantine list with a lint, a gate exclusion and a
non-blocking stress job, starting empty. The devcontainer job runs only when
its inputs change or off pull requests; the minimal core profile runs as its
own job.
…stead of migrating them

Schema 25 shipped in v0.0.1. Steps 1-24 only served unreleased builds, so
they go together with their tests, and opening an older store now fails with
SessionRuntimeError::UnsupportedStoreSchema.
Seeds at unreleased schemas (27, 29-31, 40-42, 45-49, 51-57, 60-63) move to
the nearest released schema below them (26, 28, 39, 43, 50, 58). Tests whose
seeded state never existed in a released store (goal rows before 58, the
experimental 48 notice build) are deleted.
With an active goal the scheduler queues a goal-origin run as soon as the
goal is set. Under load it was claimed before the fixture's prompt, so the
report counted the prompt's tool events (zero) while the goal run did the
work. The fixture now follows the queued goal run, with a per-run turn cap
that fits the scripted workload.
One checked goal now covers the real kills, waits, outages, interleaved
prompts, achievement through the check, and then a replacement goal that
runs out its deadline, which the unchecked soak used to prove.
The perf run keeps its 560 paced 1 KiB chunks. The test streams 8 KiB
chunks with no pause, which still commits over 512 events, the gate it
checks. The captured-output timeout test waits 100 ms instead of 1 s.
The in-run compaction scripts spawned about 640 shells only to produce
6 KB results. A test tool now returns the same stored bytes (the bounded
2,051-byte shell result), so every test compacts exactly as many times as
before. The verbatim-goal test runs 30 turns instead of 72, which still
compacts five times per row.
A 5 s limit made each case wait 5 s. On one loaded core the run needs
about 520 ms to reach the hung summarizer (22 ms unloaded), so 500 ms
failed under stress while 2 s passed 40 of 40.
Each run reads three 90 KiB notes instead of one, so the window-less
session crosses the point where stale reads must be shed after about 40
runs instead of 140. The assertions are unchanged.
@lg2m lg2m added the ci:full label Nov 1, 2026
@lg2m

lg2m commented Nov 1, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-01T21:34:33.045682Z 4505de4 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Delightful!

Reviewed commit: 4505de465a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@lg2m
lg2m enabled auto-merge November 1, 2026 21:42
@lg2m
lg2m added this pull request to the merge queue Nov 1, 2026
Merged via the queue into main with commit 6949e82 Nov 1, 2026
14 checks passed
@lg2m
lg2m deleted the test/shared-fixtures branch November 1, 2026 21:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant