fix: 稳定 PaC source artifact YAML 空白

This commit is contained in:
Codex
2026-07-11 07:48:19 +02:00
parent 0e8ffe58d6
commit 2197de7336
8 changed files with 77 additions and 1 deletions
@@ -270,6 +270,20 @@ describe("source artifact serialization", () => {
expect(first).toContain("apiVersion: tekton.dev/v1\nkind: Pipeline\n");
expect(Bun.YAML.parse(first)).toEqual(manifest);
});
test("empty mappings and sequences have stable whitespace without changing structure", () => {
const manifest = {
apiVersion: "tekton.dev/v1",
kind: "PipelineRun",
metadata: {},
spec: { params: [], workspaces: [], pipelineSpec: { tasks: [] } },
};
const serialized = pacSourceArtifactYaml(manifest);
expect(serialized).not.toMatch(/[\t ]+$/m);
expect(serialized.endsWith("\n")).toBe(true);
expect(serialized.endsWith("\n\n")).toBe(false);
expect(Bun.YAML.parse(serialized)).toEqual(manifest);
});
});
describe("runtime source-commit selection", () => {
@@ -1032,7 +1032,12 @@ function parseYamlRecord(text: string, label: string): Record<string, unknown> {
}
export function pacSourceArtifactYaml(value: Record<string, unknown>): string {
return `${Bun.YAML.stringify(value, null, 2).trim()}\n`;
const serialized = Bun.YAML.stringify(value, null, 2)
.split("\n")
.map((line) => line.replace(/[\t ]+$/u, ""))
.join("\n")
.trim();
return `${serialized}\n`;
}
function requiredParam(binding: PacSourceArtifactBinding, key: string): string {