@jjh32456/dsh-longlive 1.6.7 → 1.6.8

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.
Files changed (41) hide show
  1. package/CHANGELOG.md +40 -8
  2. package/QUICKSTART.md +10 -10
  3. package/README.en.md +4 -3
  4. package/README.md +10 -4
  5. package/SPEC.md +2 -2
  6. package/cordis.patch.yml +9 -0
  7. package/docs/ARCHITECTURE.md +3 -2
  8. package/docs/CONFIG.md +33 -6
  9. package/docs/DEV.md +3 -3
  10. package/docs/FAQ.md +4 -4
  11. package/docs/FEATURES.md +36 -5
  12. package/docs/OPERATIONS.md +1 -1
  13. package/docs/QUICKSTART.md +3 -3
  14. package/docs/README.en.md +3 -2
  15. package/docs/TROUBLESHOOTING.md +3 -3
  16. package/package.json +13 -8
  17. package/src/activity/index.js +649 -0
  18. package/src/activity/model.js +341 -0
  19. package/src/activity/store.js +625 -0
  20. package/src/config.js +29 -2
  21. package/src/features.js +26 -0
  22. package/src/heartbeat.js +156 -23
  23. package/src/identity/handover.js +52 -1
  24. package/src/live.js +22 -2
  25. package/src/recall/privacy.mjs +105 -16
  26. package/src/router/service/board.mjs +95 -15
  27. package/src/router/service/hint.mjs +14 -0
  28. package/src/router/service/service.mjs +27 -11
  29. package/test/activity-realtime.test.mjs +959 -0
  30. package/test/activity-stream.test.mjs +512 -0
  31. package/test/autobind.test.mjs +25 -11
  32. package/test/config-schema.test.mjs +6 -0
  33. package/test/feature-flags.test.mjs +17 -0
  34. package/test/fixtures/activity-append-child.mjs +29 -0
  35. package/test/live.test.mjs +6 -3
  36. package/test/packaging.test.mjs +7 -5
  37. package/test/router-background/router.test.mjs +44 -12
  38. package/test/run-rc.mjs +16 -0
  39. package/test/safety-defaults.test.mjs +5 -3
  40. package/test/state-truth.test.mjs +937 -0
  41. package/test/version-consistency.test.mjs +286 -0
