@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.
- package/dist/cli/commands/delivery.d.ts.map +1 -1
- package/dist/cli/commands/delivery.js +13 -197
- package/dist/cli/commands/delivery.js.map +1 -1
- package/dist/cli/commands/ingest.d.ts.map +1 -1
- package/dist/cli/commands/ingest.js +56 -4
- package/dist/cli/commands/ingest.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/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/actions/click-action.hbs +1 -1
- package/dist/generators/test-generator/adapters/playwright/templates/steps/actions/click-element-with-text.hbs +1 -1
- package/dist/generators/test-generator/adapters/playwright/templates/steps/navigation/wait-timeout.hbs +1 -1
- package/dist/generators/test-generator/utils/runtime-data-transformer.d.ts.map +1 -1
- package/dist/generators/test-generator/utils/runtime-data-transformer.js +28 -17
- package/dist/generators/test-generator/utils/runtime-data-transformer.js.map +1 -1
- package/dist/ingest/legacy-parser.d.ts +3 -0
- package/dist/ingest/legacy-parser.d.ts.map +1 -1
- package/dist/ingest/legacy-parser.js +52 -3
- package/dist/ingest/legacy-parser.js.map +1 -1
- package/dist/orchestrator/templates/ai-src/commands/delivery.md +120 -202
- 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 +6 -92
- package/dist/orchestrator/templates/ai-src/skills/sungen-gherkin-syntax/SKILL.md +7 -0
- package/package.json +4 -4
- package/src/cli/commands/delivery.ts +15 -227
- package/src/cli/commands/ingest.ts +57 -5
- package/src/dashboard/templates/index.html +1 -1
- package/src/exporters/feature-parser.ts +1 -1
- package/src/exporters/scenario-merger.ts +1 -1
- package/src/exporters/spec-parser.ts +1 -1
- package/src/exporters/xlsx-report-builder.ts +2 -3
- package/src/generators/test-generator/adapters/playwright/templates/steps/actions/click-action.hbs +1 -1
- package/src/generators/test-generator/adapters/playwright/templates/steps/actions/click-element-with-text.hbs +1 -1
- package/src/generators/test-generator/adapters/playwright/templates/steps/navigation/wait-timeout.hbs +1 -1
- package/src/generators/test-generator/utils/runtime-data-transformer.ts +29 -18
- package/src/ingest/legacy-parser.ts +48 -3
- package/src/orchestrator/templates/ai-src/commands/delivery.md +120 -202
- 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 +6 -92
- package/src/orchestrator/templates/ai-src/skills/sungen-gherkin-syntax/SKILL.md +7 -0
- package/dist/exporters/matrix/build.d.ts +0 -61
- package/dist/exporters/matrix/build.d.ts.map +0 -1
- package/dist/exporters/matrix/build.js +0 -472
- package/dist/exporters/matrix/build.js.map +0 -1
- package/dist/exporters/matrix/export.d.ts +0 -50
- package/dist/exporters/matrix/export.d.ts.map +0 -1
- package/dist/exporters/matrix/export.js +0 -152
- package/dist/exporters/matrix/export.js.map +0 -1
- package/dist/exporters/matrix/fingerprint.d.ts +0 -20
- package/dist/exporters/matrix/fingerprint.d.ts.map +0 -1
- package/dist/exporters/matrix/fingerprint.js +0 -83
- package/dist/exporters/matrix/fingerprint.js.map +0 -1
- package/dist/exporters/matrix/gates.d.ts +0 -21
- package/dist/exporters/matrix/gates.d.ts.map +0 -1
- package/dist/exporters/matrix/gates.js +0 -358
- package/dist/exporters/matrix/gates.js.map +0 -1
- package/dist/exporters/matrix/map-loader.d.ts +0 -22
- package/dist/exporters/matrix/map-loader.d.ts.map +0 -1
- package/dist/exporters/matrix/map-loader.js +0 -193
- package/dist/exporters/matrix/map-loader.js.map +0 -1
- package/dist/exporters/matrix/render-csv.d.ts +0 -9
- package/dist/exporters/matrix/render-csv.d.ts.map +0 -1
- package/dist/exporters/matrix/render-csv.js +0 -92
- package/dist/exporters/matrix/render-csv.js.map +0 -1
- package/dist/exporters/matrix/render-xlsx.d.ts +0 -41
- package/dist/exporters/matrix/render-xlsx.d.ts.map +0 -1
- package/dist/exporters/matrix/render-xlsx.js +0 -430
- package/dist/exporters/matrix/render-xlsx.js.map +0 -1
- package/dist/exporters/matrix/types.d.ts +0 -196
- package/dist/exporters/matrix/types.d.ts.map +0 -1
- package/dist/exporters/matrix/types.js +0 -15
- package/dist/exporters/matrix/types.js.map +0 -1
- package/dist/exporters/matrix/wording.d.ts +0 -51
- package/dist/exporters/matrix/wording.d.ts.map +0 -1
- package/dist/exporters/matrix/wording.js +0 -169
- package/dist/exporters/matrix/wording.js.map +0 -1
- package/src/exporters/matrix/build.ts +0 -503
- package/src/exporters/matrix/export.ts +0 -149
- package/src/exporters/matrix/fingerprint.ts +0 -49
- package/src/exporters/matrix/gates.ts +0 -391
- package/src/exporters/matrix/map-loader.ts +0 -163
- package/src/exporters/matrix/render-csv.ts +0 -94
- package/src/exporters/matrix/render-xlsx.ts +0 -420
- package/src/exporters/matrix/types.ts +0 -223
- package/src/exporters/matrix/wording.ts +0 -174
|
@@ -1,503 +0,0 @@
|
|
|
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 } 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 { classifyManualComments, renderAction, renderExpected, renderPrecondition, renderSetupInstruction } from './wording';
|
|
18
|
-
import { scenarioFingerprint, combinedFingerprint, mapContentFingerprint } from './fingerprint';
|
|
19
|
-
import {
|
|
20
|
-
CoverageVariant,
|
|
21
|
-
DeliveryItem,
|
|
22
|
-
DeliveryMap,
|
|
23
|
-
ItemResult,
|
|
24
|
-
VariantState,
|
|
25
|
-
MatrixDisposition,
|
|
26
|
-
MatrixLayer,
|
|
27
|
-
MatrixModel,
|
|
28
|
-
RequirementCoverage,
|
|
29
|
-
MAX_VARIANTS_PER_ITEM,
|
|
30
|
-
} from './types';
|
|
31
|
-
import { runGates } from './gates';
|
|
32
|
-
|
|
33
|
-
// ---------------------------------------------------------------------------
|
|
34
|
-
// Variant derivation
|
|
35
|
-
// ---------------------------------------------------------------------------
|
|
36
|
-
|
|
37
|
-
/** Collapse `{{var}}` placeholders so data values become parameters, not shape. */
|
|
38
|
-
function normalizeShape(text: string): string {
|
|
39
|
-
return text.replace(/\{\{[^}]*\}\}/g, '{{*}}').replace(/\s+/g, ' ').trim();
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function deriveLayers(tags: string[]): MatrixLayer[] {
|
|
43
|
-
const layers = new Set<MatrixLayer>(['ui']);
|
|
44
|
-
if (tags.some((t) => t === '@api' || t.startsWith('@api:') || t === '@requires:api')) layers.add('api');
|
|
45
|
-
if (tags.some((t) => t.startsWith('@query') || t === '@requires:db')) layers.add('db');
|
|
46
|
-
return Array.from(layers);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/** 'simple' single G*→W*→T* pass; 'sequence' when the flow re-enters Given/When after a Then. */
|
|
50
|
-
function deriveProcedureProfile(m: MergedScenario): 'simple' | 'sequence' | 'manual' {
|
|
51
|
-
if (extractTestcaseType(m.feature.tags) === 'Manual') return 'manual';
|
|
52
|
-
const order = m.feature.orderedSteps.map((s) => s.bucket);
|
|
53
|
-
let seenThen = false;
|
|
54
|
-
for (const bucket of order) {
|
|
55
|
-
if (bucket === 'then') seenThen = true;
|
|
56
|
-
else if (seenThen) return 'sequence'; // action/setup after an assertion → ordered flow
|
|
57
|
-
}
|
|
58
|
-
return 'simple';
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function manualReason(tags: string[]): string | undefined {
|
|
62
|
-
const t = tags.find((x) => x.startsWith('@manual:'));
|
|
63
|
-
return t ? t.slice('@manual:'.length) : undefined;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/** Resolve `{{var}}` refs of a scenario into display `key: value` pairs. */
|
|
67
|
-
function resolveDataPairs(
|
|
68
|
-
vars: string[],
|
|
69
|
-
testData: Record<string, string> | null,
|
|
70
|
-
row?: Record<string, unknown>,
|
|
71
|
-
): string[] {
|
|
72
|
-
const pairs: string[] = [];
|
|
73
|
-
if (row) {
|
|
74
|
-
for (const [k, v] of Object.entries(row)) {
|
|
75
|
-
if (k.startsWith('__') || k === 'case' || k === 'name' || k === 'label') continue;
|
|
76
|
-
pairs.push(`${k}: ${displayValue(String(v))}`);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
for (const v of vars) {
|
|
80
|
-
const val = row && v in row ? undefined : testData?.[v]; // row columns already listed
|
|
81
|
-
if (val !== undefined) pairs.push(`${v}: ${displayValue(val)}`);
|
|
82
|
-
}
|
|
83
|
-
return pairs;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export interface BuildInputs {
|
|
87
|
-
unit: string;
|
|
88
|
-
feature: FeatureMetadata;
|
|
89
|
-
merged: MergedScenario[];
|
|
90
|
-
testData: Record<string, string> | null;
|
|
91
|
-
results: Map<string, PlaywrightResult> | null;
|
|
92
|
-
map: DeliveryMap;
|
|
93
|
-
transformerVersion: string;
|
|
94
|
-
/** requirements/spec.md content — source of the requirement-id inventory (FR/TR/NFR). */
|
|
95
|
-
specText?: string;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Derive every atomic coverage variant of the unit (one per scenario, or one per
|
|
100
|
-
* `@cases` dataset row). Exported separately so the gates + the map-proposal
|
|
101
|
-
* support tooling see the same universe the builder does.
|
|
102
|
-
*/
|
|
103
|
-
export function deriveVariants(inputs: Pick<BuildInputs, 'feature' | 'merged' | 'testData' | 'results'>): CoverageVariant[] {
|
|
104
|
-
const { merged, results } = inputs;
|
|
105
|
-
// Test-data values may cross-reference other keys (email_padded: " {{valid_email}} ") —
|
|
106
|
-
// resolve one level so display cells never leak a template token (review B-04).
|
|
107
|
-
const testData = resolveCrossRefs(inputs.testData);
|
|
108
|
-
const variants: CoverageVariant[] = [];
|
|
109
|
-
|
|
110
|
-
for (const m of merged) {
|
|
111
|
-
const { vpId, category1 } = splitVpAndName(m.feature.name);
|
|
112
|
-
if (!vpId) continue; // Gate A reports it — no variant can be addressed without a VP-id
|
|
113
|
-
const tags = m.feature.tags;
|
|
114
|
-
const mode = extractTestcaseType(tags) === 'Manual' ? 'manual' : 'auto';
|
|
115
|
-
const authRole = extractAuthRole(tags);
|
|
116
|
-
const vpCategory = vpId.replace(/^VP-/, '').replace(/-\d+[a-zA-Z]?$/, '');
|
|
117
|
-
const procedureProfile = deriveProcedureProfile(m);
|
|
118
|
-
|
|
119
|
-
// Manual scenarios: the `# Tester verifies:` block is classified into structured
|
|
120
|
-
// fields — Setup → precondition (review B-02), Action → trigger, Observable →
|
|
121
|
-
// expected, Oracle → verification method. Labels never remain inside prose.
|
|
122
|
-
const manual = mode === 'manual' && m.feature.comments?.length
|
|
123
|
-
? classifyManualComments(m.feature.comments)
|
|
124
|
-
: null;
|
|
125
|
-
|
|
126
|
-
// Raw (pre-wording) step texts — these feed shapes + Gate C, never the cells.
|
|
127
|
-
const rawTrigger = manual ? manual.actions : m.feature.rawWhenSteps;
|
|
128
|
-
const rawOracle = manual
|
|
129
|
-
? (manual.expected.length > 0 ? manual.expected : m.feature.rawThenSteps)
|
|
130
|
-
: m.resolvedExpected.filter((s) => s.bucket === 'then').map((s) => s.text);
|
|
131
|
-
|
|
132
|
-
const preconditionProfile = [
|
|
133
|
-
authRole ?? '-',
|
|
134
|
-
m.feature.extendsName ?? '-',
|
|
135
|
-
...m.feature.rawGivenSteps.map(normalizeShape),
|
|
136
|
-
...(manual?.preconditions ?? []).map(normalizeShape),
|
|
137
|
-
].join(' | ');
|
|
138
|
-
// Display precondition = auth state + Background Given (shared start state) +
|
|
139
|
-
// the scenario's own Given steps + manual Setup lines — deduplicated (a manual
|
|
140
|
-
// scenario often repeats the Background navigation as its own Given).
|
|
141
|
-
const precondition = Array.from(new Set([
|
|
142
|
-
...(authRole ? [authRole === 'no-auth' ? 'The user is signed out.' : `The user is signed in as ${authRole}.`] : []),
|
|
143
|
-
...inputs.feature.backgroundGivenSteps.map(renderPrecondition),
|
|
144
|
-
...m.feature.rawGivenSteps.map(renderPrecondition),
|
|
145
|
-
...(manual?.preconditions ?? []).map((t) => renderSetupInstruction(t)),
|
|
146
|
-
]));
|
|
147
|
-
|
|
148
|
-
const base = {
|
|
149
|
-
vpId,
|
|
150
|
-
vpCategory,
|
|
151
|
-
priority: extractPriority(tags),
|
|
152
|
-
mode: mode as 'auto' | 'manual',
|
|
153
|
-
manualReason: manualReason(tags),
|
|
154
|
-
layers: deriveLayers(tags),
|
|
155
|
-
traces: tags.filter((t) => t.startsWith('@spec:')).map((t) => t.slice('@spec:'.length)),
|
|
156
|
-
triggerShape: rawTrigger.map(normalizeShape),
|
|
157
|
-
oracleShape: rawOracle.map(normalizeShape),
|
|
158
|
-
preconditionProfile,
|
|
159
|
-
precondition,
|
|
160
|
-
procedureProfile,
|
|
161
|
-
verification: manual?.verification.map((t) => sentenceOf(t)) ?? [],
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
/** Render the display cells for one data context (vars resolved first). */
|
|
165
|
-
const renderCells = (vars: Record<string, string>): { trigger: string[]; oracle: string[]; precondition: string[]; verification: string[] } => {
|
|
166
|
-
const sub = (s: string): string => substituteDisplayVars(s, vars);
|
|
167
|
-
const preconditionOut = precondition.map(sub);
|
|
168
|
-
const verificationOut = base.verification.map(sub);
|
|
169
|
-
if (procedureProfile === 'sequence' && !manual) {
|
|
170
|
-
// Ordered flow (review B-03): keep the event order — actions stay numbered in
|
|
171
|
-
// the trigger, mid-flow assertions render inline as "Verify:", and only the
|
|
172
|
-
// FINAL Then block becomes the expected result.
|
|
173
|
-
const steps = m.feature.orderedSteps;
|
|
174
|
-
let lastActionIdx = -1;
|
|
175
|
-
steps.forEach((s, i) => { if (s.bucket !== 'then') lastActionIdx = i; });
|
|
176
|
-
const trigger: string[] = [];
|
|
177
|
-
const oracle: string[] = [];
|
|
178
|
-
steps.forEach((s, i) => {
|
|
179
|
-
if (i > lastActionIdx) oracle.push(renderExpected(sub(s.text))); // trailing Then block
|
|
180
|
-
else if (s.bucket === 'then') trigger.push(`Verify: ${renderExpected(sub(s.text))}`);
|
|
181
|
-
else if (s.bucket === 'when') trigger.push(renderAction(sub(s.text)));
|
|
182
|
-
// leading given steps already live in the precondition
|
|
183
|
-
});
|
|
184
|
-
return { trigger, oracle, precondition: preconditionOut, verification: verificationOut };
|
|
185
|
-
}
|
|
186
|
-
const trigger = rawTrigger.map((s) => renderAction(sub(s)));
|
|
187
|
-
const oracle = rawOracle.map((s) => renderExpected(sub(s)));
|
|
188
|
-
return {
|
|
189
|
-
// A pure-render check (Given + Then only) is checked on page load — say so
|
|
190
|
-
// in words instead of a placeholder token (review §10.3).
|
|
191
|
-
trigger: trigger.length > 0 ? trigger : ['No action — the state is checked on page load.'],
|
|
192
|
-
oracle,
|
|
193
|
-
precondition: preconditionOut,
|
|
194
|
-
verification: verificationOut,
|
|
195
|
-
};
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
const rows = getCasesDatasetRows(m, testData ?? undefined);
|
|
199
|
-
if (rows) {
|
|
200
|
-
// One variant per dataset row; results matched per row label by the shared resolver.
|
|
201
|
-
const resultVariants = resolveResultVariants(m, results ?? null, testData ?? undefined);
|
|
202
|
-
const resultByLabel = new Map(resultVariants.map((rv) => [rv.nameSuffix.replace(/^ — /, ''), rv.result]));
|
|
203
|
-
rows.forEach((row, i) => {
|
|
204
|
-
const label = String(row.case ?? row.name ?? row.label ?? `row ${i + 1}`);
|
|
205
|
-
const cells = renderCells({ ...(testData ?? {}), ...rowAsStrings(row) });
|
|
206
|
-
variants.push({
|
|
207
|
-
...base,
|
|
208
|
-
ref: `${vpId}#${label}`,
|
|
209
|
-
caseLabel: label,
|
|
210
|
-
title: `${category1} — ${label}`,
|
|
211
|
-
condition: label,
|
|
212
|
-
data: resolveDataPairs(m.feature.referencedVars, testData, row),
|
|
213
|
-
trigger: cells.trigger,
|
|
214
|
-
oracle: cells.oracle,
|
|
215
|
-
precondition: cells.precondition,
|
|
216
|
-
verification: cells.verification,
|
|
217
|
-
fingerprint: scenarioFingerprint(m.feature, row),
|
|
218
|
-
result: resultByLabel.get(label),
|
|
219
|
-
});
|
|
220
|
-
});
|
|
221
|
-
} else {
|
|
222
|
-
const cells = renderCells(testData ?? {});
|
|
223
|
-
variants.push({
|
|
224
|
-
...base,
|
|
225
|
-
ref: vpId,
|
|
226
|
-
title: category1,
|
|
227
|
-
condition: category1,
|
|
228
|
-
data: resolveDataPairs(m.feature.referencedVars, testData),
|
|
229
|
-
trigger: cells.trigger,
|
|
230
|
-
oracle: cells.oracle,
|
|
231
|
-
precondition: cells.precondition,
|
|
232
|
-
verification: cells.verification,
|
|
233
|
-
fingerprint: scenarioFingerprint(m.feature),
|
|
234
|
-
result: resolveResultVariants(m, results ?? null, testData ?? undefined)[0]?.result,
|
|
235
|
-
});
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
return variants;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* Display substitution for matrix cells. Unlike the legacy exporter's
|
|
243
|
-
* substituteTestDataVars (which keeps EMPTY values literal for the Steps
|
|
244
|
-
* column), an empty value is a legitimate test input here (an intentionally
|
|
245
|
-
* empty field) — it renders as `(empty)` so the tester sees the intent and no
|
|
246
|
-
* `{{token}}` survives into the deliverable (Gate D would reject it).
|
|
247
|
-
*/
|
|
248
|
-
function substituteDisplayVars(text: string, vars: Record<string, string>): string {
|
|
249
|
-
return text.replace(/\{\{\s*([^}\s]+)\s*\}\}/g, (m, key: string) => {
|
|
250
|
-
if (!(key in vars)) return m; // unknown stays literal → Gate D flags it
|
|
251
|
-
return displayValue(vars[key]);
|
|
252
|
-
});
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
/**
|
|
256
|
-
* Make invisible test data VISIBLE instead of losing it (review GAP-04):
|
|
257
|
-
* '' → (empty) · whitespace-only → (N spaces) · padded → quoted verbatim.
|
|
258
|
-
* The canonical value is never changed — only its presentation.
|
|
259
|
-
*/
|
|
260
|
-
export function displayValue(v: string): string {
|
|
261
|
-
if (v === '') return '(empty)';
|
|
262
|
-
if (/^\s+$/.test(v)) return `(${v.length} space${v.length > 1 ? 's' : ''})`;
|
|
263
|
-
if (v !== v.trim()) return `"${v}"`;
|
|
264
|
-
return v;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
function sentenceOf(text: string): string {
|
|
268
|
-
const s = text.trim();
|
|
269
|
-
if (!s) return s;
|
|
270
|
-
const cap = s.charAt(0).toUpperCase() + s.slice(1);
|
|
271
|
-
return /[.!?…]$/.test(cap) ? cap : `${cap}.`;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
/**
|
|
275
|
-
* Requirement inventory ∪ traces → coverage table. Ids are scanned from the spec
|
|
276
|
-
* text (FR-/TR-/NFR-<n>); map overrides win over the derived covered/gap status.
|
|
277
|
-
*/
|
|
278
|
-
export function computeRequirements(
|
|
279
|
-
specText: string,
|
|
280
|
-
map: DeliveryMap,
|
|
281
|
-
items: DeliveryItem[],
|
|
282
|
-
): RequirementCoverage[] {
|
|
283
|
-
const ids: string[] = [];
|
|
284
|
-
const seen = new Set<string>();
|
|
285
|
-
for (const m of specText.matchAll(/\b(?:FR|TR|NFR)-\d+\b/g)) {
|
|
286
|
-
if (!seen.has(m[0])) { seen.add(m[0]); ids.push(m[0]); }
|
|
287
|
-
}
|
|
288
|
-
// Overrides may reference ids the spec text doesn't list (e.g. a shared catalog).
|
|
289
|
-
for (const id of Object.keys(map.requirements ?? {})) {
|
|
290
|
-
if (!seen.has(id)) { seen.add(id); ids.push(id); }
|
|
291
|
-
}
|
|
292
|
-
if (ids.length === 0) return [];
|
|
293
|
-
|
|
294
|
-
return ids.map((id) => {
|
|
295
|
-
const traced = items.filter((it) => it.variants.some((v) => v.traces.includes(id)));
|
|
296
|
-
const override = (map.requirements ?? {})[id];
|
|
297
|
-
return {
|
|
298
|
-
id,
|
|
299
|
-
status: override?.status ?? (traced.length > 0 ? 'covered' : 'gap'),
|
|
300
|
-
items: traced.map((it) => it.id),
|
|
301
|
-
variantCount: traced.reduce((a, it) => a + it.variants.filter((v) => v.traces.includes(id)).length, 0),
|
|
302
|
-
note: override?.note ?? '',
|
|
303
|
-
};
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
/** Resolve one level of {{key}} cross-references inside test-data VALUES. */
|
|
308
|
-
function resolveCrossRefs(testData: Record<string, string> | null): Record<string, string> | null {
|
|
309
|
-
if (!testData) return null;
|
|
310
|
-
const out: Record<string, string> = {};
|
|
311
|
-
for (const [k, v] of Object.entries(testData)) {
|
|
312
|
-
out[k] = typeof v === 'string' && v.includes('{{') ? substituteDisplayVars(v, testData) : v;
|
|
313
|
-
}
|
|
314
|
-
return out;
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
function rowAsStrings(row: Record<string, unknown>): Record<string, string> {
|
|
318
|
-
const out: Record<string, string> = {};
|
|
319
|
-
for (const [k, v] of Object.entries(row)) {
|
|
320
|
-
out[k] = String(v);
|
|
321
|
-
out[`row.${k}`] = String(v); // steps reference dataset columns as {{row.<col>}}
|
|
322
|
-
}
|
|
323
|
-
return out;
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
// ---------------------------------------------------------------------------
|
|
327
|
-
// Item assembly + roll-up
|
|
328
|
-
// ---------------------------------------------------------------------------
|
|
329
|
-
|
|
330
|
-
/**
|
|
331
|
-
* The exact word rendered in a variant's Result cell. This is the SINGLE
|
|
332
|
-
* vocabulary both the renderers and the parent's COUNTIF roll-up use — the
|
|
333
|
-
* legacy exporter's statusToTestResult disagreed on two statuses (`skipped`
|
|
334
|
-
* showed N/A but counted as not-run; `interrupted` showed Pending but counted
|
|
335
|
-
* as blocked), which silently skewed the derived parent result.
|
|
336
|
-
*/
|
|
337
|
-
export function variantState(v: CoverageVariant): VariantState {
|
|
338
|
-
const r = v.result;
|
|
339
|
-
if (!r) return 'Pending';
|
|
340
|
-
switch (r.status) {
|
|
341
|
-
case 'passed': return 'Passed';
|
|
342
|
-
case 'failed':
|
|
343
|
-
case 'timedOut': return 'Failed';
|
|
344
|
-
case 'interrupted': return 'Blocked';
|
|
345
|
-
case 'skipped': return 'N/A';
|
|
346
|
-
default: return 'Pending';
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
const STATE_TO_COUNT: Record<VariantState, keyof DeliveryItem['resultCounts']> = {
|
|
351
|
-
Passed: 'passed', Failed: 'failed', Blocked: 'blocked', Pending: 'notRun', 'N/A': 'na',
|
|
352
|
-
};
|
|
353
|
-
|
|
354
|
-
/**
|
|
355
|
-
* Derived parent result — precedence failed → blocked → all-N/A → not_run →
|
|
356
|
-
* partial → passed. `N/A` variants leave the denominator (an intentionally
|
|
357
|
-
* skipped case must not make the parent look incomplete).
|
|
358
|
-
*/
|
|
359
|
-
export function rollUp(variants: CoverageVariant[]): { result: ItemResult; counts: DeliveryItem['resultCounts'] } {
|
|
360
|
-
const counts = { passed: 0, failed: 0, blocked: 0, notRun: 0, na: 0 };
|
|
361
|
-
for (const v of variants) counts[STATE_TO_COUNT[variantState(v)]]++;
|
|
362
|
-
const effective = variants.length - counts.na;
|
|
363
|
-
let result: ItemResult;
|
|
364
|
-
if (counts.failed > 0) result = 'failed';
|
|
365
|
-
else if (counts.blocked > 0) result = 'blocked';
|
|
366
|
-
else if (effective === 0) result = 'na';
|
|
367
|
-
else if (counts.passed === 0) result = 'not_run';
|
|
368
|
-
else if (counts.passed === effective) result = 'passed';
|
|
369
|
-
else result = 'partial';
|
|
370
|
-
return { result, counts };
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
/** Longest shared leading run of steps — hoisted onto the parent row. */
|
|
374
|
-
function commonPrefix(lists: string[][]): number {
|
|
375
|
-
if (lists.length === 0) return 0;
|
|
376
|
-
let n = 0;
|
|
377
|
-
while (lists.every((l) => l.length > n) && new Set(lists.map((l) => l[n])).size === 1) n++;
|
|
378
|
-
return n;
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
/**
|
|
382
|
-
* Expand one map variant ref to concrete variant refs:
|
|
383
|
-
* a bare VP-id whose scenario has a dataset means ALL its rows.
|
|
384
|
-
*/
|
|
385
|
-
export function expandMapRef(ref: string, variantsByVp: Map<string, CoverageVariant[]>): CoverageVariant[] {
|
|
386
|
-
if (ref.includes('#')) {
|
|
387
|
-
const [vp] = ref.split('#');
|
|
388
|
-
return (variantsByVp.get(vp) ?? []).filter((v) => v.ref === ref);
|
|
389
|
-
}
|
|
390
|
-
return variantsByVp.get(ref) ?? [];
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
export function buildMatrix(inputs: BuildInputs): MatrixModel {
|
|
394
|
-
const { unit, map, transformerVersion } = inputs;
|
|
395
|
-
const variants = deriveVariants(inputs);
|
|
396
|
-
|
|
397
|
-
const variantsByVp = new Map<string, CoverageVariant[]>();
|
|
398
|
-
for (const v of variants) {
|
|
399
|
-
const list = variantsByVp.get(v.vpId) ?? [];
|
|
400
|
-
list.push(v);
|
|
401
|
-
variantsByVp.set(v.vpId, list);
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
const findings = runGates({ inputs, variants, variantsByVp });
|
|
405
|
-
const stale = new Set(findings.filter((f) => f.gate === 'E' && f.ref).map((f) => f.ref as string));
|
|
406
|
-
|
|
407
|
-
const items: DeliveryItem[] = map.groups.map((g) => {
|
|
408
|
-
const groupVariants = g.variants.flatMap((ref) => expandMapRef(ref, variantsByVp));
|
|
409
|
-
const { result, counts } = rollUp(groupVariants);
|
|
410
|
-
const first = groupVariants[0];
|
|
411
|
-
const modes = new Set(groupVariants.map((v) => v.mode));
|
|
412
|
-
const commonPre = (first?.precondition ?? []).filter((line) =>
|
|
413
|
-
groupVariants.every((v) => v.precondition.includes(line)));
|
|
414
|
-
// Steps every variant starts with belong on the parent once; each variant
|
|
415
|
-
// renders only its remaining steps (review: the shared prefix was repeated
|
|
416
|
-
// on every child while the parent cell sat empty).
|
|
417
|
-
const prefixLen = commonPrefix(groupVariants.map((v) => v.trigger));
|
|
418
|
-
// Item priority = highest variant priority (per-variant priorities stay visible).
|
|
419
|
-
const priorityRank: Record<string, number> = { High: 0, Normal: 1, Low: 2 };
|
|
420
|
-
const priority = groupVariants
|
|
421
|
-
.map((v) => v.priority)
|
|
422
|
-
.sort((a, b) => (priorityRank[a] ?? 1) - (priorityRank[b] ?? 1))[0] ?? 'Normal';
|
|
423
|
-
return {
|
|
424
|
-
id: g.id,
|
|
425
|
-
target: g.target,
|
|
426
|
-
intent: g.intent,
|
|
427
|
-
oracle: g.oracle,
|
|
428
|
-
category: g.category,
|
|
429
|
-
// A stale (drifted) group presents as proposed regardless of its stored state.
|
|
430
|
-
review: stale.has(g.id) ? 'proposed' : g.review,
|
|
431
|
-
priority,
|
|
432
|
-
mode: modes.size > 1 ? 'mixed' : (first?.mode ?? 'auto'),
|
|
433
|
-
layers: Array.from(new Set(groupVariants.flatMap((v) => v.layers))),
|
|
434
|
-
traces: Array.from(new Set(groupVariants.flatMap((v) => v.traces))),
|
|
435
|
-
dimensions: g.dimensions,
|
|
436
|
-
// Only the preconditions COMMON to every variant belong on the parent —
|
|
437
|
-
// copying the first variant's setup mis-states the start state of the
|
|
438
|
-
// others (review GAP-03). Variant-specific lines render as the sub-row's
|
|
439
|
-
// precondition delta.
|
|
440
|
-
precondition: commonPre,
|
|
441
|
-
preconditionDeltas: Object.fromEntries(groupVariants.map((v) =>
|
|
442
|
-
[v.ref, v.precondition.filter((line) => !commonPre.includes(line))])),
|
|
443
|
-
triggerDeltas: Object.fromEntries(groupVariants.map((v) =>
|
|
444
|
-
[v.ref, v.trigger.slice(prefixLen)])),
|
|
445
|
-
trigger: (first?.trigger ?? []).slice(0, prefixLen),
|
|
446
|
-
variants: groupVariants,
|
|
447
|
-
result,
|
|
448
|
-
resultCounts: counts,
|
|
449
|
-
};
|
|
450
|
-
});
|
|
451
|
-
|
|
452
|
-
const dispositions: MatrixDisposition[] = Object.entries(map.dispositions).map(([vpId, d]) => ({
|
|
453
|
-
vpId,
|
|
454
|
-
title: variantsByVp.get(vpId)?.[0]?.title ?? '',
|
|
455
|
-
as: d.as,
|
|
456
|
-
reason: d.reason ?? '',
|
|
457
|
-
}));
|
|
458
|
-
|
|
459
|
-
// Requirement coverage (review §6): the requirement-id inventory comes from
|
|
460
|
-
// requirements/spec.md; @spec: traces mark `covered`; the map's `requirements:`
|
|
461
|
-
// section carries the reviewed overrides (partially_covered / not_applicable / …).
|
|
462
|
-
const requirements = computeRequirements(inputs.specText ?? '', map, items);
|
|
463
|
-
const gaps = requirements.filter((r) => r.status === 'gap');
|
|
464
|
-
if (gaps.length > 0) {
|
|
465
|
-
findings.push({
|
|
466
|
-
gate: 'R', severity: 'warning',
|
|
467
|
-
message: `${gaps.length} requirement id(s) with no coverage or disposition: ${gaps.map((g) => g.id).join(', ')} — trace them, or record a status in the map \`requirements:\` section`,
|
|
468
|
-
});
|
|
469
|
-
}
|
|
470
|
-
// A `covered` claim with no traced variant is prose, not traceability: nothing
|
|
471
|
-
// detects it when the proving scenario is later changed or deleted. Either tag
|
|
472
|
-
// the scenario that proves it (`@spec:<id>`) or say where it IS covered.
|
|
473
|
-
const unbacked = requirements.filter((r) => r.status === 'covered' && r.items.length === 0);
|
|
474
|
-
if (unbacked.length > 0) {
|
|
475
|
-
findings.push({
|
|
476
|
-
gate: 'R', severity: 'warning',
|
|
477
|
-
message: `${unbacked.length} requirement id(s) declared \`covered\` with no variant tracing to them: ${unbacked.map((r) => r.id).join(', ')} — add \`@spec:<id>\` to the scenario that proves each, or use covered_elsewhere / partially_covered with a named reference`,
|
|
478
|
-
});
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
const variantCount = items.reduce((a, i) => a + i.variants.length, 0);
|
|
482
|
-
const approved = items.every((i) => i.review === 'approved')
|
|
483
|
-
&& !findings.some((f) => f.severity === 'error' || f.severity === 'review');
|
|
484
|
-
|
|
485
|
-
return {
|
|
486
|
-
unit,
|
|
487
|
-
formNo: map.formNo ?? 'BM-2-901-13',
|
|
488
|
-
items,
|
|
489
|
-
dispositions,
|
|
490
|
-
requirements,
|
|
491
|
-
findings,
|
|
492
|
-
manifest: {
|
|
493
|
-
unit,
|
|
494
|
-
transformerVersion,
|
|
495
|
-
sourceFingerprint: combinedFingerprint(variants.map((v) => v.fingerprint)),
|
|
496
|
-
mapFingerprint: mapContentFingerprint(map.groups, map.dispositions),
|
|
497
|
-
approvalState: approved ? 'approved' : 'draft',
|
|
498
|
-
itemCount: items.length,
|
|
499
|
-
variantCount,
|
|
500
|
-
thresholds: { maxVariantsPerItem: MAX_VARIANTS_PER_ITEM },
|
|
501
|
-
},
|
|
502
|
-
};
|
|
503
|
-
}
|
|
@@ -1,149 +0,0 @@
|
|
|
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 { mapContentFingerprint } from './fingerprint';
|
|
21
|
-
import { buildMatrix, deriveVariants } from './build';
|
|
22
|
-
import { renderMatrixXlsx } from './render-xlsx';
|
|
23
|
-
import { renderMatrixCsv } from './render-csv';
|
|
24
|
-
import { DeliveryMap, MatrixFinding, MatrixModel } from './types';
|
|
25
|
-
|
|
26
|
-
export interface MatrixTargetPaths {
|
|
27
|
-
cwd: string;
|
|
28
|
-
/** Feature basename — names the deliverable files. */
|
|
29
|
-
unit: string;
|
|
30
|
-
/** Display label (flow/… prefix for flows). */
|
|
31
|
-
label: string;
|
|
32
|
-
featureFile: string;
|
|
33
|
-
testDataFile: string;
|
|
34
|
-
specFile: string;
|
|
35
|
-
/** requirements/spec.md — the requirement-id inventory for coverage (optional). */
|
|
36
|
-
specMdFile?: string;
|
|
37
|
-
resultsPath: string | null;
|
|
38
|
-
mapFile: string;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function readSpecText(paths: MatrixTargetPaths): string {
|
|
42
|
-
return paths.specMdFile && fs.existsSync(paths.specMdFile)
|
|
43
|
-
? fs.readFileSync(paths.specMdFile, 'utf-8')
|
|
44
|
-
: '';
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
export interface MatrixLoadResult {
|
|
48
|
-
model?: MatrixModel;
|
|
49
|
-
map?: DeliveryMap;
|
|
50
|
-
/** No map file → the caller prints the guidance path (AI proposal or --legacy). */
|
|
51
|
-
mapMissing?: boolean;
|
|
52
|
-
/** Structural map problems (bad YAML/shape) — fix the file before anything else. */
|
|
53
|
-
mapErrors: string[];
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export function loadMatrixModel(paths: MatrixTargetPaths): MatrixLoadResult {
|
|
57
|
-
const { map, errors } = loadDeliveryMap(paths.mapFile);
|
|
58
|
-
if (!map) {
|
|
59
|
-
return errors.length === 0 ? { mapMissing: true, mapErrors: [] } : { mapErrors: errors };
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const feature = parseFeatureMetadata(paths.featureFile);
|
|
63
|
-
const spec = parseSpecFile(paths.specFile);
|
|
64
|
-
const merged = mergeFeatureAndSpec(feature, spec);
|
|
65
|
-
const testData = fs.existsSync(paths.testDataFile) ? loadTestData(paths.testDataFile, process.env.SUNGEN_ENV ?? null) : null;
|
|
66
|
-
const results = paths.resultsPath ? loadPlaywrightReport(paths.resultsPath) : null;
|
|
67
|
-
|
|
68
|
-
const model = buildMatrix({
|
|
69
|
-
unit: paths.unit,
|
|
70
|
-
feature,
|
|
71
|
-
merged,
|
|
72
|
-
testData,
|
|
73
|
-
results,
|
|
74
|
-
map,
|
|
75
|
-
transformerVersion: getPackageVersion(),
|
|
76
|
-
specText: readSpecText(paths),
|
|
77
|
-
});
|
|
78
|
-
return { model, map, mapErrors: [] };
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
export const hasErrors = (f: MatrixFinding[]): boolean => f.some((x) => x.severity === 'error');
|
|
82
|
-
export const hasReview = (f: MatrixFinding[]): boolean => f.some((x) => x.severity === 'review');
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* Stamp fingerprints + flip groups to `approved` (all groups, or just `groupIds`).
|
|
86
|
-
* Refuses when gate ERRORs remain — an invalid map must not be frozen as approved.
|
|
87
|
-
* Returns the findings so the caller reports what blocked or what was approved.
|
|
88
|
-
*/
|
|
89
|
-
export function approveMatrix(paths: MatrixTargetPaths, groupIds?: string[]): { findings: MatrixFinding[]; approved: string[] } {
|
|
90
|
-
const { map, errors } = loadDeliveryMap(paths.mapFile);
|
|
91
|
-
if (!map) throw new Error(errors.length > 0 ? `map is invalid:\n - ${errors.join('\n - ')}` : `no delivery map at ${paths.mapFile}`);
|
|
92
|
-
|
|
93
|
-
const feature = parseFeatureMetadata(paths.featureFile);
|
|
94
|
-
const spec = parseSpecFile(paths.specFile);
|
|
95
|
-
const merged = mergeFeatureAndSpec(feature, spec);
|
|
96
|
-
const testData = fs.existsSync(paths.testDataFile) ? loadTestData(paths.testDataFile, process.env.SUNGEN_ENV ?? null) : null;
|
|
97
|
-
|
|
98
|
-
const model = buildMatrix({
|
|
99
|
-
unit: paths.unit, feature, merged, testData, results: null, map,
|
|
100
|
-
transformerVersion: getPackageVersion(),
|
|
101
|
-
specText: readSpecText(paths),
|
|
102
|
-
});
|
|
103
|
-
const blocking = model.findings.filter((f) => f.severity === 'error');
|
|
104
|
-
if (blocking.length > 0) return { findings: blocking, approved: [] };
|
|
105
|
-
|
|
106
|
-
const variants = deriveVariants({ feature, merged, testData, results: null });
|
|
107
|
-
const byRef = new Map(variants.map((v) => [v.ref, v] as const));
|
|
108
|
-
const byVp = new Map<string, typeof variants>();
|
|
109
|
-
for (const v of variants) {
|
|
110
|
-
const list = byVp.get(v.vpId) ?? [];
|
|
111
|
-
list.push(v);
|
|
112
|
-
byVp.set(v.vpId, list);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const approved: string[] = [];
|
|
116
|
-
for (const g of map.groups) {
|
|
117
|
-
if (groupIds && groupIds.length > 0 && !groupIds.includes(g.id)) continue;
|
|
118
|
-
for (const ref of g.variants) {
|
|
119
|
-
const expanded = ref.includes('#') ? [byRef.get(ref)].filter(Boolean) : (byVp.get(ref) ?? []);
|
|
120
|
-
for (const v of expanded) map.fingerprints[(v as NonNullable<typeof expanded[number]>).ref] = (v as NonNullable<typeof expanded[number]>).fingerprint;
|
|
121
|
-
}
|
|
122
|
-
g.review = 'approved';
|
|
123
|
-
approved.push(g.id);
|
|
124
|
-
}
|
|
125
|
-
// Freeze the reviewed map semantics as well (GAP-09) — computed AFTER the
|
|
126
|
-
// review flips so re-running approve on an unchanged map is idempotent.
|
|
127
|
-
map.fingerprints.__map__ = mapContentFingerprint(map.groups, map.dispositions);
|
|
128
|
-
writeDeliveryMap(paths.mapFile, map);
|
|
129
|
-
return { findings: model.findings.filter((f) => f.severity !== 'error'), approved };
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
export type MatrixFormat = 'xlsx' | 'csv' | 'both';
|
|
133
|
-
|
|
134
|
-
/** Render + write the requested format(s). Caller has already enforced the gate policy. */
|
|
135
|
-
export async function writeMatrixDeliverables(
|
|
136
|
-
paths: MatrixTargetPaths,
|
|
137
|
-
model: MatrixModel,
|
|
138
|
-
format: MatrixFormat = 'xlsx',
|
|
139
|
-
): Promise<{ csvPath?: string; xlsxPath?: string }> {
|
|
140
|
-
const out: { csvPath?: string; xlsxPath?: string } = {};
|
|
141
|
-
if (format === 'csv' || format === 'both') {
|
|
142
|
-
out.csvPath = writeCsv(paths.cwd, paths.unit, renderMatrixCsv(model));
|
|
143
|
-
}
|
|
144
|
-
if (format === 'xlsx' || format === 'both') {
|
|
145
|
-
const wb = renderMatrixXlsx(model, getPackageVersion());
|
|
146
|
-
out.xlsxPath = await writeXlsx(paths.cwd, paths.unit, wb);
|
|
147
|
-
}
|
|
148
|
-
return out;
|
|
149
|
-
}
|