@sun-asterisk/sungen 3.2.16-beta.7 → 3.2.17

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 (95) hide show
  1. package/dist/cli/commands/delivery.d.ts.map +1 -1
  2. package/dist/cli/commands/delivery.js +13 -197
  3. package/dist/cli/commands/delivery.js.map +1 -1
  4. package/dist/cli/commands/ingest.d.ts.map +1 -1
  5. package/dist/cli/commands/ingest.js +56 -4
  6. package/dist/cli/commands/ingest.js.map +1 -1
  7. package/dist/dashboard/templates/index.html +1 -1
  8. package/dist/exporters/feature-parser.js +1 -1
  9. package/dist/exporters/feature-parser.js.map +1 -1
  10. package/dist/exporters/scenario-merger.js +1 -1
  11. package/dist/exporters/scenario-merger.js.map +1 -1
  12. package/dist/exporters/spec-parser.js +1 -1
  13. package/dist/exporters/spec-parser.js.map +1 -1
  14. package/dist/exporters/xlsx-report-builder.d.ts +1 -1
  15. package/dist/exporters/xlsx-report-builder.d.ts.map +1 -1
  16. package/dist/exporters/xlsx-report-builder.js +3 -3
  17. package/dist/exporters/xlsx-report-builder.js.map +1 -1
  18. package/dist/generators/test-generator/adapters/playwright/templates/steps/actions/click-action.hbs +1 -1
  19. package/dist/generators/test-generator/adapters/playwright/templates/steps/actions/click-element-with-text.hbs +1 -1
  20. package/dist/generators/test-generator/adapters/playwright/templates/steps/navigation/wait-timeout.hbs +1 -1
  21. package/dist/generators/test-generator/utils/runtime-data-transformer.d.ts.map +1 -1
  22. package/dist/generators/test-generator/utils/runtime-data-transformer.js +28 -17
  23. package/dist/generators/test-generator/utils/runtime-data-transformer.js.map +1 -1
  24. package/dist/ingest/legacy-parser.d.ts +3 -0
  25. package/dist/ingest/legacy-parser.d.ts.map +1 -1
  26. package/dist/ingest/legacy-parser.js +52 -3
  27. package/dist/ingest/legacy-parser.js.map +1 -1
  28. package/dist/orchestrator/templates/ai-src/commands/delivery.md +120 -202
  29. package/dist/orchestrator/templates/ai-src/config/claude.md +1 -1
  30. package/dist/orchestrator/templates/ai-src/config/copilot.md +1 -1
  31. package/dist/orchestrator/templates/ai-src/skills/sungen-delivery/SKILL.md +6 -92
  32. package/dist/orchestrator/templates/ai-src/skills/sungen-gherkin-syntax/SKILL.md +7 -0
  33. package/package.json +4 -4
  34. package/src/cli/commands/delivery.ts +15 -227
  35. package/src/cli/commands/ingest.ts +57 -5
  36. package/src/dashboard/templates/index.html +1 -1
  37. package/src/exporters/feature-parser.ts +1 -1
  38. package/src/exporters/scenario-merger.ts +1 -1
  39. package/src/exporters/spec-parser.ts +1 -1
  40. package/src/exporters/xlsx-report-builder.ts +2 -3
  41. package/src/generators/test-generator/adapters/playwright/templates/steps/actions/click-action.hbs +1 -1
  42. package/src/generators/test-generator/adapters/playwright/templates/steps/actions/click-element-with-text.hbs +1 -1
  43. package/src/generators/test-generator/adapters/playwright/templates/steps/navigation/wait-timeout.hbs +1 -1
  44. package/src/generators/test-generator/utils/runtime-data-transformer.ts +29 -18
  45. package/src/ingest/legacy-parser.ts +48 -3
  46. package/src/orchestrator/templates/ai-src/commands/delivery.md +120 -202
  47. package/src/orchestrator/templates/ai-src/config/claude.md +1 -1
  48. package/src/orchestrator/templates/ai-src/config/copilot.md +1 -1
  49. package/src/orchestrator/templates/ai-src/skills/sungen-delivery/SKILL.md +6 -92
  50. package/src/orchestrator/templates/ai-src/skills/sungen-gherkin-syntax/SKILL.md +7 -0
  51. package/dist/exporters/matrix/build.d.ts +0 -61
  52. package/dist/exporters/matrix/build.d.ts.map +0 -1
  53. package/dist/exporters/matrix/build.js +0 -472
  54. package/dist/exporters/matrix/build.js.map +0 -1
  55. package/dist/exporters/matrix/export.d.ts +0 -50
  56. package/dist/exporters/matrix/export.d.ts.map +0 -1
  57. package/dist/exporters/matrix/export.js +0 -152
  58. package/dist/exporters/matrix/export.js.map +0 -1
  59. package/dist/exporters/matrix/fingerprint.d.ts +0 -20
  60. package/dist/exporters/matrix/fingerprint.d.ts.map +0 -1
  61. package/dist/exporters/matrix/fingerprint.js +0 -83
  62. package/dist/exporters/matrix/fingerprint.js.map +0 -1
  63. package/dist/exporters/matrix/gates.d.ts +0 -21
  64. package/dist/exporters/matrix/gates.d.ts.map +0 -1
  65. package/dist/exporters/matrix/gates.js +0 -358
  66. package/dist/exporters/matrix/gates.js.map +0 -1
  67. package/dist/exporters/matrix/map-loader.d.ts +0 -22
  68. package/dist/exporters/matrix/map-loader.d.ts.map +0 -1
  69. package/dist/exporters/matrix/map-loader.js +0 -193
  70. package/dist/exporters/matrix/map-loader.js.map +0 -1
  71. package/dist/exporters/matrix/render-csv.d.ts +0 -9
  72. package/dist/exporters/matrix/render-csv.d.ts.map +0 -1
  73. package/dist/exporters/matrix/render-csv.js +0 -92
  74. package/dist/exporters/matrix/render-csv.js.map +0 -1
  75. package/dist/exporters/matrix/render-xlsx.d.ts +0 -41
  76. package/dist/exporters/matrix/render-xlsx.d.ts.map +0 -1
  77. package/dist/exporters/matrix/render-xlsx.js +0 -430
  78. package/dist/exporters/matrix/render-xlsx.js.map +0 -1
  79. package/dist/exporters/matrix/types.d.ts +0 -196
  80. package/dist/exporters/matrix/types.d.ts.map +0 -1
  81. package/dist/exporters/matrix/types.js +0 -15
  82. package/dist/exporters/matrix/types.js.map +0 -1
  83. package/dist/exporters/matrix/wording.d.ts +0 -51
  84. package/dist/exporters/matrix/wording.d.ts.map +0 -1
  85. package/dist/exporters/matrix/wording.js +0 -169
  86. package/dist/exporters/matrix/wording.js.map +0 -1
  87. package/src/exporters/matrix/build.ts +0 -503
  88. package/src/exporters/matrix/export.ts +0 -149
  89. package/src/exporters/matrix/fingerprint.ts +0 -49
  90. package/src/exporters/matrix/gates.ts +0 -391
  91. package/src/exporters/matrix/map-loader.ts +0 -163
  92. package/src/exporters/matrix/render-csv.ts +0 -94
  93. package/src/exporters/matrix/render-xlsx.ts +0 -420
  94. package/src/exporters/matrix/types.ts +0 -223
  95. package/src/exporters/matrix/wording.ts +0 -174
