|
1 | | -import { describe, expect, test } from "bun:test"; |
| 1 | +// Loading the @intx/types/runtime barrel evaluates inference-events.ts and |
| 2 | +// builds the InferenceEvent union. Session modules that need runtime values |
| 3 | +// import @intx/types/runtime-core so that boot does not pay for the union. |
| 4 | + |
| 5 | +import { expect, test } from "bun:test"; |
2 | 6 | import { spawnSync } from "node:child_process"; |
| 7 | +import path from "node:path"; |
3 | 8 | import { fileURLToPath } from "node:url"; |
4 | 9 |
|
5 | | -const repoRoot = fileURLToPath(new URL("../..", import.meta.url)); |
6 | | - |
7 | | -function probeImport(specifier: string): number | null { |
8 | | - const script = ` |
9 | | - import { mock } from "bun:test"; |
10 | | - mock.module("@intx/types/inference-events", () => { |
11 | | - throw new Error("evaluated-inference-events"); |
12 | | - }); |
13 | | - await import(${JSON.stringify(specifier)}); |
14 | | - `; |
15 | | - const result = spawnSync("bun", ["-e", script], { |
| 10 | +const repoRoot = path.resolve( |
| 11 | + path.dirname(fileURLToPath(import.meta.url)), |
| 12 | + "../..", |
| 13 | +); |
| 14 | + |
| 15 | +const probe = ` |
| 16 | +import { mock } from "bun:test"; |
| 17 | +mock.module("@intx/types/inference-events", () => { |
| 18 | + throw new Error("evaluated-inference-events"); |
| 19 | +}); |
| 20 | +const specifier = process.env.PROBE_SPECIFIER; |
| 21 | +if (specifier === undefined || specifier.length === 0) { |
| 22 | + throw new Error("missing PROBE_SPECIFIER"); |
| 23 | +} |
| 24 | +for (const target of specifier.split(",")) { |
| 25 | + await import(target); |
| 26 | +} |
| 27 | +`; |
| 28 | + |
| 29 | +function importUnderProbe(specifier: string): { |
| 30 | + status: number | null; |
| 31 | + stderr: string; |
| 32 | +} { |
| 33 | + const result = spawnSync("bun", ["-e", probe], { |
16 | 34 | cwd: repoRoot, |
17 | 35 | encoding: "utf8", |
| 36 | + env: { ...process.env, PROBE_SPECIFIER: specifier }, |
18 | 37 | }); |
19 | | - if ( |
20 | | - result.status !== 0 && |
21 | | - !`${result.stderr}${result.stdout}`.includes("evaluated-inference-events") |
22 | | - ) { |
23 | | - throw new Error( |
24 | | - `probe of ${specifier} failed without evaluated-inference-events:\n${result.stderr}\n${result.stdout}`, |
25 | | - ); |
26 | | - } |
27 | | - return result.status; |
| 38 | + return { |
| 39 | + status: result.status, |
| 40 | + stderr: result.stderr, |
| 41 | + }; |
28 | 42 | } |
29 | 43 |
|
30 | | -describe("runtime-core import boundary", () => { |
31 | | - test("importing reactor-authorize does not evaluate inference-events", () => { |
32 | | - expect(probeImport("./src/permission/reactor-authorize.ts")).toBe(0); |
33 | | - }); |
| 44 | +const sessionBootModules = [ |
| 45 | + "./src/session/optimized-context-store.ts", |
| 46 | + "./src/session/pending-approval-record.ts", |
| 47 | + "./src/session/summarizer.ts", |
| 48 | +].join(","); |
| 49 | + |
| 50 | +test("the runtime barrel evaluates the inference event union", () => { |
| 51 | + const result = importUnderProbe("@intx/types/runtime"); |
| 52 | + expect(result.status).not.toBe(0); |
| 53 | + expect(result.stderr).toContain("evaluated-inference-events"); |
34 | 54 | }); |
| 55 | + |
| 56 | +test( |
| 57 | + "session value imports do not evaluate the inference event union", |
| 58 | + () => { |
| 59 | + const result = importUnderProbe(sessionBootModules); |
| 60 | + expect(result.stderr).not.toContain("evaluated-inference-events"); |
| 61 | + expect(result.status).toBe(0); |
| 62 | + }, |
| 63 | + { timeout: 60_000 }, |
| 64 | +); |
| 65 | + |
| 66 | +test( |
| 67 | + "importing reactor-authorize does not evaluate inference-events", |
| 68 | + () => { |
| 69 | + const result = importUnderProbe("./src/permission/reactor-authorize.ts"); |
| 70 | + expect(result.stderr).not.toContain("evaluated-inference-events"); |
| 71 | + expect(result.status).toBe(0); |
| 72 | + }, |
| 73 | + { timeout: 60_000 }, |
| 74 | +); |
0 commit comments