Skip to content

test(loop): cover run() wiring of gate_result events - #3611

Merged
clabonte merged 1 commit into
mainfrom
fix/issue-3599-run-gate-result-wiring
Nov 26, 2026
Merged

clabonte merged 1 commit into
mainfrom
fix/issue-3599-run-gate-result-wiring

Conversation

@clabonte

Copy link
Copy Markdown
Contributor

Closes #3599.

Root cause

tests/test_gate_timings.py exercises execute_unit_attempt(), build_attempt_gate_events() and build_phase_gate_events() directly. Nothing tested that run() calls them. If a refactor dropped one of the four wiring points, every test would still pass, and specfuse stats would quietly report "not recorded", or stale results from an earlier attempt. The four wiring points:

  • the per-attempt reset of wu.last_gate_results;
  • the attempt gate_result extend;
  • the phase: baseline extend on the retroactive attribution path;
  • the phase: broad extend after the gate's broad run.

Fix

This is a test-only change; no production code changes. tests/test_run_gate_result_wiring.py runs run() end to end on a temporary feature. The agent is stubbed, and the gates are real commands: test ! -f broken.flag and sleep 0.1. The run goes:

  1. Attempt 1 writes the flag, so a gate fails. That failure triggers the retroactive baseline probe.
  2. Attempt 2 bills zero input tokens, so verify() never runs.
  3. Attempt 3 passes.
  4. The close triggers the gate's broad run, then reports itself blocked, which ends the run.

Tests

RunGateResultWiringTest, which has 4 tests, asserts that events.jsonl holds:

  • one phase: attempt gate_result per gate for attempts 1 and 3, with the right attempt numbers, and none for attempt 2;
  • phase: baseline events after the failed attempt;
  • phase: broad events after the broad run.

Red evidence. I removed each wiring point in run() one at a time, then restored it. Each removal fails exactly one test:

Removed Failing test
wu.last_gate_results = [] reset test_attempt_phase_one_per_gate_per_verified_attempt (attempt 2 carries attempt 1's results)
attempt gate_result extend test_attempt_phase_one_per_gate_per_verified_attempt
baseline-phase extend test_baseline_phase_after_failed_attempt
broad-phase extend test_broad_phase_after_broad_run

Verification

🤖 Generated with Claude Code

Closes #3599. tests/test_gate_timings.py drives execute_unit_attempt(),
build_attempt_gate_events() and build_phase_gate_events() directly, so a
refactor that dropped run()'s calls to them would leave every test green while
`specfuse stats` silently reported "not recorded" or stale results.

tests/test_run_gate_result_wiring.py runs run() end to end on a temporary
feature with a stubbed agent and real gate commands: attempt 1 fails a gate
(triggering the retroactive baseline probe), attempt 2 bills zero tokens (no
verify), attempt 3 passes, and the close triggers the broad run. It asserts
events.jsonl holds attempt-phase gate_result events for attempts 1 and 3 only,
baseline-phase events after the failed attempt, and broad-phase events after
the broad run.

Tests:
- tests/test_run_gate_result_wiring.py:RunGateResultWiringTest — 4 tests;
  removing each of the four wiring points in run() fails exactly one of them.

Verification:
- scripts/smoke-test.sh: 5118 tests OK (skipped=4)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@clabonte
clabonte merged commit 45fe7e0 into main Nov 26, 2026
7 checks passed
@clabonte
clabonte deleted the fix/issue-3599-run-gate-result-wiring branch November 26, 2026 14:17
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.

test: cover run() wiring of gate_result events (attempt, baseline and broad phases)

1 participant