@@ -0,0 +1,286 @@
1
+ // Version-consistency gate (added for 1.6.8, see VERSION-AUDIT.md).
2
+ //
3
+ // The ONLY authority for the package version is `package.json#version`; every
4
+ // other version-bearing place is a projection of it. This suite pins each
5
+ // projection so a missed bump fails here instead of shipping an install whose
6
+ // docs/tgz/CHANGELOG still name the previous release.
7
+ //
8
+ // Rules of the house:
9
+ // * current-version claims must equal VERSION exactly;
10
+ // * historical mentions are allowed only in CHANGELOG.md and
11
+ // docs/MIGRATION-1.6.0.md (plus source/test comments, which are not scanned);
12
+ // * the panel (`@jjh32456/dsh-longlive-panel`) is an INDEPENDENT package: its
13
+ // version must be internally consistent but not equal to VERSION.
14
+ //
15
+ // Everything is read-only file IO: no host, no network, no writes.
16
+
17
+ import fs from 'node:fs';
18
+ import path from 'node:path';
19
+ import test from 'node:test';
20
+ import assert from 'node:assert/strict';
21
+ import { fileURLToPath } from 'node:url';
22
+
23
+ import { VERSION, PACKAGE_ROOT } from '../src/version.js';
24
+
25
+ const ROOT = PACKAGE_ROOT || path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
26
+ const PKG = JSON.parse(fs.readFileSync(path.join(ROOT, 'package.json'), 'utf8'));
27
+ const V = PKG.version;
28
+
29
+ // Panel is an independent package pinned to its own release 0.2.6, which ships
30
+ // together with 1.6.8; the activity panel page ("谁在干什么") is still NOT in
31
+ // 0.2.6 (deferred to panel 0.2.7). Bump only with a panel release.
32
+ const PANEL_VERSION = '0.2.6';
33
+
34
+ // Docs that carry release-facing version claims.
35
+ const DOC_FILES = [
36
+ 'README.md',
37
+ 'README.en.md',
38
+ 'QUICKSTART.md',
39
+ 'SPEC.md',
40
+ 'docs/README.en.md',
41
+ 'docs/QUICKSTART.md',
42
+ 'docs/DEV.md',
43
+ 'docs/FAQ.md',
44
+ 'docs/CONFIG.md',
45
+ 'docs/FEATURES.md',
46
+ 'docs/TROUBLESHOOTING.md',
47
+ 'docs/ARCHITECTURE.md',
48
+ 'docs/OPERATIONS.md',
49
+ ];
50
+
51
+ // Files where old version numbers are history, not claims.
52
+ const HISTORY_FILES = new Set(['CHANGELOG.md', 'docs/MIGRATION-1.6.0.md']);
53
+
54
+ const SEMVER = String.raw`(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-rc\.(?:0|[1-9]\d*))?`;
55
+
56
+ function readText(rel) {
57
+ return fs.readFileSync(path.join(ROOT, rel), 'utf8').replace(/^\uFEFF/, '');
58
+ }
59
+
60
+ function scan(text, re) {
61
+ const out = [];
62
+ for (const match of text.matchAll(re)) out.push(match);
63
+ return out;
64
+ }
65
+
66
+ // Same minimal glob semantics as scripts/pack.mjs: ** crosses directories, * does not.
67
+ function globToRegExp(pattern) {
68
+ let source = '';
69
+ for (let i = 0; i < pattern.length; i += 1) {
70
+ const char = pattern[i];
71
+ if (char === '*') {
72
+ if (pattern[i + 1] === '*') {
73
+ i += 1;
74
+ if (pattern[i + 1] === '/') {
75
+ i += 1;
76
+ source += '(?:.*/)?';
77
+ } else {
78
+ source += '.*';
79
+ }
80
+ } else {
81
+ source += '[^/]*';
82
+ }
83
+ } else if (char === '?') {
84
+ source += '[^/]';
85
+ } else {
86
+ source += char.replace(/[.+^${}()|[\]\\]/g, '\\$&');
87
+ }
88
+ }
89
+ return new RegExp(`^${source}$`);
90
+ }
91
+
92
+ function whitelisted(rel) {
93
+ for (const entry of PKG.files) {
94
+ if (typeof entry !== 'string' || entry.startsWith('!')) continue;
95
+ if (globToRegExp(entry).test(rel)) return true;
96
+ }
97
+ return false;
98
+ }
99
+
100
+ function walk(dir, base = dir, out = []) {
101
+ for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
102
+ const full = path.join(dir, entry.name);
103
+ if (entry.isDirectory()) walk(full, base, out);
104
+ else if (entry.isFile()) out.push(path.relative(base, full).split(path.sep).join('/'));
105
+ }
106
+ return out;
107
+ }
108
+
109
+ test('1) authority: package.json#version is the only version literal', () => {
110
+ assert.equal(PKG.version, VERSION, 'package.json version must be what src/version.js exports');
111
+ // 1.6.8 is a plain release. A future -rc should change this gate deliberately.
112
+ assert.match(V, new RegExp(String.raw`^(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)$`),
113
+ `release version must be plain MAJOR.MINOR.PATCH, got ${JSON.stringify(V)}`);
114
+ });
115
+
116
+ test('2) build-info.json: if shipped in the tree it must match the package version', () => {
117
+ const file = path.join(ROOT, 'build-info.json');
118
+ if (!fs.existsSync(file)) {
119
+ // npm pack does not include it (1.6.5/1.6.7 archives: 296 files, no build-info);
120
+ // scripts/pack.mjs regenerates it inside the archive. Absent is the normal state.
121
+ return;
122
+ }
123
+ const info = JSON.parse(fs.readFileSync(file, 'utf8'));
124
+ assert.equal(info.schema, 1, 'build-info schema must be 1');
125
+ assert.equal(info.version, V, `build-info version must be ${V} (stale build-info is a release bug)`);
126
+ assert.equal(info.expectedVersion, V, `build-info expectedVersion must be ${V}`);
127
+ assert.equal(info.name, PKG.name, 'build-info name must equal package.json name');
128
+ assert.ok(Number.isInteger(info.fileCount) && info.fileCount > 0, 'build-info fileCount must be a positive integer');
129
+ });
130
+
131
+ test('3) tgz names in docs: every install example names the current release', () => {
132
+ const re = new RegExp(String.raw`([A-Za-z0-9@_.-]*dsh-longlive-)(${SEMVER})\.tgz`, 'g');
133
+ for (const rel of DOC_FILES) {
134
+ const text = readText(rel);
135
+ for (const match of scan(text, re)) {
136
+ const [whole, prefix, version] = match;
137
+ assert.equal(version, V, `${rel}: tgz example ${whole} does not match version ${V}`);
138
+ assert.ok(prefix.startsWith('jjh32456-dsh-longlive-'),
139
+ `${rel}: tgz example must use the scoped release name jjh32456-dsh-longlive-<version>.tgz, got ${whole}`);
140
+ }
141
+ }
142
+ // History may keep old tgz names, but the current release must appear somewhere real.
143
+ assert.ok(readText('SPEC.md').includes(`jjh32456-dsh-longlive-${V}.tgz`),
144
+ `SPEC.md must name the current install archive jjh32456-dsh-longlive-${V}.tgz`);
145
+ });
146
+
147
+ test('4) --expect-version in docs: equals the package version', () => {
148
+ const re = new RegExp(String.raw`--expect-version\s+['"]?(${SEMVER})`, 'g');
149
+ let seen = 0;
150
+ for (const rel of DOC_FILES) {
151
+ for (const match of scan(readText(rel), re)) {
152
+ seen += 1;
153
+ assert.equal(match[1], V, `${rel}: --expect-version ${match[1]} does not match ${V}`);
154
+ }
155
+ }
156
+ assert.ok(seen >= 1, 'no --expect-version example found in published docs (QUICKSTART/DEV must keep one)');
157
+ });
158
+
159
+ test('5) plugin version strings in docs: @jjh32456/dsh-longlive@<v> == VERSION', () => {
160
+ const re = new RegExp(String.raw`@jjh32456/dsh-longlive@(${SEMVER})`, 'g');
161
+ for (const rel of DOC_FILES) {
162
+ for (const match of scan(readText(rel), re)) {
163
+ assert.equal(match[1], V, `${rel}: plugin version string ${match[0]} does not match ${V}`);
164
+ }
165
+ }
166
+ // The bare `@<version>` style used by `plugin list` examples.
167
+ for (const [rel, anchor] of [['docs/DEV.md', `# 应显示 @${V}`], ['docs/FAQ.md', `\`plugin list\` 显示 \`@${V}\``]]) {
168
+ assert.ok(readText(rel).includes(anchor), `${rel}: expected current-version anchor ${JSON.stringify(anchor)}`);
169
+ }
170
+ });
171
+
172
+ test('6) current-version headers and release anchors', () => {
173
+ const features = readText('docs/FEATURES.md');
174
+ assert.ok(features.startsWith(`# ${V} 可选能力与开关`),
175
+ `docs/FEATURES.md must start with "# ${V} 可选能力与开关"`);
176
+
177
+ assert.ok(readText('docs/CONFIG.md').includes(`适用版本:**${V}**`),
178
+ `docs/CONFIG.md must say 适用版本:**${V}**`);
179
+
180
+ const spec = readText('SPEC.md');
181
+ assert.ok(spec.includes(`当前版本:**${V}**`), `SPEC.md must say 当前版本:**${V}**`);
182
+ assert.ok(spec.includes(`jjh32456-dsh-longlive-${V}.tgz`), `SPEC.md must name jjh32456-dsh-longlive-${V}.tgz`);
183
+
184
+ assert.ok(readText('QUICKSTART.md').startsWith(`# QUICKSTART — 五步跑通(${V})`),
185
+ `QUICKSTART.md must start with the ${V} title`);
186
+ assert.ok(readText('docs/TROUBLESHOOTING.md').startsWith(`# TROUBLESHOOTING.md — 按症状查(${V})`),
187
+ `docs/TROUBLESHOOTING.md must carry the ${V} title`);
188
+ assert.ok(readText('README.md').includes(`本套文档对应 **${V}**`),
189
+ `README.md must say 本套文档对应 **${V}**`);
190
+
191
+ // The activity-stream suite label is versioned dynamically from src/version.js.
192
+ const runRc = readText('test/run-rc.mjs');
193
+ assert.ok(runRc.includes('${VERSION} shared-brain activity stream'),
194
+ 'test/run-rc.mjs activity suite label must use ${VERSION} instead of a hardcoded version');
195
+ assert.ok(runRc.includes('${VERSION} version consistency'),
196
+ 'test/run-rc.mjs must register the version-consistency suite with a ${VERSION} label');
197
+ });
198
+
199
+ test('7) CHANGELOG: first release heading is the current version, no Unreleased left', () => {
200
+ const changelog = readText('CHANGELOG.md');
201
+ const headings = [...changelog.matchAll(/^## (.+)$/gm)].map((m) => m[1].trim());
202
+ assert.ok(headings.length > 0, 'CHANGELOG.md has no "## " release headings');
203
+ assert.ok(headings[0].startsWith(V),
204
+ `CHANGELOG.md first release heading must start with the current version ${V}, got ${JSON.stringify(headings[0])}`);
205
+ assert.ok(!/^## Unreleased/m.test(changelog), 'CHANGELOG.md must not keep an Unreleased section in a release');
206
+ });
207
+
208
+ test('8) cordis.patch.yml carries the current release marker', () => {
209
+ const yml = readText('cordis.patch.yml');
210
+ assert.ok(yml.includes(`# ${V}:`),
211
+ `cordis.patch.yml must carry a "# ${V}:" release marker on the current feature block`);
212
+ // The patch has no version field of its own; the marker is the only version projection.
213
+ assert.ok(!/^\s*version:/m.test(yml), 'cordis.patch.yml must not invent a version field');
214
+ });
215
+
216
+ test('9) panel version is internally consistent (independent package)', () => {
217
+ const panelRe = new RegExp(String.raw`@jjh32456/dsh-longlive-panel@(${SEMVER})`, 'g');
218
+ const panelTgzRe = new RegExp(String.raw`jjh32456-dsh-longlive-panel-(${SEMVER})\.tgz`, 'g');
219
+ for (const rel of DOC_FILES) {
220
+ const text = readText(rel);
221
+ for (const match of [...scan(text, panelRe), ...scan(text, panelTgzRe)]) {
222
+ assert.equal(match[1], PANEL_VERSION,
223
+ `${rel}: panel reference ${match[0]} does not match PANEL_VERSION ${PANEL_VERSION}`);
224
+ }
225
+ }
226
+ assert.ok(readText('docs/README.en.md').includes(`@jjh32456/dsh-longlive-panel@${PANEL_VERSION}`),
227
+ `docs/README.en.md must reference the scoped panel @jjh32456/dsh-longlive-panel@${PANEL_VERSION}`);
228
+ assert.ok(readText('test/packaging.test.mjs').includes(`@jjh32456/dsh-longlive-panel@${PANEL_VERSION}`),
229
+ `test/packaging.test.mjs must keep its scoped panel assertion on ${PANEL_VERSION}`);
230
+ });
231
+
232
+ test('10) package.json files whitelist covers every shipped test and src file', () => {
233
+ const tests = fs.readdirSync(path.join(ROOT, 'test'))
234
+ .filter((name) => name.endsWith('.test.mjs'))
235
+ .map((name) => `test/${name}`)
236
+ .sort();
237
+ assert.ok(tests.length > 20, `unexpectedly few test files: ${tests.length}`);
238
+ for (const rel of tests) {
239
+ assert.ok(PKG.files.includes(rel), `package.json files whitelist misses ${rel}`);
240
+ }
241
+
242
+ const srcFiles = walk(path.join(ROOT, 'src'), ROOT).filter((rel) => rel.endsWith('.js') || rel.endsWith('.mjs'));
243
+ assert.ok(srcFiles.length > 50, `unexpectedly few src files: ${srcFiles.length}`);
244
+ const uncovered = srcFiles.filter((rel) => !whitelisted(rel));
245
+ assert.deepEqual(uncovered, [], `src files missing from package.json files whitelist:\n${uncovered.join('\n')}`);
246
+
247
+ assert.ok(PKG.files.includes('test/version-consistency.test.mjs'),
248
+ 'package.json files must include test/version-consistency.test.mjs');
249
+ });
250
+
251
+ test('11) no workspace wording leaks into the release surface', () => {
252
+ const forbidden = ['activity-stream-165', '本工作树', '版本号仍标', '未做发布级版本推进'];
253
+ for (const rel of DOC_FILES) {
254
+ const text = readText(rel);
255
+ for (const phrase of forbidden) {
256
+ assert.ok(!text.includes(phrase), `${rel}: release docs must not contain workspace wording ${JSON.stringify(phrase)}`);
257
+ }
258
+ }
259
+ const changelog = readText('CHANGELOG.md');
260
+ for (const phrase of forbidden) {
261
+ assert.ok(!changelog.includes(phrase), `CHANGELOG.md must not contain workspace wording ${JSON.stringify(phrase)}`);
262
+ }
263
+ const description = String(PKG.description || '');
264
+ for (const phrase of forbidden) {
265
+ assert.ok(!description.includes(phrase), `package.json description must not contain ${JSON.stringify(phrase)}`);
266
+ }
267
+ });
268
+
269
+ test('12) release tooling must not hardcode the version', () => {
270
+ for (const rel of ['scripts/pack.mjs', 'src/version.js']) {
271
+ const text = readText(rel);
272
+ assert.ok(!/\b1\.\d+\.\d+\b/.test(text),
273
+ `${rel} must derive the version from package.json, found a hardcoded 1.x.y literal`);
274
+ }
275
+ });
276
+
277
+ test('13) dist archives (when present) are named after the current version', () => {
278
+ const dist = path.join(ROOT, 'dist');
279
+ if (!fs.existsSync(dist)) return; // release tree has no dist/; build output lives outside
280
+ const re = new RegExp(String.raw`jjh32456-dsh-longlive-(${SEMVER})\.tgz$`);
281
+ for (const name of fs.readdirSync(dist)) {
282
+ const match = re.exec(name);
283
+ if (!match) continue;
284
+ assert.equal(match[1], V, `dist/${name} is not built from the current version ${V}`);
285
+ }
286
+ });