@specdest/devkit 0.4.10 → 0.4.12
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/npm/commands.js +6 -0
- package/dist/npm/project-check.d.ts +11 -0
- package/dist/npm/project-check.js +30 -1
- package/dist/npm/state.js +16 -2
- package/package.json +1 -1
package/dist/npm/commands.js
CHANGED
|
@@ -127,6 +127,12 @@ export function createCanonicalCommandHandlers(projectRoot = process.cwd(), opti
|
|
|
127
127
|
return 2;
|
|
128
128
|
}
|
|
129
129
|
const result = await canonicalCheck(projectRoot, source, parsed);
|
|
130
|
+
if (result.versionProblems?.length && !parsed.json) {
|
|
131
|
+
for (const problem of result.versionProblems) {
|
|
132
|
+
io.stderr.write(`FAIL stale rule ${problem.id}: installed ${problem.installedVersion}, canonical ${problem.requiredVersion}${problem.contentMismatch ? ' (content hash mismatch)' : ''}.\n`);
|
|
133
|
+
}
|
|
134
|
+
io.stderr.write('No validators executed. Run `pnpm exec specdest sync`, commit `.spd/installed.json`, then retry.\n');
|
|
135
|
+
}
|
|
130
136
|
if (parsed.json) {
|
|
131
137
|
io.stdout.write(`${JSON.stringify(result, null, 2)}\n`);
|
|
132
138
|
return result.exitCode;
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
export declare function runWithConcurrency<T, R>(items: T[], limit: number, worker: (item: T, index: number) => Promise<R>): Promise<R[]>;
|
|
2
2
|
export declare function canonicalCheck(projectRoot: string, source: any, options?: any): Promise<{
|
|
3
|
+
exitCode: number;
|
|
4
|
+
results: any;
|
|
5
|
+
executions: never[];
|
|
6
|
+
versionProblems: {
|
|
7
|
+
id: any;
|
|
8
|
+
installedVersion: any;
|
|
9
|
+
requiredVersion: any;
|
|
10
|
+
contentMismatch: boolean;
|
|
11
|
+
}[];
|
|
12
|
+
} | {
|
|
3
13
|
exitCode: number;
|
|
4
14
|
results: {
|
|
5
15
|
[k: string]: any;
|
|
@@ -11,4 +21,5 @@ export declare function canonicalCheck(projectRoot: string, source: any, options
|
|
|
11
21
|
stdout: any;
|
|
12
22
|
stderr: any;
|
|
13
23
|
}[];
|
|
24
|
+
versionProblems?: undefined;
|
|
14
25
|
}>;
|
|
@@ -36,8 +36,37 @@ export async function runWithConcurrency(items, limit, worker) {
|
|
|
36
36
|
export async function canonicalCheck(projectRoot, source, options = {}) {
|
|
37
37
|
await assertPredefinedPackageState(projectRoot);
|
|
38
38
|
const current = await readInstalledState(projectRoot);
|
|
39
|
-
const { applicable, canonicalCheckRoot, checkerRuntimeRoot } = await loadCanonicalProjectContext(projectRoot, source, { offline: false, withCheckers: true, refresh:
|
|
39
|
+
const { applicable, canonicalCheckRoot, checkerRuntimeRoot } = await loadCanonicalProjectContext(projectRoot, source, { offline: false, withCheckers: true, refresh: true });
|
|
40
40
|
const byId = new Map(applicable.map((entry) => [entry.id, entry]));
|
|
41
|
+
// Fail closed before invoking any checker if its installed contract is stale.
|
|
42
|
+
// A cached validator may otherwise report PASS against obsolete requirements.
|
|
43
|
+
const versionProblems = applicable.flatMap((entry) => {
|
|
44
|
+
if ((entry.enforcement ?? 'guidance') === 'guidance')
|
|
45
|
+
return [];
|
|
46
|
+
const installed = current.installed[entry.id];
|
|
47
|
+
if (!installed || installed.kind !== 'rule')
|
|
48
|
+
return [];
|
|
49
|
+
if (installed.version === entry.version && installed.contentHash === entry.contentHash)
|
|
50
|
+
return [];
|
|
51
|
+
return [
|
|
52
|
+
{
|
|
53
|
+
id: entry.id,
|
|
54
|
+
installedVersion: installed.version ?? 'unknown',
|
|
55
|
+
requiredVersion: entry.version,
|
|
56
|
+
contentMismatch: installed.version === entry.version,
|
|
57
|
+
},
|
|
58
|
+
];
|
|
59
|
+
});
|
|
60
|
+
if (versionProblems.length) {
|
|
61
|
+
const results = Object.fromEntries(versionProblems.map((problem) => {
|
|
62
|
+
const message = `STALE RULE ${problem.id}: installed ${problem.installedVersion}, canonical ${problem.requiredVersion}${problem.contentMismatch ? ' (content hash differs)' : ''}. Run \`pnpm exec specdest sync\` and commit .spd/installed.json.`;
|
|
63
|
+
return [
|
|
64
|
+
problem.id,
|
|
65
|
+
{ status: 'fail', exitCode: 1, stderr: message, diagnostics: [{ message }] },
|
|
66
|
+
];
|
|
67
|
+
}));
|
|
68
|
+
return { exitCode: 1, results, executions: [], versionProblems };
|
|
69
|
+
}
|
|
41
70
|
const results = {};
|
|
42
71
|
const groups = new Map();
|
|
43
72
|
const executor = options.executor ?? execute;
|
package/dist/npm/state.js
CHANGED
|
@@ -223,9 +223,23 @@ export async function writeChecksState(projectRoot, state) {
|
|
|
223
223
|
schemaVersion: CHECKS_SCHEMA_VERSION,
|
|
224
224
|
results: {},
|
|
225
225
|
}));
|
|
226
|
-
|
|
226
|
+
const next = migrateChecksStateRuleIds({
|
|
227
227
|
...current,
|
|
228
228
|
...state,
|
|
229
229
|
schemaVersion: CHECKS_SCHEMA_VERSION,
|
|
230
|
-
})
|
|
230
|
+
});
|
|
231
|
+
let fileExists = true;
|
|
232
|
+
try {
|
|
233
|
+
await access(join(projectRoot, STATE_RELATIVE_PATH));
|
|
234
|
+
}
|
|
235
|
+
catch (error) {
|
|
236
|
+
if (error.code !== 'ENOENT')
|
|
237
|
+
throw error;
|
|
238
|
+
fileExists = false;
|
|
239
|
+
}
|
|
240
|
+
const { checkedAt: _previousCheckedAt, ...previousMeaningful } = current;
|
|
241
|
+
const { checkedAt: _nextCheckedAt, ...nextMeaningful } = next;
|
|
242
|
+
if (fileExists && JSON.stringify(previousMeaningful) === JSON.stringify(nextMeaningful))
|
|
243
|
+
return;
|
|
244
|
+
await writeJsonAtomic(join(projectRoot, STATE_RELATIVE_PATH), next);
|
|
231
245
|
}
|