jbc-dssi 1.1.11 → 1.1.12
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/lib/restart-autocheck.js +69 -23
- package/package.json +1 -1
package/lib/restart-autocheck.js
CHANGED
|
@@ -77,12 +77,13 @@ export function processStartMs(now = Date.now(), uptimeSec = process.uptime()) {
|
|
|
77
77
|
return Math.round(now - uptimeSec * 1000);
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
/** 成功消息(一行,模板见文档
|
|
81
|
-
export function formatSuccess({ pid, startedAt, version, checkedAt,
|
|
80
|
+
/** 成功消息(一行,模板见文档 §四)。`versionNote` 必须是明确对照,不许再出现 N/A。 */
|
|
81
|
+
export function formatSuccess({ pid, startedAt, version, checkedAt, versionNote = '' }) {
|
|
82
82
|
const hhmmss = new Date(checkedAt).toLocaleTimeString('zh-CN', { hour12: false });
|
|
83
|
+
const note = versionNote ? `(${versionNote})` : '';
|
|
83
84
|
return (
|
|
84
85
|
`✅ 重启已接续:PID ${pid}(${new Date(startedAt).toLocaleTimeString('zh-CN', { hour12: false })} 起)` +
|
|
85
|
-
`|插件 ${version}${
|
|
86
|
+
`|插件 ${version}${note}|3080 可连(401 正常)` +
|
|
86
87
|
`|群数据/工作区/配对均未重置(自动核验 ${hhmmss})`
|
|
87
88
|
);
|
|
88
89
|
}
|
|
@@ -106,7 +107,7 @@ export function formatFailure({ missing, evidence, checkedAt }) {
|
|
|
106
107
|
* @param {object} [opts.deps] 测试注入(clock/fs/net/通道)
|
|
107
108
|
*/
|
|
108
109
|
export function createRestartAutocheck({ ctx, log, config = {}, groups = null, packageVersion = '', deps = {} }) {
|
|
109
|
-
const cfg = { ...DEFAULTS, ...(config ?? {}) };
|
|
110
|
+
const cfg = { ...DEFAULTS, packageVersion: String(packageVersion ?? ''), ...(config ?? {}) };
|
|
110
111
|
const now = deps.now ?? (() => Date.now());
|
|
111
112
|
const pid = deps.pid ?? process.pid;
|
|
112
113
|
const startMs = deps.processStartMs ?? (() => processStartMs(now()));
|
|
@@ -125,7 +126,7 @@ export function createRestartAutocheck({ ctx, log, config = {}, groups = null, p
|
|
|
125
126
|
});
|
|
126
127
|
const probePort = deps.probePort ?? ((port) => probeHttp(port));
|
|
127
128
|
const checkBaseline = deps.checkBaseline ?? ((markerMtimeMs) => baselineCheck({ markerMtimeMs, config: cfg, log }));
|
|
128
|
-
const readExpectedVersion = deps.readExpectedVersion ?? (() =>
|
|
129
|
+
const readExpectedVersion = deps.readExpectedVersion ?? (() => resolveExpectedVersion(cfg));
|
|
129
130
|
const postGroupLine = deps.postGroupLine ?? (async (groupId, line) => groups?.postSystemLine?.(groupId, line));
|
|
130
131
|
const promptManager = deps.promptManager ?? (async (sessionId, text) => {
|
|
131
132
|
const controller = ctx?.sessionController;
|
|
@@ -159,7 +160,6 @@ export function createRestartAutocheck({ ctx, log, config = {}, groups = null, p
|
|
|
159
160
|
const missing = [];
|
|
160
161
|
const evidence = [];
|
|
161
162
|
const version = String(packageVersion ?? '');
|
|
162
|
-
const expected = String(cfg.expectVersion || readExpectedVersion() || '');
|
|
163
163
|
/** 判据 1:进程已换新(marker 不早于本次启动)。 */
|
|
164
164
|
const startedAt = startMs();
|
|
165
165
|
if (!(markerMtimeMs >= startedAt - PROCESS_START_TOLERANCE_MS)) missing.push('process');
|
|
@@ -175,21 +175,38 @@ export function createRestartAutocheck({ ctx, log, config = {}, groups = null, p
|
|
|
175
175
|
missing.push('port');
|
|
176
176
|
}
|
|
177
177
|
|
|
178
|
-
|
|
179
|
-
|
|
178
|
+
/*
|
|
179
|
+
* 判据 3:插件版本符合。
|
|
180
|
+
*
|
|
181
|
+
* 2026-11-02 修「版本对照 N/A」含糊值:必须给出**期望 X / 实际 Y → 一致/不一致**;
|
|
182
|
+
* 拿不到期望版本时写清「期望版本未知(原因)」,不许再用 N/A。
|
|
183
|
+
*/
|
|
184
|
+
const expectedInfo = (() => {
|
|
185
|
+
if (cfg.expectVersion) return { version: String(cfg.expectVersion), reason: null };
|
|
186
|
+
const raw = readExpectedVersion();
|
|
187
|
+
if (typeof raw === 'string') return { version: raw || null, reason: raw ? null : '未提供期望版本' };
|
|
188
|
+
return raw ?? { version: null, reason: '未提供期望版本' };
|
|
189
|
+
})();
|
|
190
|
+
const expected = expectedInfo.version ? String(expectedInfo.version) : '';
|
|
191
|
+
let versionNote;
|
|
180
192
|
if (!version) {
|
|
193
|
+
// 实际版本都取不到:失败,并把期望层也一并说清(不留含糊值)
|
|
181
194
|
missing.push('version');
|
|
182
|
-
|
|
195
|
+
const why = expected ? '' : `;期望版本未知(${expectedInfo.reason || '未提供期望版本'})`;
|
|
196
|
+
versionNote = `实际版本未知${why}`;
|
|
197
|
+
evidence.push(`version=${versionNote}`);
|
|
183
198
|
} else if (expected) {
|
|
184
199
|
if (version !== expected) {
|
|
185
200
|
missing.push('version');
|
|
186
|
-
|
|
201
|
+
versionNote = `期望 ${expected} / 实际 ${version} → 不一致`;
|
|
187
202
|
} else {
|
|
188
|
-
|
|
203
|
+
versionNote = `期望 ${expected} / 实际 ${version} → 一致`;
|
|
189
204
|
}
|
|
205
|
+
evidence.push(`version=${versionNote}`);
|
|
190
206
|
} else {
|
|
191
|
-
|
|
192
|
-
|
|
207
|
+
const why = expectedInfo.reason || '未提供期望版本';
|
|
208
|
+
versionNote = `期望版本未知(${why})`;
|
|
209
|
+
evidence.push(`version=实际 ${version};${versionNote}`);
|
|
193
210
|
}
|
|
194
211
|
|
|
195
212
|
/** 判据 4:数据基线未重置(查不到=失败;groups 整体关闭才 N/A)。 */
|
|
@@ -204,7 +221,7 @@ export function createRestartAutocheck({ ctx, log, config = {}, groups = null, p
|
|
|
204
221
|
|
|
205
222
|
const ok = missing.length === 0;
|
|
206
223
|
const text = ok
|
|
207
|
-
? formatSuccess({ pid, startedAt, version, checkedAt,
|
|
224
|
+
? formatSuccess({ pid, startedAt, version, checkedAt, versionNote })
|
|
208
225
|
: formatFailure({ missing: [...new Set(missing)], evidence: evidence.join(' '), checkedAt });
|
|
209
226
|
|
|
210
227
|
/** 通道 1:群消息(以主管身份落一行;posts 后返回主管会话信息,供通道 2 复用)。 */
|
|
@@ -405,24 +422,53 @@ export function baselineCheck({ markerMtimeMs, config, log }) {
|
|
|
405
422
|
return { missing, evidence, skipped: false };
|
|
406
423
|
}
|
|
407
424
|
|
|
408
|
-
/**
|
|
409
|
-
|
|
425
|
+
/**
|
|
426
|
+
* 解析期望版本,返回 `{version, reason}`(reason 仅当三层都拿不到时填写,供消息明确写"未知(原因)")。
|
|
427
|
+
*
|
|
428
|
+
* 三层来源(2026-11-02 老大定,解决"生产永远未知"):
|
|
429
|
+
* ① 发版脚本写入的配置 `expectVersion`(最权威:用户期望安装到哪个版本);
|
|
430
|
+
* ② 版本来源文件:dev 仓库的 `version.json`(向上 5 层)优先,其次插件包自身
|
|
431
|
+
* `package.json` 的 version(生产安装包内没有 version.json 时的兜底);
|
|
432
|
+
* ③ 都拿不到 → `{version:null, reason}`,消息里写"期望版本未知(原因)"。
|
|
433
|
+
*/
|
|
434
|
+
function resolveExpectedVersion(config) {
|
|
435
|
+
// ① 发版配置
|
|
436
|
+
if (config.expectVersion) return { version: String(config.expectVersion), reason: null };
|
|
437
|
+
|
|
438
|
+
// ② 仓库 version.json(dev 归档场景)
|
|
439
|
+
const repo = readRepoVersionJson(config.packageRoot);
|
|
440
|
+
if (repo.version) return repo;
|
|
441
|
+
|
|
442
|
+
// ② 插件包 package.json(生产兜底:期望 = 已安装包版本)
|
|
443
|
+
if (config.packageVersion) return { version: String(config.packageVersion), reason: null };
|
|
444
|
+
|
|
445
|
+
// ③ 未知 + 原因
|
|
446
|
+
return {
|
|
447
|
+
version: null,
|
|
448
|
+
reason: repo.reason
|
|
449
|
+
? `${repo.reason};插件包 package.json 也没有 version`
|
|
450
|
+
: '配置未提供 expectVersion,插件包 package.json 也没有 version',
|
|
451
|
+
};
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
/** 读仓库 `version.json`(向上 5 层);返回 `{version, reason}`,无则 reason 说明。 */
|
|
455
|
+
function readRepoVersionJson(packageRoot) {
|
|
456
|
+
if (!packageRoot) return { version: null, reason: '未提供插件包目录' };
|
|
410
457
|
try {
|
|
411
|
-
let dir =
|
|
412
|
-
if (!dir) return null;
|
|
458
|
+
let dir = packageRoot;
|
|
413
459
|
for (let i = 0; i < 5; i += 1) {
|
|
414
460
|
const candidate = join(dir, 'version.json');
|
|
415
461
|
if (existsSync(candidate)) {
|
|
416
462
|
const json = JSON.parse(readFileSync(candidate, 'utf8'));
|
|
417
|
-
|
|
418
|
-
return
|
|
463
|
+
const value = json.versionName ?? json.version;
|
|
464
|
+
return value ? { version: String(value), reason: null } : { version: null, reason: `version.json 缺少版本字段:${candidate}` };
|
|
419
465
|
}
|
|
420
466
|
const parent = dirname(dir);
|
|
421
467
|
if (parent === dir) break;
|
|
422
468
|
dir = parent;
|
|
423
469
|
}
|
|
424
|
-
return null;
|
|
425
|
-
} catch {
|
|
426
|
-
return null;
|
|
470
|
+
return { version: null, reason: '插件包内没有 version.json(生产 profile 不随包发布)' };
|
|
471
|
+
} catch (err) {
|
|
472
|
+
return { version: null, reason: `读取 version.json 失败:${err?.message ?? err}` };
|
|
427
473
|
}
|
|
428
474
|
}
|