diff --git a/pkg/workflow/wasm_golden_test.go b/pkg/workflow/wasm_golden_test.go index d21a8dcfa6a..e8facd29e6f 100644 --- a/pkg/workflow/wasm_golden_test.go +++ b/pkg/workflow/wasm_golden_test.go @@ -13,6 +13,13 @@ import ( "github.com/stretchr/testify/require" ) +// normalizeOutput applies all stable-comparison normalizations to compiled workflow output +// before golden comparison: heredoc delimiter normalization and container pin normalization. +// Mirrors normalize() in scripts/test-wasm-golden.mjs. +func normalizeOutput(content string) string { + return normalizeContainerPins(normalizeHeredocDelimiters(content)) +} + // TestWasmGolden_CompileFixtures compiles each workflow fixture using the string API // (the same code path used by the wasm compiler) and compares against golden files. // @@ -82,11 +89,10 @@ func TestWasmGolden_CompileFixtures(t *testing.T) { // testdata/ relative to the package root (not the fixtures dir). require.NoError(t, os.Chdir(origDir)) - // Normalize heredoc delimiters before comparing so golden files are - // stable across compilations (randomized token is replaced by a placeholder). - // Also normalize container pins since the action cache may or may not be - // available depending on the environment (native vs wasm). - golden.RequireEqual(t, normalizeContainerPins(normalizeHeredocDelimiters(yamlOutput))) + // Normalize heredoc delimiters and container pins before comparing so golden files + // are stable across compilations (randomized tokens and environment-specific pins + // are replaced by stable placeholders). + golden.RequireEqual(t, normalizeOutput(yamlOutput)) }) } } diff --git a/scripts/test-wasm-golden.mjs b/scripts/test-wasm-golden.mjs index 5e1564772a9..242f51c7cf5 100644 --- a/scripts/test-wasm-golden.mjs +++ b/scripts/test-wasm-golden.mjs @@ -149,6 +149,15 @@ function normalizeContainerPins(content) { return content.replace(/@sha256:[0-9a-f]{64}/g, ""); } +// ── Normalize output ────────────────────────────────────────────────── +// Applies all normalizations needed for stable golden comparison. +// Combines heredoc delimiter and container pin normalizations so that +// new normalization steps only need to be added in one place. +// Mirrors normalizeOutput() in pkg/workflow/wasm_golden_test.go. +function normalize(content) { + return normalizeContainerPins(normalizeHeredocDelimiters(content)); +} + // ── Load golden file ───────────────────────────────────────────────── function loadGoldenFile(testName) { // Golden files follow the charmbracelet/x/exp/golden convention: @@ -231,8 +240,8 @@ async function main() { continue; } - const normalizedWasm = normalizeContainerPins(normalizeHeredocDelimiters(wasmYaml)); - const normalizedGolden = normalizeContainerPins(normalizeHeredocDelimiters(goldenYaml)); + const normalizedWasm = normalize(wasmYaml); + const normalizedGolden = normalize(goldenYaml); if (normalizedWasm === normalizedGolden) { console.log("PASS");