@gate-forge/cli 0.7.1 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (296) hide show
  1. package/README.md +91 -704
  2. package/dist/adapter-audit.d.ts +208 -0
  3. package/dist/adapter-audit.d.ts.map +1 -0
  4. package/dist/adapter-audit.js +579 -0
  5. package/dist/adapter-audit.js.map +1 -0
  6. package/dist/adapter-scaffold.d.ts +91 -0
  7. package/dist/adapter-scaffold.d.ts.map +1 -0
  8. package/dist/adapter-scaffold.js +474 -0
  9. package/dist/adapter-scaffold.js.map +1 -0
  10. package/dist/adopted-baseline.d.ts +10 -0
  11. package/dist/adopted-baseline.d.ts.map +1 -1
  12. package/dist/adopted-baseline.js +18 -1
  13. package/dist/adopted-baseline.js.map +1 -1
  14. package/dist/args.d.ts +15 -0
  15. package/dist/args.d.ts.map +1 -1
  16. package/dist/args.js +61 -2
  17. package/dist/args.js.map +1 -1
  18. package/dist/behavior-setup.d.ts +239 -0
  19. package/dist/behavior-setup.d.ts.map +1 -0
  20. package/dist/behavior-setup.js +751 -0
  21. package/dist/behavior-setup.js.map +1 -0
  22. package/dist/broker.d.ts.map +1 -1
  23. package/dist/broker.js +28 -2
  24. package/dist/broker.js.map +1 -1
  25. package/dist/cache-exclusions.d.ts +45 -0
  26. package/dist/cache-exclusions.d.ts.map +1 -0
  27. package/dist/cache-exclusions.js +205 -0
  28. package/dist/cache-exclusions.js.map +1 -0
  29. package/dist/candidate-tree.d.ts +86 -14
  30. package/dist/candidate-tree.d.ts.map +1 -1
  31. package/dist/candidate-tree.js +236 -62
  32. package/dist/candidate-tree.js.map +1 -1
  33. package/dist/ci-witnessed-template.d.ts +43 -0
  34. package/dist/ci-witnessed-template.d.ts.map +1 -0
  35. package/dist/ci-witnessed-template.js +283 -0
  36. package/dist/ci-witnessed-template.js.map +1 -0
  37. package/dist/cli.d.ts +1 -1
  38. package/dist/cli.d.ts.map +1 -1
  39. package/dist/cli.js +31 -4
  40. package/dist/cli.js.map +1 -1
  41. package/dist/commands/adapters.d.ts +15 -0
  42. package/dist/commands/adapters.d.ts.map +1 -0
  43. package/dist/commands/adapters.js +355 -0
  44. package/dist/commands/adapters.js.map +1 -0
  45. package/dist/commands/adopt.d.ts +7 -0
  46. package/dist/commands/adopt.d.ts.map +1 -1
  47. package/dist/commands/adopt.js +44 -2
  48. package/dist/commands/adopt.js.map +1 -1
  49. package/dist/commands/baseline.d.ts.map +1 -1
  50. package/dist/commands/baseline.js +42 -1
  51. package/dist/commands/baseline.js.map +1 -1
  52. package/dist/commands/blocking.d.ts +105 -2
  53. package/dist/commands/blocking.d.ts.map +1 -1
  54. package/dist/commands/blocking.js +395 -53
  55. package/dist/commands/blocking.js.map +1 -1
  56. package/dist/commands/check.d.ts +36 -0
  57. package/dist/commands/check.d.ts.map +1 -1
  58. package/dist/commands/check.js +1068 -64
  59. package/dist/commands/check.js.map +1 -1
  60. package/dist/commands/classify.d.ts +2 -1
  61. package/dist/commands/classify.d.ts.map +1 -1
  62. package/dist/commands/classify.js +188 -5
  63. package/dist/commands/classify.js.map +1 -1
  64. package/dist/commands/enforce.d.ts +4 -4
  65. package/dist/commands/enforce.d.ts.map +1 -1
  66. package/dist/commands/enforce.js +41 -9
  67. package/dist/commands/enforce.js.map +1 -1
  68. package/dist/commands/enforcement.d.ts +13 -1
  69. package/dist/commands/enforcement.d.ts.map +1 -1
  70. package/dist/commands/enforcement.js +880 -33
  71. package/dist/commands/enforcement.js.map +1 -1
  72. package/dist/commands/explain.d.ts +1 -1
  73. package/dist/commands/explain.d.ts.map +1 -1
  74. package/dist/commands/explain.js +162 -3
  75. package/dist/commands/explain.js.map +1 -1
  76. package/dist/commands/history.d.ts +12 -0
  77. package/dist/commands/history.d.ts.map +1 -0
  78. package/dist/commands/history.js +45 -0
  79. package/dist/commands/history.js.map +1 -0
  80. package/dist/commands/init-presets.d.ts +155 -0
  81. package/dist/commands/init-presets.d.ts.map +1 -0
  82. package/dist/commands/init-presets.js +203 -0
  83. package/dist/commands/init-presets.js.map +1 -0
  84. package/dist/commands/init.d.ts +7 -12
  85. package/dist/commands/init.d.ts.map +1 -1
  86. package/dist/commands/init.js +987 -99
  87. package/dist/commands/init.js.map +1 -1
  88. package/dist/commands/keys.d.ts.map +1 -1
  89. package/dist/commands/keys.js +29 -13
  90. package/dist/commands/keys.js.map +1 -1
  91. package/dist/commands/next.d.ts.map +1 -1
  92. package/dist/commands/next.js +846 -19
  93. package/dist/commands/next.js.map +1 -1
  94. package/dist/commands/pre-commit.d.ts +25 -0
  95. package/dist/commands/pre-commit.d.ts.map +1 -1
  96. package/dist/commands/pre-commit.js +91 -6
  97. package/dist/commands/pre-commit.js.map +1 -1
  98. package/dist/commands/quarantine.d.ts +16 -0
  99. package/dist/commands/quarantine.d.ts.map +1 -0
  100. package/dist/commands/quarantine.js +213 -0
  101. package/dist/commands/quarantine.js.map +1 -0
  102. package/dist/commands/run.d.ts +39 -0
  103. package/dist/commands/run.d.ts.map +1 -0
  104. package/dist/commands/run.js +196 -0
  105. package/dist/commands/run.js.map +1 -0
  106. package/dist/commands/test-gates.d.ts +284 -2
  107. package/dist/commands/test-gates.d.ts.map +1 -1
  108. package/dist/commands/test-gates.js +3620 -187
  109. package/dist/commands/test-gates.js.map +1 -1
  110. package/dist/commands/tests.d.ts +1 -1
  111. package/dist/commands/tests.d.ts.map +1 -1
  112. package/dist/commands/tests.js +264 -29
  113. package/dist/commands/tests.js.map +1 -1
  114. package/dist/docs-exclusions.d.ts.map +1 -1
  115. package/dist/docs-exclusions.js +18 -3
  116. package/dist/docs-exclusions.js.map +1 -1
  117. package/dist/endpoint-compiler.d.ts.map +1 -1
  118. package/dist/endpoint-compiler.js +78 -9
  119. package/dist/endpoint-compiler.js.map +1 -1
  120. package/dist/engine-browser.d.ts +183 -0
  121. package/dist/engine-browser.d.ts.map +1 -0
  122. package/dist/engine-browser.js +381 -0
  123. package/dist/engine-browser.js.map +1 -0
  124. package/dist/engine-identity.d.ts +100 -0
  125. package/dist/engine-identity.d.ts.map +1 -0
  126. package/dist/engine-identity.js +182 -0
  127. package/dist/engine-identity.js.map +1 -0
  128. package/dist/evaluate.d.ts +105 -1
  129. package/dist/evaluate.d.ts.map +1 -1
  130. package/dist/evaluate.js +149 -18
  131. package/dist/evaluate.js.map +1 -1
  132. package/dist/execution.d.ts +253 -9
  133. package/dist/execution.d.ts.map +1 -1
  134. package/dist/execution.js +309 -12
  135. package/dist/execution.js.map +1 -1
  136. package/dist/gateforge-owned.d.ts +78 -0
  137. package/dist/gateforge-owned.d.ts.map +1 -0
  138. package/dist/gateforge-owned.js +254 -0
  139. package/dist/gateforge-owned.js.map +1 -0
  140. package/dist/git-hooks.d.ts +35 -0
  141. package/dist/git-hooks.d.ts.map +1 -1
  142. package/dist/git-hooks.js +140 -1
  143. package/dist/git-hooks.js.map +1 -1
  144. package/dist/git-ignored.d.ts +27 -0
  145. package/dist/git-ignored.d.ts.map +1 -0
  146. package/dist/git-ignored.js +102 -0
  147. package/dist/git-ignored.js.map +1 -0
  148. package/dist/git-objects.d.ts +60 -0
  149. package/dist/git-objects.d.ts.map +1 -0
  150. package/dist/git-objects.js +152 -0
  151. package/dist/git-objects.js.map +1 -0
  152. package/dist/glob.d.ts +33 -14
  153. package/dist/glob.d.ts.map +1 -1
  154. package/dist/glob.js +96 -5
  155. package/dist/glob.js.map +1 -1
  156. package/dist/history.d.ts +52 -0
  157. package/dist/history.d.ts.map +1 -0
  158. package/dist/history.js +116 -0
  159. package/dist/history.js.map +1 -0
  160. package/dist/host-load.d.ts +49 -0
  161. package/dist/host-load.d.ts.map +1 -0
  162. package/dist/host-load.js +78 -0
  163. package/dist/host-load.js.map +1 -0
  164. package/dist/index.d.ts +4 -1
  165. package/dist/index.d.ts.map +1 -1
  166. package/dist/index.js +2 -1
  167. package/dist/index.js.map +1 -1
  168. package/dist/input-snapshot.d.ts +63 -9
  169. package/dist/input-snapshot.d.ts.map +1 -1
  170. package/dist/input-snapshot.js +195 -17
  171. package/dist/input-snapshot.js.map +1 -1
  172. package/dist/io.d.ts +49 -0
  173. package/dist/io.d.ts.map +1 -1
  174. package/dist/io.js +22 -0
  175. package/dist/io.js.map +1 -1
  176. package/dist/mapping.d.ts +84 -1
  177. package/dist/mapping.d.ts.map +1 -1
  178. package/dist/mapping.js +276 -5
  179. package/dist/mapping.js.map +1 -1
  180. package/dist/native-freeze.d.ts +217 -0
  181. package/dist/native-freeze.d.ts.map +1 -0
  182. package/dist/native-freeze.js +332 -0
  183. package/dist/native-freeze.js.map +1 -0
  184. package/dist/pipeline.d.ts +67 -1
  185. package/dist/pipeline.d.ts.map +1 -1
  186. package/dist/pipeline.js +164 -6
  187. package/dist/pipeline.js.map +1 -1
  188. package/dist/planes-inference.d.ts +12 -5
  189. package/dist/planes-inference.d.ts.map +1 -1
  190. package/dist/planes-inference.js +13 -15
  191. package/dist/planes-inference.js.map +1 -1
  192. package/dist/playwright-browsers.d.ts +210 -0
  193. package/dist/playwright-browsers.d.ts.map +1 -0
  194. package/dist/playwright-browsers.js +364 -0
  195. package/dist/playwright-browsers.js.map +1 -0
  196. package/dist/plugins.d.ts +15 -5
  197. package/dist/plugins.d.ts.map +1 -1
  198. package/dist/plugins.js +59 -9
  199. package/dist/plugins.js.map +1 -1
  200. package/dist/progress.d.ts +148 -0
  201. package/dist/progress.d.ts.map +1 -0
  202. package/dist/progress.js +263 -0
  203. package/dist/progress.js.map +1 -0
  204. package/dist/providers.d.ts +26 -1
  205. package/dist/providers.d.ts.map +1 -1
  206. package/dist/providers.js +39 -0
  207. package/dist/providers.js.map +1 -1
  208. package/dist/receipts.d.ts +1 -0
  209. package/dist/receipts.d.ts.map +1 -1
  210. package/dist/receipts.js +35 -7
  211. package/dist/receipts.js.map +1 -1
  212. package/dist/repo-scan.d.ts +15 -1
  213. package/dist/repo-scan.d.ts.map +1 -1
  214. package/dist/repo-scan.js +329 -34
  215. package/dist/repo-scan.js.map +1 -1
  216. package/dist/reseal-chain.d.ts +184 -0
  217. package/dist/reseal-chain.d.ts.map +1 -0
  218. package/dist/reseal-chain.js +735 -0
  219. package/dist/reseal-chain.js.map +1 -0
  220. package/dist/reseal-evidence.d.ts +241 -0
  221. package/dist/reseal-evidence.d.ts.map +1 -0
  222. package/dist/reseal-evidence.js +319 -0
  223. package/dist/reseal-evidence.js.map +1 -0
  224. package/dist/reseal.d.ts +181 -0
  225. package/dist/reseal.d.ts.map +1 -0
  226. package/dist/reseal.js +1620 -0
  227. package/dist/reseal.js.map +1 -0
  228. package/dist/response-field-guidance.d.ts +82 -0
  229. package/dist/response-field-guidance.d.ts.map +1 -0
  230. package/dist/response-field-guidance.js +184 -0
  231. package/dist/response-field-guidance.js.map +1 -0
  232. package/dist/route-plane-proposals.d.ts +100 -0
  233. package/dist/route-plane-proposals.d.ts.map +1 -0
  234. package/dist/route-plane-proposals.js +213 -0
  235. package/dist/route-plane-proposals.js.map +1 -0
  236. package/dist/run-cache.d.ts +260 -0
  237. package/dist/run-cache.d.ts.map +1 -0
  238. package/dist/run-cache.js +771 -0
  239. package/dist/run-cache.js.map +1 -0
  240. package/dist/run-preflight.d.ts +77 -0
  241. package/dist/run-preflight.d.ts.map +1 -0
  242. package/dist/run-preflight.js +774 -0
  243. package/dist/run-preflight.js.map +1 -0
  244. package/dist/run-recipe.d.ts +107 -0
  245. package/dist/run-recipe.d.ts.map +1 -0
  246. package/dist/run-recipe.js +295 -0
  247. package/dist/run-recipe.js.map +1 -0
  248. package/dist/run-reliability.d.ts +126 -0
  249. package/dist/run-reliability.d.ts.map +1 -0
  250. package/dist/run-reliability.js +221 -0
  251. package/dist/run-reliability.js.map +1 -0
  252. package/dist/runtime.d.ts +15 -0
  253. package/dist/runtime.d.ts.map +1 -1
  254. package/dist/runtime.js +11 -1
  255. package/dist/runtime.js.map +1 -1
  256. package/dist/scope.d.ts +20 -0
  257. package/dist/scope.d.ts.map +1 -1
  258. package/dist/scope.js +26 -5
  259. package/dist/scope.js.map +1 -1
  260. package/dist/secret-guard.d.ts +36 -0
  261. package/dist/secret-guard.d.ts.map +1 -0
  262. package/dist/secret-guard.js +63 -0
  263. package/dist/secret-guard.js.map +1 -0
  264. package/dist/singleton-guidance.d.ts +82 -0
  265. package/dist/singleton-guidance.d.ts.map +1 -0
  266. package/dist/singleton-guidance.js +138 -0
  267. package/dist/singleton-guidance.js.map +1 -0
  268. package/dist/staged-candidate.d.ts +17 -0
  269. package/dist/staged-candidate.d.ts.map +1 -1
  270. package/dist/staged-candidate.js +50 -0
  271. package/dist/staged-candidate.js.map +1 -1
  272. package/dist/state-artifacts.d.ts +70 -0
  273. package/dist/state-artifacts.d.ts.map +1 -0
  274. package/dist/state-artifacts.js +215 -0
  275. package/dist/state-artifacts.js.map +1 -0
  276. package/dist/state.d.ts +170 -2
  277. package/dist/state.d.ts.map +1 -1
  278. package/dist/state.js +248 -8
  279. package/dist/state.js.map +1 -1
  280. package/dist/unmatched-routes.d.ts +60 -0
  281. package/dist/unmatched-routes.d.ts.map +1 -0
  282. package/dist/unmatched-routes.js +131 -0
  283. package/dist/unmatched-routes.js.map +1 -0
  284. package/dist/verifier-keys.d.ts +33 -2
  285. package/dist/verifier-keys.d.ts.map +1 -1
  286. package/dist/verifier-keys.js +95 -9
  287. package/dist/verifier-keys.js.map +1 -1
  288. package/guides/CONNECT-YOUR-PROJECT.md +425 -0
  289. package/guides/QUICKSTART.md +306 -26
  290. package/guides/REFERENCE.md +1710 -0
  291. package/guides/RUNNER-NEUTRAL-EVIDENCE.md +199 -0
  292. package/guides/TEST-ENVIRONMENT.md +1044 -6
  293. package/guides/UPGRADE-0.6-to-0.7.md +3 -3
  294. package/guides/UPGRADE-0.7-to-0.8.md +114 -0
  295. package/guides/UPGRADE-0.8-to-0.9.md +104 -0
  296. package/package.json +10 -9
