dsh-config-manager 0.4.2 → 0.5.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/README.md +24 -0
- package/README.zh-CN.md +10 -0
- package/lib/adapters/mcp.d.ts +9 -0
- package/lib/adapters/mcp.js +37 -0
- package/lib/adapters/plugins.js +10 -2
- package/lib/adapters/pnpm-workspace.js +1 -1
- package/lib/adapters/self.d.ts +2 -0
- package/lib/adapters/self.js +18 -2
- package/lib/adapters/workspaces.js +1 -1
- package/lib/cli/restore-resume.js +1 -1
- package/lib/cli/web/page.js +2 -2
- package/lib/client.d.ts +19 -41
- package/lib/client.js +863 -722
- package/lib/core/access-mode.d.ts +25 -0
- package/lib/core/access-mode.js +28 -0
- package/lib/core/backup.d.ts +11 -0
- package/lib/core/backup.js +27 -0
- package/lib/core/env-lock-lifecycle.d.ts +17 -3
- package/lib/core/env-lock-lifecycle.js +38 -0
- package/lib/core/external-failure.d.ts +9 -0
- package/lib/core/external-failure.js +50 -0
- package/lib/core/local-plugin-host.d.ts +9 -7
- package/lib/core/local-plugin-host.js +109 -15
- package/lib/core/local-plugin-pack.d.ts +20 -0
- package/lib/core/local-plugin-pack.js +18 -3
- package/lib/core/mcp-connector-store.d.ts +13 -0
- package/lib/core/mcp-connector-store.js +16 -1
- package/lib/core/messages-core.d.ts +45 -0
- package/lib/core/messages-core.js +92 -0
- package/lib/core/messages.d.ts +1 -0
- package/lib/core/messages.js +6 -0
- package/lib/core/model-tool-plans.d.ts +66 -0
- package/lib/core/model-tool-plans.js +128 -0
- package/lib/core/model-tools.d.ts +96 -8
- package/lib/core/model-tools.js +568 -31
- package/lib/core/phase3-host.js +10 -2
- package/lib/core/plugin-data-registry.d.ts +1 -1
- package/lib/core/plugin-data-registry.js +1 -1
- package/lib/core/restore-plan-fingerprint.d.ts +2 -0
- package/lib/core/restore-plan-fingerprint.js +18 -0
- package/lib/core/restore-resume.d.ts +1 -1
- package/lib/core/restore-resume.js +1 -1
- package/lib/core/restore.d.ts +5 -0
- package/lib/core/restore.js +4 -1
- package/lib/core/types.d.ts +12 -0
- package/lib/foreign/claude-sessions.d.ts +1 -1
- package/lib/foreign/claude-sessions.js +1 -1
- package/lib/foreign/registry.js +1 -1
- package/lib/foreign/types.d.ts +1 -1
- package/lib/index.d.ts +15 -15
- package/lib/index.js +65 -72
- package/lib/market/git-file-writer.js +1 -1
- package/lib/market/github-repos.js +1 -1
- package/lib/market/market-config.js +1 -1
- package/lib/market/messages-market.js +1 -1
- package/lib/market/my-repo.js +1 -1
- package/lib/market/prepare.js +1 -1
- package/lib/market/reader.js +2 -2
- package/lib/market/repo-url.d.ts +1 -1
- package/lib/market/security.js +2 -2
- package/lib/market/star-cache.d.ts +1 -1
- package/lib/market/types.d.ts +1 -1
- package/lib/market/types.js +1 -1
- package/lib/market/url.js +1 -1
- package/lib/routes/backup.js +17 -9
- package/lib/routes/index.d.ts +1 -1
- package/lib/routes/kit.d.ts +42 -3
- package/lib/routes/kit.js +43 -3
- package/lib/routes/market.d.ts +1 -1
- package/lib/routes/market.js +3 -60
- package/lib/routes/model-tools-deps.d.ts +41 -0
- package/lib/routes/model-tools-deps.js +18 -0
- package/lib/routes/recovery.js +5 -3
- package/lib/routes/request-trust.d.ts +28 -0
- package/lib/routes/request-trust.js +65 -0
- package/lib/routes/route-support.d.ts +18 -26
- package/lib/routes/route-support.js +19 -32
- package/lib/routes/snapshots.d.ts +1 -1
- package/lib/routes/snapshots.js +4 -40
- package/lib/routes/sync.js +40 -28
- package/lib/schema/index.d.ts +2 -2
- package/lib/schema/index.js +2 -2
- package/lib/schema/section-registry.d.ts +5 -3
- package/lib/schema/section-registry.js +7 -3
- package/lib/security/secret-scanner.js +1 -1
- package/lib/sync/apply-bundle.d.ts +50 -0
- package/lib/sync/apply-bundle.js +60 -0
- package/lib/sync/autosync-scheduler.d.ts +9 -0
- package/lib/sync/autosync-scheduler.js +118 -89
- package/lib/sync/backup-scheduler.js +5 -4
- package/lib/sync/blob-store.d.ts +2 -2
- package/lib/sync/git/git-transport.d.ts +12 -0
- package/lib/sync/git/git-transport.js +50 -2
- package/lib/sync/merge.d.ts +2 -0
- package/lib/sync/merge.js +28 -0
- package/lib/sync/messages.d.ts +4 -0
- package/lib/sync/messages.js +9 -2
- package/lib/sync/s3/s3-transport.d.ts +1 -1
- package/lib/sync/s3/s3-transport.js +1 -1
- package/lib/sync/sync-engine.d.ts +4 -4
- package/lib/sync/sync-engine.js +25 -26
- package/lib/sync/sync-scope-boot.d.ts +34 -0
- package/lib/sync/sync-scope-boot.js +71 -0
- package/lib/sync/sync-scope.d.ts +103 -0
- package/lib/sync/sync-scope.js +229 -0
- package/lib/sync/sync-selection.d.ts +17 -4
- package/lib/sync/sync-selection.js +40 -14
- package/lib/sync/transport.d.ts +4 -1
- package/lib/sync/transport.js +6 -0
- package/lib/sync/webdav/webdav-transport.js +1 -1
- package/lib/sync/workspace-merge.d.ts +36 -0
- package/lib/sync/workspace-merge.js +152 -0
- package/lib/ui/backup-schedule.d.ts +13 -2
- package/lib/ui/backup-schedule.js +3 -0
- package/lib/ui/snapshots-view.d.ts +16 -0
- package/lib/ui/snapshots-view.js +21 -0
- package/lib/utils/env-lock.d.ts +96 -0
- package/lib/utils/env-lock.js +332 -111
- package/lib/utils/messages-utils.d.ts +6 -0
- package/lib/utils/messages-utils.js +17 -1
- package/lib/utils/patch-yaml.js +1 -1
- package/lib/utils/zip.js +1 -1
- package/package.json +3 -2
- package/src/adapters/mcp.test.ts +28 -0
- package/src/adapters/mcp.ts +33 -0
- package/src/adapters/plugins.test.ts +49 -0
- package/src/adapters/plugins.ts +9 -1
- package/src/adapters/pnpm-workspace.ts +1 -1
- package/src/adapters/self.test.ts +39 -1
- package/src/adapters/self.ts +20 -2
- package/src/adapters/workspaces.ts +1 -1
- package/src/cli/restore-resume.ts +1 -1
- package/src/cli/web/page.ts +2 -2
- package/src/client/about/AboutPanel.tsx +8 -1
- package/src/client/about/about-view.test.ts +1 -1
- package/src/client/about/about-view.ts +1 -1
- package/src/client/api.ts +1 -6
- package/src/client/chat/chat-entry-view.test.ts +1 -1
- package/src/client/chat/chat-slots.ts +1 -1
- package/src/client/chat/rollback-diff-tab.ts +1 -1
- package/src/client/client-types.ts +1 -1
- package/src/client/common/access-mode.ts +21 -0
- package/src/client/common/routes.ts +1 -5
- package/src/client/css-scale-guard.test.ts +1 -1
- package/src/client/home/HomePanel.tsx +34 -6
- package/src/client/library/ArtifactRow.tsx +14 -2
- package/src/client/library/LibraryPanel.tsx +44 -0
- package/src/client/locales/about.ts +6 -0
- package/src/client/locales/overview.ts +18 -2
- package/src/client/locales/sessions.ts +3 -0
- package/src/client/market/MyConfigsView.tsx +1 -1
- package/src/client/market/market-api.ts +2 -14
- package/src/client/market/market-locales.ts +1 -1
- package/src/client/market/market-view.ts +3 -3
- package/src/client/market/my-configs-api.ts +1 -1
- package/src/client/market/my-configs-view.ts +1 -1
- package/src/client/recovery/recovery-locales.test.ts +1 -1
- package/src/client/run-store.ts +1 -1
- package/src/client/sync/SyncSectionPickerDialog.tsx +0 -5
- package/src/client/sync/history-model.test.ts +28 -7
- package/src/client/sync/history-model.ts +6 -3
- package/src/client/sync/sync-locales.ts +10 -4
- package/src/client/sync/sync-view.ts +1 -1
- package/src/core/access-mode.ts +37 -0
- package/src/core/analyzer-cache.test.ts +1 -1
- package/src/core/backup.test.ts +45 -1
- package/src/core/backup.ts +25 -0
- package/src/core/disk-usage.test.ts +2 -0
- package/src/core/env-lock-lifecycle.ts +33 -3
- package/src/core/external-failure.test.ts +60 -0
- package/src/core/external-failure.ts +54 -0
- package/src/core/integrity-extra-entries.test.ts +1 -1
- package/src/core/local-plugin-host.test.ts +134 -0
- package/src/core/local-plugin-host.ts +122 -17
- package/src/core/local-plugin-pack.ts +39 -3
- package/src/core/mcp-connector-store.ts +26 -1
- package/src/core/messages-core.ts +94 -0
- package/src/core/messages.ts +6 -0
- package/src/core/model-tool-plans.test.ts +111 -0
- package/src/core/model-tool-plans.ts +170 -0
- package/src/core/model-tools.test.ts +212 -12
- package/src/core/model-tools.ts +710 -38
- package/src/core/phase3-host.ts +10 -2
- package/src/core/phase3-production-integration.test.ts +43 -0
- package/src/core/plugin-data-registry.ts +1 -1
- package/src/core/restore-plan-fingerprint.ts +19 -0
- package/src/core/restore-resume.ts +1 -1
- package/src/core/restore.ts +9 -1
- package/src/core/types.ts +12 -0
- package/src/foreign/claude-sessions.ts +3 -3
- package/src/foreign/registry.ts +1 -1
- package/src/foreign/types.ts +1 -1
- package/src/index.ts +96 -103
- package/src/market/git-file-writer.ts +1 -1
- package/src/market/github-repos.test.ts +1 -1
- package/src/market/github-repos.ts +1 -1
- package/src/market/market-config.ts +1 -1
- package/src/market/messages-market.ts +1 -1
- package/src/market/my-repo.test.ts +1 -1
- package/src/market/my-repo.ts +1 -1
- package/src/market/prepare.test.ts +1 -1
- package/src/market/prepare.ts +1 -1
- package/src/market/reader.ts +2 -2
- package/src/market/repo-url.ts +1 -1
- package/src/market/security.ts +2 -2
- package/src/market/star-cache.ts +1 -1
- package/src/market/types.ts +1 -1
- package/src/market/url.test.ts +1 -1
- package/src/market/url.ts +1 -1
- package/src/profiles/dsh-profile-copy-rollback.test.ts +1 -1
- package/src/routes/backup.ts +16 -9
- package/src/routes/index.ts +1 -1
- package/src/routes/kit.ts +71 -5
- package/src/routes/market.ts +2 -59
- package/src/routes/model-tools-deps.ts +56 -0
- package/src/routes/recovery.ts +5 -3
- package/src/routes/request-trust.ts +97 -0
- package/src/routes/route-support.ts +49 -36
- package/src/routes/snapshots.ts +4 -40
- package/src/routes/sync.ts +39 -27
- package/src/schema/index.ts +2 -2
- package/src/schema/manifest-schema.test.ts +2 -2
- package/src/schema/registry.test.ts +1 -1
- package/src/schema/section-registry.ts +9 -4
- package/src/security/redaction.test.ts +1 -1
- package/src/security/secret-scanner.test.ts +2 -2
- package/src/security/secret-scanner.ts +1 -1
- package/src/sync/apply-bundle.ts +104 -0
- package/src/sync/autosync-scheduler.test.ts +180 -6
- package/src/sync/autosync-scheduler.ts +132 -92
- package/src/sync/backup-scheduler.test.ts +11 -4
- package/src/sync/backup-scheduler.ts +5 -4
- package/src/sync/blob-store.ts +2 -2
- package/src/sync/git/git-transport.test.ts +62 -0
- package/src/sync/git/git-transport.ts +54 -3
- package/src/sync/merge.ts +29 -0
- package/src/sync/messages.ts +9 -2
- package/src/sync/s3/s3-transport.ts +1 -1
- package/src/sync/sync-engine.test.ts +238 -2
- package/src/sync/sync-engine.ts +25 -26
- package/src/sync/sync-preview-push.test.ts +2 -1
- package/src/sync/sync-scope-boot.ts +87 -0
- package/src/sync/sync-scope.test.ts +154 -0
- package/src/sync/sync-scope.ts +256 -0
- package/src/sync/sync-selection.test.ts +76 -2
- package/src/sync/sync-selection.ts +40 -13
- package/src/sync/transport.test.ts +21 -1
- package/src/sync/transport.ts +12 -0
- package/src/sync/webdav/webdav-delete-index-unreadable.test.ts +2 -2
- package/src/sync/webdav/webdav-transport.ts +1 -1
- package/src/sync/workspace-merge.test.ts +110 -0
- package/src/sync/workspace-merge.ts +180 -0
- package/src/ui/backup-schedule.test.ts +5 -0
- package/src/ui/backup-schedule.ts +21 -2
- package/src/ui/session-issue-labels.ts +1 -1
- package/src/ui/snapshots-view.test.ts +32 -0
- package/src/ui/snapshots-view.ts +34 -0
- package/src/utils/env-lock.test.ts +242 -9
- package/src/utils/env-lock.ts +247 -13
- package/src/utils/messages-utils.ts +17 -1
- package/src/utils/patch-yaml.ts +1 -1
- package/src/utils/zip.ts +1 -1
- package/src/client/CLIENT_DEPENDENCIES.md +0 -94
|
@@ -30,7 +30,7 @@ import type { RunRegistry } from '../core/run-registry.ts';
|
|
|
30
30
|
import type { ConfigAdapter, HostContext, SecretScanner } from '../core/types.ts';
|
|
31
31
|
import type { MutationLockPort } from '../utils/env-lock.ts';
|
|
32
32
|
import type { LockBlockReason } from '../utils/env-lock.ts';
|
|
33
|
-
import { runWithMutationLock, EnvironmentLockUnavailableError, LOCK_BLOCK_MESSAGE, LOCK_BLOCK_BRIEF } from '../utils/env-lock.ts';
|
|
33
|
+
import { runWithMutationLock, EnvironmentLockUnavailableError, LOCK_BLOCK_MESSAGE, LOCK_BLOCK_BRIEF, lockSkipToken } from '../utils/env-lock.ts';
|
|
34
34
|
import { Exporter } from '../core/exporter.ts';
|
|
35
35
|
import { randomBytes } from 'node:crypto';
|
|
36
36
|
import { join } from 'node:path';
|
|
@@ -341,12 +341,13 @@ export class BackupScheduler {
|
|
|
341
341
|
// (LOCK_BLOCK_MESSAGE),避免同一句指引在多条路径上再次漂移(#27 只接了 autosync,
|
|
342
342
|
// 本路径漏接 → 实测 9 天内 57 次静默跳过,用户无从知道要回收残留锁)。
|
|
343
343
|
if (err instanceof EnvironmentLockUnavailableError) {
|
|
344
|
-
|
|
345
|
-
|
|
344
|
+
// stale 与 stale-degraded 同属「重试不会自愈」,都走 warn(都带显式回收指引)。
|
|
345
|
+
if (err.reason === 'stale' || err.reason === 'stale-degraded') {
|
|
346
|
+
this.log.warn(`${trigger}跳过:${LOCK_BLOCK_MESSAGE[err.reason]}`);
|
|
346
347
|
} else {
|
|
347
348
|
this.log.info(`${trigger}跳过:${LOCK_BLOCK_MESSAGE[err.reason]}`);
|
|
348
349
|
}
|
|
349
|
-
const skipped: BackupRunResult = { status: 'skipped', skipReason:
|
|
350
|
+
const skipped: BackupRunResult = { status: 'skipped', skipReason: lockSkipToken(err.reason), consecutiveFailures: cfg.consecutiveFailures };
|
|
350
351
|
// skipReason 保持稳定的机器 token(客户端据此本地化);历史摘要用同源**短**文案,
|
|
351
352
|
// 不留裸 token(issue #31 ②:中文前缀 + 英文 token 的历史行)。
|
|
352
353
|
await this.appendHistory(skipped, err.reason, manual);
|
package/src/sync/blob-store.ts
CHANGED
|
@@ -9,13 +9,13 @@
|
|
|
9
9
|
* (`<section>.blobs.json` / WebDAV 的 JSON 载荷里的 blobRefs)。内容没变 = 同一个哈希 =
|
|
10
10
|
* 已在仓里 = 不再传输。快照保留策略裁剪快照时,无人引用的 blob 由 GC 回收。
|
|
11
11
|
*
|
|
12
|
-
* 兼容性(**这是对外格式变更**,必须同步 docs/
|
|
12
|
+
* 兼容性(**这是对外格式变更**,必须同步 docs/contracts/):
|
|
13
13
|
* - 外置只发生在**通道侧**:只有 transport 传了 BlobSink 才启用;引擎/导出/导入看到的
|
|
14
14
|
* 仍是普通 FilesSection(含 data)。本地散文件副本、加密快照、加密载荷一律不外置。
|
|
15
15
|
* - 旧版插件读新格式:`<section>.blobs.json` 不是 FilesSection,旧版 layout 会当成
|
|
16
16
|
* 「文件分区目录缺失」—— git 通道 missingFileDir='empty' 会降级为空分区(丢内容但不崩),
|
|
17
17
|
* WebDAV 通道 blobRefs 也认不出。因此 /sync/status 不下发版本协商,**跨版本混用不被支持**:
|
|
18
|
-
* 两端插件版本应当一致(与既有「同步通道不做协议协商」的定位一致,见 docs/
|
|
18
|
+
* 两端插件版本应当一致(与既有「同步通道不做协议协商」的定位一致,见 docs/contracts/)。
|
|
19
19
|
*/
|
|
20
20
|
import type { FilesSection, SectionId } from '../schema/types.ts';
|
|
21
21
|
import { sha256Hex } from '../utils/hashing.ts';
|
|
@@ -19,6 +19,7 @@ import type { SyncSnapshot } from '../transport.ts';
|
|
|
19
19
|
import type { FilesSection, SectionData, SectionId } from '../../schema/types.ts';
|
|
20
20
|
import { sha256Hex } from '../../utils/hashing.ts';
|
|
21
21
|
import { resetWorkdirLockChainsForTest, workdirLockPath } from '../../utils/workdir-lock.ts';
|
|
22
|
+
import { isLocalOnlyExternalFailure, localOnlyFailureReason } from '../../core/external-failure.ts';
|
|
22
23
|
|
|
23
24
|
/* ---------------- helpers ---------------- */
|
|
24
25
|
|
|
@@ -1877,3 +1878,64 @@ test('RV1-F8:错误文本与工作副本自检返回体都不含 userinfo(to
|
|
|
1877
1878
|
assert.ok(!hostErr.message.includes(localDir), '本机路径同样不得原样回显: ' + hostErr.message);
|
|
1878
1879
|
}
|
|
1879
1880
|
});
|
|
1881
|
+
|
|
1882
|
+
/* ---------------- 本机提交身份(issue:commit exit 128 ⇒ NEEDS_ATTENTION ⇒ 误升 SAFE MODE) ---------------- */
|
|
1883
|
+
|
|
1884
|
+
test('本机缺 git 身份导致 commit 失败 → kind=config、不可重试、文案点名 git config,并标记 localOnly', async (t) => {
|
|
1885
|
+
const dir = await makeGitWorkDir(t);
|
|
1886
|
+
const calls: CallRecord[] = [];
|
|
1887
|
+
const transport = new GitTransport(makeOptions({
|
|
1888
|
+
workDir: dir,
|
|
1889
|
+
exec: mockExec(calls, {
|
|
1890
|
+
failOn: { match: 'commit', code: 128, stderr: "fatal: unable to auto-detect email address (got 'runner@BUILD.(none)')" },
|
|
1891
|
+
}),
|
|
1892
|
+
}));
|
|
1893
|
+
await assert.rejects(transport.upload(sampleSnapshot()), (err: unknown) => {
|
|
1894
|
+
assert.ok(err instanceof SyncTransportError, '必须仍是统一传输层错误');
|
|
1895
|
+
assert.equal(err.kind, 'config', '身份缺失必须归 config(不是 auth/notfound/unknown)');
|
|
1896
|
+
assert.equal(err.retryable, false, '本机配置问题重试无意义');
|
|
1897
|
+
// 文案必须指向本机 git 配置:用户此前只看到「备份已跳过」,完全不知道要配身份
|
|
1898
|
+
assert.match(err.message, /git config/);
|
|
1899
|
+
assert.match(err.message, /user\.email/);
|
|
1900
|
+
// localOnly 标记 = phase3 不把插件升进 durable SAFE MODE(一个可修的配置问题不该冻结全部写入)
|
|
1901
|
+
assert.ok(isLocalOnlyExternalFailure(err), '必须打 localOnly 标记');
|
|
1902
|
+
assert.equal(localOnlyFailureReason(err), 'git-identity');
|
|
1903
|
+
return true;
|
|
1904
|
+
});
|
|
1905
|
+
});
|
|
1906
|
+
|
|
1907
|
+
test('已有工作副本缺提交身份 → 进入工作副本时自动补写仓库级 user.name/user.email(不覆盖已有值)', async (t) => {
|
|
1908
|
+
const dir = await makeTempDir(t);
|
|
1909
|
+
await fs.mkdir(path.join(dir, '.git'), { recursive: true });
|
|
1910
|
+
const writes: string[] = [];
|
|
1911
|
+
const probes: string[] = [];
|
|
1912
|
+
const exec: GitExecFn = async (_cmd, args) => {
|
|
1913
|
+
const joined = args.join(' ');
|
|
1914
|
+
if (joined.includes('--get user.name') || joined.includes('--get user.email')) {
|
|
1915
|
+
probes.push(joined);
|
|
1916
|
+
return { stdout: '', stderr: '', code: 1 }; // 1 = 未配置
|
|
1917
|
+
}
|
|
1918
|
+
if (joined.includes('config user.name') || joined.includes('config user.email')) writes.push(joined);
|
|
1919
|
+
return { stdout: '', stderr: '', code: 0 };
|
|
1920
|
+
};
|
|
1921
|
+
const transport = new GitTransport(makeOptions({ workDir: dir, exec }));
|
|
1922
|
+
await transport.list();
|
|
1923
|
+
assert.equal(probes.length, 2, '必须探测两个键: ' + probes.join(' | '));
|
|
1924
|
+
assert.equal(writes.length, 2, '两个键都缺失时必须都补写: ' + writes.join(' | '));
|
|
1925
|
+
assert.ok(writes.some((w) => w.includes('DSH Config Sync')), '补写默认作者名: ' + writes.join(' | '));
|
|
1926
|
+
assert.ok(writes.some((w) => w.includes('sync@dsh.local')), '补写默认作者邮箱: ' + writes.join(' | '));
|
|
1927
|
+
|
|
1928
|
+
// 已有值(用户自己配的)→ 绝不覆盖
|
|
1929
|
+
const dir2 = await makeTempDir(t);
|
|
1930
|
+
await fs.mkdir(path.join(dir2, '.git'), { recursive: true });
|
|
1931
|
+
const writes2: string[] = [];
|
|
1932
|
+
const exec2: GitExecFn = async (_cmd, args) => {
|
|
1933
|
+
const joined = args.join(' ');
|
|
1934
|
+
if (joined.includes('--get user.name')) return { stdout: 'Alice\n', stderr: '', code: 0 };
|
|
1935
|
+
if (joined.includes('--get user.email')) return { stdout: 'alice@example.com\n', stderr: '', code: 0 };
|
|
1936
|
+
if (joined.includes('config user.name') || joined.includes('config user.email')) writes2.push(joined);
|
|
1937
|
+
return { stdout: '', stderr: '', code: 0 };
|
|
1938
|
+
};
|
|
1939
|
+
await new GitTransport(makeOptions({ workDir: dir2, exec: exec2 })).list();
|
|
1940
|
+
assert.deepEqual(writes2, [], '已有身份不得被覆盖: ' + writes2.join(' | '));
|
|
1941
|
+
});
|
|
@@ -36,6 +36,7 @@ import {
|
|
|
36
36
|
classifyNetworkErrorText, computeSnapshotMeta, DEFAULT_SYNC_TIMEOUT_MS, isEncryptedSections,
|
|
37
37
|
SyncTransportError, withSyncRetry,
|
|
38
38
|
} from '../transport.ts';
|
|
39
|
+
import { markLocalOnlyExternalFailure } from '../../core/external-failure.ts';
|
|
39
40
|
import type {
|
|
40
41
|
SyncProbeResult, SyncRetryOptions, SyncSnapshot, SyncSnapshotMeta, SyncTransport, SyncTransportErrorOptions,
|
|
41
42
|
} from '../transport.ts';
|
|
@@ -698,6 +699,11 @@ export class GitTransport implements SyncTransport {
|
|
|
698
699
|
// 而失败面表现为旧地址的网络超时(真机:局域网地址 → Tailscale 地址后同步长期失败),
|
|
699
700
|
// 用户会误判成网络/凭据问题。
|
|
700
701
|
await this.reconcileOrigin();
|
|
702
|
+
// 真机 issue:仓库级提交身份此前**只在首次 clone 时**写过(见本方法末尾),已有 .git 的分支
|
|
703
|
+
// 直接 return —— 换机器/换工作副本/用户清过本地配置之后,每次 commit 都以 exit 128 失败
|
|
704
|
+
// ("unable to auto-detect email address"),交易停在 NEEDS_ATTENTION,用户只看到
|
|
705
|
+
// 「备份已跳过:环境锁被占用」。这里在每次进入工作副本时 best-effort 补齐身份。
|
|
706
|
+
await this.ensureCommitIdentity();
|
|
701
707
|
this.repoReady = true;
|
|
702
708
|
return;
|
|
703
709
|
}
|
|
@@ -721,6 +727,34 @@ export class GitTransport implements SyncTransport {
|
|
|
721
727
|
this.repoReady = true;
|
|
722
728
|
}
|
|
723
729
|
|
|
730
|
+
/**
|
|
731
|
+
* 补写工作副本的提交身份(best-effort;只补**缺失**的键,绝不覆盖用户自己配的值)。
|
|
732
|
+
*
|
|
733
|
+
* 为什么需要:git 的提交身份是「仓库级 or 全局」二选一,本插件只写仓库级(不改用户全局配置)。
|
|
734
|
+
* 一旦这个工作副本被别人重建、被 relink、或在没配全局身份的机器上首次同步,仓库级键就没了 ——
|
|
735
|
+
* 之后每次 commit 都 exit 128,而错误面在用户那里只剩一句「备份已跳过」。
|
|
736
|
+
*
|
|
737
|
+
* 纪律:探测(git config --get)失败 → 当作「不知道」而不写(不拿猜测覆盖用户配置);
|
|
738
|
+
* 写入失败 → 静默放过(不是同步失败)。真缺身份时下一条 commit 仍会以 kind='config'
|
|
739
|
+
* 的可操作文案失败,并且**不再升级 SAFE MODE**(见 raiseGitFailure 的 localOnly 标记)。
|
|
740
|
+
*/
|
|
741
|
+
private async ensureCommitIdentity(): Promise<void> {
|
|
742
|
+
const isMissing = async (key: string): Promise<boolean> => {
|
|
743
|
+
try {
|
|
744
|
+
const r = await this.runGit(['config', '--get', key], { allowNonZero: true });
|
|
745
|
+
return r.code !== 0 || r.stdout.trim() === '';
|
|
746
|
+
} catch {
|
|
747
|
+
return false;
|
|
748
|
+
}
|
|
749
|
+
};
|
|
750
|
+
try {
|
|
751
|
+
if (await isMissing('user.name')) await this.runGit(['config', 'user.name', this.o.author.name]);
|
|
752
|
+
if (await isMissing('user.email')) await this.runGit(['config', 'user.email', this.o.author.email]);
|
|
753
|
+
} catch {
|
|
754
|
+
/* best-effort:写入失败留给后续 commit 以 config 分类暴露,不在这里阻断同步 */
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
|
|
724
758
|
/**
|
|
725
759
|
* 首次 clone(issue #122):partial clone + sparse-checkout,只落地同步内容。
|
|
726
760
|
*
|
|
@@ -1208,11 +1242,16 @@ export class GitTransport implements SyncTransport {
|
|
|
1208
1242
|
if (err instanceof GitTransportError) throw err;
|
|
1209
1243
|
// 注入的 exec 实现可能直接抛错(默认实现只返回非零 code)——同样归一为带分类的传输层错误
|
|
1210
1244
|
const detail = err instanceof Error ? err.message : String(err);
|
|
1211
|
-
|
|
1245
|
+
const classified = classifyNetworkErrorText(detail);
|
|
1246
|
+
const failure = new GitTransportError(
|
|
1212
1247
|
// argv 里含 repoUrl 原文(clone/ls-remote/remote set-url -- <url>)→ 必须经 mask 才进文案
|
|
1213
|
-
|
|
1214
|
-
|
|
1248
|
+
classified.kind === 'config'
|
|
1249
|
+
? this.msg('sync.git.identityMissing', { err: this.mask(detail, token) })
|
|
1250
|
+
: this.msg('sync.git.cmdFailed', { args: this.mask(args.join(' '), token), code: 'exec', err: this.mask(detail, token) }),
|
|
1251
|
+
{ ...classified, cause: err },
|
|
1215
1252
|
);
|
|
1253
|
+
// 与 raiseGitFailure 同口径:本机身份缺失不升级全局阻断(localOnly 标记)
|
|
1254
|
+
throw classified.kind === 'config' ? markLocalOnlyExternalFailure(failure, 'git-identity') : failure;
|
|
1216
1255
|
} finally {
|
|
1217
1256
|
if (cleanup) await cleanup();
|
|
1218
1257
|
}
|
|
@@ -1230,6 +1269,18 @@ export class GitTransport implements SyncTransport {
|
|
|
1230
1269
|
if (SSH_HOST_KEY_RE.test(combined)) {
|
|
1231
1270
|
throw new GitTransportError(this.hostKeyMessage(), { kind: 'auth', retryable: false });
|
|
1232
1271
|
}
|
|
1272
|
+
// 本机提交身份缺失(kind='config'):与网络/远端/令牌无关,本机一步配置就能修好。
|
|
1273
|
+
// 文案点名 git config,并打 localOnly 标记 —— phase3 据此不升 durable SAFE MODE
|
|
1274
|
+
// (真机 issue:一个缺 user.email 的 commit 把插件变成「全部写入 423」)。
|
|
1275
|
+
if (classified.kind === 'config') {
|
|
1276
|
+
throw markLocalOnlyExternalFailure(
|
|
1277
|
+
new GitTransportError(
|
|
1278
|
+
this.msg('sync.git.identityMissing', { err: this.mask(result.stderr, token) }),
|
|
1279
|
+
classified,
|
|
1280
|
+
),
|
|
1281
|
+
'git-identity',
|
|
1282
|
+
);
|
|
1283
|
+
}
|
|
1233
1284
|
// 推送 + 鉴权失败:git 原文只说「认证失败」——换成能照做的说明(令牌失效 / 无写权限 / 远端禁用了密码推送)
|
|
1234
1285
|
// issue #115:clone 的鉴权失败原文(remote: Write access to repository not granted / 403)读不出「缺哪种权限」,
|
|
1235
1286
|
// 换成点名 Contents: Read and write 的说明 —— 否则用户只会以为令牌坏了(细粒度 PAT 常只勾了 Administration)
|
package/src/sync/merge.ts
CHANGED
|
@@ -12,6 +12,8 @@
|
|
|
12
12
|
* 5. remoteHash == ancestorHash → keepLocal(仅本地改)
|
|
13
13
|
* 6. 双侧相对祖先都改 → 精细合并:
|
|
14
14
|
* - JSON 分区:递归对象合并(mergeJsonValues),冲突路径精确到叶子('namespaces.general.value.theme')
|
|
15
|
+
* - 分区专属钩子(GRANULAR_MERGES,当前 = workspaces):按记录 id 做并集(sessionIds 取并集、
|
|
16
|
+
* 其它字段逐键三方取舍),见 workspace-merge.ts —— 通用 JSON 合并对数组只会判冲突
|
|
15
17
|
* - FilesSection:逐 relativePath 合并,两侧都改的文本文件再走行级三方合并(mergeBytesThreeWay)
|
|
16
18
|
* - 无残留冲突 → decision='merge'(merged + autoMerged 计数)
|
|
17
19
|
* - 有残留冲突 → decision='conflict'(merged 为 undefined:绝不把半成品当结果)
|
|
@@ -30,6 +32,8 @@
|
|
|
30
32
|
import type { FilesSection, SectionData, SectionId } from '../schema/types.ts';
|
|
31
33
|
import { hashSection } from './sync-state.ts';
|
|
32
34
|
import { mergeBytesThreeWay, mergeJsonValues, type TextMergeConflict } from './text-merge.ts';
|
|
35
|
+
import { mergeWorkspacesSection } from './workspace-merge.ts';
|
|
36
|
+
import type { GranularMerger } from './workspace-merge.ts';
|
|
33
37
|
|
|
34
38
|
/**
|
|
35
39
|
* 分区级决胜结果(三方合并,2026-10 收口):
|
|
@@ -285,6 +289,17 @@ function mergeFilesSectionGranular(
|
|
|
285
289
|
return { merged: { version: 1, files: mergedFiles }, conflicts, mergePoints };
|
|
286
290
|
}
|
|
287
291
|
|
|
292
|
+
/**
|
|
293
|
+
* 分区专属的记录级合并钩子(issue #127)。
|
|
294
|
+
*
|
|
295
|
+
* 缺省 = 走下面的通用 JSON / 文件合并。当前只有 workspaces:它的 `sessionIds` 必须取并集
|
|
296
|
+
* (通用 JSON 合并对数组一律判冲突 —— 两侧各自挂过会话就永远冲突,且裁决任一侧都会丢另一侧的
|
|
297
|
+
* 会话归属)。钩子返回 undefined = 形状不认识,仍交回通用路径(畸形数据由形状闸门拒绝)。
|
|
298
|
+
*/
|
|
299
|
+
const GRANULAR_MERGES: Partial<Record<SectionId, GranularMerger>> = {
|
|
300
|
+
workspaces: mergeWorkspacesSection,
|
|
301
|
+
};
|
|
302
|
+
|
|
288
303
|
/** 单分区三方合并(决策链见文件头注释)。 */
|
|
289
304
|
function mergeSectionTriple(
|
|
290
305
|
id: SectionId,
|
|
@@ -347,6 +362,20 @@ function mergeSectionTriple(
|
|
|
347
362
|
conflicts: [{ path: '$', kind: 'key', reason: 'section', autoMergeAttempted: false, local, remote, ancestor: aData }],
|
|
348
363
|
};
|
|
349
364
|
}
|
|
365
|
+
// ③' 分区专属记录级合并(**早于 ancestor 闸门**):workspaces 的 sessionIds 是并集语义 ——
|
|
366
|
+
// 没有祖先时也应并集(否则首轮同步就整分区冲突),字段取值分歧由钩子逐键如实报冲突。
|
|
367
|
+
const granular = GRANULAR_MERGES[id];
|
|
368
|
+
if (granular !== undefined) {
|
|
369
|
+
const res = granular(local, remote, aData);
|
|
370
|
+
if (res !== undefined) {
|
|
371
|
+
if (res.conflicts.length > 0) return { id, decision: 'conflict', conflicts: res.conflicts };
|
|
372
|
+
const merged = res.merged;
|
|
373
|
+
const mh = hashSection(merged);
|
|
374
|
+
if (mh === h.remote) return { id, decision: 'useRemote', merged, conflicts: [] };
|
|
375
|
+
if (mh === h.local) return { id, decision: 'keepLocal', merged, conflicts: [] };
|
|
376
|
+
return { id, decision: 'merge', merged, conflicts: [], autoMerged: res.mergePoints };
|
|
377
|
+
}
|
|
378
|
+
}
|
|
350
379
|
if (h.ancestor === undefined) {
|
|
351
380
|
return {
|
|
352
381
|
id,
|
package/src/sync/messages.ts
CHANGED
|
@@ -43,7 +43,11 @@ export const zh = {
|
|
|
43
43
|
// ---------- 内容寻址 blob 仓 ----------
|
|
44
44
|
'sync.blobMissing': '内容的 blob 缺失({hash},{path}):远端仓不完整,拒绝降级为空分区',
|
|
45
45
|
'sync.webdav.blobHashInvalid': '内容哈希形状非法,拒绝写入 blob 仓: {hash}',
|
|
46
|
-
// ----------
|
|
46
|
+
// ---------- 按档案分作用域(sync-scope) ----------
|
|
47
|
+
'sync.scopeDirCreateFailed': '无法创建档案同步目录 {dir}:{reason}',
|
|
48
|
+
'sync.scopeAdoptFailed': '继承 {file} 失败:{reason}',
|
|
49
|
+
'sync.scopeAdopted': '档案 {profile} 已从历史同步根继承:{files}',
|
|
50
|
+
'sync.scopeBootFailed': '档案作用域继承失败:{reason}', // ---------- 审查队列 ----------
|
|
47
51
|
'sync.reviewQueueNotObject': 'sync-review-queue.json 损坏:必须是对象',
|
|
48
52
|
'sync.reviewQueueItemsNotArray': 'sync-review-queue.json 损坏:items 必须是数组',
|
|
49
53
|
'sync.reviewQueueItemNotObject': 'sync-review-queue.json 损坏:每个 item 必须是对象',
|
|
@@ -124,7 +128,10 @@ export const en: Record<keyof typeof zh, string> = {
|
|
|
124
128
|
'sync.layoutFileSectionDirMissing': 'Snapshot is missing the file section directory {prefix} ({section})',
|
|
125
129
|
'sync.blobMissing': 'The blob for {path} is missing ({hash}): the remote store is incomplete, refusing to degrade to an empty section',
|
|
126
130
|
'sync.webdav.blobHashInvalid': 'Malformed content hash; refusing to write to the blob store: {hash}',
|
|
127
|
-
'sync.
|
|
131
|
+
'sync.scopeDirCreateFailed': 'Cannot create the profile sync directory {dir}: {reason}',
|
|
132
|
+
'sync.scopeAdoptFailed': 'Failed to adopt {file}: {reason}',
|
|
133
|
+
'sync.scopeAdopted': 'Profile {profile} adopted settings from the shared sync root: {files}',
|
|
134
|
+
'sync.scopeBootFailed': 'Failed to adopt the shared sync settings for this profile: {reason}', 'sync.reviewQueueNotObject': 'sync-review-queue.json is corrupt: must be an object',
|
|
128
135
|
'sync.reviewQueueItemsNotArray': 'sync-review-queue.json is corrupt: items must be an array',
|
|
129
136
|
'sync.reviewQueueItemNotObject': 'sync-review-queue.json is corrupt: every item must be an object',
|
|
130
137
|
'sync.reviewQueueItemFieldsMissing': 'sync-review-queue.json is corrupt: an item must contain the strings id/sectionId/kind/description',
|
|
@@ -413,7 +413,7 @@ export class S3Transport implements SyncTransport {
|
|
|
413
413
|
* 变了 / 对象没了 → 按并发写中止(零写入)。
|
|
414
414
|
*
|
|
415
415
|
* **不是原子的**:复核与 PUT 之间仍有窗口(服务端不支持条件写就没有真正的解),
|
|
416
|
-
* 比无保护强、比 If-Match 弱 —— 如实登记在 docs/
|
|
416
|
+
* 比无保护强、比 If-Match 弱 —— 如实登记在 docs/adr/0003。
|
|
417
417
|
* 其它方言(etag)与「服务端不给 ETag」两种情况一律直接放行,不改既有行为。
|
|
418
418
|
*/
|
|
419
419
|
private async reassertIndexEtag(etag: string | undefined, secret: string): Promise<void> {
|
|
@@ -26,7 +26,8 @@ import { createAdapters } from '../adapters/index.ts';
|
|
|
26
26
|
import { makeContext, MemSnapshotStore } from '../adapters/test-helpers.ts';
|
|
27
27
|
import { Importer } from '../core/importer.ts';
|
|
28
28
|
import type { SectionId } from '../schema/types.ts';
|
|
29
|
-
import type { SectionData } from '../schema/types.ts';
|
|
29
|
+
import type { SectionData, WorkspacesSection } from '../schema/types.ts';
|
|
30
|
+
import { AUTO_SYNC_OPT_IN_SECTION_IDS } from '../schema/section-registry.ts';
|
|
30
31
|
import { Phase3Recovery, readSafeModeMarkerSync } from '../core/phase3-host.ts';
|
|
31
32
|
import type { JournalRunContext } from '../core/phase3-host.ts';
|
|
32
33
|
import type { MutationLockContext } from '../utils/env-lock.ts';
|
|
@@ -1459,6 +1460,102 @@ test('hasLocalChanges: 从未同步→true;推后无改动→false;本地改
|
|
|
1459
1460
|
}
|
|
1460
1461
|
});
|
|
1461
1462
|
|
|
1463
|
+
/**
|
|
1464
|
+
* 连接器存储(mcp 分区的**第二个**数据源,用户实际配 MCP 的地方):`storages/mcp_connector.json`。
|
|
1465
|
+
* 形态取自 core/mcp-connector-store.ts:361-378(`tables.connections` 表,按 key 索引)。
|
|
1466
|
+
*/
|
|
1467
|
+
function seedConnectorStore(ctx: ReturnType<typeof makeContext>, args: string[]): void {
|
|
1468
|
+
const store = {
|
|
1469
|
+
tables: {
|
|
1470
|
+
connections: {
|
|
1471
|
+
citra: {
|
|
1472
|
+
key: 'citra',
|
|
1473
|
+
connectorId: 'citra',
|
|
1474
|
+
kind: 'manual',
|
|
1475
|
+
name: 'Citra',
|
|
1476
|
+
serverName: 'citra',
|
|
1477
|
+
transport: 'stdio',
|
|
1478
|
+
command: 'npx',
|
|
1479
|
+
args,
|
|
1480
|
+
enabled: true,
|
|
1481
|
+
},
|
|
1482
|
+
},
|
|
1483
|
+
},
|
|
1484
|
+
};
|
|
1485
|
+
void ctx.fs.writeFile('storages/mcp_connector.json', new TextEncoder().encode(JSON.stringify(store)));
|
|
1486
|
+
}
|
|
1487
|
+
|
|
1488
|
+
/**
|
|
1489
|
+
* 复现:自动同步只放行 'auto' 档可选分区(当前 = mcp,src/index.ts:2796-2810),
|
|
1490
|
+
* 而 hasLocalChanges 只比 portable 分区(sync-engine.ts:1397-1413)⇒ 用户勾了 mcp 后
|
|
1491
|
+
* **只改连接器存储**时判「无改动」,Phase C 不 push(autosync-scheduler.ts:800-819)⇒ 改动永不单独上行。
|
|
1492
|
+
*
|
|
1493
|
+
* 注意(实测,见报告):patch 行(cordis.patch.yml 的 dsh-mcp-client 行)那条路径**已被顺带覆盖** ——
|
|
1494
|
+
* plugins(portable)也导出全部 patch 行(src/adapters/plugins.ts:430-434),所以改 patch 行会让 plugins
|
|
1495
|
+
* 的 hash 变。连接器存储没有任何 portable 分区覆盖(pluginData 是 deviceSpecific),这才是真空洞。
|
|
1496
|
+
*/
|
|
1497
|
+
test('hasLocalChanges 必须覆盖「已勾选的 mcp」:仅改连接器存储也要判有改动', async () => {
|
|
1498
|
+
const tmp = await fs.mkdtemp(path.join(os.tmpdir(), 'dsh-sync-engine-haslocal-optin-'));
|
|
1499
|
+
try {
|
|
1500
|
+
const ctx = makeContext('win32', 'C:\\Users\\alice');
|
|
1501
|
+
seedSource(ctx);
|
|
1502
|
+
seedMcp(ctx);
|
|
1503
|
+
seedConnectorStore(ctx, ['-y', '@sylphx/citra']);
|
|
1504
|
+
const transport = new MemSyncTransport();
|
|
1505
|
+
// 自动同步装配形态:push 不带 sections,optInSections = 'auto' 档 = ['mcp']
|
|
1506
|
+
const engine = makeEngine({ ctx, transport, stateDir: tmp, extra: { optInSections: ['mcp'] } });
|
|
1507
|
+
|
|
1508
|
+
const first = await engine.push({ snapshotId: 'sync-optin-001' });
|
|
1509
|
+
assert.ok(first.sections.includes('mcp'), '放行的 mcp 进快照: ' + first.sections.join(','));
|
|
1510
|
+
assert.equal(await engine.hasLocalChanges(), false, '刚推完 → 无改动(mcp 基线已记)');
|
|
1511
|
+
// 稳定性:判定字节若含易变字段(exportedAt = 导出当刻),这里会恒为 true ⇒ 每轮轮询真推一次空推
|
|
1512
|
+
assert.equal(await engine.hasLocalChanges(), false, '再判一次仍须是「无改动」(判定字节必须稳定)');
|
|
1513
|
+
|
|
1514
|
+
// 只改连接器存储:portable 分区与 patch 行一律不动
|
|
1515
|
+
seedConnectorStore(ctx, ['-y', '@sylphx/citra@2']);
|
|
1516
|
+
assert.equal(
|
|
1517
|
+
await engine.hasLocalChanges(), true,
|
|
1518
|
+
'勾选 mcp 后仅连接器存储改动必须被识别为有改动(否则自动同步永不推它)',
|
|
1519
|
+
);
|
|
1520
|
+
} finally {
|
|
1521
|
+
await fs.rm(tmp, { recursive: true, force: true });
|
|
1522
|
+
}
|
|
1523
|
+
});
|
|
1524
|
+
|
|
1525
|
+
test('hasLocalChanges: 未勾选分区既不参与判定、也不进载荷(注入 sections 收窄范围)', async () => {
|
|
1526
|
+
const tmp = await fs.mkdtemp(path.join(os.tmpdir(), 'dsh-sync-engine-haslocal-scope-'));
|
|
1527
|
+
try {
|
|
1528
|
+
const ctx = makeContext('win32', 'C:\\Users\\alice');
|
|
1529
|
+
seedSource(ctx);
|
|
1530
|
+
seedMcp(ctx);
|
|
1531
|
+
await ctx.fs.writeFile('skills/coding.md', Buffer.from('# Coding\n', 'utf8'));
|
|
1532
|
+
const transport = new MemSyncTransport();
|
|
1533
|
+
// 高级模式只勾了 settings(= effectiveSections 注入),mcp 未勾
|
|
1534
|
+
const engine = makeEngine({ ctx, transport, stateDir: tmp, extra: { sections: ['settings'] } });
|
|
1535
|
+
const report = await engine.push({ snapshotId: 'sync-scope-001' });
|
|
1536
|
+
assert.deepEqual(report.sections, ['settings'], '载荷只含已勾选分区: ' + report.sections.join(','));
|
|
1537
|
+
assert.equal(await engine.hasLocalChanges(), false, '刚推完 → 无改动');
|
|
1538
|
+
|
|
1539
|
+
// 未勾选分区(skills 文件、mcp patch 行)改动 → 不得被判为有改动
|
|
1540
|
+
await ctx.fs.writeFile('skills/coding.md', Buffer.from('# Coding v2\n', 'utf8'));
|
|
1541
|
+
ctx.patchFile.lines.set('mcp-citra', {
|
|
1542
|
+
lineId: 'mcp-citra',
|
|
1543
|
+
raw: {
|
|
1544
|
+
id: 'mcp-citra',
|
|
1545
|
+
name: 'dsh-mcp-client',
|
|
1546
|
+
config: { serverName: 'citra', command: 'npx', args: ['-y', '@sylphx/citra@2'] },
|
|
1547
|
+
},
|
|
1548
|
+
});
|
|
1549
|
+
assert.equal(await engine.hasLocalChanges(), false, '未勾选分区改动不参与「有无改动」比较');
|
|
1550
|
+
|
|
1551
|
+
// 已勾选分区改动 → 必须识别
|
|
1552
|
+
ctx.settings.ns.set('general', { value: { theme: 'light', language: 'zh-CN' }, revision: 9, secrets: [] });
|
|
1553
|
+
assert.equal(await engine.hasLocalChanges(), true, '已勾选分区改动必须被识别');
|
|
1554
|
+
} finally {
|
|
1555
|
+
await fs.rm(tmp, { recursive: true, force: true });
|
|
1556
|
+
}
|
|
1557
|
+
});
|
|
1558
|
+
|
|
1462
1559
|
test('push + webdav 快照级跳过:同 id 同内容二次 push → 不重复 PUT 快照文件(端到端组合)', async () => {
|
|
1463
1560
|
const tmp = await fs.mkdtemp(path.join(os.tmpdir(), 'dsh-sync-engine-webdav-skip-'));
|
|
1464
1561
|
try {
|
|
@@ -1744,7 +1841,9 @@ test('issue #107 源码守卫:/sync/apply-items 的祖先副本按会话加密
|
|
|
1744
1841
|
assert.ok(/ancestorPassword: applyDecryptPassword/.test(source), '有密码 → ancestorPassword 必须透传(写密文副本)');
|
|
1745
1842
|
assert.ok(/suppressAncestor: true/.test(source), '没密码 → 必须 suppressAncestor(宁可不落,也绝不落明文)');
|
|
1746
1843
|
assert.ok(/\.\.\.ancestorOpts/.test(options), 'applyItems 调用必须展开 ancestorOpts(否则上面两处判定全是死代码)');
|
|
1747
|
-
|
|
1844
|
+
// 按档案分槽位后,路由用本地 `passwordRef`(= syncScope.passwordRef)而不是直接调 syncPasswordRef;
|
|
1845
|
+
// 守卫的意图不变:密码来源必须是已存凭据(客户端不持有密码),不接受字面量密码。
|
|
1846
|
+
assert.ok(/resolveSyncPassword\(\s*(?:syncPasswordRef|passwordRef)\('DECRYPT'/.test(source), '密码来源必须回落到已存凭据(客户端不持有密码)');
|
|
1748
1847
|
assert.ok(source.includes('encrypted: preview.encrypted === true,'), '同步会话必须登记「远端快照是否加密」(只存布尔,不存密码)');
|
|
1749
1848
|
assert.equal(/ancestorPassword:\s*session\./.test(source), false, '会话里绝不存密码字段');
|
|
1750
1849
|
});
|
|
@@ -3090,3 +3189,140 @@ test('F3/②:手动删快照但没有放弃码(通道无该字段 / 非非
|
|
|
3090
3189
|
});
|
|
3091
3190
|
|
|
3092
3191
|
|
|
3192
|
+
|
|
3193
|
+
/* ------------------------------------------- issue #127:workspaces 成为手动可选同步分区 */
|
|
3194
|
+
|
|
3195
|
+
/** 播种一条工作区记录(workspaces adapter 的数据源)。 */
|
|
3196
|
+
function seedWorkspace(
|
|
3197
|
+
ctx: ReturnType<typeof makeContext>,
|
|
3198
|
+
rec: { id: string; path: string; sessionIds: string[]; title?: string },
|
|
3199
|
+
): void {
|
|
3200
|
+
ctx.workspace.records.set(rec.id, { ...rec });
|
|
3201
|
+
}
|
|
3202
|
+
|
|
3203
|
+
/** 造一份「另一台设备推的」远端快照(只有 workspaces 分区),模拟 #127 的跨机场景。 */
|
|
3204
|
+
function remoteWorkspaceSnapshot(id: string, sessionIds: string[]): SyncSnapshot {
|
|
3205
|
+
return {
|
|
3206
|
+
id,
|
|
3207
|
+
createdAt: '2026-08-16T12:00:00.000Z',
|
|
3208
|
+
manifest: { schemaVersion: 1, dshVersion: '1.2.3', platform: 'win32', sectionIds: ['workspaces'], containsSecrets: false },
|
|
3209
|
+
sections: {
|
|
3210
|
+
workspaces: {
|
|
3211
|
+
version: 1,
|
|
3212
|
+
workspaces: [{ id: 'w1', path: 'C:/Users/alice/proj', sessionIds }],
|
|
3213
|
+
},
|
|
3214
|
+
},
|
|
3215
|
+
};
|
|
3216
|
+
}
|
|
3217
|
+
|
|
3218
|
+
test('issue #127: workspaces 为手动可选分区 —— 未放行不进快照(跳过可见);放行后才随 push 上行;自动档不含它', async () => {
|
|
3219
|
+
const tmp = await fs.mkdtemp(path.join(os.tmpdir(), 'dsh-sync-engine-ws-push-'));
|
|
3220
|
+
try {
|
|
3221
|
+
const ctx = makeContext('win32', 'C:\\Users\\alice');
|
|
3222
|
+
seedSource(ctx);
|
|
3223
|
+
seedWorkspace(ctx, { id: 'w1', path: 'C:/Users/alice/proj', sessionIds: ['s1'] });
|
|
3224
|
+
const transport = new MemSyncTransport();
|
|
3225
|
+
const adapters = createAdapters({ namespaces: NS, includeSessions: true });
|
|
3226
|
+
const importer = new Importer({ ctx, adapters, snapshotStore: new MemSnapshotStore() });
|
|
3227
|
+
const now = () => new Date('2026-08-16T12:00:00.000Z');
|
|
3228
|
+
|
|
3229
|
+
assert.ok(
|
|
3230
|
+
!AUTO_SYNC_OPT_IN_SECTION_IDS.includes('workspaces'),
|
|
3231
|
+
'workspaces 必须是 manual 档:自动同步绝不带它(路径与本机绑定)',
|
|
3232
|
+
);
|
|
3233
|
+
|
|
3234
|
+
const plain = new SyncEngine({
|
|
3235
|
+
ctx, transport, stateDir: path.join(tmp, 'plain'), adapters, importer, now,
|
|
3236
|
+
} as ConstructorParameters<typeof SyncEngine>[0]);
|
|
3237
|
+
const skipped = await plain.push({ snapshotId: 'sync-ws-off', sections: ['settings', 'workspaces'] });
|
|
3238
|
+
assert.ok(!skipped.sections.includes('workspaces'), '未放行时 workspaces 不得进入快照');
|
|
3239
|
+
assert.ok(
|
|
3240
|
+
skipped.warnings.some((w) => w.includes('workspaces')),
|
|
3241
|
+
'跳过必须可见(不静默): ' + skipped.warnings.join(' | '),
|
|
3242
|
+
);
|
|
3243
|
+
|
|
3244
|
+
const optIn = new SyncEngine({
|
|
3245
|
+
ctx, transport, stateDir: path.join(tmp, 'optin'), adapters, importer, now, optInSections: ['workspaces'],
|
|
3246
|
+
} as ConstructorParameters<typeof SyncEngine>[0]);
|
|
3247
|
+
const pushed = await optIn.push({ snapshotId: 'sync-ws-on', sections: ['workspaces'] });
|
|
3248
|
+
assert.deepEqual(pushed.sections, ['workspaces'], '放行后必须能单独上行 workspaces');
|
|
3249
|
+
const records = (plainSections(transport.snapshots.get('sync-ws-on')!.sections)['workspaces'] as WorkspacesSection).workspaces;
|
|
3250
|
+
assert.deepEqual(records.map((r) => r.id), ['w1'], '工作区记录必须完整进入快照');
|
|
3251
|
+
} finally {
|
|
3252
|
+
await fs.rm(tmp, { recursive: true, force: true });
|
|
3253
|
+
}
|
|
3254
|
+
});
|
|
3255
|
+
|
|
3256
|
+
test('issue #127: 拉取侧两侧各自挂过会话 → sessionIds 取并集(不冲突、不丢本地归属)', async () => {
|
|
3257
|
+
const tmp = await fs.mkdtemp(path.join(os.tmpdir(), 'dsh-sync-engine-ws-merge-'));
|
|
3258
|
+
try {
|
|
3259
|
+
const ctx = makeContext('win32', 'C:\\Users\\alice');
|
|
3260
|
+
seedSource(ctx);
|
|
3261
|
+
seedWorkspace(ctx, { id: 'w1', path: 'C:/Users/alice/proj', sessionIds: ['s-local'] });
|
|
3262
|
+
const transport = new MemSyncTransport();
|
|
3263
|
+
const adapters = createAdapters({ namespaces: NS, includeSessions: true });
|
|
3264
|
+
const importer = new Importer({ ctx, adapters, snapshotStore: new MemSnapshotStore() });
|
|
3265
|
+
seedRemoteSnapshot(transport, remoteWorkspaceSnapshot('remote-ws-1', ['s-remote']));
|
|
3266
|
+
|
|
3267
|
+
const engine = new SyncEngine({
|
|
3268
|
+
ctx, transport, stateDir: tmp, adapters, importer,
|
|
3269
|
+
now: () => new Date('2026-08-16T12:00:00.000Z'), optInSections: ['workspaces'],
|
|
3270
|
+
} as ConstructorParameters<typeof SyncEngine>[0]);
|
|
3271
|
+
|
|
3272
|
+
const plan = await engine.merge();
|
|
3273
|
+
const section = plan.sections.find((s) => s.id === 'workspaces');
|
|
3274
|
+
assert.ok(section, '放行后 workspaces 必须进合并计划');
|
|
3275
|
+
assert.equal(section!.decision, 'merge', '两侧各挂会话应能自动合并(改造前是 no-ancestor 整分区冲突)');
|
|
3276
|
+
const merged = (section!.merged as WorkspacesSection).workspaces;
|
|
3277
|
+
assert.deepEqual(merged[0]?.sessionIds, ['s-local', 's-remote'], '本地在前、远端追加,两侧都不丢');
|
|
3278
|
+
} finally {
|
|
3279
|
+
await fs.rm(tmp, { recursive: true, force: true });
|
|
3280
|
+
}
|
|
3281
|
+
});
|
|
3282
|
+
|
|
3283
|
+
test('issue #127: apply 阶段会话必须伴随工作区落地 —— 只应用 sessions 时自动补 workspaces 计划项', async () => {
|
|
3284
|
+
const tmp = await fs.mkdtemp(path.join(os.tmpdir(), 'dsh-sync-engine-ws-companion-'));
|
|
3285
|
+
try {
|
|
3286
|
+
const ctx = makeContext('win32', 'C:\\Users\\alice');
|
|
3287
|
+
seedSource(ctx);
|
|
3288
|
+
// 本机已有同名工作区(只挂了本地会话)→ 远端那条挂了另一台机器的会话
|
|
3289
|
+
seedWorkspace(ctx, { id: 'w1', path: 'C:/Users/alice/proj', sessionIds: ['s-local'] });
|
|
3290
|
+
const transport = new MemSyncTransport();
|
|
3291
|
+
const adapters = createAdapters({ namespaces: NS, includeSessions: true });
|
|
3292
|
+
const importer = new Importer({ ctx, adapters, snapshotStore: new MemSnapshotStore() });
|
|
3293
|
+
const engine = new SyncEngine({
|
|
3294
|
+
ctx, transport, stateDir: tmp, adapters, importer,
|
|
3295
|
+
now: () => new Date('2026-08-16T12:00:00.000Z'), optInSections: ['sessions', 'workspaces'],
|
|
3296
|
+
} as ConstructorParameters<typeof SyncEngine>[0]);
|
|
3297
|
+
|
|
3298
|
+
// 用户只确认了「会话」这一行:workspaces 留在 review 里(它的合并值随计划一起给出)
|
|
3299
|
+
const apply: SyncApplyPlan = {
|
|
3300
|
+
autoApply: [{ id: 'sessions', decision: 'useRemote', conflicts: [], merged: { version: 1, files: [] } }],
|
|
3301
|
+
review: [{
|
|
3302
|
+
id: 'workspaces',
|
|
3303
|
+
decision: 'useRemote',
|
|
3304
|
+
conflicts: [],
|
|
3305
|
+
merged: {
|
|
3306
|
+
version: 1,
|
|
3307
|
+
workspaces: [{ id: 'w1', path: 'C:/Users/alice/proj', sessionIds: ['s-remote'] }],
|
|
3308
|
+
},
|
|
3309
|
+
}],
|
|
3310
|
+
skipped: [],
|
|
3311
|
+
};
|
|
3312
|
+
const report = await engine.applyMergePlan(apply, { remoteSnapshotId: 'remote-ws-1' });
|
|
3313
|
+
assert.equal(report.ok, true, '整体应用必须成功: ' + report.warnings.join(' | '));
|
|
3314
|
+
assert.ok(
|
|
3315
|
+
report.applied.includes('workspaces'),
|
|
3316
|
+
'伴随分区必须计入 applied(否则基线不记它、下一轮又当成新变化): ' + report.applied.join(','),
|
|
3317
|
+
);
|
|
3318
|
+
const landed = ctx.workspace.records.get('w1');
|
|
3319
|
+
assert.ok(landed, '工作区记录必须落到本机');
|
|
3320
|
+
assert.deepEqual(
|
|
3321
|
+
landed!.sessionIds,
|
|
3322
|
+
['s-local', 's-remote'],
|
|
3323
|
+
'本机既有会话归属不得被覆盖,远端会话也要挂上(否则导入的会话在目标机完全不显示)',
|
|
3324
|
+
);
|
|
3325
|
+
} finally {
|
|
3326
|
+
await fs.rm(tmp, { recursive: true, force: true });
|
|
3327
|
+
}
|
|
3328
|
+
});
|