This repository has been archived on 2026-09-06. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
cad-atlas/internal/atlas/stuck_test.go
T
mathiasandClaude Opus 5 097d8747c6
CD / Deploy via GitOps (push) Successful in 0s
CD / Detect unsubstituted template (push) Successful in 1s
CD / Lint / Test / Vet (push) Successful in 6s
CD / var-go/oath (push) Skipped
CD / Build & Import (push) Successful in 5s
feat(atlas): surface the user's own Gitea repos on stage 05 (#10)
Adds the repos panel from #4's "Not yet shipped" list, following the shipped
issues slice (b2761a4) structurally rather than inventing a second approach:

- internal/atlas/repos.go — RepoNodes(), a pure parser over an already-decoded
  /user/repos response. Archived repos are dropped: the atlas shows where work
  happens, and an archived repo is by definition somewhere it does not.
- internal/gitea/client.go — MyRepos(), same PAT and same contract as MyIssues:
  errors when GITEA_TOKEN is unset so the caller skips the overlay rather than
  issuing an unauthenticated request. That unset path is the one running in
  prod today (#4), so it is tested, not assumed.
- internal/web/handler.go — wired into liveOverlay().

Stage 05 is the right home — repos are what the execution stage acts on — but
#11 had just claimed its `generate` key for stuck-badges, and a stage could
only name one source. So `generate` now accepts either spelling:

    "generate": "ci-jobs"
    "generate": ["stuck-badges", "gitea-repos"]

The bare string stays valid and marshals back as a bare string, so no authored
stage is rewritten and the frontend contract is unchanged. Stages 04 and 08
already share stuck-badges between them; this is the same growth one level in.

The overlay merge also moves out of the handler into atlas.PrependGenerated,
which is unit-testable where the inline loop was not — it sat behind a network
call. It covers the issues path too, and fixes a latent aliasing bug there: the
old `append(liveNodes, authored...)` wrote into the live slice's backing array,
so two stages sharing a key would corrupt each other. That shape is no longer
hypothetical now that stuck-badges spans three stages.

Verified end-to-end both ways: without GITEA_TOKEN the atlas returns 200 with
stage 05's authored nodes intact; with a real token stage 05 serves both
overlays at once — stuck badges, then eight live repos, then the authored
nodes — and a repo with no language emits one tag rather than an empty pill.

task check green (golangci-lint 0 issues, vet, -race).

Closes #10.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-28 22:01:48 +02:00

115 lines
4.2 KiB
Go

package atlas_test
import (
"testing"
"git.d-ma.be/mathias/cad-atlas/internal/atlas"
caddomain "git.d-ma.be/mathias/cad/domain"
)
func stage(no, generate string) atlas.Stage {
s := atlas.Stage{No: no, Title: "example"}
if generate != "" {
s.Generate = atlas.GenerateKeys{generate}
}
return s
}
func finding(repo string, issue int, cat caddomain.StuckCategory, class caddomain.StuckClass) caddomain.StuckFinding {
return caddomain.StuckFinding{
Repo: repo, Issue: issue, Title: "example", Category: cat, Class: class,
Detail: "detail",
Locators: []string{"https://git.d-ma.be/" + repo + "/issues/1"},
}
}
func TestApplyStuckOverlay_BadgesOnlyOnGeneratedStages(t *testing.T) {
stages := []atlas.Stage{
stage("STAGE 04", ""), // no generate marker — must be untouched
stage("STAGE 04b", "stuck-badges"), // marked but no findings map here
}
out := atlas.ApplyStuckOverlay(stages, nil)
if len(out[0].Nodes) != 0 || out[0].StuckCount != 0 {
t.Fatalf("un-marked stage was touched: %+v", out[0])
}
}
func TestApplyStuckOverlay_ArmedNeverFiredGoesToStage04(t *testing.T) {
stages := []atlas.Stage{stage("STAGE 04", "stuck-badges")}
findings := []caddomain.StuckFinding{
finding("mathias/brain-gardener", 190, caddomain.CategoryArmedNeverFired, caddomain.ClassStuck),
}
out := atlas.ApplyStuckOverlay(stages, findings)
if out[0].StuckCount != 1 || out[0].AwaitingCount != 0 {
t.Fatalf("counts = stuck=%d awaiting=%d, want stuck=1 awaiting=0", out[0].StuckCount, out[0].AwaitingCount)
}
if len(out[0].Nodes) != 1 {
t.Fatalf("want 1 node, got %d", len(out[0].Nodes))
}
n := out[0].Nodes[0]
if n.Cls != "stuck" {
t.Errorf("Cls = %q, want %q", n.Cls, "stuck")
}
if n.URL == "" {
t.Error("node has no URL locator")
}
if n.Title != "#190 armed_never_fired" {
t.Errorf("Title = %q", n.Title)
}
}
func TestApplyStuckOverlay_DoneNotClosedIsAwaitingHumanAtStage08(t *testing.T) {
stages := []atlas.Stage{stage("STAGE 08", "stuck-badges")}
findings := []caddomain.StuckFinding{
finding("mathias/cobalt-dingo", 19, caddomain.CategoryDoneNotClosed, caddomain.ClassAwaitingHuman),
finding("mathias/cobalt-dingo", 16, caddomain.CategoryDoneNotClosed, caddomain.ClassAwaitingHuman),
}
out := atlas.ApplyStuckOverlay(stages, findings)
if out[0].StuckCount != 0 || out[0].AwaitingCount != 2 {
t.Fatalf("counts = stuck=%d awaiting=%d, want stuck=0 awaiting=2 — done_not_closed must never render as stuck", out[0].StuckCount, out[0].AwaitingCount)
}
for _, n := range out[0].Nodes {
if n.Cls != "awaiting-human" {
t.Errorf("node Cls = %q, want %q", n.Cls, "awaiting-human")
}
}
}
func TestApplyStuckOverlay_ExecutionCategoriesCollapseToStage05(t *testing.T) {
stages := []atlas.Stage{stage("STAGE 05", "stuck-badges")}
findings := []caddomain.StuckFinding{
finding("mathias/cobalt-dingo", 30, caddomain.CategoryCeilingHit, caddomain.ClassStuck),
finding("mathias/cad-atlas", 10, caddomain.CategoryNearAttemptCap, caddomain.ClassStuck),
finding("mathias/cobalt-dingo", 16, caddomain.CategoryReFireLoop, caddomain.ClassStuck),
finding("mathias/cobalt-dingo", 41, caddomain.CategoryClaimedNeverRan, caddomain.ClassStuck),
}
out := atlas.ApplyStuckOverlay(stages, findings)
if out[0].StuckCount != 4 {
t.Fatalf("StuckCount = %d, want 4", out[0].StuckCount)
}
}
func TestApplyStuckOverlay_NodesPrependedNotReplacingAuthoredContent(t *testing.T) {
s := stage("STAGE 04", "stuck-badges")
s.Nodes = []atlas.Node{{Title: "authored node"}}
out := atlas.ApplyStuckOverlay([]atlas.Stage{s}, []caddomain.StuckFinding{
finding("mathias/brain-gardener", 190, caddomain.CategoryArmedNeverFired, caddomain.ClassStuck),
})
if len(out[0].Nodes) != 2 {
t.Fatalf("want 2 nodes (1 live + 1 authored), got %d", len(out[0].Nodes))
}
if out[0].Nodes[len(out[0].Nodes)-1].Title != "authored node" {
t.Errorf("authored node was not preserved: %+v", out[0].Nodes)
}
}
func TestApplyStuckOverlay_DoesNotMutateInput(t *testing.T) {
stages := []atlas.Stage{stage("STAGE 04", "stuck-badges")}
_ = atlas.ApplyStuckOverlay(stages, []caddomain.StuckFinding{
finding("mathias/brain-gardener", 190, caddomain.CategoryArmedNeverFired, caddomain.ClassStuck),
})
if len(stages[0].Nodes) != 0 {
t.Fatalf("input slice was mutated: %+v", stages[0].Nodes)
}
}