dsh-trajectory-traceview-plus 0.0.0-stage → 0.11.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/CHANGELOG.md +62 -0
- package/LICENSE +21 -0
- package/README.en.md +318 -0
- package/README.md +337 -2
- package/cordis.patch.yml +10 -0
- package/docs/DESIGN.md +7797 -0
- package/docs/PROVENANCE.md +149 -0
- package/lib/client.js +5551 -0
- package/lib/index.js +6 -0
- package/package.json +67 -4
- package/screenshot/overview.png +0 -0
- package/scripts/bench-fold.mjs +141 -0
- package/scripts/browser-check.mjs +75 -0
- package/scripts/browser-harness.mjs +162 -0
- package/scripts/build-client.mjs +96 -0
- package/scripts/doc-heading-check.mjs +66 -0
- package/scripts/doc-ref-check.mjs +94 -0
- package/scripts/provenance.mjs +197 -0
- package/scripts/readme-numbers.mjs +157 -0
- package/scripts/release-status.mjs +92 -0
- package/scripts/version-check.mjs +105 -0
- package/src/00-locale.js +366 -0
- package/src/10-styles.js +321 -0
- package/src/20-fields.js +21 -0
- package/src/30-helpers.js +2627 -0
- package/src/40-view.js +2130 -0
- package/src/50-entry.js +61 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Fail when `docs/DESIGN.md` references a section that does not exist.
|
|
4
|
+
*
|
|
5
|
+
* The document has accumulated ~170 `§x.y` references across a few hundred
|
|
6
|
+
* sessions of work. That is enough for real drift: a renumbered section, or a
|
|
7
|
+
* section deleted because its conclusion was withdrawn, leaves the surrounding
|
|
8
|
+
* prose pointing at nothing — and a reader who follows the pointer finds no
|
|
9
|
+
* explanation where one was promised.
|
|
10
|
+
*
|
|
11
|
+
* Two kinds of reference are treated differently on purpose:
|
|
12
|
+
*
|
|
13
|
+
* - a reference to an existing section → fine
|
|
14
|
+
* - a reference to a missing section, on a line
|
|
15
|
+
* that itself says 已删除 / 被我删掉 → allowed, and COUNTED
|
|
16
|
+
* - any other reference to a missing section → failure
|
|
17
|
+
*
|
|
18
|
+
* The middle case is not a loophole: §13.05 argues against a conclusion that
|
|
19
|
+
* used to live in §13.04, and §13.05 would be unreadable without naming it. What
|
|
20
|
+
* the rule forbids is a pointer to nowhere that does not admit it.
|
|
21
|
+
*
|
|
22
|
+
* node scripts/doc-ref-check.mjs
|
|
23
|
+
*/
|
|
24
|
+
import { readFileSync } from 'node:fs';
|
|
25
|
+
import { dirname, join } from 'node:path';
|
|
26
|
+
import { fileURLToPath } from 'node:url';
|
|
27
|
+
|
|
28
|
+
const ROOT = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
29
|
+
const DOC = join(ROOT, 'docs', 'DESIGN.md');
|
|
30
|
+
const md = readFileSync(DOC, 'utf8');
|
|
31
|
+
|
|
32
|
+
// `\s+`, not `\s*`: a section only counts if the `#` run is followed by a space,
|
|
33
|
+
// which is exactly what Markdown itself requires. With `\s*` this script accepted
|
|
34
|
+
// `###13.25` — a line that renders as plain paragraph text — as a live section, so a
|
|
35
|
+
// `§13.25` pointer would resolve here while leading the reader to nothing on GitHub.
|
|
36
|
+
// doc-heading-check.mjs is the guard that fails on such a line; the two now agree on
|
|
37
|
+
// what a section is instead of disagreeing silently.
|
|
38
|
+
const sections = new Set([...md.matchAll(/^###\s+(\d+\.\d+)/gm)].map((m) => m[1]));
|
|
39
|
+
const lines = md.split('\n');
|
|
40
|
+
|
|
41
|
+
const dangling = [];
|
|
42
|
+
let markedDeleted = 0;
|
|
43
|
+
lines.forEach((line, i) => {
|
|
44
|
+
const refs = [...line.matchAll(/§\s*(\d+\.\d+)/g)].map((m) => m[1]);
|
|
45
|
+
if (refs.length === 0) return;
|
|
46
|
+
// The admission has to be on the same line as the reference: a paragraph-long
|
|
47
|
+
// caveat elsewhere in the section would otherwise excuse every pointer in it.
|
|
48
|
+
const admitsDeletion = /已删除|被我删掉/.test(line);
|
|
49
|
+
for (const ref of refs) {
|
|
50
|
+
if (sections.has(ref)) continue;
|
|
51
|
+
if (admitsDeletion) { markedDeleted += 1; continue; }
|
|
52
|
+
dangling.push('line ' + (i + 1) + ': §' + ref + ' — ' + line.trim().slice(0, 80));
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
console.log('doc-ref-check: ' + sections.size + ' sections, ' + markedDeleted + ' reference(s) to withdrawn sections (explicitly marked)');
|
|
57
|
+
|
|
58
|
+
// ── the READMEs point INTO this document too, and nothing was checking that ──
|
|
59
|
+
//
|
|
60
|
+
// Both READMEs cite `docs/DESIGN.md` §x.y ("why hard pin" -> §12.25-§12.27,
|
|
61
|
+
// `readme-numbers` -> §13.37, the engines range -> §13.43). Those pointers were only
|
|
62
|
+
// ever verified by hand, in a throwaway script, twice — the same "one-off check"
|
|
63
|
+
// failure that §13.42 records for the README counts.
|
|
64
|
+
//
|
|
65
|
+
// A README reference gets a stricter rule than a DESIGN one: there is no "marked as
|
|
66
|
+
// deleted" escape hatch, because a README is the first thing a reader opens and a
|
|
67
|
+
// pointer to a section that no longer exists is just broken.
|
|
68
|
+
const readmeProblems = [];
|
|
69
|
+
for (const file of ['README.md', 'README.en.md']) {
|
|
70
|
+
const body = readFileSync(join(ROOT, file), 'utf8');
|
|
71
|
+
body.split('\n').forEach((line, i) => {
|
|
72
|
+
for (const m of line.matchAll(/§\s*(\d+\.\d+)/g)) {
|
|
73
|
+
if (!sections.has(m[1])) readmeProblems.push(file + ':' + (i + 1) + ': §' + m[1] + ' does not exist in docs/DESIGN.md');
|
|
74
|
+
}
|
|
75
|
+
// `§11`-style references point at the README's OWN numbered sections. `§1.2`
|
|
76
|
+
// was handled above, so only bare integers reach here.
|
|
77
|
+
for (const m of line.matchAll(/§\s*(\d+)(?!\.\d)/g)) {
|
|
78
|
+
const own = new Set([...body.matchAll(/^## (\d+)\./gm)].map((x) => x[1]));
|
|
79
|
+
if (!own.has(m[1])) readmeProblems.push(file + ':' + (i + 1) + ': §' + m[1] + ' is not a section of this file');
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (dangling.length > 0) {
|
|
85
|
+
for (const d of dangling) console.error(' ✗ ' + d);
|
|
86
|
+
console.error('doc-ref-check: FAIL (' + dangling.length + ' reference(s) to sections that do not exist)');
|
|
87
|
+
process.exit(1);
|
|
88
|
+
}
|
|
89
|
+
if (readmeProblems.length > 0) {
|
|
90
|
+
for (const p of readmeProblems) console.error(' ✗ ' + p);
|
|
91
|
+
console.error('doc-ref-check: FAIL (' + readmeProblems.length + ' broken README cross-reference(s))');
|
|
92
|
+
process.exit(1);
|
|
93
|
+
}
|
|
94
|
+
console.log('DOC REFS OK');
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Regenerate docs/PROVENANCE.md by diffing this repository against the upstream
|
|
4
|
+
* release it forked from.
|
|
5
|
+
*
|
|
6
|
+
* Why generate instead of hand-write: a hand-maintained split ("these functions are
|
|
7
|
+
* ours") goes stale the first time someone edits a function and forgets the list,
|
|
8
|
+
* and then it silently lies. This script reads the actual bodies from `git show`
|
|
9
|
+
* and the working tree, so the document is reproducible and reviewable:
|
|
10
|
+
*
|
|
11
|
+
* node scripts/provenance.mjs # rewrite docs/PROVENANCE.md
|
|
12
|
+
* node scripts/provenance.mjs --check # exit 1 when the file is stale (CI-able)
|
|
13
|
+
*/
|
|
14
|
+
import { execFileSync } from 'node:child_process';
|
|
15
|
+
import { readFileSync, writeFileSync } from 'node:fs';
|
|
16
|
+
import { dirname, join } from 'node:path';
|
|
17
|
+
import { fileURLToPath } from 'node:url';
|
|
18
|
+
|
|
19
|
+
const ROOT = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
20
|
+
const UPSTREAM_REF = 'v0.3.0';
|
|
21
|
+
const UPSTREAM_REPO = 'AFAP/dsh-trajectory-traceview';
|
|
22
|
+
const OUT = join(ROOT, 'docs', 'PROVENANCE.md');
|
|
23
|
+
|
|
24
|
+
const git = (...args) => execFileSync('git', args, { cwd: ROOT, encoding: 'utf8', maxBuffer: 64 * 1024 * 1024 });
|
|
25
|
+
|
|
26
|
+
/** Function bodies keyed by name; braces are counted so nested blocks stay intact. */
|
|
27
|
+
function functionBodies(src) {
|
|
28
|
+
const out = new Map();
|
|
29
|
+
const re = /^(\t| )*function ([A-Za-z0-9_]+)\s*\(/gm;
|
|
30
|
+
let m;
|
|
31
|
+
while ((m = re.exec(src)) !== null) {
|
|
32
|
+
const name = m[2];
|
|
33
|
+
let i = src.indexOf('{', m.index);
|
|
34
|
+
if (i < 0) continue;
|
|
35
|
+
let depth = 0;
|
|
36
|
+
let end = -1;
|
|
37
|
+
for (; i < src.length; i += 1) {
|
|
38
|
+
const ch = src[i];
|
|
39
|
+
if (ch === '{') depth += 1;
|
|
40
|
+
else if (ch === '}') { depth -= 1; if (depth === 0) { end = i + 1; break; } }
|
|
41
|
+
}
|
|
42
|
+
out.set(name, src.slice(m.index, end));
|
|
43
|
+
}
|
|
44
|
+
return out;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Class methods and top-level declarations that are not plain `function` bodies. */
|
|
48
|
+
function otherSymbols(src) {
|
|
49
|
+
const out = new Map();
|
|
50
|
+
for (const re of [/^(\t| )*class ([A-Za-z0-9_]+)/gm, /^(\t| )*const ([A-Za-z0-9_]+) = \(/gm]) {
|
|
51
|
+
let m;
|
|
52
|
+
while ((m = re.exec(src)) !== null) out.set(m[2], (out.get(m[2]) ?? 0) + 1);
|
|
53
|
+
}
|
|
54
|
+
return out;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const upSrc = git('show', `${UPSTREAM_REF}:lib/client.js`);
|
|
58
|
+
const curSrc = readFileSync(join(ROOT, 'lib', 'client.js'), 'utf8');
|
|
59
|
+
const up = functionBodies(upSrc);
|
|
60
|
+
const cur = functionBodies(curSrc);
|
|
61
|
+
|
|
62
|
+
const untouched = [];
|
|
63
|
+
const modified = [];
|
|
64
|
+
const added = [];
|
|
65
|
+
const dropped = [];
|
|
66
|
+
for (const [name, body] of up) {
|
|
67
|
+
if (!cur.has(name)) dropped.push(name);
|
|
68
|
+
else if (cur.get(name) === body) untouched.push(name);
|
|
69
|
+
else modified.push(name);
|
|
70
|
+
}
|
|
71
|
+
for (const name of cur.keys()) if (!up.has(name)) added.push(name);
|
|
72
|
+
untouched.sort(); modified.sort(); added.sort(); dropped.sort();
|
|
73
|
+
|
|
74
|
+
// File-level map: which upstream files survived byte-for-byte.
|
|
75
|
+
//
|
|
76
|
+
// A renamed upstream file needs its own status. Without it, `git mv a b` reads as
|
|
77
|
+
// "a was deleted" — which is literally true of the *path* but hides the thing the
|
|
78
|
+
// document exists to answer: the content came from upstream and is still here. The
|
|
79
|
+
// rename is detected from git's own similarity matching (`-M`), so a file that was
|
|
80
|
+
// renamed *and* edited shows as a rename rather than being silently filed as new.
|
|
81
|
+
const upstreamFiles = git('ls-tree', '-r', '--name-only', UPSTREAM_REF).trim().split('\n').filter(Boolean);
|
|
82
|
+
|
|
83
|
+
const renamedFrom = new Map(); // old upstream path -> new path
|
|
84
|
+
for (const extra of [[], ['--cached']]) {
|
|
85
|
+
const raw = git('diff', '--name-status', '-M', '--diff-filter=R', ...extra, UPSTREAM_REF).trim();
|
|
86
|
+
if (raw === '') continue;
|
|
87
|
+
for (const line of raw.split('\n')) {
|
|
88
|
+
const [kind, from, to] = line.split('\t');
|
|
89
|
+
if (kind.startsWith('R') && from && to) renamedFrom.set(from, to);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const fileRows = upstreamFiles.map((file) => {
|
|
94
|
+
let status;
|
|
95
|
+
try {
|
|
96
|
+
const now = readFileSync(join(ROOT, file), 'utf8');
|
|
97
|
+
status = now === git('show', `${UPSTREAM_REF}:${file}`) ? '原样保留' : '已修改';
|
|
98
|
+
} catch {
|
|
99
|
+
const to = renamedFrom.get(file);
|
|
100
|
+
let renamedTo = null;
|
|
101
|
+
if (to !== undefined) {
|
|
102
|
+
try { readFileSync(join(ROOT, to)); renamedTo = to; } catch { renamedTo = null; }
|
|
103
|
+
}
|
|
104
|
+
status = renamedTo !== null ? `已改名 → \`${renamedTo}\`` : '已删除';
|
|
105
|
+
}
|
|
106
|
+
return { file, status };
|
|
107
|
+
});
|
|
108
|
+
// Added files come from THREE sources, all measured against the working tree:
|
|
109
|
+
// 1. `git diff --diff-filter=A` — added and staged/committed
|
|
110
|
+
// 2. `git diff --diff-filter=A --cached` — added and staged but not yet committed
|
|
111
|
+
// 3. `git ls-files --others` — created on disk, not yet added at all
|
|
112
|
+
//
|
|
113
|
+
// Source 3 is what makes this trustworthy and it was missing. `provenance` is
|
|
114
|
+
// normally run *before* committing (the docs tell you to regenerate after adding
|
|
115
|
+
// a file), but `git diff` cannot see a file that is not in the index yet. So the
|
|
116
|
+
// regenerated document omitted the new file, and `--check` then failed on the
|
|
117
|
+
// commit the user was about to make — twice in one session, both times in CI
|
|
118
|
+
// after a push, which is the most expensive possible moment to learn about a
|
|
119
|
+
// missing line. Ignored paths are excluded by `--exclude-standard`, so local
|
|
120
|
+
// scratch never leaks in.
|
|
121
|
+
const addedFiles = [...new Set([
|
|
122
|
+
...git('diff', '--name-status', '--diff-filter=A', UPSTREAM_REF).trim().split('\n').filter(Boolean).map((line) => line.split('\t')[1]),
|
|
123
|
+
...git('diff', '--name-status', '--diff-filter=A', '--cached', UPSTREAM_REF).trim().split('\n').filter(Boolean).map((line) => line.split('\t')[1]),
|
|
124
|
+
...git('ls-files', '--others', '--exclude-standard').trim().split('\n').filter(Boolean),
|
|
125
|
+
])]
|
|
126
|
+
.filter((f) => !upstreamFiles.includes(f))
|
|
127
|
+
.concat(['docs/PROVENANCE.md', 'scripts/provenance.mjs'])
|
|
128
|
+
.filter((f, i, all) => all.indexOf(f) === i)
|
|
129
|
+
.sort();
|
|
130
|
+
|
|
131
|
+
const upCommit = git('rev-parse', '--short', UPSTREAM_REF).trim();
|
|
132
|
+
const upDate = git('log', '-1', '--format=%ad', '--date=short', UPSTREAM_REF).trim();
|
|
133
|
+
|
|
134
|
+
const md = `# 来源清单 · Provenance
|
|
135
|
+
|
|
136
|
+
> 本文件由 \`node scripts/provenance.mjs\` **自动生成**,请勿手工编辑。
|
|
137
|
+
> 它回答一个问题:**哪部分是上游的,哪部分是本仓二开的。**
|
|
138
|
+
|
|
139
|
+
基线:\`${UPSTREAM_REF}\`(\`${upCommit}\`,${upDate})来自 [${UPSTREAM_REPO}](https://github.com/${UPSTREAM_REPO}),MIT。
|
|
140
|
+
上游在该提交后未再发布(仓库共 3 个提交)。
|
|
141
|
+
|
|
142
|
+
## 一、文件级
|
|
143
|
+
|
|
144
|
+
上游共 ${upstreamFiles.length} 个文件,其中 ${fileRows.filter((r) => r.status === '原样保留').length} 个一字未改:
|
|
145
|
+
|
|
146
|
+
| 文件 | 状态 |
|
|
147
|
+
| --- | --- |
|
|
148
|
+
${fileRows.map((r) => `| \`${r.file}\` | ${r.status} |`).join('\n')}
|
|
149
|
+
|
|
150
|
+
本仓新增的文件:
|
|
151
|
+
|
|
152
|
+
${addedFiles.map((f) => `- \`${f}\``).join('\n')}
|
|
153
|
+
|
|
154
|
+
## 二、\`lib/client.js\` 函数级
|
|
155
|
+
|
|
156
|
+
上游 ${up.size} 个函数:**${untouched.length} 个原样保留、${modified.length} 个被修改、${dropped.length} 个被删除**;本仓**新增 ${added.length} 个**。
|
|
157
|
+
|
|
158
|
+
### 原样保留(${untouched.length})
|
|
159
|
+
|
|
160
|
+
未做任何改动,可与上游逐字对照:
|
|
161
|
+
|
|
162
|
+
${untouched.map((n) => `- \`${n}\``).join('\n')}
|
|
163
|
+
|
|
164
|
+
### 已修改(${modified.length})
|
|
165
|
+
|
|
166
|
+
**这些是二开最容易与前人意图冲突的地方**——功能骨架来自上游,但行为已被改变。每处都应在 \`docs/DESIGN.md\` 里找得到"为什么改"的记录:
|
|
167
|
+
|
|
168
|
+
${modified.map((n) => `- \`${n}\``).join('\n')}
|
|
169
|
+
|
|
170
|
+
### 本仓新增(${added.length})
|
|
171
|
+
|
|
172
|
+
上游完全没有:
|
|
173
|
+
|
|
174
|
+
${added.map((n) => `- \`${n}\``).join('\n')}
|
|
175
|
+
|
|
176
|
+
${dropped.length > 0 ? `### 上游有、本仓删除(${dropped.length})\n\n${dropped.map((n) => `- \`${n}\``).join('\n')}\n` : ''}
|
|
177
|
+
## 三、怎么用它
|
|
178
|
+
|
|
179
|
+
- \`git diff ${UPSTREAM_REF} -- <file>\` —— 看某个文件相对上游改了什么
|
|
180
|
+
- 本文件 —— 看改动**规模**和**落点**(哪个函数、哪一类)
|
|
181
|
+
- \`docs/DESIGN.md\` —— 看每处改动**为什么**这么做
|
|
182
|
+
- \`node scripts/provenance.mjs --check\` —— 确认本文件没有过期
|
|
183
|
+
`;
|
|
184
|
+
|
|
185
|
+
if (process.argv.includes('--check')) {
|
|
186
|
+
const exists = (() => { try { return readFileSync(OUT, 'utf8'); } catch { return ''; } })();
|
|
187
|
+
if (exists !== md) {
|
|
188
|
+
console.error('docs/PROVENANCE.md 已过期:请运行 node scripts/provenance.mjs');
|
|
189
|
+
process.exit(1);
|
|
190
|
+
}
|
|
191
|
+
console.log('PROVENANCE OK');
|
|
192
|
+
process.exit(0);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
writeFileSync(OUT, md);
|
|
196
|
+
console.log(`wrote ${OUT}`);
|
|
197
|
+
console.log(`上游函数 ${up.size}:原样 ${untouched.length} / 修改 ${modified.length} / 删除 ${dropped.length};新增 ${added.length}`);
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Fail when a count stated in the READMEs disagrees with the thing it counts.
|
|
4
|
+
*
|
|
5
|
+
* Three numbers in the docs are derived, not invented, and every one of them has
|
|
6
|
+
* drifted at least once:
|
|
7
|
+
*
|
|
8
|
+
* - "CI 门禁 7 项" ← the number of named steps in check.yml, minus Install
|
|
9
|
+
* - "npm run check 跑 N 步" ← the number of `&&` segments in package.json
|
|
10
|
+
* - "13 组观测 / 47 条断言" ← probe.js: `info.X =` assignments, `fail(` calls
|
|
11
|
+
*
|
|
12
|
+
* Reading the README and comparing it to the workflow by eye already failed twice
|
|
13
|
+
* (the directory tree said "5 项门禁" for weeks after the count became 7). A number
|
|
14
|
+
* that can be computed should never be typed.
|
|
15
|
+
*
|
|
16
|
+
* Every count is derived STATICALLY — no browser, no agent-browser, no network — so
|
|
17
|
+
* this can run as a gate anywhere, including CI.
|
|
18
|
+
*
|
|
19
|
+
* node scripts/readme-numbers.mjs # check
|
|
20
|
+
* node scripts/readme-numbers.mjs --print # show what it thinks the counts are
|
|
21
|
+
*/
|
|
22
|
+
import { readFileSync } from 'node:fs';
|
|
23
|
+
import { dirname, join } from 'node:path';
|
|
24
|
+
import { fileURLToPath } from 'node:url';
|
|
25
|
+
|
|
26
|
+
const ROOT = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
27
|
+
const read = (rel) => readFileSync(join(ROOT, rel), 'utf8');
|
|
28
|
+
|
|
29
|
+
// ── the three truths, each taken from the file that defines it ────────────────
|
|
30
|
+
const wf = read('.github/workflows/check.yml');
|
|
31
|
+
const namedSteps = [...wf.matchAll(/^\s+- name: (.+)$/gm)].map((m) => m[1]);
|
|
32
|
+
const ciGates = namedSteps.filter((n) => n !== 'Install').length;
|
|
33
|
+
|
|
34
|
+
const pkg = JSON.parse(read('package.json'));
|
|
35
|
+
const localSteps = pkg.scripts.check.split('&&').map((s) => s.trim()).filter(Boolean).length;
|
|
36
|
+
|
|
37
|
+
const probe = read('test/browser/probe.js');
|
|
38
|
+
const observedGroups = new Set([...probe.matchAll(/info\.([a-zA-Z]\w*)\s*=/g)].map((m) => m[1]));
|
|
39
|
+
const assertions = [...probe.matchAll(/\bfail\(/g)].length;
|
|
40
|
+
|
|
41
|
+
const truth = { ciGates, localSteps, groups: observedGroups.size, assertions };
|
|
42
|
+
|
|
43
|
+
if (process.argv.includes('--print')) {
|
|
44
|
+
console.log('CI 门禁 ' + ciGates + ' 项(workflow 具名步骤 ' + namedSteps.length + ' − Install)');
|
|
45
|
+
console.log('npm run check ' + localSteps + ' 步');
|
|
46
|
+
console.log('probe.js 观测组 ' + truth.groups + ' 个 / 断言 ' + assertions + ' 条');
|
|
47
|
+
process.exit(0);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// ── what each README claims, matched by the sentence it appears in ────────────
|
|
51
|
+
//
|
|
52
|
+
// The line's CONTEXT decides which number it is, not the number's suffix. The first
|
|
53
|
+
// version of this audit classified "门禁本身是 7 项" as a browser-check count because
|
|
54
|
+
// it looked for `N 项` — the audit was wrong, not the document. Anchoring on the
|
|
55
|
+
// sentence is what made it correct.
|
|
56
|
+
const problems = [];
|
|
57
|
+
const counted = { ciGates: 0, localSteps: 0, groups: 0, assertions: 0 };
|
|
58
|
+
|
|
59
|
+
const claim = (file, lineNo, kind, found, want) => {
|
|
60
|
+
counted[kind] += 1;
|
|
61
|
+
if (found !== want) {
|
|
62
|
+
problems.push(file + ':' + lineNo + ' — ' + kind + ' says ' + found + ', actual ' + want);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
for (const file of ['README.md', 'README.en.md']) {
|
|
67
|
+
read(file).split('\n').forEach((line, i) => {
|
|
68
|
+
const at = i + 1;
|
|
69
|
+
|
|
70
|
+
// "CI:7 项门禁" / "the seven gates" / "门禁本身是 7 项" / "those 7 gates"
|
|
71
|
+
for (const m of line.matchAll(/(\d+)\s*项门禁/g)) claim(file, at, 'ciGates', Number(m[1]), ciGates);
|
|
72
|
+
for (const m of line.matchAll(/(\d+)\s*gates\b/g)) claim(file, at, 'ciGates', Number(m[1]), ciGates);
|
|
73
|
+
for (const m of line.matchAll(/门禁(?:本身)?是\s*(\d+)\s*项/g)) claim(file, at, 'ciGates', Number(m[1]), ciGates);
|
|
74
|
+
|
|
75
|
+
// "其中 6 步" / "6 of them"
|
|
76
|
+
for (const m of line.matchAll(/(\d+)\s*步/g)) {
|
|
77
|
+
// "7 项门禁(…)" style lines also contain 步 sometimes; require the verb nearby.
|
|
78
|
+
if (!/跑|runs?|其中|of them/.test(line)) continue;
|
|
79
|
+
claim(file, at, 'localSteps', Number(m[1]), localSteps);
|
|
80
|
+
}
|
|
81
|
+
for (const m of line.matchAll(/(\d+)\s*of them/g)) claim(file, at, 'localSteps', Number(m[1]), localSteps);
|
|
82
|
+
|
|
83
|
+
// "跑 47 条断言 / 记录 13 组观测" and its English twin
|
|
84
|
+
for (const m of line.matchAll(/(\d+)\s*条断言/g)) claim(file, at, 'assertions', Number(m[1]), assertions);
|
|
85
|
+
for (const m of line.matchAll(/(\d+)\s*assertions?/g)) claim(file, at, 'assertions', Number(m[1]), assertions);
|
|
86
|
+
for (const m of line.matchAll(/(\d+)\s*组观测/g)) claim(file, at, 'groups', Number(m[1]), truth.groups);
|
|
87
|
+
for (const m of line.matchAll(/(\d+)\s*recorded groups/g)) claim(file, at, 'groups', Number(m[1]), truth.groups);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// ── the `npm run check` comment must enumerate the steps that are really there ──
|
|
92
|
+
//
|
|
93
|
+
// The count check above ("7 步") caught the number but not the LIST. Both READMEs
|
|
94
|
+
// said `npm run check # build --check + version-check + smoke` long after the
|
|
95
|
+
// command had grown to seven steps — the number was right three lines further down
|
|
96
|
+
// while the comment beside the command was three versions out of date. A reader who
|
|
97
|
+
// trusts the comment would skip provenance, both doc gates and the numbers gate.
|
|
98
|
+
//
|
|
99
|
+
// Scope: this fires on a line that *attempts an enumeration* — one whose comment
|
|
100
|
+
// names at least one real step. A bare `npm run check # 5. run the gates` in the
|
|
101
|
+
// release ritual makes no claim about WHICH steps, so demanding all seven there
|
|
102
|
+
// would be this gate inventing a rule the prose never stated. The second half of the
|
|
103
|
+
// guard keeps that from becoming an escape hatch: each README must still contain at
|
|
104
|
+
// least one real enumeration.
|
|
105
|
+
const checkScripts = [...pkg.scripts.check.matchAll(/node (scripts\/[\w.-]+\.mjs|test\/[\w.-]+\.cjs)/g)]
|
|
106
|
+
.map((m) => m[1]);
|
|
107
|
+
// Normalize to the word the prose uses: `scripts/build-client.mjs` -> `build-client`,
|
|
108
|
+
// `test/smoke.test.cjs` -> `smoke` (the `.test` infix is not spoken).
|
|
109
|
+
const shortOf = (script) => script
|
|
110
|
+
.replace(/^scripts\//, '').replace(/^test\//, '')
|
|
111
|
+
.replace(/\.mjs$/, '').replace(/\.test\.cjs$/, '').replace(/\.cjs$/, '');
|
|
112
|
+
const aliasOf = (short) => (short === 'build-client' ? /build(?: --check)?/ : null);
|
|
113
|
+
const names = (block, script) => {
|
|
114
|
+
const alias = aliasOf(shortOf(script));
|
|
115
|
+
return alias !== null ? alias.test(block) : block.includes(shortOf(script));
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
let listChecked = 0;
|
|
119
|
+
for (const file of ['README.md', 'README.en.md']) {
|
|
120
|
+
let enumerations = 0;
|
|
121
|
+
const lines = read(file).split('\n');
|
|
122
|
+
lines.forEach((line, i) => {
|
|
123
|
+
// Matches the code-block comment AND the prose enumeration (the 'local `npm run
|
|
124
|
+
// check` runs 7 of them (...)' sentence). The historical staleness happened in the
|
|
125
|
+
// code block, but the prose copy makes the same claim and drifts the same way.
|
|
126
|
+
if (!/npm run check\b/.test(line)) return;
|
|
127
|
+
listChecked += 1;
|
|
128
|
+
// The comment may continue on the next line (it is long); join both.
|
|
129
|
+
const block = line + ' ' + (lines[i + 1] ?? '');
|
|
130
|
+
// Does this line attempt an enumeration at all?
|
|
131
|
+
if (!checkScripts.some((s) => names(block, s))) return;
|
|
132
|
+
enumerations += 1;
|
|
133
|
+
for (const script of checkScripts) {
|
|
134
|
+
if (!names(block, script)) problems.push(file + ':' + (i + 1) + ' — `npm run check` list omits ' + script);
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
if (enumerations === 0) {
|
|
138
|
+
problems.push(file + ' — no `npm run check` line enumerates the steps any more; the guard has nothing to check');
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const total = Object.values(counted).reduce((a, b) => a + b, 0);
|
|
143
|
+
if (total === 0 || listChecked === 0) {
|
|
144
|
+
// A gate that matches nothing is worse than no gate: it reports success forever.
|
|
145
|
+
console.error('readme-numbers: found NO claim to check (numbers ' + total + ', `npm run check` lines '
|
|
146
|
+
+ listChecked + ') — the patterns have drifted from the prose');
|
|
147
|
+
process.exit(1);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
console.log('readme-numbers: 核对 ' + total + ' 处数字(门禁 ' + ciGates + ' / 本地 ' + localSteps
|
|
151
|
+
+ ' / 观测组 ' + truth.groups + ' / 断言 ' + assertions + ')');
|
|
152
|
+
if (problems.length > 0) {
|
|
153
|
+
for (const p of problems) console.error(' ✗ ' + p);
|
|
154
|
+
console.error('readme-numbers: FAIL (' + problems.length + ' 处不一致)');
|
|
155
|
+
process.exit(1);
|
|
156
|
+
}
|
|
157
|
+
console.log('README NUMBERS OK');
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Report the three places a release has to exist, side by side.
|
|
4
|
+
*
|
|
5
|
+
* §13.43, §13.45 and §13.47 are the same failure three times: the repository was
|
|
6
|
+
* self-consistent while an outside world disagreed.
|
|
7
|
+
*
|
|
8
|
+
* git tag ← what this checkout claims
|
|
9
|
+
* GitHub Release ← what the badge on the repo page reads
|
|
10
|
+
* npm registry ← what `npm i <name>` actually installs
|
|
11
|
+
*
|
|
12
|
+
* Each one is invisible from inside the others. After `git push` + `git tag` +
|
|
13
|
+
* `gh release create` the repo looks finished; if `npm publish` never ran, everyone
|
|
14
|
+
* installing by package name still gets the previous version and nothing errors.
|
|
15
|
+
*
|
|
16
|
+
* NOT a CI gate, deliberately: it needs network access to registry.npmjs.org and
|
|
17
|
+
* api.github.com, and a gate that fails when the network is flaky trains people to
|
|
18
|
+
* ignore it. Run it before announcing a release:
|
|
19
|
+
*
|
|
20
|
+
* node scripts/release-status.mjs # report; exit 1 if npm is behind
|
|
21
|
+
* node scripts/release-status.mjs --warn # report only, always exit 0
|
|
22
|
+
*/
|
|
23
|
+
import { execFileSync } from 'node:child_process';
|
|
24
|
+
import { readFileSync } from 'node:fs';
|
|
25
|
+
import { dirname, join } from 'node:path';
|
|
26
|
+
import { fileURLToPath } from 'node:url';
|
|
27
|
+
|
|
28
|
+
const ROOT = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
29
|
+
const WARN_ONLY = process.argv.includes('--warn');
|
|
30
|
+
|
|
31
|
+
const pkg = JSON.parse(readFileSync(join(ROOT, 'package.json'), 'utf8'));
|
|
32
|
+
const version = String(pkg.version);
|
|
33
|
+
const name = String(pkg.name);
|
|
34
|
+
|
|
35
|
+
const run = (cmd, args) => {
|
|
36
|
+
try {
|
|
37
|
+
return { ok: true, out: execFileSync(cmd, args, { cwd: ROOT, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] }).trim() };
|
|
38
|
+
} catch (e) {
|
|
39
|
+
return { ok: false, out: ((e.stdout ?? '') + (e.stderr ?? '')).trim() };
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const rows = [];
|
|
44
|
+
|
|
45
|
+
// 1. git tag — local truth, no network.
|
|
46
|
+
const tag = run('git', ['tag', '--list', 'v' + version]);
|
|
47
|
+
const headTagged = run('git', ['describe', '--tags', '--exact-match', 'HEAD']);
|
|
48
|
+
rows.push({
|
|
49
|
+
place: 'git tag',
|
|
50
|
+
present: tag.out.split('\n').filter(Boolean).includes('v' + version),
|
|
51
|
+
detail: headTagged.ok ? 'HEAD is exactly v' + version : 'HEAD is not exactly v' + version,
|
|
52
|
+
missing: 'git tag -a v' + version + ' -m "…" && git push origin v' + version,
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
// 2. GitHub Release — what the repo-page badge reads. No gh? Then say so, don't guess.
|
|
56
|
+
const gh = run('gh', ['api', 'repos/' + (run('git', ['remote', 'get-url', 'origin']).out.match(/github\.com[:/]([^/]+\/[^/.]+)/) ?? [])[1] + '/releases/tags/v' + version]);
|
|
57
|
+
rows.push({
|
|
58
|
+
place: 'GitHub Release',
|
|
59
|
+
present: gh.ok,
|
|
60
|
+
detail: gh.ok ? 'exists (the version badge resolves)' : 'not found — the badge shows a red "no releases"',
|
|
61
|
+
missing: 'gh release create v' + version + ' --notes-file …',
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
// 3. npm registry — what `npm i <name>@latest` installs.
|
|
65
|
+
const npmView = run('npm', ['view', name + '@' + version, 'version']);
|
|
66
|
+
const latest = run('npm', ['view', name, 'dist-tags.latest']);
|
|
67
|
+
rows.push({
|
|
68
|
+
place: 'npm registry',
|
|
69
|
+
present: npmView.ok && npmView.out.includes(version),
|
|
70
|
+
detail: npmView.ok && npmView.out.includes(version)
|
|
71
|
+
? 'published' + (latest.ok ? ' (dist-tags.latest = ' + latest.out + ')' : '')
|
|
72
|
+
: 'MISSING — `npm i ' + name + '@latest` still installs ' + (latest.ok ? latest.out : '(unknown)'),
|
|
73
|
+
missing: 'npm publish',
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
const pad = (s, n) => s + ' '.repeat(Math.max(0, n - [...s].length));
|
|
77
|
+
console.log('release-status: ' + name + '@' + version + '\n');
|
|
78
|
+
for (const r of rows) console.log(' ' + (r.present ? '●' : '○') + ' ' + pad(r.place, 16) + r.detail);
|
|
79
|
+
const absent = rows.filter((r) => !r.present);
|
|
80
|
+
if (absent.length > 0) {
|
|
81
|
+
console.log('\nmissing from ' + absent.length + ' place(s):');
|
|
82
|
+
for (const r of absent) console.log(' ' + r.place + ': ' + r.missing);
|
|
83
|
+
}
|
|
84
|
+
if (absent.some((r) => r.place === 'npm registry')) {
|
|
85
|
+
const msg = 'release-status: ' + version + ' is tagged but NOT on npm — anyone installing by package name gets the old version';
|
|
86
|
+
if (WARN_ONLY) console.log('\n' + msg + ' (warn only)');
|
|
87
|
+
else {
|
|
88
|
+
console.error('\n' + msg);
|
|
89
|
+
process.exit(1);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
console.log('\nrelease-status: consistent everywhere');
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Fail when the released version, its Git tag, and the changelog disagree.
|
|
4
|
+
*
|
|
5
|
+
* `README.md` §14 used to admit this was unchecked ("版本号与 tag 不一致 → 暂无自动
|
|
6
|
+
* 检查,人工确认"). A human reminder is exactly the kind of rule that rots: the
|
|
7
|
+
* dangerous case is silent, because `npm publish` succeeds whether or not the tag
|
|
8
|
+
* exists, and a tag can point at a commit whose `package.json` still says the old
|
|
9
|
+
* version — so the tarball a user installs is not the tree the tag claims.
|
|
10
|
+
*
|
|
11
|
+
* Three hard failures, one notice:
|
|
12
|
+
*
|
|
13
|
+
* F1 tag `v<version>` exists but that commit's package.json says another version
|
|
14
|
+
* F2 `CHANGELOG.md` has no heading for `<version>`
|
|
15
|
+
* F3 `<version>` is not greater than the highest other tag (version went backwards)
|
|
16
|
+
* note no tag yet — a development state, not an error
|
|
17
|
+
*
|
|
18
|
+
* Deliberately does NOT require a tag: work-in-progress commits bump the version
|
|
19
|
+
* before the tag is cut, and failing there would train people to skip the check.
|
|
20
|
+
*
|
|
21
|
+
* node scripts/version-check.mjs
|
|
22
|
+
*/
|
|
23
|
+
import { execFileSync } from 'node:child_process';
|
|
24
|
+
import { readFileSync } from 'node:fs';
|
|
25
|
+
import { dirname, join } from 'node:path';
|
|
26
|
+
import { fileURLToPath } from 'node:url';
|
|
27
|
+
|
|
28
|
+
const ROOT = dirname(dirname(fileURLToPath(import.meta.url)));
|
|
29
|
+
const git = (...args) => execFileSync('git', args, { cwd: ROOT, encoding: 'utf8', maxBuffer: 16 * 1024 * 1024 }).trim();
|
|
30
|
+
|
|
31
|
+
const pkg = JSON.parse(readFileSync(join(ROOT, 'package.json'), 'utf8'));
|
|
32
|
+
const version = String(pkg.version);
|
|
33
|
+
|
|
34
|
+
/** Numeric triple from `1.2.3` / `v1.2.3`; anything else (pre-release) keeps its text. */
|
|
35
|
+
function parse(v) {
|
|
36
|
+
const m = /^v?(\d+)\.(\d+)\.(\d+)(.*)$/.exec(v);
|
|
37
|
+
return m === null ? null : { nums: [Number(m[1]), Number(m[2]), Number(m[3])], rest: m[4] };
|
|
38
|
+
}
|
|
39
|
+
function compare(a, b) {
|
|
40
|
+
for (let i = 0; i < 3; i += 1) if (a.nums[i] !== b.nums[i]) return a.nums[i] - b.nums[i];
|
|
41
|
+
// A pre-release sorts BEFORE its release (1.0.0-rc < 1.0.0).
|
|
42
|
+
if (a.rest === b.rest) return 0;
|
|
43
|
+
if (a.rest === '') return 1;
|
|
44
|
+
if (b.rest === '') return -1;
|
|
45
|
+
return a.rest < b.rest ? -1 : 1;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const self = parse(version);
|
|
49
|
+
if (self === null) {
|
|
50
|
+
console.error('version-check: package.json version is not semver: ' + JSON.stringify(version));
|
|
51
|
+
process.exit(1);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const failures = [];
|
|
55
|
+
const notices = [];
|
|
56
|
+
|
|
57
|
+
// ── F3: the version must move forward relative to every other tag ──────────────
|
|
58
|
+
const tags = git('tag', '--list', 'v*').split('\n').filter(Boolean);
|
|
59
|
+
const others = tags.filter((t) => t !== 'v' + version).map((t) => ({ tag: t, v: parse(t) })).filter((x) => x.v !== null);
|
|
60
|
+
if (others.length > 0) {
|
|
61
|
+
const highest = others.reduce((best, x) => (compare(x.v, best.v) > 0 ? x : best));
|
|
62
|
+
if (compare(self, highest.v) <= 0) {
|
|
63
|
+
failures.push('F3 package.json is ' + version + ' but tag ' + highest.tag + ' is already that high or higher — the version went backwards');
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// ── F1: an existing tag must describe the same version it is named after ───────
|
|
68
|
+
const tagName = 'v' + version;
|
|
69
|
+
if (tags.includes(tagName)) {
|
|
70
|
+
let taggedVersion = null;
|
|
71
|
+
try {
|
|
72
|
+
taggedVersion = JSON.parse(git('show', tagName + ':package.json')).version;
|
|
73
|
+
} catch {
|
|
74
|
+
failures.push('F1 tag ' + tagName + ' exists but its package.json could not be read');
|
|
75
|
+
}
|
|
76
|
+
if (taggedVersion !== null && String(taggedVersion) !== version) {
|
|
77
|
+
failures.push('F1 tag ' + tagName + ' points at a commit whose package.json says ' + taggedVersion + ' — the tag and the published tree disagree');
|
|
78
|
+
}
|
|
79
|
+
// A tag that is not reachable from HEAD cannot describe what is being shipped.
|
|
80
|
+
try {
|
|
81
|
+
git('merge-base', '--is-ancestor', tagName, 'HEAD');
|
|
82
|
+
} catch {
|
|
83
|
+
notices.push('tag ' + tagName + ' is not an ancestor of HEAD — this checkout is not the tagged tree');
|
|
84
|
+
}
|
|
85
|
+
} else {
|
|
86
|
+
notices.push('no tag ' + tagName + ' yet (development state; tag before publishing)');
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// ── F2: the changelog must mention the version being released ─────────────────
|
|
90
|
+
let changelog = '';
|
|
91
|
+
try {
|
|
92
|
+
changelog = readFileSync(join(ROOT, 'CHANGELOG.md'), 'utf8');
|
|
93
|
+
} catch {
|
|
94
|
+
failures.push('F2 CHANGELOG.md is missing');
|
|
95
|
+
}
|
|
96
|
+
if (changelog !== '' && changelog.indexOf('## ' + version) < 0) {
|
|
97
|
+
failures.push('F2 CHANGELOG.md has no "## ' + version + '" heading — a release without an entry is a release nobody can read about');
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
for (const n of notices) console.log('version-check: note: ' + n);
|
|
101
|
+
if (failures.length > 0) {
|
|
102
|
+
for (const f of failures) console.error('version-check: FAIL ' + f);
|
|
103
|
+
process.exit(1);
|
|
104
|
+
}
|
|
105
|
+
console.log('VERSION OK (' + version + ', ' + tags.length + ' tag(s) seen)');
|