Files
git-runner/act/runner/run_context_apiurl_test.go
zeekayandHanzo Dev cf55efbb4f fix: honour the server's api_url instead of hardcoding <instance>/api/v1
Every docker build on this forge fails at `Extract metadata`:

    ::group::Run Extract metadata
    ::error::Not found.%0A

and takes build-arm64, create-manifest, tag-single-arch, deploy and sbom
to `skipped` with it. Measured across the estate: build-amd64 has 0
successes and fails identically in every repo using the shared reusable
(hanzoai/cli 2026-07-31, hanzoai/team 2026-08-01).

docker/metadata-action reads repo metadata through octokit, which builds
$GITHUB_API_URL + "/repos/...". This forge serves its API at bare /v1:

    git.hanzo.ai/api/v1/repos/hanzoai/team   404   <- Gitea layout
    git.hanzo.ai/api/v3/repos/hanzoai/team   404   <- GHES layout
    git.hanzo.ai/v1/repos/hanzoai/team       200

The server already publishes that correctly — services/actions/context.go
sets "api_url" to AppURL + "v1", with integration tests asserting it. The
runner threw it away. getGithubContext copies sixteen fields off the
preset (Event, RunID, Actor, Repository, Sha, Ref, Token, ...) and then
overwrote APIURL with instance + "/api/v1", returning before the
GITHUB_API_URL user override could apply. withGithubEnv then recomputed
the same suffix over env, so $GITHUB_API_URL disagreed with
${{ github.api_url }} — and octokit reads the env one, so no amount of
configuration could reach it.

Both now prefer the resolved value and fall back to the upstream Gitea
layout only when nothing was supplied, so a stock Gitea is unaffected.
The two fallback cases in the new test pass against the UNPATCHED source;
the two api_url cases fail there with actual "https://git.hanzo.ai/api/v1",
which is exactly the URL measured returning 404 above.

Same shape as b304bfa: the server sends a URL, the runner discards it for
an upstream assumption, and the job dies somewhere that looks unrelated.

Co-authored-by: Hanzo Dev <[email protected]>
2026-08-01 03:06:59 -07:00

99 lines
2.7 KiB
Go

package runner
import (
"context"
"testing"
"github.com/hanzoai/git-runner/act/model"
"github.com/stretchr/testify/assert"
)
// The server publishes where its API lives via the github context's "api_url".
// The runner used to discard that and hardcode <instance>/api/v1, so a forge
// serving its API anywhere else made every octokit-based action 404 ("Not
// found." out of docker/metadata-action, which takes the whole build with it).
func TestGetGithubContextAPIURLHonoursPreset(t *testing.T) {
for _, tc := range []struct {
name string
presetAPI string
instance string
want string
}{
{
name: "server-supplied api_url wins",
presetAPI: "https://git.hanzo.ai/v1",
instance: "git.hanzo.ai",
want: "https://git.hanzo.ai/v1",
},
{
name: "empty api_url falls back to the upstream Gitea layout",
presetAPI: "",
instance: "gitea.example.com",
want: "https://gitea.example.com/api/v1",
},
{
name: "a scheme already on the instance is not doubled",
presetAPI: "",
instance: "https://gitea.example.com",
want: "https://gitea.example.com/api/v1",
},
} {
t.Run(tc.name, func(t *testing.T) {
rc := &RunContext{
Config: &Config{
GitHubInstance: tc.instance,
PresetGitHubContext: &model.GithubContext{
APIURL: tc.presetAPI,
},
},
Run: &model.Run{
JobID: "job",
Workflow: &model.Workflow{
Jobs: map[string]*model.Job{"job": {}},
},
},
}
assert.Equal(t, tc.want, rc.getGithubContext(context.Background()).APIURL)
})
}
}
// withGithubEnv must mirror the resolved context. It used to recompute the
// suffix, so $GITHUB_API_URL disagreed with ${{ github.api_url }} — and actions
// read the env one.
func TestWithGithubEnvAPIURLMirrorsContext(t *testing.T) {
rc := &RunContext{
Config: &Config{GitHubInstance: "git.hanzo.ai"},
Run: &model.Run{
JobID: "job",
Workflow: &model.Workflow{
Jobs: map[string]*model.Job{"job": {}},
},
},
}
gh := &model.GithubContext{APIURL: "https://git.hanzo.ai/v1"}
env := rc.withGithubEnv(context.Background(), gh, map[string]string{})
assert.Equal(t, "https://git.hanzo.ai/v1", env["GITHUB_API_URL"])
}
// An empty context still yields a usable default rather than an empty env var.
func TestWithGithubEnvAPIURLFallsBack(t *testing.T) {
rc := &RunContext{
Config: &Config{GitHubInstance: "gitea.example.com"},
Run: &model.Run{
JobID: "job",
Workflow: &model.Workflow{
Jobs: map[string]*model.Job{"job": {}},
},
},
}
env := rc.withGithubEnv(context.Background(), &model.GithubContext{}, map[string]string{})
assert.Equal(t, "https://gitea.example.com/api/v1", env["GITHUB_API_URL"])
}