@widgetic/dev-tools 0.1.0 → 0.3.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/CHANGELOG.md +129 -0
- package/README.md +186 -7
- package/bin/check-design-system-peers.mjs +53 -0
- package/bin/check-layout-fixtures.mjs +35 -0
- package/bin/check-links-fixtures.mjs +28 -0
- package/bin/check-links.mjs +80 -0
- package/bin/check-readme-contracts-fixtures.mjs +27 -0
- package/bin/check-readme-contracts.mjs +77 -0
- package/lib/check-links.d.mts +78 -0
- package/lib/check-links.mjs +349 -0
- package/lib/frontend-layout.mjs +3 -1
- package/lib/lockfile-peers.mjs +193 -0
- package/lib/readme-contract.d.mts +99 -0
- package/lib/readme-contract.mjs +307 -0
- package/lib/semver-lite.mjs +71 -0
- package/package.json +19 -5
- package/test/check-links.test.mjs +359 -0
- package/test/frontend-layout.test.mjs +19 -3
- package/test/lockfile-peers.test.mjs +208 -0
- package/test/readme-contract.test.mjs +459 -0
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Does the link-doctor actually fail when a sibling promise breaks?
|
|
4
|
+
*
|
|
5
|
+
* `check-links.mjs` guards a Frontend checkout against three ways its sibling
|
|
6
|
+
* wiring can silently rot — a `@widgetic/*` symlink that resolves to nothing,
|
|
7
|
+
* a manifest that promises built output nobody built, and a source tree that
|
|
8
|
+
* still names a checkout which no longer exists. All three degrade quietly:
|
|
9
|
+
* the dev server boots, the feature is just gone. A guard nobody has watched
|
|
10
|
+
* fail is indistinguishable from one that inspects nothing.
|
|
11
|
+
*
|
|
12
|
+
* Each rule is driven here against a throwaway checkout — sibling packages
|
|
13
|
+
* written to `node_modules/@widgetic/*` links, manifests and sources that
|
|
14
|
+
* disagree on purpose — asserting on `collectLinkProblems`'s findings. The
|
|
15
|
+
* false-positive shapes matter as much as the true ones: a checker that
|
|
16
|
+
* reports the reporter's own rename history, live hyphenated classnames, or a
|
|
17
|
+
* manifest whose exports are glob patterns gets switched off within a day.
|
|
18
|
+
*
|
|
19
|
+
* Fixtures are built in the OS temp dir, never in the package: the fixture
|
|
20
|
+
* root is deliberately indistinguishable from a real Frontend checkout.
|
|
21
|
+
*
|
|
22
|
+
* Runs on the built-in test runner — no framework, no dependencies:
|
|
23
|
+
*
|
|
24
|
+
* npm run test:links (in this repo)
|
|
25
|
+
* npx check-links-fixtures (in a consumer, against what it installed)
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
import { mkdirSync, mkdtempSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';
|
|
29
|
+
import { spawnSync } from 'node:child_process';
|
|
30
|
+
import { tmpdir } from 'node:os';
|
|
31
|
+
import { dirname, join } from 'node:path';
|
|
32
|
+
import { fileURLToPath } from 'node:url';
|
|
33
|
+
import { after, describe, it } from 'node:test';
|
|
34
|
+
import assert from 'node:assert/strict';
|
|
35
|
+
|
|
36
|
+
import { collectLinkProblems, deadNameHits, promisedFiles } from '../lib/check-links.mjs';
|
|
37
|
+
|
|
38
|
+
const BIN = fileURLToPath(new URL('../bin/check-links.mjs', import.meta.url));
|
|
39
|
+
|
|
40
|
+
/** Every fixture this run created, so a failure cannot leave one behind. */
|
|
41
|
+
const created = [];
|
|
42
|
+
|
|
43
|
+
after(() => {
|
|
44
|
+
for (const root of created) rmSync(root, { recursive: true, force: true });
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* A minimal Frontend checkout. `packages` maps sibling directory → manifest;
|
|
49
|
+
* each gets `package.json`, and any `files`/`links` entries are materialized.
|
|
50
|
+
*
|
|
51
|
+
* `links` entries are `[pkg, name, targetDir]`: a symlink at
|
|
52
|
+
* `<pkg>/node_modules/@widgetic/<name>` → `<targetDir>`. Pass `null` as the
|
|
53
|
+
* target to build a **dangling** link — the symlink points at a checkout that
|
|
54
|
+
* is never created, which is the residue a rename leaves behind.
|
|
55
|
+
*/
|
|
56
|
+
function checkout({ packages, links = [] }) {
|
|
57
|
+
const root = mkdtempSync(join(tmpdir(), 'check-links-'));
|
|
58
|
+
created.push(root);
|
|
59
|
+
for (const [pkg, manifest] of Object.entries(packages)) {
|
|
60
|
+
const pkgDir = join(root, pkg);
|
|
61
|
+
mkdirSync(pkgDir, { recursive: true });
|
|
62
|
+
writeFileSync(join(pkgDir, 'package.json'), JSON.stringify(manifest, null, 2));
|
|
63
|
+
}
|
|
64
|
+
for (const [pkg, name, targetDir] of links) {
|
|
65
|
+
const scope = join(root, pkg, 'node_modules', '@widgetic');
|
|
66
|
+
mkdirSync(scope, { recursive: true });
|
|
67
|
+
if (targetDir === null) {
|
|
68
|
+
// Dangling by omission: the sibling was never created.
|
|
69
|
+
symlinkSync(join(root, `${name}-deleted`), join(scope, name), 'dir');
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
const target = join(root, targetDir);
|
|
73
|
+
mkdirSync(target, { recursive: true });
|
|
74
|
+
symlinkSync(target, join(scope, name), 'dir');
|
|
75
|
+
}
|
|
76
|
+
return root;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** Run the CLI against a checkout root, returning what CI would read. */
|
|
80
|
+
function run(root) {
|
|
81
|
+
// Spawned, not imported: the exit code is the only thing CI reads, and the
|
|
82
|
+
// bin's default-root behavior must stay exercised alongside the pure API.
|
|
83
|
+
const result = spawnSync(process.execPath, [BIN, root], { encoding: 'utf8' });
|
|
84
|
+
return { code: result.status, output: `${result.stdout ?? ''}${result.stderr ?? ''}` };
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** The problems for one fixture root, filtered by kind and/or package. */
|
|
88
|
+
function findings(root, { kind, pkg } = {}) {
|
|
89
|
+
return collectLinkProblems(root).problems.filter(
|
|
90
|
+
(p) => (kind ? p.kind === kind : true) && (pkg ? p.pkg === pkg : true)
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
describe('rule 1 — dangling @widgetic symlinks', () => {
|
|
95
|
+
it('fails when a link resolves to nothing, and names the package and link', () => {
|
|
96
|
+
const root = checkout({
|
|
97
|
+
packages: { site: { name: '@widgetic/site' } },
|
|
98
|
+
// The sibling the link points at was deleted after linking.
|
|
99
|
+
links: [['site', 'editor', null]]
|
|
100
|
+
});
|
|
101
|
+
const [problem] = findings(root, { kind: 'dangling link', pkg: 'site' });
|
|
102
|
+
assert.ok(problem, 'a dangling link must be reported');
|
|
103
|
+
assert.match(problem.detail, /node_modules\/@widgetic\/editor/);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it('reports which links resolve, so a clean run is not an inspecting-nothing run', () => {
|
|
107
|
+
const root = checkout({
|
|
108
|
+
packages: { site: { name: '@widgetic/site' }, chat: { name: '@widgetic/chat' } },
|
|
109
|
+
links: [['site', 'chat', 'chat']]
|
|
110
|
+
});
|
|
111
|
+
const links = collectLinkProblems(root).problems.filter((p) => p.kind === 'dangling link');
|
|
112
|
+
assert.equal(links.length, 0, 'a resolving sibling link is not a finding');
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it('fails when a link resolves outside the checkout', () => {
|
|
116
|
+
const root = checkout({ packages: { site: { name: '@widgetic/site' } } });
|
|
117
|
+
const scope = join(root, 'site', 'node_modules', '@widgetic');
|
|
118
|
+
mkdirSync(scope, { recursive: true });
|
|
119
|
+
symlinkSync(tmpdir(), join(scope, 'chat'), 'dir');
|
|
120
|
+
const [problem] = findings(root, { kind: 'outside checkout' });
|
|
121
|
+
assert.ok(problem, 'a link escaping the checkout must be reported');
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
describe('rule 2 — manifest-promised dist output', () => {
|
|
126
|
+
it('fails when a promised main/module/svelte/types file does not exist', () => {
|
|
127
|
+
const root = checkout({
|
|
128
|
+
packages: {
|
|
129
|
+
editor: {
|
|
130
|
+
name: '@widgetic/editor',
|
|
131
|
+
main: './dist/index.js',
|
|
132
|
+
module: './dist/index.js',
|
|
133
|
+
svelte: './dist/index.js',
|
|
134
|
+
types: './dist/index.d.ts'
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
});
|
|
138
|
+
const problems = findings(root, { kind: 'missing dist', pkg: 'editor' });
|
|
139
|
+
// Three fields promise the same file (deduplicated to one promise) plus
|
|
140
|
+
// the types entry — two distinct files, both missing.
|
|
141
|
+
assert.equal(problems.length, 2);
|
|
142
|
+
assert.match(problems[0].detail, /dist\/index\.js/);
|
|
143
|
+
assert.match(problems[1].detail, /dist\/index\.d\.ts/);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it('fails for a missing non-glob exports value', () => {
|
|
147
|
+
const root = checkout({
|
|
148
|
+
packages: {
|
|
149
|
+
'design-system': {
|
|
150
|
+
name: '@widgetic/design-system',
|
|
151
|
+
exports: {
|
|
152
|
+
'.': { import: './dist/index.js' },
|
|
153
|
+
'./previews': { import: './dist/components/previews/index.js' }
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
});
|
|
158
|
+
mkdirSync(join(root, 'design-system', 'dist'), { recursive: true });
|
|
159
|
+
writeFileSync(join(root, 'design-system', 'dist', 'index.js'), 'export {}');
|
|
160
|
+
const problems = findings(root, { kind: 'missing dist', pkg: 'design-system' });
|
|
161
|
+
assert.equal(problems.length, 1, 'only the previews export is unbuilt');
|
|
162
|
+
assert.match(problems[0].detail, /previews/);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it('does not flag glob exports or source-first .ts exports', () => {
|
|
166
|
+
const root = checkout({
|
|
167
|
+
packages: {
|
|
168
|
+
canvas: {
|
|
169
|
+
name: '@widgetic/canvas',
|
|
170
|
+
main: './dist/index.js',
|
|
171
|
+
types: './src/index.ts',
|
|
172
|
+
exports: {
|
|
173
|
+
'.': { types: './src/index.ts', import: './dist/index.js' },
|
|
174
|
+
'./icons/*': './dist/icons/*.js',
|
|
175
|
+
'./package.json': './package.json'
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
mkdirSync(join(root, 'canvas', 'dist'), { recursive: true });
|
|
181
|
+
writeFileSync(join(root, 'canvas', 'dist', 'index.js'), 'export {}');
|
|
182
|
+
const problems = findings(root, { kind: 'missing dist' });
|
|
183
|
+
assert.deepEqual(problems, [], 'globs, .ts contracts and existing files are not promises broken');
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
describe('rule 3 — dead checkout names', () => {
|
|
188
|
+
it('fails in source code, naming the file and the replacement', () => {
|
|
189
|
+
const root = checkout({
|
|
190
|
+
packages: { site: { name: '@widgetic/site' } }
|
|
191
|
+
});
|
|
192
|
+
writeFileSync(
|
|
193
|
+
join(root, 'site', 'vite.config.ts'),
|
|
194
|
+
["import { defineConfig } from 'vite';", "const ignore = ['**/props-editor/dist/**'];"].join('\n')
|
|
195
|
+
);
|
|
196
|
+
const [problem] = findings(root, { kind: 'dead name', pkg: 'site' });
|
|
197
|
+
assert.ok(problem, 'a live dead glob must be reported');
|
|
198
|
+
assert.match(problem.fix, /@widgetic\/editor/);
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it('fails in config JSON and other non-source files, not only imports', () => {
|
|
202
|
+
const root = checkout({
|
|
203
|
+
packages: { chat: { name: '@widgetic/chat' } }
|
|
204
|
+
});
|
|
205
|
+
writeFileSync(join(root, 'chat', 'conf.json'), '{"dir": "props-editor"}\n');
|
|
206
|
+
writeFileSync(join(root, 'chat', 'README.md'), 'Run the app from Frontend/prompt-chat/.\n');
|
|
207
|
+
const problems = findings(root, { kind: 'dead name' });
|
|
208
|
+
assert.equal(problems.length, 2, 'JSON and markdown carry dead paths too');
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it('does not flag live hyphenated identifiers that merely contain a dead name', () => {
|
|
212
|
+
const root = checkout({
|
|
213
|
+
packages: { chat: { name: '@widgetic/chat' } }
|
|
214
|
+
});
|
|
215
|
+
writeFileSync(
|
|
216
|
+
join(root, 'chat', 'names.ts'),
|
|
217
|
+
"export const MESSAGES_CLASS = 'prompt-chat-messages-scroll';\n"
|
|
218
|
+
);
|
|
219
|
+
assert.deepEqual(findings(root, { kind: 'dead name' }), [], 'prompt-chat-messages is a live identifier');
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
it('leaves CSS stylesheets unscanned — their identifiers are live contracts', () => {
|
|
223
|
+
const root = checkout({
|
|
224
|
+
packages: { editor: { name: '@widgetic/editor' } }
|
|
225
|
+
});
|
|
226
|
+
writeFileSync(
|
|
227
|
+
join(root, 'editor', 'component.css'),
|
|
228
|
+
':global(.props-editor) { overflow: hidden }\n'
|
|
229
|
+
);
|
|
230
|
+
assert.deepEqual(
|
|
231
|
+
findings(root, { kind: 'dead name' }),
|
|
232
|
+
[],
|
|
233
|
+
'.props-editor is the PropsEditor wrapper classname, not a checkout path'
|
|
234
|
+
);
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
it('strips comment lines from source, so documenting a rename is not a violation', () => {
|
|
238
|
+
const root = checkout({
|
|
239
|
+
packages: { 'widget-creator': { name: '@widgetic/creator' } }
|
|
240
|
+
});
|
|
241
|
+
writeFileSync(
|
|
242
|
+
join(root, 'widget-creator', 'vite.config.ts'),
|
|
243
|
+
[
|
|
244
|
+
'// The hand-kept table drifted onto two dead paths (prompt-chat, props-editor).',
|
|
245
|
+
'/* block * props-editor */',
|
|
246
|
+
'const dead = 0; // trailing props-editor comment stays exempt',
|
|
247
|
+
'const live = "props-editor";'
|
|
248
|
+
].join('\n')
|
|
249
|
+
);
|
|
250
|
+
const problems = findings(root, { kind: 'dead name' });
|
|
251
|
+
assert.equal(problems.length, 1, 'only the live string remains scannable');
|
|
252
|
+
assert.match(problems[0].detail, /vite\.config\.ts/);
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it('skips archive trees (__docs, __specs) and build output', () => {
|
|
256
|
+
const root = checkout({
|
|
257
|
+
packages: { site: { name: '@widgetic/site' } }
|
|
258
|
+
});
|
|
259
|
+
mkdirSync(join(root, 'site', '__docs'), { recursive: true });
|
|
260
|
+
mkdirSync(join(root, 'site', 'build', 'client'), { recursive: true });
|
|
261
|
+
writeFileSync(join(root, 'site', '__docs', 'history.md'), 'props-editor was renamed.\n');
|
|
262
|
+
writeFileSync(join(root, 'site', 'build', 'client', 'bundle.js'), 'props-editor\n');
|
|
263
|
+
assert.deepEqual(findings(root, { kind: 'dead name' }), [], 'history and build output are not live references');
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
it('skips the reporter package (dev-tools) — it names the renames as data', () => {
|
|
267
|
+
const root = checkout({
|
|
268
|
+
packages: {
|
|
269
|
+
'dev-tools': {
|
|
270
|
+
name: '@widgetic/dev-tools',
|
|
271
|
+
main: './dist/index.js'
|
|
272
|
+
},
|
|
273
|
+
site: { name: '@widgetic/site' }
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
mkdirSync(join(root, 'dev-tools', 'lib'), { recursive: true });
|
|
277
|
+
writeFileSync(join(root, 'dev-tools', 'lib', 'check-links.mjs'), 'const DEAD = { "props-editor": 1 };\n');
|
|
278
|
+
writeFileSync(join(root, 'site', 'vite.config.ts'), 'const ignore = ["prompt-chat"];');
|
|
279
|
+
const problems = findings(root, { kind: 'dead name' });
|
|
280
|
+
assert.equal(problems.length, 1, 'dev-tools is exempt; site is not');
|
|
281
|
+
assert.equal(problems[0].pkg, 'site');
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
it('honors per-package file exemptions but scans everything else in the package', () => {
|
|
285
|
+
const root = checkout({
|
|
286
|
+
packages: { site: { name: '@widgetic/site' } }
|
|
287
|
+
});
|
|
288
|
+
mkdirSync(join(root, 'site', 'scripts'), { recursive: true });
|
|
289
|
+
writeFileSync(join(root, 'site', 'scripts', 'build-creator-embed.mjs'), 'const c = "../prompt-chat/src/lib";\n');
|
|
290
|
+
writeFileSync(join(root, 'site', 'vite.config.ts'), 'const ignore = ["prompt-chat"];');
|
|
291
|
+
const { problems } = collectLinkProblems(root, {
|
|
292
|
+
exemptFiles: { site: ['scripts/build-creator-embed.mjs'] }
|
|
293
|
+
});
|
|
294
|
+
const dead = problems.filter((p) => p.kind === 'dead name');
|
|
295
|
+
assert.equal(dead.length, 1, 'the exempt file is skipped; the rest of the package is not');
|
|
296
|
+
assert.match(dead[0].detail, /vite\.config\.ts/);
|
|
297
|
+
});
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
describe('the CLI', () => {
|
|
301
|
+
it('exits 0 with a summary when the checkout is clean', () => {
|
|
302
|
+
const root = checkout({
|
|
303
|
+
packages: {
|
|
304
|
+
editor: { name: '@widgetic/editor', main: './dist/index.js' },
|
|
305
|
+
site: { name: '@widgetic/site' }
|
|
306
|
+
},
|
|
307
|
+
links: [['site', 'editor', 'editor']]
|
|
308
|
+
});
|
|
309
|
+
mkdirSync(dirname(join(root, 'editor', 'dist', 'index.js')), { recursive: true });
|
|
310
|
+
writeFileSync(join(root, 'editor', 'dist', 'index.js'), 'export {}');
|
|
311
|
+
const { code, output } = run(root);
|
|
312
|
+
assert.equal(code, 0, output);
|
|
313
|
+
assert.match(output, /2 packages/);
|
|
314
|
+
assert.match(output, /OK/);
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
it('exits 1 and prints the fix when anything is broken', () => {
|
|
318
|
+
const root = checkout({
|
|
319
|
+
packages: { site: { name: '@widgetic/site' }, editor: { name: '@widgetic/editor', main: './dist/index.js' } },
|
|
320
|
+
links: [['site', 'editor', null]]
|
|
321
|
+
});
|
|
322
|
+
const { code, output } = run(root);
|
|
323
|
+
assert.equal(code, 1);
|
|
324
|
+
assert.match(output, /dangling link/);
|
|
325
|
+
assert.match(output, /missing dist/);
|
|
326
|
+
assert.match(output, /npm run ldt/);
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
it('exits 1 when the root holds no packages', () => {
|
|
330
|
+
const root = mkdtempSync(join(tmpdir(), 'check-links-empty-'));
|
|
331
|
+
created.push(root);
|
|
332
|
+
const { code, output } = run(root);
|
|
333
|
+
assert.equal(code, 1);
|
|
334
|
+
assert.match(output, /no packages found/);
|
|
335
|
+
});
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
describe('unit shapes', () => {
|
|
339
|
+
it('promisedFiles skips globs and .ts, dedupes, and walks exports', () => {
|
|
340
|
+
const manifest = {
|
|
341
|
+
main: './dist/index.js',
|
|
342
|
+
module: './dist/index.js',
|
|
343
|
+
types: './src/index.ts',
|
|
344
|
+
exports: {
|
|
345
|
+
'.': './dist/index.js',
|
|
346
|
+
'./icons/*': './dist/icons/*.js',
|
|
347
|
+
'./package.json': './package.json'
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
assert.deepEqual(promisedFiles(manifest), ['./dist/index.js', './package.json']);
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
it('deadNameHits is word-bounded on both sides', () => {
|
|
354
|
+
assert.deepEqual(deadNameHits('import "../prompt-chat/src/lib"'), ['prompt-chat']);
|
|
355
|
+
assert.deepEqual(deadNameHits('.prompt-chat-messages-scroll {}'), []);
|
|
356
|
+
assert.deepEqual(deadNameHits('Frontend/props-editor/.env'), ['props-editor']);
|
|
357
|
+
assert.deepEqual(deadNameHits('nothing here'), []);
|
|
358
|
+
});
|
|
359
|
+
});
|
|
@@ -23,7 +23,6 @@ test('the design-system table expands to every subpath plus the index', () => {
|
|
|
23
23
|
'@widgetic/design-system/components',
|
|
24
24
|
'@widgetic/design-system/fonts',
|
|
25
25
|
'@widgetic/design-system/icons',
|
|
26
|
-
'@widgetic/design-system/previews',
|
|
27
26
|
'@widgetic/design-system/shad-editor',
|
|
28
27
|
'@widgetic/design-system/stores',
|
|
29
28
|
'@widgetic/design-system/styles'
|
|
@@ -107,14 +106,31 @@ test('the exclude and noExternal lists mirror the selection', () => {
|
|
|
107
106
|
* The layout truth on disk: every declared directory must exist, and the
|
|
108
107
|
* renamed-away ones must not come back. This is the pin that keeps a future
|
|
109
108
|
* sibling move a one-file change here instead of a silent five-repo drift.
|
|
109
|
+
*
|
|
110
|
+
* These gates need the real `Frontend/` checkout beside this package — which
|
|
111
|
+
* this repo's own CI does not have (it checks out dev-tools alone), so they
|
|
112
|
+
* skip there and run for real through `check-layout-fixtures` in a consumer,
|
|
113
|
+
* whose CI *does* sit beside the siblings.
|
|
110
114
|
*/
|
|
111
|
-
test('every declared checkout directory exists under Frontend/', () => {
|
|
115
|
+
test('every declared checkout directory exists under Frontend/', { skip: !existsSync(join(FRONTEND, 'api-sdk')) ? 'requires the Frontend/ sibling checkout (run check-layout-fixtures in a consumer)' : false }, () => {
|
|
112
116
|
for (const pkg of Object.values(SIBLING_PACKAGES)) {
|
|
113
117
|
assert.ok(existsSync(join(FRONTEND, pkg.dir)), `missing checkout: ${pkg.dir}`);
|
|
114
118
|
}
|
|
115
119
|
});
|
|
116
120
|
|
|
117
|
-
test('the
|
|
121
|
+
test('every declared subpath target exists inside its lib tree', { skip: !existsSync(join(FRONTEND, 'api-sdk')) ? 'requires the Frontend/ sibling checkout (run check-layout-fixtures in a consumer)' : false }, () => {
|
|
122
|
+
for (const [name, pkg] of Object.entries(SIBLING_PACKAGES)) {
|
|
123
|
+
if (!pkg.lib || !pkg.subpaths) continue;
|
|
124
|
+
for (const [suffix, target] of Object.entries(pkg.subpaths)) {
|
|
125
|
+
assert.ok(
|
|
126
|
+
existsSync(join(FRONTEND, pkg.dir, pkg.lib, target)),
|
|
127
|
+
`${name} subpath '${suffix}' -> ${target} does not exist`
|
|
128
|
+
);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
test('the renamed-away checkouts stay gone', { skip: !existsSync(join(FRONTEND, 'api-sdk')) ? 'requires the Frontend/ sibling checkout (run check-layout-fixtures in a consumer)' : false }, () => {
|
|
118
134
|
assert.ok(!existsSync(join(FRONTEND, 'props-editor')));
|
|
119
135
|
assert.ok(!existsSync(join(FRONTEND, 'prompt-chat')));
|
|
120
136
|
});
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Does the lockfile-peers check actually fail when coordination breaks?
|
|
4
|
+
*
|
|
5
|
+
* Each rule is driven against a throwaway Frontend checkout — manifests,
|
|
6
|
+
* lockfiles and the design-system checkout written to disagree on purpose —
|
|
7
|
+
* asserting on `collectPeersProblems`'s findings. The false-positive shapes
|
|
8
|
+
* matter as much as the true ones: a checker that red-flags an aligned pair,
|
|
9
|
+
* an exact-pin consumer, or a `>=` peer gets switched off within a day.
|
|
10
|
+
*
|
|
11
|
+
* Fixtures are built in the OS temp dir, never in the package.
|
|
12
|
+
*
|
|
13
|
+
* Runs on the built-in test runner:
|
|
14
|
+
*
|
|
15
|
+
* npm run test:peers
|
|
16
|
+
*/
|
|
17
|
+
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
|
18
|
+
import { spawnSync } from 'node:child_process';
|
|
19
|
+
import { tmpdir } from 'node:os';
|
|
20
|
+
import { join } from 'node:path';
|
|
21
|
+
import { fileURLToPath } from 'node:url';
|
|
22
|
+
import { after, describe, it } from 'node:test';
|
|
23
|
+
import assert from 'node:assert/strict';
|
|
24
|
+
|
|
25
|
+
import { collectPeersProblems, formatPeersProblems } from '../lib/lockfile-peers.mjs';
|
|
26
|
+
import { satisfies } from '../lib/semver-lite.mjs';
|
|
27
|
+
|
|
28
|
+
const DT_ROOT = fileURLToPath(new URL('..', import.meta.url));
|
|
29
|
+
|
|
30
|
+
const root = mkdtempSync(join(tmpdir(), 'dt-peers-'));
|
|
31
|
+
after(() => rmSync(root, { recursive: true, force: true }));
|
|
32
|
+
|
|
33
|
+
/** Write `root/<pkg>/<file>` with parent dirs. */
|
|
34
|
+
function put(pkg, file, content) {
|
|
35
|
+
const dir = join(root, pkg);
|
|
36
|
+
mkdirSync(dir, { recursive: true });
|
|
37
|
+
writeFileSync(join(dir, file), content);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** A healthy two-peer checkout: both resolve V, both declare ^V, checkout carries V. */
|
|
41
|
+
function healthyAt(version) {
|
|
42
|
+
for (const pkg of ['canvas', 'file-browser']) {
|
|
43
|
+
put(pkg, 'package.json', JSON.stringify({
|
|
44
|
+
name: pkg,
|
|
45
|
+
dependencies: { '@widgetic/design-system': `^${version}` }
|
|
46
|
+
}));
|
|
47
|
+
put(pkg, 'package-lock.json', JSON.stringify({
|
|
48
|
+
lockfileVersion: 3,
|
|
49
|
+
packages: { 'node_modules/@widgetic/design-system': { version } }
|
|
50
|
+
}));
|
|
51
|
+
}
|
|
52
|
+
put('design-system', 'package.json', JSON.stringify({
|
|
53
|
+
name: '@widgetic/design-system',
|
|
54
|
+
version
|
|
55
|
+
}));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function problemsFor(mutate) {
|
|
59
|
+
if (mutate) mutate();
|
|
60
|
+
return collectPeersProblems(root);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
describe('semver-lite', () => {
|
|
64
|
+
it('admits carets, >= peers, and exact pins', () => {
|
|
65
|
+
assert.equal(satisfies('0.5.14', '^0.5.12'), true);
|
|
66
|
+
assert.equal(satisfies('0.5.12', '^0.5.12'), true);
|
|
67
|
+
assert.equal(satisfies('0.6.0', '^0.5.12'), false); // ^0.x pins the minor
|
|
68
|
+
assert.equal(satisfies('1.9.0', '^1.2.3'), true); // non-zero major opens the minor
|
|
69
|
+
assert.equal(satisfies('2.0.0', '^1.2.3'), false);
|
|
70
|
+
assert.equal(satisfies('0.5.14', '>=0.3.0'), true);
|
|
71
|
+
assert.equal(satisfies('0.5.14', '0.5.14'), true);
|
|
72
|
+
assert.equal(satisfies('0.5.15', '0.5.14'), false);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('fails closed on shapes it does not understand', () => {
|
|
76
|
+
assert.equal(satisfies('0.5.14', 'workspace:*'), false);
|
|
77
|
+
assert.equal(satisfies('0.5.14', '~0.5.12'), false); // tilde out of vocabulary on purpose
|
|
78
|
+
assert.equal(satisfies('0.5.14-beta.1', '^0.5.12'), false);
|
|
79
|
+
assert.equal(satisfies('not-a-version', '^1.0.0'), false);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
describe('collectPeersProblems', () => {
|
|
84
|
+
it('passes the healthy aligned pair — no false positive', () => {
|
|
85
|
+
assert.deepEqual(problemsFor(() => healthyAt('0.5.14')), []);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('passes an exact-pin consumer whose pin matches', () => {
|
|
89
|
+
healthyAt('0.5.14');
|
|
90
|
+
put('file-browser', 'package.json', JSON.stringify({
|
|
91
|
+
name: 'file-browser',
|
|
92
|
+
dependencies: { '@widgetic/design-system': '0.5.14' }
|
|
93
|
+
}));
|
|
94
|
+
assert.deepEqual(collectPeersProblems(root), []);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it('flags version divergence when the lockfiles disagree within the same range', () => {
|
|
98
|
+
healthyAt('0.5.14');
|
|
99
|
+
put('file-browser', 'package-lock.json', JSON.stringify({
|
|
100
|
+
lockfileVersion: 3,
|
|
101
|
+
packages: { 'node_modules/@widgetic/design-system': { version: '0.5.12' } }
|
|
102
|
+
}));
|
|
103
|
+
const problems = collectPeersProblems(root);
|
|
104
|
+
// Two findings: the divergence itself, and checkout-sync for file-browser
|
|
105
|
+
// (its 0.5.12 lock also differs from the checkout's 0.5.14 — the exact
|
|
106
|
+
// shape the real repo was in before the alignment commit).
|
|
107
|
+
assert.equal(problems.length, 2);
|
|
108
|
+
assert.equal(problems[0].kind, 'version-divergence');
|
|
109
|
+
assert.match(problems[0].detail, /canvas 0\.5\.14/);
|
|
110
|
+
assert.match(problems[0].detail, /file-browser 0\.5\.12/);
|
|
111
|
+
assert.match(problems[0].fix, /coordinated/);
|
|
112
|
+
assert.equal(problems[1].kind, 'checkout-sync');
|
|
113
|
+
assert.equal(problems[1].pkg, 'file-browser');
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it('fires at the next publish: stale ranges and out-of-sync lockfiles, two findings per peer', () => {
|
|
117
|
+
healthyAt('0.5.14');
|
|
118
|
+
put('design-system', 'package.json', JSON.stringify({
|
|
119
|
+
name: '@widgetic/design-system',
|
|
120
|
+
version: '0.6.0'
|
|
121
|
+
}));
|
|
122
|
+
const problems = collectPeersProblems(root);
|
|
123
|
+
assert.equal(problems.filter((p) => p.kind === 'stale-manifest').length, 2); // ^0.5.12 cannot admit 0.6.0
|
|
124
|
+
assert.equal(problems.filter((p) => p.kind === 'checkout-sync').length, 2); // locks still at 0.5.14
|
|
125
|
+
assert.ok(problems.every((p) => p.fix.match(/coordinated|together with the other peer/)));
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('fires checkout-sync on a minor-only release, which a caret range silently admits', () => {
|
|
129
|
+
healthyAt('0.5.14');
|
|
130
|
+
put('design-system', 'package.json', JSON.stringify({
|
|
131
|
+
name: '@widgetic/design-system',
|
|
132
|
+
version: '0.5.15'
|
|
133
|
+
}));
|
|
134
|
+
const problems = collectPeersProblems(root);
|
|
135
|
+
assert.deepEqual(problems.map((p) => p.kind), ['checkout-sync', 'checkout-sync']);
|
|
136
|
+
assert.match(problems[0].detail, /carries 0\.5\.15 but canvas's lockfile resolves 0\.5\.14/);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it('goes quiet again once the coordinated bump lands', () => {
|
|
140
|
+
healthyAt('0.5.14');
|
|
141
|
+
put('design-system', 'package.json', JSON.stringify({
|
|
142
|
+
name: '@widgetic/design-system',
|
|
143
|
+
version: '0.5.15'
|
|
144
|
+
}));
|
|
145
|
+
for (const pkg of ['canvas', 'file-browser']) {
|
|
146
|
+
put(pkg, 'package.json', JSON.stringify({
|
|
147
|
+
name: pkg,
|
|
148
|
+
dependencies: { '@widgetic/design-system': '^0.5.15' }
|
|
149
|
+
}));
|
|
150
|
+
put(pkg, 'package-lock.json', JSON.stringify({
|
|
151
|
+
lockfileVersion: 3,
|
|
152
|
+
packages: { 'node_modules/@widgetic/design-system': { version: '0.5.15' } }
|
|
153
|
+
}));
|
|
154
|
+
}
|
|
155
|
+
assert.deepEqual(collectPeersProblems(root), []);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it('reports an unreadable lockfile instead of crashing', () => {
|
|
159
|
+
healthyAt('0.5.14');
|
|
160
|
+
writeFileSync(join(root, 'canvas', 'package-lock.json'), '{ not json');
|
|
161
|
+
const problems = collectPeersProblems(root);
|
|
162
|
+
assert.equal(problems[0].kind, 'unreadable');
|
|
163
|
+
assert.equal(problems[0].pkg, 'canvas');
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it('reports a lockfile that resolves no design-system at all', () => {
|
|
167
|
+
healthyAt('0.5.14');
|
|
168
|
+
put('canvas', 'package-lock.json', JSON.stringify({ lockfileVersion: 3, packages: {} }));
|
|
169
|
+
const problems = collectPeersProblems(root);
|
|
170
|
+
assert.equal(problems[0].kind, 'unresolved');
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it('formats findings with kind, detail, and the arrow-fix', () => {
|
|
174
|
+
healthyAt('0.5.14');
|
|
175
|
+
put('file-browser', 'package-lock.json', JSON.stringify({
|
|
176
|
+
lockfileVersion: 3,
|
|
177
|
+
packages: { 'node_modules/@widgetic/design-system': { version: '0.5.12' } }
|
|
178
|
+
}));
|
|
179
|
+
const text = formatPeersProblems(collectPeersProblems(root));
|
|
180
|
+
assert.match(text, /version-divergence/);
|
|
181
|
+
assert.match(text, /→/);
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
describe('the CLI', () => {
|
|
186
|
+
const bin = join(DT_ROOT, 'bin', 'check-design-system-peers.mjs');
|
|
187
|
+
|
|
188
|
+
it('exits 0 on the healthy fixture root', () => {
|
|
189
|
+
healthyAt('0.5.14');
|
|
190
|
+
const { status } = spawnSync(process.execPath, [bin, root], { encoding: 'utf8' });
|
|
191
|
+
assert.equal(status, 0);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it('exits 1 on a diverged fixture root and prints the findings', () => {
|
|
195
|
+
put('file-browser', 'package-lock.json', JSON.stringify({
|
|
196
|
+
lockfileVersion: 3,
|
|
197
|
+
packages: { 'node_modules/@widgetic/design-system': { version: '0.5.12' } }
|
|
198
|
+
}));
|
|
199
|
+
const { status, stderr } = spawnSync(process.execPath, [bin, root], { encoding: 'utf8' });
|
|
200
|
+
assert.equal(status, 1);
|
|
201
|
+
assert.match(stderr, /version-divergence/);
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it('exits 2 without a root argument', () => {
|
|
205
|
+
const { status } = spawnSync(process.execPath, [bin], { encoding: 'utf8' });
|
|
206
|
+
assert.equal(status, 2);
|
|
207
|
+
});
|
|
208
|
+
});
|