@sun-asterisk/sungen 3.2.15 → 3.2.16-beta.1

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 (84) hide show
  1. package/dist/cli/commands/delivery.d.ts.map +1 -1
  2. package/dist/cli/commands/delivery.js +138 -1
  3. package/dist/cli/commands/delivery.js.map +1 -1
  4. package/dist/dashboard/templates/index.html +1 -1
  5. package/dist/exporters/feature-parser.js +1 -1
  6. package/dist/exporters/feature-parser.js.map +1 -1
  7. package/dist/exporters/matrix/build.d.ts +36 -0
  8. package/dist/exporters/matrix/build.d.ts.map +1 -0
  9. package/dist/exporters/matrix/build.js +267 -0
  10. package/dist/exporters/matrix/build.js.map +1 -0
  11. package/dist/exporters/matrix/export.d.ts +47 -0
  12. package/dist/exporters/matrix/export.d.ts.map +1 -0
  13. package/dist/exporters/matrix/export.js +136 -0
  14. package/dist/exporters/matrix/export.js.map +1 -0
  15. package/dist/exporters/matrix/fingerprint.d.ts +20 -0
  16. package/dist/exporters/matrix/fingerprint.d.ts.map +1 -0
  17. package/dist/exporters/matrix/fingerprint.js +83 -0
  18. package/dist/exporters/matrix/fingerprint.js.map +1 -0
  19. package/dist/exporters/matrix/gates.d.ts +21 -0
  20. package/dist/exporters/matrix/gates.d.ts.map +1 -0
  21. package/dist/exporters/matrix/gates.js +258 -0
  22. package/dist/exporters/matrix/gates.js.map +1 -0
  23. package/dist/exporters/matrix/map-loader.d.ts +22 -0
  24. package/dist/exporters/matrix/map-loader.d.ts.map +1 -0
  25. package/dist/exporters/matrix/map-loader.js +173 -0
  26. package/dist/exporters/matrix/map-loader.js.map +1 -0
  27. package/dist/exporters/matrix/render-csv.d.ts +8 -0
  28. package/dist/exporters/matrix/render-csv.d.ts.map +1 -0
  29. package/dist/exporters/matrix/render-csv.js +69 -0
  30. package/dist/exporters/matrix/render-csv.js.map +1 -0
  31. package/dist/exporters/matrix/render-xlsx.d.ts +17 -0
  32. package/dist/exporters/matrix/render-xlsx.d.ts.map +1 -0
  33. package/dist/exporters/matrix/render-xlsx.js +298 -0
  34. package/dist/exporters/matrix/render-xlsx.js.map +1 -0
  35. package/dist/exporters/matrix/types.d.ts +153 -0
  36. package/dist/exporters/matrix/types.d.ts.map +1 -0
  37. package/dist/exporters/matrix/types.js +15 -0
  38. package/dist/exporters/matrix/types.js.map +1 -0
  39. package/dist/exporters/scenario-merger.js +1 -1
  40. package/dist/exporters/scenario-merger.js.map +1 -1
  41. package/dist/exporters/spec-parser.js +1 -1
  42. package/dist/exporters/spec-parser.js.map +1 -1
  43. package/dist/exporters/xlsx-report-builder.d.ts +1 -1
  44. package/dist/exporters/xlsx-report-builder.d.ts.map +1 -1
  45. package/dist/exporters/xlsx-report-builder.js +3 -3
  46. package/dist/exporters/xlsx-report-builder.js.map +1 -1
  47. package/dist/harness/audit.d.ts.map +1 -1
  48. package/dist/harness/audit.js +6 -1
  49. package/dist/harness/audit.js.map +1 -1
  50. package/dist/harness/capability.d.ts +25 -0
  51. package/dist/harness/capability.d.ts.map +1 -1
  52. package/dist/harness/capability.js +44 -2
  53. package/dist/harness/capability.js.map +1 -1
  54. package/dist/orchestrator/templates/ai-src/commands/create-test.md +1 -1
  55. package/dist/orchestrator/templates/ai-src/commands/delivery.md +118 -120
  56. package/dist/orchestrator/templates/ai-src/config/claude.md +1 -1
  57. package/dist/orchestrator/templates/ai-src/config/copilot.md +1 -1
  58. package/dist/orchestrator/templates/ai-src/skills/sungen-delivery/SKILL.md +36 -6
  59. package/dist/orchestrator/templates/ai-src/skills/sungen-harness-audit/SKILL.md +1 -1
  60. package/dist/orchestrator/templates/ai-src/skills/sungen-tc-generation/SKILL.md +1 -0
  61. package/package.json +4 -4
  62. package/src/cli/commands/delivery.ts +168 -2
  63. package/src/dashboard/templates/index.html +1 -1
  64. package/src/exporters/feature-parser.ts +1 -1
  65. package/src/exporters/matrix/build.ts +294 -0
  66. package/src/exporters/matrix/export.ts +124 -0
  67. package/src/exporters/matrix/fingerprint.ts +49 -0
  68. package/src/exporters/matrix/gates.ts +284 -0
  69. package/src/exporters/matrix/map-loader.ts +142 -0
  70. package/src/exporters/matrix/render-csv.ts +71 -0
  71. package/src/exporters/matrix/render-xlsx.ts +289 -0
  72. package/src/exporters/matrix/types.ts +176 -0
  73. package/src/exporters/scenario-merger.ts +1 -1
  74. package/src/exporters/spec-parser.ts +1 -1
  75. package/src/exporters/xlsx-report-builder.ts +3 -2
  76. package/src/harness/audit.ts +7 -2
  77. package/src/harness/capability.ts +53 -3
  78. package/src/orchestrator/templates/ai-src/commands/create-test.md +1 -1
  79. package/src/orchestrator/templates/ai-src/commands/delivery.md +118 -120
  80. package/src/orchestrator/templates/ai-src/config/claude.md +1 -1
  81. package/src/orchestrator/templates/ai-src/config/copilot.md +1 -1
  82. package/src/orchestrator/templates/ai-src/skills/sungen-delivery/SKILL.md +36 -6
  83. package/src/orchestrator/templates/ai-src/skills/sungen-harness-audit/SKILL.md +1 -1
  84. package/src/orchestrator/templates/ai-src/skills/sungen-tc-generation/SKILL.md +1 -0
