diff --git a/pkg/cli/compile_integration_test.go b/pkg/cli/compile_integration_test.go index 5138b086743..755182bf19e 100644 --- a/pkg/cli/compile_integration_test.go +++ b/pkg/cli/compile_integration_test.go @@ -2247,3 +2247,65 @@ func TestCompileWithActionsRepoDefaultFallback(t *testing.T) { t.Logf("Default actions repo test passed - default repo baked into lock file: %s", lockFilePath) } + +func TestCompileWithActionRefOverrideIncludesCompilerVersionMetadata(t *testing.T) { + tests := []struct { + name string + args []string + }{ + { + name: "action-tag", + args: []string{"--action-tag", "v9.9.9"}, + }, + { + name: "gh-aw-ref", + args: []string{"--gh-aw-ref", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"}, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + setup := setupIntegrationTest(t) + defer setup.cleanup() + + srcPath := filepath.Join(projectRoot, "pkg/cli/workflows/test-actions-repo.md") + dstPath := filepath.Join(setup.workflowsDir, "test-actions-repo.md") + + srcContent, err := os.ReadFile(srcPath) + if err != nil { + t.Fatalf("Failed to read source workflow file %s: %v", srcPath, err) + } + if err := os.WriteFile(dstPath, srcContent, 0o644); err != nil { + t.Fatalf("Failed to write workflow to test dir: %v", err) + } + + cmdArgs := append([]string{"compile"}, tt.args...) + cmdArgs = append(cmdArgs, dstPath) + cmd := exec.Command(setup.binaryPath, cmdArgs...) + output, err := cmd.CombinedOutput() + if err != nil { + t.Fatalf("CLI compile command failed: %v\nOutput: %s", err, string(output)) + } + + lockFilePath := filepath.Join(setup.workflowsDir, "test-actions-repo.lock.yml") + lockContent, err := os.ReadFile(lockFilePath) + if err != nil { + t.Fatalf("Failed to read lock file: %v", err) + } + + metadataLine := "" + for line := range strings.SplitSeq(string(lockContent), "\n") { + if strings.Contains(line, "gh-aw-metadata:") { + metadataLine = line + break + } + } + if metadataLine == "" { + t.Fatal("Could not find gh-aw-metadata in lock file") + } + if !strings.Contains(metadataLine, `"compiler_version":"`) || strings.Contains(metadataLine, `"compiler_version":""`) { + t.Fatalf("Expected non-empty compiler_version in metadata, got: %s", metadataLine) + } + }) + } +} diff --git a/pkg/workflow/compiler_yaml.go b/pkg/workflow/compiler_yaml.go index 2975827fbc6..56961b56c71 100644 --- a/pkg/workflow/compiler_yaml.go +++ b/pkg/workflow/compiler_yaml.go @@ -109,6 +109,9 @@ func (c *Compiler) generateWorkflowHeader(yaml *strings.Builder, data *WorkflowD agentInfo.EngineVersions = collectEngineVersionsForMetadata(data) agentInfo.AgentImageRunner = resolveAgentImageRunnerIdentifier(data.RawFrontmatter) metadata := GenerateLockMetadata(LockHashInfo{FrontmatterHash: frontmatterHash, BodyHash: bodyHash}, data.StopTime, c.effectiveStrictMode(data.RawFrontmatter), agentInfo) + if metadata.CompilerVersion == "" && c.GetActionTag() != "" { + metadata.CompilerVersion = c.GetVersion() + } metadataJSON, err := metadata.ToJSON() if err != nil { // Fallback to legacy format if JSON serialization fails diff --git a/pkg/workflow/compiler_yaml_test.go b/pkg/workflow/compiler_yaml_test.go index 2ddc202bb11..43f969c6dcf 100644 --- a/pkg/workflow/compiler_yaml_test.go +++ b/pkg/workflow/compiler_yaml_test.go @@ -1399,18 +1399,28 @@ func TestLockMetadataVersionInReleaseBuilds(t *testing.T) { name string isRelease bool version string + actionTag string expectVersion bool }{ { name: "dev build should not include version", isRelease: false, version: "dev", + actionTag: "", expectVersion: false, }, { name: "release build should include version", isRelease: true, version: "v0.1.2", + actionTag: "", + expectVersion: true, + }, + { + name: "action-tag compile should include current ref", + isRelease: false, + version: "401bd13", + actionTag: "v9.9.9", expectVersion: true, }, } @@ -1437,6 +1447,7 @@ Test prompt. // Compile the workflow compiler := NewCompiler() + compiler.SetActionTag(tt.actionTag) err := compiler.CompileWorkflow(workflowPath) if err != nil { t.Fatalf("Failed to compile workflow: %v", err)