@@ -1,7 +1,6 @@
1
1
  /**
2
- * `gateforge tests`: the existing-test workflow (plan 2026-09-13
3
- * Phase 2-3, Phase 4 diagnose). Five subcommands:
4
- *
2
+ * `gateforge tests`: seven subcommands for test inventory, annotation sync,
3
+ * mapping, and diagnostic workflows.
5
4
  * - `discover` — inventory the repository's tests into the derived
6
5
  * run-state catalog (Phase 2).
7
6
  * - `suggest` — resolve mappings for the run's obligations and produce
@@ -13,6 +12,8 @@
13
12
  * obligation registry, then write/update `.gateforge/test-map.yml`
14
13
  * ATOMICALLY and idempotently, printing the exact diff. Never edits
15
14
  * test files, never adds waivers, refuses contradictions.
15
+ * - `sync` — regenerate only annotation-sourced entries from an AST-only
16
+ * scan; hand-written sidecar entries are never modified.
16
17
  * - `explain` — the per-test §4 report: requirements, existing-test
17
18
  * identity, mapping origin, honest execution status, next action, and
18
19
  * `New test needed`. Exit 2 for an unknown key.
@@ -31,31 +32,37 @@
31
32
  * contract: 0 ok, 2 config/usage errors (including unknown keys/ids and
32
33
  * failed native enumeration).
33
34
  */
