Files
agent-lib/internal/e2e/sync_default_branch_test.go
m3ta-chiron 2017329015 fix(client): resolve default branch from the remote advertisement
A cached bare clone's HEAD points at refs/heads/<branch>, which is written
once at clone time and never updated again — fetch only touches
refs/remotes/*. Syncs without --ref therefore resolved the frozen
clone-time revision forever: the literal "cached version of the repo"
symptom.

Resolve the default branch via remote.List instead: the advertised HEAD
(plain hash or symref target) is the only source of truth. Verified
against the production Forgejo instance; e2e test fails on the pre-fix
binary and passes now.
2026-10-02 12:34:41 +02:00

43 lines
1.4 KiB
Go

package e2e
import (
"os"
"path/filepath"
"testing"
)
// TestSyncDefaultBranchStaysFresh pins the fix for the stale-cache bug: with
// no ref configured, sync must resolve the default branch from the remote
// advertisement, never from the cached bare clone's frozen refs/heads ref.
func TestSyncDefaultBranchStaysFresh(t *testing.T) {
h := newHarness(t)
env := newSyncEnv(t, h)
buildWorkRepo(t, h, env.workRepo)
// config without "ref": the default-branch resolution path
env.config = filepath.Join(env.configDir, "config.json")
os.WriteFile(env.config, []byte(`{"repo_url": "`+env.workRepo+`"}`), 0o600)
if _, err := env.run(t); err != nil {
t.Fatal(err)
}
// upstream change on the default branch
p := filepath.Join(env.workRepo, "commands/deploy.md")
os.WriteFile(p, []byte("---\nname: Deploy\ndescription: updated\n---\nfresh body\n"), 0o644)
h.git(t, env.workRepo, "add", "-A")
h.git(t, env.workRepo, "commit", "-m", "update command on default branch")
out, err := env.run(t)
if err != nil {
t.Fatalf("second sync (default branch) failed: %v\n%s", err, out)
}
if !contains(out, "updated: 1") {
t.Errorf("default-branch sync must pick up the upstream change:\n%s", out)
}
deployed := readFile(t, filepath.Join(env.home, ".config/opencode/commands/deploy.md"))
if !contains(deployed, "fresh body") {
t.Error("default-branch sync must deploy the fresh content, not the clone-time revision")
}
}