@ai-ecoverse/slicc-shared-web 2.7.5 → 2.7.7
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 +19 -5
- package/package.json +2 -2
- package/unit/merge.mjs +160 -0
package/README.md
CHANGED
|
@@ -69,7 +69,7 @@ The caller cancels superseded runs on pull requests only, so a push to `main` ne
|
|
|
69
69
|
|
|
70
70
|
**Deploy** runs on pull requests only, never in the merge queue, with `id-token: write` for an OIDC-authenticated deploy. The merge queue's tests therefore run without `STAGING_URL`: a test that needs it skips when it's empty. It runs the `deploy` command with every secret the caller passes as an environment variable, except the pipeline's own `AWS_BEARER_TOKEN_BEDROCK`, `SLICC_ISSUES_TOKEN` and `github_token`. The command writes `url=<staging URL>` to `$GITHUB_OUTPUT`; the tests and the reviewers get it as `STAGING_URL`. With `deploy-secrets`, a newline- or space-separated list of secret names, only those of them are exported.
|
|
71
71
|
|
|
72
|
-
**Integration tests** install Chrome for Testing with `slicc-cdp install-browser` (with `--with-deps` where the runner has root or passwordless sudo) (`--version` from the `chrome` input, stable without it), then each runs its share of the files matching `test-glob`. `lint` plans the split once for all `shards`, so the shards can't disagree: it takes the JUnit reports of the latest completed merge queue run of the same workflow (else the latest completed pull request run), and hands each file to the shard with the least time so far, longest first; a file without a timing counts as the average, and without any timings every file counts the same. Each shard runs the repo's own `test` command unchanged: `harness/shard.cjs`, preloaded through `NODE_OPTIONS`, makes the outermost `node --test` run only the shard's files that its own patterns match, writes `junit/<shard>.xml` next to the usual spec output, and then takes itself out of the environment, so a `node --test` that a test starts runs as it would without it. Files a `node --test` call would run that are not in `test-glob` (unit tests, say, whether in the same call or another) run on shard 0 only, so nothing is dropped; when `test-glob` matches nothing, shard 0 runs the command unchanged and the others run nothing. Each call keeps its own JUnit report (`junit/<shard>-<pid>.xml` for all but the last). Each shard uploads `coverage/`, `artifacts/` and `junit/` as `integration-<shard>`. `integration` passes only when every shard did and their JUnit reports add up to at least one test that ran, not skipped, and no failure or error (the placeholder an empty shard runs doesn't count), and every file matching `test-glob` was handed to `node --test` on exactly one shard (`shard.cjs` lists the files it hands over next to its JUnit report, as `junit/<shard>-<pid>.files`, since a test registered through a helper is attributed to the helper); a file that ran on no shard or on two is named as an error, and it prints `integration: PASS <n> tests (<k> skipped) in <m> JUnit reports` or `integration: FAIL <why>`; a repo without node tests sets `require-tests: false`. Setting `NODE_OPTIONS` in `test` would replace the pipeline's own, which carry the shard preload and the JUnit reporter, so extra node flags (a bigger heap, say) go in `node-options`. `integration` is therefore the one check to require for the tests, under the caller's job name (`ci / integration`). A suite whose last step reads every test's artifacts, as this repo's `verify.mjs` does, sets `shards: 1`.
|
|
72
|
+
**Integration tests** install Chrome for Testing with `slicc-cdp install-browser` (with `--with-deps` where the runner has root or passwordless sudo) (`--version` from the `chrome` input, stable without it), then each runs its share of the files matching `test-glob`. `lint` plans the split once for all `shards`, so the shards can't disagree: it takes the JUnit reports of the latest completed merge queue run of the same workflow (else the latest completed pull request run), and hands each file to the shard with the least time so far, longest first; a file without a timing counts as the average, and without any timings every file counts the same. Each shard runs the repo's own `test` command unchanged: `harness/shard.cjs`, preloaded through `NODE_OPTIONS`, makes the outermost `node --test` run only the shard's files that its own patterns match, writes `junit/<shard>.xml` next to the usual spec output, and then takes itself out of the environment, so a `node --test` that a test starts runs as it would without it. Files a `node --test` call would run that are not in `test-glob` (unit tests, say, whether in the same call or another) run on shard 0 only, so nothing is dropped; when `test-glob` matches nothing, shard 0 runs the command unchanged and the others run nothing. Each call keeps its own JUnit report (`junit/<shard>-<pid>.xml` for all but the last). Each shard uploads `coverage/`, `artifacts/` and `junit/` as `integration-<shard>`. `integration` passes only when every shard did and their JUnit reports add up to at least one test that ran, not skipped, and no failure or error (the placeholder an empty shard runs doesn't count), and every file matching `test-glob` was handed to `node --test` on exactly one shard (`shard.cjs` lists the files it hands over next to its JUnit report, as `junit/<shard>-<pid>.files`, since a test registered through a helper is attributed to the helper); a file that ran on no shard or on two is named as an error, and it prints `integration: PASS <n> tests (<k> skipped) in <m> JUnit reports, <f> of <f> test-glob files on exactly one shard` or `integration: FAIL <why>`; a repo without node tests sets `require-tests: false`. Setting `NODE_OPTIONS` in `test` would replace the pipeline's own, which carry the shard preload and the JUnit reporter, so extra node flags (a bigger heap, say) go in `node-options`. `integration` is therefore the one check to require for the tests, under the caller's job name (`ci / integration`). A suite whose last step reads every test's artifacts, as this repo's `verify.mjs` does, sets `shards: 1`.
|
|
73
73
|
|
|
74
74
|
**Reviewer** runs twice, once with [claude-code-action](https://github.com/anthropics/claude-code-action) and once with [codex-action](https://github.com/openai/codex-action), on the same prompt, whether the tests passed or not. Both run on Amazon Bedrock with the org secret `AWS_BEARER_TOKEN_BEDROCK`, in the region of the org variable `CERT_AWS_REGION` (`us-west-2` without it). Claude uses the model in `CERT_BEDROCK_MODEL` (`global.anthropic.claude-opus-5-5` without it), as the cert reviews do. Codex uses its built-in `amazon-bedrock-runtime` provider (codex-action waits for its OpenAI proxy's `<run id>.json` in `codex-home` whenever it has a prompt, so the job writes a placeholder one) and the model in `CODEX_BEDROCK_MODEL` (`global.openai.gpt-6.1-sol` without it). Models that Bedrock serves only through inference profiles, as Sol 6.1 is, need the runtime provider and the profile's `global.` id; the `amazon-bedrock` provider's endpoint doesn't list them. The job token can only read. Each reviewer gets:
|
|
75
75
|
|
|
@@ -248,6 +248,7 @@ The diff-coverage hook, `slicc-unit-cover`, runs only the unit tests that cover
|
|
|
248
248
|
|
|
249
249
|
- **Which directories are source:** `src/` by default, anywhere in the path, as before. A repo whose code lives elsewhere lists its directories in `package.json`: `"slicc": { "unitSources": ["extension", "six", "scripts"] }`, repo-relative, without `.` or `..` segments. `mcr.config.mjs` then collects coverage only from those directories, and the hook treats a staged file outside them as no code. A malformed list fails the hook.
|
|
250
250
|
- **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.
|
|
251
|
+
- **Committing a merge, cherry-pick or rebase:** while `MERGE_HEAD` or `CHERRY_PICK_HEAD` exists, or a rebase is running and has stopped at `REBASE_HEAD`, only lines that are new against `HEAD` and against each of those commits count: conflict resolutions and edits made during the merge, not what the other side brought, which was covered where it was written. Diff coverage checks only those lines; the tests that run and the missing-lcov check follow the files that hold them, and files the merge itself deleted lines from, renamed, added empty or changed the mode of. A merge with no changes of its own is no code staged. A revert counts as usual.
|
|
251
252
|
- **A unit test for code this tree doesn't have:** a test whose imports reach a staged file but also a code module under the sources that doesn't exist, isn't gitignored 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. A missing `new URL(…, import.meta.url)` target, a missing non-code file such as `.wasm` or `.json`, and a missing file outside the sources or gitignored (a build output such as `dist/` or a bundled worker) don't skip the test.
|
|
252
253
|
- **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, or amaro's transform where stripping isn't enough. 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/`.
|
|
253
254
|
- **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.
|
package/bin/slicc-unit-cover.mjs
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { spawn, spawnSync } from 'node:child_process';
|
|
3
|
-
import { existsSync, mkdtempSync, readFileSync, rmSync } from 'node:fs';
|
|
3
|
+
import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
4
4
|
import { tmpdir } from 'node:os';
|
|
5
5
|
import { join } from 'node:path';
|
|
6
6
|
import { fileURLToPath } from 'node:url';
|
|
7
7
|
import { code, ParseError, select } from '../unit/graph.mjs';
|
|
8
8
|
import { inject } from '../unit/inject.mjs';
|
|
9
|
+
import { merged } from '../unit/merge.mjs';
|
|
9
10
|
import { inSources } from '../unit/sources.mjs';
|
|
10
11
|
|
|
11
12
|
const root = process.cwd();
|
|
@@ -75,9 +76,12 @@ function selection(staged) {
|
|
|
75
76
|
}
|
|
76
77
|
}
|
|
77
78
|
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
79
|
+
const merge = merged(root);
|
|
80
|
+
const staged =
|
|
81
|
+
merge?.files ??
|
|
82
|
+
(git('diff', '--cached', '--name-only', '--relative', '--no-renames', '-z') ?? '')
|
|
83
|
+
.split('\0')
|
|
84
|
+
.filter(Boolean);
|
|
81
85
|
if (
|
|
82
86
|
process.env.SLICC_UNIT_ALL !== '1' &&
|
|
83
87
|
!staged.some((file) => code.test(file) && inSources(file, root))
|
|
@@ -163,6 +167,16 @@ const lcov = (reports.length > 0 ? reports : [join('coverage', 'unit', 'lcov.inf
|
|
|
163
167
|
const seen = new Set(lcov.match(/^SF:.*$/gm)?.map((line) => line.slice(3)) ?? []);
|
|
164
168
|
const missing = measured.filter((file) => !seen.has(file));
|
|
165
169
|
if (missing.length > 0) verdict(false, `no coverage was collected for ${missing.join(' ')}`);
|
|
166
|
-
|
|
170
|
+
let args = reports;
|
|
171
|
+
if (merge !== undefined) {
|
|
172
|
+
const diff = join(scratch, 'diff');
|
|
173
|
+
writeFileSync(diff, merge.diff);
|
|
174
|
+
args = [
|
|
175
|
+
...(reports.length > 0 ? reports : [join('coverage', 'unit', 'lcov.info')]),
|
|
176
|
+
'--diff-file',
|
|
177
|
+
diff,
|
|
178
|
+
];
|
|
179
|
+
}
|
|
180
|
+
const covered = run(cover, args, process.env);
|
|
167
181
|
if (covered !== 0) verdict(false, `diff coverage is not 100% (${files} in ${counted})`);
|
|
168
182
|
verdict(true, `${files} in ${counted}, diff coverage 100%`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-ecoverse/slicc-shared-web",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.7",
|
|
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",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"release": "semantic-release"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
|
-
"@ai-ecoverse/slicc-browsers": "1.
|
|
69
|
+
"@ai-ecoverse/slicc-browsers": "1.17.0",
|
|
70
70
|
"@ai-ecoverse/slicc-cdp": "1.30.23",
|
|
71
71
|
"@biomejs/biome": "2.5.15",
|
|
72
72
|
"lefthook": "2.2.2",
|
package/unit/merge.mjs
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { spawnSync } from 'node:child_process';
|
|
2
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
3
|
+
import { resolve } from 'node:path';
|
|
4
|
+
|
|
5
|
+
const diff = [
|
|
6
|
+
'-c',
|
|
7
|
+
'diff.mnemonicprefix=no',
|
|
8
|
+
'-c',
|
|
9
|
+
'diff.noprefix=no',
|
|
10
|
+
'-c',
|
|
11
|
+
'diff.srcPrefix=a/',
|
|
12
|
+
'-c',
|
|
13
|
+
'diff.dstPrefix=b/',
|
|
14
|
+
'diff',
|
|
15
|
+
'--cached',
|
|
16
|
+
'--no-color',
|
|
17
|
+
'--no-ext-diff',
|
|
18
|
+
'--no-relative',
|
|
19
|
+
'-U0',
|
|
20
|
+
];
|
|
21
|
+
const escapes = { a: 7, b: 8, f: 12, n: 10, r: 13, t: 9, v: 11 };
|
|
22
|
+
const hunk = /^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@/;
|
|
23
|
+
|
|
24
|
+
function git(root, args) {
|
|
25
|
+
const run = spawnSync('git', args, { cwd: root, encoding: 'utf8', maxBuffer: 2 ** 30 });
|
|
26
|
+
return run.status === 0 ? run.stdout : undefined;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function unquote(text) {
|
|
30
|
+
if (!text.startsWith('"')) return text;
|
|
31
|
+
const bytes = [];
|
|
32
|
+
for (let at = 1; at < text.length - 1; at++) {
|
|
33
|
+
if (text[at] !== '\\') {
|
|
34
|
+
bytes.push(text.charCodeAt(at));
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
const next = text[++at];
|
|
38
|
+
if (/[0-7]/.test(next)) {
|
|
39
|
+
bytes.push(Number.parseInt(text.slice(at, at + 3), 8));
|
|
40
|
+
at += 2;
|
|
41
|
+
} else bytes.push(escapes[next] ?? next.charCodeAt(0));
|
|
42
|
+
}
|
|
43
|
+
return Buffer.from(bytes).toString('utf8');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function named(header) {
|
|
47
|
+
const rest = header.slice('diff --git '.length);
|
|
48
|
+
const half = (rest.length - 1) / 2;
|
|
49
|
+
if (rest[half] !== ' ') return undefined;
|
|
50
|
+
const from = unquote(rest.slice(0, half)).slice(2);
|
|
51
|
+
return from === unquote(rest.slice(half + 1)).slice(2) ? from : undefined;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function mark(file, found) {
|
|
55
|
+
file.hunks = true;
|
|
56
|
+
const start = Number(found[1]);
|
|
57
|
+
const count = found[2] === undefined ? 1 : Number(found[2]);
|
|
58
|
+
for (let at = start; at < start + count; at++) file.marks.add(`+${at}`);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const meta = /^(new file mode|deleted file mode|new mode|rename from|rename to) /;
|
|
62
|
+
|
|
63
|
+
function describe(files, file, line) {
|
|
64
|
+
file.marks.add(`=${line}`);
|
|
65
|
+
const moved = /^rename (from|to) (.*)$/.exec(line);
|
|
66
|
+
if (moved === null) return;
|
|
67
|
+
file.paths.push(unquote(moved[2]));
|
|
68
|
+
if (moved[1] === 'to') files.set(file.paths.at(-1), file);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function marks(text) {
|
|
72
|
+
const files = new Map();
|
|
73
|
+
let file;
|
|
74
|
+
for (const line of text.split('\n')) {
|
|
75
|
+
if (line.startsWith('diff --git ')) {
|
|
76
|
+
const path = named(line);
|
|
77
|
+
file = {
|
|
78
|
+
header: line,
|
|
79
|
+
paths: path === undefined ? [] : [path],
|
|
80
|
+
marks: new Set(),
|
|
81
|
+
hunks: false,
|
|
82
|
+
};
|
|
83
|
+
if (path !== undefined) files.set(path, file);
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (!file) continue;
|
|
87
|
+
const found = hunk.exec(line);
|
|
88
|
+
if (found) mark(file, found);
|
|
89
|
+
else if (file.hunks && line.startsWith('-')) file.marks.add(line);
|
|
90
|
+
else if (!file.hunks && meta.test(line)) describe(files, file, line);
|
|
91
|
+
}
|
|
92
|
+
return files;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function where(root, name) {
|
|
96
|
+
const found = git(root, ['rev-parse', '--git-path', name]);
|
|
97
|
+
return found === undefined ? undefined : resolve(root, found.trim());
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const present = (file) => file !== undefined && existsSync(file);
|
|
101
|
+
|
|
102
|
+
export function parents(root) {
|
|
103
|
+
const head = where(root, 'MERGE_HEAD');
|
|
104
|
+
const merging = present(head) ? readFileSync(head, 'utf8').split('\n').filter(Boolean) : [];
|
|
105
|
+
const rebasing = ['rebase-merge', 'rebase-apply'].some((dir) => present(where(root, dir)));
|
|
106
|
+
const picked = (rebasing ? ['CHERRY_PICK_HEAD', 'REBASE_HEAD'] : ['CHERRY_PICK_HEAD'])
|
|
107
|
+
.map((ref) => git(root, ['rev-parse', '-q', '--verify', `${ref}^{commit}`])?.trim())
|
|
108
|
+
.filter(Boolean);
|
|
109
|
+
return [...merging, ...picked];
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function renames(text) {
|
|
113
|
+
const moved = new Map();
|
|
114
|
+
const parts = text.split('\0');
|
|
115
|
+
for (let at = 0; at < parts.length; at += 2) {
|
|
116
|
+
if (!parts[at].startsWith('R')) continue;
|
|
117
|
+
moved.set(parts[at + 1], parts[at + 2]);
|
|
118
|
+
at += 1;
|
|
119
|
+
}
|
|
120
|
+
return moved;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function merged(root = process.cwd()) {
|
|
124
|
+
const others = parents(root);
|
|
125
|
+
if (others.length === 0) return undefined;
|
|
126
|
+
const views = ['HEAD', ...others].map((parent) => git(root, [...diff, parent]));
|
|
127
|
+
const moves = others.map((parent) =>
|
|
128
|
+
git(root, [
|
|
129
|
+
'diff',
|
|
130
|
+
'--no-ext-diff',
|
|
131
|
+
'--no-relative',
|
|
132
|
+
'-M',
|
|
133
|
+
'--name-status',
|
|
134
|
+
'-z',
|
|
135
|
+
'HEAD',
|
|
136
|
+
parent,
|
|
137
|
+
])
|
|
138
|
+
);
|
|
139
|
+
if ([...views, ...moves].includes(undefined)) return undefined;
|
|
140
|
+
const [base, ...rest] = views.map(marks);
|
|
141
|
+
const moved = moves.map(renames);
|
|
142
|
+
const prefix = git(root, ['rev-parse', '--show-prefix'])?.trim() ?? '';
|
|
143
|
+
const files = new Set();
|
|
144
|
+
let text = '';
|
|
145
|
+
for (const [name, file] of base) {
|
|
146
|
+
const matches = rest.map((other, at) => other.get(name) ?? other.get(moved[at].get(name)));
|
|
147
|
+
const kept = [...file.marks].filter((entry) =>
|
|
148
|
+
matches.every(
|
|
149
|
+
(other) => other !== undefined && (entry.startsWith('=') || other.marks.has(entry))
|
|
150
|
+
)
|
|
151
|
+
);
|
|
152
|
+
if (kept.length === 0) continue;
|
|
153
|
+
for (const each of [file, ...matches].flatMap((one) => one.paths))
|
|
154
|
+
if (each.startsWith(prefix)) files.add(each.slice(prefix.length));
|
|
155
|
+
const lines = kept.filter((entry) => entry.startsWith('+')).map((entry) => entry.slice(1));
|
|
156
|
+
if (lines.length > 0)
|
|
157
|
+
text += `${file.header}\n${lines.map((at) => `@@ -0,0 +${at} @@\n+\n`).join('')}`;
|
|
158
|
+
}
|
|
159
|
+
return { files: [...files], diff: text };
|
|
160
|
+
}
|