@sun-asterisk/sungen 3.3.0-alpha.1 → 3.3.0-alpha.3

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 (233) hide show
  1. package/dist/capabilities/discover.d.ts +4 -0
  2. package/dist/capabilities/discover.d.ts.map +1 -1
  3. package/dist/capabilities/discover.js +16 -2
  4. package/dist/capabilities/discover.js.map +1 -1
  5. package/dist/cli/commands/audit.js +1 -1
  6. package/dist/cli/commands/audit.js.map +1 -1
  7. package/dist/cli/commands/contract-derive-command.d.ts +3 -2
  8. package/dist/cli/commands/contract-derive-command.d.ts.map +1 -1
  9. package/dist/cli/commands/contract-derive-command.js +3 -3
  10. package/dist/cli/commands/contract-derive-command.js.map +1 -1
  11. package/dist/cli/commands/contract.d.ts +3 -0
  12. package/dist/cli/commands/contract.d.ts.map +1 -1
  13. package/dist/cli/commands/contract.js +35 -5
  14. package/dist/cli/commands/contract.js.map +1 -1
  15. package/dist/cli/commands/delivery.d.ts.map +1 -1
  16. package/dist/cli/commands/delivery.js +9 -2
  17. package/dist/cli/commands/delivery.js.map +1 -1
  18. package/dist/cli/commands/journey.js +2 -2
  19. package/dist/cli/commands/journey.js.map +1 -1
  20. package/dist/cli/commands/next.d.ts.map +1 -1
  21. package/dist/cli/commands/next.js +8 -6
  22. package/dist/cli/commands/next.js.map +1 -1
  23. package/dist/cli/index.js +1 -1
  24. package/dist/cli/index.js.map +1 -1
  25. package/dist/cli/project-sungen-invocation.d.ts +7 -0
  26. package/dist/cli/project-sungen-invocation.d.ts.map +1 -0
  27. package/dist/cli/project-sungen-invocation.js +76 -0
  28. package/dist/cli/project-sungen-invocation.js.map +1 -0
  29. package/dist/contract/accept-opaque-steps.d.ts +3 -0
  30. package/dist/contract/accept-opaque-steps.d.ts.map +1 -0
  31. package/dist/contract/accept-opaque-steps.js +114 -0
  32. package/dist/contract/accept-opaque-steps.js.map +1 -0
  33. package/dist/contract/approve-contract.d.ts +8 -1
  34. package/dist/contract/approve-contract.d.ts.map +1 -1
  35. package/dist/contract/approve-contract.js +6 -0
  36. package/dist/contract/approve-contract.js.map +1 -1
  37. package/dist/contract/build-contract-verdict.js +2 -2
  38. package/dist/contract/build-contract-verdict.js.map +1 -1
  39. package/dist/contract/build-trace-conformance.d.ts +5 -1
  40. package/dist/contract/build-trace-conformance.d.ts.map +1 -1
  41. package/dist/contract/build-trace-conformance.js +9 -4
  42. package/dist/contract/build-trace-conformance.js.map +1 -1
  43. package/dist/contract/classify-contract-change.d.ts +3 -2
  44. package/dist/contract/classify-contract-change.d.ts.map +1 -1
  45. package/dist/contract/classify-contract-change.js.map +1 -1
  46. package/dist/contract/classify-trace-conformance.d.ts +18 -3
  47. package/dist/contract/classify-trace-conformance.d.ts.map +1 -1
  48. package/dist/contract/classify-trace-conformance.js +64 -17
  49. package/dist/contract/classify-trace-conformance.js.map +1 -1
  50. package/dist/contract/contract-schema.d.ts +21 -0
  51. package/dist/contract/contract-schema.d.ts.map +1 -1
  52. package/dist/contract/contract-schema.js +25 -3
  53. package/dist/contract/contract-schema.js.map +1 -1
  54. package/dist/contract/contracts-lock-file.d.ts.map +1 -1
  55. package/dist/contract/contracts-lock-file.js +1 -0
  56. package/dist/contract/contracts-lock-file.js.map +1 -1
  57. package/dist/contract/derive-free-feature.d.ts +8 -0
  58. package/dist/contract/derive-free-feature.d.ts.map +1 -1
  59. package/dist/contract/derive-free-feature.js +10 -1
  60. package/dist/contract/derive-free-feature.js.map +1 -1
  61. package/dist/contract/project-contract-blockers.d.ts.map +1 -1
  62. package/dist/contract/project-contract-blockers.js +4 -2
  63. package/dist/contract/project-contract-blockers.js.map +1 -1
  64. package/dist/contract/record-contract-approval.d.ts +16 -1
  65. package/dist/contract/record-contract-approval.d.ts.map +1 -1
  66. package/dist/contract/record-contract-approval.js +29 -1
  67. package/dist/contract/record-contract-approval.js.map +1 -1
  68. package/dist/contract/render-free-gherkin.d.ts +2 -0
  69. package/dist/contract/render-free-gherkin.d.ts.map +1 -1
  70. package/dist/contract/render-free-gherkin.js +6 -0
  71. package/dist/contract/render-free-gherkin.js.map +1 -1
  72. package/dist/contract/trace/collect-trace-evidence.d.ts +8 -3
  73. package/dist/contract/trace/collect-trace-evidence.d.ts.map +1 -1
  74. package/dist/contract/trace/collect-trace-evidence.js +66 -35
  75. package/dist/contract/trace/collect-trace-evidence.js.map +1 -1
  76. package/dist/contract/trace/read-file-once.d.ts +20 -0
  77. package/dist/contract/trace/read-file-once.d.ts.map +1 -0
  78. package/dist/contract/trace/read-file-once.js +135 -0
  79. package/dist/contract/trace/read-file-once.js.map +1 -0
  80. package/dist/contract/trace/select-final-attempt.d.ts +2 -2
  81. package/dist/contract/trace/select-final-attempt.d.ts.map +1 -1
  82. package/dist/contract/trace/select-final-attempt.js +3 -3
  83. package/dist/contract/trace/select-final-attempt.js.map +1 -1
  84. package/dist/contract/trace/test-step-join.d.ts +3 -3
  85. package/dist/contract/trace/test-step-join.d.ts.map +1 -1
  86. package/dist/contract/trace/test-step-join.js +2 -2
  87. package/dist/contract/trace/test-step-join.js.map +1 -1
  88. package/dist/contract/trace/trace-file-reader.d.ts +14 -2
  89. package/dist/contract/trace/trace-file-reader.d.ts.map +1 -1
  90. package/dist/contract/trace/trace-file-reader.js +27 -45
  91. package/dist/contract/trace/trace-file-reader.js.map +1 -1
  92. package/dist/contract/trace/trace-run-record.d.ts +6 -3
  93. package/dist/contract/trace/trace-run-record.d.ts.map +1 -1
  94. package/dist/contract/trace/trace-run-record.js +23 -17
  95. package/dist/contract/trace/trace-run-record.js.map +1 -1
  96. package/dist/contract/trace/trace-steps.js +1 -1
  97. package/dist/contract/trace/trace-steps.js.map +1 -1
  98. package/dist/contract/trace/trace-zip-limits.d.ts +5 -1
  99. package/dist/contract/trace/trace-zip-limits.d.ts.map +1 -1
  100. package/dist/contract/trace/trace-zip-limits.js +6 -2
  101. package/dist/contract/trace/trace-zip-limits.js.map +1 -1
  102. package/dist/contract/verify-approval-decisions.d.ts.map +1 -1
  103. package/dist/contract/verify-approval-decisions.js +9 -4
  104. package/dist/contract/verify-approval-decisions.js.map +1 -1
  105. package/dist/decisions/confirmed-decision-commands.d.ts +11 -0
  106. package/dist/decisions/confirmed-decision-commands.d.ts.map +1 -1
  107. package/dist/decisions/confirmed-decision-commands.js +21 -3
  108. package/dist/decisions/confirmed-decision-commands.js.map +1 -1
  109. package/dist/decisions/human-confirmation.d.ts +2 -0
  110. package/dist/decisions/human-confirmation.d.ts.map +1 -1
  111. package/dist/decisions/human-confirmation.js +6 -0
  112. package/dist/decisions/human-confirmation.js.map +1 -1
  113. package/dist/exporters/matrix/xlsx-cells.js +1 -1
  114. package/dist/exporters/matrix/xlsx-cells.js.map +1 -1
  115. package/dist/graph/evaluate-graph.d.ts +3 -1
  116. package/dist/graph/evaluate-graph.d.ts.map +1 -1
  117. package/dist/graph/evaluate-graph.js +8 -5
  118. package/dist/graph/evaluate-graph.js.map +1 -1
  119. package/dist/graph/node-decl.d.ts +7 -0
  120. package/dist/graph/node-decl.d.ts.map +1 -1
  121. package/dist/graph/node-decl.js.map +1 -1
  122. package/dist/graph/nodes/test-case-contract-nodes.d.ts +3 -1
  123. package/dist/graph/nodes/test-case-contract-nodes.d.ts.map +1 -1
  124. package/dist/graph/nodes/test-case-contract-nodes.js +7 -4
  125. package/dist/graph/nodes/test-case-contract-nodes.js.map +1 -1
  126. package/dist/graph/nodes/unit-contract-node.d.ts +2 -1
  127. package/dist/graph/nodes/unit-contract-node.d.ts.map +1 -1
  128. package/dist/graph/nodes/unit-contract-node.js +8 -1
  129. package/dist/graph/nodes/unit-contract-node.js.map +1 -1
  130. package/dist/graph/nodes/unit-design-nodes.d.ts.map +1 -1
  131. package/dist/graph/nodes/unit-design-nodes.js +2 -1
  132. package/dist/graph/nodes/unit-design-nodes.js.map +1 -1
  133. package/dist/harness/catalog/gate-rules.yaml +2 -2
  134. package/dist/harness/gates/audit-report-verification.d.ts +15 -6
  135. package/dist/harness/gates/audit-report-verification.d.ts.map +1 -1
  136. package/dist/harness/gates/audit-report-verification.js +49 -20
  137. package/dist/harness/gates/audit-report-verification.js.map +1 -1
  138. package/dist/harness/gates/delivery-checklist.js +2 -2
  139. package/dist/harness/gates/delivery-checklist.js.map +1 -1
  140. package/dist/harness/gates/delivery-decision-gate.d.ts +4 -0
  141. package/dist/harness/gates/delivery-decision-gate.d.ts.map +1 -1
  142. package/dist/harness/gates/delivery-decision-gate.js +26 -1
  143. package/dist/harness/gates/delivery-decision-gate.js.map +1 -1
  144. package/dist/harness/gates/delivery-decision-step.d.ts +4 -1
  145. package/dist/harness/gates/delivery-decision-step.d.ts.map +1 -1
  146. package/dist/harness/gates/delivery-decision-step.js +17 -2
  147. package/dist/harness/gates/delivery-decision-step.js.map +1 -1
  148. package/dist/harness/journey.d.ts +19 -0
  149. package/dist/harness/journey.d.ts.map +1 -1
  150. package/dist/harness/journey.js +94 -11
  151. package/dist/harness/journey.js.map +1 -1
  152. package/dist/harness/provenance.d.ts +29 -0
  153. package/dist/harness/provenance.d.ts.map +1 -1
  154. package/dist/harness/provenance.js +109 -9
  155. package/dist/harness/provenance.js.map +1 -1
  156. package/dist/hooks/guard-protected-paths.d.ts.map +1 -1
  157. package/dist/hooks/guard-protected-paths.js +3 -2
  158. package/dist/hooks/guard-protected-paths.js.map +1 -1
  159. package/dist/hooks/guard-rules.d.ts +1 -1
  160. package/dist/hooks/guard-tty-spoof-rule.d.ts +1 -1
  161. package/dist/hooks/guard-tty-spoof-rule.js +2 -2
  162. package/dist/hooks/guard-tty-spoof-rule.js.map +1 -1
  163. package/dist/hooks/hand-back-core.d.ts +5 -3
  164. package/dist/hooks/hand-back-core.d.ts.map +1 -1
  165. package/dist/hooks/hand-back-core.js +17 -10
  166. package/dist/hooks/hand-back-core.js.map +1 -1
  167. package/dist/hooks/session-start-unit-state-hook.d.ts.map +1 -1
  168. package/dist/hooks/session-start-unit-state-hook.js +5 -3
  169. package/dist/hooks/session-start-unit-state-hook.js.map +1 -1
  170. package/dist/orchestrator/assets-drift.d.ts +5 -0
  171. package/dist/orchestrator/assets-drift.d.ts.map +1 -1
  172. package/dist/orchestrator/assets-drift.js +12 -3
  173. package/dist/orchestrator/assets-drift.js.map +1 -1
  174. package/dist/orchestrator/project-initializer.d.ts.map +1 -1
  175. package/dist/orchestrator/project-initializer.js +1 -0
  176. package/dist/orchestrator/project-initializer.js.map +1 -1
  177. package/dist/orchestrator/templates/ai-src/commands/create-test.md +2 -2
  178. package/dist/orchestrator/templates/ai-src/commands/run-test.md +1 -1
  179. package/package.json +3 -3
  180. package/src/capabilities/discover.ts +15 -2
  181. package/src/cli/commands/audit.ts +1 -1
  182. package/src/cli/commands/contract-derive-command.ts +7 -6
  183. package/src/cli/commands/contract.ts +36 -5
  184. package/src/cli/commands/delivery.ts +7 -2
  185. package/src/cli/commands/journey.ts +4 -4
  186. package/src/cli/commands/next.ts +8 -6
  187. package/src/cli/index.ts +1 -1
  188. package/src/cli/project-sungen-invocation.ts +39 -0
  189. package/src/contract/accept-opaque-steps.ts +114 -0
  190. package/src/contract/approve-contract.ts +10 -3
  191. package/src/contract/build-contract-verdict.ts +2 -2
  192. package/src/contract/build-trace-conformance.ts +8 -3
  193. package/src/contract/classify-contract-change.ts +3 -3
  194. package/src/contract/classify-trace-conformance.ts +76 -22
  195. package/src/contract/contract-schema.ts +31 -2
  196. package/src/contract/contracts-lock-file.ts +1 -0
  197. package/src/contract/derive-free-feature.ts +12 -2
  198. package/src/contract/project-contract-blockers.ts +4 -2
  199. package/src/contract/record-contract-approval.ts +41 -1
  200. package/src/contract/render-free-gherkin.ts +5 -0
  201. package/src/contract/trace/collect-trace-evidence.ts +67 -30
  202. package/src/contract/trace/read-file-once.ts +95 -0
  203. package/src/contract/trace/select-final-attempt.ts +3 -3
  204. package/src/contract/trace/test-step-join.ts +6 -5
  205. package/src/contract/trace/trace-file-reader.ts +34 -13
  206. package/src/contract/trace/trace-run-record.ts +17 -11
  207. package/src/contract/trace/trace-steps.ts +1 -1
  208. package/src/contract/trace/trace-zip-limits.ts +6 -2
  209. package/src/contract/verify-approval-decisions.ts +9 -5
  210. package/src/decisions/confirmed-decision-commands.ts +25 -4
  211. package/src/decisions/human-confirmation.ts +5 -0
  212. package/src/exporters/matrix/xlsx-cells.ts +1 -1
  213. package/src/graph/evaluate-graph.ts +9 -5
  214. package/src/graph/node-decl.ts +7 -0
  215. package/src/graph/nodes/test-case-contract-nodes.ts +9 -4
  216. package/src/graph/nodes/unit-contract-node.ts +8 -1
  217. package/src/graph/nodes/unit-design-nodes.ts +2 -1
  218. package/src/harness/catalog/gate-rules.yaml +2 -2
  219. package/src/harness/gates/audit-report-verification.ts +51 -23
  220. package/src/harness/gates/delivery-checklist.ts +2 -2
  221. package/src/harness/gates/delivery-decision-gate.ts +29 -1
  222. package/src/harness/gates/delivery-decision-step.ts +19 -3
  223. package/src/harness/journey.ts +95 -13
  224. package/src/harness/provenance.ts +99 -11
  225. package/src/hooks/guard-protected-paths.ts +3 -2
  226. package/src/hooks/guard-rules.ts +1 -1
  227. package/src/hooks/guard-tty-spoof-rule.ts +3 -3
  228. package/src/hooks/hand-back-core.ts +17 -11
  229. package/src/hooks/session-start-unit-state-hook.ts +5 -3
  230. package/src/orchestrator/assets-drift.ts +12 -5
  231. package/src/orchestrator/project-initializer.ts +1 -0
  232. package/src/orchestrator/templates/ai-src/commands/create-test.md +2 -2
  233. package/src/orchestrator/templates/ai-src/commands/run-test.md +1 -1
