@ai-ecoverse/slicc-shared-web 1.23.3 → 1.24.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/README.md CHANGED
@@ -144,7 +144,7 @@ The diff-coverage hook, `slicc-unit-cover`, runs only the unit tests that cover
144
144
  - **A staged file no unit test reaches:** no tests run, its lines show as uncovered, and diff coverage fails as before.
145
145
  - **A file that won't parse:** one warning line, then every unit test.
146
146
 
147
- The hook passes the list to the repo's own `test:unit` in `SLICC_UNIT_TESTS` (one path per line). A `--require` preload, which `slicc-unit-cover` and the shared `mcr.config.mjs` add to `NODE_OPTIONS`, makes the `node --test` process run the files on that list that its own patterns match, and none when the list is empty. Without the variable, `npm run test:unit` runs everything as before. To force a full run in the hook:
147
+ The hook passes the list to the repo's own `test:unit` in `SLICC_UNIT_TESTS` (one path per line). A selection of more than `SLICC_UNIT_BATCH` files (60 by default) runs in batches of that size, one `test:unit` run each with its own coverage in `coverage/unit/batch-N/` (the shared `mcr.config.mjs` writes to `SLICC_UNIT_COVERAGE_DIR` when it's set), and `slicc-diff-cover` gets every batch's `lcov.info`; diff-cover counts a line covered when any batch covered it. The hook ends with one verdict line over all batches, `slicc-unit-cover: PASS …` or `slicc-unit-cover: FAIL …` (the first failing batch stops the run and fails it; diff coverage then doesn't run). That keeps the coverage merge, which grows with the number of test files, small enough for a memory-capped hook on a widely imported file. A `--require` preload, which `slicc-unit-cover` and the shared `mcr.config.mjs` add to `NODE_OPTIONS`, makes the `node --test` process run the files on that list that its own patterns match, and none when the list is empty. Without the variable, `npm run test:unit` runs everything as before. To force a full run in the hook:
148
148
 
149
149
  ```sh
150
150
  SLICC_UNIT_ALL=1 git commit
@@ -4,4 +4,5 @@ if ! command -v uvx > /dev/null 2>&1; then
4
4
  printf 'slicc-diff-cover runs diff-cover through uvx; install uv first: https://docs.astral.sh/uv/getting-started/installation/\n' >&2
5
5
  exit 1
6
6
  fi
7
- exec uvx diff-cover@10.6.0 "${1:-coverage/unit/lcov.info}" --compare-branch HEAD --ignore-unstaged --fail-under 100
7
+ [ "$#" -gt 0 ] || set -- coverage/unit/lcov.info
8
+ exec uvx diff-cover@10.6.0 "$@" --compare-branch HEAD --ignore-unstaged --fail-under 100
@@ -8,6 +8,10 @@ import { inject } from '../unit/inject.mjs';
8
8
 
9
9
  const root = process.cwd();
10
10
  const say = (line) => process.stderr.write(`slicc-unit-cover: ${line}\n`);
11
+ const verdict = (ok, line) => {
12
+ process.stdout.write(`slicc-unit-cover: ${ok ? 'PASS' : 'FAIL'} ${line}\n`);
13
+ process.exit(ok ? 0 : 1);
14
+ };
11
15
 
12
16
  function git(...args) {
13
17
  const run = spawnSync('git', args, { cwd: root, encoding: 'utf8' });
@@ -45,20 +49,39 @@ const staged = (git('diff', '--cached', '--name-only', '--relative', '--no-renam
45
49
  .filter(Boolean);
46
50
  if (process.env.SLICC_UNIT_ALL !== '1' && !staged.some((file) => code.test(file))) {
47
51
  say('no code staged, skipping unit tests and diff coverage');
48
- process.exit(0);
52
+ verdict(true, 'no code staged');
49
53
  }
50
54
 
51
- const env = { ...process.env };
55
+ const size = Number(process.env.SLICC_UNIT_BATCH ?? 60);
52
56
  const tests = selection(staged);
53
- if (tests === undefined) delete env.SLICC_UNIT_TESTS;
54
- else {
55
- env.SLICC_UNIT_TESTS = tests.join('\n');
56
- env.NODE_OPTIONS = inject(env.NODE_OPTIONS ?? '');
57
+ const batches = [];
58
+ if (tests === undefined || !(size > 0) || tests.length <= size) batches.push(tests);
59
+ else for (let at = 0; at < tests.length; at += size) batches.push(tests.slice(at, at + size));
60
+ const reports = [];
61
+ for (const [index, batch] of batches.entries()) {
62
+ const env = { ...process.env };
63
+ if (batch === undefined) delete env.SLICC_UNIT_TESTS;
64
+ else {
65
+ env.SLICC_UNIT_TESTS = batch.join('\n');
66
+ env.NODE_OPTIONS = inject(env.NODE_OPTIONS ?? '');
67
+ }
68
+ if (batches.length > 1) {
69
+ env.SLICC_UNIT_COVERAGE_DIR = join('coverage', 'unit', `batch-${index + 1}`);
70
+ reports.push(join(env.SLICC_UNIT_COVERAGE_DIR, 'lcov.info'));
71
+ say(`batch ${index + 1} of ${batches.length}: ${batch.length} files`);
72
+ }
73
+ const status = run('npm', ['run', '--silent', 'test:unit'], env);
74
+ if (status !== 0) {
75
+ const which = batches.length > 1 ? `batch ${index + 1} of ${batches.length}` : 'the unit tests';
76
+ verdict(false, `${which} failed (status ${status})`);
77
+ }
57
78
  }
58
- const status = run('npm', ['run', '--silent', 'test:unit'], env);
59
- if (status !== 0) process.exit(status);
60
79
  const local = join(root, 'node_modules', '.bin', 'slicc-diff-cover');
61
80
  const cover = existsSync(local)
62
81
  ? local
63
82
  : fileURLToPath(new URL('slicc-diff-cover.sh', import.meta.url));
64
- process.exit(run(cover, [], process.env));
83
+ const files = tests === undefined ? 'every unit test file' : `${tests.length} unit test files`;
84
+ const counted = `${batches.length} ${batches.length === 1 ? 'batch' : 'batches'}`;
85
+ const covered = run(cover, reports, process.env);
86
+ if (covered !== 0) verdict(false, `diff coverage is not 100% (${files} in ${counted})`);
87
+ verdict(true, `${files} in ${counted}, diff coverage 100%`);
package/mcr.config.mjs CHANGED
@@ -12,7 +12,7 @@ const ours = (url) =>
12
12
 
13
13
  export default {
14
14
  name: process.env.npm_package_name ?? 'unit',
15
- outputDir: 'coverage/unit',
15
+ outputDir: process.env.SLICC_UNIT_COVERAGE_DIR ?? 'coverage/unit',
16
16
  reports: ['lcovonly', 'console-details'],
17
17
  all: { dir: 'src', filter: '**/*.{js,mjs,ts}', transformer: strip },
18
18
  entryFilter: (entry) => ours(entry.url),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-ecoverse/slicc-shared-web",
3
- "version": "1.23.3",
3
+ "version": "1.24.0",
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.6",
65
+ "@ai-ecoverse/slicc-browsers": "1.8.4",
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.2",
69
+ "pnpm": "12.12.0",
70
70
  "semantic-release": "25.0.9"
71
71
  },
72
72
  "peerDependencies": {