@ai-ecoverse/slicc-shared-web 1.29.9 → 1.29.10
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 +1 -1
- package/package.json +1 -1
- package/unit/exports.mjs +3 -1
- package/unit/graph.mjs +25 -7
package/README.md
CHANGED
|
@@ -229,7 +229,7 @@ The diff-coverage hook, `slicc-unit-cover`, runs only the unit tests that cover
|
|
|
229
229
|
|
|
230
230
|
- **Which directories are source:** `src/` by default, anywhere in the path, as before. A repo whose code lives elsewhere lists its directories in `package.json`: `"slicc": { "unitSources": ["extension", "six", "scripts"] }`, repo-relative, without `.` or `..` segments. `mcr.config.mjs` then collects coverage only from those directories, and the hook treats a staged file outside them as no code. A malformed list fails the hook.
|
|
231
231
|
- **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.
|
|
232
|
-
- **A unit test for code this tree doesn't have:** a test whose imports reach a staged file but also a
|
|
232
|
+
- **A unit test for code this tree doesn't have:** a test whose imports reach a staged file but also a code module under the sources that doesn't exist, isn't gitignored 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. A missing `new URL(…, import.meta.url)` target, a missing non-code file such as `.wasm` or `.json`, and a missing file outside the sources or gitignored (a build output such as `dist/` or a bundled worker) don't skip the test.
|
|
233
233
|
- **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, or amaro's transform where stripping isn't enough. 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/`.
|
|
234
234
|
- **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.
|
|
235
235
|
- **No code staged** (only docs, YAML, JSON or lockfiles): no unit tests and no diff coverage; the hook passes.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-ecoverse/slicc-shared-web",
|
|
3
|
-
"version": "1.29.
|
|
3
|
+
"version": "1.29.10",
|
|
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",
|
package/unit/exports.mjs
CHANGED
|
@@ -59,7 +59,9 @@ function dynamics(ast) {
|
|
|
59
59
|
continue;
|
|
60
60
|
}
|
|
61
61
|
const value = dynamic(node);
|
|
62
|
-
if (value !== undefined)
|
|
62
|
+
if (value !== undefined) {
|
|
63
|
+
found.push({ spec: value, names: [ALL], asset: node.type === 'NewExpression' });
|
|
64
|
+
}
|
|
63
65
|
for (const key of Object.keys(node)) {
|
|
64
66
|
const child = node[key];
|
|
65
67
|
if (Array.isArray(child)) {
|
package/unit/graph.mjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
1
2
|
import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';
|
|
2
3
|
import { dirname, extname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
3
4
|
import { parse } from 'acorn';
|
|
4
5
|
import { ALL, BODY, describe } from './exports.mjs';
|
|
6
|
+
import { inSources, unitSources } from './sources.mjs';
|
|
5
7
|
import { compile } from './typescript.mjs';
|
|
6
8
|
|
|
7
9
|
export const code = /\.(m|c)?(j|t)sx?$/;
|
|
@@ -226,12 +228,12 @@ function reacher(graph) {
|
|
|
226
228
|
const absent = [];
|
|
227
229
|
const seen = new Set();
|
|
228
230
|
const queue = [[start, BODY]];
|
|
229
|
-
const go = (file, spec, name) => {
|
|
231
|
+
const go = (file, spec, name, asset) => {
|
|
230
232
|
const found = find(file, spec);
|
|
231
233
|
if (found?.hit) queue.push([found.hit, name]);
|
|
232
234
|
else if (found) {
|
|
233
235
|
for (const path of found.missing) touched.add(path);
|
|
234
|
-
if (found.missing.length > 0) absent.push(found.missing);
|
|
236
|
+
if (found.missing.length > 0 && !asset) absent.push(found.missing);
|
|
235
237
|
}
|
|
236
238
|
};
|
|
237
239
|
while (queue.length > 0) {
|
|
@@ -242,9 +244,9 @@ function reacher(graph) {
|
|
|
242
244
|
touched.add(file);
|
|
243
245
|
const info = graph.load(file);
|
|
244
246
|
if (!info) continue;
|
|
245
|
-
for (const [next, wanted, spec] of step(info, name, file, context)) {
|
|
247
|
+
for (const [next, wanted, spec, asset] of step(info, name, file, context)) {
|
|
246
248
|
if (spec === undefined) queue.push([next, wanted]);
|
|
247
|
-
else go(next, spec, wanted);
|
|
249
|
+
else go(next, spec, wanted, asset);
|
|
248
250
|
}
|
|
249
251
|
}
|
|
250
252
|
return { touched, absent };
|
|
@@ -264,7 +266,9 @@ function step(info, name, file, context) {
|
|
|
264
266
|
if (name === BODY) {
|
|
265
267
|
return [
|
|
266
268
|
...info.imports.flatMap(({ spec, names }) => names.map((wanted) => [file, wanted, spec])),
|
|
267
|
-
...info.dynamic.flatMap(({ spec, names }) =>
|
|
269
|
+
...info.dynamic.flatMap(({ spec, names, asset }) =>
|
|
270
|
+
names.map((wanted) => [file, wanted, spec, asset])
|
|
271
|
+
),
|
|
268
272
|
];
|
|
269
273
|
}
|
|
270
274
|
if (info.whole) return [[file, BODY]];
|
|
@@ -282,15 +286,29 @@ function step(info, name, file, context) {
|
|
|
282
286
|
return starred(file, info, name, context);
|
|
283
287
|
}
|
|
284
288
|
|
|
289
|
+
function ignored(root) {
|
|
290
|
+
const memo = new Map();
|
|
291
|
+
return (path) => {
|
|
292
|
+
if (!memo.has(path)) {
|
|
293
|
+
const run = spawnSync('git', ['check-ignore', '-q', '--', path], { cwd: root });
|
|
294
|
+
memo.set(path, run.status === 0);
|
|
295
|
+
}
|
|
296
|
+
return memo.get(path);
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
|
|
285
300
|
export function select({ root, changed }) {
|
|
286
301
|
const all = walk(join(root, 'test', 'unit')).filter((file) => tests.test(file));
|
|
287
302
|
const staged = new Set(changed.map((file) => resolve(root, file)));
|
|
288
303
|
const reach = reacher(modules(root));
|
|
289
304
|
const posix = (file) => relative(root, file).split(sep).join('/');
|
|
305
|
+
const sources = unitSources(root);
|
|
306
|
+
const built = ignored(root);
|
|
290
307
|
const lacks = ([target, ...rest]) =>
|
|
291
|
-
|
|
292
|
-
|
|
308
|
+
(code.test(target) || extname(target) === '') &&
|
|
309
|
+
inSources(relative(root, target), root, sources) &&
|
|
293
310
|
!existsSync(target) &&
|
|
311
|
+
!built(target) &&
|
|
294
312
|
![target, ...rest].some((path) => staged.has(path));
|
|
295
313
|
const reached = [];
|
|
296
314
|
const elsewhere = [];
|