import assert from "node:assert/strict"; import { readFile } from "node:fs/promises"; import test from "node:test"; const pageURL = new URL("../../src/pages/ObjectSync.tsx", import.meta.url); const serviceURL = new URL("../../src/services/api/object-sync.ts", import.meta.url); const appURL = new URL("../../src/App.tsx", import.meta.url); const sidebarURL = new URL("../../src/components/Sidebar.tsx", import.meta.url); const objectStoragePageURL = new URL("../../src/pages/ObjectStorageBrowser.tsx", import.meta.url); const authorizationPanelURL = new URL( "../../src/components/object-storage/ObjectStorageAuthorizationPanel.tsx", import.meta.url, ); const credentialPanelURL = new URL("../../src/components/object-sync/DrosyncCredentialPanel.tsx", import.meta.url); test("drosync page exposes capability, session, conflict, release, audit and update surfaces", async () => { const source = await readFile(pageURL, "utf8"); for (const label of [ "能力门禁", "同步空间", "设备", "Session", "Keep-both 冲突", "不可变 Release", "审计哈希链", "客户端更新策略", "客户端下载", "授权密钥", ]) { assert.match(source, new RegExp(label)); } assert.match(source, /条件创建/); assert.match(source, /发现漂移/); assert.match(source, /已确认无外部直写/); assert.match(source, /条件覆盖/); assert.match(source, /window\.confirm/); assert.match(source, /Key\/Secret 验证后自动登记/); assert.match(source, /channel === "stable"/); assert.match(source, /rolloutPercent === 100/); assert.match(source, /item\.kind === "preview"/); assert.match(source, /POC 预览/); assert.match(source, /不会进入自动更新/); assert.match(source, /drosync-create-preview-release/); assert.match(source, /drosync-download-/); assert.match(source, /DrosyncCredentialPanel/); assert.doesNotMatch(source, /配对短码/); assert.doesNotMatch(source, /findAuthorizationByCode/); assert.doesNotMatch(source, /decideAuthorization/); }); test("drosync page applies role-specific views", async () => { const source = await readFile(pageURL, "utf8"); assert.match(source, /role === "admin"/); assert.match(source, /visible: isAdmin/); }); test("drosync API client adds idempotency keys to every mutation", async () => { const source = await readFile(serviceURL, "utf8"); assert.match(source, /"Idempotency-Key"/); assert.match(source, /crypto\?\.randomUUID/); assert.match(source, /const mutation =/); assert.match(source, /\/api\/object-sync\/spaces/); assert.match(source, /capability-probe/); assert.match(source, /\/api\/object-sync\/credentials/); assert.match(source, /audit-events\/export/); assert.match(source, /force-overwrite/); assert.match(source, /createCredential/); }); test("drosync stays reachable from data storage without becoming a ninth primary module", async () => { const [app, sidebar] = await Promise.all([readFile(appURL, "utf8"), readFile(sidebarURL, "utf8")]); assert.match(app, /lazyRoute\(\(\) => import\("\.\/pages\/ObjectSync"\)\)/); assert.match(app, /path="\/object-sync"/); assert.doesNotMatch(sidebar, /label: "drosync 同步"/); for (const label of ["仪表盘", "项目管理", "工作流", "算子库", "数据存储", "用户管理"]) { assert.match(sidebar, new RegExp(`label: "${label}"`)); } assert.match(sidebar, /getPluginPrimaryNavigationContributions\(pluginStatuses, role\)/); assert.doesNotMatch(sidebar, /label: "任务审核"|label: "抽检任务"/); }); test("object storage links to a standalone drosync surface and keeps only BOS validation", async () => { const [page, panel, credentialPanel] = await Promise.all([ readFile(objectStoragePageURL, "utf8"), readFile(authorizationPanelURL, "utf8"), readFile(credentialPanelURL, "utf8"), ]); assert.match(page, /BOS 密钥验证/); assert.match(page, /drosync 客户端/); assert.match(page, /to="\/object-sync\?view=access"/); assert.match(page, /object-storage-drosync-entry/); assert.match(page, /ObjectStorageAuthorizationPanel/); assert.match(panel, /BOS Key \/ 密钥验证/); assert.match(panel, /objectStorageApi\.listObjects/); assert.match(panel, /limit: 1/); assert.match(panel, /BOS 已接受本次只读对象列表请求/); assert.match(panel, /验证密钥/); assert.match(panel, /验证通过/); assert.match(panel, /不审批设备/); assert.doesNotMatch(panel, /findAuthorizationByCode/); assert.doesNotMatch(panel, /decideAuthorization/); assert.doesNotMatch(panel, /objectSyncApi/); assert.match(credentialPanel, /客户端授权 Key \/ Secret/); assert.match(credentialPanel, /与服务端访问 BOS 的 AK\/SK 不同/); assert.match(credentialPanel, /objectSyncApi\.createCredential/); assert.match(credentialPanel, /objectSyncApi\.mutateCredential/); assert.match(credentialPanel, /Secret 只显示一次/); });