@ai-ecoverse/slicc-shared-web 1.29.10 → 1.29.11

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
@@ -237,7 +237,7 @@ The diff-coverage hook, `slicc-unit-cover`, runs only the unit tests that cover
237
237
  - **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.
238
238
  - **A file that won't parse:** one warning line, then every unit test.
239
239
 
240
- 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:
240
+ 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. To force a full run in the hook:
241
241
 
242
242
  ```sh
243
243
  SLICC_UNIT_ALL=1 git commit
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import { spawnSync } from 'node:child_process';
3
- import { existsSync, readFileSync } from 'node:fs';
3
+ import { existsSync, mkdtempSync, readFileSync, rmSync } from 'node:fs';
4
+ import { tmpdir } from 'node:os';
4
5
  import { join } from 'node:path';
5
6
  import { fileURLToPath } from 'node:url';
6
7
  import { code, ParseError, select } from '../unit/graph.mjs';
@@ -69,8 +70,19 @@ const batches = [];
69
70
  if (tests === undefined || !(size > 0) || tests.length <= size) batches.push(tests);
70
71
  else for (let at = 0; at < tests.length; at += size) batches.push(tests.slice(at, at + size));
71
72
  const reports = [];
73
+ const scratch = mkdtempSync(join(tmpdir(), 'slicc-unit-cover-'));
74
+ const report = join(scratch, 'report');
75
+ process.on('exit', () => rmSync(scratch, { recursive: true, force: true }));
76
+ const why = () => {
77
+ const lines = existsSync(report) ? readFileSync(report, 'utf8').trim().split('\n') : [];
78
+ return lines.length > 0 ? `: ${lines.join('; ')}` : '';
79
+ };
72
80
  for (const [index, batch] of batches.entries()) {
73
- const env = { ...process.env };
81
+ const env = {
82
+ ...process.env,
83
+ SLICC_UNIT_TIMEOUT: process.env.SLICC_UNIT_TIMEOUT ?? '60000',
84
+ SLICC_UNIT_REPORT: report,
85
+ };
74
86
  if (batch === undefined) delete env.SLICC_UNIT_TESTS;
75
87
  else {
76
88
  env.SLICC_UNIT_TESTS = batch.join('\n');
@@ -84,7 +96,7 @@ for (const [index, batch] of batches.entries()) {
84
96
  const status = run('npm', ['run', '--silent', 'test:unit'], env);
85
97
  if (status !== 0) {
86
98
  const which = batches.length > 1 ? `batch ${index + 1} of ${batches.length}` : 'the unit tests';
87
- verdict(false, `${which} failed (status ${status})`);
99
+ verdict(false, `${which} failed (status ${status})${why()}`);
88
100
  }
89
101
  }
90
102
  const local = join(root, 'node_modules', '.bin', 'slicc-diff-cover');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-ecoverse/slicc-shared-web",
3
- "version": "1.29.10",
3
+ "version": "1.29.11",
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/guard.cjs ADDED
@@ -0,0 +1,60 @@
1
+ 'use strict';
2
+ const { appendFileSync } = require('node:fs');
3
+ const { relative } = require('node:path');
4
+
5
+ const report = process.env.SLICC_UNIT_REPORT;
6
+ const runner = 'SLICC_UNIT_RUNNER';
7
+ const ms = Number(process.env.SLICC_UNIT_TIMEOUT);
8
+ const stall = ms + 5000;
9
+
10
+ const watchdog = `const { appendFileSync } = require('node:fs');
11
+ const { workerData: { beat, stall, report, line } } = require('node:worker_threads');
12
+ let last = Atomics.load(beat, 0);
13
+ while (Atomics.wait(beat, 0, last, stall) !== 'timed-out') last = Atomics.load(beat, 0);
14
+ appendFileSync(report, line);
15
+ process.kill(process.pid, 'SIGKILL');`;
16
+
17
+ if (report && process.execArgv.includes('--test') && !process.env.NODE_TEST_CONTEXT) {
18
+ process.env[runner] = String(process.pid);
19
+ if (ms > 0) process.execArgv.push(`--test-timeout=${ms}`);
20
+ } else if (
21
+ report &&
22
+ process.env.NODE_TEST_CONTEXT &&
23
+ require('node:worker_threads').isMainThread &&
24
+ process.ppid === Number(process.env[runner])
25
+ ) {
26
+ const file = relative(process.cwd(), process.argv[1] ?? '');
27
+ const note = (line) => appendFileSync(report, `${file}${line}\n`);
28
+ const beat = new Int32Array(new SharedArrayBuffer(4));
29
+ const alive = () => Atomics.notify(beat, 0, Atomics.add(beat, 0, 1) + 1);
30
+ const { after, afterEach, beforeEach } = require('node:test');
31
+ let running = 0;
32
+ beforeEach(() => {
33
+ running++;
34
+ alive();
35
+ });
36
+ afterEach((t) => {
37
+ running--;
38
+ alive();
39
+ if (t.error?.failureType === 'testTimeoutFailure') note(`: "${t.fullName}" ${t.error.message}`);
40
+ });
41
+ if (ms > 0) {
42
+ const { Worker } = require('node:worker_threads');
43
+ const line = `${file} was killed after ${stall}ms with no test running and nothing finishing, or its event loop blocked\n`;
44
+ new Worker(watchdog, { eval: true, workerData: { beat, stall, report, line } }).unref();
45
+ setInterval(() => running > 0 && alive(), 1000).unref();
46
+ after(() => {
47
+ alive();
48
+ setTimeout(() => {
49
+ let stdio = 3;
50
+ const open = process
51
+ .getActiveResourcesInfo()
52
+ .filter((name) => !(/^(Pipe|TTY)Wrap$/.test(name) && stdio-- > 0));
53
+ note(
54
+ ` was still running ${ms}ms after its tests ended, open handles kept it alive (${open.join(', ')})`
55
+ );
56
+ process.exit(1);
57
+ }, ms).unref();
58
+ });
59
+ }
60
+ }
package/unit/select.cjs CHANGED
@@ -1,4 +1,5 @@
1
1
  'use strict';
2
+ require('./guard.cjs');
2
3
  const { isAbsolute, join, matchesGlob, normalize, relative } = require('node:path');
3
4
 
4
5
  const key = Symbol.for('slicc.unit.select');