@ai-ecoverse/slicc-shared-web 1.23.0 → 1.23.2
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 +3 -2
- package/bin/slicc-agents-md.sh +6 -1
- package/bin/slicc-lint-comments.sh +3 -2
- package/bin/slicc-lint.sh +27 -6
- package/bin/slicc-no-unit-tests.sh +2 -0
- package/bin/slicc-unit-cover.mjs +6 -8
- package/package.json +3 -3
- package/unit/graph.mjs +24 -17
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ Configuration shared by SLICC's web repos ([slicc-bios](https://github.com/ai-ec
|
|
|
10
10
|
| `tsconfig.json` | TypeScript base for Node's type stripping | `tsconfig.json`: `{ "extends": "@ai-ecoverse/slicc-shared-web/tsconfig.json", "include": ["src/**/*.ts"] }` |
|
|
11
11
|
| `lefthook.yml` | Pre-commit hooks: Biome, typecheck, no comments, no unit tests in git, AGENTS.md, and diff coverage over [only the unit tests the change reaches](#which-unit-tests-a-commit-runs) | `lefthook.yml`: `extends: [node_modules/@ai-ecoverse/slicc-shared-web/lefthook.yml]` |
|
|
12
12
|
| `mcr.config.mjs` | Unit-test coverage for JS and TS sources in `src/` (TS types are stripped first), written to `coverage/unit/lcov.info`. With `SLICC_UNIT_TESTS` set, `node --test` runs only those files ([below](#which-unit-tests-a-commit-runs)) | `test:unit`: `mcr -c node_modules/@ai-ecoverse/slicc-shared-web/mcr.config.mjs node --test 'test/unit/**/*.test.mjs'` |
|
|
13
|
-
| `bin/` | `slicc-lint` runs every check below plus Biome and, if the repo has one, `typecheck`. `slicc-lint-comments` runs the [slicc no-comment checker](https://github.com/ai-ecoverse/slicc/tree/main/packages/dev-tools/no-comment) at a pinned commit, allowing AGENTS.md and [`# renovate:` annotations](#versions-pinned-in-workflow-files) in workflow and action files. `slicc-agents-md`, `slicc-no-unit-tests` and `slicc-diff-cover` complete the set, and `slicc-unit-cover` is the diff-coverage hook. `slicc-minidump <file.dmp>...` prints a crash dump's stack, described [below](#crash-dumps). `slicc-memory-peak` prints the job's [memory peak](#memory-peak) | `lint`: `slicc-lint`, and the hooks above |
|
|
13
|
+
| `bin/` | `slicc-lint` runs every check below plus Biome and, if the repo has one, `typecheck`. Every step prints its own `<step>: PASS …` line, and slicc-lint checks for it: a step that exits 0 without one fails the run with exit 70 (`slicc-lint: FAIL <step> (no PASS line from it)`), so a check that silently stops early can't pass. The last line, `slicc-lint: PASS`, comes only after every step has printed its PASS, and a gate can require it. `slicc-lint-comments` runs the [slicc no-comment checker](https://github.com/ai-ecoverse/slicc/tree/main/packages/dev-tools/no-comment) at a pinned commit, allowing AGENTS.md and [`# renovate:` annotations](#versions-pinned-in-workflow-files) in workflow and action files. `slicc-agents-md`, `slicc-no-unit-tests` and `slicc-diff-cover` complete the set, and `slicc-unit-cover` is the diff-coverage hook. `slicc-minidump <file.dmp>...` prints a crash dump's stack, described [below](#crash-dumps). `slicc-memory-peak` prints the job's [memory peak](#memory-peak) | `lint`: `slicc-lint`, and the hooks above |
|
|
14
14
|
| `pnpmfile.mjs` | pnpm's counterpart to the Renovate preset: an `updateConfig` hook that adds `@ai-ecoverse/*` to `minimumReleaseAgeExclude`, so pnpm 12 doesn't hold back our own fresh releases (`ERR_PNPM_MINIMUM_RELEASE_AGE_VIOLATION`) while third-party packages keep its age check | in a repo with a pnpm lockfile, as a [config dependency](https://pnpm.io/config-dependencies) in `pnpm-workspace.yaml`: `configDependencies: { '@ai-ecoverse/slicc-shared-web': X.Y.Z }` plus `pnpmfile: node_modules/.pnpm-config/@ai-ecoverse/slicc-shared-web/pnpmfile.mjs` |
|
|
15
15
|
| `harness/` | The CDP integration-test harness, described [below](#integration-test-harness) | `import { launch } from '@ai-ecoverse/slicc-shared-web/harness'`, and `--test-global-setup=node_modules/@ai-ecoverse/slicc-shared-web/harness/global.mjs` |
|
|
16
16
|
|
|
@@ -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-agents-md.sh
CHANGED
|
@@ -19,5 +19,10 @@ while IFS= read -r file; do
|
|
|
19
19
|
;;
|
|
20
20
|
esac
|
|
21
21
|
done < "$list"
|
|
22
|
+
count=$(wc -l < "$list" | tr -d ' ')
|
|
22
23
|
rm -f "$list"
|
|
23
|
-
|
|
24
|
+
if [ "$failed" -ne 0 ]; then
|
|
25
|
+
printf 'slicc-agents-md: FAIL\n' >&2
|
|
26
|
+
exit 1
|
|
27
|
+
fi
|
|
28
|
+
printf 'slicc-agents-md: PASS %s AGENTS.md files within %s characters, no CLAUDE.md\n' "$count" "$limit"
|
|
@@ -10,13 +10,14 @@ if [ ! -f "$dir/check.mjs" ]; then
|
|
|
10
10
|
fi
|
|
11
11
|
report=$(node "$dir/check.mjs" --force "$@" 2>&1) || true
|
|
12
12
|
if [ -z "$report" ]; then
|
|
13
|
-
printf 'slicc-lint-comments: the no-comment checker produced no report\n' >&2
|
|
13
|
+
printf 'slicc-lint-comments: FAIL the no-comment checker produced no report\n' >&2
|
|
14
14
|
exit 1
|
|
15
15
|
fi
|
|
16
16
|
renovate='^(\.github/workflows/[^/:]+|(.+/)?action)\.ya?ml:[0-9]+: comment not allowed: # renovate: datasource=[a-z.-]+ depName=[^ ]+( packageName=[^ ]+)?( versioning=[^ ]+)?( extractVersion=[^ ]+)?( registryUrl=[^ ]+)?$'
|
|
17
17
|
rest=$(printf '%s\n' "$report" | grep -vE '^ok: |^(.+/)?AGENTS\.md: documentation file is not allowed' | grep -vE "$renovate" || true)
|
|
18
18
|
if [ -n "$rest" ]; then
|
|
19
19
|
printf '%s\n' "$rest" >&2
|
|
20
|
+
printf 'slicc-lint-comments: FAIL\n' >&2
|
|
20
21
|
exit 1
|
|
21
22
|
fi
|
|
22
|
-
printf '
|
|
23
|
+
printf 'slicc-lint-comments: PASS no comments besides # renovate: annotations, and no documentation besides README.md and AGENTS.md\n'
|
package/bin/slicc-lint.sh
CHANGED
|
@@ -1,10 +1,31 @@
|
|
|
1
1
|
#!/bin/sh
|
|
2
|
-
set -
|
|
2
|
+
set -u
|
|
3
3
|
bin=$(dirname "$(readlink -f "$0")")
|
|
4
|
-
|
|
4
|
+
failed() {
|
|
5
|
+
printf 'slicc-lint: FAIL %s\n' "$1" >&2
|
|
6
|
+
exit "$2"
|
|
7
|
+
}
|
|
8
|
+
run() {
|
|
9
|
+
name=$1
|
|
10
|
+
shift
|
|
11
|
+
out=$("$@" 2>&1)
|
|
12
|
+
rc=$?
|
|
13
|
+
[ -n "$out" ] && printf '%s\n' "$out"
|
|
14
|
+
[ "$rc" -eq 0 ] || failed "$name" "$rc"
|
|
15
|
+
}
|
|
16
|
+
checked() {
|
|
17
|
+
name=$1
|
|
18
|
+
shift
|
|
19
|
+
run "$name" "$@"
|
|
20
|
+
printf '%s\n' "$out" | grep -q "^$name: PASS" || failed "$name (no PASS line from it)" 70
|
|
21
|
+
}
|
|
22
|
+
run biome npx --no-install biome check .
|
|
23
|
+
printf 'biome: PASS\n'
|
|
5
24
|
if node -e "process.exit(require('./package.json').scripts?.typecheck ? 0 : 1)"; then
|
|
6
|
-
npm run --silent typecheck
|
|
25
|
+
run typecheck npm run --silent typecheck
|
|
26
|
+
printf 'typecheck: PASS\n'
|
|
7
27
|
fi
|
|
8
|
-
"$bin/slicc-lint-comments.sh"
|
|
9
|
-
"$bin/slicc-no-unit-tests.sh"
|
|
10
|
-
"$bin/slicc-agents-md.sh"
|
|
28
|
+
checked slicc-lint-comments "$bin/slicc-lint-comments.sh"
|
|
29
|
+
checked slicc-no-unit-tests "$bin/slicc-no-unit-tests.sh"
|
|
30
|
+
checked slicc-agents-md "$bin/slicc-agents-md.sh"
|
|
31
|
+
printf 'slicc-lint: PASS\n'
|
|
@@ -3,5 +3,7 @@ set -u
|
|
|
3
3
|
found=$(git ls-files --cached --others --exclude-standard | grep -E '(^|/)(tests?|__tests__)/|\.(test|spec)\.' | grep -vE '^test/integration/')
|
|
4
4
|
if [ -n "$found" ]; then
|
|
5
5
|
printf 'Unit tests stay out of git; keep them in the gitignored test/unit/:\n%s\n' "$found" >&2
|
|
6
|
+
printf 'slicc-no-unit-tests: FAIL\n' >&2
|
|
6
7
|
exit 1
|
|
7
8
|
fi
|
|
9
|
+
printf 'slicc-no-unit-tests: PASS no unit tests in git\n'
|
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.2",
|
|
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",
|
|
@@ -62,11 +62,11 @@
|
|
|
62
62
|
"release": "semantic-release"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
|
-
"@ai-ecoverse/slicc-browsers": "1.7.
|
|
65
|
+
"@ai-ecoverse/slicc-browsers": "1.7.6",
|
|
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
|
}
|