beads/cmd/bd/mol_progress_proxied_integration_test.go
coffeegoddd☕️✨ 35f41fd6f7 test(mol): add proxied-server integration tests for bd mol commands
Adds 11 new test files exercising every bd mol/wisp/pour subcommand
against a real proxied-server (dolt sql-server via testcontainers),
following the existing t.Parallel() + newSharedProxiedProject pattern
from ready_wisp_proxied_integration_test.go. Covers show, current,
progress, last-activity, stale, ready --gated, distill, pour, bond,
squash, burn, and wisp create/list/gc — 47 subtests total.

Running these against a live container surfaced and fixed two real
bugs in the proxied-server mol port (cmd/bd/mol_port.go):
- uowMolReader.GetIssue/GetIssuesByIDs never hydrated Labels (the
  domain layer's IssueUseCase.GetIssue doesn't join labels the way
  storage.DoltStorage.GetIssue does), which broke every isProto/
  isProtoIssue check downstream (pour, wisp create, bond).
- uowMolWriter.AddDependency routed to the wisp_dependencies table
  whenever either end of a dependency was a wisp; it must route
  based on dep.IssueID alone (the depender), since the target column
  (depends_on_wisp_id vs depends_on_issue_id) is already resolved
  dynamically by the underlying repo insert. The old routing caused
  an FK violation whenever a persistent digest issue was linked to
  an ephemeral wisp root during squash.

Also fixes a real nil-pointer panic in wisp_proxied_server.go's
runWispPurgeClosedProxiedServer: it closed the UnitOfWork's
connection before a loop that still called IsInfraTypeCtx through it.

Testing also surfaced two pre-existing (not introduced here) bugs
shared identically by both backends, confirmed by manually running
the embedded CLI: `bd mol stale --all` can never surface childless
epics (GetEpicsEligibleForClosure skips zero-child epics before --all
is consulted), and `bd mol bond` can never produce a "compound_proto"
result via any real CLI invocation (its dispatch checks issue.IsTemplate,
which is only set on never-persisted formula-cooked subgraphs, while
bondProtoProto assumes its operands are already-persisted DB issues).
The new tests document these as parity guards rather than silently
skipping them.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-27 13:06:47 -07:00

81 lines
2.5 KiB
Go

//go:build cgo
package main
import (
"encoding/json"
"strings"
"testing"
)
func TestProxiedServerMolProgress(t *testing.T) {
requireSharedProxiedServer(t)
t.Parallel()
bd := buildEmbeddedBD(t)
t.Run("explicit_id_reports_totals", func(t *testing.T) {
t.Parallel()
p := newSharedProxiedProject(t, bd, "mpg")
root := bdProxiedCreate(t, bd, p.dir, "Progress root", "--type", "epic")
step1 := bdProxiedCreate(t, bd, p.dir, "Step 1", "--type", "task", "--parent", root.ID)
bdProxiedCreate(t, bd, p.dir, "Step 2", "--type", "task", "--parent", root.ID)
if out, err := bdProxiedRun(t, bd, p.dir, "close", step1.ID); err != nil {
t.Fatalf("bd close: %v\n%s", err, out)
}
out, err := bdProxiedRun(t, bd, p.dir, "mol", "progress", root.ID, "--json")
if err != nil {
t.Fatalf("bd mol progress --json: %v\n%s", err, out)
}
var got struct {
MoleculeID string `json:"molecule_id"`
Total int `json:"total"`
Completed int `json:"completed"`
}
if err := json.Unmarshal(out, &got); err != nil {
t.Fatalf("unmarshal: %v\n%s", err, out)
}
if got.MoleculeID != root.ID {
t.Errorf("molecule_id = %s, want %s", got.MoleculeID, root.ID)
}
if got.Total != 2 || got.Completed != 1 {
t.Errorf("total/completed = %d/%d, want 2/1", got.Total, got.Completed)
}
})
t.Run("infers_current_from_in_progress", func(t *testing.T) {
t.Parallel()
p := newSharedProxiedProject(t, bd, "mpgi")
root := bdProxiedCreate(t, bd, p.dir, "Inferred progress root", "--type", "epic")
step := bdProxiedCreate(t, bd, p.dir, "In progress step", "--type", "task", "--parent", root.ID)
if out, err := bdProxiedRun(t, bd, p.dir, "update", step.ID, "--claim"); err != nil {
t.Fatalf("bd update --claim: %v\n%s", err, out)
}
out, err := bdProxiedRun(t, bd, p.dir, "mol", "progress", "--json")
if err != nil {
t.Fatalf("bd mol progress --json: %v\n%s", err, out)
}
var got struct {
MoleculeID string `json:"molecule_id"`
}
if err := json.Unmarshal(out, &got); err != nil {
t.Fatalf("unmarshal: %v\n%s", err, out)
}
if got.MoleculeID != root.ID {
t.Errorf("molecule_id = %s, want %s", got.MoleculeID, root.ID)
}
})
t.Run("no_molecules_in_progress_empty", func(t *testing.T) {
t.Parallel()
p := newSharedProxiedProject(t, bd, "mpgn")
out, err := bdProxiedRun(t, bd, p.dir, "mol", "progress", "--json")
if err != nil {
t.Fatalf("bd mol progress --json: %v\n%s", err, out)
}
if strings.TrimSpace(string(out)) != "[]" {
t.Errorf("expected empty JSON array, got: %s", out)
}
})
}