@planu/cli 5.7.11 → 5.7.13
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/CHANGELOG.md +43 -0
- package/dist/.planu-build.json +1 -1
- package/dist/cli/commands/doctor.d.ts +2 -1
- package/dist/cli/commands/doctor.js +51 -1
- package/dist/cli/commands/install.js +14 -0
- package/dist/cli/commands/package-handoff.js +10 -3
- package/dist/config/registries/strict-audit-scripts.json +4 -0
- package/dist/config/runtime-policy.json +2 -1
- package/dist/engine/abortable-process-runner.js +1 -0
- package/dist/engine/bump-carrier-binding.d.ts +10 -0
- package/dist/engine/bump-carrier-binding.js +276 -0
- package/dist/engine/doctor/npm-cache-check.d.ts +10 -0
- package/dist/engine/doctor/npm-cache-check.js +109 -0
- package/dist/engine/ears-gate.d.ts +1 -0
- package/dist/engine/ears-gate.js +64 -2
- package/dist/engine/framework-detector.d.ts +1 -0
- package/dist/engine/framework-detector.js +1 -1
- package/dist/engine/handoff-artifacts/schemas.d.ts +22 -0
- package/dist/engine/handoff-artifacts/schemas.js +13 -1
- package/dist/engine/runtime-policy.js +4 -0
- package/dist/engine/source-quality-binding.d.ts +26 -0
- package/dist/engine/source-quality-binding.js +162 -0
- package/dist/engine/source-quality-receipt-reader.d.ts +3 -0
- package/dist/engine/source-quality-receipt-reader.js +51 -0
- package/dist/engine/spec-format/bdd-parser.js +7 -4
- package/dist/engine/spec-format/technical-md-populator.js +114 -3
- package/dist/engine/spec-format/unified-spec-builder.js +33 -6
- package/dist/engine/spec-grounding/contract.js +3 -1
- package/dist/engine/spec-grounding/grounding-entry-parser.js +1 -0
- package/dist/engine/validator/blast-radius-gate.d.ts +3 -0
- package/dist/engine/validator/blast-radius-gate.js +225 -0
- package/dist/engine/validator/spec-compliance-runner.d.ts +2 -0
- package/dist/engine/validator/spec-compliance-runner.js +78 -25
- package/dist/engine/validator/strict-audits-gate.d.ts +3 -0
- package/dist/engine/validator/strict-audits-gate.js +74 -0
- package/dist/engine/validator/validation-report-writer.d.ts +2 -0
- package/dist/engine/validator/validation-report-writer.js +72 -32
- package/dist/storage/runtime-db.js +7 -3
- package/dist/storage/spec-store.js +6 -2
- package/dist/tools/challenge-spec/scenarios-data.js +4 -3
- package/dist/tools/challenge-spec/scenarios-utils.d.ts +1 -0
- package/dist/tools/challenge-spec/scenarios-utils.js +47 -3
- package/dist/tools/register-spec-tools/core-spec-tools.js +5 -0
- package/dist/tools/update-status/batch.js +1 -0
- package/dist/tools/update-status/file-sync.d.ts +1 -1
- package/dist/tools/update-status/file-sync.js +4 -2
- package/dist/tools/update-status/index.js +4 -1
- package/dist/tools/update-status/transition-guard.d.ts +0 -1
- package/dist/tools/update-status/transition-guard.js +9 -5
- package/dist/tools/validate-lint.js +19 -0
- package/dist/tools/validate.js +111 -4
- package/dist/types/abortable-process.d.ts +1 -0
- package/dist/types/handoff-artifacts.d.ts +11 -1
- package/dist/types/installation.d.ts +10 -0
- package/dist/types/runtime-policy.d.ts +1 -0
- package/dist/types/spec-format.d.ts +10 -0
- package/dist/types/spec-grounding.d.ts +1 -1
- package/dist/types/validation-evidence.d.ts +51 -1
- package/package.json +2 -2
- package/planu-plugin.json +1 -1
- package/src/i18n/messages/en.json +1 -1
- package/src/i18n/messages/es.json +1 -1
- package/src/i18n/messages/pt.json +1 -1
|
@@ -20,7 +20,8 @@ export function buildCanonicalUnifiedSpecContent(input) {
|
|
|
20
20
|
const source = input.sourceDescription.replace(/\r\n/g, '\n').trim();
|
|
21
21
|
const explicitProblem = extractTopLevelSectionBody(source, 'Problem');
|
|
22
22
|
const proseBeforeHeading = source.split(/^##[ \t]+\S.*$/m, 1)[0]?.trim() ?? '';
|
|
23
|
-
const
|
|
23
|
+
const fallbackSection = explicitProblem === null && proseBeforeHeading.length === 0 ? firstAuthorSection(source) : null;
|
|
24
|
+
const problem = firstNonEmpty(explicitProblem, proseBeforeHeading, fallbackSection?.body, source);
|
|
24
25
|
const explicitGoal = extractTopLevelSectionBody(source, 'Goal');
|
|
25
26
|
const goal = firstNonEmpty(explicitGoal, firstSentence(problem), 'Needs decision: define the goal this spec must achieve.');
|
|
26
27
|
const explicitTechnical = extractTopLevelSectionBody(source, 'Technical');
|
|
@@ -39,7 +40,7 @@ export function buildCanonicalUnifiedSpecContent(input) {
|
|
|
39
40
|
renderSection('Acceptance Criteria', acceptance),
|
|
40
41
|
renderSection('Files', renderOwnedFiles(input.files)),
|
|
41
42
|
renderSection('Out of scope', outOfScope),
|
|
42
|
-
...extractAuthorSections(source),
|
|
43
|
+
...extractAuthorSections(source, fallbackSection?.name),
|
|
43
44
|
];
|
|
44
45
|
return `${frontmatter ? `${frontmatter}\n\n` : ''}${sections.join('\n\n')}\n`;
|
|
45
46
|
}
|
|
@@ -52,7 +53,7 @@ const CANONICAL_SECTION_NAMES = new Set([
|
|
|
52
53
|
'Files',
|
|
53
54
|
'Out of scope',
|
|
54
55
|
].map((name) => name.toLowerCase()));
|
|
55
|
-
function extractAuthorSections(source) {
|
|
56
|
+
function extractAuthorSections(source, skipName) {
|
|
56
57
|
const scannable = stripFencedCodeBlocks(source);
|
|
57
58
|
const headingRe = /^##[ \t]+(\S.*?)[ \t]*$/gm;
|
|
58
59
|
const preserved = [];
|
|
@@ -62,6 +63,9 @@ function extractAuthorSections(source) {
|
|
|
62
63
|
if (CANONICAL_SECTION_NAMES.has(name.toLowerCase())) {
|
|
63
64
|
continue;
|
|
64
65
|
}
|
|
66
|
+
if (skipName?.toLowerCase() === name.toLowerCase()) {
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
65
69
|
const body = extractTopLevelSectionBody(source, name);
|
|
66
70
|
if (body !== null && body.length > 0) {
|
|
67
71
|
preserved.push(renderSection(name, body));
|
|
@@ -69,6 +73,27 @@ function extractAuthorSections(source) {
|
|
|
69
73
|
}
|
|
70
74
|
return preserved;
|
|
71
75
|
}
|
|
76
|
+
/**
|
|
77
|
+
* The first non-canonical `##` section with a non-empty body, used as the
|
|
78
|
+
* problem fallback when the description opens directly with a heading
|
|
79
|
+
* (SPEC-1753). Returns null when no such section exists.
|
|
80
|
+
*/
|
|
81
|
+
function firstAuthorSection(source) {
|
|
82
|
+
const scannable = stripFencedCodeBlocks(source);
|
|
83
|
+
const headingRe = /^##[ \t]+(\S.*?)[ \t]*$/gm;
|
|
84
|
+
let match;
|
|
85
|
+
while ((match = headingRe.exec(scannable)) !== null) {
|
|
86
|
+
const name = match[1] ?? '';
|
|
87
|
+
if (CANONICAL_SECTION_NAMES.has(name.toLowerCase())) {
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
const body = extractTopLevelSectionBody(source, name);
|
|
91
|
+
if (body !== null && body.length > 0) {
|
|
92
|
+
return { name, body };
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
72
97
|
/**
|
|
73
98
|
* Combine a generated lean spec.md body and a generated lean technical.md body
|
|
74
99
|
* into a single unified spec.md content. The technical body's YAML frontmatter
|
|
@@ -294,14 +319,16 @@ function findEmbeddedRequiredSections(body) {
|
|
|
294
319
|
return [...embedded];
|
|
295
320
|
}
|
|
296
321
|
function extractTopLevelSectionBody(body, section) {
|
|
297
|
-
const
|
|
322
|
+
const scannable = maskFencedAndQuotedText(body);
|
|
323
|
+
const heading = new RegExp(`^##[ \\t]+${escapeRegex(section)}[ \\t]*$`, 'mi').exec(scannable);
|
|
298
324
|
if (!heading) {
|
|
299
325
|
return null;
|
|
300
326
|
}
|
|
301
327
|
const start = heading.index + heading[0].length;
|
|
302
|
-
const rest =
|
|
328
|
+
const rest = scannable.slice(start);
|
|
303
329
|
const next = /^##[ \t]+\S.*$/m.exec(rest);
|
|
304
|
-
|
|
330
|
+
const end = start + (next?.index ?? rest.length);
|
|
331
|
+
return body.slice(start, end).trim();
|
|
305
332
|
}
|
|
306
333
|
function renderSection(title, body) {
|
|
307
334
|
return `## ${title}\n\n${body.trim()}`;
|
|
@@ -65,7 +65,9 @@ export function buildCriterionGroundingRecords(args) {
|
|
|
65
65
|
});
|
|
66
66
|
}
|
|
67
67
|
export function getContractCriteria(records) {
|
|
68
|
-
return records.filter((record) => record.source === 'user_input' ||
|
|
68
|
+
return records.filter((record) => record.source === 'user_input' ||
|
|
69
|
+
record.source === 'project_evidence' ||
|
|
70
|
+
record.source === 'review_evidence');
|
|
69
71
|
}
|
|
70
72
|
export function getAdvisoryCriteria(records) {
|
|
71
73
|
return records.filter((record) => record.source === 'documented_assumption' || record.source === 'ungrounded_advisory');
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { BlastRadiusGateResult, RunBlastRadiusGateOptions } from '../../types/validation-evidence.js';
|
|
2
|
+
export declare function runBlastRadiusGate(projectPath: string, candidateFiles: string[], options: RunBlastRadiusGateOptions): Promise<BlastRadiusGateResult>;
|
|
3
|
+
//# sourceMappingURL=blast-radius-gate.d.ts.map
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { existsSync, mkdtempSync, readFileSync, rmSync } from 'node:fs';
|
|
2
|
+
import { tmpdir } from 'node:os';
|
|
3
|
+
import { isAbsolute, join, relative } from 'node:path';
|
|
4
|
+
import { runAbortableProcess } from '../abortable-process-runner.js';
|
|
5
|
+
import { technologyValue } from '../technology-registry.js';
|
|
6
|
+
const IMPORTABLE_SOURCE_PATTERN = /\.(?:ts|tsx|js|jsx|mjs|cjs)$/u;
|
|
7
|
+
const INTEGRATION_ONLY_ENV = 'PLANU_INTEGRATION_TESTS_ONLY';
|
|
8
|
+
const EXCLUDE_INTEGRATION_ENV = 'PLANU_EXCLUDE_INTEGRATION_TESTS';
|
|
9
|
+
function skippedResult(skipped) {
|
|
10
|
+
return {
|
|
11
|
+
skipped,
|
|
12
|
+
selectedFiles: [],
|
|
13
|
+
passed: true,
|
|
14
|
+
timedOut: false,
|
|
15
|
+
failures: [],
|
|
16
|
+
integrationImporters: [],
|
|
17
|
+
warningReason: null,
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
function normalizeCandidate(projectPath, file) {
|
|
21
|
+
const absolute = isAbsolute(file) ? file : join(projectPath, file);
|
|
22
|
+
const relativePath = relative(projectPath, absolute);
|
|
23
|
+
return relativePath.startsWith('..') ? null : relativePath;
|
|
24
|
+
}
|
|
25
|
+
function selectCandidateFiles(projectPath, candidateFiles) {
|
|
26
|
+
const normalized = candidateFiles
|
|
27
|
+
.map((file) => normalizeCandidate(projectPath, file))
|
|
28
|
+
.filter((file) => file !== null);
|
|
29
|
+
return [...new Set(normalized)].filter((file) => IMPORTABLE_SOURCE_PATTERN.test(file) && existsSync(join(projectPath, file)));
|
|
30
|
+
}
|
|
31
|
+
function firstFailureLine(assertion) {
|
|
32
|
+
const message = assertion.failureMessages?.[0] ?? 'test failed';
|
|
33
|
+
return message.split('\n')[0] ?? message;
|
|
34
|
+
}
|
|
35
|
+
function relativeReportPath(projectPath, reportedPath) {
|
|
36
|
+
return isAbsolute(reportedPath) ? relative(projectPath, reportedPath) : reportedPath;
|
|
37
|
+
}
|
|
38
|
+
function parseVitestReport(projectPath, reportPath) {
|
|
39
|
+
const raw = readFileSync(reportPath, 'utf-8');
|
|
40
|
+
const parsed = JSON.parse(raw);
|
|
41
|
+
if (!Array.isArray(parsed.testResults)) {
|
|
42
|
+
throw new Error('vitest report has no testResults array');
|
|
43
|
+
}
|
|
44
|
+
const failures = [];
|
|
45
|
+
for (const testResult of parsed.testResults) {
|
|
46
|
+
const reportedPath = testResult.testFilePath ?? testResult.name;
|
|
47
|
+
if (!reportedPath) {
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
const file = relativeReportPath(projectPath, reportedPath);
|
|
51
|
+
for (const assertion of testResult.assertionResults ?? []) {
|
|
52
|
+
if (assertion.status === 'failed') {
|
|
53
|
+
failures.push({ file, message: firstFailureLine(assertion) });
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return failures;
|
|
58
|
+
}
|
|
59
|
+
function abortFailure(reportPath, signal, selectedFiles) {
|
|
60
|
+
const message = signal !== null ? `vitest related aborted (signal ${signal})` : 'vitest related aborted';
|
|
61
|
+
return {
|
|
62
|
+
skipped: null,
|
|
63
|
+
selectedFiles,
|
|
64
|
+
passed: false,
|
|
65
|
+
timedOut: false,
|
|
66
|
+
failures: [{ file: reportPath, message }],
|
|
67
|
+
integrationImporters: [],
|
|
68
|
+
warningReason: null,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function exitStatusFailure(reportPath, status, selectedFiles) {
|
|
72
|
+
return {
|
|
73
|
+
skipped: null,
|
|
74
|
+
selectedFiles,
|
|
75
|
+
passed: false,
|
|
76
|
+
timedOut: false,
|
|
77
|
+
failures: [
|
|
78
|
+
{
|
|
79
|
+
file: reportPath,
|
|
80
|
+
message: `vitest related exited with status ${status} without parseable failures`,
|
|
81
|
+
},
|
|
82
|
+
],
|
|
83
|
+
integrationImporters: [],
|
|
84
|
+
warningReason: null,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function reportFailure(reportPath, selectedFiles, error) {
|
|
88
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
89
|
+
return {
|
|
90
|
+
skipped: null,
|
|
91
|
+
selectedFiles,
|
|
92
|
+
passed: false,
|
|
93
|
+
timedOut: false,
|
|
94
|
+
failures: [
|
|
95
|
+
{ file: reportPath, message: `blast radius report missing or unreadable: ${detail}` },
|
|
96
|
+
],
|
|
97
|
+
integrationImporters: [],
|
|
98
|
+
warningReason: null,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
async function runIntegrationPass(args) {
|
|
102
|
+
const budgetMs = args.options.integrationTimeoutMs ?? 0;
|
|
103
|
+
if (budgetMs <= 0) {
|
|
104
|
+
return { outcome: 'skipped' };
|
|
105
|
+
}
|
|
106
|
+
const reportDir = mkdtempSync(join(tmpdir(), 'planu-blast-radius-integration-'));
|
|
107
|
+
const reportPath = join(reportDir, 'blast-radius-integration.json');
|
|
108
|
+
try {
|
|
109
|
+
const { [EXCLUDE_INTEGRATION_ENV]: _excluded, ...envWithoutExclusion } = process.env;
|
|
110
|
+
const integrationEnv = {
|
|
111
|
+
...envWithoutExclusion,
|
|
112
|
+
[INTEGRATION_ONLY_ENV]: '1',
|
|
113
|
+
};
|
|
114
|
+
const result = await args.runProcess(args.vitestBin, [
|
|
115
|
+
'related',
|
|
116
|
+
'--run',
|
|
117
|
+
'--maxWorkers=6',
|
|
118
|
+
'--reporter=json',
|
|
119
|
+
`--outputFile.json=${reportPath}`,
|
|
120
|
+
...args.selectedFiles,
|
|
121
|
+
], {
|
|
122
|
+
cwd: args.projectPath,
|
|
123
|
+
timeoutMs: budgetMs,
|
|
124
|
+
maxBufferBytes: 64 * 1024 * 1024,
|
|
125
|
+
signal: args.options.signal,
|
|
126
|
+
env: integrationEnv,
|
|
127
|
+
});
|
|
128
|
+
if (result.timedOut || result.aborted || result.signal !== null) {
|
|
129
|
+
return { outcome: 'skipped' };
|
|
130
|
+
}
|
|
131
|
+
let report;
|
|
132
|
+
try {
|
|
133
|
+
report = JSON.parse(readFileSync(reportPath, 'utf-8'));
|
|
134
|
+
}
|
|
135
|
+
catch {
|
|
136
|
+
return { outcome: 'skipped' };
|
|
137
|
+
}
|
|
138
|
+
const importers = [
|
|
139
|
+
...new Set((report.testResults ?? []).map((entry) => relativeReportPath(args.projectPath, entry.testFilePath ?? entry.name ?? ''))),
|
|
140
|
+
].filter((path) => path.length > 0);
|
|
141
|
+
const failures = parseVitestReport(args.projectPath, reportPath);
|
|
142
|
+
return { outcome: 'ran', importers, failures };
|
|
143
|
+
}
|
|
144
|
+
finally {
|
|
145
|
+
rmSync(reportDir, { recursive: true, force: true });
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
async function buildSuccessResult(args) {
|
|
149
|
+
const integration = await runIntegrationPass(args);
|
|
150
|
+
const integrationFailures = integration.outcome === 'ran' ? integration.failures : [];
|
|
151
|
+
const allFailures = [...args.firstPassFailures, ...integrationFailures];
|
|
152
|
+
return {
|
|
153
|
+
skipped: null,
|
|
154
|
+
selectedFiles: args.selectedFiles,
|
|
155
|
+
passed: allFailures.length === 0,
|
|
156
|
+
timedOut: false,
|
|
157
|
+
failures: allFailures,
|
|
158
|
+
integrationImporters: integration.outcome === 'ran' ? integration.importers : [],
|
|
159
|
+
warningReason: integration.outcome === 'skipped' ? 'integration-importers-skipped' : null,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
export async function runBlastRadiusGate(projectPath, candidateFiles, options) {
|
|
163
|
+
const selectedFiles = selectCandidateFiles(projectPath, candidateFiles);
|
|
164
|
+
if (selectedFiles.length === 0) {
|
|
165
|
+
return skippedResult('no-importable-files');
|
|
166
|
+
}
|
|
167
|
+
const vitestBin = join(projectPath, 'node_modules', '.bin', technologyValue('technology-vitest-a9127f'));
|
|
168
|
+
if (!existsSync(vitestBin)) {
|
|
169
|
+
return skippedResult('vitest-not-installed');
|
|
170
|
+
}
|
|
171
|
+
const runProcess = options.runProcess ?? runAbortableProcess;
|
|
172
|
+
const reportDir = mkdtempSync(join(tmpdir(), 'planu-blast-radius-'));
|
|
173
|
+
const reportPath = join(reportDir, 'blast-radius.json');
|
|
174
|
+
try {
|
|
175
|
+
const result = await runProcess(vitestBin, [
|
|
176
|
+
'related',
|
|
177
|
+
'--run',
|
|
178
|
+
'--maxWorkers=6',
|
|
179
|
+
'--reporter=json',
|
|
180
|
+
`--outputFile.json=${reportPath}`,
|
|
181
|
+
...selectedFiles,
|
|
182
|
+
], {
|
|
183
|
+
cwd: projectPath,
|
|
184
|
+
timeoutMs: options.timeoutMs,
|
|
185
|
+
maxBufferBytes: 64 * 1024 * 1024,
|
|
186
|
+
signal: options.signal,
|
|
187
|
+
env: { ...process.env, [EXCLUDE_INTEGRATION_ENV]: '1' },
|
|
188
|
+
});
|
|
189
|
+
if (result.timedOut) {
|
|
190
|
+
return {
|
|
191
|
+
skipped: null,
|
|
192
|
+
selectedFiles,
|
|
193
|
+
passed: false,
|
|
194
|
+
timedOut: true,
|
|
195
|
+
failures: [],
|
|
196
|
+
integrationImporters: [],
|
|
197
|
+
warningReason: null,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
if (result.aborted || result.signal !== null) {
|
|
201
|
+
return abortFailure(reportPath, result.signal, selectedFiles);
|
|
202
|
+
}
|
|
203
|
+
try {
|
|
204
|
+
const failures = parseVitestReport(projectPath, reportPath);
|
|
205
|
+
if (failures.length === 0 && result.status !== null && result.status !== 0) {
|
|
206
|
+
return exitStatusFailure(reportPath, result.status, selectedFiles);
|
|
207
|
+
}
|
|
208
|
+
return await buildSuccessResult({
|
|
209
|
+
projectPath,
|
|
210
|
+
vitestBin,
|
|
211
|
+
selectedFiles,
|
|
212
|
+
options,
|
|
213
|
+
runProcess,
|
|
214
|
+
firstPassFailures: failures,
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
catch (error) {
|
|
218
|
+
return reportFailure(reportPath, selectedFiles, error);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
finally {
|
|
222
|
+
rmSync(reportDir, { recursive: true, force: true });
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
//# sourceMappingURL=blast-radius-gate.js.map
|
|
@@ -6,7 +6,9 @@ export declare class ComplianceCommandTerminalError extends Error {
|
|
|
6
6
|
constructor(code: string);
|
|
7
7
|
}
|
|
8
8
|
export declare function parseFrontmatterScenarios(raw: string): FrontmatterScenario[];
|
|
9
|
+
export declare function parseJsonOutput(stdout: string): unknown;
|
|
9
10
|
export declare function runSpecCompliance(spec: Spec, projectPath: string, signal?: AbortSignal, canonicalProjectId?: string): Promise<SpecComplianceResult>;
|
|
10
11
|
export declare function findScenariosWithoutTests(raw: string): string[];
|
|
12
|
+
export declare function collectDeclaredSpecFiles(raw: string): string[];
|
|
11
13
|
export declare function findDoneDriftMissingFiles(spec: Spec, raw: string, projectPath: string, fileExists: (path: string) => boolean): DoneDriftMissingFileFinding[];
|
|
12
14
|
//# sourceMappingURL=spec-compliance-runner.d.ts.map
|
|
@@ -210,6 +210,11 @@ export function parseFrontmatterScenarios(raw) {
|
|
|
210
210
|
}
|
|
211
211
|
return scenarios;
|
|
212
212
|
}
|
|
213
|
+
function isAdapterFailure(adapter) {
|
|
214
|
+
return (adapter?.statuses.size === 0 &&
|
|
215
|
+
(adapter.detail.startsWith('runner failed') ||
|
|
216
|
+
adapter.detail.startsWith('unparseable runner output')));
|
|
217
|
+
}
|
|
213
218
|
function validRelativePath(candidate) {
|
|
214
219
|
if (candidate.trim() !== candidate ||
|
|
215
220
|
candidate.length === 0 ||
|
|
@@ -254,17 +259,20 @@ async function matchPlaywrightLink(reportedPath, links, projectPath) {
|
|
|
254
259
|
const candidates = links.filter((link) => link.path === reportedPath || link.path.endsWith(`/${reportedPath}`));
|
|
255
260
|
return candidates.length === 1 ? (candidates[0] ?? null) : null;
|
|
256
261
|
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
262
|
+
const VITEST_REPORT_ANCHOR = '{"numTotalTestSuites';
|
|
263
|
+
export function parseJsonOutput(stdout) {
|
|
264
|
+
for (const start of [stdout.lastIndexOf(VITEST_REPORT_ANCHOR), stdout.indexOf('{')]) {
|
|
265
|
+
if (start === -1) {
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
try {
|
|
269
|
+
return JSON.parse(stdout.slice(start));
|
|
270
|
+
}
|
|
271
|
+
catch {
|
|
272
|
+
continue;
|
|
273
|
+
}
|
|
267
274
|
}
|
|
275
|
+
return null;
|
|
268
276
|
}
|
|
269
277
|
function vitestFilePath(result) {
|
|
270
278
|
for (const candidate of [result.testFilePath, result.name, result.filepath, result.filePath]) {
|
|
@@ -290,9 +298,14 @@ function throwForTerminalProcessFailure(result) {
|
|
|
290
298
|
throw new ComplianceCommandTerminalError('COMPLIANCE_COMMAND_TIMED_OUT');
|
|
291
299
|
}
|
|
292
300
|
}
|
|
301
|
+
function isVitestReport(report) {
|
|
302
|
+
return (typeof report === 'object' &&
|
|
303
|
+
report !== null &&
|
|
304
|
+
Array.isArray(report.testResults));
|
|
305
|
+
}
|
|
293
306
|
async function runVitestAdapter(links, projectPath, signal) {
|
|
294
307
|
const statuses = new Map();
|
|
295
|
-
const
|
|
308
|
+
const runVitestOnce = () => runAbortableProcess('pnpm', [
|
|
296
309
|
'exec',
|
|
297
310
|
technologyValue('technology-vitest-a9127f'),
|
|
298
311
|
'--reporter=json',
|
|
@@ -304,15 +317,26 @@ async function runVitestAdapter(links, projectPath, signal) {
|
|
|
304
317
|
maxBufferBytes: 64 * 1024 * 1024,
|
|
305
318
|
signal,
|
|
306
319
|
});
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
320
|
+
const first = await runVitestOnce();
|
|
321
|
+
throwForTerminalProcessFailure(first);
|
|
322
|
+
const firstReport = first.error ? null : parseJsonOutput(first.stdout);
|
|
323
|
+
const attempt = isVitestReport(firstReport)
|
|
324
|
+
? { result: first, report: firstReport }
|
|
325
|
+
: await (async () => {
|
|
326
|
+
const second = await runVitestOnce();
|
|
327
|
+
throwForTerminalProcessFailure(second);
|
|
328
|
+
const secondReport = second.error ? null : parseJsonOutput(second.stdout);
|
|
329
|
+
return { result: second, report: isVitestReport(secondReport) ? secondReport : null };
|
|
330
|
+
})();
|
|
331
|
+
if (attempt.report === null) {
|
|
332
|
+
return {
|
|
333
|
+
statuses,
|
|
334
|
+
detail: attempt.result.error
|
|
335
|
+
? 'runner failed (retried once)'
|
|
336
|
+
: 'unparseable runner output (retried once)',
|
|
337
|
+
};
|
|
314
338
|
}
|
|
315
|
-
for (const testResult of report.testResults) {
|
|
339
|
+
for (const testResult of attempt.report.testResults) {
|
|
316
340
|
const reportedPath = vitestFilePath(testResult);
|
|
317
341
|
if (!reportedPath || !Array.isArray(testResult.assertionResults)) {
|
|
318
342
|
continue;
|
|
@@ -588,12 +612,13 @@ export async function runSpecCompliance(spec, projectPath, signal, canonicalProj
|
|
|
588
612
|
}
|
|
589
613
|
return `${technologyValue('technology-vitest-a9127f')} --reporter=json --run ${links.map((link) => link.path).join(' ')}`;
|
|
590
614
|
});
|
|
591
|
-
const
|
|
615
|
+
const scenarioResults = scenarios.map((scenario) => {
|
|
592
616
|
if (!scenario.tests?.length) {
|
|
593
617
|
return {
|
|
594
618
|
title: scenario.title,
|
|
595
619
|
verdict: 'missing',
|
|
596
620
|
evidence: ['No test links — scenario has no tests array'],
|
|
621
|
+
linkVerdicts: [],
|
|
597
622
|
};
|
|
598
623
|
}
|
|
599
624
|
const evidence = [];
|
|
@@ -614,34 +639,59 @@ export async function runSpecCompliance(spec, projectPath, signal, canonicalProj
|
|
|
614
639
|
evidence.push(`${source.path || '(missing path)'}: ${link?.error ?? 'malformed test link'}`);
|
|
615
640
|
return { verdict: 'missing', unverifiable: true };
|
|
616
641
|
}
|
|
642
|
+
const groupResult = statusByGroup.get(groupKey(link));
|
|
643
|
+
if (isAdapterFailure(groupResult)) {
|
|
644
|
+
evidence.push(`${link.path}: runner reported ${groupResult.detail}`);
|
|
645
|
+
return { verdict: 'indeterminate', unverifiable: true };
|
|
646
|
+
}
|
|
617
647
|
const adapter = statusByGroup.get(groupKey(link));
|
|
618
648
|
const verdict = adapter?.statuses.get(link.path) ?? 'missing';
|
|
619
649
|
evidence.push(`${link.path}: ${verdict === 'pass' ? 'passed' : verdict === 'fail' ? 'failed' : `not found in ${adapter?.detail ?? 'runner output'}`}`);
|
|
620
650
|
return { verdict, unverifiable: false };
|
|
621
651
|
});
|
|
622
652
|
const verdicts = linkResults.map((entry) => entry.verdict);
|
|
623
|
-
const
|
|
653
|
+
const hasFail = verdicts.some((item) => item === 'fail');
|
|
654
|
+
const hasMissing = verdicts.some((item) => item === 'missing');
|
|
624
655
|
const verdict = verdicts.every((item) => item === 'pass')
|
|
625
656
|
? 'pass'
|
|
626
|
-
:
|
|
627
|
-
? '
|
|
628
|
-
:
|
|
657
|
+
: !hasFail && !hasMissing
|
|
658
|
+
? 'indeterminate'
|
|
659
|
+
: hasMissing
|
|
660
|
+
? 'missing'
|
|
661
|
+
: 'fail';
|
|
662
|
+
const unverifiable = verdict === 'indeterminate' ||
|
|
663
|
+
linkResults.some((entry) => entry.verdict === 'missing' && entry.unverifiable);
|
|
629
664
|
return {
|
|
630
665
|
title: scenario.title,
|
|
631
666
|
verdict,
|
|
632
667
|
evidence,
|
|
668
|
+
linkVerdicts: verdicts,
|
|
633
669
|
...(unverifiable ? { unverifiable: true } : {}),
|
|
634
670
|
};
|
|
635
671
|
});
|
|
672
|
+
const perScenario = scenarioResults.map(({ linkVerdicts: _linkVerdicts, ...scenario }) => scenario);
|
|
636
673
|
const passCount = perScenario.filter((scenario) => scenario.verdict === 'pass').length;
|
|
674
|
+
const indeterminateCount = perScenario.filter((scenario) => scenario.verdict === 'indeterminate').length;
|
|
675
|
+
const scoredCount = scenarios.length - indeterminateCount;
|
|
676
|
+
const failedAdapters = [...statusByGroup.values()].filter(isAdapterFailure);
|
|
677
|
+
const affectedScenarios = scenarioResults.filter((scenario) => scenario.linkVerdicts.some((verdict) => verdict === 'indeterminate')).length;
|
|
637
678
|
return {
|
|
638
|
-
dimensionScore: Math.round((passCount /
|
|
679
|
+
dimensionScore: scoredCount > 0 ? Math.round((passCount / scoredCount) * 100) : 0,
|
|
639
680
|
perScenario,
|
|
640
681
|
command: commands.join(' && ') ||
|
|
641
682
|
`${technologyValue('technology-vitest-a9127f')} --reporter=json --run (no test files linked)`,
|
|
642
683
|
evidenceSource: executableEvidence.source,
|
|
643
684
|
ignoredCriteriaTitles: executableEvidence.ignoredCriteriaTitles,
|
|
644
685
|
doneDriftFindings,
|
|
686
|
+
...(failedAdapters.length > 0
|
|
687
|
+
? {
|
|
688
|
+
runnerFailure: {
|
|
689
|
+
kind: 'runner-output-unparseable',
|
|
690
|
+
detail: failedAdapters[0]?.detail ?? 'unparseable runner output',
|
|
691
|
+
indeterminateScenarios: affectedScenarios,
|
|
692
|
+
},
|
|
693
|
+
}
|
|
694
|
+
: {}),
|
|
645
695
|
};
|
|
646
696
|
}
|
|
647
697
|
export function findScenariosWithoutTests(raw) {
|
|
@@ -701,6 +751,9 @@ function extractFilesSectionPaths(raw) {
|
|
|
701
751
|
}
|
|
702
752
|
return paths;
|
|
703
753
|
}
|
|
754
|
+
export function collectDeclaredSpecFiles(raw) {
|
|
755
|
+
return [...new Set([...extractFilesMarkerPaths(raw), ...extractFilesSectionPaths(raw)])];
|
|
756
|
+
}
|
|
704
757
|
export function findDoneDriftMissingFiles(spec, raw, projectPath, fileExists) {
|
|
705
758
|
if (spec.status !== 'done') {
|
|
706
759
|
return [];
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { RunStrictAuditsGateOptions, StrictAuditsGateResult } from '../../types/validation-evidence.js';
|
|
2
|
+
export declare function runStrictAuditsGate(projectPath: string, options: RunStrictAuditsGateOptions): Promise<StrictAuditsGateResult>;
|
|
3
|
+
//# sourceMappingURL=strict-audits-gate.d.ts.map
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { readFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { runAbortableProcess } from '../abortable-process-runner.js';
|
|
4
|
+
import { pmRunner } from '../framework-detector.js';
|
|
5
|
+
import { resolveProjectCommandPlan } from '../project-command-runtime.js';
|
|
6
|
+
import { remainingExecutionMs } from '../execution/context.js';
|
|
7
|
+
import strictAuditScripts from '../../config/registries/strict-audit-scripts.json' with { type: 'json' };
|
|
8
|
+
const REGISTRY = strictAuditScripts;
|
|
9
|
+
const MAX_FINDING_LINES = 20;
|
|
10
|
+
function fallbackFindingLine(script, result) {
|
|
11
|
+
const signal = result.signal !== null ? ` (signal ${result.signal})` : '';
|
|
12
|
+
const error = result.error !== undefined ? `: ${result.error.message}` : '';
|
|
13
|
+
return `${script} exited with status ${String(result.status)}${signal}${error}`;
|
|
14
|
+
}
|
|
15
|
+
function findingsForFailure(script, result) {
|
|
16
|
+
const lines = `${result.stdout}\n${result.stderr}`
|
|
17
|
+
.split('\n')
|
|
18
|
+
.map((line) => line.trim())
|
|
19
|
+
.filter((line) => line.length > 0)
|
|
20
|
+
.slice(0, MAX_FINDING_LINES);
|
|
21
|
+
if (lines.length === 0) {
|
|
22
|
+
return [{ script, line: fallbackFindingLine(script, result) }];
|
|
23
|
+
}
|
|
24
|
+
return lines.map((line) => ({ script, line }));
|
|
25
|
+
}
|
|
26
|
+
function noStrictScriptsResult() {
|
|
27
|
+
return { skipped: 'no-strict-scripts', executedScripts: [], passed: true, findings: [] };
|
|
28
|
+
}
|
|
29
|
+
function deadlineExceededResult(executedScripts, findings) {
|
|
30
|
+
return { skipped: 'deadline-exceeded', executedScripts, passed: false, findings };
|
|
31
|
+
}
|
|
32
|
+
export async function runStrictAuditsGate(projectPath, options) {
|
|
33
|
+
let pkg;
|
|
34
|
+
try {
|
|
35
|
+
const raw = readFileSync(join(projectPath, 'package.json'), 'utf-8');
|
|
36
|
+
pkg = JSON.parse(raw);
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return noStrictScriptsResult();
|
|
40
|
+
}
|
|
41
|
+
const scripts = pkg.scripts ?? {};
|
|
42
|
+
const declared = REGISTRY.scripts.filter((script) => typeof scripts[script] === 'string');
|
|
43
|
+
if (declared.length === 0) {
|
|
44
|
+
return noStrictScriptsResult();
|
|
45
|
+
}
|
|
46
|
+
const packageManagerName = typeof pkg.packageManager === 'string' ? (pkg.packageManager.split('@')[0] ?? null) : null;
|
|
47
|
+
const runner = pmRunner(packageManagerName);
|
|
48
|
+
const runProcess = options.runProcess ?? runAbortableProcess;
|
|
49
|
+
const deadlineAt = Date.now() + options.timeoutMs;
|
|
50
|
+
const executedScripts = [];
|
|
51
|
+
const findings = [];
|
|
52
|
+
for (const script of declared) {
|
|
53
|
+
const budgetMs = Math.min(deadlineAt - Date.now(), remainingExecutionMs());
|
|
54
|
+
if (budgetMs <= 0) {
|
|
55
|
+
return deadlineExceededResult(executedScripts, findings);
|
|
56
|
+
}
|
|
57
|
+
const plan = resolveProjectCommandPlan(projectPath, `${runner} run ${script}`);
|
|
58
|
+
const result = await runProcess(plan.executable, plan.args, {
|
|
59
|
+
cwd: projectPath,
|
|
60
|
+
timeoutMs: budgetMs,
|
|
61
|
+
maxBufferBytes: 8 * 1024 * 1024,
|
|
62
|
+
signal: options.signal,
|
|
63
|
+
});
|
|
64
|
+
executedScripts.push(script);
|
|
65
|
+
if (result.timedOut || result.aborted) {
|
|
66
|
+
return deadlineExceededResult(executedScripts, findings);
|
|
67
|
+
}
|
|
68
|
+
if (result.error !== undefined || result.status !== 0) {
|
|
69
|
+
findings.push(...findingsForFailure(script, result));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return { skipped: null, executedScripts, passed: findings.length === 0, findings };
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=strict-audits-gate.js.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Spec } from '../../types/index.js';
|
|
2
2
|
import type { ValidationReportV1 } from '../../types/handoff-artifacts.js';
|
|
3
|
+
import type { BlastRadiusGateResult } from '../../types/validation-evidence.js';
|
|
3
4
|
import type { MinimalImplementationReport } from '../../types/minimal-implementation-gate.js';
|
|
4
5
|
export declare const AUTOMATED_VALIDATOR_AGENT = "planu-automated-validator";
|
|
5
6
|
export declare function writeImplementationReviewReport(input: {
|
|
@@ -12,6 +13,7 @@ export declare function writeImplementationReviewReport(input: {
|
|
|
12
13
|
conventionRegression?: boolean;
|
|
13
14
|
minimalityReport?: MinimalImplementationReport;
|
|
14
15
|
signal?: AbortSignal;
|
|
16
|
+
blastRadius?: BlastRadiusGateResult;
|
|
15
17
|
}): Promise<{
|
|
16
18
|
written: boolean;
|
|
17
19
|
path?: string;
|