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

Function TestWorkspaceCheckoutForDetectionStep

pkg/workflow/threat_detection_test.go:1646–1691  ·  view source on GitHub ↗

TestWorkspaceCheckoutForDetectionStep verifies that a conditional checkout step is added to the detection job when threat detection is enabled, allowing the engine to see patches in the context of the full repository.

(t *testing.T)

Source from the content-addressed store, hash-verified

1644// is added to the detection job when threat detection is enabled, allowing the
1645// engine to see patches in the context of the full repository.
1646func TestWorkspaceCheckoutForDetectionStep(t *testing.T) {
1647 compiler := NewCompiler()
1648
1649 data := &WorkflowData{
1650 Name: "test-workflow",
1651 AI: "copilot",
1652 SafeOutputs: &SafeOutputsConfig{
1653 ThreatDetection: &ThreatDetectionConfig{},
1654 },
1655 }
1656
1657 job, err := compiler.buildDetectionJob(data)
1658 if err != nil {
1659 t.Fatalf("buildDetectionJob() error: %v", err)
1660 }
1661 if job == nil {
1662 t.Fatal("buildDetectionJob() returned nil job")
1663 }
1664
1665 stepsString := strings.Join(job.Steps, "")
1666
1667 // Workspace checkout step should be present
1668 if !strings.Contains(stepsString, "Checkout repository for patch context") {
1669 t.Error("Detection job should include workspace checkout step")
1670 }
1671
1672 // Step should be conditional on has_patch
1673 expectedCondition := "if: needs." + string(constants.AgentJobName) + ".outputs.has_patch == 'true'"
1674 if !strings.Contains(stepsString, expectedCondition) {
1675 t.Errorf("Workspace checkout step should have has_patch condition, expected %q in steps", expectedCondition)
1676 }
1677
1678 // Step should disable credential persistence
1679 if !strings.Contains(stepsString, "persist-credentials: false") {
1680 t.Error("Workspace checkout step should set persist-credentials: false")
1681 }
1682
1683 // Step should use pinned actions/checkout
1684 checkoutPin := getActionPin("actions/checkout")
1685 if checkoutPin == "" {
1686 t.Fatal("Expected actions/checkout to have a pin")
1687 }
1688 if !strings.Contains(stepsString, checkoutPin) {
1689 t.Errorf("Workspace checkout step should use pinned action %q", checkoutPin)
1690 }
1691}
1692
1693// TestDetectionJobAlwaysHasContentsRead verifies that the detection job always
1694// receives contents: read permission (required for the workspace checkout step),

Callers

nothing calls this directly

Calls 5

buildDetectionJobMethod · 0.95
NewCompilerFunction · 0.85
getActionPinFunction · 0.85
ErrorMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected