fix(taskactions): resolve max_retries from the task's owning identity
WIRE, not delete: per-repo max_retries is a configured field with a real consumer (the retry gate), and it works for the legacy single-identity [[repos]] list. In a multi-identity deployment repositories live under [[identities.repos]] and there is no global [[repos]] at all, so the resolver never saw the override and a parked task was killed at the global cap rather than the configured one. MaxRetries now consults the identity named on the task before the legacy list, then falls back to the global cap. Identity name is the only thing that says which repository list owns a persisted row. Red-then-green: TestMaxRetriesResolvesFromTheOwningIdentity gained the multi-identity cases; "identity repo override wins over the global cap" failed with `MaxRetries = 3, want 7`. Two neighbouring cases keep the fix honest: another identity's override must not leak, and the legacy path must still resolve. Mutation-verified by deleting only the identity lookup, keeping the extracted helper and the API intact.
This commit is contained in:
2 files changed
+113
-3
No files matched your search
@@ -25,11 +25,36 @@ func MaxRetries(cfg *config.Holder) func(*taskactions.Task) int {
|
||||
return 0
|
||||
}
|
||||
c := cfg.Get()
|
||||
for _, repo := range c.Repos {
|
||||
if repo.Owner == t.Owner && repo.Name == t.Repo {
|
||||
return repo.EffectiveMaxRetries(c.MaxRetries)
|
||||
// A multi-identity deployment declares its repositories under
|
||||
// [[identities.repos]] and has no global [[repos]] at all, so the
|
||||
// task's owning identity is the only place a per-repo override can
|
||||
// live. Without this lookup the override is never matched and the
|
||||
// task dies at the global cap instead of the configured one.
|
||||
if t.Identity != "" {
|
||||
for _, identity := range c.Identities {
|
||||
if identity.Name != t.Identity {
|
||||
continue
|
||||
}
|
||||
if n, ok := repoMaxRetries(identity.Repos, t, c.MaxRetries); ok {
|
||||
return n
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
if n, ok := repoMaxRetries(c.Repos, t, c.MaxRetries); ok {
|
||||
return n
|
||||
}
|
||||
return c.MaxRetries
|
||||
}
|
||||
}
|
||||
|
||||
// repoMaxRetries returns the effective cap for the task's repository within one
|
||||
// repository list, and whether that list knows the repository at all.
|
||||
func repoMaxRetries(repos []config.Repo, t *taskactions.Task, global int) (int, bool) {
|
||||
for _, repo := range repos {
|
||||
if repo.Owner == t.Owner && repo.Name == t.Repo {
|
||||
return repo.EffectiveMaxRetries(global), true
|
||||
}
|
||||
}
|
||||
return 0, false
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package taskactions
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/samcharles93/archie-core/internal/config"
|
||||
"github.com/samcharles93/archie-core/internal/domain/taskactions"
|
||||
)
|
||||
|
||||
// TestMaxRetriesResolvesFromTheOwningIdentity pins the retry cap's resolution
|
||||
// order. A multi-identity deployment declares its repositories under
|
||||
// [[identities.repos]] and has no global [[repos]] at all, so a resolver that
|
||||
// only walks cfg.Repos never sees the per-repo override and the task is killed
|
||||
// at the global cap instead of the configured one. The task's stored Identity
|
||||
// is the only thing that says which identity's repository list owns the row.
|
||||
func TestMaxRetriesResolvesFromTheOwningIdentity(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
cfg config.Config
|
||||
task taskactions.Task
|
||||
want int
|
||||
}{
|
||||
{
|
||||
name: "identity repo override wins over the global cap",
|
||||
cfg: config.Config{
|
||||
MaxRetries: 3,
|
||||
Identities: []config.IdentityConfig{{
|
||||
Name: "gh",
|
||||
Repos: []config.Repo{{Owner: "acme", Name: "widget", MaxRetries: 7}},
|
||||
}},
|
||||
},
|
||||
task: taskactions.Task{Owner: "acme", Repo: "widget", Identity: "gh"},
|
||||
want: 7,
|
||||
},
|
||||
{
|
||||
name: "identity repo with no override uses the global cap",
|
||||
cfg: config.Config{
|
||||
MaxRetries: 3,
|
||||
Identities: []config.IdentityConfig{{
|
||||
Name: "gh",
|
||||
Repos: []config.Repo{{Owner: "acme", Name: "widget"}},
|
||||
}},
|
||||
},
|
||||
task: taskactions.Task{Owner: "acme", Repo: "widget", Identity: "gh"},
|
||||
want: 3,
|
||||
},
|
||||
{
|
||||
name: "another identity's override does not leak",
|
||||
cfg: config.Config{
|
||||
MaxRetries: 3,
|
||||
Identities: []config.IdentityConfig{
|
||||
{Name: "gh", Repos: []config.Repo{{Owner: "acme", Name: "widget", MaxRetries: 7}}},
|
||||
{Name: "gitea", Repos: []config.Repo{{Owner: "acme", Name: "widget"}}},
|
||||
},
|
||||
},
|
||||
task: taskactions.Task{Owner: "acme", Repo: "widget", Identity: "gitea"},
|
||||
want: 3,
|
||||
},
|
||||
{
|
||||
name: "legacy single-identity repos still resolve",
|
||||
cfg: config.Config{
|
||||
MaxRetries: 3,
|
||||
Repos: []config.Repo{{Owner: "acme", Name: "widget", MaxRetries: 9}},
|
||||
},
|
||||
task: taskactions.Task{Owner: "acme", Repo: "widget"},
|
||||
want: 9,
|
||||
},
|
||||
{
|
||||
name: "an unknown repository falls back to the global cap",
|
||||
cfg: config.Config{MaxRetries: 5},
|
||||
task: taskactions.Task{Owner: "other", Repo: "thing", Identity: "gh"},
|
||||
want: 5,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
got := MaxRetries(config.NewHolder(tc.cfg))(&tc.task)
|
||||
if got != tc.want {
|
||||
t.Fatalf("MaxRetries = %d, want %d (identity %q, repo %s/%s)",
|
||||
got, tc.want, tc.task.Identity, tc.task.Owner, tc.task.Repo)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user