import { describe, expect, test } from "vitest"; import { bootstrap } from "./bootstrap.js"; import { registerOutputTemplates } from "./output-templates.js"; import { renderAsync, renderDirectAsync } from "./render.js"; import { putSchema } from "./schema.js"; import { createMemoryStore } from "./store.js"; import type { Hash } from "./types.js"; describe("renderDirectAsync — object-valued envelope rendering with templates", () => { test("uses text template when one exists for the type", async () => { // Spec: render-pipe-object-uses-template const store = createMemoryStore(); bootstrap(store); await registerOutputTemplates(store); // Get the gc output schema hash const aliases = bootstrap(store); const gcTypeHash = aliases["@ocas/output/gc"]; if (!gcTypeHash) throw new Error("@ocas/output/gc not found"); const gcValue = { total: 10, reachable: 8, collected: 2, scanned: 10 }; const output = await renderDirectAsync(gcTypeHash, gcValue, store, {}); // Should use the text template, not YAML expect(output).toContain("total: 10"); expect(output).toContain("reachable: 8"); expect(output).toContain("collected: 2"); expect(output).toContain("scanned: 10"); // Should NOT be raw YAML with nested object format expect(output).not.toContain("{"); }); test("respects --format html with object-valued envelopes", async () => { // Spec: render-pipe-object-respects-format const store = createMemoryStore(); bootstrap(store); await registerOutputTemplates(store); const aliases = bootstrap(store); const gcTypeHash = aliases["@ocas/output/gc"]; if (!gcTypeHash) throw new Error("@ocas/output/gc not found"); const gcValue = { total: 5, reachable: 3, collected: 2, scanned: 5 }; const output = await renderDirectAsync(gcTypeHash, gcValue, store, { format: "html", }); // Should use HTML template (new card layout) expect(output).toContain('