@ai-ecoverse/slicc-shared-web 1.30.4 → 1.30.6

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
@@ -230,7 +230,7 @@ The diff-coverage hook, `slicc-unit-cover`, runs only the unit tests that cover
230
230
 
231
231
  - **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.
232
232
  - **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.
233
- - **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 where the merge itself deleted lines. A merge with no changes of its own is no code staged. A revert counts as usual.
233
+ - **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.
234
234
  - **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.
235
235
  - **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/`.
236
236
  - **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.
@@ -5,4 +5,6 @@ if ! command -v uvx > /dev/null 2>&1; then
5
5
  exit 1
6
6
  fi
7
7
  [ "$#" -gt 0 ] || set -- coverage/unit/lcov.info
8
+ n="${GIT_CONFIG_COUNT:-0}"
9
+ export "GIT_CONFIG_COUNT=$((n + 1))" "GIT_CONFIG_KEY_$n=core.quotePath" "GIT_CONFIG_VALUE_$n=false"
8
10
  exec uvx diff-cover@10.6.0 "$@" --compare-branch HEAD --ignore-unstaged --fail-under 100
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-ecoverse/slicc-shared-web",
3
- "version": "1.30.4",
3
+ "version": "1.30.6",
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/merge.mjs CHANGED
@@ -11,6 +11,8 @@ const diff = [
11
11
  'diff.srcPrefix=a/',
12
12
  '-c',
13
13
  'diff.dstPrefix=b/',
14
+ '-c',
15
+ 'core.quotePath=false',
14
16
  'diff',
15
17
  '--cached',
16
18
  '--no-color',
@@ -43,9 +45,12 @@ export function unquote(text) {
43
45
  return Buffer.from(bytes).toString('utf8');
44
46
  }
45
47
 
46
- function path(side) {
47
- const named = side.replace(/\t$/, '');
48
- return named === '/dev/null' ? undefined : unquote(named).slice(2);
48
+ function named(header) {
49
+ const rest = header.slice('diff --git '.length);
50
+ const half = (rest.length - 1) / 2;
51
+ if (rest[half] !== ' ') return undefined;
52
+ const from = unquote(rest.slice(0, half)).slice(2);
53
+ return from === unquote(rest.slice(half + 1)).slice(2) ? from : undefined;
49
54
  }
50
55
 
51
56
  function mark(file, found) {
@@ -55,23 +60,36 @@ function mark(file, found) {
55
60
  for (let at = start; at < start + count; at++) file.marks.add(`+${at}`);
56
61
  }
57
62
 
63
+ const meta = /^(new file mode|deleted file mode|new mode|rename from|rename to) /;
64
+
65
+ function describe(files, file, line) {
66
+ file.marks.add(`=${line}`);
67
+ const moved = /^rename (from|to) (.*)$/.exec(line);
68
+ if (moved === null) return;
69
+ file.paths.push(unquote(moved[2]));
70
+ if (moved[1] === 'to') files.set(file.paths.at(-1), file);
71
+ }
72
+
58
73
  export function marks(text) {
59
74
  const files = new Map();
60
75
  let file;
61
76
  for (const line of text.split('\n')) {
62
77
  if (line.startsWith('diff --git ')) {
63
- file = { header: line, paths: [], marks: new Set(), hunks: false };
78
+ const path = named(line);
79
+ file = {
80
+ header: line,
81
+ paths: path === undefined ? [] : [path],
82
+ marks: new Set(),
83
+ hunks: false,
84
+ };
85
+ if (path !== undefined) files.set(path, file);
64
86
  continue;
65
87
  }
66
88
  if (!file) continue;
67
89
  const found = hunk.exec(line);
68
90
  if (found) mark(file, found);
69
91
  else if (file.hunks && line.startsWith('-')) file.marks.add(line);
70
- else if (!file.hunks && (line.startsWith('--- ') || line.startsWith('+++ '))) {
71
- const named = path(line.slice(4));
72
- if (named !== undefined) file.paths.push(named);
73
- if (line.startsWith('+++ ')) files.set(file.paths.at(-1), file);
74
- }
92
+ else if (!file.hunks && meta.test(line)) describe(files, file, line);
75
93
  }
76
94
  return files;
77
95
  }
@@ -93,21 +111,48 @@ export function parents(root) {
93
111
  return [...merging, ...picked];
94
112
  }
95
113
 
114
+ export function renames(text) {
115
+ const moved = new Map();
116
+ const parts = text.split('\0');
117
+ for (let at = 0; at < parts.length; at += 2) {
118
+ if (!parts[at].startsWith('R')) continue;
119
+ moved.set(parts[at + 1], parts[at + 2]);
120
+ at += 1;
121
+ }
122
+ return moved;
123
+ }
124
+
96
125
  export function merged(root = process.cwd()) {
97
126
  const others = parents(root);
98
127
  if (others.length === 0) return undefined;
99
128
  const views = ['HEAD', ...others].map((parent) => git(root, [...diff, parent]));
100
- if (views.includes(undefined)) return undefined;
129
+ const moves = others.map((parent) =>
130
+ git(root, [
131
+ 'diff',
132
+ '--no-ext-diff',
133
+ '--no-relative',
134
+ '-M',
135
+ '--name-status',
136
+ '-z',
137
+ 'HEAD',
138
+ parent,
139
+ ])
140
+ );
141
+ if ([...views, ...moves].includes(undefined)) return undefined;
101
142
  const [base, ...rest] = views.map(marks);
143
+ const moved = moves.map(renames);
102
144
  const prefix = git(root, ['rev-parse', '--show-prefix'])?.trim() ?? '';
103
145
  const files = new Set();
104
146
  let text = '';
105
147
  for (const [name, file] of base) {
148
+ const matches = rest.map((other, at) => other.get(name) ?? other.get(moved[at].get(name)));
106
149
  const kept = [...file.marks].filter((entry) =>
107
- rest.every((other) => other.get(name)?.marks.has(entry))
150
+ matches.every(
151
+ (other) => other !== undefined && (entry.startsWith('=') || other.marks.has(entry))
152
+ )
108
153
  );
109
154
  if (kept.length === 0) continue;
110
- for (const each of file.paths)
155
+ for (const each of [file, ...matches].flatMap((one) => one.paths))
111
156
  if (each.startsWith(prefix)) files.add(each.slice(prefix.length));
112
157
  const lines = kept.filter((entry) => entry.startsWith('+')).map((entry) => entry.slice(1));
113
158
  if (lines.length > 0)