From 1dc01d738e9d560902fda2653e1f09b1934a22fb Mon Sep 17 00:00:00 2001 From: Jake Gaylor Date: Fri, 31 Jul 2026 23:03:55 -0400 Subject: [PATCH] fountain: emit map list items in inline-dash form MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit toYaml wrote a map list item as a bare `-` on its own line with the map indented beneath it. That form is spec-legal, but chant's parseYAML can't read it: the list collapses to {}, the item's keys leak to the top level, and a later spec.metadata overwrites the document metadata — so parseManifest returns every resource with an empty name and bulk apply 422s on the serializer's own output (#1286). Fold the item's first line onto the dash instead (`- key: value`). `- ` is exactly one indent level wide, so the body's continuation lines already align and the substitution is a same-width replacement of the first line's indentation. Adds a shape test and a serialize→parseManifest round-trip test over the exact shape that collapsed (a list-of-maps field plus a spec-level metadata key), so the emitter and parser can't drift apart silently again. Fixes #1286 Co-Authored-By: Claude Fable 5 --- lexicons/fountain/src/serializer.test.ts | 51 ++++++++++++++++++++++++ lexicons/fountain/src/serializer.ts | 6 ++- 2 files changed, 56 insertions(+), 1 deletion(-) 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;