From 0c9916e3c7d2062d9983a5fb8f592a000893281a Mon Sep 17 00:00:00 2001 From: Kingsword Date: Sun, 6 Dec 2026 22:51:14 +0800 Subject: [PATCH] test(runtime): scope 4.0 compatibility checks --- test/runtime/runtime-4.0-compat.test.ts | 49 ++++++++++++++----------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/test/runtime/runtime-4.0-compat.test.ts b/test/runtime/runtime-4.0-compat.test.ts index a5ad2102..37b2dbc0 100644 --- a/test/runtime/runtime-4.0-compat.test.ts +++ b/test/runtime/runtime-4.0-compat.test.ts @@ -11,28 +11,35 @@ import { runtimePatchPlan } from "../../scripts/sync-runtime.ts"; -test("4.0 native runtime features are verified without applying legacy compatibility rewrites", async () => { - const runtime = await readFile(new URL("../../vendor/zcode.cjs", import.meta.url), "utf8"); - const nativePatches = new Map(runtimePatchPlan.map(patch => [patch.id, patch])); - expect(nativePatches.has("official-mcp-availability")).toBe(false); - expect(runtime).toContain("official MCP trusted origin registry is not available in this runtime"); +const extraction = JSON.parse(await readFile(new URL("../../vendor/extraction.json", import.meta.url), "utf8")) as { + appVersion?: unknown; +}; - for (const [id, check] of [ - ["detached-agent-lifecycle", hasRuntimeTrackedDetachedAgentLifecycle], - ["http-no-content", hasRuntimeHttpNoContentGuard], - ["native-oauth-polling", hasRuntimeNativePollingOAuth] - ] as const) { - const patch = nativePatches.get(id); - expect(patch, `missing native runtime check ${id}`).toBeDefined(); - expect(patch!.apply(runtime)).toBe(runtime); - expect(patch!.verify?.(runtime)).toBe(true); - } +test.skipIf(extraction.appVersion !== "4.0.0")( + "4.0 native runtime features are verified without applying legacy compatibility rewrites", + async () => { + const runtime = await readFile(new URL("../../vendor/zcode.cjs", import.meta.url), "utf8"); + const nativePatches = new Map(runtimePatchPlan.map(patch => [patch.id, patch])); + expect(nativePatches.has("official-mcp-availability")).toBe(false); + expect(runtime).toContain("official MCP trusted origin registry is not available in this runtime"); - for (const id of ["http-no-content", "native-oauth-polling"]) { - const patch = nativePatches.get(id)!; - expect(() => applyRuntimePatchPlan("", [patch])).toThrow(`Required runtime patch ${id} failed`); + for (const [id, check] of [ + ["detached-agent-lifecycle", hasRuntimeTrackedDetachedAgentLifecycle], + ["http-no-content", hasRuntimeHttpNoContentGuard], + ["native-oauth-polling", hasRuntimeNativePollingOAuth] + ] as const) { + const patch = nativePatches.get(id); + expect(patch, `missing native runtime check ${id}`).toBeDefined(); + expect(patch!.apply(runtime)).toBe(runtime); + expect(patch!.verify?.(runtime)).toBe(true); + } + + for (const id of ["http-no-content", "native-oauth-polling"]) { + const patch = nativePatches.get(id)!; + expect(() => applyRuntimePatchPlan("", [patch])).toThrow(`Required runtime patch ${id} failed`); + } } -}); +); test("4.0 TUI prompt overrides apply before the current app wrapper returns", async () => { const runtime = await readFile(new URL("../../vendor/zcode.cjs", import.meta.url), "utf8"); @@ -44,13 +51,13 @@ test("4.0 TUI prompt overrides apply before the current app wrapper returns", as expect(patched.indexOf('},"createApp")', override)).toBeGreaterThan(override); }); -test("4.0 BigModel session reuse holds a credential recovery guard through config persistence", async () => { +test("BigModel session reuse holds a credential recovery guard through config persistence", async () => { const runtime = await readFile(new URL("../../vendor/zcode.cjs", import.meta.url), "utf8"); const patched = patchRuntimeBigmodelSessionReuse(runtime); expect(patched).toContain("ZCODE_CLI_BIGMODEL_REUSE_SESSION"); expect(patched).toContain("captureRecoveryGuard()"); expect(patched).toContain("loadOAuthSessionSnapshot()"); - expect(patched).toContain("$bGuard.run(()=>dDi({"); + expect(patched).toMatch(/\$bGuard\.run\(\(\)=>[A-Za-z_$][\w$]*\(\{/u); expect(patchRuntimeBigmodelSessionReuse(patched)).toBe(patched); expect(() => parse(patched, { ecmaVersion: "latest", allowReturnOutsideFunction: true })).not.toThrow(); });