diff --git a/lexicons/fountain/src/serializer.test.ts b/lexicons/fountain/src/serializer.test.ts index 50c5dad225..86b301196e 100644 --- a/lexicons/fountain/src/serializer.test.ts +++ b/lexicons/fountain/src/serializer.test.ts @@ -1,5 +1,6 @@ import { describe, expect, it } from "vitest"; import { fountainSerializer } from "./serializer"; +import { parseManifest } from "./op/activities/fountain-apply"; import type { Declarable } from "@intentius/chant"; function entity(entityType: string, props: Record): Declarable { @@ -85,6 +86,56 @@ describe("fountain serializer", () => { expect(out).toContain('description: "true"'); }); + it("folds the first line of a map list item onto the dash", () => { + const agent = entity("Fountain::V1::Agent", { + name: "a", + model: "anthropic/claude-sonnet-4-6", + runtime: "claude", + skills: [{ source: "anthropics/skills", name: "frontend-design" }], + }); + + const out = fountainSerializer.serialize(new Map([["a", agent]])) as string; + expect(out).toContain(" - source: anthropics/skills\n name: frontend-design"); + expect(out).not.toMatch(/^\s*-$/m); + }); + + it("round-trips its own output through parseManifest", () => { + // A list-of-maps field plus a spec-level `metadata` key is the shape + // that used to collapse in parseYAML (#1286): the list item's keys + // leaked to the top level and spec.metadata clobbered the document + // metadata, blanking every resource name. + const env = entity("Fountain::V1::Environment", { + name: "e", + secrets: [{ key: "GITHUB_TOKEN", value: "infisical:///dev/GITHUB_TOKEN" }], + metadata: { "managed-by": "chant" }, + }); + const agent = entity("Fountain::V1::Agent", { + name: "a", + model: "anthropic/claude-sonnet-4-6", + runtime: "claude", + environment: env, + skills: [{ source: "anthropics/skills", name: "frontend-design" }], + metadata: { "managed-by": "chant" }, + }); + + const out = fountainSerializer.serialize( + new Map([ + ["e", env], + ["a", agent], + ]), + ) as string; + const resources = parseManifest(out); + + expect(resources.map((r) => `${r.kind}/${r.name}`)).toEqual(["Environment/e", "Agent/a"]); + expect(resources[0].spec.secrets).toEqual([ + { key: "GITHUB_TOKEN", value: "infisical:///dev/GITHUB_TOKEN" }, + ]); + expect(resources[1].spec.skills).toEqual([ + { source: "anthropics/skills", name: "frontend-design" }, + ]); + expect(resources[1].spec.metadata).toEqual({ "managed-by": "chant" }); + }); + it("does not use YAML aliases or tags for substitution references", () => { const agent = entity("Fountain::V1::Agent", { name: "a", diff --git a/lexicons/fountain/src/serializer.ts b/lexicons/fountain/src/serializer.ts index 24b275479d..a6ebe13751 100644 --- a/lexicons/fountain/src/serializer.ts +++ b/lexicons/fountain/src/serializer.ts @@ -90,8 +90,12 @@ function toYaml(value: unknown, indent = 0): string { if (isScalar(item)) { out += `${pad}- ${scalar(item)}\n`; } else { + // Fold the item's first line onto the dash (`- key: value`) rather + // than emitting the dash on its own line: `- ` is exactly as wide + // as one indent level, so continuation lines already align, and + // parseYAML can't read the dash-alone form (#1286). const body = toYaml(item, indent + 1); - out += `${pad}-\n${body}`; + out += `${pad}- ${body.slice(pad.length + 2)}`; } } return out;