34
- import { mkdirSync, writeFileSync } from 'node:fs';
35
+ import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
35
36
  import { join } from 'node:path';
36
- import { canonicalJson, compareStrings, mappingSuggestions, TestKindSchema, } from '@gate-forge/core';
37
- import { discoverTestCatalog, TestDiscoveryError, } from '@gate-forge/pack-playwright';
37
+ import { canonicalJson, compareStrings, mappingSuggestions, TestKindSchema, TestMapSchema, } from '@gate-forge/core';
38
+ import { discoverTestCatalog, TestDiscoveryError, scanTestFiles, } from '@gate-forge/pack-playwright';
38
39
  import { parseArgs, stringFlag } from '../args.js';
39
40
  import { diagnosticsJson, renderDiagnosticsText, runDiagnosticSuites } from '../diagnostics.js';
40
41
  import { UsageError } from '../errors.js';
41
42
  import { writeLine } from '../io.js';
42
43
  import { collectInputFiles, computeInputSnapshot, diffInputFiles, SnapshotUnavailableError, UnsupportedSnapshotError, } from '../input-snapshot.js';
43
- import { diffLines, loadOptionalTestMap, relativeToRepo, resolveRepositoryMappings, serializeTestMap, TEST_MAP_RELATIVE, writeTestMapAtomic, } from '../mapping.js';
44
+ import { diffLines, loadOptionalTestMap, relativeToRepo, resolveRepositoryMappings, nativeInventoryBlocking, serializeTestMap, TEST_MAP_RELATIVE, annotationTestMapEntries, writeTestMapAtomic, } from '../mapping.js';
44
45
  import { runPipeline, sourcesByResourceId } from '../pipeline.js';
