oficina / equipo Public

thintest: the fence contract waits for the dispatch's ack first

On hosted CI the reconnect could beat the ack of the merge's dispatch,
so the fence (correctly) dropped the unsent dispatch instead of
cancelling it and the contract waited for a cancel that never came. The
contract now waits until the instance holds the ack, so the cancel path
is the one it proves.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev 43ba14a457a4f2d52dac89205d527d97df472b69 parent c09b1f9
1 file changed, +23 −0
  • internal/thintest/mergeauth_contract_test.go +23 −0

CI passed — run details

diff --git a/internal/thintest/mergeauth_contract_test.go b/internal/thintest/mergeauth_contract_test.go
index e28b0fc8..f60ffd44 100644
--- a/internal/thintest/mergeauth_contract_test.go
+++ b/internal/thintest/mergeauth_contract_test.go
@@ -6,6 +6,7 @@ import (
"slices"
"strings"
"testing"
+ "time"
"amadan.net/oficina/equipo/internal/equipo"
"amadan.net/oficina/equipo/internal/wire"
@@ -256,6 +257,7 @@ func TestContractMergeFenceOldRunner(t *testing.T) {
r := newToolRigAt(t, wire.ProtocolMergeFacts)
id = r.judgedTask("f", "Fix the README typo", base, cand, wire.ChecksPassed, "")
m := r.dispatched(wire.SpecialistMerge, base, cand, 0)
+ r.dispatchAcked(m.StepID)
// The runner comes back at protocol 2 (an older build) before the
// request: its lease names the attempt but cannot carry the purpose.
two, err := DialRunnerHello(r.ctx, r.inst.URL, r.rig.runner, primaryAt(wire.Hello{Generation: r.runner.Welcome.Generation, Repos: []string{}, Connections: []wire.HeldConnection{}, Versions: map[string]string{"runner": "test"}}, wire.Protocol2))
@@ -311,6 +313,7 @@ func TestContractMergeFenceOldRunner(t *testing.T) {
r1 := newToolRigAt(t, wire.ProtocolMergeFacts)
id1 := r1.judgedTask("p1", "Fix the README typo", base, cand, wire.ChecksPassed, "")
m1 := r1.dispatched(wire.SpecialistMerge, base, cand, 0)
+ r1.dispatchAcked(m1.StepID)
one, err := DialRunnerHello(r1.ctx, r1.inst.URL, r1.rig.runner, wire.Hello{Generation: r1.runner.Welcome.Generation, Repos: []string{}, Connections: []wire.HeldConnection{}, Versions: map[string]string{"runner": "old"}})
if err != nil {
t.Fatal(err)
@@ -337,6 +340,26 @@ func TestContractMergeFenceOldRunner(t *testing.T) {
}
}
+// dispatchAcked waits until the instance has the runner's ack of the
+// step's dispatch, so a fence after it cancels (rather than drops) it.
+func (r *toolRig) dispatchAcked(step string) {
+ r.t.Helper()
+ deadline := time.Now().Add(20 * time.Second)
+ for {
+ var n int
+ if err := r.inst.DB.Writer().QueryRow("SELECT count(*) FROM runner_commands WHERE kind = ? AND acked_at IS NOT NULL AND body LIKE ?", wire.FrameDispatch, `%"step_id":"`+step+`"%`).Scan(&n); err != nil {
+ r.t.Fatal(err)
+ }
+ if n > 0 {
+ return
+ }
+ if time.Now().After(deadline) {
+ r.t.Fatal("the dispatch was never acked")
+ }
+ time.Sleep(20 * time.Millisecond)
+ }
+}
+
// mergeCardsWait waits for the task's merge card.
func (r *toolRig) mergeCardsWait(id string) wire.Card {
r.t.Helper()