@sun-asterisk/sungen 3.2.17 → 3.2.18
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/audit.d.ts.map +1 -1
- package/dist/cli/commands/audit.js +23 -0
- package/dist/cli/commands/audit.js.map +1 -1
- package/dist/cli/commands/delivery.d.ts.map +1 -1
- package/dist/cli/commands/delivery.js +209 -16
- package/dist/cli/commands/delivery.js.map +1 -1
- package/dist/cli/index.js +5 -0
- package/dist/cli/index.js.map +1 -1
- package/dist/dashboard/snapshot-builder.d.ts.map +1 -1
- package/dist/dashboard/snapshot-builder.js +8 -1
- package/dist/dashboard/snapshot-builder.js.map +1 -1
- package/dist/dashboard/templates/index.html +1 -1
- package/dist/exporters/api-environment.d.ts +11 -0
- package/dist/exporters/api-environment.d.ts.map +1 -0
- package/dist/exporters/api-environment.js +129 -0
- package/dist/exporters/api-environment.js.map +1 -0
- package/dist/exporters/feature-parser.d.ts +16 -1
- package/dist/exporters/feature-parser.d.ts.map +1 -1
- package/dist/exporters/feature-parser.js +21 -2
- package/dist/exporters/feature-parser.js.map +1 -1
- package/dist/exporters/matrix/build.d.ts +70 -0
- package/dist/exporters/matrix/build.d.ts.map +1 -0
- package/dist/exporters/matrix/build.js +516 -0
- package/dist/exporters/matrix/build.js.map +1 -0
- package/dist/exporters/matrix/export.d.ts +50 -0
- package/dist/exporters/matrix/export.d.ts.map +1 -0
- package/dist/exporters/matrix/export.js +152 -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 +367 -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 +193 -0
- package/dist/exporters/matrix/map-loader.js.map +1 -0
- package/dist/exporters/matrix/render-csv.d.ts +9 -0
- package/dist/exporters/matrix/render-csv.d.ts.map +1 -0
- package/dist/exporters/matrix/render-csv.js +92 -0
- package/dist/exporters/matrix/render-csv.js.map +1 -0
- package/dist/exporters/matrix/render-xlsx.d.ts +41 -0
- package/dist/exporters/matrix/render-xlsx.d.ts.map +1 -0
- package/dist/exporters/matrix/render-xlsx.js +430 -0
- package/dist/exporters/matrix/render-xlsx.js.map +1 -0
- package/dist/exporters/matrix/types.d.ts +199 -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/matrix/wording.d.ts +61 -0
- package/dist/exporters/matrix/wording.d.ts.map +1 -0
- package/dist/exporters/matrix/wording.js +221 -0
- package/dist/exporters/matrix/wording.js.map +1 -0
- package/dist/exporters/scenario-merger.d.ts.map +1 -1
- package/dist/exporters/scenario-merger.js +2 -1
- package/dist/exporters/scenario-merger.js.map +1 -1
- package/dist/exporters/spec-parser.d.ts.map +1 -1
- package/dist/exporters/spec-parser.js +2 -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/harness/audit.d.ts +10 -0
- package/dist/harness/audit.d.ts.map +1 -1
- package/dist/harness/audit.js +98 -16
- package/dist/harness/audit.js.map +1 -1
- package/dist/harness/blindspot.d.ts.map +1 -1
- package/dist/harness/blindspot.js +2 -1
- package/dist/harness/blindspot.js.map +1 -1
- package/dist/harness/capability-plan.d.ts +2 -0
- package/dist/harness/capability-plan.d.ts.map +1 -1
- package/dist/harness/capability-plan.js +17 -4
- package/dist/harness/capability-plan.js.map +1 -1
- package/dist/harness/feedback.d.ts.map +1 -1
- package/dist/harness/feedback.js +3 -2
- package/dist/harness/feedback.js.map +1 -1
- package/dist/harness/flow-check.d.ts.map +1 -1
- package/dist/harness/flow-check.js +2 -1
- package/dist/harness/flow-check.js.map +1 -1
- package/dist/harness/flow-plan.d.ts.map +1 -1
- package/dist/harness/flow-plan.js +3 -2
- package/dist/harness/flow-plan.js.map +1 -1
- package/dist/harness/intent.d.ts.map +1 -1
- package/dist/harness/intent.js +2 -1
- package/dist/harness/intent.js.map +1 -1
- package/dist/harness/journey.d.ts.map +1 -1
- package/dist/harness/journey.js +3 -2
- package/dist/harness/journey.js.map +1 -1
- package/dist/harness/ledger.d.ts.map +1 -1
- package/dist/harness/ledger.js +3 -2
- package/dist/harness/ledger.js.map +1 -1
- package/dist/harness/manifest.d.ts.map +1 -1
- package/dist/harness/manifest.js +4 -3
- package/dist/harness/manifest.js.map +1 -1
- package/dist/harness/parse.d.ts.map +1 -1
- package/dist/harness/parse.js +16 -3
- package/dist/harness/parse.js.map +1 -1
- package/dist/harness/quality-gates.d.ts.map +1 -1
- package/dist/harness/quality-gates.js +2 -1
- package/dist/harness/quality-gates.js.map +1 -1
- package/dist/harness/read-text.d.ts +22 -0
- package/dist/harness/read-text.d.ts.map +1 -0
- package/dist/harness/read-text.js +64 -0
- package/dist/harness/read-text.js.map +1 -0
- package/dist/harness/script-check.d.ts.map +1 -1
- package/dist/harness/script-check.js +3 -2
- package/dist/harness/script-check.js.map +1 -1
- package/dist/harness/sensors.d.ts +13 -1
- package/dist/harness/sensors.d.ts.map +1 -1
- package/dist/harness/sensors.js +63 -20
- package/dist/harness/sensors.js.map +1 -1
- package/dist/harness/spec-coverage.d.ts +5 -0
- package/dist/harness/spec-coverage.d.ts.map +1 -1
- package/dist/harness/spec-coverage.js +17 -7
- package/dist/harness/spec-coverage.js.map +1 -1
- package/dist/harness/trace.d.ts.map +1 -1
- package/dist/harness/trace.js +4 -3
- package/dist/harness/trace.js.map +1 -1
- package/dist/harness/viewpoint-baseline.d.ts +49 -0
- package/dist/harness/viewpoint-baseline.d.ts.map +1 -0
- package/dist/harness/viewpoint-baseline.js +141 -0
- package/dist/harness/viewpoint-baseline.js.map +1 -0
- package/dist/harness/viewpoint-ledger.d.ts.map +1 -1
- package/dist/harness/viewpoint-ledger.js +2 -1
- package/dist/harness/viewpoint-ledger.js.map +1 -1
- package/dist/orchestrator/assets-drift.d.ts +24 -0
- package/dist/orchestrator/assets-drift.d.ts.map +1 -0
- package/dist/orchestrator/assets-drift.js +80 -0
- package/dist/orchestrator/assets-drift.js.map +1 -0
- package/dist/orchestrator/templates/ai-src/commands/create-test.md +24 -0
- package/dist/orchestrator/templates/ai-src/commands/delivery.md +203 -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 +102 -6
- package/dist/orchestrator/templates/ai-src/skills/sungen-gherkin-syntax/SKILL.md +1 -0
- package/dist/orchestrator/templates/ai-src/skills/sungen-tc-generation/SKILL.md +23 -0
- package/package.json +3 -3
- package/src/cli/commands/audit.ts +23 -1
- package/src/cli/commands/delivery.ts +240 -18
- package/src/cli/index.ts +6 -0
- package/src/dashboard/snapshot-builder.ts +8 -1
- package/src/dashboard/templates/index.html +1 -1
- package/src/exporters/api-environment.ts +97 -0
- package/src/exporters/feature-parser.ts +21 -2
- package/src/exporters/matrix/build.ts +551 -0
- package/src/exporters/matrix/export.ts +149 -0
- package/src/exporters/matrix/fingerprint.ts +49 -0
- package/src/exporters/matrix/gates.ts +400 -0
- package/src/exporters/matrix/map-loader.ts +163 -0
- package/src/exporters/matrix/render-csv.ts +94 -0
- package/src/exporters/matrix/render-xlsx.ts +420 -0
- package/src/exporters/matrix/types.ts +226 -0
- package/src/exporters/matrix/wording.ts +221 -0
- package/src/exporters/scenario-merger.ts +2 -1
- package/src/exporters/spec-parser.ts +2 -1
- package/src/exporters/xlsx-report-builder.ts +3 -2
- package/src/harness/audit.ts +104 -18
- package/src/harness/blindspot.ts +2 -1
- package/src/harness/capability-plan.ts +17 -4
- package/src/harness/feedback.ts +3 -2
- package/src/harness/flow-check.ts +2 -1
- package/src/harness/flow-plan.ts +3 -2
- package/src/harness/intent.ts +2 -1
- package/src/harness/journey.ts +3 -2
- package/src/harness/ledger.ts +3 -2
- package/src/harness/manifest.ts +4 -3
- package/src/harness/parse.ts +17 -3
- package/src/harness/quality-gates.ts +2 -1
- package/src/harness/read-text.ts +28 -0
- package/src/harness/script-check.ts +3 -2
- package/src/harness/sensors.ts +55 -8
- package/src/harness/spec-coverage.ts +22 -7
- package/src/harness/trace.ts +4 -3
- package/src/harness/viewpoint-baseline.ts +128 -0
- package/src/harness/viewpoint-ledger.ts +2 -1
- package/src/orchestrator/assets-drift.ts +64 -0
- package/src/orchestrator/templates/ai-src/commands/create-test.md +24 -0
- package/src/orchestrator/templates/ai-src/commands/delivery.md +203 -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 +102 -6
- package/src/orchestrator/templates/ai-src/skills/sungen-gherkin-syntax/SKILL.md +1 -0
- package/src/orchestrator/templates/ai-src/skills/sungen-tc-generation/SKILL.md +23 -0
|
@@ -0,0 +1,551 @@
|
|
|
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, runtimeVarsOf } 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
|
+
// Category segment of the id, whatever the project's scheme:
|
|
117
|
+
// VP-SEC-001 → SEC · SEC-123 → SEC · MS-HP-001 → MS-HP · PER-345 → PER.
|
|
118
|
+
const vpCategory = vpId.replace(/^VP-/, '').replace(/-\d+(?:[a-zA-Z]|-[A-Z0-9]+)?$/, '');
|
|
119
|
+
const procedureProfile = deriveProcedureProfile(m);
|
|
120
|
+
|
|
121
|
+
// Manual scenarios: the `# Tester verifies:` block is classified into structured
|
|
122
|
+
// fields — Setup → precondition (review B-02), Action → trigger, Observable →
|
|
123
|
+
// expected, Oracle → verification method. Labels never remain inside prose.
|
|
124
|
+
const manual = mode === 'manual' && m.feature.comments?.length
|
|
125
|
+
? classifyManualComments(m.feature.comments)
|
|
126
|
+
: null;
|
|
127
|
+
|
|
128
|
+
// Raw (pre-wording) step texts — these feed shapes + Gate C, never the cells.
|
|
129
|
+
const rawTrigger = manual ? manual.actions : m.feature.rawWhenSteps;
|
|
130
|
+
const rawOracle = manual
|
|
131
|
+
? (manual.expected.length > 0 ? manual.expected : m.feature.rawThenSteps)
|
|
132
|
+
: m.resolvedExpected.filter((s) => s.bucket === 'then').map((s) => s.text);
|
|
133
|
+
|
|
134
|
+
// Values the scenario itself produces during the run — captured from the page
|
|
135
|
+
// or bound by a capability precondition. The compiler registers these as
|
|
136
|
+
// "captured" and skips YAML validation; the matrix does the same.
|
|
137
|
+
const runtimeVars = runtimeVarsOf(
|
|
138
|
+
[...m.resolvedSteps.map((st) => st.text), ...m.resolvedExpected.map((st) => st.text)],
|
|
139
|
+
tags,
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
const preconditionProfile = [
|
|
143
|
+
authRole ?? '-',
|
|
144
|
+
m.feature.extendsName ?? '-',
|
|
145
|
+
...m.feature.rawGivenSteps.map(normalizeShape),
|
|
146
|
+
...(manual?.preconditions ?? []).map(normalizeShape),
|
|
147
|
+
].join(' | ');
|
|
148
|
+
// Display precondition = auth state + Background Given (shared start state) +
|
|
149
|
+
// the scenario's own Given steps + manual Setup lines — deduplicated (a manual
|
|
150
|
+
// scenario often repeats the Background navigation as its own Given).
|
|
151
|
+
const precondition = Array.from(new Set([
|
|
152
|
+
...(authRole ? [authRole === 'no-auth' ? 'The user is signed out.' : `The user is signed in as ${authRole}.`] : []),
|
|
153
|
+
...inputs.feature.backgroundGivenSteps.map(renderPrecondition),
|
|
154
|
+
...m.feature.rawGivenSteps.map(renderPrecondition),
|
|
155
|
+
...(manual?.preconditions ?? []).map((t) => renderSetupInstruction(t)),
|
|
156
|
+
]));
|
|
157
|
+
|
|
158
|
+
const base = {
|
|
159
|
+
vpId,
|
|
160
|
+
vpCategory,
|
|
161
|
+
priority: extractPriority(tags),
|
|
162
|
+
mode: mode as 'auto' | 'manual',
|
|
163
|
+
manualReason: manualReason(tags),
|
|
164
|
+
layers: deriveLayers(tags),
|
|
165
|
+
traces: tags.filter((t) => t.startsWith('@spec:')).map((t) => t.slice('@spec:'.length)),
|
|
166
|
+
runtimeVars: [...runtimeVars],
|
|
167
|
+
triggerShape: rawTrigger.map(normalizeShape),
|
|
168
|
+
oracleShape: rawOracle.map(normalizeShape),
|
|
169
|
+
preconditionProfile,
|
|
170
|
+
precondition,
|
|
171
|
+
procedureProfile,
|
|
172
|
+
verification: manual?.verification.map((t) => sentenceOf(t)) ?? [],
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
/** Render the display cells for one data context (vars resolved first). */
|
|
176
|
+
const renderCells = (vars: Record<string, string>): { trigger: string[]; oracle: string[]; precondition: string[]; verification: string[] } => {
|
|
177
|
+
const sub = (s: string): string => substituteDisplayVars(s, vars, runtimeVars);
|
|
178
|
+
const preconditionOut = precondition.map(sub);
|
|
179
|
+
const verificationOut = base.verification.map(sub);
|
|
180
|
+
if (procedureProfile === 'sequence' && !manual) {
|
|
181
|
+
// Ordered flow (review B-03): keep the event order — actions stay numbered in
|
|
182
|
+
// the trigger, mid-flow assertions render inline as "Verify:", and only the
|
|
183
|
+
// FINAL Then block becomes the expected result.
|
|
184
|
+
const steps = m.feature.orderedSteps;
|
|
185
|
+
let lastActionIdx = -1;
|
|
186
|
+
steps.forEach((s, i) => { if (s.bucket !== 'then') lastActionIdx = i; });
|
|
187
|
+
const trigger: string[] = [];
|
|
188
|
+
const oracle: string[] = [];
|
|
189
|
+
steps.forEach((s, i) => {
|
|
190
|
+
if (i > lastActionIdx) oracle.push(renderExpected(sub(s.text))); // trailing Then block
|
|
191
|
+
else if (s.bucket === 'then') trigger.push(`Verify: ${renderExpected(sub(s.text))}`);
|
|
192
|
+
else if (s.bucket === 'when') trigger.push(renderAction(sub(s.text)));
|
|
193
|
+
// leading given steps already live in the precondition
|
|
194
|
+
});
|
|
195
|
+
return { trigger, oracle, precondition: preconditionOut, verification: verificationOut };
|
|
196
|
+
}
|
|
197
|
+
const trigger = rawTrigger.map((s) => renderAction(sub(s)));
|
|
198
|
+
const oracle = rawOracle.map((s) => renderExpected(sub(s)));
|
|
199
|
+
return {
|
|
200
|
+
// A pure-render check (Given + Then only) is checked on page load — say so
|
|
201
|
+
// in words instead of a placeholder token (review §10.3).
|
|
202
|
+
trigger: trigger.length > 0 ? trigger : ['No action — the state is checked on page load.'],
|
|
203
|
+
oracle,
|
|
204
|
+
precondition: preconditionOut,
|
|
205
|
+
verification: verificationOut,
|
|
206
|
+
};
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
const rows = getCasesDatasetRows(m, testData ?? undefined);
|
|
210
|
+
if (rows) {
|
|
211
|
+
// One variant per dataset row; results matched per row label by the shared resolver.
|
|
212
|
+
const resultVariants = resolveResultVariants(m, results ?? null, testData ?? undefined);
|
|
213
|
+
const resultByLabel = new Map(resultVariants.map((rv) => [rv.nameSuffix.replace(/^ — /, ''), rv.result]));
|
|
214
|
+
rows.forEach((row, i) => {
|
|
215
|
+
const label = String(row.case ?? row.name ?? row.label ?? `row ${i + 1}`);
|
|
216
|
+
const cells = renderCells({ ...(testData ?? {}), ...rowAsStrings(row) });
|
|
217
|
+
variants.push({
|
|
218
|
+
...base,
|
|
219
|
+
ref: `${vpId}#${label}`,
|
|
220
|
+
caseLabel: label,
|
|
221
|
+
title: `${category1} — ${label}`,
|
|
222
|
+
condition: label,
|
|
223
|
+
data: resolveDataPairs(m.feature.referencedVars, testData, row),
|
|
224
|
+
trigger: cells.trigger,
|
|
225
|
+
oracle: cells.oracle,
|
|
226
|
+
precondition: cells.precondition,
|
|
227
|
+
verification: cells.verification,
|
|
228
|
+
fingerprint: scenarioFingerprint(m.feature, row),
|
|
229
|
+
result: resultByLabel.get(label),
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
} else {
|
|
233
|
+
const cells = renderCells(testData ?? {});
|
|
234
|
+
variants.push({
|
|
235
|
+
...base,
|
|
236
|
+
ref: vpId,
|
|
237
|
+
title: category1,
|
|
238
|
+
condition: category1,
|
|
239
|
+
data: resolveDataPairs(m.feature.referencedVars, testData),
|
|
240
|
+
trigger: cells.trigger,
|
|
241
|
+
oracle: cells.oracle,
|
|
242
|
+
precondition: cells.precondition,
|
|
243
|
+
verification: cells.verification,
|
|
244
|
+
fingerprint: scenarioFingerprint(m.feature),
|
|
245
|
+
result: resolveResultVariants(m, results ?? null, testData ?? undefined)[0]?.result,
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return variants;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Display substitution for matrix cells. Unlike the legacy exporter's
|
|
254
|
+
* substituteTestDataVars (which keeps EMPTY values literal for the Steps
|
|
255
|
+
* column), an empty value is a legitimate test input here (an intentionally
|
|
256
|
+
* empty field) — it renders as `(empty)` so the tester sees the intent and no
|
|
257
|
+
* `{{token}}` survives into the deliverable (Gate D would reject it).
|
|
258
|
+
*/
|
|
259
|
+
function substituteDisplayVars(
|
|
260
|
+
text: string,
|
|
261
|
+
vars: Record<string, string>,
|
|
262
|
+
runtimeVars: Set<string> = new Set(),
|
|
263
|
+
): string {
|
|
264
|
+
// `remember … as {{v}}` DECLARES v — leave that token for renderAction, which
|
|
265
|
+
// turns it into a quoted name ("note it as …"), not a value to look up.
|
|
266
|
+
const isCapture = /\bremember\b/i.test(text);
|
|
267
|
+
return text.replace(/\{\{\s*([^}\s]+)\s*\}\}/g, (m, key: string, offset: number) => {
|
|
268
|
+
if (isCapture && /\bas\s+$/i.test(text.slice(0, offset))) return m;
|
|
269
|
+
// A value the test produces at run time has no static form — name it so the
|
|
270
|
+
// tester knows to compare against what the earlier step captured.
|
|
271
|
+
if (runtimeVars.has(key) || runtimeVars.has(key.split(/[.[]/)[0])) return `the captured ${key}`;
|
|
272
|
+
if (!(key in vars)) return m; // unknown stays literal → Gate D flags it
|
|
273
|
+
return displayValue(vars[key]);
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* Make invisible test data VISIBLE instead of losing it (review GAP-04):
|
|
279
|
+
* '' → (empty) · whitespace-only → (N spaces) · padded → quoted verbatim.
|
|
280
|
+
* The canonical value is never changed — only its presentation.
|
|
281
|
+
*/
|
|
282
|
+
export function displayValue(v: string): string {
|
|
283
|
+
if (v === '') return '(empty)';
|
|
284
|
+
if (/^\s+$/.test(v)) return `(${v.length} space${v.length > 1 ? 's' : ''})`;
|
|
285
|
+
if (v !== v.trim()) return `"${v}"`;
|
|
286
|
+
return v;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
function sentenceOf(text: string): string {
|
|
290
|
+
const s = text.trim();
|
|
291
|
+
if (!s) return s;
|
|
292
|
+
const cap = s.charAt(0).toUpperCase() + s.slice(1);
|
|
293
|
+
return /[.!?…]$/.test(cap) ? cap : `${cap}.`;
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/**
|
|
297
|
+
* Requirement inventory ∪ traces → coverage table. Ids are scanned from the spec
|
|
298
|
+
* text (FR-/TR-/NFR-<n>); map overrides win over the derived covered/gap status.
|
|
299
|
+
*/
|
|
300
|
+
export function computeRequirements(
|
|
301
|
+
specText: string,
|
|
302
|
+
map: DeliveryMap,
|
|
303
|
+
items: DeliveryItem[],
|
|
304
|
+
): RequirementCoverage[] {
|
|
305
|
+
const ids: string[] = [];
|
|
306
|
+
const seen = new Set<string>();
|
|
307
|
+
const add = (id: string): void => { if (!seen.has(id)) { seen.add(id); ids.push(id); } };
|
|
308
|
+
// A spec declares its requirements in bold — `- **FR-001**: …`, `- **REQ-12**: …`.
|
|
309
|
+
// Reading the DECLARATION (rather than any `PREFIX-123` token in the prose) keeps
|
|
310
|
+
// a project's own scheme working without matching ISO numbers, dates, or the form
|
|
311
|
+
// number in a header.
|
|
312
|
+
for (const m of specText.matchAll(/\*\*([A-Z][A-Z0-9]{1,7}-\d+)\*\*/g)) add(m[1]);
|
|
313
|
+
// Specs that do not bold their ids still work for the conventional prefixes.
|
|
314
|
+
if (ids.length === 0) {
|
|
315
|
+
for (const m of specText.matchAll(/\b(?:FR|TR|NFR)-\d+\b/g)) add(m[0]);
|
|
316
|
+
}
|
|
317
|
+
// Overrides may reference ids the spec text doesn't list (e.g. a shared catalog).
|
|
318
|
+
for (const id of Object.keys(map.requirements ?? {})) {
|
|
319
|
+
if (!seen.has(id)) { seen.add(id); ids.push(id); }
|
|
320
|
+
}
|
|
321
|
+
if (ids.length === 0) return [];
|
|
322
|
+
|
|
323
|
+
return ids.map((id) => {
|
|
324
|
+
const traced = items.filter((it) => it.variants.some((v) => v.traces.includes(id)));
|
|
325
|
+
const override = (map.requirements ?? {})[id];
|
|
326
|
+
return {
|
|
327
|
+
id,
|
|
328
|
+
status: override?.status ?? (traced.length > 0 ? 'covered' : 'gap'),
|
|
329
|
+
items: traced.map((it) => it.id),
|
|
330
|
+
variantCount: traced.reduce((a, it) => a + it.variants.filter((v) => v.traces.includes(id)).length, 0),
|
|
331
|
+
note: override?.note ?? '',
|
|
332
|
+
};
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/** Resolve one level of {{key}} cross-references inside test-data VALUES. */
|
|
337
|
+
function resolveCrossRefs(testData: Record<string, string> | null): Record<string, string> | null {
|
|
338
|
+
if (!testData) return null;
|
|
339
|
+
const out: Record<string, string> = {};
|
|
340
|
+
for (const [k, v] of Object.entries(testData)) {
|
|
341
|
+
out[k] = typeof v === 'string' && v.includes('{{') ? substituteDisplayVars(v, testData) : v;
|
|
342
|
+
}
|
|
343
|
+
return out;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
function rowAsStrings(row: Record<string, unknown>): Record<string, string> {
|
|
347
|
+
const out: Record<string, string> = {};
|
|
348
|
+
for (const [k, v] of Object.entries(row)) {
|
|
349
|
+
out[k] = String(v);
|
|
350
|
+
out[`row.${k}`] = String(v); // steps reference dataset columns as {{row.<col>}}
|
|
351
|
+
}
|
|
352
|
+
return out;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// ---------------------------------------------------------------------------
|
|
356
|
+
// Item assembly + roll-up
|
|
357
|
+
// ---------------------------------------------------------------------------
|
|
358
|
+
|
|
359
|
+
/**
|
|
360
|
+
* The exact word rendered in a variant's Result cell. This is the SINGLE
|
|
361
|
+
* vocabulary both the renderers and the parent's COUNTIF roll-up use — the
|
|
362
|
+
* legacy exporter's statusToTestResult disagreed on two statuses (`skipped`
|
|
363
|
+
* showed N/A but counted as not-run; `interrupted` showed Pending but counted
|
|
364
|
+
* as blocked), which silently skewed the derived parent result.
|
|
365
|
+
*/
|
|
366
|
+
export function variantState(v: CoverageVariant): VariantState {
|
|
367
|
+
const r = v.result;
|
|
368
|
+
if (!r) return 'Pending';
|
|
369
|
+
switch (r.status) {
|
|
370
|
+
case 'passed': return 'Passed';
|
|
371
|
+
case 'failed':
|
|
372
|
+
case 'timedOut': return 'Failed';
|
|
373
|
+
case 'interrupted': return 'Blocked';
|
|
374
|
+
case 'skipped': return 'N/A';
|
|
375
|
+
default: return 'Pending';
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
const STATE_TO_COUNT: Record<VariantState, keyof DeliveryItem['resultCounts']> = {
|
|
380
|
+
Passed: 'passed', Failed: 'failed', Blocked: 'blocked', Pending: 'notRun', 'N/A': 'na',
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Derived parent result — precedence failed → blocked → all-N/A → not_run →
|
|
385
|
+
* partial → passed. `N/A` variants leave the denominator (an intentionally
|
|
386
|
+
* skipped case must not make the parent look incomplete).
|
|
387
|
+
*/
|
|
388
|
+
export function rollUp(variants: CoverageVariant[]): { result: ItemResult; counts: DeliveryItem['resultCounts'] } {
|
|
389
|
+
const counts = { passed: 0, failed: 0, blocked: 0, notRun: 0, na: 0 };
|
|
390
|
+
for (const v of variants) counts[STATE_TO_COUNT[variantState(v)]]++;
|
|
391
|
+
const effective = variants.length - counts.na;
|
|
392
|
+
let result: ItemResult;
|
|
393
|
+
if (counts.failed > 0) result = 'failed';
|
|
394
|
+
else if (counts.blocked > 0) result = 'blocked';
|
|
395
|
+
else if (effective === 0) result = 'na';
|
|
396
|
+
else if (counts.passed === 0) result = 'not_run';
|
|
397
|
+
else if (counts.passed === effective) result = 'passed';
|
|
398
|
+
else result = 'partial';
|
|
399
|
+
return { result, counts };
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/** Longest shared leading run of steps — hoisted onto the parent row. */
|
|
403
|
+
function commonPrefix(lists: string[][]): number {
|
|
404
|
+
if (lists.length === 0) return 0;
|
|
405
|
+
let n = 0;
|
|
406
|
+
while (lists.every((l) => l.length > n) && new Set(lists.map((l) => l[n])).size === 1) n++;
|
|
407
|
+
return n;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* What the parent row's Action says when the variants share no opening step.
|
|
412
|
+
*
|
|
413
|
+
* The parent is the row a reviewer (and the customer) reads AS the test case, and
|
|
414
|
+
* with nothing to hoist its Action cell came out empty — 12 of 38 items in a real
|
|
415
|
+
* delivery. The steps are not missing, they are per-variant; say that, and name the
|
|
416
|
+
* axis they vary along so the cell carries meaning on its own.
|
|
417
|
+
*/
|
|
418
|
+
export function varyingTriggerNote(dimensions: string | undefined, count: number): string {
|
|
419
|
+
// `dimensions` reads "matching rule — title only · content only · …"; the part
|
|
420
|
+
// before the dash is the axis name.
|
|
421
|
+
const axis = dimensions?.split('—')[0].trim();
|
|
422
|
+
const where = axis && axis.length > 0 && axis.length <= 60 ? ` by ${axis}` : '';
|
|
423
|
+
return `The action differs${where} — run each of the ${count} variants below with its own steps.`;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* Expand one map variant ref to concrete variant refs:
|
|
428
|
+
* a bare VP-id whose scenario has a dataset means ALL its rows.
|
|
429
|
+
*/
|
|
430
|
+
export function expandMapRef(ref: string, variantsByVp: Map<string, CoverageVariant[]>): CoverageVariant[] {
|
|
431
|
+
if (ref.includes('#')) {
|
|
432
|
+
const [vp] = ref.split('#');
|
|
433
|
+
return (variantsByVp.get(vp) ?? []).filter((v) => v.ref === ref);
|
|
434
|
+
}
|
|
435
|
+
return variantsByVp.get(ref) ?? [];
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
export function buildMatrix(inputs: BuildInputs): MatrixModel {
|
|
439
|
+
const { unit, map, transformerVersion } = inputs;
|
|
440
|
+
const variants = deriveVariants(inputs);
|
|
441
|
+
|
|
442
|
+
const variantsByVp = new Map<string, CoverageVariant[]>();
|
|
443
|
+
for (const v of variants) {
|
|
444
|
+
const list = variantsByVp.get(v.vpId) ?? [];
|
|
445
|
+
list.push(v);
|
|
446
|
+
variantsByVp.set(v.vpId, list);
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
const findings = runGates({ inputs, variants, variantsByVp });
|
|
450
|
+
const stale = new Set(findings.filter((f) => f.gate === 'E' && f.ref).map((f) => f.ref as string));
|
|
451
|
+
|
|
452
|
+
const items: DeliveryItem[] = map.groups.map((g) => {
|
|
453
|
+
const groupVariants = g.variants.flatMap((ref) => expandMapRef(ref, variantsByVp));
|
|
454
|
+
const { result, counts } = rollUp(groupVariants);
|
|
455
|
+
const first = groupVariants[0];
|
|
456
|
+
const modes = new Set(groupVariants.map((v) => v.mode));
|
|
457
|
+
const commonPre = (first?.precondition ?? []).filter((line) =>
|
|
458
|
+
groupVariants.every((v) => v.precondition.includes(line)));
|
|
459
|
+
// Steps every variant starts with belong on the parent once; each variant
|
|
460
|
+
// renders only its remaining steps (review: the shared prefix was repeated
|
|
461
|
+
// on every child while the parent cell sat empty).
|
|
462
|
+
const prefixLen = commonPrefix(groupVariants.map((v) => v.trigger));
|
|
463
|
+
// Item priority = highest variant priority (per-variant priorities stay visible).
|
|
464
|
+
const priorityRank: Record<string, number> = { High: 0, Normal: 1, Low: 2 };
|
|
465
|
+
const priority = groupVariants
|
|
466
|
+
.map((v) => v.priority)
|
|
467
|
+
.sort((a, b) => (priorityRank[a] ?? 1) - (priorityRank[b] ?? 1))[0] ?? 'Normal';
|
|
468
|
+
return {
|
|
469
|
+
id: g.id,
|
|
470
|
+
target: g.target,
|
|
471
|
+
intent: g.intent,
|
|
472
|
+
oracle: g.oracle,
|
|
473
|
+
category: g.category,
|
|
474
|
+
// A stale (drifted) group presents as proposed regardless of its stored state.
|
|
475
|
+
review: stale.has(g.id) ? 'proposed' : g.review,
|
|
476
|
+
priority,
|
|
477
|
+
mode: modes.size > 1 ? 'mixed' : (first?.mode ?? 'auto'),
|
|
478
|
+
layers: Array.from(new Set(groupVariants.flatMap((v) => v.layers))),
|
|
479
|
+
traces: Array.from(new Set(groupVariants.flatMap((v) => v.traces))),
|
|
480
|
+
dimensions: g.dimensions,
|
|
481
|
+
// Only the preconditions COMMON to every variant belong on the parent —
|
|
482
|
+
// copying the first variant's setup mis-states the start state of the
|
|
483
|
+
// others (review GAP-03). Variant-specific lines render as the sub-row's
|
|
484
|
+
// precondition delta.
|
|
485
|
+
precondition: commonPre,
|
|
486
|
+
preconditionDeltas: Object.fromEntries(groupVariants.map((v) =>
|
|
487
|
+
[v.ref, v.precondition.filter((line) => !commonPre.includes(line))])),
|
|
488
|
+
triggerDeltas: Object.fromEntries(groupVariants.map((v) =>
|
|
489
|
+
[v.ref, v.trigger.slice(prefixLen)])),
|
|
490
|
+
// Nothing shared to hoist → say what varies rather than leaving the cell blank.
|
|
491
|
+
trigger: prefixLen > 0 || groupVariants.length === 0
|
|
492
|
+
? (first?.trigger ?? []).slice(0, prefixLen)
|
|
493
|
+
: [varyingTriggerNote(g.dimensions, groupVariants.length)],
|
|
494
|
+
variants: groupVariants,
|
|
495
|
+
result,
|
|
496
|
+
resultCounts: counts,
|
|
497
|
+
};
|
|
498
|
+
});
|
|
499
|
+
|
|
500
|
+
const dispositions: MatrixDisposition[] = Object.entries(map.dispositions).map(([vpId, d]) => ({
|
|
501
|
+
vpId,
|
|
502
|
+
title: variantsByVp.get(vpId)?.[0]?.title ?? '',
|
|
503
|
+
as: d.as,
|
|
504
|
+
reason: d.reason ?? '',
|
|
505
|
+
}));
|
|
506
|
+
|
|
507
|
+
// Requirement coverage (review §6): the requirement-id inventory comes from
|
|
508
|
+
// requirements/spec.md; @spec: traces mark `covered`; the map's `requirements:`
|
|
509
|
+
// section carries the reviewed overrides (partially_covered / not_applicable / …).
|
|
510
|
+
const requirements = computeRequirements(inputs.specText ?? '', map, items);
|
|
511
|
+
const gaps = requirements.filter((r) => r.status === 'gap');
|
|
512
|
+
if (gaps.length > 0) {
|
|
513
|
+
findings.push({
|
|
514
|
+
gate: 'R', severity: 'warning',
|
|
515
|
+
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`,
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
// A `covered` claim with no traced variant is prose, not traceability: nothing
|
|
519
|
+
// detects it when the proving scenario is later changed or deleted. Either tag
|
|
520
|
+
// the scenario that proves it (`@spec:<id>`) or say where it IS covered.
|
|
521
|
+
const unbacked = requirements.filter((r) => r.status === 'covered' && r.items.length === 0);
|
|
522
|
+
if (unbacked.length > 0) {
|
|
523
|
+
findings.push({
|
|
524
|
+
gate: 'R', severity: 'warning',
|
|
525
|
+
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`,
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
const variantCount = items.reduce((a, i) => a + i.variants.length, 0);
|
|
530
|
+
const approved = items.every((i) => i.review === 'approved')
|
|
531
|
+
&& !findings.some((f) => f.severity === 'error' || f.severity === 'review');
|
|
532
|
+
|
|
533
|
+
return {
|
|
534
|
+
unit,
|
|
535
|
+
formNo: map.formNo ?? 'BM-2-901-13',
|
|
536
|
+
items,
|
|
537
|
+
dispositions,
|
|
538
|
+
requirements,
|
|
539
|
+
findings,
|
|
540
|
+
manifest: {
|
|
541
|
+
unit,
|
|
542
|
+
transformerVersion,
|
|
543
|
+
sourceFingerprint: combinedFingerprint(variants.map((v) => v.fingerprint)),
|
|
544
|
+
mapFingerprint: mapContentFingerprint(map.groups, map.dispositions),
|
|
545
|
+
approvalState: approved ? 'approved' : 'draft',
|
|
546
|
+
itemCount: items.length,
|
|
547
|
+
variantCount,
|
|
548
|
+
thresholds: { maxVariantsPerItem: MAX_VARIANTS_PER_ITEM },
|
|
549
|
+
},
|
|
550
|
+
};
|
|
551
|
+
}
|