@@ -4,6 +4,9 @@
4
4
  * approve --screen <u> [--scenario <id>] [--reason <text>]
5
5
  * a human types a confirmation on a TTY; writes contracts.lock.yaml + a contract-approval
6
6
  * decision. No TTY → refused with the exact command (exit 1).
7
+ * approve --screen <u> --scenario <id> --accept-opaque [--reason <text>]
8
+ * the same human act for the reviewed opaque trace steps of one approved free / impl:code
9
+ * scenario (#923): bound to each step as it reads now (accept-opaque-steps.ts).
7
10
  * check --screen <u> [--trace] [--json]
8
11
  * rebuilds the verdict from .feature + lock + git HEAD + recorded traces (never from a report),
9
12
  * writes .sungen/reports/<slug>-contract.json as output (secret-scanned first). Exit 2 on a hard
@@ -17,6 +20,7 @@ import * as fs from 'fs';
17
20
  import * as path from 'path';
18
21
  import { approveContract } from '../../contract/approve-contract';
19
22
  import { buildContractVerdict, ContractVerdict } from '../../contract/build-contract-verdict';
23
+ import { LOW_IDENTITY_FINDING } from '../../contract/classify-trace-conformance';
20
24
  import { contractReportPath, writeContractReport } from '../../contract/contract-report-file';
21
25
  import { HARD_CLASSES, REVIEW_CLASSES } from '../../contract/contract-schema';
22
26
  import { processIO } from '../../decisions/human-confirmation';
@@ -31,9 +35,15 @@ const MARK: Record<string, string> = {
31
35
  };
32
36
  /** `contract check` judges traces with a generous deadline (the guard path keeps ~3 s). */
33
37
  const CHECK_TRACE_BUDGET_MS = 120_000;
34
- const UNPROVEN_HINT = " → free / impl:code tests need trace: 'on' and the sungen run-record reporter, then a fresh run (see `sungen contract derive`).";
38
+ const UNPROVEN_HINT = " → free / impl:code tests need their own config (outputDir 'test-results-free', trace: 'on', the sungen run-record reporter), then a fresh run (see `sungen contract derive`).";
35
39
 
36
- function printVerdict(v: ContractVerdict, reportFile: string): void {
40
+ /** The command that recompiles a unit's spec — `sungen generate --screen|--flow|--api <unit>`. */
41
+ function generateCommand(unit: { name: string; dir: string }): string {
42
+ const kind = path.relative(path.join(process.cwd(), 'qa'), unit.dir).split(path.sep)[0];
43
+ return `sungen generate --${kind === 'flows' ? 'flow' : kind === 'api' ? 'api' : 'screen'} ${unit.name}`;
44
+ }
45
+
46
+ function printVerdict(v: ContractVerdict, reportFile: string, generate: string): void {
37
47
  const L = console.log;
38
48
  const head = v.verdict === 'pass' ? '✓ PASS' : v.verdict === 'review'
39
49
  ? '⚖ REVIEW — changed, not weaker. Exit 0 here, but review blocks `sungen delivery` until QA re-approves' : '✗ FAIL';
@@ -64,7 +74,19 @@ function printVerdict(v: ContractVerdict, reportFile: string): void {
64
74
  : onlyUnproven ? " → Re-run the free / impl:code tests with trace: 'on', then check again."
65
75
  : ' → Restore the approved checks in the .feature — or, if the change is intended, QA approves it on a terminal:');
66
76
  }
67
- if (v.verdict !== 'pass' && !v.uncommitted.length && !onlyUnproven) L(` sungen contract approve --screen ${v.unit}`);
77
+ // An opaque step is not cleared by re-approving (#923): QA reviews it, then accepts it as it reads now.
78
+ const acceptable = blocking.filter((s) => s.class === 'opaque' && s.trace?.opaque?.some((o) => !o.accepted)
79
+ && !s.findings.some((f) => f.detail.startsWith(LOW_IDENTITY_FINDING)));
80
+ if (v.verdict !== 'pass' && !v.uncommitted.length && !onlyUnproven && acceptable.length < blocking.length) L(` sungen contract approve --screen ${v.unit}`);
81
+ for (const s of acceptable) {
82
+ L(` → ${s.id}: QA reviews each opaque step above (verbatim, file:line); to accept them as they read now, on a terminal:`);
83
+ L(` sungen contract approve --screen ${v.unit} --scenario ${s.id} --accept-opaque`);
84
+ }
85
+ // A weakened compiled scenario also leaves its spec out of step (#943): name the command that fixes the drift.
86
+ // (A free / impl:code scenario carries a trace summary; its test is hand-written, never regenerated.)
87
+ if (v.verdict === 'fail' && !v.uncommitted.length && v.scenarios.some((s) => !s.trace && HARD_CLASSES.has(s.class))) {
88
+ L(` → After fixing the scenario, run \`${generate}\`: until the compiled spec is regenerated, \`sungen script-check\` reports drift.`);
89
+ }
68
90
  L(` Report: ${path.relative(process.cwd(), reportFile)}`);
69
91
  L('');
70
92
  }
@@ -85,11 +107,20 @@ export function registerContractCommand(program: Command): void {
85
107
  .option('-s, --screen <name>', 'Screen / flow / api unit name')
86
108
  .option('--scenario <id>', 'Approve one scenario only (its ID, e.g. VP-LOGIN-001)')
87
109
  .option('--reason <text>', 'Why (recorded in the contract-approval decision)')
110
+ .option('--accept-opaque', 'With --scenario: accept the reviewed opaque trace step(s) of one approved free / impl:code scenario')
88
111
  .action(async (options) => {
89
112
  try {
90
113
  const unit = unitOrThrow(options.screen);
91
- const r = await approveContract({ projectRoot: process.cwd(), unit: unit.name, scenario: options.scenario, reason: options.reason, io: processIO() });
114
+ const r = await approveContract({
115
+ projectRoot: process.cwd(), unit: unit.name, scenario: options.scenario, reason: options.reason, acceptOpaque: options.acceptOpaque === true, io: processIO(),
116
+ });
92
117
  if (r.status === 'nothing-to-approve') { console.log(`\n= Nothing to approve: every chosen scenario of ${unit.name} already matches its approved lock entry.\n`); return; }
118
+ if (r.status === 'nothing-to-accept') { console.log(`\n= Nothing to accept: every opaque step of ${options.scenario} is already accepted as it reads now.\n`); return; }
119
+ if (r.status === 'accepted') {
120
+ console.log(`\n✓ Accepted ${r.accepted?.length ?? 0} opaque step(s) of ${options.scenario} → ${path.relative(process.cwd(), r.lockPath)} (decision ${r.decisionId})`);
121
+ console.log(' Commit the lock and the decision through review, then re-run the free test with its trace: a trace older than the lock proves nothing.\n');
122
+ return;
123
+ }
93
124
  console.log(`\n✓ Approved ${r.approved.length} scenario(s)${r.removed.length ? `, removed ${r.removed.length}` : ''} → ${path.relative(process.cwd(), r.lockPath)} (decision ${r.decisionId})`);
94
125
  console.log(' Commit the lock and the decision through review: until they are in git HEAD, `sungen contract check` reports contract.lock-uncommitted.\n');
95
126
  } catch (error) {
@@ -116,7 +147,7 @@ export function registerContractCommand(program: Command): void {
116
147
  if (hits.length) throw new Error(`Refused to write the contract report — likely secret(s): ${hits.map((h) => `${h.where} ${h.reason}`).join('; ')}`);
117
148
  const file = writeContractReport(process.cwd(), verdict);
118
149
  if (options.json) console.log(JSON.stringify(verdict, null, 2));
119
- else printVerdict(verdict, file);
150
+ else printVerdict(verdict, file, generateCommand(unit));
120
151
  process.exit(verdict.exitCode);
121
152
  } catch (error) {
122
153
  // Unreadable = not run (DOS-14.0): an earlier report must not outlive the inputs it judged.
@@ -711,6 +711,8 @@ async function exportMatrixTarget(
711
711
  }
712
712
 
713
713
  const { model, mapMissing, mapErrors } = loadMatrixModel(paths);
714
+ // An audit that is untrusted or FAILs never yields an official deliverable: --preview renders a DRAFT (#935).
715
+ if (model && decisions?.auditDraft(qaDir(cwd, target))) model.manifest.approvalState = 'draft';
714
716
 
715
717
  if (mapMissing) {
716
718
  log(`${COLOR.yellow}${paths.label}: no delivery map${COLOR.reset} (${path.relative(cwd, paths.mapFile)})`);
@@ -1095,9 +1097,12 @@ export function registerDeliveryCommand(program: Command): void {
1095
1097
  // an approval are the normal state of a live project. Preflight skips are
1096
1098
  // not counted here: reaching this point in an explicit scope means
1097
1099
  // --continue-on-missing was passed, which IS the opt-in to tolerate them.
1098
- const failed = explicitScope
1100
+ // --check reports like its checklist: an audit box that does not hold is a non-zero exit (#935).
1101
+ const auditFails = (decisions?.untrustedAudits.length ?? 0) + (decisions?.failingAudits.length ?? 0);
1102
+ if (options.check && auditFails) log(`${COLOR.red}✗ --check: ${auditFails} unit(s) whose audit does not pass — see the audit box above.${COLOR.reset}`);
1103
+ const failed = (explicitScope
1099
1104
  ? notExported.length > 0
1100
- : matrixSummaries.length === 0;
1105
+ : matrixSummaries.length === 0) || (!!options.check && auditFails > 0);
1101
1106
  if (failed) process.exit(1);
1102
1107
  return;
1103
1108
  }
@@ -1,9 +1,9 @@
1
1
  import { Command } from 'commander';
2
2
  import * as path from 'path';
3
- import { runJourney, signoff, renderJourneyBoard, rollupJourney, renderRollupBoard, writeJourneyFileBestEffort } from '../../harness/journey';
3
+ import { runJourney, renderJourneyBoard, rollupJourney, renderRollupBoard, writeJourneyFileBestEffort } from '../../harness/journey';
4
4
  import { reportSlug } from '../../harness/unit-paths';
5
5
  import { findUnitDir } from '../resolve-unit';
6
- import { answerPendingMigration, decideWithConfirmation, DECIDE_KINDS, waiveWithConfirmation } from '../../decisions/confirmed-decision-commands';
6
+ import { answerPendingMigration, decideWithConfirmation, DECIDE_KINDS, signoffWithConfirmation, waiveWithConfirmation } from '../../decisions/confirmed-decision-commands';
7
7
  import { processIO } from '../../decisions/human-confirmation';
8
8
 
9
9
  const collect = (value: string, previous: string[]): string[] => [...previous, value];
@@ -22,7 +22,7 @@ export function registerJourneyCommand(program: Command): void {
22
22
  .option('--payload <json>', 'Kind-specific fields as a JSON object, e.g. a gate-override\'s {"rule","severity","scope"} (with --decide)')
23
23
  .option('--visibility <v>', 'internal (default, never exported) | client (with --decide)')
24
24
  .option('--supersedes <id>', 'The decision this one replaces — the old entry is never edited (with --decide)')
25
- .option('--signoff', 'Sign off the review queue — the single human gate (allowed only when every other obligation is satisfied/waived)')
25
+ .option('--signoff', 'Sign off the review queue — the single human gate (allowed only when every other obligation is satisfied/waived); a human types a confirmation on a TTY')
26
26
  .option('--by <name>', 'Who is signing off (recorded with --signoff)')
27
27
  .option('--json', 'Output the raw JSON report')
28
28
  .action(async (options) => {
@@ -63,7 +63,7 @@ export function registerJourneyCommand(program: Command): void {
63
63
  const report = options.waive
64
64
  ? await waiveWithConfirmation({ projectRoot: process.cwd(), unit: name, obligation: options.waive, reason: options.reason || '', io })
65
65
  : options.signoff
66
- ? signoff(process.cwd(), name, options.by)
66
+ ? await signoffWithConfirmation({ projectRoot: process.cwd(), unit: name, by: options.by, io })
67
67
  : runJourney(process.cwd(), name);
68
68
 
69
69
  const outDir = path.join(process.cwd(), '.sungen', 'journey');
@@ -20,6 +20,7 @@ import { testCaseStatusLabel } from '../../graph/test-case-satisfied';
20
20
  import { testCaseStates } from '../../graph/test-case-states';
21
21
  import { deriveSteps, NextStep, readUnitState, UnitState } from '../../harness/next-step';
22
22
  import { resolveUnit, resolveUnitCandidates, AmbiguousUnitError } from '../resolve-unit';
23
+ import { withProjectInvocation } from '../project-sungen-invocation';
23
24
 
24
25
  /** Every unit the project holds, so `sungen next` with no argument still answers. */
25
26
  function allUnits(cwd: string): Array<{ name: string; kind: UnitState['kind']; dir: string }> {
@@ -35,15 +36,16 @@ function allUnits(cwd: string): Array<{ name: string; kind: UnitState['kind']; d
35
36
  return out;
36
37
  }
37
38
 
38
- function renderSteps(steps: NextStep[]): void {
39
+ /** Steps as text, each `sungen …` command as this project runs it (#939); `--json` keeps them canonical. */
40
+ function renderSteps(steps: NextStep[], cwd: string): void {
39
41
  for (const st of steps) {
40
42
  const mark = st.kind === 'blocked' ? '⛔' : st.kind === 'optional' ? '○' : st.kind === 'decide' ? '⚖' : '→';
41
- console.log(` ${mark} ${st.command}${st.kind === 'decide' ? ' (a QA decision — ask, do not run)' : ''}`);
43
+ console.log(` ${mark} ${withProjectInvocation(st.command, cwd)}${st.kind === 'decide' ? ' (a QA decision — ask, do not run)' : ''}`);
42
44
  console.log(` ${st.because}`);
43
45
  }
44
46
  }
45
47
 
46
- function render(s: UnitState): void {
48
+ function render(s: UnitState, cwd: string): void {
47
49
  const L = console.log;
48
50
  L('');
49
51
  L(`━━━ Next steps: ${s.unit} (${s.kind}) ━━━`);
@@ -59,7 +61,7 @@ function render(s: UnitState): void {
59
61
  if (s.audit) L(` audit: ${s.audit.overall}/10 [${s.audit.gateStatus}] · ${s.audit.findings.length} finding(s)`);
60
62
  else if (s.auditNotCounted) L(` audit: ${s.auditNotCounted.state === 'stale' ? 'stale' : 'not trusted'} — ${s.auditNotCounted.reason}`);
61
63
  L('');
62
- renderSteps(s.steps);
64
+ renderSteps(s.steps, cwd);
63
65
  L('');
64
66
  }
65
67
 
@@ -89,7 +91,7 @@ function caseView(s: UnitState, cwd: string, unitDir: string, id: string, json:
89
91
  if (tc.anchors.length) L(` anchors: ${tc.anchors.map((a) => `${a.anchor} (${a.change})`).join(', ')}`);
90
92
  for (const f of tc.findings) L(` finding: ${f.code} [${f.confidence.label} ${f.confidence.score}] ${f.citation}`);
91
93
  L('');
92
- if (steps.length) renderSteps(steps);
94
+ if (steps.length) renderSteps(steps, cwd);
93
95
  else L(` ✓ nothing to do for this test case — ${testCaseStatusLabel(tc)}`);
94
96
  L('');
95
97
  }
@@ -131,7 +133,7 @@ export function registerNextCommand(program: Command): void {
131
133
  console.log(JSON.stringify(states.length === 1 ? states[0] : states, null, 2));
132
134
  return;
133
135
  }
134
- for (const s of states) render(s);
136
+ for (const s of states) render(s, cwd);
135
137
  } catch (e) {
136
138
  console.error(`Error: ${e instanceof Error ? e.message : e}`);
137
139
  process.exit(1);
package/src/cli/index.ts CHANGED
@@ -56,7 +56,7 @@ async function main() {
56
56
  // process exit (not postAction) because several commands exit with a MEANINGFUL code that skips
57
57
  // commander's hooks (`depth-lint` → 2). It points at `sungen next` instead of restating a step,
58
58
  // so it cannot drift from the project state. A failure prints it on stderr after the error;
59
- // `--json`/`--grep` keep it off stdout (#836); `next` and `hook` never print one. The line and
59
+ // `--json`/`--grep` keep it off stdout (#836); `hook` never prints one, `next` only when it fails (#937). The line and
60
60
  // those rules live in the hook core (src/hooks/hand-back-core.ts) — this file only wires it.
61
61
  const handBack = attachCliHandBack(process.argv, process.cwd());
62
62
  const program = new Command();
@@ -0,0 +1,39 @@
1
+ /**
2
+ * How a hint names sungen inside a project (#939, items 1–2).
3
+ *
4
+ * A project that installs its own sungen (`npm i -D @sun-asterisk/sungen`) runs it with `npx sungen`;
5
+ * a bare `sungen` is whatever global install the machine has — in the field test an older 3.2.24-beta
6
+ * beside the project's 3.3.0-alpha. And `sungen update` without a flag switches to the stable
7
+ * channel, so on an alpha or beta install the update hint must keep the channel it runs on.
8
+ *
9
+ * sungenInvocation(root) 'npx sungen' when <root>/node_modules/@sun-asterisk/sungen exists, else 'sungen'
10
+ * withProjectInvocation(cmd, root) a canonical `sungen …` command as this project runs it
11
+ * updateCommand(root, version?) `<invocation> update` plus `--alpha` / `--beta` (`--tag <id>` for another prerelease)
12
+ *
13
+ * Only the project root itself is looked at — where `npm i` puts a QA project's install — so a
14
+ * monorepo checkout above a fixture does not turn its hints into `npx`.
15
+ */
16
+ import * as fs from 'fs';
17
+ import * as path from 'path';
18
+ import { getPackageVersion } from '../exporters/package-info';
19
+
20
+ export function sungenInvocation(projectRoot: string): string {
21
+ return fs.existsSync(path.join(projectRoot, 'node_modules', '@sun-asterisk', 'sungen', 'package.json')) ? 'npx sungen' : 'sungen';
22
+ }
23
+
24
+ /** `sungen audit --screen x` → `npx sungen audit --screen x` in a project with its own install; anything else unchanged. */
25
+ export function withProjectInvocation(command: string, projectRoot: string): string {
26
+ const inv = sungenInvocation(projectRoot);
27
+ return inv !== 'sungen' && /^sungen\b/.test(command) ? `${inv}${command.slice('sungen'.length)}` : command;
28
+ }
29
+
30
+ /** The `sungen update` flag that keeps the channel of `version` (its prerelease id); '' for stable. */
31
+ export function updateChannelFlag(version: string = getPackageVersion()): string {
32
+ const id = version.match(/^\d+\.\d+\.\d+-([0-9A-Za-z-]+)/)?.[1];
33
+ if (!id) return '';
34
+ return id === 'alpha' || id === 'beta' ? ` --${id}` : ` --tag ${id}`;
35
+ }
36
+
37
+ export function updateCommand(projectRoot: string, version: string = getPackageVersion()): string {
38
+ return `${sungenInvocation(projectRoot)} update${updateChannelFlag(version)}`;
39
+ }
@@ -0,0 +1,114 @@
1
+ /**
2
+ * `sungen contract approve --screen <u> --scenario <id> --accept-opaque` — a QA accepts the reviewed
3
+ * opaque steps of ONE approved free / impl:code scenario (#923). An opaque step (a check on a JS value,
4
+ * an API request, an evaluate) is never compared by code, so without this an approved test that has one
5
+ * stays in review for good: re-approving changes nothing and contract.opaque-step allows no override.
6
+ * In order, like `approve` (approve-contract.ts), so a human never confirms something then refused:
7
+ *
8
+ * 1. the scenario must be approved AS IT READS NOW — its lock entry human-approved, intact, at the
9
+ * current hash, and vouched for by its decision — else: approve it first
10
+ * 2. its verdict is rebuilt (buildContractVerdict, as `contract check`): the opaque steps must be the
11
+ * ONLY thing holding it; anything else (changed, unproven, inconclusive, a `low` identity…) refuses
12
+ * with its own fix. Every opaque step already accepted → nothing to accept, no prompt
13
+ * 3. each opaque step is shown verbatim with its file:line; on a TTY the human types the scenario id
14
+ * and a one-time code — without one: refused with the exact command (an agent never runs this)
15
+ * 4. everything is read AGAIN: if the trace, the feature or the lock moved meanwhile → refused
16
+ * 5. a contract-approval decision records the scenario at its hash WITH the accepted steps (step + sha)
17
+ * and the lock entry points at it (record-contract-approval.ts)
18
+ *
19
+ * The acceptance is bound to each step's sha (opaqueStepSha): a change to an accepted step, or a new
20
+ * approval of the scenario, brings it back to review.
21
+ *
22
+ * Trust boundary: the TTY confirmation guards this command, not the files. A lock entry AND a matching
23
+ * decision forged together and committed through review are trusted like any approval — git review
24
+ * is that boundary, here as for `approve`.
25
+ */
26
+ import { gitUserName } from '../decisions/decision-source';
27
+ import { formatCommand, requireTypedConfirmation } from '../decisions/human-confirmation';
28
+ import type { ApproveInput, ApproveResult } from './approve-contract';
29
+ import { buildContractVerdict } from './build-contract-verdict';
30
+ import { LOW_IDENTITY_FINDING } from './classify-trace-conformance';
31
+ import { canonicalJson } from './contract-hash';
32
+ import { ContractScenario, isHumanApproved, OpaqueStep } from './contract-schema';
33
+ import { resolveContractUnit } from './contract-units';
34
+ import { lockPathFor, ReadLock, readLockFile } from './contracts-lock-file';
35
+ import { loadContractScenarios } from './normalize-feature-steps';
36
+ import { recordOpaqueAcceptance } from './record-contract-approval';
37
+ import { unverifiedApprovals } from './verify-approval-decisions';
38
+
39
+ /** Accepting reads the traces with `contract check`'s generous deadline, never the guard's ~3 s. */
40
+ const ACCEPT_TRACE_BUDGET_MS = 120_000;
41
+ /** Findings that never hold a scenario back may stand beside the opaque steps. */
42
+ const HARMLESS = new Set(['strengthened', 'nondeterministic']);
43
+
44
+ interface Plan { unitDir: string; unit: string; scenario: ContractScenario; lock: ReadLock; decisionId: string; opaque: OpaqueStep[]; fingerprint: string }
45
+
46
+ const isLow = (detail: string): boolean => detail.startsWith(LOW_IDENTITY_FINDING);
47
+
48
+ function plan(i: ApproveInput, id: string): Plan {
49
+ const unit = resolveContractUnit(i.projectRoot, i.unit);
50
+ const lock = readLockFile(lockPathFor(unit.dir));
51
+ const matches = loadContractScenarios(unit.dir, unit.name).filter((s) => s.id === id);
52
+ if (!matches.length) throw new Error(`--scenario ${id} names no scenario of ${i.unit}`);
53
+ if (matches.length > 1) throw new Error(`Refused: scenario id ${id} is used by ${matches.length} scenarios — an acceptance must name exactly one. Give each its own ID.`);
54
+ const sc = matches[0];
55
+ if (sc.implementation === 'compiled') throw new Error(`Refused: ${id} is compiled — only a free / impl:code test has trace steps to accept.`);
56
+ const entry = lock?.scenarios[id];
57
+ if (!lock || !isHumanApproved(entry) || lock.tampered.includes(id) || entry.hash !== sc.hash) {
58
+ throw new Error(`Refused: ${id} is not approved as it reads now — approve it first (\`sungen contract approve --screen ${i.unit} --scenario ${id}\`), re-run it with a trace, then accept its opaque steps.`);
59
+ }
60
+ // The entry an acceptance re-points must be QA's own: its decision (on disk) vouches for it as it is.
61
+ const [unvouched] = unverifiedApprovals(i.projectRoot, unit.dir, { schema: lock.schema, scenarios: { [id]: entry } }, new Set(), { root: i.projectRoot, timeoutMs: 0, blobs: null });
62
+ if (unvouched) throw new Error(`Refused: the lock entry of ${id} is not vouched for by its decision (${unvouched.detail}) — restore the lock from git, or approve the scenario again.`);
63
+
64
+ const v = buildContractVerdict(i.projectRoot, unit, { traceBudgetMs: ACCEPT_TRACE_BUDGET_MS });
65
+ const bad = v.uncommitted.find((u) => u.id === id && (u.change === 'tampered' || u.change === 'unverified'));
66
+ if (bad) throw new Error(`Refused: the lock entry of ${id} is ${bad.change} (${bad.detail}) — restore it from git before accepting anything.`);
67
+ const r = v.scenarios.find((s) => s.id === id);
68
+ const blocking = (r?.findings ?? []).filter((f) => !HARMLESS.has(f.class) && !(f.class === 'opaque' && !isLow(f.detail)));
69
+ if (blocking.length) {
70
+ const fix = blocking.some((f) => isLow(f.detail))
71
+ ? `run \`sungen contract check --screen ${i.unit} --trace\` (a real browser resolves the identity) first`
72
+ : `settle that first — \`sungen contract check --screen ${i.unit}\` names the fix`;
73
+ throw new Error(`Refused: accepting clears only opaque steps, and ${id} is also held by: ${blocking.map((f) => `${f.class}${f.step ? ` (step ${f.step})` : ''} — ${f.detail}`).join('; ')}. ${fix[0].toUpperCase()}${fix.slice(1)}.`);
74
+ }
75
+ const opaque = r?.trace?.opaque ?? [];
76
+ if (!opaque.length) throw new Error(`Refused: the trace of ${id} has no opaque step — nothing to accept (${r?.class ?? 'not judged'}).`);
77
+ return { unitDir: unit.dir, unit: unit.name, scenario: sc, lock, decisionId: entry.decisionId, opaque, fingerprint: canonicalJson({ lock, hash: sc.hash, opaque }) };
78
+ }
79
+
80
+ const describe = (o: OpaqueStep): string =>
81
+ `${o.accepted ? '=' : '◐'} step ${o.step} opaque ${o.kind === 'assert' ? 'check' : 'step'} "${o.verbatim}"${o.where ? ` at ${o.where}` : ''}`
82
+ + `${o.replaces ? ` — replaces approved ${o.replaces}` : ''}${o.accepted ? ' (accepted before)' : ''}`;
83
+
84
+ export async function acceptOpaqueSteps(i: ApproveInput): Promise<ApproveResult> {
85
+ const id = i.scenario;
86
+ if (!id) throw new Error('--accept-opaque needs --scenario <id>: an acceptance names the one scenario whose opaque steps QA reviewed');
87
+ const before = plan(i, id);
88
+ const lockPath = lockPathFor(before.unitDir);
89
+ if (before.opaque.every((o) => o.accepted)) return { status: 'nothing-to-accept', lockPath, approved: [], removed: [] };
90
+
91
+ const pending = before.opaque.filter((o) => !o.accepted);
92
+ await requireTypedConfirmation({
93
+ what: `accept ${pending.length} reviewed opaque step(s) of ${id} (${i.unit}) — steps sungen cannot compare, so they are never checked by code`,
94
+ phrase: id,
95
+ command: formatCommand(['sungen', 'contract', 'approve', '--screen', i.unit, '--scenario', id, '--accept-opaque', ...(i.reason ? ['--reason', i.reason] : [])]),
96
+ summary: [
97
+ ...before.opaque.map(describe),
98
+ `bound to each step as it reads now: a change to it, or a new approval of ${id}, brings it back to review`,
99
+ `${id} stays approved at hash ${before.scenario.hash}; its lock entry moves from decision ${before.decisionId} to the new one`,
100
+ `recorded by: ${gitUserName(i.projectRoot)}`,
101
+ ],
102
+ io: i.io,
103
+ });
104
+
105
+ const after = plan(i, id);
106
+ if (after.fingerprint !== before.fingerprint) {
107
+ throw new Error('Refused: the trace, the feature or the lock changed while you were confirming — nothing was written. Run the command again and review the new summary.');
108
+ }
109
+ const { decisionId } = recordOpaqueAcceptance({
110
+ projectRoot: i.projectRoot, unitDir: after.unitDir, unit: after.unit, scenario: after.scenario, reason: i.reason, lock: after.lock,
111
+ accepted: after.opaque.map((o) => ({ step: o.step, sha: o.sha })),
112
+ });
113
+ return { status: 'accepted', lockPath, decisionId, approved: [id], removed: [], accepted: after.opaque };
114
+ }
@@ -11,25 +11,31 @@
11
11
  * 5. read everything AGAIN: if the feature or the lock moved while the human was reading, what
12
12
  * they confirmed is not what would be written — refuse (L5)
13
13
  * 6. record the decision and the lock (record-contract-approval.ts)
14
+ *
15
+ * `--accept-opaque` (with `--scenario`) is the other human act of this command: accepting the reviewed
16
+ * opaque trace steps of one approved free / impl:code scenario — accept-opaque-steps.ts (#923).
14
17
  */
15
18
  import { ConfirmationIO, formatCommand, requireTypedConfirmation } from '../decisions/human-confirmation';
16
19
  import { gitUserName } from '../decisions/decision-source';
17
20
  import { classifyScenario } from './classify-contract-change';
18
21
  import { canonicalJson } from './contract-hash';
19
- import { ContractScenario, isHumanApproved } from './contract-schema';
22
+ import { acceptOpaqueSteps } from './accept-opaque-steps';
23
+ import { ContractScenario, isHumanApproved, OpaqueStep } from './contract-schema';
20
24
  import { resolveContractUnit } from './contract-units';
21
25
  import { lockPathFor, ReadLock, readLockFile } from './contracts-lock-file';
22
26
  import { dropProposedTags } from './free-feature-blocks';
23
27
  import { contractFeatureFiles, loadContractScenarios } from './normalize-feature-steps';
24
28
  import { ApprovalWrite, checkApprovalSecrets, recordContractApproval } from './record-contract-approval';
25
29
 
26
- export interface ApproveInput { projectRoot: string; unit: string; scenario?: string; reason?: string; io: ConfirmationIO }
30
+ export interface ApproveInput { projectRoot: string; unit: string; scenario?: string; reason?: string; io: ConfirmationIO; acceptOpaque?: boolean }
27
31
  export interface ApproveResult {
28
- status: 'approved' | 'nothing-to-approve';
32
+ status: 'approved' | 'nothing-to-approve' | 'accepted' | 'nothing-to-accept';
29
33
  lockPath: string;
30
34
  decisionId?: string;
31
35
  approved: string[];
32
36
  removed: string[];
37
+ /** `--accept-opaque`: the scenario's opaque steps, all accepted by the new decision. */
38
+ accepted?: OpaqueStep[];
33
39
  }
34
40
 
35
41
  interface Plan { write: ApprovalWrite; lock: ReadLock | null; fingerprint: string }
@@ -62,6 +68,7 @@ function describe(sc: ContractScenario, lock: ReadLock | null): string {
62
68
  }
63
69
 
64
70
  export async function approveContract(i: ApproveInput): Promise<ApproveResult> {
71
+ if (i.acceptOpaque) return acceptOpaqueSteps(i);
65
72
  const before = plan(i);
66
73
  const { approve, removed } = before.write;
67
74
  const lockPath = lockPathFor(before.write.unitDir);
@@ -9,7 +9,7 @@
9
9
  * (added · changed · removed vs HEAD, tampered, unverified), or an APPROVED free /
10
10
  * impl:code scenario with no admissible trace (unproven, also past the deadline) exit 2
11
11
  * review any hash-changed (changed, not weaker — QA re-approves), opaque (a check no code
12
- * can compare, or a target identity that is only `low`), or inconclusive (an
12
+ * can compare and QA has not accepted, or a target identity that is only `low`), or inconclusive (an
13
13
  * approved free scenario's final attempt did not pass); blocks delivery exit 0
14
14
  * pass only match / strengthened / proposed / nondeterministic exit 0
15
15
  *
@@ -64,7 +64,7 @@ function withTrace(results: ScenarioResult[], outcomes: Map<string, TraceOutcome
64
64
  const o = outcomes.get(r.id);
65
65
  if (!o) return r;
66
66
  const cls = severityOf(o.class) > severityOf(r.class) ? o.class : r.class;
67
- return { ...r, class: cls, findings: [...r.findings, ...o.findings], trace: { hashes: o.hashes, runs: o.runs } };
67
+ return { ...r, class: cls, findings: [...r.findings, ...o.findings], trace: { hashes: o.hashes, runs: o.runs, ...(o.opaque.length ? { opaque: o.opaque } : {}) } };
68
68
  });
69
69
  }
70
70
 
@@ -38,11 +38,16 @@ const sha = (s: string | Buffer): string => createHash('sha256').update(s).diges
38
38
  const why = (e: unknown): string => (e instanceof Error ? e.message : String(e)).split('\n')[0].slice(0, 300);
39
39
 
40
40
  export const MOBILE_NOT_SUPPORTED = 'trace conformance is web-only: free / impl:code scenarios of a mobile project are not supported yet (not judged)';
41
- /** The guard path's deadline for the trace part of one unit's verdict (override: SUNGEN_TRACE_VERDICT_BUDGET_MS). */
41
+ /** The Claude Code guard's deadline for the trace part of one unit's verdict (its hook has ~5 s in all). */
42
+ export const GUARD_TRACE_BUDGET_MS = 3_000;
43
+ /** The default deadline (`next`, the guard) — override: SUNGEN_TRACE_VERDICT_BUDGET_MS. */
42
44
  export function defaultTraceBudgetMs(env: Record<string, string | undefined> = process.env): number {
43
45
  const v = Number(env.SUNGEN_TRACE_VERDICT_BUDGET_MS);
44
- return Number.isFinite(v) && v > 0 ? v : 3_000;
46
+ return Number.isFinite(v) && v > 0 ? v : GUARD_TRACE_BUDGET_MS;
45
47
  }
48
+ /** Inside the guard path the override may only SHORTEN the deadline (#926): the hook cannot wait longer. */
49
+ export const guardTraceBudgetMs = (env: Record<string, string | undefined> = process.env): number =>
50
+ Math.min(defaultTraceBudgetMs(env), GUARD_TRACE_BUDGET_MS);
46
51
 
47
52
  export function traceConformanceForUnit(
48
53
  projectRoot: string, unit: { name: string; dir: string }, current: ContractScenario[], lock: ContractLock | null,
@@ -61,7 +66,7 @@ export function traceConformanceForUnit(
61
66
  let setupError = '';
62
67
  try {
63
68
  const notBefore = Math.max(mtimeMs(lockPathFor(unit.dir)), ...contractFeatureFiles(unit.dir, unit.name).map(mtimeMs));
64
- evidence = collectScenarioEvidence(projectRoot, new Set(traced.map((s) => s.id)), notBefore, deadline);
69
+ evidence = collectScenarioEvidence(projectRoot, new Set(traced.map((s) => s.id)), notBefore, deadline, new Map(traced.map((s) => [s.id, s.source.name])));
65
70
  index = loadTestDataIndex(unit.dir, unit.name);
66
71
  } catch (e) { setupError = `trace conformance could not run: ${why(e)}`; }
67
72
  const { cache, problem } = readIdentityCache(projectRoot);
@@ -14,12 +14,12 @@
14
14
  * still `hash-changed`: equal hashes are the only road to `match`.
15
15
  */
16
16
  import { sameJson } from './contract-hash';
17
- import { ContractScenario, ContractStep, FindingClass, LadderClass, LockEntry, RULE_OF, ScenarioClass, TraceClass } from './contract-schema';
17
+ import { ContractScenario, ContractStep, FindingClass, LadderClass, LockEntry, OpaqueStep, RULE_OF, ScenarioClass, TraceClass } from './contract-schema';
18
18
  import { compareAsserts } from './oracle-strength';
19
19
 
20
20
  export interface ContractFinding { class: FindingClass; rule?: string; detail: string; step?: number }
21
- /** What a free / impl:code scenario's traces fingerprinted to (DOS-14.6) — output only. */
22
- export interface TraceSummary { hashes: string[]; runs: string[] }
21
+ /** What a free / impl:code scenario's traces fingerprinted to (DOS-14.6), and their opaque steps (#923) — output only. */
22
+ export interface TraceSummary { hashes: string[]; runs: string[]; opaque?: OpaqueStep[] }
23
23
  export interface ScenarioResult { id: string; class: ScenarioClass; findings: ContractFinding[]; file?: string; trace?: TraceSummary }
24
24
 
25
25
  const SEVERITY: Record<ScenarioClass, number> = {