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/repos_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

81 lines
2.7 KiB
Go

package atlas_test
import (
"testing"
"git.d-ma.be/mathias/cad-atlas/internal/atlas"
)
// A Gitea /user/repos response, trimmed to the fields RepoNodes reads.
const repoList = `[
{"name":"cad-atlas","full_name":"mathias/cad-atlas","description":"Visualising the CAD workflow","html_url":"https://git.d-ma.be/mathias/cad-atlas","archived":false,"language":"Go"},
{"name":"dispatch","full_name":"mathias/dispatch","description":"","html_url":"https://git.d-ma.be/mathias/dispatch","archived":false,"language":""},
{"name":"old-thing","full_name":"mathias/old-thing","description":"retired","html_url":"https://git.d-ma.be/mathias/old-thing","archived":true,"language":"Go"}
]`
func TestRepoNodes_OneNodePerRepoWithDescriptionAndURL(t *testing.T) {
nodes, err := atlas.RepoNodes([]byte(repoList))
if err != nil {
t.Fatalf("RepoNodes: %v", err)
}
if len(nodes) != 2 {
t.Fatalf("want 2 nodes (archived excluded), got %d", len(nodes))
}
if nodes[0].Title != "cad-atlas" {
t.Fatalf("title = %q, want %q", nodes[0].Title, "cad-atlas")
}
if nodes[0].URL != "https://git.d-ma.be/mathias/cad-atlas" {
t.Fatalf("url = %q", nodes[0].URL)
}
if nodes[0].Desc != "Visualising the CAD workflow" {
t.Fatalf("desc = %q", nodes[0].Desc)
}
}
// Mirrors IssueNodes' tagging so the two live slices read identically on stage.
func TestRepoNodes_TagsCarryLiveMarkerAndLanguage(t *testing.T) {
nodes, err := atlas.RepoNodes([]byte(repoList))
if err != nil {
t.Fatalf("RepoNodes: %v", err)
}
if len(nodes) < 2 {
t.Fatalf("want at least 2 nodes, got %d", len(nodes))
}
if len(nodes[0].Tags) != 2 || nodes[0].Tags[0] != "live · Gitea" || nodes[0].Tags[1] != "Go" {
t.Fatalf("tags = %v, want [live · Gitea Go]", nodes[0].Tags)
}
// A repo with no language must not emit an empty tag pill.
if len(nodes[1].Tags) != 1 || nodes[1].Tags[0] != "live · Gitea" {
t.Fatalf("tags = %v, want [live · Gitea]", nodes[1].Tags)
}
}
// Load-bearing: archived repos are explicitly out of scope per the issue.
func TestRepoNodes_ExcludesArchived(t *testing.T) {
nodes, err := atlas.RepoNodes([]byte(repoList))
if err != nil {
t.Fatalf("RepoNodes: %v", err)
}
for _, n := range nodes {
if n.Title == "old-thing" {
t.Fatalf("archived repo surfaced: %+v", n)
}
}
}
func TestRepoNodes_EmptyListReturnsEmptyNotNil(t *testing.T) {
nodes, err := atlas.RepoNodes([]byte(`[]`))
if err != nil {
t.Fatalf("RepoNodes: %v", err)
}
if nodes == nil || len(nodes) != 0 {
t.Fatalf("nodes = %+v, want empty non-nil slice", nodes)
}
}
func TestRepoNodes_MalformedJSONErrors(t *testing.T) {
if _, err := atlas.RepoNodes([]byte(`{`)); err == nil {
t.Fatal("want an error for malformed JSON, got nil")
}
}