Skip to main content

trusty_code/
verify_gate.rs

1//! Verify-before-finish gate (#2279): a recoverable retry, not a hard block,
2//! that keeps a coding agent from calling `finish_task` before it has run a
3//! test suite it was explicitly told about.
4//!
5//! Why: (bake-off L2 diagnosis) tcode's delegated engineer authored 81 tests
6//! validating the wrong contract and never ran the visible, prompt-named
7//! test suite the L2 challenge instructed it to run before submitting. The
8//! task prompt and `challenges/README.md` (folded into project context)
9//! named a runnable test command (`pytest challenges/level-2-git-analyzer/
10//! test_suite/ -v`); the transcript never shows it being invoked. This
11//! module is the structural fix: at the `finish_task` turn boundary
12//! (`agent_loop::AgentLoop::dispatch_all`), if the task/project-context text
13//! names a runnable test command AND no matching `bash` invocation appears
14//! in the relevant transcript, `finish_task` is rejected with a recoverable
15//! error — the SAME `ToolResult::err` retry path every other tool failure
16//! uses — instead of terminating the loop. If no test command is named at
17//! all, the gate is INERT: #2279 explicitly defers general polyglot
18//! test-suite discovery (the "(b2)" follow-up) rather than inventing one
19//! here.
20//! What: [`names_test_command`] and [`is_test_command`] are pure,
21//! independently unit-testable regex predicates — Improvement 2's own
22//! testability principle applied to its sibling Improvement 1. Two
23//! `agent_loop::FinishGate` constructors build on them: [`default_finish_gate`]
24//! scans a single loop's OWN `Transcript` — what a delegated engineer's
25//! sub-agent loop attaches (`runner::in_process::InProcessAgentRunner`),
26//! since its own `bash` calls land directly in that transcript.
27//! [`pm_finish_gate`] is for the delegating PM's loop, which never calls
28//! `bash` itself — it scans the externally shared `run_task::SharedTranscript`
29//! of `TurnRecord`s the delegated engineer's turns are recorded into
30//! instead, via each record's `ran_test_command` flag (set by
31//! `run_task::recorder::RecordingLlmClient` using the SAME [`is_test_command`]
32//! predicate this module owns, so the two paths can never independently
33//! drift on what counts as a matching invocation).
34//! Test: `verify_gate::tests::*`.
35//!
36//! [`names_test_command`]: crate::verify_gate::names_test_command
37//! [`is_test_command`]: crate::verify_gate::is_test_command
38//! [`default_finish_gate`]: crate::verify_gate::default_finish_gate
39//! [`pm_finish_gate`]: crate::verify_gate::pm_finish_gate
40
41use std::sync::Arc;
42
43use regex::Regex;
44use serde_json::Value;
45
46use crate::agent_loop::{FinishGate, Transcript};
47use crate::llm::{ChatMessage, ToolCall};
48use crate::run_task::SharedTranscript;
49use crate::tools::BASH_TOOL_NAME;
50
51/// Recoverable-retry message fed back to a delegated engineer's own loop
52/// when its `finish_task` call is rejected.
53const GATE_REASON_ENGINEER: &str = "finish_task rejected: the task prompt or project context \
54names a runnable test command (a pytest/cargo/npm/pnpm/go test invocation), but no matching \
55command has been run yet in this session. Run the named test suite via the bash tool, \
56reconcile any failures, and only then call finish_task again.";
57
58/// Recoverable-retry message fed back to the delegating PM's own loop when
59/// its `finish_task` call is rejected because the delegated engineer never
60/// ran the named tests.
61const GATE_REASON_PM: &str = "finish_task rejected: the task prompt or project context names a \
62runnable test command (a pytest/cargo/npm/pnpm/go test invocation), but the delegated \
63engineer's transcript shows no matching invocation yet. Delegate a follow-up task instructing \
64the engineer to run the named test suite and reconcile any failures before finishing.";
65
66/// Build the regex alternation matching the six test-invocation shapes named
67/// in #2279's finalized trigger heuristic.
68///
69/// Why: A single compiled pattern, rather than six separate `Regex`es, keeps
70/// [`names_test_command`] and [`is_test_command`] identical in shape — "does
71/// this text contain a recognizable test-command invocation" — the only
72/// difference between the two call sites is WHICH text they scan. Compiled
73/// fresh per call rather than cached in a `once_cell`/`lazy_static` global
74/// (project convention reserves those for the tracing subscriber only); this
75/// is not a hot path — at most once per `finish_task` dispatch attempt, or
76/// once per recorded turn — so the recompilation cost is immaterial next to
77/// the LLM round-trip it sits beside.
78/// What: `pytest\s+\S+` (a pytest invocation naming a path/module),
79/// `cargo test`, `npm test`, `pnpm test`, `go test`, `python -m pytest` —
80/// exactly the six patterns #2279's finalized decision comment named.
81/// Test: covered indirectly by every `tests::*` case below.
82fn test_command_pattern() -> Regex {
83    Regex::new(
84        r"(?:pytest\s+\S+)|(?:cargo\s+test)|(?:npm\s+test)|(?:pnpm\s+test)|(?:go\s+test)|(?:python\s+-m\s+pytest)",
85    )
86    .expect("test_command_pattern: hardcoded regex literal must compile")
87}
88
89/// Whether `text` textually names a runnable test command (the gate's
90/// TRIGGER half).
91///
92/// Why: The gate must stay inert when nothing in the task/project context
93/// ever asked for a specific test command.
94/// What: `true` iff [`test_command_pattern`] finds a match anywhere in
95/// `text`.
96/// Test: `tests::names_test_command_detects_each_pattern`,
97/// `tests::names_test_command_false_on_unrelated_text`.
98pub fn names_test_command(text: &str) -> bool {
99    test_command_pattern().is_match(text)
100}
101
102/// Whether `command` (a `bash` tool call's shell command) IS a matching test
103/// invocation (the gate's VERIFY half).
104///
105/// Why: Reused by both [`default_finish_gate`]'s own-transcript scan and
106/// `run_task::recorder`'s per-turn `ran_test_command` signal, so the two
107/// gate sites can never independently drift on what counts as "the named
108/// tests actually ran".
109/// What: Same predicate as [`names_test_command`], applied to a single
110/// command string rather than free-form prose.
111/// Test: `tests::is_test_command_matches_each_pattern`,
112/// `tests::is_test_command_false_on_unrelated_command`.
113pub fn is_test_command(command: &str) -> bool {
114    test_command_pattern().is_match(command)
115}
116
117/// Extract the shell command from a `bash` tool call's arguments, if `call`
118/// names the `bash` tool at all.
119///
120/// Why: Shared by [`default_finish_gate`]'s own-transcript scan and
121/// `run_task::recorder::RecordingLlmClient`'s per-turn signal, so the two
122/// gate sites parse the SAME wire shape (`{"command": "..."}`) identically.
123/// What: `None` when `call.function.name != BASH_TOOL_NAME` or the
124/// arguments do not parse as a JSON object with a string `command` field.
125/// Test: `tests::bash_command_from_call_extracts_command`,
126/// `tests::bash_command_from_call_ignores_other_tools`.
127pub fn bash_command_from_call(call: &ToolCall) -> Option<String> {
128    if call.function.name != BASH_TOOL_NAME {
129        return None;
130    }
131    let parsed: Value = serde_json::from_str(&call.function.arguments).ok()?;
132    parsed.get("command")?.as_str().map(str::to_string)
133}
134
135/// Whether any `bash` call in `messages` invoked a matching test command.
136///
137/// Why: The core predicate [`default_finish_gate`] applies to a delegated
138/// engineer's own `Transcript` — factored out as a free function so it is
139/// independently unit-testable against a plain `&[ChatMessage]` without
140/// constructing a full `Transcript`.
141/// What: Flattens every assistant turn's `tool_calls`, extracts each `bash`
142/// call's command via [`bash_command_from_call`], and checks
143/// [`is_test_command`].
144/// Test: `tests::transcript_ran_test_command_detects_match`,
145/// `tests::transcript_ran_test_command_false_without_bash`.
146fn transcript_ran_test_command(messages: &[ChatMessage]) -> bool {
147    messages
148        .iter()
149        .filter_map(|m| m.tool_calls.as_ref())
150        .flatten()
151        .filter_map(bash_command_from_call)
152        .any(|cmd| is_test_command(&cmd))
153}
154
155/// Join the seeded `system` + `user` message text into one haystack for
156/// [`names_test_command`].
157///
158/// Why: `Transcript::seed` is the ONLY place raw history ever gets a
159/// `system`- or `user`-role entry, and it seeds exactly one of each — the
160/// assembled system prompt (BASE + agent prompt + project `CLAUDE.md`
161/// context) and the task text. Scanning by role (not position) stays
162/// correct even if `Transcript`'s internal layout ever changes.
163/// What: Concatenates the `content` of every `system`/`user` entry with
164/// newlines.
165/// Test: `tests::seed_text_joins_system_and_user`.
166fn seed_text(messages: &[ChatMessage]) -> String {
167    messages
168        .iter()
169        .filter(|m| m.role == "system" || m.role == "user")
170        .filter_map(|m| m.content.as_deref())
171        .collect::<Vec<_>>()
172        .join("\n")
173}
174
175/// Build the default verify-before-finish gate: scans the SAME loop's own
176/// transcript for both the trigger and the verification.
177///
178/// Why: This is the shape a delegated engineer's sub-agent loop needs — its
179/// own `bash` calls land directly in its own `Transcript`, so no external
180/// state is required.
181/// What: Returns a [`FinishGate`] closure that is inert unless
182/// [`seed_text`] of the transcript [`names_test_command`]; when it does,
183/// trips (returning [`GATE_REASON_ENGINEER`]) unless
184/// [`transcript_ran_test_command`] finds a match.
185/// Test: `tests::default_gate_trips_when_named_and_unrun`,
186/// `tests::default_gate_inert_when_not_named`,
187/// `tests::default_gate_satisfied_when_run`,
188/// `agent_loop::tests::finish_gate_trips_and_recovers`.
189pub fn default_finish_gate() -> FinishGate {
190    Arc::new(|transcript: &Transcript| {
191        let messages = transcript.messages();
192        if !names_test_command(&seed_text(&messages)) {
193            return None;
194        }
195        if transcript_ran_test_command(&messages) {
196            return None;
197        }
198        Some(GATE_REASON_ENGINEER.to_string())
199    })
200}
201
202/// Build the delegating PM's verify-before-finish gate: the trigger comes
203/// from the PM's own transcript, but the verification scans the externally
204/// shared engineer transcript instead.
205///
206/// Why: The PM's own tool registry never includes `bash` (`run_task::
207/// execute_run_task` registers only `delegate_to_agent` and `finish_task`),
208/// so scanning the PM's own `Transcript` for a `bash` call would ALWAYS
209/// report "not run" — wrongly tripping the gate even when the delegated
210/// engineer ran the named tests correctly. `shared` is the SAME
211/// `run_task::SharedTranscript` the engineer's `RecordingLlmClient` records
212/// into, so this closure sees the engineer's turns too.
213/// What: Returns a [`FinishGate`] closure inert unless the PM transcript's
214/// [`seed_text`] [`names_test_command`]; when it does, trips (returning
215/// [`GATE_REASON_PM`]) unless any `TurnRecord` in `shared` has
216/// `ran_test_command == true`. A poisoned lock is treated as "not run" —
217/// fail toward asking the model to verify, not toward silently finishing —
218/// and (#2857) logs `tracing::warn!` when this happens, since a poisoned
219/// lock means some other turn's code already panicked; silently folding
220/// that into an ordinary gate trip would hide the real failure.
221/// Test: `tests::pm_gate_trips_when_engineer_never_ran_tests`,
222/// `tests::pm_gate_satisfied_when_engineer_ran_tests`,
223/// `tests::pm_gate_inert_when_not_named`,
224/// `tests::pm_gate_poisoned_lock_warns_and_trips`.
225pub fn pm_finish_gate(shared: SharedTranscript) -> FinishGate {
226    Arc::new(move |transcript: &Transcript| {
227        let messages = transcript.messages();
228        if !names_test_command(&seed_text(&messages)) {
229            return None;
230        }
231        // (#2857) A poisoned lock (some other turn's code panicked while
232        // holding it) is treated as "tests not run" — fail toward asking the
233        // model to verify, per this function's own doc. That fallback is
234        // itself a decision worth surfacing: silently swallowing the
235        // poisoning would hide a real prior panic behind an ordinary-looking
236        // gate trip.
237        let ran = shared
238            .lock()
239            .map(|turns| turns.iter().any(|t| t.ran_test_command))
240            .unwrap_or_else(|_| {
241                tracing::warn!(
242                    "verify_gate: shared transcript lock poisoned (a prior turn likely \
243                     panicked) — treating as tests-not-run and tripping the PM finish gate"
244                );
245                false
246            });
247        if ran {
248            return None;
249        }
250        Some(GATE_REASON_PM.to_string())
251    })
252}
253
254// ── Tests ─────────────────────────────────────────────────────────────────────
255
256#[cfg(test)]
257mod tests {
258    use std::sync::Mutex;
259
260    use super::*;
261    use crate::llm::FunctionCall;
262    use crate::run_task::TurnRecord;
263
264    fn bash_call(id: &str, command: &str) -> ToolCall {
265        ToolCall {
266            id: id.into(),
267            kind: "function".into(),
268            function: FunctionCall {
269                name: BASH_TOOL_NAME.into(),
270                arguments: serde_json::json!({"command": command}).to_string(),
271            },
272        }
273    }
274
275    fn assistant_with_tool_calls(calls: Vec<ToolCall>) -> ChatMessage {
276        ChatMessage {
277            role: "assistant".into(),
278            content: None,
279            tool_calls: Some(calls),
280            tool_call_id: None,
281            name: None,
282            cache_control: None,
283        }
284    }
285
286    /// [`names_test_command`] detects each of the six finalized patterns.
287    ///
288    /// Why: Guards the exact pattern set #2279's decision comment named.
289    /// What: One assertion per pattern, embedded in surrounding prose.
290    /// Test: this test.
291    #[test]
292    fn names_test_command_detects_each_pattern() {
293        for text in [
294            "please run pytest tests/test_basic.py -v before submitting",
295            "then run cargo test",
296            "run npm test after building",
297            "use pnpm test to check",
298            "run go test ./... first",
299            "invoke python -m pytest as the final step",
300        ] {
301            assert!(names_test_command(text), "expected a match in {text:?}");
302        }
303    }
304
305    /// [`names_test_command`] is `false` on prose naming no test command.
306    ///
307    /// Why: The gate must stay inert for ordinary tasks that never mention a
308    /// runnable test suite.
309    /// What: Free-form task text with no recognizable pattern.
310    /// Test: this test.
311    #[test]
312    fn names_test_command_false_on_unrelated_text() {
313        assert!(!names_test_command(
314            "implement a git log parser and make sure it builds cleanly"
315        ));
316    }
317
318    /// [`is_test_command`] matches each pattern as a standalone command
319    /// string (not embedded in prose).
320    ///
321    /// Why: This is the shape a `bash` tool call's `command` argument
322    /// actually takes.
323    /// What: One assertion per pattern.
324    /// Test: this test.
325    #[test]
326    fn is_test_command_matches_each_pattern() {
327        for cmd in [
328            "pytest challenges/level-2-git-analyzer/test_suite/ -v",
329            "cargo test -p trusty-code",
330            "npm test",
331            "pnpm test --run",
332            "go test ./...",
333            "python -m pytest -x",
334        ] {
335            assert!(is_test_command(cmd), "expected a match in {cmd:?}");
336        }
337    }
338
339    /// [`is_test_command`] is `false` on an unrelated shell command.
340    ///
341    /// Why: Ordinary bash calls (`ls`, `git status`, a build command) must
342    /// not be mistaken for a test invocation.
343    /// What: A handful of common non-test commands.
344    /// Test: this test.
345    #[test]
346    fn is_test_command_false_on_unrelated_command() {
347        for cmd in ["ls -la", "git status", "cargo build --release", "echo ok"] {
348            assert!(!is_test_command(cmd), "unexpected match in {cmd:?}");
349        }
350    }
351
352    /// [`bash_command_from_call`] extracts the command from a real `bash`
353    /// call's JSON arguments.
354    ///
355    /// Why: This is the exact wire shape `BashTool::schema` declares.
356    /// What: Build a `bash` call, assert the extracted command.
357    /// Test: this test.
358    #[test]
359    fn bash_command_from_call_extracts_command() {
360        let call = bash_call("c1", "cargo test -p trusty-code");
361        assert_eq!(
362            bash_command_from_call(&call).as_deref(),
363            Some("cargo test -p trusty-code")
364        );
365    }
366
367    /// [`bash_command_from_call`] returns `None` for a non-`bash` tool call.
368    ///
369    /// Why: The gate must only ever consider `bash` calls a test invocation
370    /// — a `write_file` or `delegate_to_agent` call must never match.
371    /// What: A `write_file`-named call with an unrelated argument shape.
372    /// Test: this test.
373    #[test]
374    fn bash_command_from_call_ignores_other_tools() {
375        let call = ToolCall {
376            id: "c1".into(),
377            kind: "function".into(),
378            function: FunctionCall {
379                name: "write_file".into(),
380                arguments: serde_json::json!({"path": "x", "content": "y"}).to_string(),
381            },
382        };
383        assert_eq!(bash_command_from_call(&call), None);
384    }
385
386    /// [`seed_text`] joins the `system` and `user` entries, skipping any
387    /// `assistant`/`tool` entries in between.
388    ///
389    /// Why: The trigger check must only ever consider the ORIGINAL task
390    /// prompt/project context, never text that later shows up in tool
391    /// output.
392    /// What: Build a small message list; assert the join.
393    /// Test: this test.
394    #[test]
395    fn seed_text_joins_system_and_user() {
396        let messages = vec![
397            ChatMessage::system("SYSTEM_TEXT"),
398            ChatMessage::user("USER_TEXT"),
399            ChatMessage {
400                role: "assistant".into(),
401                content: Some("mentions cargo test in passing".into()),
402                tool_calls: None,
403                tool_call_id: None,
404                name: None,
405                cache_control: None,
406            },
407        ];
408        let joined = seed_text(&messages);
409        assert!(joined.contains("SYSTEM_TEXT"));
410        assert!(joined.contains("USER_TEXT"));
411        assert!(!joined.contains("mentions cargo test"));
412    }
413
414    /// [`transcript_ran_test_command`] finds a match inside an assistant
415    /// turn's `bash` tool calls.
416    ///
417    /// Why: This is the exact shape the engineer's own transcript takes
418    /// after it runs the named suite.
419    /// What: An assistant turn with one matching `bash` call.
420    /// Test: this test.
421    #[test]
422    fn transcript_ran_test_command_detects_match() {
423        let messages = vec![assistant_with_tool_calls(vec![bash_call(
424            "c1",
425            "pytest tests/ -v",
426        )])];
427        assert!(transcript_ran_test_command(&messages));
428    }
429
430    /// [`transcript_ran_test_command`] is `false` when no `bash` call is
431    /// present at all.
432    ///
433    /// Why: Guards the common "nothing ran yet" case.
434    /// What: An empty message list.
435    /// Test: this test.
436    #[test]
437    fn transcript_ran_test_command_false_without_bash() {
438        assert!(!transcript_ran_test_command(&[]));
439    }
440
441    /// [`default_finish_gate`] trips when the task names a test command and
442    /// no matching `bash` call appears in the transcript.
443    ///
444    /// Why: This is the core acceptance behaviour — a `finish_task` call
445    /// must be rejected with a recoverable reason under exactly this
446    /// condition.
447    /// What: Seed a transcript whose task names `pytest`, with no tool
448    /// calls at all; assert the gate returns `Some`.
449    /// Test: this test.
450    #[test]
451    fn default_gate_trips_when_named_and_unrun() {
452        let transcript = Transcript::seed("system prompt", "run pytest tests/ -v before finishing");
453        let gate = default_finish_gate();
454        assert!(gate(&transcript).is_some());
455    }
456
457    /// [`default_finish_gate`] is inert when the task never names a test
458    /// command.
459    ///
460    /// Why: #2279 explicitly defers general polyglot test-suite discovery —
461    /// the gate must not invent a requirement that was never stated.
462    /// What: Seed a transcript with an unrelated task; assert `None`.
463    /// Test: this test.
464    #[test]
465    fn default_gate_inert_when_not_named() {
466        let transcript = Transcript::seed("system prompt", "implement a widget");
467        let gate = default_finish_gate();
468        assert!(gate(&transcript).is_none());
469    }
470
471    /// [`default_finish_gate`] is satisfied once a matching `bash` call has
472    /// been pushed onto the transcript.
473    ///
474    /// Why: Proves the "recover" half of the recoverable-retry contract —
475    /// after the agent runs the named tests, a second gate check must pass.
476    /// What: Seed, push an assistant turn with a matching `bash` call;
477    /// assert `None`.
478    /// Test: this test.
479    #[test]
480    fn default_gate_satisfied_when_run() {
481        let mut transcript = Transcript::seed("system prompt", "run cargo test before finishing");
482        transcript.push_assistant(None, &[bash_call("c1", "cargo test -p trusty-code")]);
483        let gate = default_finish_gate();
484        assert!(gate(&transcript).is_none());
485    }
486
487    /// [`pm_finish_gate`] trips when the PM's task names a test command but
488    /// the shared (engineer) transcript never records a matching invocation.
489    ///
490    /// Why: This is the PM-symmetric half of the acceptance criterion — the
491    /// PM must not be able to `finish_task` while its delegated engineer's
492    /// transcript shows no verification either.
493    /// What: An empty `SharedTranscript`; assert the gate trips.
494    /// Test: this test.
495    #[test]
496    fn pm_gate_trips_when_engineer_never_ran_tests() {
497        let shared: SharedTranscript = Arc::new(Mutex::new(Vec::new()));
498        let transcript = Transcript::seed("pm system prompt", "run pytest tests/ -v");
499        let gate = pm_finish_gate(shared);
500        assert!(gate(&transcript).is_some());
501    }
502
503    /// [`pm_finish_gate`] is satisfied when a `TurnRecord` in the shared
504    /// transcript (recorded from the delegated engineer's own turns) has
505    /// `ran_test_command == true`.
506    ///
507    /// Why: Proves the PM-side gate correctly consults EXTERNAL state
508    /// (the engineer's recorded turns) rather than its own (bash-less)
509    /// transcript.
510    /// What: Seed the shared transcript with one `python-engineer` turn
511    /// carrying `ran_test_command: true`; assert `None`.
512    /// Test: this test.
513    #[test]
514    fn pm_gate_satisfied_when_engineer_ran_tests() {
515        let shared: SharedTranscript = Arc::new(Mutex::new(vec![TurnRecord {
516            role: "python-engineer".into(),
517            model: "test-model".into(),
518            text: String::new(),
519            tool_calls: vec!["bash".into()],
520            ran_test_command: true,
521            usage: crate::perf::TokenUsage::default(),
522        }]));
523        let transcript = Transcript::seed("pm system prompt", "run pytest tests/ -v");
524        let gate = pm_finish_gate(shared);
525        assert!(gate(&transcript).is_none());
526    }
527
528    /// [`pm_finish_gate`] treats a poisoned shared-transcript lock as
529    /// "tests not run" (fail toward verify) AND logs a WARN naming why
530    /// (#2857) — a poisoned lock means some other turn's code already
531    /// panicked, which must not be silently folded into an ordinary gate
532    /// trip.
533    ///
534    /// Why: This is the audited #2857 site: `unwrap_or(false)` previously
535    /// swallowed the poisoning distinction entirely.
536    /// What: Poison `shared`'s mutex by panicking on another thread while
537    /// holding the lock, then call the gate under
538    /// `crate::test_support::begin_capture`; assert the gate still trips
539    /// AND a warning naming "lock poisoned" was captured via
540    /// `captured_at_least`.
541    /// Test: this test.
542    #[test]
543    fn pm_gate_poisoned_lock_warns_and_trips() {
544        let shared: SharedTranscript = Arc::new(Mutex::new(Vec::new()));
545        {
546            let shared = shared.clone();
547            let _ = std::thread::spawn(move || {
548                let _guard = shared.lock().expect("lock for poisoning");
549                panic!("intentional poison for pm_gate_poisoned_lock_warns_and_trips");
550            })
551            .join();
552        }
553        assert!(shared.is_poisoned(), "setup must actually poison the lock");
554
555        crate::test_support::begin_capture();
556
557        let transcript = Transcript::seed("pm system prompt", "run pytest tests/ -v");
558        let gate = pm_finish_gate(shared);
559        let result = gate(&transcript);
560
561        assert!(
562            result.is_some(),
563            "a poisoned lock must still trip the gate (fail toward verify)"
564        );
565        let captured = crate::test_support::captured_at_least(tracing::Level::WARN);
566        assert!(
567            captured.iter().any(|m| m.contains("lock poisoned")),
568            "expected a warn-level poisoned-lock log, got: {captured:?}"
569        );
570    }
571
572    /// [`pm_finish_gate`] is inert when the PM's own task never names a test
573    /// command, regardless of the shared transcript's contents.
574    ///
575    /// Why: Mirrors [`default_gate_inert_when_not_named`] for the PM path.
576    /// What: An unrelated PM task with an empty shared transcript.
577    /// Test: this test.
578    #[test]
579    fn pm_gate_inert_when_not_named() {
580        let shared: SharedTranscript = Arc::new(Mutex::new(Vec::new()));
581        let transcript = Transcript::seed("pm system prompt", "coordinate the widget build");
582        let gate = pm_finish_gate(shared);
583        assert!(gate(&transcript).is_none());
584    }
585}