From e6dc9dfec5f33c7e517ece762b9cb0c9015d3a59 Mon Sep 17 00:00:00 2001 From: sudacode Date: Fri, 11 Sep 2026 01:53:26 -0700 Subject: [PATCH] test: clone VM results across Electron boundaries - Clone tokenizer VM results into the host realm - Expect null-prototype profile maps in IPC validation tests --- src/core/services/ipc.test.ts | 8 +++++++- src/core/services/tokenizer/golden-corpus-harness.ts | 3 ++- src/core/services/tokenizer/yomitan-scan-test-harness.ts | 6 ++++-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/core/services/ipc.test.ts b/src/core/services/ipc.test.ts index 7196d037..8fcfb2e6 100644 --- a/src/core/services/ipc.test.ts +++ b/src/core/services/ipc.test.ts @@ -1037,7 +1037,13 @@ test('registerIpcHandlers accepts per-controller profile config updates', async }, }; await saveHandler({}, update); - assert.deepEqual(controllerSaves, [update]); + assert.deepEqual(controllerSaves, [ + { + ...update, + // Validation uses a null prototype to safely store arbitrary profile IDs. + profiles: { __proto__: null, ...update.profiles }, + }, + ]); await assert.rejects(async () => { await saveHandler( diff --git a/src/core/services/tokenizer/golden-corpus-harness.ts b/src/core/services/tokenizer/golden-corpus-harness.ts index ce17fa35..4a9b7d9e 100644 --- a/src/core/services/tokenizer/golden-corpus-harness.ts +++ b/src/core/services/tokenizer/golden-corpus-harness.ts @@ -396,7 +396,8 @@ function createInjectedScriptVm(store: ReplayMessageStore): (script: string) => Set, String, }); - return async (script: string) => await vm.runInContext(script, context); + // Clone results into the host realm, matching Electron's process boundary. + return async (script: string) => structuredClone(await vm.runInContext(script, context)); } export function createReplayTokenizerDeps(fixture: GoldenFixture): TokenizerServiceDeps { diff --git a/src/core/services/tokenizer/yomitan-scan-test-harness.ts b/src/core/services/tokenizer/yomitan-scan-test-harness.ts index 01745a96..8c9efeaa 100644 --- a/src/core/services/tokenizer/yomitan-scan-test-harness.ts +++ b/src/core/services/tokenizer/yomitan-scan-test-harness.ts @@ -64,7 +64,8 @@ export async function runInjectedYomitanScript( script: string, handler: (action: string, params: unknown) => unknown, ): Promise { - return await vm.runInNewContext(script, createYomitanScriptSandbox(handler)); + // Clone results into the host realm, matching Electron's process boundary. + return structuredClone(await vm.runInNewContext(script, createYomitanScriptSandbox(handler))); } // Persistent page context shared across executeJavaScript calls, matching the @@ -75,7 +76,8 @@ function createPersistentYomitanScriptRunner( handler: (action: string, params: unknown) => unknown, ): (script: string) => Promise { const context = vm.createContext(createYomitanScriptSandbox(handler)); - return async (script: string) => await vm.runInContext(script, context); + // Clone results into the host realm, matching Electron's process boundary. + return async (script: string) => structuredClone(await vm.runInContext(script, context)); } // Deps whose parser window executes every injected script (profile metadata,