45
46
  import { resolveProvider } from '../providers.js';
46
47
  import { httpRoutesView, resolveStateDir } from '../state.js';
48
+ import { engineGeneratedStateFileFilter } from '../state-artifacts.js';
47
49
  import { loadConfigAt, rejectUnknownFlags } from './common.js';
48
50
  import { installedPlaywrightCompatibilityError } from '../package-compatibility.js';
51
+ import { loadCacheExclusions } from '../cache-exclusions.js';
49
52
  export const TESTS_USAGE = `\
50
53
  usage: gateforge tests discover [--json] [--pytest]
54
+ gateforge tests catalog [--json]
51
55
  gateforge tests surface-doctor [--json]
52
56
  gateforge tests suggest [--changed] [--json]
53
57
  gateforge tests mark --test <key> --kind <kind> [--category <c>]... \\
54
58
  --obligation <id>... --reason "<text>"
59
+ gateforge tests sync [--json]
55
60
  gateforge tests explain --test <key> [--json]
56
61
  gateforge tests diagnose [--suite <name>] [--json]`;
57
62
  /** The derived catalog file under the run-state directory. */
58
63
  export const CATALOG_FILE_NAME = 'test-catalog.json';
64
+ /** How many ranked candidates the text surface prints per obligation. */
65
+ const SUGGESTED_CANDIDATE_LIMIT = 5;
59
66
  /**
60
67
  * Runs the `tests` command family (discover/suggest/mark/explain).
61
68
  *
@@ -81,12 +88,16 @@ export async function testsCommand(io, argv) {
81
88
  switch (subcommand) {
82
89
  case 'discover':
83
90
  return discoverSubcommand(io, options);
91
+ case 'catalog':
92
+ return catalogSubcommand(io, options);
84
93
  case 'surface-doctor':
85
94
  return surfaceDoctorSubcommand(io, options);
86
95
  case 'suggest':
87
96
  return suggestSubcommand(io, options);
88
97
  case 'mark':
89
98
  return markSubcommand(io, options);
99
+ case 'sync':
100
+ return syncSubcommand(io, options);
90
101
  case 'explain':
91
102
  return explainSubcommand(io, options);
92
103
  case 'diagnose':
@@ -129,7 +140,12 @@ async function surfaceDoctorSubcommand(io, options) {
129
140
  async function runDiscovery(cwd, config, stateDir, collectPytest) {
130
141
  let discovered;
131
142
  try {
132
- discovered = await discoverTestCatalog({ cwd, config, collectPytest });
143
+ discovered = await discoverTestCatalog({
144
+ cwd,
145
+ config,
146
+ collectPytest,
147
+ excludeFile: engineGeneratedStateFileFilter(cwd, stateDir),
148
+ });
133
149
  }
134
150
  catch (error) {
135
151
  // A failed native enumeration is a config/environment problem
@@ -144,6 +160,76 @@ async function runDiscovery(cwd, config, stateDir, collectPytest) {
144
160
  writeFileSync(join(stateDir, CATALOG_FILE_NAME), `${discovered.json}\n`, 'utf8');
145
161
  return discovered;
146
162
  }
163
+ /**
164
+ * Builds a derived test catalog with mapped claims and related HTTP routes.
165
+ *
166
+ * Args:
167
+ * io: repository context and output streams.
168
+ * options: parsed catalog flags.
169
+ *
170
+ * Returns:
171
+ * Promise<number>: zero when discovery completes, two for usage or discovery errors.
172
+ */
173
+ async function catalogSubcommand(io, options) {
174
+ rejectUnknownFlags(options, ['json', 'help'], TESTS_USAGE);
175
+ const config = loadConfigAt(io.cwd);
176
+ const stateDir = resolveStateDir(io.cwd);
177
+ const discovered = await runDiscovery(io.cwd, config, stateDir, false);
178
+ const sidecar = loadOptionalTestMap(io.cwd);
179
+ const entries = discovered.catalog.entries.map((entry) => {
180
+ const claims = new Set(sidecar?.tests.find((declaration) => declaration.key === entry.logicalKey)?.claims ?? []);
181
+ for (const claim of discovered.nativeClaims) {
182
+ if (claim.testFile === entry.file && (claim.testId === entry.logicalKey || claim.testId === entry.title)) {
183
+ claims.add(claim.obligationId);
184
+ }
185
+ }
186
+ const sortedClaims = [...claims].sort(compareStrings);
187
+ const source = readFileSync(join(io.cwd, entry.file), 'utf8');
188
+ const routePattern = /(?:goto|route|url|path)\s*\(\s*(['"`])(\/[^'"`]*?)\1/g;
189
+ const routeMatches = [];
190
+ for (const match of source.matchAll(routePattern)) {
191
+ const route = match[2];
192
+ if (route !== undefined)
193
+ routeMatches.push(route);
194
+ }
195
+ const routes = [...new Set(routeMatches)].sort(compareStrings);
196
+ return { file: entry.file, title: entry.title, claims: sortedClaims, routes };
197
+ });
198
+ if (options['json'] === true) {
199
+ writeLine(io.stdout, canonicalJson({ schemaVersion: 1, entries }));
200
+ }
201
+ else {
202
+ writeLine(io.stdout, `tests catalog: ${entries.length} test(s)`);
203
+ for (const entry of entries) {
204
+ writeLine(io.stdout, ` ${entry.file}: ${entry.title}`);
205
+ if (entry.claims.length > 0)
206
+ writeLine(io.stdout, ` claims: ${entry.claims.join(', ')}`);
207
+ if (entry.routes.length > 0)
208
+ writeLine(io.stdout, ` routes: ${entry.routes.join(', ')}`);
209
+ }
210
+ }
211
+ writeRegistrationWarnings(io, discovered.registrationWarnings, 'tests catalog');
212
+ return 0;
213
+ }
214
+ /**
215
+ * Prints static warnings for test registrations controlled by Gateforge
216
+ * environment state without changing the machine-readable catalog.
217
+ *
218
+ * Args:
219
+ * io: command output streams.
220
+ * warnings: registration warnings from static discovery.
221
+ * command: command label used to identify the advisory.
222
+ *
223
+ * Returns:
224
+ * void.
225
+ */
226
+ function writeRegistrationWarnings(io, warnings, command) {
227
+ for (const warning of warnings) {
228
+ writeLine(io.stderr, `${command}: registration warning ${warning.file}:${String(warning.location.line)}: ` +
229
+ `${warning.titlePath.join(' > ')} is conditional on ${warning.environmentVariable}; ` +
230
+ 'keep test registration independent of Gateforge run variables');
231
+ }
232
+ }
147
233
  // ---------------------------------------------------------------------------
148
234
  // tests discover (Phase 2 surface, unchanged behavior)
149
235
  // ---------------------------------------------------------------------------
@@ -153,13 +239,15 @@ async function discoverSubcommand(io, options) {
153
239
  const asJson = options['json'] === true;
154
240
  const config = loadConfigAt(io.cwd);
155
241
  const stateDir = resolveStateDir(io.cwd);
156
- const { catalog, json } = await runDiscovery(io.cwd, config, stateDir, options['pytest'] === true);
242
+ const discovered = await runDiscovery(io.cwd, config, stateDir, options['pytest'] === true);
243
+ const { catalog, json } = discovered;
157
244
  if (asJson) {
158
245
  writeLine(io.stdout, json);
246
+ writeRegistrationWarnings(io, discovered.registrationWarnings, 'tests discover');
159
247
  return 0;
160
248
  }
161
- const discovered = catalog.entries.filter((entry) => entry.discoveryStatus === 'discovered').length;
162
- writeLine(io.stdout, `test catalog: discovered=${String(discovered)}` +
249
+ const discoveredCount = catalog.entries.filter((entry) => entry.discoveryStatus === 'discovered').length;
250
+ writeLine(io.stdout, `test catalog: discovered=${String(discoveredCount)}` +
163
251
  ` unresolved=${String(catalog.unresolved.length)}` +
164
252
  ` parseErrors=${String(catalog.parseErrors.length)}` +
165
253
  ` inventoryComplete=${catalog.inventoryComplete ? 'true' : 'false'}`);
@@ -172,6 +260,16 @@ async function discoverSubcommand(io, options) {
172
260
  for (const summary of catalog.runnerSummaries) {
173
261
  writeLine(io.stdout, `runner ${summary.runner}/${summary.name}: ${summary.status} — ${summary.detail}`);
174
262
  }
263
+ const edges = Object.entries(discovered.projectDependencies ?? {})
264
+ .filter(([, dependencies]) => dependencies.length > 0)
265
+ .map(([name, dependencies]) => `${name} → ${dependencies.join(', ')}`)
266
+ .sort();
267
+ if (edges.length > 0) {
268
+ // The runner's OWN resolved graph, not a reading of the consumer
269
+ // config: a supervised run orders its projects by exactly these edges.
270
+ writeLine(io.stdout, `project dependencies: ${edges.join('; ')}`);
271
+ }
272
+ writeRegistrationWarnings(io, discovered.registrationWarnings, 'tests discover');
175
273
  if (catalog.unresolved.length > 0) {
176
274
  writeLine(io.stdout, `unresolved (${String(catalog.unresolved.length)}):`);
177
275
  for (const gap of catalog.unresolved) {
@@ -200,12 +298,15 @@ async function suggestSubcommand(io, options) {
200
298
  const provider = diffScoped ? resolveProvider(config.changed.provider, io.cwd, io.env).provider : 'all-files';
201
299
  const pipeline = await runPipeline({ cwd: io.cwd, env: io.env, config, provider, stateDir });
202
300
  const discovered = await runDiscovery(io.cwd, config, stateDir, true);
301
+ writeRegistrationWarnings(io, discovered.registrationWarnings, 'tests suggest');
203
302
  const mapped = await resolveRepositoryMappings({
204
303
  cwd: io.cwd,
205
304
  config,
206
305
  obligations: pipeline.policy.obligations,
207
306
  catalog: discovered.catalog,
208
307
  nativeClaims: discovered.nativeClaims,
308
+ nativeErrors: discovered.nativeErrors,
309
+ nativeInstances: discovered.nativeInstances,
209
310
  behaviorCatalog: pipeline.behaviorCatalog,
210
311
  });
211
312
  // `--changed` narrows the SUGGESTED obligations to the changed scope
@@ -220,11 +321,46 @@ async function suggestSubcommand(io, options) {
220
321
  const sources = sourcesByResourceId(pipeline.graph, pipeline.behaviorCatalog);
221
322
  scoped = pipeline.policy.obligations.filter((obligation) => (sources.get(obligation.resourceId) ?? []).some((source) => changedSet.has(source)));
222
323
  }
223
- const suggestions = mappingSuggestions({
224
- catalog: discovered.catalog,
225
- obligationIds: scoped.map((obligation) => obligation.id),
226
- resolution: mapped.resolution,
227
- });
324
+ // Route hints rank candidates by route evidence ("this test talks to
325
+ // the obligation's route"). They only ADD a ranking signal; without
326
+ // them the same candidates come back in token order.
327
+ const routesByResource = new Map();
328
+ for (const route of httpRoutesView(pipeline.graph)) {
329
+ const hints = routesByResource.get(route.resourceId) ?? [];
330
+ hints.push(`${route.method} ${route.canonicalPath}`);
331
+ routesByResource.set(route.resourceId, hints);
332
+ }
333
+ const routeHints = new Map();
334
+ for (const obligation of pipeline.policy.obligations) {
335
+ const hints = routesByResource.get(obligation.resourceId);
336
+ if (hints !== undefined)
337
+ routeHints.set(obligation.id, [...hints]);
338
+ }
339
+ // A COMPLETE enumeration failure of the CONFIGURED runner hides the
340
+ // suggestions (an empty inventory would read as "no candidates"
341
+ // instead of "the runner could not enumerate"). The runner is
342
+ // `config.runner` — absent means playwright, the historical behavior.
343
+ const enumerationFailedCompletely = mapped.nativeErrors.length > 0 &&
344
+ !discovered.catalog.entries.some((entry) => entry.runner === config.runner);
345
+ const suggestions = enumerationFailedCompletely
346
+ ? []
347
+ : mappingSuggestions({
348
+ catalog: discovered.catalog,
349
+ obligationIds: scoped.map((obligation) => obligation.id),
350
+ resolution: mapped.resolution,
351
+ routeHints,
352
+ });
353
+ const mappingProblems = [
354
+ ...mapped.resolution.problems,
355
+ ...(mapped.nativeLoadProblem === null
356
+ ? []
357
+ : [
358
+ {
359
+ ...mapped.nativeLoadProblem,
360
+ nextAction: nativeInventoryBlocking(mapped.nativeLoadProblem)[0]?.nextAction ?? '',
361
+ },
362
+ ]),
363
+ ];
228
364
  // Required-case hints (plan 2026-09-19 Phase 6 item 6): candidates
229
365
  // come from the current inventory (resolver suggestions above); the
230
366
  // unmapped required cases name what final approval still needs —
@@ -248,6 +384,19 @@ async function suggestSubcommand(io, options) {
248
384
  .filter((caseId) => !mapped.has(caseId))
249
385
  .map((caseId) => pipeline.behaviorCatalog?.cases.find((item) => item.caseId === caseId)?.definition.id ?? caseId);
250
386
  };
387
+ // "already declared for" is about DECLARATIONS: a `test-map.yml` entry
388
+ // or an `@gateforge` annotation. An inferred or prior-run binding is a
389
+ // suggestion and never a declaration.
390
+ const obligationsByTestKey = new Map();
391
+ for (const group of mapped.resolution.obligations) {
392
+ for (const binding of group.bindings) {
393
+ if (binding.origin !== 'native' && binding.origin !== 'sidecar')
394
+ continue;
395
+ const obligations = obligationsByTestKey.get(binding.logicalKey) ?? [];
396
+ obligations.push(group.obligationId);
397
+ obligationsByTestKey.set(binding.logicalKey, obligations);
398
+ }
399
+ }
251
400
  const suggestionJson = suggestions.map((suggestion) => ({
252
401
  obligationId: suggestion.obligationId,
253
402
  cause: suggestion.cause,
@@ -255,6 +404,11 @@ async function suggestSubcommand(io, options) {
255
404
  logicalKey: candidate.logicalKey,
256
405
  file: candidate.file,
257
406
  why: [...candidate.why],
407
+ overlaps: [...new Set(obligationsByTestKey.get(candidate.logicalKey) ?? [])]
408
+ .filter((obligationId) => obligationId !== suggestion.obligationId)
409
+ .sort(compareStrings),
410
+ score: candidate.score,
411
+ rank: candidate.rank,
258
412
  })),
259
413
  missingEvidence: suggestion.missingEvidence,
260
414
  nextAction: suggestion.nextAction,
@@ -269,18 +423,20 @@ async function suggestSubcommand(io, options) {
269
423
  changedFiles: [...pipeline.changedFiles].sort(compareStrings),
270
424
  obligationsInScope: scoped.length,
271
425
  },
272
- problems: mapped.resolution.problems,
426
+ problems: mappingProblems,
273
427
  suggestions: suggestionJson,
274
428
  }));
275
429
  return 0;
276
430
  }
277
431
  writeLine(io.stdout, `suggest: ${String(pipeline.policy.obligations.length)} obligation(s) considered` +
278
432
  ` (${String(scoped.length)} in ${scopeMode} scope),` +
279
- ` ${String(mapped.resolution.problems.length)} mapping problem(s),` +
433
+ ` ${String(mappingProblems.length)} mapping problem(s),` +
280
434
  ` ${String(suggestions.length)} suggestion(s)`);
281
- for (const problem of mapped.resolution.problems) {
435
+ for (const problem of mappingProblems) {
282
436
  const where = problem.obligationId === null ? '' : ` for '${problem.obligationId}'`;
283
437
  writeLine(io.stdout, `problem [${problem.cause}]${where}: ${problem.detail}`);
438
+ if ('nextAction' in problem)
439
+ writeLine(io.stdout, ` next action: ${problem.nextAction}`);
284
440
  }
285
441
  for (const suggestion of suggestions) {
286
442
  writeLine(io.stdout, `[${suggestion.cause}] ${suggestion.obligationId}`);
@@ -292,12 +448,26 @@ async function suggestSubcommand(io, options) {
292
448
  writeLine(io.stdout, ` unmapped cases: ${unmapped.join(', ')} (map with tests mark --case, then prove with witnessed execution)`);
293
449
  }
294
450
  if (suggestion.candidates.length > 0) {
295
- writeLine(io.stdout, ' candidates:');
296
- for (const candidate of suggestion.candidates) {
297
- writeLine(io.stdout, ` - ${candidate.logicalKey} (${candidate.file})`);
451
+ writeLine(io.stdout, ' candidates (ranked by evidence):');
452
+ // The printed list is capped so one weakly-matching repository
453
+ // cannot bury the answer; `--json` keeps every ranked candidate.
454
+ const printed = suggestion.candidates.slice(0, SUGGESTED_CANDIDATE_LIMIT);
455
+ for (const candidate of printed) {
456
+ writeLine(io.stdout, ` - #${String(candidate.rank)} ${candidate.logicalKey} (${candidate.file})`);
298
457
  for (const why of candidate.why) {
299
458
  writeLine(io.stdout, ` why: ${why}`);
300
459
  }
460
+ const overlaps = obligationsByTestKey.get(candidate.logicalKey) ?? [];
461
+ const otherObligations = [...new Set(overlaps)]
462
+ .filter((obligationId) => obligationId !== suggestion.obligationId)
463
+ .sort(compareStrings);
464
+ if (otherObligations.length > 0) {
465
+ writeLine(io.stdout, ` already declared for: ${otherObligations.join(', ')}`);
466
+ }
467
+ }
468
+ const hidden = suggestion.candidates.length - printed.length;
469
+ if (hidden > 0) {
470
+ writeLine(io.stdout, ` ... and ${String(hidden)} more candidate(s) — run \`gateforge tests suggest --json\` for the full ranked list`);
301
471
  }
302
472
  }
303
473
  }
@@ -485,6 +655,68 @@ function assertKindDeclarationAllowed(entry, kind, key) {
485
655
  // ---------------------------------------------------------------------------
486
656
  // tests explain (Phase 3)
487
657
  // ---------------------------------------------------------------------------
658
+ /**
659
+ * Synchronizes generated test-map declarations without changing handwritten entries.
660
+ *
661
+ * Args:
662
+ * io: process context.
663
+ * options: parsed command flags.
664
+ *
665
+ * Returns:
666
+ * number: 0 when the static scan is complete, 1 when unresolved rows
667
+ * need owner review, or 2 for invalid configuration or sidecar data.
668
+ */
669
+ async function syncSubcommand(io, options) {
670
+ rejectUnknownFlags(options, ['json'], TESTS_USAGE);
671
+ const config = loadConfigAt(io.cwd);
672
+ const stateDir = resolveStateDir(io.cwd);
673
+ const scan = scanTestFiles({
674
+ cwd: io.cwd,
675
+ include: config.project.paths.include,
676
+ exclude: config.project.paths.exclude,
677
+ excludeFile: engineGeneratedStateFileFilter(io.cwd, stateDir),
678
+ });
679
+ const generated = annotationTestMapEntries(scan);
680
+ const previous = loadOptionalTestMap(io.cwd);
681
+ const handwritten = (previous?.tests ?? []).filter((entry) => entry.source !== 'annotation');
682
+ const candidate = { schemaVersion: 1, tests: [...handwritten, ...generated] };
683
+ const parsed = TestMapSchema.safeParse(candidate);
684
+ if (!parsed.success) {
685
+ const issue = parsed.error.issues[0];
686
+ const path = issue === undefined ? '' : ` at '${issue.path.map(String).join('.')}':`;
687
+ throw new UsageError(`annotation sync produced an invalid test map${path} ${issue?.message ?? 'unknown schema error'}`);
688
+ }
689
+ const previousContent = serializeTestMap(previous ?? { schemaVersion: 1, tests: [] });
690
+ const nextContent = serializeTestMap(parsed.data);
691
+ const changed = previousContent !== nextContent;
692
+ if (changed)
693
+ writeTestMapAtomic(io.cwd, parsed.data);
694
+ const unresolved = [
695
+ ...scan.parseErrors.map((entry) => `UNRESOLVED ${entry.file}:${entry.location.line}:${entry.location.col}: ${entry.message}`),
696
+ ...scan.unresolved.map((entry) => `UNRESOLVED ${entry.file}:${entry.location.line}:${entry.location.col}: ` +
697
+ `${entry.titlePath.join(' > ')} — ${entry.code}: ${entry.detail}`),
698
+ ...scan.entries
699
+ .filter((entry) => entry.annotationIssue !== undefined)
700
+ .map((entry) => `UNRESOLVED ${entry.file}:${entry.location.line}:${entry.location.col}: ` +
701
+ `${entry.titlePath.join(' > ')} — ${entry.annotationIssue}`),
702
+ ].sort(compareStrings);
703
+ const asJson = options['json'] === true;
704
+ if (asJson) {
705
+ writeLine(io.stdout, canonicalJson({
706
+ schemaVersion: 1,
707
+ generatedEntries: generated.length,
708
+ changed,
709
+ unresolved,
710
+ nextAction: unresolved.length > 0 ? 'Review unresolved static test annotations.' : null,
711
+ }));
712
+ }
713
+ else {
714
+ writeLine(io.stdout, `tests sync: ${generated.length} annotation mapping(s) ${changed ? 'updated' : 'unchanged'}`);
715
+ for (const row of unresolved)
716
+ writeLine(io.stdout, row);
717
+ }
718
+ return unresolved.length > 0 ? 1 : 0;
719
+ }
488
720
  /** Implements `tests explain --test <key>`. */
489
721
  async function explainSubcommand(io, options) {
490
722
  rejectUnknownFlags(options, ['test', 'json', 'help'], TESTS_USAGE);
@@ -510,7 +742,8 @@ async function explainSubcommand(io, options) {
510
742
  obligations: pipeline.policy.obligations,
511
743
  catalog: discovered.catalog,
512
744
  nativeClaims: discovered.nativeClaims,
513
- behaviorCatalog: pipeline.behaviorCatalog,
745
+ nativeErrors: discovered.nativeErrors,
746
+ nativeInstances: discovered.nativeInstances,
514
747
  });
515
748
  const entry = discovered.catalog.entries.find((candidate) => candidate.logicalKey === testKey);
516
749
  if (entry === undefined) {
@@ -592,13 +825,13 @@ function explainReport(testKey, entry, mapped, obligations, behaviorCatalog) {
592
825
  let mapping;
593
826
  let nextAction;
594
827
  if (sidecarDeclares) {
595
- mapping = `declared by agent (test-map.yml)${caseSuffix}`;
828
+ mapping = `declared in test-map.yml${caseSuffix}`;
596
829
  nextAction =
597
830
  missingCases.length > 0
598
831
  ? `map the missing cases (${missingCases
599
832
  .map((caseId) => behaviorCatalog?.cases.find((item) => item.caseId === caseId)?.definition.id ?? caseId)
600
833
  .join(', ')}) with tests mark --case; then run the test with the required channel`
601
- : 'run the existing test with the browser observer; its witnessed evidence must cover this change (execution and sealing land in Phase 4)';
834
+ : 'run the existing test with the witness: `gateforge test-gates --changed` executes the suite and collects the witnessed evidence that must cover this change';
602
835
  }
603
836
  else if (nativeDeclares) {
604
837
  mapping = `declared by native annotation${caseSuffix}`;
@@ -607,7 +840,7 @@ function explainReport(testKey, entry, mapped, obligations, behaviorCatalog) {
607
840
  ? `native annotations never implicitly claim behavior cases — add an explicit sidecar entry with tests mark --case for: ${missingCases
608
841
  .map((caseId) => behaviorCatalog?.cases.find((item) => item.caseId === caseId)?.definition.id ?? caseId)
609
842
  .join(', ')}`
610
- : 'run the existing test with the browser observer; its witnessed evidence must cover this change (execution and sealing land in Phase 4)';
843
+ : 'run the existing test with the witness: `gateforge test-gates --changed` executes the suite and collects the witnessed evidence that must cover this change';
611
844
  }
612
845
  else if (binding?.origin === 'prior-run') {
613
846
  mapping = 'prior run (suggestion only — never satisfies a new run)';
@@ -654,7 +887,7 @@ function explainReport(testKey, entry, mapped, obligations, behaviorCatalog) {
654
887
  titlePath: [...entry.titlePath],
655
888
  inferredKind: entry.inferredKind,
656
889
  },
657
- execution: 'not run for this change (execution and evidence sealing land in Phase 4)',
890
+ execution: 'not run for this change (`tests explain` is inspection only — run `gateforge test-gates --changed` to execute the suite with the witness)',
658
891
  blocks,
659
892
  };
660
893
  }
@@ -667,6 +900,7 @@ async function diagnoseSubcommand(io, options) {
667
900
  const asJson = options['json'] === true;
668
901
  const suiteName = stringFlag(options, 'suite');
669
902
  const config = loadConfigAt(io.cwd);
903
+ const cacheExclusions = loadCacheExclusions(io.cwd, config);
670
904
  const stateDir = resolveStateDir(io.cwd);
671
905
  // The alarm runs WITHOUT a browser or witness (§3.5), but it still
672
906
  // binds results to the current input identity: the same pipeline +
@@ -674,7 +908,7 @@ async function diagnoseSubcommand(io, options) {
674
908
  let preFiles = null;
675
909
  let snapshotUnavailable = false;
676
910
  try {
677
- preFiles = collectInputFiles(io.cwd, config, stateDir);
911
+ preFiles = collectInputFiles(io.cwd, config, stateDir, [], [], cacheExclusions);
678
912
  }
679
913
  catch (error) {
680
914
  if (error instanceof SnapshotUnavailableError) {
@@ -696,7 +930,7 @@ async function diagnoseSubcommand(io, options) {
696
930
  });
697
931
  let inputDigest = null;
698
932
  if (!snapshotUnavailable) {
699
- const postDiscovery = collectInputFiles(io.cwd, config, stateDir);
933
+ const postDiscovery = collectInputFiles(io.cwd, config, stateDir, [], [], cacheExclusions);
700
934
  const drift = preFiles === null ? [] : diffInputFiles(preFiles, postDiscovery);
701
935
  if (drift.length > 0) {
702
936
  throw new UsageError(`input tree changed around discovery (${drift.slice(0, 3).join('; ')}); no reliable input identity — refusing the diagnostic run`);
@@ -709,6 +943,7 @@ async function diagnoseSubcommand(io, options) {
709
943
  obligations: pipeline.policy.obligations,
710
944
  httpRoutes: httpRoutesView(pipeline.graph),
711
945
  plugins: pipeline.manifest.plugins.map((plugin) => ({ id: plugin.id, version: plugin.version })),
946
+ cacheExclusions,
712
947
  }).inputDigest;
713
948
  }
714
949
  const run = await runDiagnosticSuites({