import { describe, expect, it } from "vitest"; import type { ToolcraftEnvelopePerformanceConfig } from "./performance"; import { assessToolcraftRenderPlan } from "./performance-render-plan-assessment"; import { createBenchmarkDecision, createEnvelopeConfig, createPass, } from "./performance-render-plan-test-fixtures"; import { testSchema } from "./performance-test-fixtures"; const executableRegistrationError = "Envelope custom renderers with cache-sensitive passes must use a compiled executable renderer pipeline registration; runtimeId prose alone is not executable evidence."; describe("Toolcraft executable render plan registration", () => { it.each([ { label: "missing", options: { omitRuntimeId: true } }, { label: "empty", options: { runtimeId: "" } }, { label: "untrimmed", options: { runtimeId: " renderer-v1 " } }, ])("rejects a $label raw runtime id for envelope custom renderers", ({ options }) => { expect( assessToolcraftRenderPlan( testSchema, createEnvelopeConfig({ ...options, kernelBenchmarkDecisions: [createBenchmarkDecision()], }), ).errors, ).toContain(executableRegistrationError); }); it("does not treat a valid raw runtimeId as executable registration", () => { const executable = createEnvelopeConfig({ kernelBenchmarkDecisions: [createBenchmarkDecision()], }); const registration = executable.rendererPipeline!; const rawConfig: ToolcraftEnvelopePerformanceConfig = { ...executable, rendererPipeline: { interactionInvalidation: registration.interactionInvalidation, passes: registration.passes, runtimeId: registration.runtimeId, }, }; expect(assessToolcraftRenderPlan(testSchema, rawConfig).errors).toContain( executableRegistrationError, ); }); it("keeps the runtime id requirement for custom no-cache renderers", () => { const pass = createPass({ cacheKey: undefined, lifecycle: { cache: "none", resourceScope: "call" }, }); expect( assessToolcraftRenderPlan( testSchema, createEnvelopeConfig({ omitRuntimeId: true, pass }), ).errors, ).toContain( "Envelope custom renderers must declare rendererPipeline.runtimeId as a non-empty trimmed stable string.", ); }); it("rejects interaction resources without an executable interaction boundary", () => { const pass = createPass({ lifecycle: { cache: "retained-resource", resourceScope: "interaction" }, }); expect( assessToolcraftRenderPlan(testSchema, createEnvelopeConfig({ pass })).errors, ).toContain( 'rendererPipeline pass "effect" uses interaction-scoped resources, but executable interaction resource boundaries are not supported.', ); }); });