dsh-config-manager 0.5.0 → 0.7.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/lib/client.d.ts +8 -0
- package/lib/client.js +748 -602
- package/lib/core/local-plugin-host.d.ts +9 -0
- package/lib/core/local-plugin-host.js +174 -1
- package/lib/core/messages.d.ts +7 -0
- package/lib/core/messages.js +16 -0
- package/lib/core/migration-history.d.ts +40 -0
- package/lib/core/migration-history.js +55 -0
- package/lib/core/plugin-cli.d.ts +5 -0
- package/lib/core/plugin-cli.js +11 -3
- package/lib/core/run-registry.d.ts +10 -0
- package/lib/core/run-registry.js +17 -0
- package/lib/index.d.ts +7 -2
- package/lib/index.js +20 -19
- package/lib/profiles/dsh-profile-manager.d.ts +1 -1
- package/lib/profiles/dsh-profile-manager.js +26 -7
- package/lib/profiles/dsh-profile-shared.d.ts +3 -1
- package/lib/routes/import.js +6 -1
- package/lib/routes/route-support.d.ts +2 -1
- package/lib/routes/route-support.js +8 -3
- package/lib/routes/sync.js +5 -2
- package/lib/sync/autosync-config.d.ts +9 -1
- package/lib/sync/autosync-config.js +10 -2
- package/lib/sync/autosync-scheduler.js +18 -6
- package/lib/sync/git/git-transport.d.ts +31 -1
- package/lib/sync/git/git-transport.js +119 -23
- package/lib/sync/sync-config.d.ts +34 -3
- package/lib/sync/sync-config.js +38 -5
- package/lib/ui/sync-repository-picker.d.ts +21 -0
- package/lib/ui/sync-repository-picker.js +18 -0
- package/lib/ui/sync-settings-view.d.ts +4 -0
- package/lib/ui/sync-settings-view.js +3 -0
- package/lib/utils/remove-tree.d.ts +7 -0
- package/lib/utils/remove-tree.js +265 -0
- package/package.json +1 -1
- package/src/client/config-manager.module.css +21 -1
- package/src/client/environment/EnvironmentPanel.tsx +2 -2
- package/src/client/locales/profiles.ts +2 -0
- package/src/client/run-store.test.ts +1 -1
- package/src/client/run-store.ts +5 -0
- package/src/client/sync/ChannelConfigDialog.tsx +47 -2
- package/src/client/sync/SyncPanel.tsx +17 -30
- package/src/client/sync/SyncRepositoryPicker.tsx +34 -13
- package/src/client/sync/SyncSettingsView.test.ts +32 -0
- package/src/client/sync/config-save-state.test.ts +99 -0
- package/src/client/sync/config-save-state.ts +69 -0
- package/src/client/sync/sync-api.ts +2 -0
- package/src/client/sync/sync-locales.ts +10 -0
- package/src/core/engine-locale.test.ts +4 -0
- package/src/core/local-plugin-host.test.ts +31 -2
- package/src/core/local-plugin-host.ts +175 -2
- package/src/core/messages.ts +16 -0
- package/src/core/migration-history.test.ts +65 -0
- package/src/core/migration-history.ts +70 -0
- package/src/core/plugin-cli.fs.test.ts +30 -3
- package/src/core/plugin-cli.ts +11 -3
- package/src/core/run-registry-runs.test.ts +26 -1
- package/src/core/run-registry.ts +18 -0
- package/src/index.sync.test.ts +27 -0
- package/src/index.ts +21 -21
- package/src/profiles/dsh-profile-manager.test.ts +20 -0
- package/src/profiles/dsh-profile-manager.ts +25 -7
- package/src/profiles/dsh-profile-shared.ts +2 -0
- package/src/routes/import.ts +6 -1
- package/src/routes/route-support.ts +7 -3
- package/src/routes/sync.ts +5 -2
- package/src/sync/autosync-config.ts +10 -2
- package/src/sync/autosync-scheduler.test.ts +61 -1
- package/src/sync/autosync-scheduler.ts +17 -5
- package/src/sync/git/git-transport.test.ts +117 -0
- package/src/sync/git/git-transport.ts +131 -23
- package/src/sync/sync-config.test.ts +59 -1
- package/src/sync/sync-config.ts +51 -5
- package/src/ui/sync-repository-picker.test.ts +34 -1
- package/src/ui/sync-repository-picker.ts +24 -0
- package/src/ui/sync-settings-view.test.ts +1 -0
- package/src/ui/sync-settings-view.ts +7 -0
- package/src/utils/remove-tree.test.ts +120 -0
- package/src/utils/remove-tree.ts +239 -0
|
@@ -9,11 +9,12 @@
|
|
|
9
9
|
*/
|
|
10
10
|
import fsp from 'node:fs/promises';
|
|
11
11
|
import path from 'node:path';
|
|
12
|
+
import { createHash } from 'node:crypto';
|
|
12
13
|
import { spawn } from 'node:child_process';
|
|
13
14
|
|
|
14
15
|
import { packLocalPlugins, parsePackOutput, resolveLocalPluginPath } from './local-plugin-pack.ts';
|
|
15
16
|
import { quoteCmdArg } from './plugin-cli.ts';
|
|
16
|
-
import type { OversizeLocalPlugin, PackExec, PackExecResult, PackLocalPluginsResult } from './local-plugin-pack.ts';
|
|
17
|
+
import type { OversizeLocalPlugin, PackedLocalPlugin, PackExec, PackExecResult, PackLocalPluginsResult } from './local-plugin-pack.ts';
|
|
17
18
|
import type { HostContext } from './types.ts';
|
|
18
19
|
import { engineMsg } from './messages-core.ts';
|
|
19
20
|
|
|
@@ -106,6 +107,15 @@ export interface LocalPluginPackHookOptions {
|
|
|
106
107
|
sourceFingerprint?: (absPath: string) => Promise<string | null>;
|
|
107
108
|
/** tarball 体积上限(缺省 MAX_LOCAL_TARBALL_BYTES;测试用小值验证超限负缓存) */
|
|
108
109
|
maxTarballBytes?: number;
|
|
110
|
+
/**
|
|
111
|
+
* 内容缓存上限(字节;缺省 PACKED_CACHE_MAX_BYTES,**0 = 关闭**)。
|
|
112
|
+
* 命中判据 = 源目录的**内容指纹**(递归 rel/size/mtime)未变:命中即复用上次的 tarball 字节,跳过 npm pack。
|
|
113
|
+
*/
|
|
114
|
+
packedCacheMaxBytes?: number;
|
|
115
|
+
/** 内容缓存条目上限(缺省 PACKED_CACHE_MAX_ENTRIES)。 */
|
|
116
|
+
packedCacheMaxEntries?: number;
|
|
117
|
+
/** 内容指纹(测试注入;缺省 deepSourceFingerprint)。 */
|
|
118
|
+
contentFingerprint?: (absPath: string) => Promise<string | null>;
|
|
109
119
|
}
|
|
110
120
|
|
|
111
121
|
/**
|
|
@@ -140,6 +150,69 @@ async function defaultSourceFingerprint(absPath: string): Promise<string | null>
|
|
|
140
150
|
return null;
|
|
141
151
|
}
|
|
142
152
|
}
|
|
153
|
+
/** 内容缓存上限(缺省 128 MiB):只缓存真的打过的 tarball 字节。 */
|
|
154
|
+
const PACKED_CACHE_MAX_BYTES = 128 * 1024 * 1024;
|
|
155
|
+
|
|
156
|
+
/** 内容缓存条目上限(防「一堆小插件」把 Map 撑大)。 */
|
|
157
|
+
const PACKED_CACHE_MAX_ENTRIES = 64;
|
|
158
|
+
|
|
159
|
+
/** 内容指纹的遍历上限:超过就不缓存(宁可不省,也不拿可能过期的字节去备份)。 */
|
|
160
|
+
const CONTENT_FP_MAX_ENTRIES = 20_000;
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* 内容指纹(**正缓存**用):递归列出目录内每个文件的相对路径 + 字节数 + mtime。
|
|
164
|
+
*
|
|
165
|
+
* 为什么不用上面的 defaultSourceFingerprint:它只取「目录 mtime + package.json」,
|
|
166
|
+
* 在 lib/ 里改一行**不会**改目录 mtime —— 拿它做正缓存,会把旧 tarball 当成当前内容上传进备份。
|
|
167
|
+
* 负缓存能容忍这种粗糙(最坏是少备份一次、30 分钟内重试),正缓存不能容忍(最坏是备份里是旧代码)。
|
|
168
|
+
*
|
|
169
|
+
* 成本实测(2026-11-07,真机):8810 文件 3.6 s、51502 文件 14.9 s —— 仍比一次 210 MB 插件的
|
|
170
|
+
* 44.7 s npm pack 便宜一个量级;超过 CONTENT_FP_MAX_ENTRIES 或遇到链接/特殊文件一律返回 null
|
|
171
|
+
* (调用方据此**不缓存**,直接照常打包)。
|
|
172
|
+
*/
|
|
173
|
+
async function deepSourceFingerprint(absPath: string): Promise<string | null> {
|
|
174
|
+
let st;
|
|
175
|
+
try {
|
|
176
|
+
st = await fsp.stat(absPath);
|
|
177
|
+
} catch {
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
if (st.isFile()) return 'file:' + st.size + ':' + Math.trunc(st.mtimeMs);
|
|
181
|
+
if (!st.isDirectory()) return null;
|
|
182
|
+
|
|
183
|
+
const hash = createHash('sha256');
|
|
184
|
+
let entries = 0;
|
|
185
|
+
const walk = async (dir: string, rel: string): Promise<boolean> => {
|
|
186
|
+
let list;
|
|
187
|
+
try {
|
|
188
|
+
list = await fsp.readdir(dir, { withFileTypes: true });
|
|
189
|
+
} catch {
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
list.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
|
|
193
|
+
for (const entry of list) {
|
|
194
|
+
// 与 npm pack 同口径:node_modules 不进产物;.git 不参与内容身份
|
|
195
|
+
if (entry.name === 'node_modules' || entry.name === '.git') continue;
|
|
196
|
+
const abs = path.join(dir, entry.name);
|
|
197
|
+
const relPath = rel === '' ? entry.name : rel + '/' + entry.name;
|
|
198
|
+
if (entry.isDirectory()) {
|
|
199
|
+
if (!(await walk(abs, relPath))) return false;
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
if (!entry.isFile()) return false; // 链接 / 设备文件:不猜它指向什么,放弃缓存
|
|
203
|
+
const s = await fsp.stat(abs).catch(() => null);
|
|
204
|
+
if (s === null) return false;
|
|
205
|
+
entries += 1;
|
|
206
|
+
if (entries > CONTENT_FP_MAX_ENTRIES) return false;
|
|
207
|
+
hash.update(relPath + '\u0000' + s.size + '\u0000' + Math.trunc(s.mtimeMs) + '\n');
|
|
208
|
+
}
|
|
209
|
+
return true;
|
|
210
|
+
};
|
|
211
|
+
if (!(await walk(absPath, ''))) return null;
|
|
212
|
+
hash.update('entries:' + entries);
|
|
213
|
+
return 'deep:' + hash.digest('hex');
|
|
214
|
+
}
|
|
215
|
+
|
|
143
216
|
export function createLocalPluginPackHook(opts: LocalPluginPackHookOptions): LocalPluginPackHook {
|
|
144
217
|
const exec = opts.exec ?? defaultExec;
|
|
145
218
|
const oversizeTtlMs = opts.oversizeTtlMs ?? OVERSIZE_NEGATIVE_TTL_MS;
|
|
@@ -152,6 +225,42 @@ export function createLocalPluginPackHook(opts: LocalPluginPackHookOptions): Loc
|
|
|
152
225
|
*/
|
|
153
226
|
const oversizeCache = new Map<string, { fingerprint: string; at: number; oversize: OversizeLocalPlugin }>();
|
|
154
227
|
|
|
228
|
+
/**
|
|
229
|
+
* 内容缓存(正缓存):解析后的源路径 → 上次打出的 tarball 字节 + 当时的内容指纹。
|
|
230
|
+
*
|
|
231
|
+
* 与超限负缓存的区别:负缓存存「结论」,这里存**产物本身**,命中即跳过 npm pack。
|
|
232
|
+
* 命中判据是 deepSourceFingerprint(文件级 rel/size/mtime),不是目录 mtime —— 见该函数注释。
|
|
233
|
+
* 上限双保险:总字节数 + 条目数,超出按「最久未用」淘汰;单条超过上限则根本不入缓存。
|
|
234
|
+
*/
|
|
235
|
+
const packedMaxBytes = opts.packedCacheMaxBytes ?? PACKED_CACHE_MAX_BYTES;
|
|
236
|
+
const packedMaxEntries = opts.packedCacheMaxEntries ?? PACKED_CACHE_MAX_ENTRIES;
|
|
237
|
+
const contentFp = opts.contentFingerprint ?? deepSourceFingerprint;
|
|
238
|
+
const packedCache = new Map<string, { fingerprint: string; entry: PackedLocalPlugin; bytes: number; usedAt: number }>();
|
|
239
|
+
let packedCacheBytes = 0;
|
|
240
|
+
const evictPacked = (): void => {
|
|
241
|
+
while (packedCache.size > packedMaxEntries || packedCacheBytes > packedMaxBytes) {
|
|
242
|
+
let oldestKey: string | null = null;
|
|
243
|
+
let oldestAt = Number.POSITIVE_INFINITY;
|
|
244
|
+
for (const [key, value] of packedCache) {
|
|
245
|
+
if (value.usedAt < oldestAt) {
|
|
246
|
+
oldestAt = value.usedAt;
|
|
247
|
+
oldestKey = key;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
if (oldestKey === null) return;
|
|
251
|
+
const removed = packedCache.get(oldestKey);
|
|
252
|
+
if (removed !== undefined) packedCacheBytes -= removed.bytes;
|
|
253
|
+
packedCache.delete(oldestKey);
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
/** 按入参顺序输出打包结果(缓存命中与本轮打包混在一起时,保持确定性顺序)。 */
|
|
257
|
+
const orderPacked = (input: readonly { name: string }[], packed: readonly PackedLocalPlugin[]): PackedLocalPlugin[] => {
|
|
258
|
+
const byName = new Map(packed.map((p) => [p.packageName, p] as const));
|
|
259
|
+
return input.map((p) => byName.get(p.name)).filter((p): p is PackedLocalPlugin => p !== undefined);
|
|
260
|
+
};
|
|
261
|
+
const rewrittenOf = (packed: readonly PackedLocalPlugin[]): Record<string, string> =>
|
|
262
|
+
Object.fromEntries(packed.map((p) => [p.packageName, p.rewrittenSpec]));
|
|
263
|
+
|
|
155
264
|
const hasLocalSpec = (p: { spec?: string }): boolean =>
|
|
156
265
|
p.spec !== undefined && /^\s*(link|file):/i.test(p.spec);
|
|
157
266
|
|
|
@@ -209,6 +318,46 @@ export function createLocalPluginPackHook(opts: LocalPluginPackHookOptions): Loc
|
|
|
209
318
|
return { packed: [], rewritten: {}, warnings: cacheWarnings, oversize: cacheOversize };
|
|
210
319
|
}
|
|
211
320
|
|
|
321
|
+
// —— 内容缓存命中分流:源内容没变的那几个直接复用上次的 tarball,其余才真的打包 ——
|
|
322
|
+
const hitPacked: PackedLocalPlugin[] = [];
|
|
323
|
+
const toPack: { name: string; version: string; spec?: string }[] = [];
|
|
324
|
+
if (packedMaxBytes > 0) {
|
|
325
|
+
for (const p of kept) {
|
|
326
|
+
const spec = p.spec;
|
|
327
|
+
if (spec === undefined || !hasLocalSpec(p)) {
|
|
328
|
+
toPack.push(p);
|
|
329
|
+
continue;
|
|
330
|
+
}
|
|
331
|
+
const abs = resolveLocalPluginPath(spec, { homeDir: opts.homeDir, profileDir });
|
|
332
|
+
const hit = packedCache.get(abs);
|
|
333
|
+
if (hit === undefined) {
|
|
334
|
+
toPack.push(p);
|
|
335
|
+
continue;
|
|
336
|
+
}
|
|
337
|
+
const fp = await contentFp(abs).catch(() => null);
|
|
338
|
+
if (fp === null || fp !== hit.fingerprint) {
|
|
339
|
+
packedCacheBytes -= hit.bytes;
|
|
340
|
+
packedCache.delete(abs);
|
|
341
|
+
toPack.push(p);
|
|
342
|
+
continue;
|
|
343
|
+
}
|
|
344
|
+
hit.usedAt = Date.now();
|
|
345
|
+
hitPacked.push(hit.entry);
|
|
346
|
+
}
|
|
347
|
+
} else {
|
|
348
|
+
toPack.push(...kept);
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
if (!toPack.some(hasLocalSpec)) {
|
|
352
|
+
// 全部命中:不建临时目录、不 spawn 一次 npm。
|
|
353
|
+
return {
|
|
354
|
+
packed: orderPacked(plugins, hitPacked),
|
|
355
|
+
rewritten: rewrittenOf(hitPacked),
|
|
356
|
+
warnings: cacheWarnings,
|
|
357
|
+
oversize: cacheOversize,
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
|
|
212
361
|
const tmpRoot = path.join(opts.dataDir, 'tmp');
|
|
213
362
|
let packDir: string;
|
|
214
363
|
try {
|
|
@@ -227,8 +376,12 @@ export function createLocalPluginPackHook(opts: LocalPluginPackHookOptions): Loc
|
|
|
227
376
|
}
|
|
228
377
|
|
|
229
378
|
try {
|
|
379
|
+
const specOfName = new Map<string, string>();
|
|
380
|
+
for (const p of toPack) {
|
|
381
|
+
if (p.spec !== undefined && hasLocalSpec(p)) specOfName.set(p.name, p.spec);
|
|
382
|
+
}
|
|
230
383
|
const result = await packLocalPlugins({
|
|
231
|
-
plugins:
|
|
384
|
+
plugins: toPack.map((p) => ({ name: p.name, version: p.version, spec: p.spec })),
|
|
232
385
|
homeDir: opts.homeDir,
|
|
233
386
|
profileDir,
|
|
234
387
|
packDir,
|
|
@@ -257,8 +410,28 @@ export function createLocalPluginPackHook(opts: LocalPluginPackHookOptions): Loc
|
|
|
257
410
|
}
|
|
258
411
|
}
|
|
259
412
|
}
|
|
413
|
+
// 内容缓存记账:本轮真打出来的 tarball 按「源内容指纹」入缓存;超限/算不出指纹的跳过(不猜)。
|
|
414
|
+
if (packedMaxBytes > 0) {
|
|
415
|
+
for (const entry of result.packed) {
|
|
416
|
+
const spec = specOfName.get(entry.packageName);
|
|
417
|
+
if (spec === undefined) continue;
|
|
418
|
+
const bytes = entry.data.byteLength;
|
|
419
|
+
if (bytes > packedMaxBytes) continue;
|
|
420
|
+
const abs = resolveLocalPluginPath(spec, { homeDir: opts.homeDir, profileDir });
|
|
421
|
+
const fp = await contentFp(abs).catch(() => null);
|
|
422
|
+
if (fp === null) continue;
|
|
423
|
+
const prev = packedCache.get(abs);
|
|
424
|
+
if (prev !== undefined) packedCacheBytes -= prev.bytes;
|
|
425
|
+
packedCache.set(abs, { fingerprint: fp, entry, bytes, usedAt: Date.now() });
|
|
426
|
+
packedCacheBytes += bytes;
|
|
427
|
+
}
|
|
428
|
+
evictPacked();
|
|
429
|
+
}
|
|
430
|
+
const allPacked = [...hitPacked, ...result.packed];
|
|
260
431
|
return {
|
|
261
432
|
...result,
|
|
433
|
+
packed: orderPacked(plugins, allPacked),
|
|
434
|
+
rewritten: { ...result.rewritten, ...rewrittenOf(hitPacked) },
|
|
262
435
|
oversize: [...cacheOversize, ...result.oversize],
|
|
263
436
|
warnings: [...cacheWarnings, ...result.warnings],
|
|
264
437
|
};
|
package/src/core/messages.ts
CHANGED
|
@@ -215,6 +215,10 @@ export const zh = {
|
|
|
215
215
|
'host.snapshotPruneSummary': '自动保留清理删除 {count} 个旧快照',
|
|
216
216
|
'host.autosyncSummary': '自动同步 {direction}{transportSuffix}',
|
|
217
217
|
'host.autosyncTransportSuffix': '({transport})',
|
|
218
|
+
'host.autosyncDirectionPush': '上传',
|
|
219
|
+
'host.autosyncDirectionPull': '下载',
|
|
220
|
+
'host.autosyncDirectionBoth': '双向',
|
|
221
|
+
'host.autosyncDirectionNone': '检查',
|
|
218
222
|
'host.githubMissingClientId': '未配置 GitHub OAuth client_id:请在插件配置中设置 githubClientId(GitHub → Settings → Developer settings → OAuth Apps 注册应用获取)',
|
|
219
223
|
'host.githubFlowGone': 'GitHub 登录流程不存在或已过期,请重新开始',
|
|
220
224
|
'host.restoreBlobEscape': 'blob 路径越界: {blob}',
|
|
@@ -437,6 +441,10 @@ export const zh = {
|
|
|
437
441
|
'sync.git.adoptNotSyncRepo': '远端仓库顶层出现了快照布局以外的内容({entries}):它看起来不是本插件的同步仓库,已拒绝合并(不会把别的仓库内容搬进工作副本)。',
|
|
438
442
|
'sync.git.adoptMergeConflict': '合并远端 {branch} 时发生冲突:已撤销这次合并(merge --abort),工作副本回到操作前的状态。请手工解决冲突后重试,或改用「重新克隆工作副本」。',
|
|
439
443
|
'sync.workdirModeInvalidFull': '重建工作副本的模式非法: {mode}(只允许 relink(重指向地址)、adopt(采纳远端历史)或 reclone(重新克隆))',
|
|
444
|
+
// issue #131:git 通道的仓库内子目录前缀(多工具共用一个备份仓库时各占一个目录)。
|
|
445
|
+
'sync.git.subdirInvalid': '同步子目录前缀不合法:{subdir}(不得以 / 开头或结尾,不得含反斜杠、空段、. 段、.. 段或 .git 段)',
|
|
446
|
+
'sync.git.subdirRoot': '仓库根',
|
|
447
|
+
'sync.git.subdirChanged': '工作副本的同步布局是「{stored}」,当前配置是「{expected}」:sparse-checkout 只在首次克隆时生效,旧工作副本里没有新前缀的目录树 —— 照常同步会表现为「远端没有快照」。请在「同步 → 通道配置」里重建工作副本(重新克隆)后再同步。',
|
|
440
448
|
|
|
441
449
|
'sync.git.cmdFailed': 'git {args} 失败 (exit {code}): {err}',
|
|
442
450
|
// 本机提交身份缺失(真机 issue:commit exit 128 ⇒ 交易 NEEDS_ATTENTION ⇒ 被误升 SAFE MODE)。
|
|
@@ -728,6 +736,10 @@ export const en: Record<keyof typeof zh, string> = {
|
|
|
728
736
|
'host.snapshotPruneSummary': 'Automatic retention cleanup removed {count} old snapshot(s)',
|
|
729
737
|
'host.autosyncSummary': 'Autosync {direction}{transportSuffix}',
|
|
730
738
|
'host.autosyncTransportSuffix': ' ({transport})',
|
|
739
|
+
'host.autosyncDirectionPush': 'upload',
|
|
740
|
+
'host.autosyncDirectionPull': 'download',
|
|
741
|
+
'host.autosyncDirectionBoth': 'two-way',
|
|
742
|
+
'host.autosyncDirectionNone': 'check',
|
|
731
743
|
'host.githubMissingClientId': 'GitHub OAuth client_id is not configured: set githubClientId in the plugin config (GitHub → Settings → Developer settings → OAuth Apps → register an app)',
|
|
732
744
|
'host.githubFlowGone': 'The GitHub sign-in flow does not exist or has expired; please start over',
|
|
733
745
|
'host.restoreBlobEscape': 'Blob path outside snapshot directory: {blob}',
|
|
@@ -949,6 +961,10 @@ export const en: Record<keyof typeof zh, string> = {
|
|
|
949
961
|
'sync.git.adoptNotSyncRepo': 'The remote repository root contains entries outside the snapshot layout ({entries}): it does not look like this plugin\'s sync repository, so the merge was refused (another repository\'s content is never pulled into the working copy).',
|
|
950
962
|
'sync.git.adoptMergeConflict': 'Merging remote {branch} produced conflicts: the merge was aborted (merge --abort) and the working copy is back to its previous state. Resolve the conflicts manually and retry, or use "clone the working copy again".',
|
|
951
963
|
'sync.workdirModeInvalidFull': 'Invalid working-copy rebuild mode: {mode} (only relink (re-point the address), adopt (merge the remote history) or reclone (clone again) are allowed).',
|
|
964
|
+
// issue #131: in-repo subdirectory prefix for the git channel (several tools sharing one backup repository).
|
|
965
|
+
'sync.git.subdirInvalid': 'Invalid sync subdirectory prefix: {subdir} (must not start or end with /, and must not contain a backslash, an empty segment, a . segment, a .. segment, or a .git segment)',
|
|
966
|
+
'sync.git.subdirRoot': 'repository root',
|
|
967
|
+
'sync.git.subdirChanged': 'This working copy uses the sync layout "{stored}" but the current config is "{expected}": sparse-checkout only applies on the first clone, so the old working copy has no tree for the new prefix — syncing would look like "the remote has no snapshots". Rebuild the working copy (clone again) under Sync → Channel configuration, then sync again.',
|
|
952
968
|
|
|
953
969
|
'sync.git.cmdFailed': 'git {args} failed (exit {code}): {err}',
|
|
954
970
|
// Missing local commit identity (real-world issue: commit exit 128 → NEEDS_ATTENTION → wrongly escalated to SAFE MODE).
|
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
makeHistoryFilename, isHistoryBasename,
|
|
24
24
|
isValidHistoryRetention, resolveHistoryRetention,
|
|
25
25
|
HISTORY_RETENTION_MIN, HISTORY_RETENTION_MAX, DEFAULT_MIGRATION_RETENTION,
|
|
26
|
+
isAutosyncIdleRound, autosyncDirectionMessageKey, autosyncUnifiedHistoryInput,
|
|
26
27
|
type StoredMigrationHistoryEntry, type MigrationIo,
|
|
27
28
|
} from './migration-history.ts';
|
|
28
29
|
|
|
@@ -405,6 +406,70 @@ test('best-effort:read 目录不存在 → 空结果不 throw', async (t) => {
|
|
|
405
406
|
assert.equal(res.corrupted.length, 0);
|
|
406
407
|
});
|
|
407
408
|
|
|
409
|
+
// ---------- 自动同步:空检查轮与方向本地化(2026-11-08 实测) ----------
|
|
410
|
+
|
|
411
|
+
test('AUTOSYNC:60s 远端探测的空检查轮(upToDate)不构成活动,其余轮次照记', () => {
|
|
412
|
+
// 真机证据(desktop 档案):sync-history.json 每 60s 一条 upToDate,同期 git 工作副本只有 4 次真实 add。
|
|
413
|
+
assert.equal(isAutosyncIdleRound({ status: 'success', skipReason: 'upToDate' }), true, '命中 upToDate = 什么都没传,是轮询');
|
|
414
|
+
assert.equal(isAutosyncIdleRound({ status: 'success', skipReason: 'unchanged' }), false, 'unchanged 走了下行比对,仍要留痕');
|
|
415
|
+
assert.equal(isAutosyncIdleRound({ status: 'success' }), false, '无 skipReason 的 success = 真的推/拉了');
|
|
416
|
+
assert.equal(isAutosyncIdleRound({ status: 'skipped', skipReason: 'conflict' }), false, '冲突必须留在历史里等用户处理');
|
|
417
|
+
assert.equal(isAutosyncIdleRound({ status: 'failed' }), false, '失败永不静默');
|
|
418
|
+
assert.equal(isAutosyncIdleRound({ status: 'partial', skipReason: 'conflict-kept-local' }), false, '待裁决同属真实事件');
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
test('AUTOSYNC:方向枚举走字典键(两侧同键),未知方向不猜', () => {
|
|
422
|
+
assert.equal(autosyncDirectionMessageKey('push'), 'host.autosyncDirectionPush');
|
|
423
|
+
assert.equal(autosyncDirectionMessageKey('pull'), 'host.autosyncDirectionPull');
|
|
424
|
+
assert.equal(autosyncDirectionMessageKey('both'), 'host.autosyncDirectionBoth');
|
|
425
|
+
assert.equal(autosyncDirectionMessageKey('none'), 'host.autosyncDirectionNone');
|
|
426
|
+
assert.equal(autosyncDirectionMessageKey('bogus'), null, '未知方向返回 null,由调用方原样回显');
|
|
427
|
+
assert.equal(autosyncDirectionMessageKey(undefined), null);
|
|
428
|
+
|
|
429
|
+
// 字典词条本身(zh 逐字 + en 无 CJK)由 engine-locale.test.ts 的 t2 清单钉住,这里只管映射。
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
test('AUTOSYNC:统一历史载荷 —— 空轮不写、方向走字典、失败带原因', () => {
|
|
433
|
+
// 与宿主同口径的桩翻译器(字典词条本身由 engine-locale.test.ts 钉住)。
|
|
434
|
+
const dict: Record<string, string> = {
|
|
435
|
+
'host.autosyncDirectionPush': '上传',
|
|
436
|
+
'host.autosyncDirectionPull': '下载',
|
|
437
|
+
'host.autosyncDirectionBoth': '双向',
|
|
438
|
+
'host.autosyncDirectionNone': '检查',
|
|
439
|
+
};
|
|
440
|
+
const msg = (key: string, params?: Record<string, string | number>): string => {
|
|
441
|
+
if (key === 'host.autosyncSummary') return `自动同步 ${String(params?.direction ?? '')}${String(params?.transportSuffix ?? '')}`;
|
|
442
|
+
if (key === 'host.autosyncTransportSuffix') return `(${String(params?.transport ?? '')})`;
|
|
443
|
+
return dict[key] ?? key;
|
|
444
|
+
};
|
|
445
|
+
|
|
446
|
+
assert.equal(autosyncUnifiedHistoryInput({ status: 'success', skipReason: 'upToDate', direction: 'both' }, msg), null, '空检查轮不产生历史条目');
|
|
447
|
+
|
|
448
|
+
const push = autosyncUnifiedHistoryInput({ status: 'success', direction: 'push', transport: 'git', appliedSections: ['settings'] }, msg);
|
|
449
|
+
assert.ok(push);
|
|
450
|
+
assert.equal(push.result, 'success');
|
|
451
|
+
assert.equal(push.source, 'autosync');
|
|
452
|
+
assert.deepEqual(push.sections, ['settings']);
|
|
453
|
+
assert.equal(push.summary, '自动同步 上传(git)');
|
|
454
|
+
assert.equal(push.error, undefined);
|
|
455
|
+
|
|
456
|
+
// sections 必须是副本:历史条目不得与调用方共享可变数组。
|
|
457
|
+
const owned = ['ui'];
|
|
458
|
+
const shared = autosyncUnifiedHistoryInput({ status: 'skipped', direction: 'both', appliedSections: owned }, msg);
|
|
459
|
+
assert.ok(shared);
|
|
460
|
+
assert.notEqual(shared.sections, owned);
|
|
461
|
+
|
|
462
|
+
const failed = autosyncUnifiedHistoryInput({ status: 'failed', direction: 'pull', error: '鉴权失败' }, msg);
|
|
463
|
+
assert.equal(failed?.result, 'failed');
|
|
464
|
+
assert.equal(failed?.error, '鉴权失败', 'failed 必须带原因(sync-history 的 error 优先)');
|
|
465
|
+
assert.equal(autosyncUnifiedHistoryInput({ status: 'failed', direction: 'pull', skipReason: 'network' }, msg)?.error, 'network');
|
|
466
|
+
|
|
467
|
+
assert.equal(autosyncUnifiedHistoryInput({ status: 'partial', direction: 'both' }, msg)?.result, 'pending', '待裁决不是失败');
|
|
468
|
+
|
|
469
|
+
// 未知方向原样回显,不猜、不吞。
|
|
470
|
+
assert.equal(autosyncUnifiedHistoryInput({ status: 'success', direction: 'weird' }, msg)?.summary, '自动同步 weird');
|
|
471
|
+
});
|
|
472
|
+
|
|
408
473
|
test('BOUND:sanitizeEntry 保留合法 UUID operationId/snapshotId/runId', () => {
|
|
409
474
|
const uuid = '00000000-0000-4000-8000-000000000000';
|
|
410
475
|
const entry = sanitizeEntry(makeRaw({ operationId: uuid, snapshotId: uuid, runId: uuid }));
|
|
@@ -31,6 +31,7 @@ import { maskHighEntropy, redact } from '../security/redaction.ts';
|
|
|
31
31
|
import { scanAndRedact } from '../security/secret-scanner.ts';
|
|
32
32
|
import { sha256Hex } from '../utils/hashing.ts';
|
|
33
33
|
import { coreText, engineMsg } from './messages-core.ts';
|
|
34
|
+
import type { MsgFunc } from './msg-types.ts';
|
|
34
35
|
|
|
35
36
|
// ---------- 常量 ----------
|
|
36
37
|
|
|
@@ -103,6 +104,75 @@ export function historyResultFromAutosyncStatus(status: 'success' | 'skipped' |
|
|
|
103
104
|
return status === 'partial' ? 'pending' : 'failed';
|
|
104
105
|
}
|
|
105
106
|
|
|
107
|
+
/**
|
|
108
|
+
* 自动同步「空检查轮」判定:这一轮既没上传也没下行、更没应用任何分区(sections 恒空),
|
|
109
|
+
* 它只是 realtime 通道缺省每 60s 一次(remoteCheckMs)的远端探测 —— 是**轮询**,不是活动。
|
|
110
|
+
*
|
|
111
|
+
* 为什么必须挡在统一历史之外(2026-11-08 真机实测,desktop 档案):
|
|
112
|
+
* ① 1 条/分钟把首页「最近活动」刷成与真推**完全同形**的 success 行(用户据此报告
|
|
113
|
+
* 「每隔 1 分钟都在推送」,而同期 git 工作副本只有 4 次真实 add/deletes);
|
|
114
|
+
* ② 统一历史保留额度(缺省 1000 条)被空轮吃满:实测 1009 条里 934 条是 autosync,
|
|
115
|
+
* 其中 688 条正是 upToDate 空轮,真实事件(备份 22 / 档案操作 40)被最旧淘汰;
|
|
116
|
+
* ③ /history 是目录全量扫描(条目越多首页越慢),空轮只会让它线性变慢。
|
|
117
|
+
*
|
|
118
|
+
* 不丢诊断:sync-history.json 仍逐轮记录(含 upToDate),同步页「上次运行 / 跳过原因」照常显示。
|
|
119
|
+
*/
|
|
120
|
+
export function isAutosyncIdleRound(entry: { status: string; skipReason?: string }): boolean {
|
|
121
|
+
return entry.status === 'success' && entry.skipReason === 'upToDate';
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* 自动同步方向 → 字典键(`both`/`push`/`pull`/`none` 是机器 token,不得直接铺到界面上)。
|
|
126
|
+
* 未知方向返回 null,由调用方原样回显(不猜、不吞)。
|
|
127
|
+
*/
|
|
128
|
+
export function autosyncDirectionMessageKey(direction: unknown): string | null {
|
|
129
|
+
switch (direction) {
|
|
130
|
+
case 'push': return 'host.autosyncDirectionPush';
|
|
131
|
+
case 'pull': return 'host.autosyncDirectionPull';
|
|
132
|
+
case 'both': return 'host.autosyncDirectionBoth';
|
|
133
|
+
case 'none': return 'host.autosyncDirectionNone';
|
|
134
|
+
default: return null;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** 自动同步一轮 → 统一历史条目的载荷(不写则为 null)。 */
|
|
139
|
+
export type AutosyncHistoryInput = Pick<MigrationHistoryEntry, 'result' | 'sections' | 'source' | 'summary' | 'error'>;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* 自动同步一轮 → 统一历史条目;空检查轮返回 null(调用方直接 return,不写)。
|
|
143
|
+
*
|
|
144
|
+
* 规则落在 core 而不是宿主闭包里:宿主 src/index.ts 有体量棘轮(tests/file-size-ratchet.test.ts),
|
|
145
|
+
* 且这几条判断本身要能单测(空轮不写 / 方向本地化 / failed 带原因)。
|
|
146
|
+
* msg 由调用方注入(宿主传 engineMsg),本模块只管查表不引入新状态。
|
|
147
|
+
*/
|
|
148
|
+
export function autosyncUnifiedHistoryInput(
|
|
149
|
+
entry: {
|
|
150
|
+
status: 'success' | 'skipped' | 'partial' | 'failed';
|
|
151
|
+
direction?: unknown;
|
|
152
|
+
skipReason?: string;
|
|
153
|
+
transport?: string;
|
|
154
|
+
error?: string;
|
|
155
|
+
appliedSections?: string[];
|
|
156
|
+
},
|
|
157
|
+
msg: MsgFunc = engineMsg,
|
|
158
|
+
): AutosyncHistoryInput | null {
|
|
159
|
+
if (isAutosyncIdleRound(entry)) return null;
|
|
160
|
+
const directionKey = autosyncDirectionMessageKey(entry.direction);
|
|
161
|
+
const transport = entry.transport;
|
|
162
|
+
const input: AutosyncHistoryInput = {
|
|
163
|
+
result: historyResultFromAutosyncStatus(entry.status),
|
|
164
|
+
sections: entry.appliedSections === undefined ? [] : [...entry.appliedSections],
|
|
165
|
+
source: 'autosync',
|
|
166
|
+
summary: msg('host.autosyncSummary', {
|
|
167
|
+
direction: directionKey === null ? String(entry.direction ?? '') : msg(directionKey),
|
|
168
|
+
transportSuffix: transport === undefined || transport === '' ? '' : msg('host.autosyncTransportSuffix', { transport }),
|
|
169
|
+
}),
|
|
170
|
+
};
|
|
171
|
+
const error = entry.status === 'failed' ? (entry.error ?? entry.skipReason) : undefined;
|
|
172
|
+
if (error !== undefined) input.error = error;
|
|
173
|
+
return input;
|
|
174
|
+
}
|
|
175
|
+
|
|
106
176
|
/** 触发来源(常量)。 */
|
|
107
177
|
export type MigrationSource = 'api' | 'autosync' | 'backup-scheduler' | 'recovery' | 'cli' | 'internal';
|
|
108
178
|
|
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import test from 'node:test';
|
|
10
10
|
import assert from 'node:assert/strict';
|
|
11
|
-
import { mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
11
|
+
import { lstatSync, mkdirSync, mkdtempSync, readFileSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';
|
|
12
12
|
import { tmpdir } from 'node:os';
|
|
13
13
|
import { join } from 'node:path';
|
|
14
14
|
|
|
15
15
|
import {
|
|
16
|
-
isBundlesOnlyEntry, listInstalledPlugins, mergeBundleDeclaration, readInstalled,
|
|
17
|
-
reconcileBundles, reconcileBundlesAfterInstall, resolveProfileDir,
|
|
16
|
+
cleanupAbortedInstall, isBundlesOnlyEntry, listInstalledPlugins, mergeBundleDeclaration, readInstalled,
|
|
17
|
+
readInstalledVersion, reconcileBundles, reconcileBundlesAfterInstall, resolveProfileDir,
|
|
18
18
|
} from './plugin-cli.ts';
|
|
19
19
|
import { enterRescueMode } from './boot-rescue.ts';
|
|
20
20
|
import type { PluginInfo } from './types.ts';
|
|
@@ -366,3 +366,30 @@ test('issue #95: mergeBundleDeclaration 只追加一个名字;形状不符一
|
|
|
366
366
|
'bundles 字段缺省 → null(非空 bundles 会替换默认插件栈,绝不凭空造)',
|
|
367
367
|
);
|
|
368
368
|
});
|
|
369
|
+
|
|
370
|
+
test('中止安装清理:包目录是悬空 junction 时也必须删净(fs.rmSync 静默空转的回归)', () => {
|
|
371
|
+
const { profileDir, cleanup } = makeTempProfile({ 'pkg-b': '1.0.0' }, ['pkg-b']);
|
|
372
|
+
try {
|
|
373
|
+
const pkgDir = join(profileDir, 'node_modules', 'pkg-b');
|
|
374
|
+
mkdirSync(join(profileDir, 'node_modules'), { recursive: true });
|
|
375
|
+
// DSH 真实形态:node_modules/<pkg> 直接链到 .dsh-module-fallback;fallback 被宿主升级清掉后即成悬空链接。
|
|
376
|
+
symlinkSync(
|
|
377
|
+
join(profileDir, '.dsh-module-fallback', 'node_modules', 'pkg-b'),
|
|
378
|
+
pkgDir,
|
|
379
|
+
process.platform === 'win32' ? 'junction' : 'dir',
|
|
380
|
+
);
|
|
381
|
+
assert.ok(lstatSync(pkgDir).isSymbolicLink(), '链接条目本身在(existsSync 对悬空链接返回 false,不能当判据)');
|
|
382
|
+
|
|
383
|
+
cleanupAbortedInstall(profileDir, 'pkg-b');
|
|
384
|
+
|
|
385
|
+
assert.throws(() => lstatSync(pkgDir), /ENOENT/, '悬空链接必须被真的删掉,否则「跳过当前插件」留半装残留');
|
|
386
|
+
const manifest = JSON.parse(readFileSync(join(profileDir, 'package.json'), 'utf8')) as {
|
|
387
|
+
dependencies: Record<string, string>;
|
|
388
|
+
dsh: { profile: { bundles: string[] } };
|
|
389
|
+
};
|
|
390
|
+
assert.equal('pkg-b' in manifest.dependencies, false, '依赖行同步摘掉(下次安装不再撞缺包)');
|
|
391
|
+
assert.ok(Array.isArray(manifest.dsh.profile.bundles), 'bundles 形状不变');
|
|
392
|
+
} finally {
|
|
393
|
+
cleanup();
|
|
394
|
+
}
|
|
395
|
+
});
|
package/src/core/plugin-cli.ts
CHANGED
|
@@ -19,10 +19,11 @@ import { engineMsg } from './messages-core.ts'
|
|
|
19
19
|
import { isConcreteVersion } from './validator.ts';
|
|
20
20
|
import { spawn } from 'node:child_process'
|
|
21
21
|
import type { ChildProcess, SpawnOptions } from 'node:child_process'
|
|
22
|
-
import { readFileSync
|
|
22
|
+
import { readFileSync } from 'node:fs'
|
|
23
23
|
import { basename, dirname, join, resolve } from 'node:path'
|
|
24
24
|
|
|
25
25
|
import { atomicWriteFileSync } from '../utils/atomic-write.ts'
|
|
26
|
+
import { removeTreeSync } from '../utils/remove-tree.ts'
|
|
26
27
|
import { isDesktopProfile, resolveDesktopCarrier } from '../utils/desktop-carrier.ts'
|
|
27
28
|
import { isRescueActiveSync } from './boot-rescue.ts'
|
|
28
29
|
import type { PluginInfo } from './types.ts'
|
|
@@ -301,6 +302,11 @@ function isRescueActiveForProfileDir(profileDir: string): boolean {
|
|
|
301
302
|
* 直接启动 DSH 会因缺包而失败。本函数把 manifest 恢复为「该插件未安装」的一致状态,
|
|
302
303
|
* 消除「声明了依赖但没装全」的启动风险。pnpm-lock.yaml 不触碰(运行时不被读取,
|
|
303
304
|
* 下次安装 pnpm 自行对齐)。尽力而为:任何失败不抛错,由调用方记录告警。
|
|
305
|
+
*
|
|
306
|
+
* 删包目录必须走 removeTreeSync 而不是 fs.rmSync(recursive):包目录常是**链接**(DSH 把
|
|
307
|
+
* node_modules/<pkg> 链到 .dsh-module-fallback),链接目标消失后就是悬空链接,rmSync 遇到
|
|
308
|
+
* 这种树会静默空转(不抛错、一个都不删),于是「跳过当前插件」留下半装残留,下次安装撞缺包。
|
|
309
|
+
* removeTreeSync 只删链接本身(绝不跟进去删 fallback 里的实体)并在删不净时抛错。
|
|
304
310
|
*/
|
|
305
311
|
export function cleanupAbortedInstall(profileDir: string, pkg: string): void {
|
|
306
312
|
const manifest = readProfileManifest(profileDir)
|
|
@@ -315,9 +321,11 @@ export function cleanupAbortedInstall(profileDir: string, pkg: string): void {
|
|
|
315
321
|
reconcileBundles(profileDir)
|
|
316
322
|
}
|
|
317
323
|
try {
|
|
318
|
-
|
|
324
|
+
removeTreeSync(join(profileDir, 'node_modules', pkg))
|
|
319
325
|
} catch {
|
|
320
|
-
//
|
|
326
|
+
// 尽力而为:目录可能本来就不存在(正常情况下 removeTreeSync 对缺失目标是不抛的),
|
|
327
|
+
// 剩下的失败只有「真被占用 / 权限不足」——这里仍不打断「用户跳过」的流程,
|
|
328
|
+
// 但绝不再让悬空链接这种可修的形态走到这里。
|
|
321
329
|
}
|
|
322
330
|
}
|
|
323
331
|
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import test from 'node:test';
|
|
9
9
|
import assert from 'node:assert/strict';
|
|
10
10
|
|
|
11
|
-
import { RunRegistry } from './run-registry.ts';
|
|
11
|
+
import { RunRegistry, isIdleAutosyncRun } from './run-registry.ts';
|
|
12
12
|
|
|
13
13
|
test('pendingDecision:登记后可见,终态 run 上的晚到写入被忽略', () => {
|
|
14
14
|
const runs = new RunRegistry({ now: () => 1000 });
|
|
@@ -69,3 +69,28 @@ test('requestCancel:记录首个请求时刻(重复请求不刷新,界面
|
|
|
69
69
|
assert.equal(runs.requestCancel(run.runId)?.cancelRequestedAt, 1_000, '终态后的晚到请求被忽略');
|
|
70
70
|
assert.equal(runs.requestCancel('nope'), undefined, '未知 runId 返回 undefined(不伪造状态)');
|
|
71
71
|
});
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* 2026-11-09:空转的自动同步轮次不进运行中心。
|
|
75
|
+
*
|
|
76
|
+
* 现场:realtime 开着时每 60s 一轮远端探测,每轮都 register('autosync') → 运行中心每分钟一张
|
|
77
|
+
* 「自动同步 · 已完成」卡片(与迁移历史同一种噪音)。判据只认调度器写入的 result.idle,
|
|
78
|
+
* 不在 UI 猜 skipReason;running 与真干活的轮次必须照常显示。
|
|
79
|
+
*/
|
|
80
|
+
test('isIdleAutosyncRun:只认 result.idle(running / 其它 kind / 无 result 一律不算)', () => {
|
|
81
|
+
const runs = new RunRegistry({ now: () => 1000 });
|
|
82
|
+
const idle = runs.register('autosync');
|
|
83
|
+
runs.finish(idle.runId, { kind: 'autosync', idle: true });
|
|
84
|
+
assert.equal(isIdleAutosyncRun(runs.get(idle.runId)!), true);
|
|
85
|
+
|
|
86
|
+
const real = runs.register('autosync');
|
|
87
|
+
runs.finish(real.runId, { kind: 'autosync' });
|
|
88
|
+
assert.equal(isIdleAutosyncRun(runs.get(real.runId)!), false, '真推/真拉的轮次必须留卡片');
|
|
89
|
+
|
|
90
|
+
const running = runs.register('autosync');
|
|
91
|
+
assert.equal(isIdleAutosyncRun(runs.get(running.runId)!), false, '进行中的轮次不得被过滤(否则看不到在跑的任务)');
|
|
92
|
+
|
|
93
|
+
const other = runs.register('import');
|
|
94
|
+
runs.finish(other.runId, { idle: true });
|
|
95
|
+
assert.equal(isIdleAutosyncRun(runs.get(other.runId)!), false, '标志只对 autosync 生效');
|
|
96
|
+
});
|
package/src/core/run-registry.ts
CHANGED
|
@@ -136,6 +136,24 @@ export interface RunRegistryOptions {
|
|
|
136
136
|
* 内存 run 注册表。Node 单线程 + 同步 Map 读写,无并发竞争;
|
|
137
137
|
* 所有公开读方法返回状态副本,防止外部直接篡改内部状态。
|
|
138
138
|
*/
|
|
139
|
+
/**
|
|
140
|
+
* 自动同步「空转」run:60s 一次的远端探测拿到 upToDate —— 本轮既没上传也没下行、没应用任何分区。
|
|
141
|
+
*
|
|
142
|
+
* 为什么要过滤(2026-11-09 真机):realtime 通道每轮都会 register('autosync'),于是运行中心每分钟
|
|
143
|
+
* 多一张「自动同步 · 已完成」卡片,与「迁移历史」同一种噪音(那边已由 isAutosyncIdleRound 挡住)。
|
|
144
|
+
* 轮询不是活动;真干活(push/pull/冲突/失败)的卡片必须留着 —— 它们才解释「刚才发生了什么」。
|
|
145
|
+
*
|
|
146
|
+
* 判定只认 run 自己的 result.idle(由调度器收尾时写入),不在 UI 猜 skipReason。
|
|
147
|
+
*/
|
|
148
|
+
export function isIdleAutosyncRun(
|
|
149
|
+
state: Pick<RunState, 'kind' | 'status' | 'result'>,
|
|
150
|
+
): boolean {
|
|
151
|
+
if (state.kind !== 'autosync' || state.status === 'running') return false
|
|
152
|
+
const result = state.result
|
|
153
|
+
if (result === null || typeof result !== 'object') return false
|
|
154
|
+
return (result as { idle?: unknown }).idle === true
|
|
155
|
+
}
|
|
156
|
+
|
|
139
157
|
export class RunRegistry {
|
|
140
158
|
private readonly runs = new Map<string, RunState>()
|
|
141
159
|
private readonly retentionMs: number
|
package/src/index.sync.test.ts
CHANGED
|
@@ -73,6 +73,33 @@ test('parseSyncBody: git 分支 repoUrl 含 userinfo(token 拼 URL)→ 拒
|
|
|
73
73
|
);
|
|
74
74
|
});
|
|
75
75
|
|
|
76
|
+
test('issue #131 parseSyncBody: git 分支带 subdir → 归一后进配置;空串/缺省不落字段', async () => {
|
|
77
|
+
const deps = memCreds();
|
|
78
|
+
const withSubdir = await parseSyncBody({ repoUrl: 'https://github.com/foo/bar.git', subdir: ' DSH备份 ' }, deps);
|
|
79
|
+
assert.deepEqual(withSubdir, {
|
|
80
|
+
schemaVersion: 2,
|
|
81
|
+
transport: 'git',
|
|
82
|
+
git: { repoUrl: 'https://github.com/foo/bar.git', subdir: 'DSH备份' },
|
|
83
|
+
});
|
|
84
|
+
const blank = await parseSyncBody({ repoUrl: 'https://github.com/foo/bar.git', subdir: ' ' }, deps);
|
|
85
|
+
assert.deepEqual(blank, {
|
|
86
|
+
schemaVersion: 2,
|
|
87
|
+
transport: 'git',
|
|
88
|
+
git: { repoUrl: 'https://github.com/foo/bar.git' },
|
|
89
|
+
}, '空串 = 仓库根,不落字段(旧宿主/旧配置同形)');
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
test('issue #131 parseSyncBody: 非法 subdir(绝对路径 / .. / .git 段)→ SyncRouteError 且不回显裸值', async () => {
|
|
93
|
+
const deps = memCreds();
|
|
94
|
+
for (const subdir of ['/abs', 'a/../b', '.git', 'a\\b', 'a//b']) {
|
|
95
|
+
await assert.rejects(
|
|
96
|
+
() => parseSyncBody({ repoUrl: 'https://github.com/foo/bar.git', subdir }, deps),
|
|
97
|
+
(err: unknown) => err instanceof SyncRouteError && /子目录前缀不合法/.test(err.message),
|
|
98
|
+
'必须拒绝: ' + subdir,
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
|
|
76
103
|
/* ---------------- webdav 分支 ---------------- */
|
|
77
104
|
|
|
78
105
|
test('parseSyncBody: webdav 分支解析 url/username,password 写入 SYNC_WEBDAV_CREDENTIAL_REF', async () => {
|