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
10 changes: 9 additions & 1 deletion pkg/workflow/compiler_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,15 @@ func (d *WorkflowData) PinContext() *actionpins.PinContext {
// resolver targets that host and fails to resolve actions/* repos which live
// on github.com. Silently falling back to bundled hardcoded pins in that
// case produces unverified SHA pins, so disable the fallback.
if ghHost := os.Getenv("GH_HOST"); ghHost != "" && ghHost != "github.com" {
// When GH_HOST is unset, fall back to the programmatic default host (set
// for example from auto-detected git remotes). Mirror setupGHCommand's
// (github_cli.go) precedence: GH_HOST wins when present; default host is
// only consulted when GH_HOST is absent.
if ghHost := os.Getenv("GH_HOST"); ghHost != "" {
if ghHost != "github.com" {
pinCtx.SkipHardcodedFallback = true
}
} else if defaultHost := getDefaultGHHost(); defaultHost != "" && defaultHost != "github.com" {
pinCtx.SkipHardcodedFallback = true
}
return pinCtx
Expand Down
40 changes: 40 additions & 0 deletions pkg/workflow/compiler_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ import (
)

func TestWorkflowData_PinContext_SkipHardcodedFallback(t *testing.T) {
originalDefaultHost := getDefaultGHHost()
t.Cleanup(func() {
SetDefaultGHHost(originalDefaultHost)
})

t.Run("sets SkipHardcodedFallback when GH_HOST is a non-github.qkg1.top host", func(t *testing.T) {
t.Setenv("GH_HOST", "myorg.ghe.com")

Expand All @@ -31,8 +36,21 @@ func TestWorkflowData_PinContext_SkipHardcodedFallback(t *testing.T) {
assert.False(t, ctx.SkipHardcodedFallback, "Expected SkipHardcodedFallback to be false when GH_HOST is github.com")
})

t.Run("GH_HOST=github.com wins over non-github.qkg1.top default host", func(t *testing.T) {
t.Setenv("GH_HOST", "github.com")
SetDefaultGHHost("myorg.ghe.com")
t.Cleanup(func() { SetDefaultGHHost("") })

d := &WorkflowData{}
ctx := d.PinContext()

require.NotNil(t, ctx)
assert.False(t, ctx.SkipHardcodedFallback, "Expected SkipHardcodedFallback to be false when GH_HOST=github.com even if default host is GHE")
})

t.Run("does not set SkipHardcodedFallback when GH_HOST is not set", func(t *testing.T) {
require.NoError(t, os.Unsetenv("GH_HOST"))
SetDefaultGHHost("")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[/tdd] The sibling sub-test "does not set SkipHardcodedFallback when GH_HOST is github.com" also asserts SkipHardcodedFallback = false but doesn't call SetDefaultGHHost(""). Now that sub-tests 4 and 5 mutate the shared defaultGHHost, sub-test 2 relies on execution order for isolation.

💡 Suggested fix for sub-test 2
t.Run("does not set SkipHardcodedFallback when GH_HOST is github.com", func(t *testing.T) {
	t.Setenv("GH_HOST", "github.com")
	SetDefaultGHHost("") // add this guard

	d := &WorkflowData{}
	ctx := d.PinContext()
	...
})

Without this, if a future sub-test is inserted before it that sets defaultGHHost to a GHE host, the assert.False assertion would spuriously fail.


Comment on lines 51 to 54
d := &WorkflowData{}
ctx := d.PinContext()
Expand All @@ -41,6 +59,28 @@ func TestWorkflowData_PinContext_SkipHardcodedFallback(t *testing.T) {
assert.False(t, ctx.SkipHardcodedFallback, "Expected SkipHardcodedFallback to be false when GH_HOST is not set")
})

t.Run("sets SkipHardcodedFallback when default GH host is a non-github.qkg1.top host", func(t *testing.T) {
require.NoError(t, os.Unsetenv("GH_HOST"))
SetDefaultGHHost("myorg.ghe.com")

d := &WorkflowData{}
ctx := d.PinContext()

require.NotNil(t, ctx)
assert.True(t, ctx.SkipHardcodedFallback, "Expected SkipHardcodedFallback to be true when default GH host is a GHE host")
})

t.Run("does not set SkipHardcodedFallback when default GH host is github.com", func(t *testing.T) {
require.NoError(t, os.Unsetenv("GH_HOST"))
SetDefaultGHHost("github.com")

d := &WorkflowData{}
ctx := d.PinContext()

require.NotNil(t, ctx)
assert.False(t, ctx.SkipHardcodedFallback, "Expected SkipHardcodedFallback to be false when default GH host is github.com")
})

t.Run("returns nil for nil WorkflowData", func(t *testing.T) {
var d *WorkflowData
ctx := d.PinContext()
Expand Down
6 changes: 6 additions & 0 deletions pkg/workflow/github_cli_wasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,9 @@ func RunGHCombined(spinnerMessage string, args ...string) ([]byte, error) {
func ForceGHHostEnv(cmd *exec.Cmd, host string) {
// no-op in Wasm: gh CLI subprocesses are not run
}

// SetDefaultGHHost is a no-op in Wasm builds; GH CLI is unavailable.
func SetDefaultGHHost(_ string) {}

// getDefaultGHHost always returns "" in Wasm builds.
func getDefaultGHHost() string { return "" }
Loading