@marktrue/dsh-mobile-remote 3.2.4-alpha.9 → 3.2.4-rc.1
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 +421 -0
- package/CONTRIBUTING.md +72 -17
- package/docs/03-api.md +144 -27
- package/docs/04-security.md +6 -0
- package/docs/06-install-run.md +6 -36
- package/docs/09-compatibility.md +13 -3
- package/docs/10-release.md +62 -70
- package/lib/endpoint-registry.js +21 -12
- package/lib/git-read-bundled-provider.js +8 -4
- package/lib/git-read-service.js +287 -35
- package/lib/host-update-capabilities.js +7 -1
- package/lib/index.js +1830 -66
- package/lib/npm-update-source.js +16 -16
- package/lib/plugin-self-update.js +17 -3
- package/lib/plugin-update-check.js +268 -0
- package/lib/plugin-update-controller.js +62 -6
- package/lib/plugin-update-transaction.js +38 -2
- package/lib/update-lock-arbiter.js +46 -6
- package/lib/update-supervisor.js +38 -5
- package/package.json +2 -2
package/lib/git-read-service.js
CHANGED
|
@@ -3,7 +3,14 @@ import { basename, dirname, isAbsolute, relative, resolve, sep } from "node:path
|
|
|
3
3
|
import { lstat, realpath } from "node:fs/promises";
|
|
4
4
|
import { createBundledGitReadProvider } from "./git-read-bundled-provider.js";
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
// task-28(issue #86 方案 B):GET 仍 ≤32;POST 支持 ≤128(URL 16KB 限制解除)。
|
|
7
|
+
const MAX_GRAPH_TIPS_GET = 32;
|
|
8
|
+
const MAX_GRAPH_TIPS_POST = 128;
|
|
9
|
+
const GRAPH_DEADLINE_MS = 25_000;
|
|
10
|
+
// issue #93(全部分支模式):refs/扫描/页大小。阈值必须高于正常仓库(211 分支)。
|
|
11
|
+
const GRAPH_ALL_PAGE_SIZE = 16;
|
|
12
|
+
const MAX_GRAPH_ALL_REFS = 4096;
|
|
13
|
+
const MAX_GRAPH_ALL_SCAN = 5000;
|
|
7
14
|
const MAX_TRACKED_FILES = 200;
|
|
8
15
|
const FILE_HISTORY_DEFAULT_LIMIT = 20;
|
|
9
16
|
const FILE_HISTORY_MAX_LIMIT = 100;
|
|
@@ -151,7 +158,7 @@ const historyStatus = (value) => {
|
|
|
151
158
|
};
|
|
152
159
|
|
|
153
160
|
/** Session-authorized read facade over an optional external or bundled provider. */
|
|
154
|
-
export function createGitReadService(ctx, { bundledProvider, now = () => Date.now(), snapshotTtlMs = 5 * 60_000, pollIntervalMs = 30_000, onChanged } = {}) {
|
|
161
|
+
export function createGitReadService(ctx, { bundledProvider, now = () => Date.now(), snapshotTtlMs = 5 * 60_000, pollIntervalMs = 30_000, onChanged, graphDeadlineMs = GRAPH_DEADLINE_MS, onSnapshotDisposed } = {}) {
|
|
155
162
|
const get = (name) => { try { return ctx.get?.(name); } catch { return undefined; } };
|
|
156
163
|
const external = get("gitReadProvider");
|
|
157
164
|
let externalAvailable = false;
|
|
@@ -239,12 +246,140 @@ export function createGitReadService(ctx, { bundledProvider, now = () => Date.no
|
|
|
239
246
|
return Array.isArray(records) ? records : null;
|
|
240
247
|
} catch { return null; }
|
|
241
248
|
};
|
|
249
|
+
const graphTimeout = () => failure("graph-timeout", 504);
|
|
250
|
+
/** 单次 provider 调用的 25s 硬截止(provider 自身超时/挂起兜底)。 */
|
|
251
|
+
const graphRace = async (factory, deadline) => {
|
|
252
|
+
const remaining = Math.max(1, deadline - Date.now());
|
|
253
|
+
const call = Promise.resolve().then(factory);
|
|
254
|
+
let timer = null;
|
|
255
|
+
const timeout = new Promise((_, reject) => {
|
|
256
|
+
timer = setTimeout(() => reject(graphTimeout()), remaining);
|
|
257
|
+
});
|
|
258
|
+
try {
|
|
259
|
+
return await Promise.race([call, timeout]);
|
|
260
|
+
} finally {
|
|
261
|
+
if (timer) clearTimeout(timer);
|
|
262
|
+
// 超时后底层 promise 仍可能 settle:吞掉,避免 unhandledRejection。
|
|
263
|
+
void call.catch(() => {});
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
/** provider.refs 一次映射(name → commit oid);无 refs 能力/调用失败返回 null → 逐 tip 回退。 */
|
|
267
|
+
const graphRefsByName = async (root, deadline) => {
|
|
268
|
+
if (typeof provider.refs !== "function") return null;
|
|
269
|
+
try {
|
|
270
|
+
const records = await graphRace(
|
|
271
|
+
() => provider.refs(root, { timeoutMs: Math.max(1, deadline - Date.now()) }),
|
|
272
|
+
deadline,
|
|
273
|
+
);
|
|
274
|
+
if (!Array.isArray(records)) return null;
|
|
275
|
+
const byName = new Map();
|
|
276
|
+
for (const record of records) {
|
|
277
|
+
if (!record || typeof record.name !== "string") continue;
|
|
278
|
+
byName.set(record.name, validOid(record.commitOid) ? String(record.commitOid) : null);
|
|
279
|
+
}
|
|
280
|
+
return byName;
|
|
281
|
+
} catch (error) {
|
|
282
|
+
if (error?.code === "graph-timeout") throw error;
|
|
283
|
+
return null; // 外部 provider 无 refs/调用失败 → 逐 tip(兼容旧契约)
|
|
284
|
+
}
|
|
285
|
+
};
|
|
286
|
+
/** 批量解析新快照 tips:一次 refs 映射优先,缺项才逐 tip resolveTip。 */
|
|
287
|
+
const resolveGraphTips = async (root, selected, deadline) => {
|
|
288
|
+
const byName = await graphRefsByName(root, deadline);
|
|
289
|
+
const resolved = [];
|
|
290
|
+
for (const tip of selected) {
|
|
291
|
+
let oid;
|
|
292
|
+
if (byName && byName.has(tip.name)) {
|
|
293
|
+
oid = byName.get(tip.name);
|
|
294
|
+
if (!validOid(oid)) throw failure("graph-tip-invalid", 409);
|
|
295
|
+
} else {
|
|
296
|
+
try {
|
|
297
|
+
oid = await graphRace(() => provider.resolveTip(root, tip.name), deadline);
|
|
298
|
+
} catch (error) {
|
|
299
|
+
if (error?.code === "graph-timeout") throw error;
|
|
300
|
+
if (tip.name === "HEAD" && error?.code === "git-command-failed") continue;
|
|
301
|
+
throw failure("graph-tip-invalid", 409);
|
|
302
|
+
}
|
|
303
|
+
if (!validOid(oid)) throw failure("graph-tip-invalid", 409);
|
|
304
|
+
}
|
|
305
|
+
if (tip.tipOid != null && tip.tipOid.toLowerCase() !== oid.toLowerCase()) throw failure("graph-tip-invalid", 409);
|
|
306
|
+
resolved.push({ name: tip.name, tipOid: oid });
|
|
307
|
+
if (Date.now() > deadline) throw graphTimeout();
|
|
308
|
+
}
|
|
309
|
+
return resolved;
|
|
310
|
+
};
|
|
311
|
+
/** 续页/前后校验:一次 refs 映射比对 tips 未移动;失败抛 graph-stale。 */
|
|
312
|
+
const verifyGraphTips = async (root, tips, deadline) => {
|
|
313
|
+
const byName = await graphRefsByName(root, deadline);
|
|
314
|
+
for (const tip of tips) {
|
|
315
|
+
let current;
|
|
316
|
+
if (byName && byName.has(tip.name)) current = byName.get(tip.name);
|
|
317
|
+
else {
|
|
318
|
+
try {
|
|
319
|
+
current = await graphRace(() => provider.resolveTip(root, tip.name), deadline);
|
|
320
|
+
} catch (error) {
|
|
321
|
+
if (error?.code === "graph-timeout") throw error;
|
|
322
|
+
throw stale();
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
if (!validOid(current) || current.toLowerCase() !== tip.tipOid.toLowerCase()) throw stale();
|
|
326
|
+
if (Date.now() > deadline) throw graphTimeout();
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
/**
|
|
330
|
+
* issue #93:解析**全部分支**(refs/heads/* + refs/remotes/*,排除 /HEAD)。
|
|
331
|
+
* tags 不参与 tips;返回按 name 排序的 `{name, tipOid}`,供 provider.graph 使用。
|
|
332
|
+
* 超内部保护上限抛明确 graph-too-many-refs(绝不静默截断)。
|
|
333
|
+
*/
|
|
334
|
+
const resolveAllGraphRefs = async (root, deadline) => {
|
|
335
|
+
const byName = await graphRefsByName(root, deadline);
|
|
336
|
+
if (byName === null) throw failure("git-provider-unavailable", 503);
|
|
337
|
+
const refs = [];
|
|
338
|
+
for (const [name, oid] of byName) {
|
|
339
|
+
if (!name.startsWith("refs/heads/") && !name.startsWith("refs/remotes/")) continue;
|
|
340
|
+
if (name.endsWith("/HEAD")) continue;
|
|
341
|
+
if (!validOid(oid)) continue; // 非 commit 目标的 branch 不进图(与 provider 语义一致)
|
|
342
|
+
refs.push({ name, tipOid: String(oid) });
|
|
343
|
+
if (Date.now() > deadline) throw graphTimeout();
|
|
344
|
+
}
|
|
345
|
+
refs.sort((a, b) => compareText(a.name, b.name));
|
|
346
|
+
if (refs.length > MAX_GRAPH_ALL_REFS) {
|
|
347
|
+
throw failure("graph-too-many-refs", 400, `all branch refs exceed ${MAX_GRAPH_ALL_REFS}`);
|
|
348
|
+
}
|
|
349
|
+
return refs;
|
|
350
|
+
};
|
|
351
|
+
/** 全部分支快照指纹:name+oid 排序后 sha256;任一分支新增/移动/删除都会变。 */
|
|
352
|
+
const allRefsFingerprint = (refs) => createHash("sha256")
|
|
353
|
+
.update(refs.map((ref) => `${ref.name}:${ref.tipOid}`).join("\n"))
|
|
354
|
+
.digest("hex");
|
|
355
|
+
const verifyAllGraphRefs = async (snapshot, root, deadline) => {
|
|
356
|
+
const current = await resolveAllGraphRefs(root, deadline);
|
|
357
|
+
if (allRefsFingerprint(current) !== snapshot.refFingerprint) throw stale();
|
|
358
|
+
};
|
|
359
|
+
/** graph 专用:readRefRecords 纳入同一 absolute deadline(挂起→504,不返回半页)。 */
|
|
360
|
+
const readRefRecordsWithin = async (root, deadline) => {
|
|
361
|
+
if (typeof provider.refs !== "function") return null;
|
|
362
|
+
try {
|
|
363
|
+
const records = await graphRace(
|
|
364
|
+
() => provider.refs(root, { timeoutMs: Math.max(1, deadline - Date.now()) }),
|
|
365
|
+
deadline,
|
|
366
|
+
);
|
|
367
|
+
return Array.isArray(records) ? records : null;
|
|
368
|
+
} catch (error) {
|
|
369
|
+
if (error?.code === "graph-timeout") throw error;
|
|
370
|
+
return null;
|
|
371
|
+
}
|
|
372
|
+
};
|
|
242
373
|
const capabilities = () => {
|
|
243
374
|
const base = provider.capabilities?.() ?? { available: true, reason: null };
|
|
244
375
|
return {
|
|
245
376
|
contractVersion: "1.1.0", available: base.available !== false,
|
|
246
377
|
reason: ["git-provider-unavailable", "workspace-registry-unavailable"].includes(base.reason) ? base.reason : null,
|
|
247
378
|
readOnly: true, provider: provider === external ? "external" : "bundled",
|
|
379
|
+
// task-28:POST graph 的 tips 上限(旧宿主缺该字段,App 回退 5/5)。
|
|
380
|
+
graphTips: { max: MAX_GRAPH_TIPS_POST, getMax: MAX_GRAPH_TIPS_GET },
|
|
381
|
+
// issue #93:全部分支模式(all=true)与内部保护阈值;旧宿主缺该字段 → App 回退选择档。
|
|
382
|
+
graphAll: { pageSize: GRAPH_ALL_PAGE_SIZE, maxRefs: MAX_GRAPH_ALL_REFS, maxScan: MAX_GRAPH_ALL_SCAN },
|
|
248
383
|
features: {
|
|
249
384
|
repository: true, branches: true, graph: true, commit: true, worktree: true, preview: true,
|
|
250
385
|
// Both flags are independent and additive: refsDetail can be
|
|
@@ -427,60 +562,162 @@ export function createGitReadService(ctx, { bundledProvider, now = () => Date.no
|
|
|
427
562
|
stats, files: { items, total: allFiles.length, nextCursor },
|
|
428
563
|
};
|
|
429
564
|
},
|
|
430
|
-
|
|
565
|
+
/**
|
|
566
|
+
* 图分页。task-28:`maxTips` 由 HTTP 层按传输方式传入(GET=32 / POST=128),
|
|
567
|
+
* 续页可省略 tips;snapshotId/cursor 与传输方式无关(GET/POST 互通)。
|
|
568
|
+
*/
|
|
569
|
+
async graph(sessionId, repositoryId, { tips, snapshotId, cursor, limit = 100, maxTips = MAX_GRAPH_TIPS_GET, all = false, focus } = {}) {
|
|
431
570
|
const authorized = await binding(sessionId, repositoryId);
|
|
432
571
|
prune();
|
|
433
|
-
const
|
|
572
|
+
const deadline = Date.now() + graphDeadlineMs;
|
|
573
|
+
const tipCap = maxTips === MAX_GRAPH_TIPS_POST ? MAX_GRAPH_TIPS_POST : MAX_GRAPH_TIPS_GET;
|
|
574
|
+
const allMode = all === true;
|
|
575
|
+
// issue #93:全部分支模式固定每页 16;5/10 选择集保持原 limit 语义。
|
|
576
|
+
const pageSize = allMode
|
|
577
|
+
? GRAPH_ALL_PAGE_SIZE
|
|
578
|
+
: Math.max(1, Math.min(200, Number(limit) || 100));
|
|
434
579
|
let snapshot, offset = 0;
|
|
580
|
+
let snapshotCreatedNow = false;
|
|
435
581
|
if (snapshotId !== undefined || cursor !== undefined) {
|
|
436
582
|
if (!snapshotId || !cursor) throw stale();
|
|
437
583
|
snapshot = snapshots.get(snapshotId);
|
|
438
584
|
if (!snapshot || snapshot.sessionId !== sessionId || snapshot.repositoryId !== repositoryId || snapshot.root !== authorized.root || snapshot.expiresAt <= now()) throw stale();
|
|
585
|
+
if (allMode !== (snapshot.all === true)) throw stale();
|
|
439
586
|
offset = snapshot.cursors.get(cursor);
|
|
440
587
|
if (!Number.isInteger(offset)) throw stale();
|
|
588
|
+
} else if (allMode) {
|
|
589
|
+
// 全部分支:忽略 tips 选择集,自行解析 refs/heads/* + refs/remotes/*。
|
|
590
|
+
const refs = await resolveAllGraphRefs(authorized.root, deadline);
|
|
591
|
+
if (refs.length === 0) throw failure("graph-tip-invalid", 400, "no branch refs");
|
|
592
|
+
const refFingerprint = allRefsFingerprint(refs);
|
|
593
|
+
let focusOid = null;
|
|
594
|
+
let focusIndex = null;
|
|
595
|
+
if (typeof focus === "string" && focus !== "") {
|
|
596
|
+
if (!validRef(focus) && !validOid(focus)) throw failure("graph-focus-invalid", 400);
|
|
597
|
+
if (validOid(focus)) {
|
|
598
|
+
focusOid = String(focus).toLowerCase();
|
|
599
|
+
} else {
|
|
600
|
+
const hit = refs.find((ref) => ref.name === focus);
|
|
601
|
+
if (!hit) throw failure("graph-focus-invalid", 400, "focus is not a branch ref");
|
|
602
|
+
focusOid = String(hit.tipOid).toLowerCase();
|
|
603
|
+
}
|
|
604
|
+
// 与图相同的 topo/date 顺序定位 focus;扫描上限明确报错,不静默截断。
|
|
605
|
+
const scan = await graphRace(
|
|
606
|
+
() => provider.graph(authorized.root, {
|
|
607
|
+
refs: refs.map((ref) => ref.tipOid),
|
|
608
|
+
offset: 0,
|
|
609
|
+
limit: MAX_GRAPH_ALL_SCAN,
|
|
610
|
+
timeoutMs: Math.max(1, deadline - Date.now()),
|
|
611
|
+
}),
|
|
612
|
+
deadline,
|
|
613
|
+
);
|
|
614
|
+
if (scan && scan.timedOut === true) throw graphTimeout();
|
|
615
|
+
const rows = Array.isArray(scan) ? scan : [];
|
|
616
|
+
focusIndex = rows.findIndex((row) => String(row?.oid ?? "").toLowerCase() === focusOid);
|
|
617
|
+
if (focusIndex < 0) throw failure("graph-focus-not-found", 409, "focus commit not found within scan limit");
|
|
618
|
+
}
|
|
619
|
+
const pageStart = focusIndex === null ? 0 : Math.floor(focusIndex / pageSize) * pageSize;
|
|
620
|
+
snapshot = {
|
|
621
|
+
id: randomUUID(), sessionId, repositoryId, root: authorized.root,
|
|
622
|
+
all: true, branchRefs: refs, refFingerprint,
|
|
623
|
+
tips: refs.map((ref) => ({ name: ref.name, tipOid: ref.tipOid })),
|
|
624
|
+
focusOid, focusIndex, pageStart,
|
|
625
|
+
expiresAt: now() + snapshotTtlMs, cursors: new Map(),
|
|
626
|
+
};
|
|
627
|
+
snapshotCreatedNow = true;
|
|
628
|
+
snapshots.set(snapshot.id, snapshot);
|
|
629
|
+
keepBounded(snapshots, 128);
|
|
630
|
+
offset = pageStart;
|
|
441
631
|
} else {
|
|
442
632
|
const selected = tips === undefined ? [{ name: "HEAD", tipOid: null }] : tips;
|
|
443
|
-
if (!Array.isArray(selected) || selected.length >
|
|
633
|
+
if (!Array.isArray(selected) || selected.length > tipCap) throw failure("graph-too-many-tips", 400, `tips limit is ${tipCap}`);
|
|
444
634
|
if (selected.length === 0) throw failure("graph-tip-invalid", 400);
|
|
445
635
|
const names = selected.map((tip) => tip?.name);
|
|
446
636
|
if (new Set(names).size !== names.length || names.some((name) => !validRef(name)) || selected.some((tip) => tip?.tipOid != null && !validOid(tip.tipOid))) throw failure("graph-tip-invalid", 400);
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
catch (error) {
|
|
452
|
-
if (tip.name === "HEAD" && error?.code === "git-command-failed") continue;
|
|
453
|
-
throw failure("graph-tip-invalid", 409);
|
|
454
|
-
}
|
|
455
|
-
if (!validOid(oid)) throw failure("graph-tip-invalid", 409);
|
|
456
|
-
if (tip.tipOid != null && tip.tipOid.toLowerCase() !== oid.toLowerCase()) throw failure("graph-tip-invalid", 409);
|
|
457
|
-
resolved.push({ name: tip.name, tipOid: oid });
|
|
458
|
-
}
|
|
459
|
-
snapshot = { id: randomUUID(), sessionId, repositoryId, root: authorized.root, tips: resolved, expiresAt: now() + snapshotTtlMs, cursors: new Map() };
|
|
637
|
+
// P0 批量解析:128 tips 只做一次 provider.refs(外部 provider 无 refs 才逐 tip)。
|
|
638
|
+
const resolved = await resolveGraphTips(authorized.root, selected, deadline);
|
|
639
|
+
snapshot = { id: randomUUID(), sessionId, repositoryId, root: authorized.root, all: false, tips: resolved, expiresAt: now() + snapshotTtlMs, cursors: new Map(), pageStart: 0 };
|
|
640
|
+
snapshotCreatedNow = true;
|
|
460
641
|
snapshots.set(snapshot.id, snapshot);
|
|
461
642
|
keepBounded(snapshots, 128);
|
|
462
643
|
}
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
644
|
+
// 统一 snapshot 清理策略(re-review P1):
|
|
645
|
+
// - 纯 graph-timeout:本次请求**新建且尚未交付**的 initial 快照可删;
|
|
646
|
+
// 已交付/续页快照保留至 TTL,同 cursor 可重试;
|
|
647
|
+
// - graph-stale / ref 变化 / 鉴权失败等确定性失效:立即删除。
|
|
648
|
+
// 该策略覆盖 pre/post verify、provider.graph、装饰 readRefRecords 所有阶段。
|
|
649
|
+
const disposeSnapshot = () => {
|
|
650
|
+
if (snapshots.delete(snapshot.id)) onSnapshotDisposed?.(snapshot.id);
|
|
651
|
+
};
|
|
652
|
+
const disposeOnGraphFailure = (error) => {
|
|
653
|
+
if (error?.code === "graph-timeout") {
|
|
654
|
+
if (snapshotCreatedNow) disposeSnapshot();
|
|
655
|
+
return;
|
|
656
|
+
}
|
|
657
|
+
disposeSnapshot();
|
|
658
|
+
};
|
|
659
|
+
try {
|
|
660
|
+
// 全部分支:指纹覆盖全部分支 refs(新增/移动/删除都 stale);5/10:只校验选择集。
|
|
661
|
+
if (snapshot.all === true) await verifyAllGraphRefs(snapshot, authorized.root, deadline);
|
|
662
|
+
else await verifyGraphTips(authorized.root, snapshot.tips, deadline);
|
|
663
|
+
} catch (error) {
|
|
664
|
+
disposeOnGraphFailure(error);
|
|
665
|
+
throw error;
|
|
467
666
|
}
|
|
667
|
+
const graphRefs = snapshot.all === true
|
|
668
|
+
? snapshot.branchRefs.map((ref) => ref.tipOid)
|
|
669
|
+
: snapshot.tips.map((tip) => tip.tipOid);
|
|
468
670
|
let rawCommits;
|
|
469
|
-
try {
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
671
|
+
try {
|
|
672
|
+
rawCommits = await graphRace(
|
|
673
|
+
() => provider.graph(authorized.root, {
|
|
674
|
+
refs: graphRefs,
|
|
675
|
+
offset,
|
|
676
|
+
limit: pageSize,
|
|
677
|
+
timeoutMs: Math.max(1, deadline - Date.now()),
|
|
678
|
+
}),
|
|
679
|
+
deadline,
|
|
680
|
+
);
|
|
681
|
+
// provider 自报 timedOut(不得把半页当完整页返回)。
|
|
682
|
+
if (rawCommits && rawCommits.timedOut === true) throw graphTimeout();
|
|
683
|
+
} catch (error) {
|
|
684
|
+
// 超时是明确失败(504 graph-timeout),不做 stale 转换(否则面板看不到)。
|
|
685
|
+
// 已交付续页快照保留;非确定性 provider 错误保留快照供重试(verify 失败才 stale)。
|
|
686
|
+
if (error?.code === "graph-timeout") {
|
|
687
|
+
disposeOnGraphFailure(error);
|
|
688
|
+
throw error;
|
|
689
|
+
}
|
|
690
|
+
try {
|
|
691
|
+
if (snapshot.all === true) await verifyAllGraphRefs(snapshot, authorized.root, deadline);
|
|
692
|
+
else await verifyGraphTips(authorized.root, snapshot.tips, deadline);
|
|
693
|
+
} catch (verifyError) {
|
|
694
|
+
// 混合错误:provider.graph 先抛临时 503,随后为判 stale 的二次
|
|
695
|
+
// verify 因 deadline 挂起 —— 必须原样透传 504,并按统一策略
|
|
696
|
+
// (已交付保留 / 未交付新建清理),不能误判成 ref 真变化的 stale。
|
|
697
|
+
if (verifyError?.code === "graph-timeout") {
|
|
698
|
+
disposeOnGraphFailure(verifyError);
|
|
699
|
+
throw verifyError;
|
|
700
|
+
}
|
|
701
|
+
disposeSnapshot();
|
|
702
|
+
throw stale();
|
|
475
703
|
}
|
|
476
704
|
throw error;
|
|
477
705
|
}
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
706
|
+
try {
|
|
707
|
+
if (snapshot.all === true) await verifyAllGraphRefs(snapshot, authorized.root, deadline);
|
|
708
|
+
else await verifyGraphTips(authorized.root, snapshot.tips, deadline);
|
|
709
|
+
} catch (error) {
|
|
710
|
+
disposeOnGraphFailure(error);
|
|
711
|
+
throw error;
|
|
712
|
+
}
|
|
713
|
+
let records;
|
|
714
|
+
try {
|
|
715
|
+
records = await readRefRecordsWithin(authorized.root, deadline);
|
|
716
|
+
} catch (error) {
|
|
717
|
+
// 装饰(refs 记录)阶段超时同样按统一策略处理:已交付快照可重试。
|
|
718
|
+
disposeOnGraphFailure(error);
|
|
719
|
+
throw error;
|
|
482
720
|
}
|
|
483
|
-
const records = await readRefRecords(authorized.root);
|
|
484
721
|
const commits = (Array.isArray(rawCommits) ? rawCommits : []).map((row) => {
|
|
485
722
|
const oid = String(row.oid ?? "");
|
|
486
723
|
const legacy = Array.isArray(row.refs) ? row.refs.map(String) : [];
|
|
@@ -496,13 +733,28 @@ export function createGitReadService(ctx, { bundledProvider, now = () => Date.no
|
|
|
496
733
|
refs: legacy, refsDetail: refDetails.refsDetail, tagsDetail: refDetails.tagsDetail,
|
|
497
734
|
};
|
|
498
735
|
});
|
|
736
|
+
// issue #93:双向分页。nextCursor 更早(offset+本页),prevCursor 更新(offset-页)。
|
|
499
737
|
let nextCursor = null;
|
|
500
738
|
if (commits.length === pageSize) {
|
|
501
739
|
nextCursor = randomUUID();
|
|
502
740
|
snapshot.cursors.set(nextCursor, offset + commits.length);
|
|
503
|
-
keepBounded(snapshot.cursors, 128);
|
|
504
741
|
}
|
|
505
|
-
|
|
742
|
+
let prevCursor = null;
|
|
743
|
+
if (offset > 0) {
|
|
744
|
+
prevCursor = randomUUID();
|
|
745
|
+
snapshot.cursors.set(prevCursor, Math.max(0, offset - pageSize));
|
|
746
|
+
}
|
|
747
|
+
keepBounded(snapshot.cursors, 256);
|
|
748
|
+
return {
|
|
749
|
+
repositoryId, snapshotId: snapshot.id, tips: snapshot.tips, commits,
|
|
750
|
+
nextCursor, prevCursor,
|
|
751
|
+
all: snapshot.all === true,
|
|
752
|
+
pageSize,
|
|
753
|
+
pageStart: offset,
|
|
754
|
+
focusOid: snapshot.all === true ? snapshot.focusOid : null,
|
|
755
|
+
hasNewer: offset > 0,
|
|
756
|
+
hasOlder: nextCursor !== null,
|
|
757
|
+
};
|
|
506
758
|
},
|
|
507
759
|
async files(sessionId, repositoryId, { q, limit } = {}) {
|
|
508
760
|
const authorized = await binding(sessionId, repositoryId);
|
|
@@ -110,7 +110,13 @@ export function hostManagerAcceptsBundle(bundle) {
|
|
|
110
110
|
if (!bundle || typeof bundle !== "object") {
|
|
111
111
|
return { ok: false, reason: HOST_MANAGER_REASON.NOT_UPDATABLE };
|
|
112
112
|
}
|
|
113
|
-
|
|
113
|
+
// DSH 0.2.2-rc.1:`updatable: boolean`;rc.2:`update?: 'registry' | 'git'`,
|
|
114
|
+
// 不再提供 updatable。两种行契约都接受,否则 rc.2 会静默降级到重启通道。
|
|
115
|
+
// 有 rc.2 的 update 字段时以它为准;只有旧行才看 updatable,避免两字段冲突时误放行。
|
|
116
|
+
const updatable = bundle.update !== undefined
|
|
117
|
+
? (bundle.update === "registry" || bundle.update === "git")
|
|
118
|
+
: bundle.updatable === true;
|
|
119
|
+
if (!updatable) {
|
|
114
120
|
return { ok: false, reason: HOST_MANAGER_REASON.NOT_UPDATABLE };
|
|
115
121
|
}
|
|
116
122
|
if (bundle.readOnlyReason !== undefined) {
|