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
16 changes: 11 additions & 5 deletions pkg/workflow/wasm_golden_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand Down Expand Up @@ -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))
})
}
}
Expand Down
13 changes: 11 additions & 2 deletions scripts/test-wasm-golden.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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");
Expand Down
Loading