beads/cmd/bd/mol_last_activity_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

101 lines
3.4 KiB
Go

//go:build cgo
package main
import (
"encoding/json"
"testing"
"time"
)
func TestProxiedServerMolLastActivity(t *testing.T) {
requireSharedProxiedServer(t)
t.Parallel()
bd := buildEmbeddedBD(t)
t.Run("root_only_reports_molecule_updated", func(t *testing.T) {
t.Parallel()
p := newSharedProxiedProject(t, bd, "mla")
root := bdProxiedCreate(t, bd, p.dir, "Lonely root", "--type", "epic")
out, err := bdProxiedRun(t, bd, p.dir, "mol", "last-activity", root.ID, "--json")
if err != nil {
t.Fatalf("bd mol last-activity --json: %v\n%s", err, out)
}
var got struct {
MoleculeID string `json:"molecule_id"`
Source string `json:"source"`
}
if err := json.Unmarshal(out, &got); err != nil {
t.Fatalf("unmarshal: %v\n%s", err, out)
}
if got.Source != "molecule_updated" {
t.Errorf("source = %s, want molecule_updated", got.Source)
}
})
t.Run("child_update_wins_over_root", func(t *testing.T) {
t.Parallel()
p := newSharedProxiedProject(t, bd, "mlac")
root := bdProxiedCreate(t, bd, p.dir, "Root before child", "--type", "epic")
child := bdProxiedCreate(t, bd, p.dir, "Child updated later", "--type", "task", "--parent", root.ID)
db := openProxiedDB(t, p)
now := time.Now().UTC()
if _, err := db.Exec("UPDATE issues SET updated_at = ? WHERE id = ?", now.Add(-time.Hour), root.ID); err != nil {
t.Fatalf("backdate root: %v", err)
}
if _, err := db.Exec("UPDATE issues SET updated_at = ? WHERE id = ?", now, child.ID); err != nil {
t.Fatalf("set child updated_at: %v", err)
}
out, err := bdProxiedRun(t, bd, p.dir, "mol", "last-activity", root.ID, "--json")
if err != nil {
t.Fatalf("bd mol last-activity --json: %v\n%s", err, out)
}
var got struct {
Source string `json:"source"`
SourceStepID string `json:"source_step_id"`
}
if err := json.Unmarshal(out, &got); err != nil {
t.Fatalf("unmarshal: %v\n%s", err, out)
}
if got.Source != "step_updated" || got.SourceStepID != child.ID {
t.Errorf("source/step = %s/%s, want step_updated/%s", got.Source, got.SourceStepID, child.ID)
}
})
t.Run("child_closed_after_update_wins", func(t *testing.T) {
t.Parallel()
p := newSharedProxiedProject(t, bd, "mlacc")
root := bdProxiedCreate(t, bd, p.dir, "Root for closed-child test", "--type", "epic")
child := bdProxiedCreate(t, bd, p.dir, "Child closed last", "--type", "task", "--parent", root.ID)
if out, err := bdProxiedRun(t, bd, p.dir, "close", child.ID); err != nil {
t.Fatalf("bd close: %v\n%s", err, out)
}
db := openProxiedDB(t, p)
now := time.Now().UTC()
if _, err := db.Exec("UPDATE issues SET updated_at = ? WHERE id = ?", now.Add(-time.Hour), root.ID); err != nil {
t.Fatalf("backdate root: %v", err)
}
if _, err := db.Exec("UPDATE issues SET updated_at = ?, closed_at = ? WHERE id = ?", now.Add(-30*time.Minute), now, child.ID); err != nil {
t.Fatalf("set child closed_at: %v", err)
}
out, err := bdProxiedRun(t, bd, p.dir, "mol", "last-activity", root.ID, "--json")
if err != nil {
t.Fatalf("bd mol last-activity --json: %v\n%s", err, out)
}
var got struct {
Source string `json:"source"`
SourceStepID string `json:"source_step_id"`
}
if err := json.Unmarshal(out, &got); err != nil {
t.Fatalf("unmarshal: %v\n%s", err, out)
}
if got.Source != "step_closed" || got.SourceStepID != child.ID {
t.Errorf("source/step = %s/%s, want step_closed/%s", got.Source, got.SourceStepID, child.ID)
}
})
}