@llman-sdd/core 0.8.1 → 0.9.0
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/package.json +3 -1
- package/src/change/nextId.ts +7 -1
- package/src/config/load.ts +36 -2
- package/src/git/spawnGit.ts +5 -1
- package/src/index.ts +21 -5
- package/src/init/init.ts +71 -7
- package/src/project/migrations.ts +129 -47
- package/src/report/specHelpers.ts +7 -9
- package/src/spec/assignSpecIds.ts +66 -0
- package/src/spec/ir.ts +18 -7
- package/src/spec/keywords.ts +10 -0
- package/src/spec/migrateScope.ts +4 -4
- package/src/spec/parser.ts +40 -15
- package/src/validation/discover.ts +5 -1
- package/src/validation/validate.ts +42 -21
- package/src/validation/xstateTransitions.ts +372 -0
- package/templates/en/units/skills/validation-hints.md +7 -6
- package/templates/en/units/spec/feature-contract.md +1 -2
- package/templates/zh-Hans/units/skills/validation-hints.md +3 -2
- package/templates/zh-Hans/units/spec/feature-contract.md +1 -2
package/src/spec/ir.ts
CHANGED
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
export interface CapabilityHeader {
|
|
14
|
-
capability: string | null;
|
|
15
14
|
purpose: string | null;
|
|
16
15
|
}
|
|
17
16
|
|
|
@@ -22,6 +21,14 @@ export interface ScenarioStep {
|
|
|
22
21
|
text: string;
|
|
23
22
|
}
|
|
24
23
|
|
|
24
|
+
export interface ExamplesBlockIR {
|
|
25
|
+
name: string;
|
|
26
|
+
/** Trimmed header column names, e.g. ['from', 'event', 'to']. */
|
|
27
|
+
headers: string[];
|
|
28
|
+
/** Each row is a list of trimmed cell values aligned with `headers`. */
|
|
29
|
+
rows: string[][];
|
|
30
|
+
}
|
|
31
|
+
|
|
25
32
|
export interface ScenarioIR {
|
|
26
33
|
name: string;
|
|
27
34
|
/** Non-`@req` tags on this scenario (e.g. `@skip`, `@experimental`). */
|
|
@@ -32,6 +39,10 @@ export interface ScenarioIR {
|
|
|
32
39
|
steps: ScenarioStep[];
|
|
33
40
|
/** Step-texts joined (retrieval/context surface); empty for a stepless scenario. */
|
|
34
41
|
statement: string;
|
|
42
|
+
/** True when the scenario has at least one Examples block or uses Scenario Outline keyword. */
|
|
43
|
+
isOutline?: boolean;
|
|
44
|
+
/** Parsed Examples blocks attached to this scenario. */
|
|
45
|
+
examples?: ExamplesBlockIR[];
|
|
35
46
|
}
|
|
36
47
|
|
|
37
48
|
export interface RuleIR {
|
|
@@ -76,11 +87,11 @@ export function ruleHasRunnableScenario(rule: RuleIR): boolean {
|
|
|
76
87
|
}
|
|
77
88
|
|
|
78
89
|
/**
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
* `.feature` suffix. Unifies the former dual caliber (bare `fileName` vs
|
|
82
|
-
* stripped stem) shared by review/context-tree/specs-report/validate paths.
|
|
90
|
+
* Spec id for a discovered entry (r101): `entry.specId` after assignSpecIds;
|
|
91
|
+
* inline-parse fallback uses the basename stem only.
|
|
83
92
|
*/
|
|
84
|
-
export function specIdOf(entry: { fileName: string; doc: CapabilityDoc }): string {
|
|
85
|
-
|
|
93
|
+
export function specIdOf(entry: { fileName: string; doc: CapabilityDoc; specId?: string }): string {
|
|
94
|
+
if (entry.specId !== undefined && entry.specId !== '') return entry.specId;
|
|
95
|
+
const base = entry.fileName.replace(/\\/g, '/').split('/').pop() ?? entry.fileName;
|
|
96
|
+
return base.replace(/\.feature$/u, '');
|
|
86
97
|
}
|
package/src/spec/keywords.ts
CHANGED
|
@@ -17,6 +17,8 @@ export interface GherkinKeywords {
|
|
|
17
17
|
feature: string;
|
|
18
18
|
rule: string;
|
|
19
19
|
scenario: string;
|
|
20
|
+
scenarioOutline: string;
|
|
21
|
+
examples: string;
|
|
20
22
|
given: string;
|
|
21
23
|
when: string;
|
|
22
24
|
thenText: string;
|
|
@@ -29,6 +31,8 @@ const TABLE_KEY_PAIRS = [
|
|
|
29
31
|
['feature', 'feature'],
|
|
30
32
|
['rule', 'rule'],
|
|
31
33
|
['scenario', 'scenario'],
|
|
34
|
+
['scenarioOutline', 'scenarioOutline'],
|
|
35
|
+
['examples', 'examples'],
|
|
32
36
|
['given', 'given'],
|
|
33
37
|
['when', 'when'],
|
|
34
38
|
['then', 'thenText'],
|
|
@@ -40,6 +44,8 @@ const LOCKED_KEYWORDS: Record<string, GherkinKeywords> = {
|
|
|
40
44
|
feature: 'Feature',
|
|
41
45
|
rule: 'Rule',
|
|
42
46
|
scenario: 'Scenario',
|
|
47
|
+
scenarioOutline: 'Scenario Outline',
|
|
48
|
+
examples: 'Examples',
|
|
43
49
|
given: 'Given',
|
|
44
50
|
when: 'When',
|
|
45
51
|
thenText: 'Then',
|
|
@@ -48,6 +54,8 @@ const LOCKED_KEYWORDS: Record<string, GherkinKeywords> = {
|
|
|
48
54
|
feature: '功能',
|
|
49
55
|
rule: '规则',
|
|
50
56
|
scenario: '场景',
|
|
57
|
+
scenarioOutline: '场景大纲',
|
|
58
|
+
examples: '例子',
|
|
51
59
|
given: '假如',
|
|
52
60
|
when: '当',
|
|
53
61
|
thenText: '那么',
|
|
@@ -63,6 +71,8 @@ function keywordsFromTable(table: Dialect): GherkinKeywords | null {
|
|
|
63
71
|
feature: pickKeyword(table.feature),
|
|
64
72
|
rule: pickKeyword(table.rule),
|
|
65
73
|
scenario: pickKeyword(table.scenario),
|
|
74
|
+
scenarioOutline: pickKeyword(table.scenarioOutline),
|
|
75
|
+
examples: pickKeyword(table.examples),
|
|
66
76
|
given: pickKeyword(table.given),
|
|
67
77
|
when: pickKeyword(table.when),
|
|
68
78
|
thenText: pickKeyword(table.then),
|
package/src/spec/migrateScope.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Legacy governance-header strip (drop-review-stamp-and-scope): removes
|
|
3
|
-
* `# scope:` / `# reviewed-through:` comment lines anywhere in
|
|
4
|
-
*
|
|
5
|
-
*
|
|
3
|
+
* `# scope:` / `# reviewed-through:` / `# capability:` comment lines anywhere in
|
|
4
|
+
* a .feature — inert since the header contract is `# language:` + `# purpose:`.
|
|
5
|
+
* Pure: source in, result out; idempotent by construction
|
|
6
6
|
* (a stripped source yields zero removals on the second pass).
|
|
7
7
|
*/
|
|
8
8
|
export function stripLegacyHeaderLines(source: string): { content: string; removed: number } {
|
|
9
9
|
const lines = source.split('\n');
|
|
10
|
-
const kept = lines.filter((line) => !/^#\s*(scope|reviewed-through):/u.test(line));
|
|
10
|
+
const kept = lines.filter((line) => !/^#\s*(scope|reviewed-through|capability):/u.test(line));
|
|
11
11
|
return { content: kept.join('\n'), removed: lines.length - kept.length };
|
|
12
12
|
}
|
package/src/spec/parser.ts
CHANGED
|
@@ -14,6 +14,7 @@ import type { GherkinDocument } from '@cucumber/messages';
|
|
|
14
14
|
import {
|
|
15
15
|
type CapabilityDoc,
|
|
16
16
|
type CapabilityHeader,
|
|
17
|
+
type ExamplesBlockIR,
|
|
17
18
|
type RuleIR,
|
|
18
19
|
type ScenarioIR,
|
|
19
20
|
type ScenarioStepKind,
|
|
@@ -79,21 +80,15 @@ function stepKeywordToKind(keyword: string): ScenarioStepKind {
|
|
|
79
80
|
return stepKeywordToOfficialKind(keyword) ?? 'given';
|
|
80
81
|
}
|
|
81
82
|
|
|
82
|
-
const
|
|
83
|
+
const PURPOSE_HEADER_RE = /^#\s*purpose:\s*(.*)$/u;
|
|
83
84
|
|
|
84
85
|
function extractHeader(source: string): CapabilityHeader {
|
|
85
|
-
const header: CapabilityHeader = {
|
|
86
|
-
capability: null,
|
|
87
|
-
purpose: null,
|
|
88
|
-
};
|
|
86
|
+
const header: CapabilityHeader = { purpose: null };
|
|
89
87
|
for (const line of source.split('\n')) {
|
|
90
88
|
if (line.trim() === '') continue;
|
|
91
89
|
if (!line.trimStart().startsWith('#')) break;
|
|
92
|
-
const m = line.trimStart().match(
|
|
93
|
-
if (m
|
|
94
|
-
const field = m[1] as 'capability' | 'purpose';
|
|
95
|
-
header[field] = m[2]?.trim() ?? null;
|
|
96
|
-
}
|
|
90
|
+
const m = line.trimStart().match(PURPOSE_HEADER_RE);
|
|
91
|
+
if (m) header.purpose = m[1]?.trim() ?? null;
|
|
97
92
|
}
|
|
98
93
|
return header;
|
|
99
94
|
}
|
|
@@ -110,18 +105,45 @@ function parseTags(tags: readonly { name: string }[]): RawTags {
|
|
|
110
105
|
return { names, reqId: req ?? '' };
|
|
111
106
|
}
|
|
112
107
|
|
|
108
|
+
function collectExamples(
|
|
109
|
+
examples: readonly {
|
|
110
|
+
name: string;
|
|
111
|
+
tableHeader?: { cells: readonly { value: string }[] } | null;
|
|
112
|
+
tableBody: readonly { cells: readonly { value: string }[] }[];
|
|
113
|
+
}[],
|
|
114
|
+
): ExamplesBlockIR[] {
|
|
115
|
+
return examples.map((ex) => ({
|
|
116
|
+
name: ex.name ?? '',
|
|
117
|
+
headers: (ex.tableHeader?.cells ?? []).map((c) => c.value.trim()),
|
|
118
|
+
rows: ex.tableBody.map((row) => row.cells.map((c) => c.value.trim())),
|
|
119
|
+
}));
|
|
120
|
+
}
|
|
121
|
+
|
|
113
122
|
function collectScenario(sc: {
|
|
123
|
+
keyword?: string;
|
|
114
124
|
tags: readonly { name: string }[];
|
|
115
125
|
name: string;
|
|
116
126
|
steps: readonly { keyword: string; text: string }[];
|
|
127
|
+
examples?: readonly {
|
|
128
|
+
name: string;
|
|
129
|
+
tableHeader?: { cells: readonly { value: string }[] } | null;
|
|
130
|
+
tableBody: readonly { cells: readonly { value: string }[] }[];
|
|
131
|
+
}[];
|
|
117
132
|
}): ScenarioIR {
|
|
118
133
|
const { names, reqId: _ignored } = parseTags(sc.tags);
|
|
119
134
|
const skipTokens = new Set(['skip', 'experimental']);
|
|
120
|
-
|
|
135
|
+
let runnable = !names.some((n) => skipTokens.has(n));
|
|
121
136
|
const steps = sc.steps.map((s) => ({
|
|
122
137
|
kind: stepKeywordToKind(s.keyword),
|
|
123
138
|
text: s.text.trim(),
|
|
124
139
|
}));
|
|
140
|
+
const examplesBlocks = collectExamples(sc.examples ?? []);
|
|
141
|
+
const hasDataRows = examplesBlocks.some((b) => b.rows.length > 0);
|
|
142
|
+
const keyword = sc.keyword ?? '';
|
|
143
|
+
const isOutline = /outline|大纲/iu.test(keyword) || examplesBlocks.length > 0;
|
|
144
|
+
if (runnable && examplesBlocks.length > 0 && !hasDataRows) {
|
|
145
|
+
runnable = false;
|
|
146
|
+
}
|
|
125
147
|
return {
|
|
126
148
|
name: sc.name,
|
|
127
149
|
tags: names.filter(
|
|
@@ -136,6 +158,8 @@ function collectScenario(sc: {
|
|
|
136
158
|
stepCount: steps.length,
|
|
137
159
|
steps,
|
|
138
160
|
statement: steps.map((s) => s.text).join('\n'),
|
|
161
|
+
isOutline,
|
|
162
|
+
examples: examplesBlocks.length > 0 ? examplesBlocks : undefined,
|
|
139
163
|
};
|
|
140
164
|
}
|
|
141
165
|
|
|
@@ -143,10 +167,11 @@ function collectScenario(sc: {
|
|
|
143
167
|
export function parseCapability(source: string, fileName = '<inline>'): CapabilityDoc {
|
|
144
168
|
const errors: SpecStructuralError[] = [];
|
|
145
169
|
const header = extractHeader(source);
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
170
|
+
if (header.purpose === null) {
|
|
171
|
+
errors.push({
|
|
172
|
+
code: 'missing-header:purpose',
|
|
173
|
+
message: 'missing # purpose: header comment',
|
|
174
|
+
});
|
|
150
175
|
}
|
|
151
176
|
|
|
152
177
|
const { doc, language } = parseFeatureSource(source);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { assignSpecIds } from '../spec/assignSpecIds.ts';
|
|
1
2
|
import { parseCapability } from '../spec/parser.ts';
|
|
2
3
|
/**
|
|
3
4
|
* Spec discovery (validation capability): walk llmanspec/specs/** for
|
|
@@ -23,8 +24,11 @@ export function discoverSpecs(specsDir: string, io: DiscoveryIo): SpecEntry[] {
|
|
|
23
24
|
}
|
|
24
25
|
return out;
|
|
25
26
|
};
|
|
26
|
-
|
|
27
|
+
const normDir = specsDir.replace(/\\/g, '/').replace(/\/$/u, '');
|
|
28
|
+
const entries = walk(normDir).map((path) => ({
|
|
27
29
|
fileName: path,
|
|
28
30
|
doc: parseCapability(io.readText(path), path),
|
|
29
31
|
}));
|
|
32
|
+
assignSpecIds(entries, normDir);
|
|
33
|
+
return entries;
|
|
30
34
|
}
|
|
@@ -4,9 +4,11 @@
|
|
|
4
4
|
* `spec/validation.rs` observable issue order). Pure — filesystem access is
|
|
5
5
|
* injected via SpecIo.
|
|
6
6
|
*/
|
|
7
|
+
import { assignSpecIds } from '../spec/assignSpecIds.ts';
|
|
7
8
|
import type { CapabilityDoc } from '../spec/ir.ts';
|
|
8
9
|
import { ruleHasRunnableScenario, specIdOf } from '../spec/ir.ts';
|
|
9
10
|
import { buildReqRegistry } from '../spec/reqRegistry.ts';
|
|
11
|
+
import { validateTransitionsForRule } from './xstateTransitions.ts';
|
|
10
12
|
|
|
11
13
|
export type ValidationLevel = 'ERROR' | 'WARNING' | 'INFO';
|
|
12
14
|
|
|
@@ -20,6 +22,8 @@ export interface ValidationItem {
|
|
|
20
22
|
export interface SpecEntry {
|
|
21
23
|
fileName: string;
|
|
22
24
|
doc: CapabilityDoc;
|
|
25
|
+
/** Set by discoverSpecs / assignSpecIds (r101). */
|
|
26
|
+
specId?: string;
|
|
23
27
|
}
|
|
24
28
|
|
|
25
29
|
export interface SpecIo {
|
|
@@ -47,7 +51,9 @@ export function validateCapability(
|
|
|
47
51
|
entry: SpecEntry,
|
|
48
52
|
duplicatesFor: (reqId: string) => boolean,
|
|
49
53
|
_io: SpecIo,
|
|
50
|
-
|
|
54
|
+
opts: {
|
|
55
|
+
duplicateSpecId?: boolean;
|
|
56
|
+
} = {},
|
|
51
57
|
): SpecVerdict {
|
|
52
58
|
const { doc } = entry;
|
|
53
59
|
const cap = specIdOf(entry);
|
|
@@ -57,30 +63,26 @@ export function validateCapability(
|
|
|
57
63
|
items.push({ level, id, message });
|
|
58
64
|
};
|
|
59
65
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
push('ERROR', 'llmanspec/specs', `Failed to scan req_id index: ${msg}`);
|
|
67
|
-
return { fileName: entry.fileName, capability: cap, ok: false, items };
|
|
66
|
+
if (opts.duplicateSpecId) {
|
|
67
|
+
push(
|
|
68
|
+
'ERROR',
|
|
69
|
+
`${cap}/spec-id`,
|
|
70
|
+
`duplicate assigned spec id \`${cap}\` — adjust feature file paths`,
|
|
71
|
+
);
|
|
68
72
|
}
|
|
73
|
+
|
|
69
74
|
if (doc.header.purpose === null || doc.header.purpose.trim() === '') {
|
|
70
75
|
push('ERROR', `${cap}/purpose`, '`# purpose:` header comment must not be empty');
|
|
71
76
|
}
|
|
72
|
-
// Spec name must match the capability id (flat stem).
|
|
73
|
-
if (doc.header.capability !== null && doc.header.capability.trim() !== cap) {
|
|
74
|
-
push(
|
|
75
|
-
'WARNING',
|
|
76
|
-
`${cap}/meta.name`,
|
|
77
|
-
`Spec \`# capability:\` header must match spec id (flat file stem or directory name): \`${doc.header.capability.trim()}\` != \`${cap}\``,
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
77
|
|
|
81
|
-
// Feature title must be non-empty.
|
|
82
78
|
if ((doc.featureName ?? '').trim() === '') {
|
|
83
79
|
push('ERROR', `${cap}/feature`, 'Feature line must carry a title');
|
|
80
|
+
} else if (doc.featureName.trim() !== cap) {
|
|
81
|
+
push(
|
|
82
|
+
'ERROR',
|
|
83
|
+
`${cap}/feature`,
|
|
84
|
+
`Feature title must match assigned spec id: \`${doc.featureName.trim()}\` != \`${cap}\``,
|
|
85
|
+
);
|
|
84
86
|
}
|
|
85
87
|
|
|
86
88
|
// Parser-level structural errors. Header gates are owned here (mapped below);
|
|
@@ -130,6 +132,13 @@ export function validateCapability(
|
|
|
130
132
|
);
|
|
131
133
|
}
|
|
132
134
|
|
|
135
|
+
// Transition-table gates (r104) are tag-scoped per scenario — no config switch.
|
|
136
|
+
for (const rule of rules) {
|
|
137
|
+
for (const item of validateTransitionsForRule(cap, rule)) {
|
|
138
|
+
push(item.level, item.id, item.message);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
133
142
|
return {
|
|
134
143
|
fileName: entry.fileName,
|
|
135
144
|
capability: cap,
|
|
@@ -158,10 +167,22 @@ export function formatTotals(passed: number, failed: number, total: number): str
|
|
|
158
167
|
return `Totals: ${passed} passed, ${failed} failed (${total} items)`;
|
|
159
168
|
}
|
|
160
169
|
|
|
161
|
-
export function validateAllSpecs(
|
|
162
|
-
|
|
170
|
+
export function validateAllSpecs(
|
|
171
|
+
entries: readonly SpecEntry[],
|
|
172
|
+
io: SpecIo,
|
|
173
|
+
opts: { specsDir?: string } = {},
|
|
174
|
+
): ValidationReport {
|
|
175
|
+
const specsDir = opts.specsDir ?? 'llmanspec/specs';
|
|
176
|
+
const list: SpecEntry[] = entries.map((e) => ({ ...e }));
|
|
177
|
+
const duplicateSpecIds = assignSpecIds(list, specsDir);
|
|
178
|
+
const duplicatesFor = buildDuplicatesFor(list);
|
|
179
|
+
|
|
180
|
+
const verdicts = list.map((e) =>
|
|
181
|
+
validateCapability(e, duplicatesFor, io, {
|
|
182
|
+
duplicateSpecId: duplicateSpecIds.has(specIdOf(e)),
|
|
183
|
+
}),
|
|
184
|
+
);
|
|
163
185
|
|
|
164
|
-
const verdicts = entries.map((e) => validateCapability(e, duplicatesFor, io));
|
|
165
186
|
const failed = verdicts.some((v) => !v.ok);
|
|
166
187
|
const passed = verdicts.filter((v) => v.ok).length;
|
|
167
188
|
|