@ai-ecoverse/slicc-shared-web 2.4.3 → 2.4.4

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
@@ -248,7 +248,7 @@ The diff-coverage hook, `slicc-unit-cover`, runs only the unit tests that cover
248
248
  - **A staged source file missing from the lcov:** the hook fails and names it, so no file passes diff coverage just because nothing measured it. `.jsx` and `.tsx` files are not transformed for coverage, so staging one under the sources fails the hook too.
249
249
  - **A file that won't parse:** one warning line, then every unit test.
250
250
 
251
- 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. In the hook the same preload bounds each test file's process (with the default `--test-isolation=process`; `none` runs no such processes, so nothing is bounded): every test gets `--test-timeout` (`SLICC_UNIT_TIMEOUT` ms, 60000 by default, `0` turns all of these bounds off), a file still running `SLICC_UNIT_TIMEOUT` ms after its tests ended (its top-level `after()` hooks get that long too) is ended, and a file whose event loop is blocked, or that has no test running and nothing finishing, for `SLICC_UNIT_TIMEOUT` + 5 s (one that hangs at top level, or a `before()` hook running that long) is killed; a test's own longer `timeout` is honoured. The FAIL verdict names each test that timed out and each file that was ended (`… was still running 60000ms after its tests ended, open handles kept it alive (TCPServerWrap)`) or killed, and such a file fails even when its tests passed. Each `test:unit` run also has a wall-clock limit, `SLICC_UNIT_BATCH_TIMEOUT` ms (600000 by default, `0` for none): past it the run's whole process group is killed and the FAIL verdict names the batch and its files, which catches anything the per-file bounds miss, such as a test with an unlimited `timeout` of its own. To force a full run in the hook:
251
+ 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. In the hook the same preload bounds each test file's process (with the default `--test-isolation=process`; `none` runs no such processes, so nothing is bounded): every test gets `--test-timeout` (`SLICC_UNIT_TIMEOUT` ms, 60000 by default, `0` turns all of these bounds off), a file still running `SLICC_UNIT_TIMEOUT` ms after its tests ended (its top-level `after()` hooks get that long too) is ended, and a file whose event loop is blocked, or that has no test running and nothing finishing, for `SLICC_UNIT_TIMEOUT` + 5 s (one that hangs at top level, or a `before()` hook running that long) is killed; a test's own longer `timeout` is honoured. The FAIL verdict names each test that timed out and each file that was ended (`… was still running 60000ms after its tests ended, open handles kept it alive (TCPServerWrap)`) or killed, and such a file fails even when its tests passed. A value of either variable that isn't a whole number of milliseconds fails the hook before any test runs, rather than silently turning its bound off. Each `test:unit` run also has a wall-clock limit, `SLICC_UNIT_BATCH_TIMEOUT` ms (600000 by default, `0` for none): past it the run's whole process group is killed and the FAIL verdict names the batch and its files, which catches anything the per-file bounds miss, such as a test with an unlimited `timeout` of its own. To force a full run in the hook:
252
252
 
253
253
  ```sh
254
254
  SLICC_UNIT_ALL=1 git commit
@@ -93,6 +93,16 @@ if (jsx.length > 0) {
93
93
  verdict(false, `coverage cannot be measured for JSX, which is not transformed: ${jsx.join(' ')}`);
94
94
  }
95
95
 
96
+ const ms = (name, fallback) => {
97
+ const value = process.env[name] ?? fallback;
98
+ if (/^\d+$/.test(value)) return Number(value);
99
+ verdict(
100
+ false,
101
+ `${name} must be a whole number of milliseconds, 0 for none, not ${JSON.stringify(value)}`
102
+ );
103
+ };
104
+ const timeout = ms('SLICC_UNIT_TIMEOUT', '60000');
105
+ const limit = ms('SLICC_UNIT_BATCH_TIMEOUT', '600000');
96
106
  const size = Number(process.env.SLICC_UNIT_BATCH ?? 60);
97
107
  const tests = selection(staged);
98
108
  const batches = [];
@@ -109,7 +119,7 @@ const why = () => {
109
119
  for (const [index, batch] of batches.entries()) {
110
120
  const env = {
111
121
  ...process.env,
112
- SLICC_UNIT_TIMEOUT: process.env.SLICC_UNIT_TIMEOUT ?? '60000',
122
+ SLICC_UNIT_TIMEOUT: String(timeout),
113
123
  SLICC_UNIT_REPORT: report,
114
124
  };
115
125
  if (batch === undefined) delete env.SLICC_UNIT_TESTS;
@@ -122,7 +132,6 @@ for (const [index, batch] of batches.entries()) {
122
132
  reports.push(join(env.SLICC_UNIT_COVERAGE_DIR, 'lcov.info'));
123
133
  say(`batch ${index + 1} of ${batches.length}: ${batch.length} files`);
124
134
  }
125
- const limit = Number(process.env.SLICC_UNIT_BATCH_TIMEOUT ?? 600000);
126
135
  const { status, late } = await bounded('npm', ['run', '--silent', 'test:unit'], env, limit);
127
136
  const which = batches.length > 1 ? `batch ${index + 1} of ${batches.length}` : 'the unit tests';
128
137
  if (late) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-ecoverse/slicc-shared-web",
3
- "version": "2.4.3",
3
+ "version": "2.4.4",
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",