@ai-ecoverse/slicc-shared-web 1.23.0 → 1.23.1
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/README.md +2 -1
- package/bin/slicc-unit-cover.mjs +6 -8
- package/package.json +2 -2
- package/unit/graph.mjs +24 -17
package/README.md
CHANGED
|
@@ -136,7 +136,8 @@ The committed public CLI integration regressions use real git repositories and a
|
|
|
136
136
|
|
|
137
137
|
The diff-coverage hook, `slicc-unit-cover`, runs only the unit tests that cover the staged change, then `slicc-diff-cover` on their `coverage/unit/lcov.info`, so every staged line in `src/` still has to run:
|
|
138
138
|
|
|
139
|
-
- **What counts as changed:** the staged files (`git diff --cached --name-only`).
|
|
139
|
+
- **What counts as changed:** the staged files (`git diff --cached --name-only`), and nothing else. `test/unit/` is gitignored, and repos that keep their unit tests in a store outside git sync the whole store into it before a commit, which brings in tests for code that is on other branches; so a unit test that is new or edited runs only when its imports reach a staged file, like any other. One that reaches nothing staged adds no coverage to the staged lines.
|
|
140
|
+
- **A unit test for code this tree doesn't have:** a test whose imports reach a staged file but also a repo file that doesn't exist and isn't a staged deletion (a store test for a module on another branch) is skipped, and the hook names it in one line before the count.
|
|
140
141
|
- **Which tests run:** every `*.test.*` file in `test/unit/` that is changed, or whose static imports reach a changed file. The import graph is parsed with [acorn](https://github.com/acornjs/acorn), TypeScript after Node's type stripping. It follows `import`, `export … from`, `import()`, `require()` and `new URL(…, import.meta.url)` with literal paths, relative or through the `paths` of `tsconfig.json` (and the files it extends). A path may leave out its extension or name `index`, and `.js` also finds `.ts`. Type-only imports don't count, and nothing is followed into `node_modules/`.
|
|
141
142
|
- **Barrels are followed by name:** a test that imports `{ a, b }` from a module follows only what provides `a` and `b`: `export { a } from`, `export { default as a } from`, an imported binding exported again, and `export * from`, by the target's own exports. `const { a, b } = await import('…')` with a literal path is followed by name too. A name the module declares itself follows all of that module's imports. A namespace import (`import * as`), any other `import()` (bound to a namespace, with `.then`, or destructured with a computed key or a rest element), a `require()`, and an `export *` that leads outside the repo or into CommonJS (any `.cjs` or `.cts` file) all count as the whole module.
|
|
142
143
|
- **No code staged** (only docs, YAML, JSON or lockfiles): no unit tests and no diff coverage; the hook passes.
|
package/bin/slicc-unit-cover.mjs
CHANGED
|
@@ -14,13 +14,6 @@ function git(...args) {
|
|
|
14
14
|
return run.status === 0 ? run.stdout : undefined;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
function since() {
|
|
18
|
-
const moved = git('log', '-g', '-1', '--format=%gd', '--date=unix', 'HEAD')?.match(/\{(\d+)\}/);
|
|
19
|
-
const committed = git('log', '-1', '--format=%ct', 'HEAD')?.trim();
|
|
20
|
-
const seconds = Math.max(Number(moved?.[1] ?? 0), Number(committed || 0));
|
|
21
|
-
return seconds > 0 ? seconds * 1000 : undefined;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
17
|
function run(command, args, env) {
|
|
25
18
|
const result = spawnSync(command, args, { cwd: root, env, stdio: 'inherit' });
|
|
26
19
|
if (result.error) throw result.error;
|
|
@@ -30,7 +23,12 @@ function run(command, args, env) {
|
|
|
30
23
|
function selection(staged) {
|
|
31
24
|
if (process.env.SLICC_UNIT_ALL === '1') return undefined;
|
|
32
25
|
try {
|
|
33
|
-
const { tests, total } = select({ root, changed: staged
|
|
26
|
+
const { tests, elsewhere, total } = select({ root, changed: staged });
|
|
27
|
+
if (elsewhere.length > 0) {
|
|
28
|
+
say(
|
|
29
|
+
`skipping ${elsewhere.length} that import a module this tree lacks: ${elsewhere.join(' ')}`
|
|
30
|
+
);
|
|
31
|
+
}
|
|
34
32
|
say(`running ${tests.length} of ${total} unit test files`);
|
|
35
33
|
return tests;
|
|
36
34
|
} catch (error) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-ecoverse/slicc-shared-web",
|
|
3
|
-
"version": "1.23.
|
|
3
|
+
"version": "1.23.1",
|
|
4
4
|
"description": "Shared Renovate, Biome, TypeScript, lefthook and GitHub Actions configuration, plus the CDP integration-test harness, for SLICC's web repos",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"@biomejs/biome": "2.5.15",
|
|
67
67
|
"monocart-coverage-reports": "2.13.2",
|
|
68
68
|
"playwright-core": "1.64.0",
|
|
69
|
-
"pnpm": "12.11.
|
|
69
|
+
"pnpm": "12.11.2",
|
|
70
70
|
"semantic-release": "25.0.9"
|
|
71
71
|
},
|
|
72
72
|
"peerDependencies": {
|
package/unit/graph.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { readdirSync, readFileSync, statSync } from 'node:fs';
|
|
1
|
+
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
|
|
2
2
|
import { stripTypeScriptTypes } from 'node:module';
|
|
3
3
|
import { dirname, extname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
4
4
|
import { parse } from 'acorn';
|
|
@@ -243,12 +243,16 @@ function reacher(graph) {
|
|
|
243
243
|
const context = { find, provides: provider(graph) };
|
|
244
244
|
return (start) => {
|
|
245
245
|
const touched = new Set();
|
|
246
|
+
const absent = [];
|
|
246
247
|
const seen = new Set();
|
|
247
248
|
const queue = [[start, BODY]];
|
|
248
249
|
const go = (file, spec, name) => {
|
|
249
250
|
const found = find(file, spec);
|
|
250
251
|
if (found?.hit) queue.push([found.hit, name]);
|
|
251
|
-
else if (found)
|
|
252
|
+
else if (found) {
|
|
253
|
+
for (const path of found.missing) touched.add(path);
|
|
254
|
+
if (found.missing.length > 0) absent.push(found.missing);
|
|
255
|
+
}
|
|
252
256
|
};
|
|
253
257
|
while (queue.length > 0) {
|
|
254
258
|
const [file, name] = queue.pop();
|
|
@@ -263,7 +267,7 @@ function reacher(graph) {
|
|
|
263
267
|
else go(next, spec, wanted);
|
|
264
268
|
}
|
|
265
269
|
}
|
|
266
|
-
return touched;
|
|
270
|
+
return { touched, absent };
|
|
267
271
|
};
|
|
268
272
|
}
|
|
269
273
|
|
|
@@ -298,20 +302,23 @@ function step(info, name, file, context) {
|
|
|
298
302
|
return starred(file, info, name, context);
|
|
299
303
|
}
|
|
300
304
|
|
|
301
|
-
export function select({ root, changed
|
|
302
|
-
const
|
|
303
|
-
const
|
|
304
|
-
const all = files.filter((file) => tests.test(file));
|
|
305
|
-
const fresh = files.filter((file) => since === undefined || statSync(file).mtimeMs > since);
|
|
306
|
-
const touched = new Set([...changed.map((file) => resolve(root, file)), ...fresh]);
|
|
305
|
+
export function select({ root, changed }) {
|
|
306
|
+
const all = walk(join(root, 'test', 'unit')).filter((file) => tests.test(file));
|
|
307
|
+
const staged = new Set(changed.map((file) => resolve(root, file)));
|
|
307
308
|
const reach = reacher(modules(root));
|
|
308
|
-
const reached = new Set(all.filter((test) => [...reach(test)].some((file) => touched.has(file))));
|
|
309
309
|
const posix = (file) => relative(root, file).split(sep).join('/');
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
310
|
+
const lacks = ([target, ...rest]) =>
|
|
311
|
+
!relative(root, target).startsWith('..') &&
|
|
312
|
+
!target.includes(`${sep}node_modules${sep}`) &&
|
|
313
|
+
!existsSync(target) &&
|
|
314
|
+
![target, ...rest].some((path) => staged.has(path));
|
|
315
|
+
const reached = [];
|
|
316
|
+
const elsewhere = [];
|
|
317
|
+
for (const test of all) {
|
|
318
|
+
const { touched, absent } = reach(test);
|
|
319
|
+
if (![...touched].some((file) => staged.has(file))) continue;
|
|
320
|
+
const lacking = absent.some(lacks);
|
|
321
|
+
(lacking ? elsewhere : reached).push(posix(test));
|
|
322
|
+
}
|
|
323
|
+
return { tests: reached.sort(), elsewhere: elsewhere.sort(), total: all.length };
|
|
317
324
|
}
|