Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions lexicons/fountain/src/serializer.test.ts
Original file line number Diff line number Diff line change
@@ -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<string, unknown>): Declarable {
Expand Down Expand Up @@ -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",
Expand Down
6 changes: 5 additions & 1 deletion lexicons/fountain/src/serializer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down