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

Function TestConclusionJobWithGeneratedAssets

pkg/workflow/notify_comment_test.go:567–625  ·  view source on GitHub ↗

TestConclusionJobWithGeneratedAssets tests that the conclusion job includes environment variables for safe output job URLs when safe output jobs are present

(t *testing.T)

Source from the content-addressed store, hash-verified

565// TestConclusionJobWithGeneratedAssets tests that the conclusion job includes environment variables
566// for safe output job URLs when safe output jobs are present
567func TestConclusionJobWithGeneratedAssets(t *testing.T) {
568 compiler := NewCompiler()
569
570 statusCommentTrue := true
571 // Create workflow data with safe outputs configuration
572 workflowData := &WorkflowData{
573 Name: "Test Workflow",
574 StatusComment: &statusCommentTrue, // Explicitly enable status comments
575 SafeOutputs: &SafeOutputsConfig{
576 AddComments: &AddCommentsConfig{
577 BaseSafeOutputConfig: BaseSafeOutputConfig{
578 Max: strPtr("1"),
579 },
580 },
581 NoOp: &NoOpConfig{},
582 },
583 AIReaction: "eyes",
584 }
585
586 // Define safe output jobs that should have URL outputs
587 safeOutputJobNames := []string{
588 "create_issue",
589 "add_comment",
590 "create_pull_request",
591 "create_discussion",
592 }
593
594 // Build the conclusion job
595 job, err := compiler.buildConclusionJob(workflowData, string(constants.AgentJobName), safeOutputJobNames)
596 if err != nil {
597 t.Fatalf("Failed to build conclusion job: %v", err)
598 }
599
600 if job == nil {
601 t.Fatal("Expected conclusion job to be created")
602 }
603
604 // Convert job to YAML string for checking
605 jobYAML := strings.Join(job.Steps, "")
606
607 // Check that GH_AW_SAFE_OUTPUT_JOBS environment variable is declared with JSON mapping
608 if !strings.Contains(jobYAML, "GH_AW_SAFE_OUTPUT_JOBS:") {
609 t.Error("Expected GH_AW_SAFE_OUTPUT_JOBS environment variable to be declared")
610 }
611
612 // Check that individual URL output environment variables are declared
613 expectedEnvVars := []string{
614 "GH_AW_OUTPUT_CREATE_ISSUE_ISSUE_URL: ${{ needs.create_issue.outputs.issue_url }}",
615 "GH_AW_OUTPUT_ADD_COMMENT_COMMENT_URL: ${{ needs.add_comment.outputs.comment_url }}",
616 "GH_AW_OUTPUT_CREATE_PULL_REQUEST_PULL_REQUEST_URL: ${{ needs.create_pull_request.outputs.pull_request_url }}",
617 "GH_AW_OUTPUT_CREATE_DISCUSSION_DISCUSSION_URL: ${{ needs.create_discussion.outputs.discussion_url }}",
618 }
619
620 for _, expectedVar := range expectedEnvVars {
621 if !strings.Contains(jobYAML, expectedVar) {
622 t.Errorf("Expected environment variable not found: %s", expectedVar)
623 }
624 }

Callers

nothing calls this directly

Calls 5

buildConclusionJobMethod · 0.95
NewCompilerFunction · 0.85
strPtrFunction · 0.85
ErrorMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected