@ai-ecoverse/slicc-shared-web 1.29.15 → 1.30.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 +2 -1
- package/bin/slicc-unit-cover.mjs +2 -2
- package/package.json +4 -2
- package/testing/index.mjs +26 -0
package/README.md
CHANGED
|
@@ -13,6 +13,7 @@ Configuration shared by SLICC's web repos ([slicc-bios](https://github.com/ai-ec
|
|
|
13
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). `slicc-install-hooks` installs the hooks into [this worktree's own directory](#one-hooks-directory-per-worktree), and on Windows does nothing and exits 0, so `npm ci` works there | `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
|
+
| `testing/` | Git fixtures that pass the AI git wrapper: `initFixtureRepo(dir, { hooks })` inits a throwaway repo with its own identity, no signing and no template hooks (`hooks: false` sets `core.hooksPath` to `/dev/null`), and `commitAll(dir, message)` stages with `git add -A -- :/` and commits without `--no-verify`, both ignoring global and system git config, so a global `core.hooksPath` never runs in the fixture. Use them instead of `git add -A`, `git add .` or `--no-verify` in a test, which the wrapper refuses when an AI tool runs the suite | `import { commitAll, initFixtureRepo } from '@ai-ecoverse/slicc-shared-web/testing'` |
|
|
16
17
|
|
|
17
18
|
Install it from npm, and pin the reusable workflow to the matching `vX.Y.Z` tag. Renovate keeps both current without the usual waiting period:
|
|
18
19
|
|
|
@@ -237,7 +238,7 @@ The diff-coverage hook, `slicc-unit-cover`, runs only the unit tests that cover
|
|
|
237
238
|
- **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
239
|
- **A file that won't parse:** one warning line, then every unit test.
|
|
239
240
|
|
|
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. 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:
|
|
241
|
+
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 up to 2147483647 (the longest `setTimeout` delay) 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:
|
|
241
242
|
|
|
242
243
|
```sh
|
|
243
244
|
SLICC_UNIT_ALL=1 git commit
|
package/bin/slicc-unit-cover.mjs
CHANGED
|
@@ -95,10 +95,10 @@ if (jsx.length > 0) {
|
|
|
95
95
|
|
|
96
96
|
const ms = (name, fallback) => {
|
|
97
97
|
const value = process.env[name] ?? fallback;
|
|
98
|
-
if (/^\d+$/.test(value)) return Number(value);
|
|
98
|
+
if (/^\d+$/.test(value) && Number(value) <= 2147483647) return Number(value);
|
|
99
99
|
verdict(
|
|
100
100
|
false,
|
|
101
|
-
`${name} must be a whole number of milliseconds, 0 for none, not ${JSON.stringify(value)}`
|
|
101
|
+
`${name} must be a whole number of milliseconds up to 2147483647, 0 for none, not ${JSON.stringify(value)}`
|
|
102
102
|
);
|
|
103
103
|
};
|
|
104
104
|
const timeout = ms('SLICC_UNIT_TIMEOUT', '60000');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-ecoverse/slicc-shared-web",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.30.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",
|
|
@@ -29,7 +29,8 @@
|
|
|
29
29
|
"./mcr.config.mjs": "./mcr.config.mjs",
|
|
30
30
|
"./harness": "./harness/index.mjs",
|
|
31
31
|
"./harness/global": "./harness/global.mjs",
|
|
32
|
-
"./pnpmfile.mjs": "./pnpmfile.mjs"
|
|
32
|
+
"./pnpmfile.mjs": "./pnpmfile.mjs",
|
|
33
|
+
"./testing": "./testing/index.mjs"
|
|
33
34
|
},
|
|
34
35
|
"bin": {
|
|
35
36
|
"slicc-agents-md": "bin/slicc-agents-md.sh",
|
|
@@ -51,6 +52,7 @@
|
|
|
51
52
|
"mcr.config.mjs",
|
|
52
53
|
"tsconfig.json",
|
|
53
54
|
"pnpmfile.mjs",
|
|
55
|
+
"testing",
|
|
54
56
|
"unit"
|
|
55
57
|
],
|
|
56
58
|
"scripts": {
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import { devNull } from 'node:os';
|
|
3
|
+
|
|
4
|
+
function git(dir, ...args) {
|
|
5
|
+
const env = { ...process.env };
|
|
6
|
+
for (const key of Object.keys(env)) if (key.startsWith('GIT_')) delete env[key];
|
|
7
|
+
env.GIT_CONFIG_GLOBAL = devNull;
|
|
8
|
+
env.GIT_CONFIG_NOSYSTEM = '1';
|
|
9
|
+
const run = spawnSync('git', args, { cwd: dir, encoding: 'utf8', env });
|
|
10
|
+
if (run.status !== 0) {
|
|
11
|
+
throw new Error(`git ${args.join(' ')} failed in ${dir}: ${run.error?.message ?? run.stderr}`);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function initFixtureRepo(dir, { hooks = true } = {}) {
|
|
16
|
+
git(dir, 'init', '-q', '--template=');
|
|
17
|
+
git(dir, 'config', 'user.name', 'slicc-fixture');
|
|
18
|
+
git(dir, 'config', 'user.email', 'fixture@slicc.invalid');
|
|
19
|
+
git(dir, 'config', 'commit.gpgsign', 'false');
|
|
20
|
+
if (!hooks) git(dir, 'config', 'core.hooksPath', devNull);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export function commitAll(dir, message) {
|
|
24
|
+
git(dir, 'add', '-A', '--', ':/');
|
|
25
|
+
git(dir, 'commit', '-q', '--allow-empty', '-m', message);
|
|
26
|
+
}
|