42 lines
1.4 KiB
Go
42 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")
|
||
|
|
}
|
||
|
|
}
|