fix: tighten config and update error handling

This commit is contained in:
2026-05-13 17:03:20 +08:00
parent 9af18f400c
commit 142c611fcb
4 changed files with 49 additions and 4 deletions

View File

@@ -180,6 +180,37 @@ func TestRunAutoUpdateSkipsDirtyRepositories(t *testing.T) {
}
}
func TestRunAutoUpdateKeepsCurrentCommitError(t *testing.T) {
svc, _, _, _, git, _ := newTestService(t)
saveValidConfig(t, svc)
local := filepath.Join(t.TempDir(), "demo")
state := domain.State{Skills: []domain.SkillState{{
Org: "skills",
Repo: "demo",
LocalPath: local,
DefaultBranch: "main",
CurrentCommit: "old",
}}}
if err := svc.store.Save(state); err != nil {
t.Fatal(err)
}
git.remoteCommit[local] = "new"
git.currentErr[local] = errors.New("rev-parse failed")
if err := svc.RunAutoUpdate(context.Background()); err != nil {
t.Fatalf("RunAutoUpdate returned error: %v", err)
}
reloaded, err := svc.store.Load()
if err != nil {
t.Fatal(err)
}
saved, _ := skillstore.FindSkill(reloaded, "skills", "demo")
if saved.LastError != "rev-parse failed" {
t.Fatalf("LastError = %q, want rev-parse failed", saved.LastError)
}
}
func newTestService(t *testing.T) (*Service, Paths, *fakeSecretStore, *fakeRemoteClient, *fakeGit, *fakeTargets) {
t.Helper()
dir := t.TempDir()
@@ -192,7 +223,7 @@ func newTestService(t *testing.T) (*Service, Paths, *fakeSecretStore, *fakeRemot
}
secrets := &fakeSecretStore{values: map[string]string{}}
remote := &fakeRemoteClient{}
git := &fakeGit{dirty: map[string]bool{}, currentCommit: map[string]string{}, remoteCommit: map[string]string{}}
git := &fakeGit{dirty: map[string]bool{}, currentCommit: map[string]string{}, remoteCommit: map[string]string{}, currentErr: map[string]error{}}
target := &fakeTargets{}
svc := New(Options{
Paths: paths,
@@ -263,6 +294,7 @@ type fakeGit struct {
dirty map[string]bool
currentCommit map[string]string
remoteCommit map[string]string
currentErr map[string]error
pullCalls int
}
@@ -272,6 +304,9 @@ func (f *fakeGit) Pull(context.Context, string, gitops.Credentials) error {
return nil
}
func (f *fakeGit) CurrentCommit(path string) (string, error) {
if err := f.currentErr[path]; err != nil {
return "", err
}
if commit := f.currentCommit[path]; commit != "" {
return commit, nil
}