fix: 稳定 PaC source artifact YAML 空白
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user