test(archied): pin the wiring these fixes depend on and drop text coupling

Two fresh-context reviews of the preceding five fixes found that the tests were
mostly sound but that three things were not: one harness was coupled to shell
source text, one assertion was coupled to a tool count, and -- worse -- the two
changes carrying the most weight were pinned by nothing at all.

Composition order. review_pr worked only because Run builds the worktree manager
before the gateways; no test observed it. Reverting the order left every test
green while the daemon silently stopped offering review_pr, because the producer
guard then returns nil instead of advertising a broken tool. Pin the order by
source position, matching the existing
TestSetupBackendsRegistersContainerCleanupAfterNATS, since no runtime seam can
see it. methodBody now resolves package-level funcs as well as methods.

Composition wiring. The daemon fix's whole point is that resolved routing
bindings reach the worker, yet nothing verified that buildDaemon puts them on the
daemon: with b.kindWorkflows replaced by nil, only the new test fails and both
the daemon and worker packages stay green. That is the "tested in isolation,
never verified wired" shape this work exists to remove, so pin the hop.

The wire contract itself. taskrun.Request's json tags are the interface between
two binaries, and a same-type round trip cannot see a tag rename. Assert the
emitted keys literally; renaming one now fails with the key list.

Brittleness. selfHostConfig no longer string-matches install.sh's heredoc opener
or assumes the delimiter is EOF, and no longer hand-substitutes a copy of
forge_block's output -- it discovers heredocs by shape and selects the one
declaring [nats], a table the assertions never touch. Verified against four
behaviour-preserving refactors that previously failed: renaming the delimiter,
reordering the redirect, factoring the path into a variable, and <<-. The two
[services.gateway] source greps are gone: defaults.go already supplies that
target, so there was no behaviour to pin. review_pr is asserted present by name
rather than by entry count, so a sibling review tool cannot turn it red.

Also carry the published request's decode error instead of discarding it, so a
payload-shape break reports as itself rather than as an empty routing binding.

Every new test was verified non-vacuous by reintroducing the defect.
This commit is contained in:
sam committed 2026-09-15 02:18:30 +10:00
1 parent 669f98a059
commit 1f3f54bedd
7 files changed
+217 -61

No files matched your search

+17 -7
View File
@@ -753,11 +753,18 @@ func TestRunViaAgentSendsRoutingBindings(t *testing.T) {
t.Fatalf("claim: (%v, %v)", task, err)
}
received := make(chan taskrun.Request, 1)
// The published request is checked for its routing bindings, so a decode
// failure is carried out rather than discarded: otherwise a payload-shape
// break would surface as an empty binding and read as a routing bug.
type published struct {
req taskrun.Request
err error
}
received := make(chan published, 1)
sub, err := mustCoreConn(t, busClient).Subscribe(agentnats.SubjectForTask(task.ID), func(msg *natsio.Msg) {
var req taskrun.Request
_ = json.Unmarshal(msg.Data, &req)
received <- req
var p published
p.err = json.Unmarshal(msg.Data, &p.req)
received <- p
data, _ := json.Marshal(taskrun.Response{Status: workflow.StatusPROpen})
_ = msg.Respond(data)
})
@@ -769,11 +776,14 @@ func TestRunViaAgentSendsRoutingBindings(t *testing.T) {
d.runViaAgent(ctx, task, config.Repo{Owner: "acme", Name: "widget", Base: "main"})
select {
case req := <-received:
if got := req.KindWorkflows[workintake.KindBug]; got != "custom-bug" {
case p := <-received:
if p.err != nil {
t.Fatalf("decode published taskrun request: %v", p.err)
}
if got := p.req.KindWorkflows[workintake.KindBug]; got != "custom-bug" {
t.Errorf("request KindWorkflows[bug] = %q, want %q", got, "custom-bug")
}
if got := req.LabelWorkflows["security"]; got != "security-review" {
if got := p.req.LabelWorkflows["security"]; got != "security-review" {
t.Errorf("request LabelWorkflows[security] = %q, want %q", got, "security-review")
}
case <-time.After(time.Second):