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
11 changes: 11 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -663,6 +663,17 @@ jobs:
exit 1
fi

- name: Run wasm golden tests (Go string API)
run: make test-wasm-golden

- name: Set up Node.js
uses: actions/setup-node@cdca7365b2dadb8aad0a33bc7601856ffabcc48e # v4
with:
node-version: '20'

- name: Run wasm binary golden tests (Node.js)
run: node scripts/test-wasm-golden.mjs

validate-yaml:
runs-on: ubuntu-latest
permissions:
Expand Down
29 changes: 25 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ build-wasm:
echo "⚠ wasm-opt not found, skipping optimization (install binaryen for ~8% size reduction)"; \
fi
@echo "✓ Built gh-aw.wasm ($$(du -h gh-aw.wasm | cut -f1))"
@echo " Copy wasm_exec.js from: $$(go env GOROOT)/misc/wasm/wasm_exec.js"
@echo " Copy wasm_exec.js from: $$(go env GOROOT)/lib/wasm/wasm_exec.js (or misc/wasm/ for Go <1.24)"

# Test the code (runs both unlabelled unit tests and integration tests and long tests)
.PHONY: test
Expand All @@ -77,6 +77,24 @@ update-golden:
@echo "Updating golden test files..."
go test -v ./pkg/console -run='^TestGolden_' -update

# Wasm golden tests — compare wasm (string API) compiler output against golden files
.PHONY: test-wasm-golden
test-wasm-golden:
@echo "Running wasm golden tests (Go string API path)..."
go test -v -timeout=5m -run='^TestWasmGolden_' ./pkg/workflow

# Update wasm golden files from current string API output
.PHONY: update-wasm-golden
update-wasm-golden:
@echo "Updating wasm golden test files..."
go test -v -timeout=5m -run='^TestWasmGolden_' ./pkg/workflow -update

# Build wasm and run Node.js golden comparison test
.PHONY: test-wasm
test-wasm: build-wasm
@echo "Running wasm binary golden tests (Node.js)..."
node scripts/test-wasm-golden.mjs

# Test specific integration test groups (matching CI workflow)
.PHONY: test-integration-compile
test-integration-compile:
Expand Down Expand Up @@ -221,9 +239,9 @@ bundle-js:
@echo "✓ bundle-js tool built"
@echo "To bundle a JavaScript file: ./bundle-js <input-file> [output-file]"

# Test all code (Go and JavaScript)
# Test all code (Go, JavaScript, and wasm golden)
.PHONY: test-all
test-all: test test-js
test-all: test test-js test-wasm-golden

# Run tests with coverage
.PHONY: test-coverage
Expand Down Expand Up @@ -729,7 +747,10 @@ help:
@echo " test-unit - Run Go unit tests only (faster)"
@echo " test-security - Run security regression tests"
@echo " test-js - Run JavaScript tests"
@echo " test-all - Run all tests (Go and JavaScript)"
@echo " test-all - Run all tests (Go, JavaScript, and wasm golden)"
@echo " test-wasm-golden - Run wasm golden tests (Go string API path)"
@echo " test-wasm - Build wasm and run Node.js golden comparison test"
@echo " update-wasm-golden - Regenerate wasm golden files from current compiler output"
@echo " test-coverage - Run tests with coverage report"
@echo " bench - Run benchmarks for performance testing"
@echo " bench-compare - Run benchmarks with more iterations (for benchstat comparison)"
Expand Down
17 changes: 12 additions & 5 deletions cmd/gh-aw-wasm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ func main() {
}

// compileWorkflow is the JS-callable function.
// Usage: compileWorkflow(markdownString, filesObject?) → Promise<{yaml, warnings, error}>
// Usage: compileWorkflow(markdownString, filesObject?, filename?) → Promise<{yaml, warnings, error}>
//
// Arguments:
// - markdownString: the main workflow markdown content
// - filesObject (optional): a JS object mapping file paths to content strings,
// used for import resolution (e.g. {"shared/tools.md": "---\ntools:..."})
// - filename (optional): the source filename (e.g. "my-workflow.md"), defaults to "workflow.md"
func compileWorkflow(this js.Value, args []js.Value) any {
if len(args) < 1 {
return newRejectedPromise("compileWorkflow requires at least 1 argument: markdown string")
Expand All @@ -34,6 +35,12 @@ func compileWorkflow(this js.Value, args []js.Value) any {
files = jsObjectToFileMap(args[1])
}

// Extract optional filename from third argument
filename := "workflow.md"
if len(args) >= 3 && !args[2].IsNull() && !args[2].IsUndefined() {
filename = args[2].String()
}

var handler js.Func
handler = js.FuncOf(func(this js.Value, promiseArgs []js.Value) any {
resolve := promiseArgs[0]
Expand All @@ -42,7 +49,7 @@ func compileWorkflow(this js.Value, args []js.Value) any {
go func() {
defer handler.Release()

result, err := doCompile(markdown, files)
result, err := doCompile(markdown, files, filename)
if err != nil {
reject.Invoke(js.Global().Get("Error").New(err.Error()))
return
Expand Down Expand Up @@ -73,7 +80,7 @@ func jsObjectToFileMap(obj js.Value) map[string][]byte {
}

// doCompile performs the actual compilation entirely in memory.
func doCompile(markdown string, files map[string][]byte) (js.Value, error) {
func doCompile(markdown string, files map[string][]byte, filename string) (js.Value, error) {
// Set up virtual filesystem for import resolution
if files != nil {
parser.SetVirtualFiles(files)
Expand All @@ -86,12 +93,12 @@ func doCompile(markdown string, files map[string][]byte) (js.Value, error) {
)

// Parse directly from string — no temp files needed
workflowData, err := compiler.ParseWorkflowString(markdown, "workflow.md")
workflowData, err := compiler.ParseWorkflowString(markdown, filename)
if err != nil {
return js.Undefined(), err
}

yamlContent, err := compiler.CompileToYAML(workflowData, "workflow.md")
yamlContent, err := compiler.CompileToYAML(workflowData, filename)
if err != nil {
return js.Undefined(), err
}
Expand Down
12 changes: 12 additions & 0 deletions pkg/parser/virtual_fs_test_helpers.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package parser

// SetReadFileFuncForTest overrides the file reading function for testing.
// This enables testing virtual filesystem behavior in native (non-wasm) builds.
// Returns a cleanup function that restores the original.
func SetReadFileFuncForTest(fn func(string) ([]byte, error)) func() {
original := readFileFunc
readFileFunc = fn
return func() {
readFileFunc = original
}
}
Loading
Loading