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,60 @@
import { expect, test } from "bun:test";
const legacyToken = "legacy-master-token-canary";
test("legacy query and storage secrets are removed before application modules load", async () => {
const module = await import("../src/services/local-runtime-bootstrap").catch(() => ({}));
const runBootstrap = (
module as {
runLocalRuntimeBootstrap?: (environment: BootstrapEnvironment, loadApplication: (state: { legacyDeepLinkRejected: boolean }) => void) => { legacyDeepLinkRejected: boolean };
}
).runLocalRuntimeBootstrap;
expect(typeof runBootstrap).toBe("function");
if (!runBootstrap) return;
let href = `http://127.0.0.1:3001/canvas/demo?keep=1&agentUrl=http%3A%2F%2F127.0.0.1%3A17371&agentToken=${legacyToken}#timeline`;
const storage = new Map([
["canvas-agent-url", "http://127.0.0.1:17371"],
["canvas-agent-token", legacyToken],
["unrelated", "keep"],
]);
let rendered = false;
const state = runBootstrap(
{
get href() {
return href;
},
replaceUrl(url) {
href = new URL(url, href).toString();
},
removeStorageItem(key) {
storage.delete(key);
},
},
(bootstrapState) => {
rendered = true;
expect(href).toBe("http://127.0.0.1:3001/canvas/demo?keep=1#timeline");
expect(storage.has("canvas-agent-url")).toBe(false);
expect(storage.has("canvas-agent-token")).toBe(false);
expect(storage.get("unrelated")).toBe("keep");
expect(JSON.stringify(bootstrapState)).not.toContain(legacyToken);
},
);
expect(rendered).toBe(true);
expect(state).toEqual({ legacyDeepLinkRejected: true });
expect(href).not.toContain(legacyToken);
const readState = (
module as {
readLocalRuntimeBootstrapState?: () => { legacyDeepLinkRejected: boolean };
}
).readLocalRuntimeBootstrapState;
expect(typeof readState).toBe("function");
expect(readState?.()).toEqual({ legacyDeepLinkRejected: true });
});
type BootstrapEnvironment = {
readonly href: string;
replaceUrl(url: string): void;
removeStorageItem(key: string): void;
};