@@ -1,49 +0,0 @@
1
- /**
2
- * Canonical scenario fingerprints for the Delivery Map drift detector (Gate E).
3
- *
4
- * A fingerprint hashes what changes the MEANING of a variant: sorted tags + ordered
5
- * step text (+ the dataset row for a @cases variant). Formatting, comments, and
6
- * scenario order do NOT change it. `--approve` stamps these into the map; a later
7
- * mismatch drops the group back to review (stale grouping).
8
- */
9
-
10
- import * as crypto from 'crypto';
11
- import { ScenarioMetadata } from '../types';
12
-
13
- /** Stable stringify: objects get sorted keys so row column order can't shift the hash. */
14
- function canonical(value: unknown): string {
15
- if (value === null || typeof value !== 'object') return JSON.stringify(value);
16
- if (Array.isArray(value)) return `[${value.map(canonical).join(',')}]`;
17
- const obj = value as Record<string, unknown>;
18
- const keys = Object.keys(obj).sort();
19
- return `{${keys.map((k) => `${JSON.stringify(k)}:${canonical(obj[k])}`).join(',')}}`;
20
- }
21
-
22
- function sha1(text: string): string {
23
- return 'sha1:' + crypto.createHash('sha1').update(text, 'utf-8').digest('hex');
24
- }
25
-
26
- /**
27
- * Fingerprint one scenario. Tags are sorted (order is presentation); steps keep
28
- * their order (order is meaning). Manual scenarios include their procedure
29
- * comments — for them the comments ARE the test.
30
- */
31
- export function scenarioFingerprint(sc: ScenarioMetadata, datasetRow?: Record<string, unknown>): string {
32
- const body = canonical({
33
- tags: [...sc.tags].sort(),
34
- steps: sc.orderedSteps.map((s) => `${s.bucket}:${s.text}`),
35
- comments: sc.tags.some((t) => t === '@manual' || t.startsWith('@manual:')) ? (sc.comments ?? []) : [],
36
- row: datasetRow ?? null,
37
- });
38
- return sha1(body);
39
- }
40
-
41
- /** Fingerprint of the whole source (all variants) — manifest `sourceFingerprint`. */
42
- export function combinedFingerprint(parts: string[]): string {
43
- return sha1(canonical([...parts].sort()));
44
- }
45
-
46
- /** Fingerprint of the map's semantic content (groups + dispositions, not stamps). */
47
- export function mapContentFingerprint(groups: unknown, dispositions: unknown): string {
48
- return sha1(canonical({ groups, dispositions }));
49
- }
@@ -1,391 +0,0 @@
1
- /**
2
- * Deterministic quality gates for the Test Case & Coverage Matrix
3
- * (docs/spec/delivery-coverage-matrix-spec.md §6).
4
- *
5
- * Severity behavior:
6
- * error → blocks any render
7
- * review → blocks the official render; `--preview` renders with a DRAFT watermark
8
- * warning → prints + renders
9
- *
10
- * The gates recompute every signature part from the .feature — the map is never
11
- * trusted for derivable facts, only for the semantic fields (target/intent/oracle).
12
- */
13
-
14
- import { splitVpAndName, extractTestcaseType } from '../feature-parser';
15
- import { mapContentFingerprint } from './fingerprint';
16
- import { CoverageVariant, MatrixFinding, MAX_VARIANTS_PER_ITEM } from './types';
17
- import { expandMapRef, BuildInputs } from './build';
18
-
19
- export interface GateContext {
20
- inputs: BuildInputs;
21
- variants: CoverageVariant[];
22
- variantsByVp: Map<string, CoverageVariant[]>;
23
- }
24
-
25
- export function runGates(ctx: GateContext): MatrixFinding[] {
26
- const findings: MatrixFinding[] = [];
27
- gateASource(ctx, findings);
28
- gateBMapping(ctx, findings);
29
- gateCAggregation(ctx, findings);
30
- gateDExecutability(ctx, findings);
31
- gateEDrift(ctx, findings);
32
- gateGReviewState(ctx, findings);
33
- gateWWording(ctx, findings);
34
- gateKCategory(ctx, findings);
35
- return findings;
36
- }
37
-
38
- // --- Gate K — category vs the source viewpoint class -------------------------
39
-
40
- /** VP prefixes whose category is not a judgement call — the source decides it. */
41
- const VP_CATEGORY_RULE: Array<[string, string]> = [
42
- ['SEC', 'security'],
43
- ['NFR', 'nfr'],
44
- ];
45
-
46
- /**
47
- * A `VP-SEC-*` scenario filed under `normal`/`abnormal` empties the Coverage
48
- * sheet's `security` column — the grid then reports a gap the unit does not
49
- * have while hiding the security work it does have. Same for `VP-NFR-*`.
50
- * (normal vs abnormal stays a judgement call and is never checked.)
51
- */
52
- function gateKCategory(ctx: GateContext, findings: MatrixFinding[]): void {
53
- for (const g of ctx.inputs.map.groups) {
54
- const vs = g.variants.flatMap((ref) => expandMapRef(ref, ctx.variantsByVp));
55
- for (const [prefix, expected] of VP_CATEGORY_RULE) {
56
- const hits = vs.filter((v) => v.vpCategory === prefix);
57
- if (hits.length > 0 && g.category !== expected) {
58
- findings.push({
59
- gate: 'K', severity: 'warning', ref: g.id,
60
- message: `group ${g.id} is \`category: ${g.category}\` but ${hits.length}/${vs.length} of its variants are VP-${prefix}-* (${hits.slice(0, 3).map((v) => v.vpId).join(', ')}) — use \`category: ${expected}\` or the Coverage grid's ${expected} column stays empty`,
61
- });
62
- }
63
- }
64
- }
65
- }
66
-
67
- // --- Gate A — source quality ------------------------------------------------
68
-
69
- function gateASource(ctx: GateContext, findings: MatrixFinding[]): void {
70
- const { feature, merged } = ctx.inputs;
71
-
72
- if (feature.backgroundWhenSteps.length > 0 || feature.backgroundThenSteps.length > 0) {
73
- findings.push({
74
- gate: 'A', severity: 'error',
75
- message: 'Background contains When/Then steps — setup only; move the action/oracle into scenarios',
76
- });
77
- }
78
-
79
- const seen = new Map<string, number>();
80
- for (const m of merged) {
81
- const { vpId } = splitVpAndName(m.feature.name);
82
- if (!vpId) {
83
- findings.push({
84
- gate: 'A', severity: 'error', ref: m.feature.name,
85
- message: `scenario "${m.feature.name}" has no VP-id prefix — matrix variants must be addressable`,
86
- });
87
- continue;
88
- }
89
- seen.set(vpId, (seen.get(vpId) ?? 0) + 1);
90
-
91
- const isManual = extractTestcaseType(m.feature.tags) === 'Manual';
92
- if (m.resolvedExpected.length === 0) {
93
- findings.push({
94
- gate: 'A', severity: 'error', ref: vpId,
95
- message: isManual
96
- ? `manual scenario ${vpId} has no observable oracle (no Then steps and no Observable/Oracle comment lines)`
97
- : `scenario ${vpId} has no Then step — a variant without an observable oracle cannot be delivered`,
98
- });
99
- }
100
- }
101
- for (const [vpId, n] of seen) {
102
- if (n > 1) findings.push({ gate: 'A', severity: 'error', ref: vpId, message: `duplicate VP-id ${vpId} (${n} scenarios)` });
103
- }
104
- }
105
-
106
- // --- Gate B — mapping completeness -------------------------------------------
107
-
108
- function gateBMapping(ctx: GateContext, findings: MatrixFinding[]): void {
109
- const { map } = ctx.inputs;
110
- const { variants, variantsByVp } = ctx;
111
-
112
- // Where each derived variant landed: 0 → unmapped, >1 → double-mapped.
113
- const owners = new Map<string, string[]>();
114
- for (const g of map.groups) {
115
- for (const ref of g.variants) {
116
- const expanded = expandMapRef(ref, variantsByVp);
117
- if (expanded.length === 0) {
118
- findings.push({
119
- gate: 'B', severity: 'error', ref: g.id,
120
- message: `group ${g.id} references ${ref} which matches no scenario/@cases row in the .feature`,
121
- });
122
- continue;
123
- }
124
- for (const v of expanded) {
125
- const list = owners.get(v.ref) ?? [];
126
- list.push(g.id);
127
- owners.set(v.ref, list);
128
- }
129
- }
130
- }
131
-
132
- for (const [ref, groups] of owners) {
133
- if (groups.length > 1) {
134
- findings.push({
135
- gate: 'B', severity: 'error', ref,
136
- message: `variant ${ref} belongs to ${groups.length} groups (${groups.join(', ')}) — exactly one required`,
137
- });
138
- }
139
- }
140
-
141
- for (const v of variants) {
142
- const grouped = owners.has(v.ref);
143
- const disposed = v.vpId in map.dispositions;
144
- if (!grouped && !disposed) {
145
- findings.push({
146
- gate: 'B', severity: 'error', ref: v.ref,
147
- message: `variant ${v.ref} is in no group and has no disposition — 100% source disposition is required`,
148
- });
149
- }
150
- if (grouped && disposed) {
151
- findings.push({
152
- gate: 'B', severity: 'error', ref: v.ref,
153
- message: `variant ${v.ref} is grouped AND disposed (${map.dispositions[v.vpId].as}) — pick one`,
154
- });
155
- }
156
- }
157
-
158
- for (const vpId of Object.keys(map.dispositions)) {
159
- if (!variantsByVp.has(vpId)) {
160
- findings.push({
161
- gate: 'B', severity: 'warning', ref: vpId,
162
- message: `disposition for ${vpId} matches no scenario (stale entry?)`,
163
- });
164
- }
165
- }
166
- }
167
-
168
- // --- Gate C — aggregation safety ---------------------------------------------
169
-
170
- function gateCAggregation(ctx: GateContext, findings: MatrixFinding[]): void {
171
- const { map } = ctx.inputs;
172
- const { variantsByVp } = ctx;
173
-
174
- for (const g of map.groups) {
175
- const vs = g.variants.flatMap((ref) => expandMapRef(ref, variantsByVp));
176
- if (vs.length <= 1) continue;
177
-
178
- // Approval IS the QA confirmation of the heuristic parts (oracle family,
179
- // precondition equivalence, sequence safety) — once approved AND unchanged
180
- // (fingerprints intact), only the hard signature checks keep firing. A
181
- // drifted variant re-opens the heuristics (Gate E flips the item to
182
- // proposed at the same time).
183
- const stale = vs.some((v) => {
184
- const stamped = map.fingerprints[v.ref] ?? map.fingerprints[v.vpId];
185
- return !stamped || stamped !== v.fingerprint;
186
- });
187
- const heuristicsConfirmed = g.review === 'approved' && !stale;
188
-
189
- // Hard signature parts — recomputed, never trusted from the map. ERROR on mismatch.
190
- // Execution mode and priority are deliberately NOT here: they are coverage
191
- // dimensions (account states may need seeded manual variants next to auto ones;
192
- // an item takes the highest variant priority) — shown per variant, never split on.
193
- const hard: Array<[string, (v: CoverageVariant) => string]> = [
194
- ['test layer', (v) => [...v.layers].sort().join('+')],
195
- ];
196
- for (const [label, keyOf] of hard) {
197
- const distinct = new Set(vs.map(keyOf));
198
- if (distinct.size > 1) {
199
- findings.push({
200
- gate: 'C', severity: 'error', ref: g.id,
201
- message: `group ${g.id} mixes ${label}s (${[...distinct].join(' vs ')}) — mandatory split`,
202
- });
203
- }
204
- }
205
-
206
- // Heuristic signature parts — REVIEW_REQUIRED (equivalence was inferred, not declared).
207
- const preProfiles = new Set(vs.map((v) => v.preconditionProfile));
208
- if (!heuristicsConfirmed && preProfiles.size > 1) {
209
- findings.push({
210
- gate: 'C', severity: 'review', ref: g.id,
211
- message: `group ${g.id} variants have different precondition profiles — confirm the grouping is safe or split`,
212
- });
213
- }
214
- const oracleShapes = new Set(vs.map((v) => v.oracleShape.join(' ; ')));
215
- if (!heuristicsConfirmed && oracleShapes.size > 1) {
216
- findings.push({
217
- gate: 'C', severity: 'review', ref: g.id,
218
- message: `group ${g.id} variants assert different oracle shapes (${oracleShapes.size} shapes) — confirm they are one oracle family`,
219
- });
220
- }
221
- if (!heuristicsConfirmed && vs.some((v) => v.procedureProfile === 'sequence')) {
222
- findings.push({
223
- gate: 'C', severity: 'review', ref: g.id,
224
- message: `group ${g.id} contains a sequence-sensitive scenario — ordered flows stay solo items unless QA confirms`,
225
- });
226
- }
227
-
228
- if (vs.length > MAX_VARIANTS_PER_ITEM) {
229
- findings.push({
230
- gate: 'C', severity: 'warning', ref: g.id,
231
- message: `group ${g.id} has ${vs.length} variants (> ${MAX_VARIANTS_PER_ITEM}) — consider splitting for reviewability`,
232
- });
233
- }
234
- }
235
- }
236
-
237
- // --- Gate D — manual executability -------------------------------------------
238
-
239
- function gateDExecutability(ctx: GateContext, findings: MatrixFinding[]): void {
240
- const { map, testData, feature } = ctx.inputs;
241
- const { variantsByVp } = ctx;
242
-
243
- for (const g of map.groups) {
244
- const vs = g.variants.flatMap((ref) => expandMapRef(ref, variantsByVp));
245
- for (const v of vs) {
246
- const hasPrecondition = v.precondition.length > 0 || feature.backgroundGivenSteps.length > 0;
247
- if (!hasPrecondition) {
248
- findings.push({
249
- gate: 'D', severity: 'error', ref: v.ref,
250
- message: `${v.ref}: no precondition (no Background, auth tag, or Given) — a tester cannot establish the start state`,
251
- });
252
- }
253
- if (v.trigger.length === 0) {
254
- findings.push({
255
- gate: 'D', severity: 'error', ref: v.ref,
256
- message: `${v.ref}: no action/trigger (no When steps${v.mode === 'manual' ? ' and no Setup/Action comment lines' : ''})`,
257
- });
258
- }
259
- // Oracle emptiness is Gate A (source) — not repeated here.
260
- }
261
- }
262
-
263
- // Every {{var}} must resolve — data the tester cannot obtain is not executable.
264
- for (const [vpId, vs] of variantsByVp) {
265
- const scenario = ctx.inputs.merged.find((m) => splitVpAndName(m.feature.name).vpId === vpId);
266
- if (!scenario) continue;
267
- for (const varName of scenario.feature.referencedVars) {
268
- const inRows = vs.some((v) => v.caseLabel !== undefined); // dataset rows carry their own columns
269
- if (!inRows && (!testData || !(varName in testData))) {
270
- findings.push({
271
- gate: 'D', severity: 'error', ref: vpId,
272
- message: `${vpId}: {{${varName}}} does not resolve in test-data — the variant is not reproducible`,
273
- });
274
- }
275
- }
276
- }
277
-
278
- // No template token may survive into a RENDERED cell (review B-04) — this also
279
- // catches cross-referencing test-data values the one-level resolver couldn't close.
280
- for (const [, vs] of variantsByVp) {
281
- for (const v of vs) {
282
- const rendered = [...v.precondition, ...v.trigger, ...v.oracle, ...v.verification, ...v.data];
283
- const token = rendered.map((t) => t.match(/\{\{[^}]*\}\}/)).find(Boolean);
284
- if (token) {
285
- findings.push({
286
- gate: 'D', severity: 'error', ref: v.ref,
287
- message: `${v.ref}: unresolved template token ${token[0]} remains in the rendered output — the export is not deterministic for a tester`,
288
- });
289
- }
290
- }
291
- }
292
- }
293
-
294
- // --- Gate E — drift (stale approval) ------------------------------------------
295
-
296
- function gateEDrift(ctx: GateContext, findings: MatrixFinding[]): void {
297
- const { map } = ctx.inputs;
298
- const { variantsByVp } = ctx;
299
-
300
- // The map's own semantics (targets/intents/oracles/grouping) are part of what
301
- // was approved — an edit after approval must be re-reviewed, not silently
302
- // published (review GAP-09).
303
- const stampedMap = map.fingerprints.__map__;
304
- const liveMap = mapContentFingerprint(map.groups, map.dispositions);
305
- if (map.groups.some((g) => g.review === 'approved')) {
306
- if (!stampedMap) {
307
- findings.push({
308
- gate: 'E', severity: 'review',
309
- message: 'the delivery map has no stamped content fingerprint — run `sungen delivery --approve` to record the reviewed wording',
310
- });
311
- } else if (stampedMap !== liveMap) {
312
- findings.push({
313
- gate: 'E', severity: 'review',
314
- message: 'the delivery map wording/grouping changed since approval — re-review, then `sungen delivery --approve`',
315
- });
316
- }
317
- }
318
-
319
- for (const g of map.groups) {
320
- if (g.review !== 'approved') continue; // proposed groups are already under review
321
- for (const ref of g.variants) {
322
- const vs = expandMapRef(ref, variantsByVp);
323
- for (const v of vs) {
324
- const stamped = map.fingerprints[v.ref] ?? map.fingerprints[v.vpId];
325
- if (!stamped) {
326
- findings.push({
327
- gate: 'E', severity: 'review', ref: g.id,
328
- message: `group ${g.id}: ${v.ref} has no stamped fingerprint — run \`sungen delivery --approve\` after review`,
329
- });
330
- } else if (stamped !== v.fingerprint) {
331
- findings.push({
332
- gate: 'E', severity: 'review', ref: g.id,
333
- message: `group ${g.id}: ${v.ref} changed since approval (fingerprint drift) — re-review the grouping`,
334
- });
335
- }
336
- }
337
- }
338
- }
339
- }
340
-
341
- // --- Gate W — controlled-language lint on the map's semantic fields --------------
342
-
343
- /** Patterns that make customer-facing wording read machine-generated (review §10). */
344
- const WORDING_SMELLS: Array<[RegExp, string]> = [
345
- [/\{\{[^}]*\}\}/, 'an unresolved {{token}}'],
346
- [/\b(?:Setup|Observable|Oracle):/, 'a generator label (Setup:/Observable:/Oracle:)'],
347
- [/\bUser (?:fill|click|press|see|wait)\b/i, 'DSL phrasing ("User fill/click/see…") — write plain product language'],
348
- [/\[[^\]]+\]/, 'a [selector-style] reference — use the visible UI label'],
349
- ];
350
-
351
- function gateWWording(ctx: GateContext, findings: MatrixFinding[]): void {
352
- for (const g of ctx.inputs.map.groups) {
353
- const variantCount = g.variants.flatMap((ref) => expandMapRef(ref, ctx.variantsByVp)).length;
354
- // Without a digest the parent row can only list variant refs — a reviewer
355
- // then has to expand the item to learn which dimensions it covers.
356
- if (variantCount > 3 && !g.dimensions) {
357
- findings.push({
358
- gate: 'W', severity: 'warning', ref: g.id,
359
- message: `group ${g.id} has ${variantCount} variants and no \`dimensions:\` digest — add a short one (e.g. "required ×3 · format ×9") so the collapsed view stays informative`,
360
- });
361
- }
362
- if (g.dimensions && g.dimensions.length > 120) {
363
- findings.push({
364
- gate: 'W', severity: 'warning', ref: g.id,
365
- message: `group ${g.id} \`dimensions:\` is ${g.dimensions.length} chars — keep the digest short (≤120)`,
366
- });
367
- }
368
- for (const [field, text] of ([['intent', g.intent], ['oracle', g.oracle], ...(g.dimensions ? [['dimensions', g.dimensions] as const] : [])] as const)) {
369
- for (const [re, what] of WORDING_SMELLS) {
370
- if (re.test(text)) {
371
- findings.push({
372
- gate: 'W', severity: 'warning', ref: g.id,
373
- message: `group ${g.id} ${field} contains ${what}`,
374
- });
375
- }
376
- }
377
- }
378
- }
379
- }
380
-
381
- // --- Gate G — review state -----------------------------------------------------
382
-
383
- function gateGReviewState(ctx: GateContext, findings: MatrixFinding[]): void {
384
- const proposed = ctx.inputs.map.groups.filter((g) => g.review !== 'approved');
385
- if (proposed.length > 0) {
386
- findings.push({
387
- gate: 'G', severity: 'review',
388
- message: `${proposed.length} group(s) still \`proposed\` (${proposed.slice(0, 5).map((g) => g.id).join(', ')}${proposed.length > 5 ? ', …' : ''}) — approve them or render with --preview`,
389
- });
390
- }
391
- }
@@ -1,163 +0,0 @@
1
- /**
2
- * Delivery Map loader — `qa/<kind>/<unit>/delivery/<unit>.map.yaml`.
3
- *
4
- * Structural validation only (shape, required fields, enum values, duplicate ids).
5
- * Semantic validation against the .feature is the gates' job (gates.ts) — the loader
6
- * never reads the feature.
7
- */
8
-
9
- import * as fs from 'fs';
10
- import * as path from 'path';
11
- import { parse as parseYaml, stringify as stringifyYaml } from 'yaml';
12
- import { DeliveryMap, MapCategory, MapDisposition, MapGroup, RequirementOverride, RequirementStatus, ReviewState } from './types';
13
-
14
- const CATEGORIES: MapCategory[] = ['normal', 'abnormal', 'security', 'nfr'];
15
- const REVIEW_STATES: ReviewState[] = ['proposed', 'approved'];
16
- const DISPOSITIONS = ['excluded', 'blocked', 'covered_elsewhere', 'accepted_risk'];
17
- const REQUIREMENT_STATUSES: RequirementStatus[] =
18
- ['covered', 'partially_covered', 'covered_elsewhere', 'planned', 'gap', 'not_applicable'];
19
-
20
- export interface MapLoadResult {
21
- map: DeliveryMap | null;
22
- /** Structural problems — any entry blocks the matrix path (fix the file first). */
23
- errors: string[];
24
- }
25
-
26
- /** Path of the map file for a unit directory (qa/<kind>/<screen>) + feature basename. */
27
- export function mapFilePath(unitDir: string, featureBaseName: string): string {
28
- return path.join(unitDir, 'delivery', `${featureBaseName}.map.yaml`);
29
- }
30
-
31
- export function loadDeliveryMap(file: string): MapLoadResult {
32
- if (!fs.existsSync(file)) return { map: null, errors: [] };
33
- const errors: string[] = [];
34
- let raw: unknown;
35
- try {
36
- raw = parseYaml(fs.readFileSync(file, 'utf-8'));
37
- } catch (e) {
38
- return { map: null, errors: [`map YAML does not parse: ${e instanceof Error ? e.message : e}`] };
39
- }
40
- if (!raw || typeof raw !== 'object' || Array.isArray(raw)) {
41
- return { map: null, errors: ['map root must be a YAML mapping'] };
42
- }
43
- const doc = raw as Record<string, unknown>;
44
-
45
- const groups: MapGroup[] = [];
46
- const seenIds = new Set<string>();
47
- const rawGroups = doc.groups;
48
- if (!Array.isArray(rawGroups) || rawGroups.length === 0) {
49
- errors.push('map has no `groups` list');
50
- } else {
51
- rawGroups.forEach((g, i) => {
52
- if (!g || typeof g !== 'object') { errors.push(`groups[${i}] is not a mapping`); return; }
53
- const grp = g as Record<string, unknown>;
54
- const where = `groups[${i}]${typeof grp.id === 'string' ? ` (${grp.id})` : ''}`;
55
- for (const field of ['id', 'target', 'intent', 'oracle'] as const) {
56
- if (typeof grp[field] !== 'string' || !(grp[field] as string).trim()) {
57
- errors.push(`${where}: missing/empty \`${field}\``);
58
- }
59
- }
60
- if (!CATEGORIES.includes(grp.category as MapCategory)) {
61
- errors.push(`${where}: \`category\` must be one of ${CATEGORIES.join(' | ')}`);
62
- }
63
- const review = (grp.review ?? 'proposed') as ReviewState;
64
- if (!REVIEW_STATES.includes(review)) {
65
- errors.push(`${where}: \`review\` must be proposed | approved`);
66
- }
67
- const variants = grp.variants;
68
- if (!Array.isArray(variants) || variants.length === 0 || variants.some((v) => typeof v !== 'string' || !v.trim())) {
69
- errors.push(`${where}: \`variants\` must be a non-empty list of VP refs`);
70
- }
71
- const id = String(grp.id ?? '');
72
- if (id) {
73
- if (seenIds.has(id)) errors.push(`duplicate group id \`${id}\``);
74
- seenIds.add(id);
75
- }
76
- groups.push({
77
- id,
78
- target: String(grp.target ?? ''),
79
- intent: String(grp.intent ?? ''),
80
- oracle: String(grp.oracle ?? ''),
81
- ...(grp.dimensions !== undefined ? { dimensions: String(grp.dimensions) } : {}),
82
- category: grp.category as MapCategory,
83
- review,
84
- variants: Array.isArray(variants) ? variants.map(String) : [],
85
- });
86
- });
87
- }
88
-
89
- const dispositions: Record<string, MapDisposition> = {};
90
- if (doc.dispositions !== undefined) {
91
- if (!doc.dispositions || typeof doc.dispositions !== 'object' || Array.isArray(doc.dispositions)) {
92
- errors.push('`dispositions` must be a mapping of VP-id → { as, reason }');
93
- } else {
94
- for (const [vpId, d] of Object.entries(doc.dispositions as Record<string, unknown>)) {
95
- const dd = (d && typeof d === 'object' ? d : {}) as Record<string, unknown>;
96
- if (!DISPOSITIONS.includes(String(dd.as))) {
97
- errors.push(`dispositions.${vpId}: \`as\` must be one of ${DISPOSITIONS.join(' | ')}`);
98
- }
99
- dispositions[vpId] = { as: dd.as as MapDisposition['as'], reason: dd.reason ? String(dd.reason) : undefined };
100
- }
101
- }
102
- }
103
-
104
- const requirements: Record<string, RequirementOverride> = {};
105
- if (doc.requirements !== undefined) {
106
- if (!doc.requirements || typeof doc.requirements !== 'object' || Array.isArray(doc.requirements)) {
107
- errors.push('`requirements` must be a mapping of requirement-id → { status, note }');
108
- } else {
109
- for (const [reqId, r] of Object.entries(doc.requirements as Record<string, unknown>)) {
110
- const rr = (r && typeof r === 'object' ? r : {}) as Record<string, unknown>;
111
- if (!REQUIREMENT_STATUSES.includes(String(rr.status) as RequirementStatus)) {
112
- errors.push(`requirements.${reqId}: \`status\` must be one of ${REQUIREMENT_STATUSES.join(' | ')}`);
113
- }
114
- requirements[reqId] = { status: rr.status as RequirementStatus, note: rr.note ? String(rr.note) : undefined };
115
- }
116
- }
117
- }
118
-
119
- const fingerprints: Record<string, string> = {};
120
- if (doc.fingerprints && typeof doc.fingerprints === 'object' && !Array.isArray(doc.fingerprints)) {
121
- for (const [k, v] of Object.entries(doc.fingerprints as Record<string, unknown>)) {
122
- fingerprints[k] = String(v);
123
- }
124
- }
125
-
126
- const map: DeliveryMap = {
127
- version: Number(doc.version ?? 1),
128
- unit: String(doc.unit ?? ''),
129
- formNo: doc.form_no !== undefined ? String(doc.form_no) : undefined,
130
- groups,
131
- dispositions,
132
- requirements,
133
- fingerprints,
134
- };
135
- return { map: errors.length > 0 ? null : map, errors };
136
- }
137
-
138
- /**
139
- * Write the map back (used by `--approve` to flip review states + stamp fingerprints).
140
- * Field order is kept stable so approve-diffs stay minimal and reviewable.
141
- */
142
- export function writeDeliveryMap(file: string, map: DeliveryMap): void {
143
- const doc: Record<string, unknown> = {
144
- version: map.version,
145
- unit: map.unit,
146
- ...(map.formNo !== undefined ? { form_no: map.formNo } : {}),
147
- groups: map.groups.map((g) => ({
148
- id: g.id,
149
- target: g.target,
150
- intent: g.intent,
151
- oracle: g.oracle,
152
- ...(g.dimensions !== undefined ? { dimensions: g.dimensions } : {}),
153
- category: g.category,
154
- review: g.review,
155
- variants: g.variants,
156
- })),
157
- ...(Object.keys(map.dispositions).length > 0 ? { dispositions: map.dispositions } : {}),
158
- ...(Object.keys(map.requirements).length > 0 ? { requirements: map.requirements } : {}),
159
- ...(Object.keys(map.fingerprints).length > 0 ? { fingerprints: map.fingerprints } : {}),
160
- };
161
- fs.mkdirSync(path.dirname(file), { recursive: true });
162
- fs.writeFileSync(file, stringifyYaml(doc, { lineWidth: 0 }), 'utf-8');
163
- }