@sun-asterisk/sungen 3.2.14 → 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.
- package/dist/cli/commands/delivery.d.ts.map +1 -1
- package/dist/cli/commands/delivery.js +167 -51
- package/dist/cli/commands/delivery.js.map +1 -1
- package/dist/dashboard/snapshot-builder.d.ts.map +1 -1
- package/dist/dashboard/snapshot-builder.js +3 -46
- package/dist/dashboard/snapshot-builder.js.map +1 -1
- package/dist/dashboard/templates/index.html +1 -1
- package/dist/exporters/feature-parser.js +1 -1
- package/dist/exporters/feature-parser.js.map +1 -1
- package/dist/exporters/locale-variants.d.ts +38 -0
- package/dist/exporters/locale-variants.d.ts.map +1 -0
- package/dist/exporters/locale-variants.js +159 -0
- package/dist/exporters/locale-variants.js.map +1 -0
- package/dist/exporters/matrix/build.d.ts +36 -0
- package/dist/exporters/matrix/build.d.ts.map +1 -0
- package/dist/exporters/matrix/build.js +267 -0
- package/dist/exporters/matrix/build.js.map +1 -0
- package/dist/exporters/matrix/export.d.ts +47 -0
- package/dist/exporters/matrix/export.d.ts.map +1 -0
- package/dist/exporters/matrix/export.js +136 -0
- package/dist/exporters/matrix/export.js.map +1 -0
- package/dist/exporters/matrix/fingerprint.d.ts +20 -0
- package/dist/exporters/matrix/fingerprint.d.ts.map +1 -0
- package/dist/exporters/matrix/fingerprint.js +83 -0
- package/dist/exporters/matrix/fingerprint.js.map +1 -0
- package/dist/exporters/matrix/gates.d.ts +21 -0
- package/dist/exporters/matrix/gates.d.ts.map +1 -0
- package/dist/exporters/matrix/gates.js +258 -0
- package/dist/exporters/matrix/gates.js.map +1 -0
- package/dist/exporters/matrix/map-loader.d.ts +22 -0
- package/dist/exporters/matrix/map-loader.d.ts.map +1 -0
- package/dist/exporters/matrix/map-loader.js +173 -0
- package/dist/exporters/matrix/map-loader.js.map +1 -0
- package/dist/exporters/matrix/render-csv.d.ts +8 -0
- package/dist/exporters/matrix/render-csv.d.ts.map +1 -0
- package/dist/exporters/matrix/render-csv.js +69 -0
- package/dist/exporters/matrix/render-csv.js.map +1 -0
- package/dist/exporters/matrix/render-xlsx.d.ts +17 -0
- package/dist/exporters/matrix/render-xlsx.d.ts.map +1 -0
- package/dist/exporters/matrix/render-xlsx.js +298 -0
- package/dist/exporters/matrix/render-xlsx.js.map +1 -0
- package/dist/exporters/matrix/types.d.ts +153 -0
- package/dist/exporters/matrix/types.d.ts.map +1 -0
- package/dist/exporters/matrix/types.js +15 -0
- package/dist/exporters/matrix/types.js.map +1 -0
- package/dist/exporters/scenario-merger.js +1 -1
- package/dist/exporters/scenario-merger.js.map +1 -1
- package/dist/exporters/spec-parser.js +1 -1
- package/dist/exporters/spec-parser.js.map +1 -1
- package/dist/exporters/xlsx-report-builder.d.ts +1 -1
- package/dist/exporters/xlsx-report-builder.d.ts.map +1 -1
- package/dist/exporters/xlsx-report-builder.js +3 -3
- package/dist/exporters/xlsx-report-builder.js.map +1 -1
- package/dist/generators/test-generator/adapters/playwright/templates/steps/assertions/table-match-data.hbs +3 -11
- package/dist/generators/test-generator/adapters/playwright/templates/steps/assertions/table-row-exists.hbs +11 -1
- package/dist/generators/test-generator/code-generator.js +1 -1
- package/dist/generators/test-generator/code-generator.js.map +1 -1
- package/dist/generators/test-generator/diagnostics.d.ts +4 -1
- package/dist/generators/test-generator/diagnostics.d.ts.map +1 -1
- package/dist/generators/test-generator/diagnostics.js +3 -0
- package/dist/generators/test-generator/diagnostics.js.map +1 -1
- package/dist/generators/test-generator/step-mapper.d.ts +6 -0
- package/dist/generators/test-generator/step-mapper.d.ts.map +1 -1
- package/dist/generators/test-generator/step-mapper.js +41 -2
- package/dist/generators/test-generator/step-mapper.js.map +1 -1
- package/dist/harness/annotation-overrides.d.ts +4 -1
- package/dist/harness/annotation-overrides.d.ts.map +1 -1
- package/dist/harness/annotation-overrides.js +5 -2
- package/dist/harness/annotation-overrides.js.map +1 -1
- package/dist/harness/audit.d.ts.map +1 -1
- package/dist/harness/audit.js +6 -1
- package/dist/harness/audit.js.map +1 -1
- package/dist/harness/capability.d.ts +25 -0
- package/dist/harness/capability.d.ts.map +1 -1
- package/dist/harness/capability.js +44 -2
- package/dist/harness/capability.js.map +1 -1
- package/dist/harness/quality-gates.d.ts.map +1 -1
- package/dist/harness/quality-gates.js +5 -0
- package/dist/harness/quality-gates.js.map +1 -1
- package/dist/orchestrator/templates/ai-src/commands/create-test.md +1 -1
- package/dist/orchestrator/templates/ai-src/commands/delivery.md +118 -120
- package/dist/orchestrator/templates/ai-src/config/claude.md +1 -1
- package/dist/orchestrator/templates/ai-src/config/copilot.md +1 -1
- package/dist/orchestrator/templates/ai-src/skills/sungen-delivery/SKILL.md +43 -7
- package/dist/orchestrator/templates/ai-src/skills/sungen-error-mapping/SKILL.md +1 -0
- package/dist/orchestrator/templates/ai-src/skills/sungen-gherkin-syntax/SKILL.md +8 -0
- package/dist/orchestrator/templates/ai-src/skills/sungen-harness-audit/SKILL.md +1 -1
- package/dist/orchestrator/templates/ai-src/skills/sungen-locale/SKILL.md +8 -0
- package/dist/orchestrator/templates/ai-src/skills/sungen-tc-generation/SKILL.md +1 -0
- package/dist/orchestrator/templates/specs-test-data.ts +13 -4
- package/package.json +4 -4
- package/src/cli/commands/delivery.ts +199 -71
- package/src/dashboard/snapshot-builder.ts +11 -61
- package/src/dashboard/templates/index.html +1 -1
- package/src/exporters/feature-parser.ts +1 -1
- package/src/exporters/locale-variants.ts +157 -0
- package/src/exporters/matrix/build.ts +294 -0
- package/src/exporters/matrix/export.ts +124 -0
- package/src/exporters/matrix/fingerprint.ts +49 -0
- package/src/exporters/matrix/gates.ts +284 -0
- package/src/exporters/matrix/map-loader.ts +142 -0
- package/src/exporters/matrix/render-csv.ts +71 -0
- package/src/exporters/matrix/render-xlsx.ts +289 -0
- package/src/exporters/matrix/types.ts +176 -0
- package/src/exporters/scenario-merger.ts +1 -1
- package/src/exporters/spec-parser.ts +1 -1
- package/src/exporters/xlsx-report-builder.ts +3 -2
- package/src/generators/test-generator/adapters/playwright/templates/steps/assertions/table-match-data.hbs +3 -11
- package/src/generators/test-generator/adapters/playwright/templates/steps/assertions/table-row-exists.hbs +11 -1
- package/src/generators/test-generator/code-generator.ts +1 -1
- package/src/generators/test-generator/diagnostics.ts +4 -1
- package/src/generators/test-generator/step-mapper.ts +43 -2
- package/src/harness/annotation-overrides.ts +5 -2
- package/src/harness/audit.ts +7 -2
- package/src/harness/capability.ts +53 -3
- package/src/harness/quality-gates.ts +4 -0
- package/src/orchestrator/templates/ai-src/commands/create-test.md +1 -1
- package/src/orchestrator/templates/ai-src/commands/delivery.md +118 -120
- package/src/orchestrator/templates/ai-src/config/claude.md +1 -1
- package/src/orchestrator/templates/ai-src/config/copilot.md +1 -1
- package/src/orchestrator/templates/ai-src/skills/sungen-delivery/SKILL.md +43 -7
- package/src/orchestrator/templates/ai-src/skills/sungen-error-mapping/SKILL.md +1 -0
- package/src/orchestrator/templates/ai-src/skills/sungen-gherkin-syntax/SKILL.md +8 -0
- package/src/orchestrator/templates/ai-src/skills/sungen-harness-audit/SKILL.md +1 -1
- package/src/orchestrator/templates/ai-src/skills/sungen-locale/SKILL.md +8 -0
- package/src/orchestrator/templates/ai-src/skills/sungen-tc-generation/SKILL.md +1 -0
- package/src/orchestrator/templates/specs-test-data.ts +13 -4
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build the matrix model: derive atomic coverage variants from the merged
|
|
3
|
+
* feature/spec view, assemble delivery items per the Delivery Map, attach
|
|
4
|
+
* per-variant Playwright results, and roll parents up (derived only — Gate F
|
|
5
|
+
* is structural: there is no independent parent result input).
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { FeatureMetadata, PlaywrightResult } from '../types';
|
|
9
|
+
import { MergedScenario, parseManualComments } from '../scenario-merger';
|
|
10
|
+
import {
|
|
11
|
+
extractAuthRole,
|
|
12
|
+
extractPriority,
|
|
13
|
+
extractTestcaseType,
|
|
14
|
+
splitVpAndName,
|
|
15
|
+
} from '../feature-parser';
|
|
16
|
+
import { getCasesDatasetRows, resolveResultVariants } from '../result-variants';
|
|
17
|
+
import { substituteTestDataVars } from '../test-data-resolver';
|
|
18
|
+
import { scenarioFingerprint, combinedFingerprint, mapContentFingerprint } from './fingerprint';
|
|
19
|
+
import {
|
|
20
|
+
CoverageVariant,
|
|
21
|
+
DeliveryItem,
|
|
22
|
+
DeliveryMap,
|
|
23
|
+
ItemResult,
|
|
24
|
+
MatrixDisposition,
|
|
25
|
+
MatrixLayer,
|
|
26
|
+
MatrixModel,
|
|
27
|
+
MAX_VARIANTS_PER_ITEM,
|
|
28
|
+
} from './types';
|
|
29
|
+
import { runGates } from './gates';
|
|
30
|
+
|
|
31
|
+
// ---------------------------------------------------------------------------
|
|
32
|
+
// Variant derivation
|
|
33
|
+
// ---------------------------------------------------------------------------
|
|
34
|
+
|
|
35
|
+
/** Collapse `{{var}}` placeholders so data values become parameters, not shape. */
|
|
36
|
+
function normalizeShape(text: string): string {
|
|
37
|
+
return text.replace(/\{\{[^}]*\}\}/g, '{{*}}').replace(/\s+/g, ' ').trim();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function deriveLayers(tags: string[]): MatrixLayer[] {
|
|
41
|
+
const layers = new Set<MatrixLayer>(['ui']);
|
|
42
|
+
if (tags.some((t) => t === '@api' || t.startsWith('@api:') || t === '@requires:api')) layers.add('api');
|
|
43
|
+
if (tags.some((t) => t.startsWith('@query') || t === '@requires:db')) layers.add('db');
|
|
44
|
+
return Array.from(layers);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** 'simple' single G*→W*→T* pass; 'sequence' when the flow re-enters Given/When after a Then. */
|
|
48
|
+
function deriveProcedureProfile(m: MergedScenario): 'simple' | 'sequence' | 'manual' {
|
|
49
|
+
if (extractTestcaseType(m.feature.tags) === 'Manual') return 'manual';
|
|
50
|
+
const order = m.feature.orderedSteps.map((s) => s.bucket);
|
|
51
|
+
let seenThen = false;
|
|
52
|
+
for (const bucket of order) {
|
|
53
|
+
if (bucket === 'then') seenThen = true;
|
|
54
|
+
else if (seenThen) return 'sequence'; // action/setup after an assertion → ordered flow
|
|
55
|
+
}
|
|
56
|
+
return 'simple';
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
function manualReason(tags: string[]): string | undefined {
|
|
60
|
+
const t = tags.find((x) => x.startsWith('@manual:'));
|
|
61
|
+
return t ? t.slice('@manual:'.length) : undefined;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Resolve `{{var}}` refs of a scenario into display `key: value` pairs. */
|
|
65
|
+
function resolveDataPairs(
|
|
66
|
+
vars: string[],
|
|
67
|
+
testData: Record<string, string> | null,
|
|
68
|
+
row?: Record<string, unknown>,
|
|
69
|
+
): string[] {
|
|
70
|
+
const pairs: string[] = [];
|
|
71
|
+
if (row) {
|
|
72
|
+
for (const [k, v] of Object.entries(row)) {
|
|
73
|
+
if (k.startsWith('__') || k === 'case' || k === 'name' || k === 'label') continue;
|
|
74
|
+
pairs.push(`${k}: ${String(v)}`);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
for (const v of vars) {
|
|
78
|
+
const val = row && v in row ? undefined : testData?.[v]; // row columns already listed
|
|
79
|
+
if (val !== undefined) pairs.push(`${v}: ${val}`);
|
|
80
|
+
}
|
|
81
|
+
return pairs;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export interface BuildInputs {
|
|
85
|
+
unit: string;
|
|
86
|
+
feature: FeatureMetadata;
|
|
87
|
+
merged: MergedScenario[];
|
|
88
|
+
testData: Record<string, string> | null;
|
|
89
|
+
results: Map<string, PlaywrightResult> | null;
|
|
90
|
+
map: DeliveryMap;
|
|
91
|
+
transformerVersion: string;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Derive every atomic coverage variant of the unit (one per scenario, or one per
|
|
96
|
+
* `@cases` dataset row). Exported separately so the gates + the map-proposal
|
|
97
|
+
* support tooling see the same universe the builder does.
|
|
98
|
+
*/
|
|
99
|
+
export function deriveVariants(inputs: Pick<BuildInputs, 'feature' | 'merged' | 'testData' | 'results'>): CoverageVariant[] {
|
|
100
|
+
const { merged, testData, results } = inputs;
|
|
101
|
+
const variants: CoverageVariant[] = [];
|
|
102
|
+
|
|
103
|
+
for (const m of merged) {
|
|
104
|
+
const { vpId, category1 } = splitVpAndName(m.feature.name);
|
|
105
|
+
if (!vpId) continue; // Gate A reports it — no variant can be addressed without a VP-id
|
|
106
|
+
const tags = m.feature.tags;
|
|
107
|
+
const mode = extractTestcaseType(tags) === 'Manual' ? 'manual' : 'auto';
|
|
108
|
+
const authRole = extractAuthRole(tags);
|
|
109
|
+
const vpCategory = vpId.replace(/^VP-/, '').replace(/-\d+[a-zA-Z]?$/, '');
|
|
110
|
+
|
|
111
|
+
// Manual procedure comes from the parsed comment block; auto from Gherkin buckets.
|
|
112
|
+
const manual = mode === 'manual' && m.feature.comments?.length
|
|
113
|
+
? parseManualComments(m.feature.comments)
|
|
114
|
+
: null;
|
|
115
|
+
// A pure-render check (Given + Then only) is triggered by the page load itself —
|
|
116
|
+
// that IS its action, not a Gate-D executability gap.
|
|
117
|
+
const rawTrigger = manual ? manual.steps.map((s) => s.text) : m.feature.rawWhenSteps;
|
|
118
|
+
const triggerSteps = rawTrigger.length > 0 ? rawTrigger : ['(on page load)'];
|
|
119
|
+
const oracleSteps = m.resolvedExpected.map((s) => s.text);
|
|
120
|
+
|
|
121
|
+
const preconditionProfile = [
|
|
122
|
+
authRole ?? '-',
|
|
123
|
+
m.feature.extendsName ?? '-',
|
|
124
|
+
...m.feature.rawGivenSteps.map(normalizeShape),
|
|
125
|
+
].join(' | ');
|
|
126
|
+
const precondition = [
|
|
127
|
+
...(authRole ? [authRole === 'no-auth' ? 'Not authenticated' : `Authenticated as ${authRole}`] : []),
|
|
128
|
+
...m.feature.rawGivenSteps,
|
|
129
|
+
];
|
|
130
|
+
|
|
131
|
+
const base = {
|
|
132
|
+
vpId,
|
|
133
|
+
vpCategory,
|
|
134
|
+
priority: extractPriority(tags),
|
|
135
|
+
mode: mode as 'auto' | 'manual',
|
|
136
|
+
manualReason: manualReason(tags),
|
|
137
|
+
layers: deriveLayers(tags),
|
|
138
|
+
traces: tags.filter((t) => t.startsWith('@spec:')).map((t) => t.slice('@spec:'.length)),
|
|
139
|
+
triggerShape: triggerSteps.map(normalizeShape),
|
|
140
|
+
oracleShape: oracleSteps.map(normalizeShape),
|
|
141
|
+
preconditionProfile,
|
|
142
|
+
precondition,
|
|
143
|
+
procedureProfile: deriveProcedureProfile(m),
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
const rows = getCasesDatasetRows(m, testData ?? undefined);
|
|
147
|
+
if (rows) {
|
|
148
|
+
// One variant per dataset row; results matched per row label by the shared resolver.
|
|
149
|
+
const resultVariants = resolveResultVariants(m, results ?? null, testData ?? undefined);
|
|
150
|
+
const resultByLabel = new Map(resultVariants.map((rv) => [rv.nameSuffix.replace(/^ — /, ''), rv.result]));
|
|
151
|
+
rows.forEach((row, i) => {
|
|
152
|
+
const label = String(row.case ?? row.name ?? row.label ?? `row ${i + 1}`);
|
|
153
|
+
variants.push({
|
|
154
|
+
...base,
|
|
155
|
+
ref: `${vpId}#${label}`,
|
|
156
|
+
caseLabel: label,
|
|
157
|
+
title: `${category1} — ${label}`,
|
|
158
|
+
condition: label,
|
|
159
|
+
data: resolveDataPairs(m.feature.referencedVars, testData, row),
|
|
160
|
+
trigger: triggerSteps.map((s) => substituteTestDataVars(s, { ...(testData ?? {}), ...rowAsStrings(row) })),
|
|
161
|
+
oracle: oracleSteps.map((s) => substituteTestDataVars(s, { ...(testData ?? {}), ...rowAsStrings(row) })),
|
|
162
|
+
fingerprint: scenarioFingerprint(m.feature, row),
|
|
163
|
+
result: resultByLabel.get(label),
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
} else {
|
|
167
|
+
variants.push({
|
|
168
|
+
...base,
|
|
169
|
+
ref: vpId,
|
|
170
|
+
title: category1,
|
|
171
|
+
condition: category1,
|
|
172
|
+
data: resolveDataPairs(m.feature.referencedVars, testData),
|
|
173
|
+
trigger: triggerSteps.map((s) => substituteTestDataVars(s, testData ?? {})),
|
|
174
|
+
oracle: oracleSteps.map((s) => substituteTestDataVars(s, testData ?? {})),
|
|
175
|
+
fingerprint: scenarioFingerprint(m.feature),
|
|
176
|
+
result: resolveResultVariants(m, results ?? null, testData ?? undefined)[0]?.result,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return variants;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function rowAsStrings(row: Record<string, unknown>): Record<string, string> {
|
|
184
|
+
const out: Record<string, string> = {};
|
|
185
|
+
for (const [k, v] of Object.entries(row)) out[k] = String(v);
|
|
186
|
+
return out;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// ---------------------------------------------------------------------------
|
|
190
|
+
// Item assembly + roll-up
|
|
191
|
+
// ---------------------------------------------------------------------------
|
|
192
|
+
|
|
193
|
+
function classifyResult(r: PlaywrightResult | undefined): 'passed' | 'failed' | 'blocked' | 'notRun' {
|
|
194
|
+
if (!r) return 'notRun';
|
|
195
|
+
if (r.status === 'passed') return 'passed';
|
|
196
|
+
if (r.status === 'failed' || r.status === 'timedOut') return 'failed';
|
|
197
|
+
if (r.status === 'interrupted') return 'blocked';
|
|
198
|
+
return 'notRun'; // skipped / unknown
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** Derived parent result — precedence: failed → blocked → not_run → partial → passed. */
|
|
202
|
+
export function rollUp(variants: CoverageVariant[]): { result: ItemResult; counts: DeliveryItem['resultCounts'] } {
|
|
203
|
+
const counts = { passed: 0, failed: 0, blocked: 0, notRun: 0 };
|
|
204
|
+
for (const v of variants) counts[classifyResult(v.result)]++;
|
|
205
|
+
const run = counts.passed + counts.failed + counts.blocked;
|
|
206
|
+
let result: ItemResult;
|
|
207
|
+
if (counts.failed > 0) result = 'failed';
|
|
208
|
+
else if (counts.blocked > 0) result = 'blocked';
|
|
209
|
+
else if (run === 0) result = 'not_run';
|
|
210
|
+
else if (counts.notRun > 0) result = 'partial';
|
|
211
|
+
else result = 'passed';
|
|
212
|
+
return { result, counts };
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Expand one map variant ref to concrete variant refs:
|
|
217
|
+
* a bare VP-id whose scenario has a dataset means ALL its rows.
|
|
218
|
+
*/
|
|
219
|
+
export function expandMapRef(ref: string, variantsByVp: Map<string, CoverageVariant[]>): CoverageVariant[] {
|
|
220
|
+
if (ref.includes('#')) {
|
|
221
|
+
const [vp] = ref.split('#');
|
|
222
|
+
return (variantsByVp.get(vp) ?? []).filter((v) => v.ref === ref);
|
|
223
|
+
}
|
|
224
|
+
return variantsByVp.get(ref) ?? [];
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
export function buildMatrix(inputs: BuildInputs): MatrixModel {
|
|
228
|
+
const { unit, map, transformerVersion } = inputs;
|
|
229
|
+
const variants = deriveVariants(inputs);
|
|
230
|
+
|
|
231
|
+
const variantsByVp = new Map<string, CoverageVariant[]>();
|
|
232
|
+
for (const v of variants) {
|
|
233
|
+
const list = variantsByVp.get(v.vpId) ?? [];
|
|
234
|
+
list.push(v);
|
|
235
|
+
variantsByVp.set(v.vpId, list);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
const findings = runGates({ inputs, variants, variantsByVp });
|
|
239
|
+
const stale = new Set(findings.filter((f) => f.gate === 'E' && f.ref).map((f) => f.ref as string));
|
|
240
|
+
|
|
241
|
+
const items: DeliveryItem[] = map.groups.map((g) => {
|
|
242
|
+
const groupVariants = g.variants.flatMap((ref) => expandMapRef(ref, variantsByVp));
|
|
243
|
+
const { result, counts } = rollUp(groupVariants);
|
|
244
|
+
const first = groupVariants[0];
|
|
245
|
+
const triggerShapes = new Set(groupVariants.map((v) => v.triggerShape.join(' ; ')));
|
|
246
|
+
return {
|
|
247
|
+
id: g.id,
|
|
248
|
+
target: g.target,
|
|
249
|
+
intent: g.intent,
|
|
250
|
+
oracle: g.oracle,
|
|
251
|
+
category: g.category,
|
|
252
|
+
// A stale (drifted) group presents as proposed regardless of its stored state.
|
|
253
|
+
review: stale.has(g.id) ? 'proposed' : g.review,
|
|
254
|
+
priority: first?.priority ?? 'Normal',
|
|
255
|
+
mode: first?.mode ?? 'auto',
|
|
256
|
+
layers: Array.from(new Set(groupVariants.flatMap((v) => v.layers))),
|
|
257
|
+
traces: Array.from(new Set(groupVariants.flatMap((v) => v.traces))),
|
|
258
|
+
precondition: first?.precondition ?? [],
|
|
259
|
+
trigger: triggerShapes.size === 1 ? (first?.trigger ?? []) : ['(per variant)'],
|
|
260
|
+
variants: groupVariants,
|
|
261
|
+
result,
|
|
262
|
+
resultCounts: counts,
|
|
263
|
+
};
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
const dispositions: MatrixDisposition[] = Object.entries(map.dispositions).map(([vpId, d]) => ({
|
|
267
|
+
vpId,
|
|
268
|
+
title: variantsByVp.get(vpId)?.[0]?.title ?? '',
|
|
269
|
+
as: d.as,
|
|
270
|
+
reason: d.reason ?? '',
|
|
271
|
+
}));
|
|
272
|
+
|
|
273
|
+
const variantCount = items.reduce((a, i) => a + i.variants.length, 0);
|
|
274
|
+
const approved = items.every((i) => i.review === 'approved')
|
|
275
|
+
&& !findings.some((f) => f.severity === 'error' || f.severity === 'review');
|
|
276
|
+
|
|
277
|
+
return {
|
|
278
|
+
unit,
|
|
279
|
+
formNo: map.formNo ?? 'BM-2-901-13',
|
|
280
|
+
items,
|
|
281
|
+
dispositions,
|
|
282
|
+
findings,
|
|
283
|
+
manifest: {
|
|
284
|
+
unit,
|
|
285
|
+
transformerVersion,
|
|
286
|
+
sourceFingerprint: combinedFingerprint(variants.map((v) => v.fingerprint)),
|
|
287
|
+
mapFingerprint: mapContentFingerprint(map.groups, map.dispositions),
|
|
288
|
+
approvalState: approved ? 'approved' : 'draft',
|
|
289
|
+
itemCount: items.length,
|
|
290
|
+
variantCount,
|
|
291
|
+
thresholds: { maxVariantsPerItem: MAX_VARIANTS_PER_ITEM },
|
|
292
|
+
},
|
|
293
|
+
};
|
|
294
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Matrix export orchestration — the piece `sungen delivery` calls.
|
|
3
|
+
*
|
|
4
|
+
* Composes the existing parsing seams (feature-parser, spec-parser, test-data,
|
|
5
|
+
* playwright report) with the map loader, builder, gates, and renderers. All
|
|
6
|
+
* inputs arrive as resolved paths so the CLI's discovery logic stays the single
|
|
7
|
+
* owner of unit-kind layout rules.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import * as fs from 'fs';
|
|
11
|
+
import { parseFeatureMetadata } from '../feature-parser';
|
|
12
|
+
import { parseSpecFile } from '../spec-parser';
|
|
13
|
+
import { loadTestData } from '../test-data-resolver';
|
|
14
|
+
import { loadPlaywrightReport } from '../playwright-report-parser';
|
|
15
|
+
import { mergeFeatureAndSpec } from '../scenario-merger';
|
|
16
|
+
import { getPackageVersion } from '../package-info';
|
|
17
|
+
import { writeCsv } from '../csv-exporter';
|
|
18
|
+
import { writeXlsx } from '../xlsx-exporter';
|
|
19
|
+
import { loadDeliveryMap, writeDeliveryMap } from './map-loader';
|
|
20
|
+
import { buildMatrix, deriveVariants } from './build';
|
|
21
|
+
import { renderMatrixXlsx } from './render-xlsx';
|
|
22
|
+
import { renderMatrixCsv } from './render-csv';
|
|
23
|
+
import { DeliveryMap, MatrixFinding, MatrixModel } from './types';
|
|
24
|
+
|
|
25
|
+
export interface MatrixTargetPaths {
|
|
26
|
+
cwd: string;
|
|
27
|
+
/** Feature basename — names the deliverable files. */
|
|
28
|
+
unit: string;
|
|
29
|
+
/** Display label (flow/… prefix for flows). */
|
|
30
|
+
label: string;
|
|
31
|
+
featureFile: string;
|
|
32
|
+
testDataFile: string;
|
|
33
|
+
specFile: string;
|
|
34
|
+
resultsPath: string | null;
|
|
35
|
+
mapFile: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface MatrixLoadResult {
|
|
39
|
+
model?: MatrixModel;
|
|
40
|
+
map?: DeliveryMap;
|
|
41
|
+
/** No map file → the caller prints the guidance path (AI proposal or --legacy). */
|
|
42
|
+
mapMissing?: boolean;
|
|
43
|
+
/** Structural map problems (bad YAML/shape) — fix the file before anything else. */
|
|
44
|
+
mapErrors: string[];
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function loadMatrixModel(paths: MatrixTargetPaths): MatrixLoadResult {
|
|
48
|
+
const { map, errors } = loadDeliveryMap(paths.mapFile);
|
|
49
|
+
if (!map) {
|
|
50
|
+
return errors.length === 0 ? { mapMissing: true, mapErrors: [] } : { mapErrors: errors };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const feature = parseFeatureMetadata(paths.featureFile);
|
|
54
|
+
const spec = parseSpecFile(paths.specFile);
|
|
55
|
+
const merged = mergeFeatureAndSpec(feature, spec);
|
|
56
|
+
const testData = fs.existsSync(paths.testDataFile) ? loadTestData(paths.testDataFile, process.env.SUNGEN_ENV ?? null) : null;
|
|
57
|
+
const results = paths.resultsPath ? loadPlaywrightReport(paths.resultsPath) : null;
|
|
58
|
+
|
|
59
|
+
const model = buildMatrix({
|
|
60
|
+
unit: paths.unit,
|
|
61
|
+
feature,
|
|
62
|
+
merged,
|
|
63
|
+
testData,
|
|
64
|
+
results,
|
|
65
|
+
map,
|
|
66
|
+
transformerVersion: getPackageVersion(),
|
|
67
|
+
});
|
|
68
|
+
return { model, map, mapErrors: [] };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export const hasErrors = (f: MatrixFinding[]): boolean => f.some((x) => x.severity === 'error');
|
|
72
|
+
export const hasReview = (f: MatrixFinding[]): boolean => f.some((x) => x.severity === 'review');
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Stamp fingerprints + flip groups to `approved` (all groups, or just `groupIds`).
|
|
76
|
+
* Refuses when gate ERRORs remain — an invalid map must not be frozen as approved.
|
|
77
|
+
* Returns the findings so the caller reports what blocked or what was approved.
|
|
78
|
+
*/
|
|
79
|
+
export function approveMatrix(paths: MatrixTargetPaths, groupIds?: string[]): { findings: MatrixFinding[]; approved: string[] } {
|
|
80
|
+
const { map, errors } = loadDeliveryMap(paths.mapFile);
|
|
81
|
+
if (!map) throw new Error(errors.length > 0 ? `map is invalid:\n - ${errors.join('\n - ')}` : `no delivery map at ${paths.mapFile}`);
|
|
82
|
+
|
|
83
|
+
const feature = parseFeatureMetadata(paths.featureFile);
|
|
84
|
+
const spec = parseSpecFile(paths.specFile);
|
|
85
|
+
const merged = mergeFeatureAndSpec(feature, spec);
|
|
86
|
+
const testData = fs.existsSync(paths.testDataFile) ? loadTestData(paths.testDataFile, process.env.SUNGEN_ENV ?? null) : null;
|
|
87
|
+
|
|
88
|
+
const model = buildMatrix({
|
|
89
|
+
unit: paths.unit, feature, merged, testData, results: null, map,
|
|
90
|
+
transformerVersion: getPackageVersion(),
|
|
91
|
+
});
|
|
92
|
+
const blocking = model.findings.filter((f) => f.severity === 'error');
|
|
93
|
+
if (blocking.length > 0) return { findings: blocking, approved: [] };
|
|
94
|
+
|
|
95
|
+
const variants = deriveVariants({ feature, merged, testData, results: null });
|
|
96
|
+
const byRef = new Map(variants.map((v) => [v.ref, v] as const));
|
|
97
|
+
const byVp = new Map<string, typeof variants>();
|
|
98
|
+
for (const v of variants) {
|
|
99
|
+
const list = byVp.get(v.vpId) ?? [];
|
|
100
|
+
list.push(v);
|
|
101
|
+
byVp.set(v.vpId, list);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const approved: string[] = [];
|
|
105
|
+
for (const g of map.groups) {
|
|
106
|
+
if (groupIds && groupIds.length > 0 && !groupIds.includes(g.id)) continue;
|
|
107
|
+
for (const ref of g.variants) {
|
|
108
|
+
const expanded = ref.includes('#') ? [byRef.get(ref)].filter(Boolean) : (byVp.get(ref) ?? []);
|
|
109
|
+
for (const v of expanded) map.fingerprints[(v as NonNullable<typeof expanded[number]>).ref] = (v as NonNullable<typeof expanded[number]>).fingerprint;
|
|
110
|
+
}
|
|
111
|
+
g.review = 'approved';
|
|
112
|
+
approved.push(g.id);
|
|
113
|
+
}
|
|
114
|
+
writeDeliveryMap(paths.mapFile, map);
|
|
115
|
+
return { findings: model.findings.filter((f) => f.severity !== 'error'), approved };
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** Render + write both artifacts. Caller has already enforced the gate policy. */
|
|
119
|
+
export async function writeMatrixDeliverables(paths: MatrixTargetPaths, model: MatrixModel): Promise<{ csvPath: string; xlsxPath: string }> {
|
|
120
|
+
const csvPath = writeCsv(paths.cwd, paths.unit, renderMatrixCsv(model));
|
|
121
|
+
const wb = renderMatrixXlsx(model, getPackageVersion());
|
|
122
|
+
const xlsxPath = await writeXlsx(paths.cwd, paths.unit, wb);
|
|
123
|
+
return { csvPath, xlsxPath };
|
|
124
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
}
|