Files
archie/internal/daemon/intake_cap_test.go
T
sam e3ffefdc7d
deploy / plan (push) Successful in 25s
deploy / gate (push) Successful in 7m57s
deploy / agent-image (push) Successful in 21s
deploy / dist-zip (push) Skipped
deploy / archied-image (push) Successful in 2m12s
fix(identity): use System as the one root identity and record who created every task (#1851)
Drop the bot_user-derived root identity and the empty-identity sentinel. System
polls forge connections and owns instance-level work; a polled task stores the
polling identity, task_queued and work_request_submitted carry task id, actor
and principal, and an empty task identity is refused. Migration 0072 moves
empty tasks.identity, the identity-grants root key and the old root's
connection permits to System so a re-poll dedups.
2026-11-10 20:01:16 +11:00

72 lines
1.9 KiB
Go

package daemon
import (
"context"
"log/slog"
"testing"
"github.com/samcharles93/archie-core/internal/config"
"github.com/samcharles93/archie-core/internal/domain/storecontract"
"github.com/samcharles93/archie-core/internal/domain/workflow"
"github.com/samcharles93/archie-core/internal/forge"
)
type taskLookup struct {
storecontract.TaskStore
have map[int]bool
}
func (s taskLookup) TaskByIssue(_ context.Context, _, _ string, number int) (*workflow.Task, error) {
if s.have[number] {
return &workflow.Task{IssueNumber: number}, nil
}
return nil, nil
}
type publishCounter struct {
stubTasks
published int
}
func (p *publishCounter) PublishUnique(context.Context, string, string, []byte) error {
p.published++
return nil
}
// One poll creates at most the cap of tasks; the rest wait for a later poll,
// and an issue that already has a task neither counts nor is created twice.
func TestPublishDiscoveredCap(t *testing.T) {
tests := []struct {
name string
issues int
existing []int
cap int
want int
}{
{"cap below backlog", 10, nil, 3, 3},
{"backlog below cap", 2, nil, 3, 2},
{"existing tasks do not use the cap", 6, []int{1, 2}, 3, 3},
{"no cap", 10, nil, 0, 10},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
bus := &publishCounter{}
have := map[int]bool{}
for _, n := range tt.existing {
have[n] = true
}
d := &Daemon{Log: slog.New(slog.DiscardHandler), Store: taskLookup{have: have}, Tasks: bus}
var issues []forge.Issue
for n := 1; n <= tt.issues; n++ {
issues = append(issues, forge.Issue{Number: n, Labels: []string{"archie"}})
}
room := tt.cap
repo := config.Repo{Owner: "acme", Name: "widget"}
d.publishDiscovered(t.Context(), nil, config.Config{}, repo, issues, string(sys), &room)
if bus.published != tt.want {
t.Fatalf("published %d tasks, want %d", bus.published, tt.want)
}
})
}
}