@@ -0,0 +1,284 @@
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 { CoverageVariant, MatrixFinding, MAX_VARIANTS_PER_ITEM } from './types';
16
+ import { expandMapRef, BuildInputs } from './build';
17
+
18
+ export interface GateContext {
19
+ inputs: BuildInputs;
20
+ variants: CoverageVariant[];
21
+ variantsByVp: Map<string, CoverageVariant[]>;
22
+ }
23
+
24
+ export function runGates(ctx: GateContext): MatrixFinding[] {
25
+ const findings: MatrixFinding[] = [];
26
+ gateASource(ctx, findings);
27
+ gateBMapping(ctx, findings);
28
+ gateCAggregation(ctx, findings);
29
+ gateDExecutability(ctx, findings);
30
+ gateEDrift(ctx, findings);
31
+ gateGReviewState(ctx, findings);
32
+ return findings;
33
+ }
34
+
35
+ // --- Gate A — source quality ------------------------------------------------
36
+
37
+ function gateASource(ctx: GateContext, findings: MatrixFinding[]): void {
38
+ const { feature, merged } = ctx.inputs;
39
+
40
+ if (feature.backgroundWhenSteps.length > 0 || feature.backgroundThenSteps.length > 0) {
41
+ findings.push({
42
+ gate: 'A', severity: 'error',
43
+ message: 'Background contains When/Then steps — setup only; move the action/oracle into scenarios',
44
+ });
45
+ }
46
+
47
+ const seen = new Map<string, number>();
48
+ for (const m of merged) {
49
+ const { vpId } = splitVpAndName(m.feature.name);
50
+ if (!vpId) {
51
+ findings.push({
52
+ gate: 'A', severity: 'error', ref: m.feature.name,
53
+ message: `scenario "${m.feature.name}" has no VP-id prefix — matrix variants must be addressable`,
54
+ });
55
+ continue;
56
+ }
57
+ seen.set(vpId, (seen.get(vpId) ?? 0) + 1);
58
+
59
+ const isManual = extractTestcaseType(m.feature.tags) === 'Manual';
60
+ if (m.resolvedExpected.length === 0) {
61
+ findings.push({
62
+ gate: 'A', severity: 'error', ref: vpId,
63
+ message: isManual
64
+ ? `manual scenario ${vpId} has no observable oracle (no Then steps and no Observable/Oracle comment lines)`
65
+ : `scenario ${vpId} has no Then step — a variant without an observable oracle cannot be delivered`,
66
+ });
67
+ }
68
+ }
69
+ for (const [vpId, n] of seen) {
70
+ if (n > 1) findings.push({ gate: 'A', severity: 'error', ref: vpId, message: `duplicate VP-id ${vpId} (${n} scenarios)` });
71
+ }
72
+ }
73
+
74
+ // --- Gate B — mapping completeness -------------------------------------------
75
+
76
+ function gateBMapping(ctx: GateContext, findings: MatrixFinding[]): void {
77
+ const { map } = ctx.inputs;
78
+ const { variants, variantsByVp } = ctx;
79
+
80
+ // Where each derived variant landed: 0 → unmapped, >1 → double-mapped.
81
+ const owners = new Map<string, string[]>();
82
+ for (const g of map.groups) {
83
+ for (const ref of g.variants) {
84
+ const expanded = expandMapRef(ref, variantsByVp);
85
+ if (expanded.length === 0) {
86
+ findings.push({
87
+ gate: 'B', severity: 'error', ref: g.id,
88
+ message: `group ${g.id} references ${ref} which matches no scenario/@cases row in the .feature`,
89
+ });
90
+ continue;
91
+ }
92
+ for (const v of expanded) {
93
+ const list = owners.get(v.ref) ?? [];
94
+ list.push(g.id);
95
+ owners.set(v.ref, list);
96
+ }
97
+ }
98
+ }
99
+
100
+ for (const [ref, groups] of owners) {
101
+ if (groups.length > 1) {
102
+ findings.push({
103
+ gate: 'B', severity: 'error', ref,
104
+ message: `variant ${ref} belongs to ${groups.length} groups (${groups.join(', ')}) — exactly one required`,
105
+ });
106
+ }
107
+ }
108
+
109
+ for (const v of variants) {
110
+ const grouped = owners.has(v.ref);
111
+ const disposed = v.vpId in map.dispositions;
112
+ if (!grouped && !disposed) {
113
+ findings.push({
114
+ gate: 'B', severity: 'error', ref: v.ref,
115
+ message: `variant ${v.ref} is in no group and has no disposition — 100% source disposition is required`,
116
+ });
117
+ }
118
+ if (grouped && disposed) {
119
+ findings.push({
120
+ gate: 'B', severity: 'error', ref: v.ref,
121
+ message: `variant ${v.ref} is grouped AND disposed (${map.dispositions[v.vpId].as}) — pick one`,
122
+ });
123
+ }
124
+ }
125
+
126
+ for (const vpId of Object.keys(map.dispositions)) {
127
+ if (!variantsByVp.has(vpId)) {
128
+ findings.push({
129
+ gate: 'B', severity: 'warning', ref: vpId,
130
+ message: `disposition for ${vpId} matches no scenario (stale entry?)`,
131
+ });
132
+ }
133
+ }
134
+ }
135
+
136
+ // --- Gate C — aggregation safety ---------------------------------------------
137
+
138
+ function gateCAggregation(ctx: GateContext, findings: MatrixFinding[]): void {
139
+ const { map } = ctx.inputs;
140
+ const { variantsByVp } = ctx;
141
+
142
+ for (const g of map.groups) {
143
+ const vs = g.variants.flatMap((ref) => expandMapRef(ref, variantsByVp));
144
+ if (vs.length <= 1) continue;
145
+
146
+ // Approval IS the QA confirmation of the heuristic parts (oracle family,
147
+ // precondition equivalence, sequence safety) — once approved AND unchanged
148
+ // (fingerprints intact), only the hard signature checks keep firing. A
149
+ // drifted variant re-opens the heuristics (Gate E flips the item to
150
+ // proposed at the same time).
151
+ const stale = vs.some((v) => {
152
+ const stamped = map.fingerprints[v.ref] ?? map.fingerprints[v.vpId];
153
+ return !stamped || stamped !== v.fingerprint;
154
+ });
155
+ const heuristicsConfirmed = g.review === 'approved' && !stale;
156
+
157
+ // Hard signature parts — recomputed, never trusted from the map. ERROR on mismatch.
158
+ const hard: Array<[string, (v: CoverageVariant) => string]> = [
159
+ ['execution mode', (v) => v.mode],
160
+ ['test layer', (v) => [...v.layers].sort().join('+')],
161
+ ['priority', (v) => v.priority],
162
+ ];
163
+ for (const [label, keyOf] of hard) {
164
+ const distinct = new Set(vs.map(keyOf));
165
+ if (distinct.size > 1) {
166
+ findings.push({
167
+ gate: 'C', severity: 'error', ref: g.id,
168
+ message: `group ${g.id} mixes ${label}s (${[...distinct].join(' vs ')}) — mandatory split`,
169
+ });
170
+ }
171
+ }
172
+
173
+ // Heuristic signature parts — REVIEW_REQUIRED (equivalence was inferred, not declared).
174
+ const preProfiles = new Set(vs.map((v) => v.preconditionProfile));
175
+ if (!heuristicsConfirmed && preProfiles.size > 1) {
176
+ findings.push({
177
+ gate: 'C', severity: 'review', ref: g.id,
178
+ message: `group ${g.id} variants have different precondition profiles — confirm the grouping is safe or split`,
179
+ });
180
+ }
181
+ const oracleShapes = new Set(vs.map((v) => v.oracleShape.join(' ; ')));
182
+ if (!heuristicsConfirmed && oracleShapes.size > 1) {
183
+ findings.push({
184
+ gate: 'C', severity: 'review', ref: g.id,
185
+ message: `group ${g.id} variants assert different oracle shapes (${oracleShapes.size} shapes) — confirm they are one oracle family`,
186
+ });
187
+ }
188
+ if (!heuristicsConfirmed && vs.some((v) => v.procedureProfile === 'sequence')) {
189
+ findings.push({
190
+ gate: 'C', severity: 'review', ref: g.id,
191
+ message: `group ${g.id} contains a sequence-sensitive scenario — ordered flows stay solo items unless QA confirms`,
192
+ });
193
+ }
194
+
195
+ if (vs.length > MAX_VARIANTS_PER_ITEM) {
196
+ findings.push({
197
+ gate: 'C', severity: 'warning', ref: g.id,
198
+ message: `group ${g.id} has ${vs.length} variants (> ${MAX_VARIANTS_PER_ITEM}) — consider splitting for reviewability`,
199
+ });
200
+ }
201
+ }
202
+ }
203
+
204
+ // --- Gate D — manual executability -------------------------------------------
205
+
206
+ function gateDExecutability(ctx: GateContext, findings: MatrixFinding[]): void {
207
+ const { map, testData, feature } = ctx.inputs;
208
+ const { variantsByVp } = ctx;
209
+
210
+ for (const g of map.groups) {
211
+ const vs = g.variants.flatMap((ref) => expandMapRef(ref, variantsByVp));
212
+ for (const v of vs) {
213
+ const hasPrecondition = v.precondition.length > 0 || feature.backgroundGivenSteps.length > 0;
214
+ if (!hasPrecondition) {
215
+ findings.push({
216
+ gate: 'D', severity: 'error', ref: v.ref,
217
+ message: `${v.ref}: no precondition (no Background, auth tag, or Given) — a tester cannot establish the start state`,
218
+ });
219
+ }
220
+ if (v.trigger.length === 0) {
221
+ findings.push({
222
+ gate: 'D', severity: 'error', ref: v.ref,
223
+ message: `${v.ref}: no action/trigger (no When steps${v.mode === 'manual' ? ' and no Setup/Action comment lines' : ''})`,
224
+ });
225
+ }
226
+ // Oracle emptiness is Gate A (source) — not repeated here.
227
+ }
228
+ }
229
+
230
+ // Every {{var}} must resolve — data the tester cannot obtain is not executable.
231
+ for (const [vpId, vs] of variantsByVp) {
232
+ const scenario = ctx.inputs.merged.find((m) => splitVpAndName(m.feature.name).vpId === vpId);
233
+ if (!scenario) continue;
234
+ for (const varName of scenario.feature.referencedVars) {
235
+ const inRows = vs.some((v) => v.caseLabel !== undefined); // dataset rows carry their own columns
236
+ if (!inRows && (!testData || !(varName in testData))) {
237
+ findings.push({
238
+ gate: 'D', severity: 'error', ref: vpId,
239
+ message: `${vpId}: {{${varName}}} does not resolve in test-data — the variant is not reproducible`,
240
+ });
241
+ }
242
+ }
243
+ }
244
+ }
245
+
246
+ // --- Gate E — drift (stale approval) ------------------------------------------
247
+
248
+ function gateEDrift(ctx: GateContext, findings: MatrixFinding[]): void {
249
+ const { map } = ctx.inputs;
250
+ const { variantsByVp } = ctx;
251
+
252
+ for (const g of map.groups) {
253
+ if (g.review !== 'approved') continue; // proposed groups are already under review
254
+ for (const ref of g.variants) {
255
+ const vs = expandMapRef(ref, variantsByVp);
256
+ for (const v of vs) {
257
+ const stamped = map.fingerprints[v.ref] ?? map.fingerprints[v.vpId];
258
+ if (!stamped) {
259
+ findings.push({
260
+ gate: 'E', severity: 'review', ref: g.id,
261
+ message: `group ${g.id}: ${v.ref} has no stamped fingerprint — run \`sungen delivery --approve\` after review`,
262
+ });
263
+ } else if (stamped !== v.fingerprint) {
264
+ findings.push({
265
+ gate: 'E', severity: 'review', ref: g.id,
266
+ message: `group ${g.id}: ${v.ref} changed since approval (fingerprint drift) — re-review the grouping`,
267
+ });
268
+ }
269
+ }
270
+ }
271
+ }
272
+ }
273
+
274
+ // --- Gate G — review state -----------------------------------------------------
275
+
276
+ function gateGReviewState(ctx: GateContext, findings: MatrixFinding[]): void {
277
+ const proposed = ctx.inputs.map.groups.filter((g) => g.review !== 'approved');
278
+ if (proposed.length > 0) {
279
+ findings.push({
280
+ gate: 'G', severity: 'review',
281
+ 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`,
282
+ });
283
+ }
284
+ }
@@ -0,0 +1,142 @@
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, 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
+
18
+ export interface MapLoadResult {
19
+ map: DeliveryMap | null;
20
+ /** Structural problems — any entry blocks the matrix path (fix the file first). */
21
+ errors: string[];
22
+ }
23
+
24
+ /** Path of the map file for a unit directory (qa/<kind>/<screen>) + feature basename. */
25
+ export function mapFilePath(unitDir: string, featureBaseName: string): string {
26
+ return path.join(unitDir, 'delivery', `${featureBaseName}.map.yaml`);
27
+ }
28
+
29
+ export function loadDeliveryMap(file: string): MapLoadResult {
30
+ if (!fs.existsSync(file)) return { map: null, errors: [] };
31
+ const errors: string[] = [];
32
+ let raw: unknown;
33
+ try {
34
+ raw = parseYaml(fs.readFileSync(file, 'utf-8'));
35
+ } catch (e) {
36
+ return { map: null, errors: [`map YAML does not parse: ${e instanceof Error ? e.message : e}`] };
37
+ }
38
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw)) {
39
+ return { map: null, errors: ['map root must be a YAML mapping'] };
40
+ }
41
+ const doc = raw as Record<string, unknown>;
42
+
43
+ const groups: MapGroup[] = [];
44
+ const seenIds = new Set<string>();
45
+ const rawGroups = doc.groups;
46
+ if (!Array.isArray(rawGroups) || rawGroups.length === 0) {
47
+ errors.push('map has no `groups` list');
48
+ } else {
49
+ rawGroups.forEach((g, i) => {
50
+ if (!g || typeof g !== 'object') { errors.push(`groups[${i}] is not a mapping`); return; }
51
+ const grp = g as Record<string, unknown>;
52
+ const where = `groups[${i}]${typeof grp.id === 'string' ? ` (${grp.id})` : ''}`;
53
+ for (const field of ['id', 'target', 'intent', 'oracle'] as const) {
54
+ if (typeof grp[field] !== 'string' || !(grp[field] as string).trim()) {
55
+ errors.push(`${where}: missing/empty \`${field}\``);
56
+ }
57
+ }
58
+ if (!CATEGORIES.includes(grp.category as MapCategory)) {
59
+ errors.push(`${where}: \`category\` must be one of ${CATEGORIES.join(' | ')}`);
60
+ }
61
+ const review = (grp.review ?? 'proposed') as ReviewState;
62
+ if (!REVIEW_STATES.includes(review)) {
63
+ errors.push(`${where}: \`review\` must be proposed | approved`);
64
+ }
65
+ const variants = grp.variants;
66
+ if (!Array.isArray(variants) || variants.length === 0 || variants.some((v) => typeof v !== 'string' || !v.trim())) {
67
+ errors.push(`${where}: \`variants\` must be a non-empty list of VP refs`);
68
+ }
69
+ const id = String(grp.id ?? '');
70
+ if (id) {
71
+ if (seenIds.has(id)) errors.push(`duplicate group id \`${id}\``);
72
+ seenIds.add(id);
73
+ }
74
+ groups.push({
75
+ id,
76
+ target: String(grp.target ?? ''),
77
+ intent: String(grp.intent ?? ''),
78
+ oracle: String(grp.oracle ?? ''),
79
+ category: grp.category as MapCategory,
80
+ review,
81
+ variants: Array.isArray(variants) ? variants.map(String) : [],
82
+ });
83
+ });
84
+ }
85
+
86
+ const dispositions: Record<string, MapDisposition> = {};
87
+ if (doc.dispositions !== undefined) {
88
+ if (!doc.dispositions || typeof doc.dispositions !== 'object' || Array.isArray(doc.dispositions)) {
89
+ errors.push('`dispositions` must be a mapping of VP-id → { as, reason }');
90
+ } else {
91
+ for (const [vpId, d] of Object.entries(doc.dispositions as Record<string, unknown>)) {
92
+ const dd = (d && typeof d === 'object' ? d : {}) as Record<string, unknown>;
93
+ if (!DISPOSITIONS.includes(String(dd.as))) {
94
+ errors.push(`dispositions.${vpId}: \`as\` must be one of ${DISPOSITIONS.join(' | ')}`);
95
+ }
96
+ dispositions[vpId] = { as: dd.as as MapDisposition['as'], reason: dd.reason ? String(dd.reason) : undefined };
97
+ }
98
+ }
99
+ }
100
+
101
+ const fingerprints: Record<string, string> = {};
102
+ if (doc.fingerprints && typeof doc.fingerprints === 'object' && !Array.isArray(doc.fingerprints)) {
103
+ for (const [k, v] of Object.entries(doc.fingerprints as Record<string, unknown>)) {
104
+ fingerprints[k] = String(v);
105
+ }
106
+ }
107
+
108
+ const map: DeliveryMap = {
109
+ version: Number(doc.version ?? 1),
110
+ unit: String(doc.unit ?? ''),
111
+ formNo: doc.form_no !== undefined ? String(doc.form_no) : undefined,
112
+ groups,
113
+ dispositions,
114
+ fingerprints,
115
+ };
116
+ return { map: errors.length > 0 ? null : map, errors };
117
+ }
118
+
119
+ /**
120
+ * Write the map back (used by `--approve` to flip review states + stamp fingerprints).
121
+ * Field order is kept stable so approve-diffs stay minimal and reviewable.
122
+ */
123
+ export function writeDeliveryMap(file: string, map: DeliveryMap): void {
124
+ const doc: Record<string, unknown> = {
125
+ version: map.version,
126
+ unit: map.unit,
127
+ ...(map.formNo !== undefined ? { form_no: map.formNo } : {}),
128
+ groups: map.groups.map((g) => ({
129
+ id: g.id,
130
+ target: g.target,
131
+ intent: g.intent,
132
+ oracle: g.oracle,
133
+ category: g.category,
134
+ review: g.review,
135
+ variants: g.variants,
136
+ })),
137
+ ...(Object.keys(map.dispositions).length > 0 ? { dispositions: map.dispositions } : {}),
138
+ ...(Object.keys(map.fingerprints).length > 0 ? { fingerprints: map.fingerprints } : {}),
139
+ };
140
+ fs.mkdirSync(path.dirname(file), { recursive: true });
141
+ fs.writeFileSync(file, stringifyYaml(doc, { lineWidth: 0 }), 'utf-8');
142
+ }
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Flat CSV rendering of the matrix — same model as the workbook, one row per
3
+ * delivery item (`Level: item`) followed by its variant rows (`Level: variant`),
4
+ * so downstream pipelines can re-derive both views from one file.
5
+ */
6
+
7
+ import { statusToTestResult, formatExecutedDate } from '../playwright-report-parser';
8
+ import { MatrixModel } from './types';
9
+
10
+ const HEADERS = [
11
+ 'Level', 'ID', 'Target', 'Test Intent / Condition', 'Category', 'Priority',
12
+ 'Precondition', 'Coverage / Test Data', 'Action / Trigger', 'Expected (Oracle)',
13
+ 'Mode', 'Trace', 'Result', 'Executed Date', 'Note',
14
+ ];
15
+
16
+ function esc(value: string): string {
17
+ if (/[",\n]/.test(value)) return `"${value.replace(/"/g, '""')}"`;
18
+ return value;
19
+ }
20
+
21
+ export function renderMatrixCsv(model: MatrixModel): string {
22
+ const BOM = '\ufeff'; // Excel compatibility (Vietnamese/Japanese content)
23
+ const lines: string[] = [];
24
+ lines.push(`# Test Case & Coverage Matrix — ${model.unit}`);
25
+ lines.push(`# delivery items: ${model.manifest.itemCount} · coverage variants: ${model.manifest.variantCount} · state: ${model.manifest.approvalState}`);
26
+ lines.push(HEADERS.map(esc).join(','));
27
+
28
+ for (const item of model.items) {
29
+ const single = item.variants.length === 1;
30
+ const only = single ? item.variants[0] : undefined;
31
+ lines.push([
32
+ 'item',
33
+ item.id,
34
+ item.target,
35
+ item.intent,
36
+ item.category,
37
+ item.priority,
38
+ item.precondition.join('\n'),
39
+ single ? only!.data.join('\n') : `${item.variants.length} variants`,
40
+ item.trigger.join('\n'),
41
+ item.oracle,
42
+ item.mode === 'manual' ? 'Manual' : 'Auto',
43
+ item.traces.join(' '),
44
+ item.result,
45
+ single ? formatExecutedDate(only!.result?.startTime) : '',
46
+ item.review === 'proposed' ? 'REVIEW REQUIRED' : '',
47
+ ].map(esc).join(','));
48
+
49
+ if (!single) {
50
+ for (const v of item.variants) {
51
+ lines.push([
52
+ 'variant',
53
+ v.ref,
54
+ '',
55
+ v.condition,
56
+ '', '',
57
+ '',
58
+ v.data.join('\n'),
59
+ v.trigger.join('\n'),
60
+ v.oracle.join('\n'),
61
+ v.mode === 'manual' ? 'Manual' : 'Auto',
62
+ v.traces.join(' '),
63
+ v.result ? statusToTestResult(v.result.status) : 'Pending',
64
+ formatExecutedDate(v.result?.startTime),
65
+ v.result?.error ? String(v.result.error).slice(0, 200) : '',
66
+ ].map(esc).join(','));
67
+ }
68
+ }
69
+ }
70
+ return BOM + lines.join('\n') + '\n';
71
+ }