1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
//! #8206: project-side detection of a runnable test command, the precondition
//! the #2279 verify-before-finish trigger was missing.
//!
//! Why: [`super::names_test_command`] is a pure text match over the task
//! prompt and project context. On an EMPTY project root — a projectless
//! `tcode tui` run whose work root is a fresh scratch dir (#8205) — a prompt
//! that merely says "run `cargo test`" tripped the gate even though no
//! command could possibly have satisfied it, and the run wedged: the agent
//! was refused, could not comply, and was refused again. This module answers
//! the question the gate should have asked first — "is there anything here a
//! test command could run against?".
//! What: [`detect_test_command`] probes the bound project root for a manifest
//! that implies a specific test command (`Cargo.toml`, a `package.json` with
//! a `test` script, a pytest config, `go.mod`), falling back to the
//! prompt-named command when the root is non-empty but carries no recognised
//! manifest. A missing root, or an empty one, yields an
//! [`UndetectableReason`] instead — the gate turns that into an accepted
//! finish carrying a note, never a refusal.
//! Test: `verify_gate::tests::detect_*`.
use Path;
/// What a runnable test command was detected FROM, for the bound project.
///
/// Why: The refusal message must name the evidence so the agent knows what to
/// run — #8206's second closure condition. Carrying the manifest/command
/// through the detection result is what makes that message specific rather
/// than the pre-#8206 generic "a pytest/cargo/npm/pnpm/go test invocation".
/// What: `Manifest` when a root manifest implies a command; `PromptNamed`
/// when the root is non-empty but only the prompt names one.
/// Test: `verify_gate::tests::detect_manifest_names_each_ecosystem`,
/// `verify_gate::tests::detect_falls_back_to_prompt_named_on_non_empty_root`.
/// Why no test command could be detected — the reason the accepted finish
/// records instead of a refusal.
///
/// Why: #8206 closure condition 3 — `finish_task` is accepted in this arm and
/// the report states WHY no test command ran.
/// What: The three unsatisfiable states: no bound project, an empty root, or
/// an agent whose registry carries no `bash` tool to run anything with.
/// Test: `verify_gate::tests::detect_undetectable_without_root_or_on_empty_root`.
/// Whether `root` holds a manifest implying a specific test command.
///
/// Why: A manifest is the strongest evidence a test command is actually
/// runnable here, and it names the command precisely enough to put in the
/// refusal.
/// What: First match wins, in the order Rust → Node → Python → Go. A
/// `package.json` counts only when it declares a non-empty `scripts.test`;
/// the command it implies is `pnpm test` when a `pnpm-lock.yaml` sits beside
/// it, `npm test` otherwise.
/// Test: `verify_gate::tests::detect_manifest_names_each_ecosystem`,
/// `verify_gate::tests::detect_package_json_without_test_script_is_not_a_manifest`.
/// Whether `root/package.json` declares a non-empty `scripts.test`.
///
/// Why: A `package.json` with no `test` script implies no runnable command —
/// `npm test` there exits non-zero with "Missing script", which is not a
/// suite the agent can reconcile.
/// What: Unreadable or unparsable JSON is `false` — fail toward accepting the
/// finish, never toward a refusal the agent cannot satisfy.
/// Test: `verify_gate::tests::detect_package_json_without_test_script_is_not_a_manifest`.
/// Whether `root` holds no entries at all (or cannot be read).
///
/// Why: An unreadable root is treated as empty for the same reason an empty
/// one is — the gate must not refuse a finish over a suite it cannot show is
/// there.
/// Test: `verify_gate::tests::detect_undetectable_without_root_or_on_empty_root`.
/// Detect the test command the gate would require, for the bound project.
///
/// Why: The missing half of #2279's trigger — the gate may only refuse a
/// finish over a command that could actually have been run here (#8206).
/// What: `Err(UndetectableReason)` when no root is bound or the root is
/// empty; otherwise `Ok` with the manifest-implied command, or the
/// `prompt_named` text when the non-empty root carries no recognised
/// manifest. `prompt_named` is the substring `super::named_test_command`
/// matched in the task prompt / project context.
/// Test: `verify_gate::tests::detect_manifest_names_each_ecosystem`,
/// `verify_gate::tests::detect_undetectable_without_root_or_on_empty_root`,
/// `verify_gate::tests::detect_falls_back_to_prompt_named_on_non_empty_root`.