feat(runtime): 即梦本机运行时 - 接入安全生成闭环与桌面本机渠道

Refs #225

Co-authored-by: zkhyww <127009345+zkhyww@users.noreply.github.com>
This commit is contained in:
ddCat
2026-08-15 12:45:29 +08:00
parent 8f2232feee
commit 57e1820f41
179 changed files with 49746 additions and 1897 deletions

View File

@@ -0,0 +1,52 @@
import { expect, test } from "bun:test";
type Scenario = "image-cleanup" | "scope-cleanup-switch" | "scope-cleanup-late-canvas-reference" | "video-commit-race" | "audio-commit-race";
type ScenarioResponse<T> = { ok: true; result: T } | { ok: false; error: string };
function runScenario<T>(scenario: Scenario): Promise<T> {
return new Promise<T>((resolve, reject) => {
const worker = new Worker(new URL("./helpers/generation-storage-consistency.worker.ts", import.meta.url).href, { type: "module" });
const finish = () => {
worker.terminate();
};
worker.onmessage = (event: MessageEvent<ScenarioResponse<T>>) => {
finish();
if (event.data.ok) resolve(event.data.result);
else reject(new Error(event.data.error));
};
worker.onerror = (event) => {
finish();
reject(event.error ?? new Error(event.message));
};
worker.postMessage(scenario);
});
}
test("generation image cleanup removes unused generation-image blobs and preserves referenced ones", async () => {
const result = await runScenario<{ usedPresent: boolean; unusedPresent: boolean }>("image-cleanup");
expect(result.usedPresent).toBe(true);
expect(result.unusedPresent).toBe(false);
});
test("delayed cleanup keeps account-A Canvas-only image references after switching the active account", async () => {
const result = await runScenario<{ referencedPresent: boolean; unusedPresent: boolean; otherScopePresent: boolean }>("scope-cleanup-switch");
expect(result.referencedPresent).toBe(true);
expect(result.unusedPresent).toBe(false);
expect(result.otherScopePresent).toBe(true);
});
test("delayed cleanup preserves a same-scope Canvas-only reference added after cleanup was queued", async () => {
const result = await runScenario<{ referencedPresent: boolean; unusedPresent: boolean }>("scope-cleanup-late-canvas-reference");
expect(result.referencedPresent).toBe(true);
expect(result.unusedPresent).toBe(false);
});
test("generation video and audio materialization cannot race cleanup into a catalog row whose blob is missing", async () => {
for (const mediaType of ["video", "audio"] as const) {
const result = await runScenario<{ kind?: string; storageKey?: string; blobPresent: boolean; generationAssetCount: number }>(`${mediaType}-commit-race`);
expect(result.kind).toBe(mediaType);
expect(result.storageKey).toMatch(new RegExp(`^generation-${mediaType}:generation-media-commit-race-${mediaType}:`));
expect(result.blobPresent).toBe(true);
expect(result.generationAssetCount).toBe(1);
}
});