feat(harness): agent-drivable dev harness and CI that gates
Build & publish Arch package / arch-package (push) Successful in 2m8s
CI / check (push) Failing after 1m56s
CI / e2e (push) Skipped
Search index maintenance / maintain-index (push) Successful in 13s

A coding agent could develop this repo's Go packages and could not
develop the application: every path to running YellowJacket ended in a
blocking GTK window, so 265 bound methods, 46 events, 33 component
directories and 13 stores had exactly one form of verification
available — `tsc --noEmit`.

The unlock is that `wails dev`'s dev server on :34115 serves the real
frontend with the real generated bindings against the same Go backend a
desktop window attaches to, so a plain Chromium under Xvfb gets a fully
functional app. Four test tiers now exist, cheapest first:

- `make ui-test` — 313 Vitest tests in a real browser in ~2 s, no app,
  no backend, no display. Works because `frontend/wailsjs/` is a pure
  passthrough to `window.go`/`window.runtime`, so faking just those two
  globals runs the real bindings and the real store code.
- `make test` — services in-process, asserting on the payload the
  frontend would receive, via a new `events.Emit` wrapper.
- `make dev-headless` + `playwright-cli` — the real app, driven
  interactively, with an event bridge on `window.__yjEvents` and a
  dev-only control surface at `/__test/`.
- `make e2e` — 19 of those flows frozen as Playwright specs.

`events.Emit(ctx, …)` replaces all 35 direct `runtime.EventsEmit` call
sites: wails' `getEvents` `log.Fatalf`s on any context without its
runtime, so those paths could not run under test and a background
worker could take the app down. Four packages had each hand-rolled the
same guard; nine more guarded on `ctx != nil`, which does not help.
`TestNoDirectRuntimeEmits` fails the build on a new one.

Fixtures are generated, not committed (`make testdata`), and seeds are
built by *running the app* — never by hand-writing config and DB rows,
which would be a second description of a valid YJ_HOME.

`.gitea/workflows/ci.yml` is the first workflow here that tests
anything; the other three only package, so `gitea_ci` reported only
packaging jobs and misled anyone asking whether a push was healthy.
Both jobs were prototyped to green in a bare ubuntu:24.04 container
before the YAML was written, which immediately caught `make lint`
linting three configurations that nothing builds: all three passes
omitted `webkit2_41`, so wails resolved webkit2gtk-4.0 — which Arch
still ships and Ubuntu 24.04 dropped.

