MCPcopy Create free account
hub / github.com/github/gh-aw / TestBuildAgentOutputDownloadSteps

Function TestBuildAgentOutputDownloadSteps

pkg/workflow/safe_output_helpers_test.go:694–753  ·  view source on GitHub ↗

TestBuildAgentOutputDownloadSteps verifies the agent output download steps include directory creation to handle cases where artifact doesn't exist, and that GH_AW_AGENT_OUTPUT is only set when the artifact download succeeds. The Gemini engine's GetPreBundleSteps moves /tmp/gemini-client-error-*.json

(t *testing.T)

Source from the content-addressed store, hash-verified

692// into /tmp/gh-aw/ before upload, so the artifact LCA is always /tmp/gh-aw/
693// and the hardcoded path is reliable.
694func TestBuildAgentOutputDownloadSteps(t *testing.T) {
695 steps := buildAgentOutputDownloadSteps("", getActionPin)
696 stepsStr := strings.Join(steps, "")
697
698 // Verify expected steps are present
699 expectedComponents := []string{
700 "- name: Download agent output artifact",
701 "id: download-agent-output",
702 "continue-on-error: true",
703 "uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c",
704 "name: agent",
705 "path: /tmp/gh-aw/",
706 "- name: Setup agent output environment variable",
707 "id: setup-agent-output-env",
708 "if: steps.download-agent-output.outcome == 'success'",
709 "mkdir -p /tmp/gh-aw/",
710 `find "/tmp/gh-aw/" -type f -print`,
711 // Hardcoded path is correct because GetPreBundleSteps ensures LCA is /tmp/gh-aw/
712 `echo "GH_AW_AGENT_OUTPUT=/tmp/gh-aw/agent_output.json" >> "$GITHUB_OUTPUT"`,
713 }
714
715 for _, expected := range expectedComponents {
716 if !strings.Contains(stepsStr, expected) {
717 t.Errorf("Expected step to contain %q, but it was not found.\nGenerated steps:\n%s", expected, stepsStr)
718 }
719 }
720
721 // Verify no dynamic find-based lookup is used (regression guard: the Gemini engine
722 // moves files to /tmp/gh-aw/ via GetPreBundleSteps so the hardcoded path is always valid)
723 if strings.Contains(stepsStr, "FOUND_FILE=$(find") {
724 t.Error("Step must not use dynamic find resolution; hardcoded path should be used instead")
725 }
726
727 // Verify mkdir comes before find to ensure directory exists
728 mkdirIdx := strings.Index(stepsStr, "mkdir -p /tmp/gh-aw/")
729 findIdx := strings.Index(stepsStr, `find "/tmp/gh-aw/"`)
730
731 if mkdirIdx == -1 {
732 t.Fatal("mkdir command not found in steps")
733 }
734 if findIdx == -1 {
735 t.Fatal("find command not found in steps")
736 }
737 if mkdirIdx > findIdx {
738 t.Error("mkdir should come before find to ensure directory exists")
739 }
740
741 // Verify env-setup conditional comes before the run command
742 condIdx := strings.Index(stepsStr, "if: steps.download-agent-output.outcome == 'success'")
743 runIdx := strings.Index(stepsStr, "run: |")
744 if condIdx == -1 {
745 t.Fatal("env-setup conditional not found in steps")
746 }
747 if runIdx == -1 {
748 t.Fatal("run command not found in steps")
749 }
750 if condIdx > runIdx {
751 t.Error("env-setup conditional should come before run command")

Callers

nothing calls this directly

Calls 3

ErrorfMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected