import { assertEquals, assertStringIncludes } from "@std/assert"; import { transformSource, validateSource } from "./utils.ts"; import { COMMONFABRIC_TYPES } from "./commonfabric-test-types.ts"; function normalizeOutput(output: string): string { return output.replace(/\s+/g, " "); } Deno.test("transformer coverage: nested aliases expand to canonical metadata", async () => { const source = `/// import { toSchema } from "commonfabric"; type Cfc = T & { readonly __ct_cfc__?: Meta }; type Confidential = Cfc; type SecretText = Confidential; interface SchemaRoot { secret: SecretText<{ value: string }>; } const schema = toSchema(); export default schema; `; const output = normalizeOutput( await transformSource(source, { types: COMMONFABRIC_TYPES }), ); assertStringIncludes(output, "confidentiality: ["); assertStringIncludes(output, '"secret"'); assertStringIncludes(output, 'value: { type: "string" }'); }); Deno.test("transformer coverage: projection paths lower as canonical pointers", async () => { const source = `/// import { toSchema } from "commonfabric"; type Cfc = T & { readonly __ct_cfc__?: Meta }; type ProjectionPath = Cfc; type ProjectionOf = ProjectionPath; interface SchemaRoot { projection: ProjectionOf<{ title: string }, readonly ["nested", "path"]>; } const schema = toSchema(); export default schema; `; const output = normalizeOutput( await transformSource(source, { types: COMMONFABRIC_TYPES }), ); assertStringIncludes( output, 'projection: { from: "/", path: "/nested/path" }', ); assertStringIncludes(output, 'title: { type: "string" }'); }); Deno.test("transformer coverage: opaque inputs lower to ifc.opaque", async () => { const source = `/// import { toSchema } from "commonfabric"; type Cfc = T & { readonly __ct_cfc__?: Meta }; type OpaqueInput = Cfc; interface SecretPayload { token: OpaqueInput; } const schema = toSchema(); export default schema; `; const output = normalizeOutput( await transformSource(source, { types: COMMONFABRIC_TYPES }), ); assertStringIncludes(output, "ifc: { opaque: true }"); assertStringIncludes(output, 'token: { type: "string"'); }); Deno.test("transformer coverage: imported Cfc metadata survives Writable.of type arguments", async () => { const source = `/// import { type Cfc, Writable } from "commonfabric"; type AuthorshipIntegrity = { readonly kind: "authored-by"; readonly subject: Author; }; type AuthoredMessageBody = Cfc< string, { integrity: readonly [AuthorshipIntegrity] } >; const body = Writable.of>( "Verified text" as AuthoredMessageBody<"alice">, ); export default body; `; const output = normalizeOutput( await transformSource(source, { types: COMMONFABRIC_TYPES }), ); assertStringIncludes(output, 'type: "string"'); assertStringIncludes( output, 'ifc: { integrity: [{ kind: "authored-by", subject: "alice" }] }', ); assertEquals(output.includes("Unsupported intersection pattern"), false); }); Deno.test("transformer coverage: UI helpers rewrite to intrinsic tags and data-ui markers", async () => { const source = `/// import { UiAction } from "commonfabric"; export default () => ( Go ); `; const output = await transformSource(source, { types: COMMONFABRIC_TYPES, }); assertStringIncludes( output, 'Go', ); assertEquals(output.includes(" { const source = `/// import { toSchema, WriteAuthorizedBy } from "commonfabric"; declare const missingInitializer: () => void; const invalidSchema = toSchema< WriteAuthorizedBy<{ title: string }, typeof missingInitializer> >(); const invalidQuerySchema = toSchema< WriteAuthorizedBy<{ title: string }, string> >(); export { invalidSchema, invalidQuerySchema }; `; const { diagnostics } = await validateSource(source, { types: COMMONFABRIC_TYPES, }); assertEquals( diagnostics.some((diagnostic) => diagnostic.type === "cfc-write-authorized-by" ), true, ); });