Operational instructions live in `.pi/skills/yellowjacket-dev/`,
measured discoveries in `.planning/NOTES.md`, and architecture in
`CLAUDE.md` — split by tense, not by topic, because a topical split
gives every new fact two plausible homes. `make skill-check` fails a
commit if the skill cites a make target that does not exist.
This commit is contained in:
2026-08-10 23:20:42 -04:00
parent 65333857e2
commit 5ca6cad45a
117 changed files with 14585 additions and 262 deletions
+3 -1
View File
@@ -1,5 +1,7 @@
//go:build dev
// Package dev provides build-time flags for development mode.
package dev
var IsDev bool = true
// IsDev indicates whether this is a development build.
var IsDev = true
+242
View File
@@ -0,0 +1,242 @@
package testfixtures_test
import (
"crypto/sha256"
"encoding/hex"
"math"
"path/filepath"
"testing"
"yellowjacket/backend/metadata"
"yellowjacket/internal/testfixtures"
)
// durationToleranceMS is the slack allowed between the nominal length
// in the spec and what a decoder reports. Lossy encoders pad to a
// frame boundary, so exact equality is not achievable.
const durationToleranceMS = 250
// TestFixturesMatchManifest reads every generated fixture back with the
// application's own metadata extractor and asserts it says what the
// manifest claims.
//
// This is the check that keeps the generator honest: fixtures are
// tagged by backend/tagwriter and read by backend/metadata, so if those
// two ever disagree — a new format, a changed frame ID — it surfaces
// here rather than as a mystery in the UI.
func TestFixturesMatchManifest(t *testing.T) {
t.Parallel()
m := testfixtures.Load(t)
for _, want := range m.Tracks {
// WAV tags are write-only today; see
// TestWAVTagsAreNotReadableYet.
if want.Format == "wav" {
continue
}
t.Run(want.Path, func(t *testing.T) {
t.Parallel()
path := m.Abs(want.Path)
got, err := metadata.ExtractTags(path)
if err != nil {
t.Fatalf("extract tags: %v", err)
}
assertTag(t, "title", want, got.Title)
assertTag(t, "artist", want, got.Artist)
assertTag(t, "album", want, got.Album)
assertTag(t, "album_artist", want, got.AlbumArtist)
assertTag(t, "genre", want, got.Genre)
assertIntTag(t, "year", want, got.Year)
assertIntTag(t, "track_number", want, got.TrackNumber)
assertIntTag(t, "disc_number", want, got.DiscNumber)
assertCover(t, want, got)
})
}
}
// TestFixtureDurationsMatchManifest decodes each fixture and checks its
// length, which is what makes seek, progress and queue-advance
// assertions meaningful elsewhere.
func TestFixtureDurationsMatchManifest(t *testing.T) {
t.Parallel()
m := testfixtures.Load(t)
for _, want := range m.Tracks {
t.Run(want.Path, func(t *testing.T) {
t.Parallel()
got, err := metadata.GetTrackLengthMillis(m.Abs(want.Path))
if err != nil {
t.Fatalf("decode duration: %v", err)
}
if delta := math.Abs(float64(got - want.DurationMS)); delta > durationToleranceMS {
t.Errorf(
"duration: got %dms, want %dms (±%dms)",
got, want.DurationMS, durationToleranceMS,
)
}
})
}
}
// TestCoverDedupFixturesShareOneImage guards the premise of the
// cover-dedup case: every track in that album must carry byte-identical
// artwork, or the dedup path is not actually under test.
func TestCoverDedupFixturesShareOneImage(t *testing.T) {
t.Parallel()
m := testfixtures.Load(t)
var first string
for _, path := range m.Case(t, testfixtures.CaseCoverDedup) {
tags, err := metadata.ExtractTags(path)
if err != nil {
t.Fatalf("extract tags from %s: %v", path, err)
}
if tags.Picture == nil {
t.Fatalf("%s: no embedded cover", filepath.Base(path))
}
sum := sha256.Sum256(tags.Picture.Data)
digest := hex.EncodeToString(sum[:])
if first == "" {
first = digest
continue
}
if digest != first {
t.Errorf(
"%s: cover differs from the album's first track",
filepath.Base(path),
)
}
}
}
// TestDuplicateFixturesAreIndistinguishable guards the premise of the
// duplicates case: the pair must agree on everything the duplicate
// detector compares, across two different formats.
func TestDuplicateFixturesAreIndistinguishable(t *testing.T) {
t.Parallel()
m := testfixtures.Load(t)
paths := m.Case(t, testfixtures.CaseDuplicates)
if len(paths) < 2 {
t.Fatalf("expected at least two duplicate fixtures, got %d", len(paths))
}
ref, err := metadata.ExtractTags(paths[0])
if err != nil {
t.Fatalf("extract reference tags: %v", err)
}
for _, path := range paths[1:] {
got, err := metadata.ExtractTags(path)
if err != nil {
t.Fatalf("extract tags from %s: %v", path, err)
}
if got.Title != ref.Title || got.Artist != ref.Artist ||
got.Album != ref.Album {
t.Errorf(
"%s: (%q, %q, %q) differs from reference (%q, %q, %q)",
filepath.Base(path),
got.Title, got.Artist, got.Album,
ref.Title, ref.Artist, ref.Album,
)
}
}
}
// TestWAVTagsAreNotReadableYet pins a known gap rather than hiding it.
//
// backend/tagwriter writes WAV tags into a RIFF "id3 " chunk, but
// backend/metadata reads through dhowden/tag, which recognises MP3,
// FLAC, OGG, MP4 and DSF and has no RIFF parser at all. So every tag
// the app writes to a WAV is invisible to the app that wrote it, and
// WAV tracks always scan in as untitled.
//
// The fixtures are tagged correctly on disk, so when the reader learns
// to unwrap the RIFF chunk this test starts failing — which is the
// point. Delete it then and drop the "wav" skip in
// TestFixturesMatchManifest.
func TestWAVTagsAreNotReadableYet(t *testing.T) {
t.Parallel()
m := testfixtures.Load(t)
for _, path := range m.Case(t, testfixtures.CaseWAVTracks) {
got, err := metadata.ExtractTags(path)
if err != nil {
t.Fatalf("extract tags from %s: %v", path, err)
}
if got.Title != "" {
t.Errorf(
"%s: WAV tags are now readable (%q) — good news; "+
"see this test's comment for what to update",
filepath.Base(path), got.Title,
)
}
}
}
func assertTag(t *testing.T, field string, want testfixtures.Track, got string) {
t.Helper()
expected, _ := want.Tags[field].(string)
if got != expected {
t.Errorf("%s: got %q, want %q", field, got, expected)
}
}
func assertIntTag(t *testing.T, field string, want testfixtures.Track, got int) {
t.Helper()
// JSON numbers decode as float64.
expected, _ := want.Tags[field].(float64)
if got != int(expected) {
t.Errorf("%s: got %d, want %d", field, got, int(expected))
}
}
func assertCover(
t *testing.T,
want testfixtures.Track,
got *metadata.TrackMetadata,
) {
t.Helper()
if want.CoverSHA == "" {
if got.Picture != nil {
t.Errorf("cover: got embedded artwork, want none")
}
return
}
if got.Picture == nil {
t.Fatalf("cover: no embedded artwork, want %s", want.CoverSHA[:12])
}
sum := sha256.Sum256(got.Picture.Data)
if digest := hex.EncodeToString(sum[:]); digest != want.CoverSHA {
t.Errorf("cover: got sha %s, want %s", digest[:12], want.CoverSHA[:12])
}
}
+190
View File
@@ -0,0 +1,190 @@
// Package testfixtures gives tests typed access to the deterministic
// fixture library produced by cmd/gentestdata (`make testdata`).
//
// The library is gitignored and generated, so every accessor here
// skips the calling test when it is absent rather than failing: a
// clean clone must still be able to run `go test ./...`. Tests select
// fixtures by case name — the behaviour they exercise — so fixture
// paths can be renamed without touching test code.
package testfixtures
import (
"encoding/json"
"os"
"path/filepath"
"sync"
"testing"
)
// ManifestName is the manifest's filename, kept outside the library
// root so the scanner never sees it.
const ManifestName = "music_library_test.manifest.json"
// Case names, mirroring cmd/gentestdata's spec.
const (
CaseCoverDedup = "cover-dedup"
CaseMultiDisc = "multi-disc"
CaseVariousArtist = "various-artists"
CaseFLACAlbum = "flac-album"
CaseOGGAlbum = "ogg-album"
CaseWAVTracks = "wav-tracks"
CasePartialTags = "partial-tags"
CaseUnicode = "unicode"
CaseDuplicates = "duplicates"
CaseEdgeLengths = "edge-lengths"
CaseBroken = "broken"
)
// Track is one generated fixture, as specified rather than as encoded.
type Track struct {
Path string `json:"path"`
Case string `json:"case"`
Format string `json:"format"`
DurationMS int64 `json:"durationMs"`
FreqHz float64 `json:"freqHz"`
Cover string `json:"cover,omitempty"`
CoverSHA string `json:"coverSha,omitempty"`
Tags map[string]any `json:"tags"`
}
// Manifest describes a generated fixture library.
type Manifest struct {
Version int `json:"version"`
Generator string `json:"generator"`
Hash string `json:"hash"`
LibraryRoot string `json:"libraryRoot"`
BrokenRoot string `json:"brokenRoot"`
Cases map[string][]string `json:"cases"`
Tracks []Track `json:"tracks"`
Extras []string `json:"extras"`
Broken []string `json:"broken"`
repoRoot string
}
// Root returns the absolute path of the fixture library root.
func (m *Manifest) Root() string {
return filepath.Join(m.repoRoot, filepath.FromSlash(m.LibraryRoot))
}
// BrokenPath returns the absolute path of the malformed-file root,
// which is deliberately a sibling of the library rather than part of
// it: the clean library's track count has to stay deterministic.
func (m *Manifest) BrokenPath() string {
return filepath.Join(m.repoRoot, filepath.FromSlash(m.BrokenRoot))
}
// Abs resolves a manifest-relative track path to an absolute one.
func (m *Manifest) Abs(rel string) string {
return filepath.Join(m.Root(), filepath.FromSlash(rel))
}
// Case returns the absolute paths belonging to a case, failing the
// test when the case is unknown — a typo should not silently pass as
// an empty set.
func (m *Manifest) Case(t *testing.T, name string) []string {
t.Helper()
rels, ok := m.Cases[name]
if !ok {
t.Fatalf("testfixtures: unknown case %q", name)
}
paths := make([]string, 0, len(rels))
for _, rel := range rels {
paths = append(paths, m.Abs(rel))
}
return paths
}
// Track looks up a fixture by its manifest-relative path.
func (m *Manifest) Track(t *testing.T, rel string) Track {
t.Helper()
for _, track := range m.Tracks {
if track.Path == rel {
return track
}
}
t.Fatalf("testfixtures: no fixture at %q", rel)
return Track{}
}
//nolint:gochecknoglobals // memoised manifest load, keyed to the process.
var (
loadOnce sync.Once
loaded *Manifest
)
// Load returns the fixture manifest, skipping the test when the
// library has not been generated (`make testdata`).
func Load(t *testing.T) *Manifest {
t.Helper()
loadOnce.Do(func() {
loaded = load()
})
if loaded == nil {
t.Skip(
"testfixtures: fixture library not generated; " +
"run `make testdata`",
)
}
return loaded
}
// load reads and validates the manifest, returning nil when the
// fixtures are missing or stale.
func load() *Manifest {
repo, err := repoRoot()
if err != nil {
return nil
}
raw, err := os.ReadFile(filepath.Join(repo, "test_data", ManifestName))
if err != nil {
return nil
}
var m Manifest
if err := json.Unmarshal(raw, &m); err != nil {
return nil
}
m.repoRoot = repo
// A manifest without its library is worse than no manifest: it
// would point every test at paths that do not exist.
if _, err := os.Stat(m.Root()); err != nil {
return nil
}
return &m
}
// repoRoot walks up from the working directory to the module root, so
// fixtures resolve identically from any package's test.
func repoRoot() (string, error) {
dir, err := os.Getwd()
if err != nil {
return "", err
}
for {
if _, err := os.Stat(filepath.Join(dir, "go.mod")); err == nil {
return dir, nil
}
parent := filepath.Dir(dir)
if parent == dir {
return "", os.ErrNotExist
}
dir = parent
}
}