Abilities: go_live checked at the tap and at the last merge and publish
A hand-off's task merges or publishes only while its person may put things live. The merge gate turns an automatic merge into an ask when they can't, so the task waits at the go-ahead, and authorizeMergeLease (which decides again right before the hub request) refuses an approved one: merge_not_authorized, nothing sent. publishRefusal refuses a publish start and its deploy check ability_off. The answering person's go-ahead, Publish and MergeTask are refused 403 ability_off. A ready job says "Putting it live is turned off for you. <Owner> can turn it on." and keeps its preview. Work outside the board is unaffected.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
6 files changed,
+194
−3
internal/equipo/chat/ability_hold.go+42 −3internal/equipo/chat/jobs.go+11 −0internal/equipo/chat/merge.go+8 −0internal/equipo/chat/mergeauth.go+12 −0internal/equipo/chat/publish.go+13 −0internal/thintest/go_live_off_contract_test.go+108 −0
diff --git a/internal/equipo/chat/ability_hold.go b/internal/equipo/chat/ability_hold.go| index ccde36af..1d18458d 100644 |
| --- a/internal/equipo/chat/ability_hold.go |
| +++ b/internal/equipo/chat/ability_hold.go |
| @@ -185,11 +185,11 @@ func (t *txn) resumeAbilityHold(h handoffRecord) error { |
| return t.projectJob(h) |
| } |
| -// reprojectHeld redraws the person's held jobs' cards: building turned |
| -// on or off changes what they say. |
| +// reprojectHeld redraws the person's open jobs' cards: building or |
| +// putting live turned on or off changes what they say. |
| func (t *txn) reprojectHeld(person string) error { |
| var held []handoffRecord |
| - if err := t.db.Where("person = ? AND ability_held_at IS NOT NULL", person).Find(&held).Error; err != nil { |
| + if err := t.db.Where("person = ? AND state = ?", person, handoffOpen).Find(&held).Error; err != nil { |
| return err |
| } |
| for _, h := range held { |
| @@ -199,3 +199,42 @@ func (t *txn) reprojectHeld(person string) error { |
| } |
| return nil |
| } |
| + |
| +// goLiveForTask reports whether the person a task's hand-off is for may |
| +// put things live: true for a task no hand-off follows (work started in |
| +// Equipo's own pages is outside the board). Merge authority's automatic |
| +// merge and the last merge and publish checks read it. |
| +func (t *txn) goLiveForTask(taskID string) (bool, error) { |
| + h, ok, err := t.handoffOf("", taskID) |
| + if err != nil || !ok { |
| + return err == nil, err |
| + } |
| + sw, err := t.switches(h.Person) |
| + if err != nil { |
| + return false, err |
| + } |
| + return sw.Can(wire.AbilityGoLive), nil |
| +} |
| + |
| +// goLiveByActor reports whether actor, answering for a task, may put it |
| +// live: true for a task no hand-off follows. The taps read it. |
| +func (t *txn) goLiveByActor(actor, taskID string) (bool, error) { |
| + _, ok, err := t.handoffOf("", taskID) |
| + if err != nil || !ok { |
| + return err == nil, err |
| + } |
| + sw, err := t.switches(actor) |
| + if err != nil { |
| + return false, err |
| + } |
| + return sw.Can(wire.AbilityGoLive), nil |
| +} |
| + |
| +// requireGoLive is goLiveByActor as an error: ErrAbilityOff when off. |
| +func (t *txn) requireGoLive(actor, taskID string) error { |
| + ok, err := t.goLiveByActor(actor, taskID) |
| + if err == nil && !ok { |
| + return ErrAbilityOff |
| + } |
| + return err |
| +} |
diff --git a/internal/equipo/chat/jobs.go b/internal/equipo/chat/jobs.go| index 4a34a9a4..c491dd5f 100644 |
| --- a/internal/equipo/chat/jobs.go |
| +++ b/internal/equipo/chat/jobs.go |
| @@ -3,6 +3,7 @@ package chat |
| import ( |
| "context" |
| "encoding/json" |
| + "fmt" |
| "slices" |
| "strings" |
| "time" |
| @@ -232,6 +233,16 @@ func (t *txn) jobView(h handoffRecord) (state, result, detail, carryOn string, l |
| if state == wire.JobStopped && key != "" { |
| detail = t.copy("assistant.job.detail." + key) |
| } |
| + if state == wire.JobReady { |
| + // Ready, but its person can't put it live: says so (§6.4). |
| + sw, err := t.switches(h.Person) |
| + if err != nil { |
| + return "", "", "", "", nil, err |
| + } |
| + if !sw.Can(wire.AbilityGoLive) && sw.Ask() != "" { |
| + detail = fmt.Sprintf(t.copy("assistant.job.detail.go_live_off"), sw.Ask()) |
| + } |
| + } |
| return state, t.copy("assistant.job." + state), detail, "", links, nil |
| } |
diff --git a/internal/equipo/chat/merge.go b/internal/equipo/chat/merge.go| index 822c0327..73d64a83 100644 |
| --- a/internal/equipo/chat/merge.go |
| +++ b/internal/equipo/chat/merge.go |
| @@ -138,6 +138,11 @@ func (t *txn) answerMerge(person string, c cardRecord, in wire.AnswerCard) (wire |
| if k.Creator != person || c.Person != person { |
| return wire.Card{}, wire.Card{}, ErrForbidden |
| } |
| + if in.Choice == wire.ChoiceMerge { |
| + if err := t.requireGoLive(person, k.ID); err != nil { |
| + return wire.Card{}, wire.Card{}, err |
| + } |
| + } |
| if err := t.isOwner(person); err != nil { |
| return wire.Card{}, wire.Card{}, err |
| } |
| @@ -496,6 +501,9 @@ func (s *Store) MergeTask(ctx context.Context, person, id string) (attempt int64 |
| if wire.FinalStage(k.Stage) || k.CancelRequested { |
| return ErrTaskEnded |
| } |
| + if err := t.requireGoLive(person, k.ID); err != nil { |
| + return err |
| + } |
| steps, err := t.steps(k.ID) |
| if err != nil { |
| return err |
diff --git a/internal/equipo/chat/mergeauth.go b/internal/equipo/chat/mergeauth.go| index 7dc91c10..26ed2711 100644 |
| --- a/internal/equipo/chat/mergeauth.go |
| +++ b/internal/equipo/chat/mergeauth.go |
| @@ -268,6 +268,18 @@ func (t *txn) authorizeMerge(k *taskRecord, p progress, at, person string, proto |
| return mergegate.Decision{}, err |
| } |
| d := mergegate.Decide(in) |
| + if d.Class == mergegate.ClassAct { |
| + // A hand-off's person who can't put things live: nothing merges |
| + // on its own, and an approved merge isn't requested; the task |
| + // waits at the go-ahead (abilities §6.4). |
| + live, err := t.goLiveForTask(k.ID) |
| + if err != nil { |
| + return mergegate.Decision{}, err |
| + } |
| + if !live { |
| + d.Class, d.Stance = mergegate.ClassAsk, mergegate.StanceMerge |
| + } |
| + } |
| by := "" |
| switch { |
| case d.Class == mergegate.ClassAct && decides: |
diff --git a/internal/equipo/chat/publish.go b/internal/equipo/chat/publish.go| index eb89d85e..ccc1151e 100644 |
| --- a/internal/equipo/chat/publish.go |
| +++ b/internal/equipo/chat/publish.go |
| @@ -351,6 +351,11 @@ func (t *txn) answerPublish(person string, c cardRecord, in wire.AnswerCard) (wi |
| if err := t.isOwner(person); err != nil { |
| return wire.Card{}, wire.Card{}, err |
| } |
| + if in.Choice == wire.ChoicePublish { |
| + if err := t.requireGoLive(person, k.ID); err != nil { |
| + return wire.Card{}, wire.Card{}, err |
| + } |
| + } |
| steps, err := t.steps(k.ID) |
| if err != nil { |
| return wire.Card{}, wire.Card{}, err |
| @@ -490,6 +495,14 @@ func (t *txn) publishRefusal(l Lease, s *stepRecord, purpose, digest, destinatio |
| if primary != l.Runner.RunnerID || s.Person != k.Creator || k.CancelRequested || k.Stage != wire.StageDone || k.MergedSHA == "" || k.MergedSHA != s.CandidateSHA || k.MergedInto == "" || s.DecidedBy != decidedPerson+k.Creator || t.isOwner(k.Creator) != nil { |
| return "withdrawn", nil |
| } |
| + // The last check of a publish start and its deploy: the hand-off's |
| + // person still puts things live (abilities §6.4). |
| + if live, err := t.goLiveForTask(k.ID); err != nil || !live { |
| + if err == nil { |
| + return wire.CodeAbilityOff, nil |
| + } |
| + return "", err |
| + } |
| steps, err := t.steps(k.ID) |
| if err != nil { |
| return "", err |
diff --git a/internal/thintest/go_live_off_contract_test.go b/internal/thintest/go_live_off_contract_test.go| new file mode 100644 |
| index 00000000..dad6bca1 |
| --- /dev/null |
| +++ b/internal/thintest/go_live_off_contract_test.go |
| @@ -0,0 +1,108 @@ |
| +package thintest |
| + |
| +import ( |
| + "errors" |
| + "net/http" |
| + "strings" |
| + "testing" |
| + |
| + "amadan.net/oficina/equipo/internal/wire" |
| +) |
| + |
| +// A go-ahead answered, then putting live turned off, then the merge |
| +// request: the last check refuses it, and nothing reaches the hub. |
| +func TestGoLiveOffAfterApproval(t *testing.T) { |
| + o := newTeamRigAt(t, wire.ProtocolCurrent) |
| + _, _, merge := o.paulsWebsite(false) |
| + o.setBoard(wire.AbilityGoLive) |
| + if refused := o.lease(o.runner, "gl-merge", wire.LeaseCheck{StepID: merge.StepID, Attempt: merge.Attempt, Purpose: wire.LeasePurposeMerge}); refused != wire.RefusedMergeNotAuthorized { |
| + t.Errorf("merge request after going live went off: %q", refused) |
| + } |
| +} |
| + |
| +// A Publish answered, then putting live off: the publish start's last |
| +// check refuses it. |
| +func TestGoLiveOffPublishLastCheck(t *testing.T) { |
| + o := newTeamRigAt(t, wire.ProtocolCurrent) |
| + _, id, merge := o.paulsWebsite(false) |
| + publish := o.paulsPublish(id, merge) |
| + o.setBoard(wire.AbilityGoLive) |
| + if refused := o.lease(o.runner, "gl-pub", wire.LeaseCheck{StepID: publish.StepID, Attempt: publish.Attempt, Purpose: wire.LeasePurposePublish}); refused != wire.CodeAbilityOff { |
| + t.Errorf("publish start after going live went off: %q", refused) |
| + } |
| +} |
| + |
| +// With putting live off before the go-ahead, the ready job says so, |
| +// naming who can turn it on, and answering the go-ahead is refused 403 |
| +// ability_off. |
| +func TestGoLiveOffRefusesEveryPath(t *testing.T) { |
| + o := newTeamRigAt(t, wire.ProtocolCurrent) |
| + o.setBoard(wire.AbilityGoLive) |
| + request := o.readyWebsite() |
| + job := o.jobKnowing(request, "the ready job", func(c wire.AssistantCard) bool { return c.State == wire.JobReady }) |
| + if job.Detail != "Putting it live is turned off for you. Paul can turn it on." || len(job.Links) == 0 { |
| + t.Errorf("ready job with putting live off: %+v", job) |
| + } |
| + ahead := o.assistantCard("the go-ahead", func(c wire.AssistantCard) bool { return isMergeOutcome(c) && c.State == wire.CardOpen }) |
| + var s *ErrStatus |
| + if _, err := o.a.Answer(o.ctx, ahead.ID, wire.ChoiceMerge, ahead.Revision); !errors.As(err, &s) || s.Status != http.StatusForbidden || !strings.Contains(string(s.Body), `"ability_off"`) { |
| + t.Errorf("go-ahead with putting live off: %v", err) |
| + } |
| +} |
| + |
| +// readyWebsite is paulsWebsite up to its go-ahead, left unanswered. |
| +func (o *teamRig) readyWebsite() (request string) { |
| + legacy := false |
| + var id string |
| + o.t.Helper() |
| + t := o.t |
| + o.sitesOn(wire.ProtocolCurrent, true) |
| + o.shipsNo(o.project()) |
| + words := "Can you make me a website?" |
| + o.ask(words) |
| + var turn, lane string |
| + if legacy { |
| + request, turn = o.legacyHandoff("pw", words) |
| + lane = wire.LaneCoordinator |
| + } else { |
| + var cmd *wire.MessageCommand |
| + request, cmd = o.handoff("pw1", words, "") |
| + turn, lane = cmd.TurnID, wire.JobLane(request) |
| + } |
| + o.in(turn, func() { |
| + if res := o.call("pw-ask", wire.ToolAskPerson, map[string]any{"question": "Which website?", "options": []string{"A new one", "One I have"}}); res.Code != "asked" { |
| + t.Fatalf("ask %+v", res) |
| + } |
| + }) |
| + o.reply(turn) |
| + var card string |
| + var revision int64 |
| + o.until("the question", func() bool { |
| + return o.inst.DB.Writer().QueryRow("SELECT id, revision FROM chat_cards WHERE turn_id = ? AND kind = ? AND state = ?", turn, wire.CardQuestion, wire.CardOpen).Scan(&card, &revision) == nil |
| + }) |
| + ans, err := o.client.Answer(o.ctx, card, "A new one", revision) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if next := o.message(lane); next.TurnID != ans.Turn.ID { |
| + t.Fatalf("the answer's frame %+v", next) |
| + } |
| + o.reply(ans.Turn.ID) |
| + o.noteFor("the no-work note", noWork(request, 2)) |
| + o.reply(o.turn) |
| + u := o.message(wire.LaneAssistant) |
| + if u.Kind != wire.TurnTeamUpdate { |
| + t.Fatalf("update frame %+v", u) |
| + } |
| + o.in(u.TurnID, func() { nudged(t, o.teamNudge("pw-nudge", request, "make me a website"), request, 1) }) |
| + next := o.message(lane) |
| + o.reply(u.TurnID) |
| + base, cand := strings.Repeat("1", 40), strings.Repeat("2", 40) |
| + o.in(next.TurnID, func() { id, _ = o.websiteReady("pw", "Disability benefits website", base, cand, true) }) |
| + o.reply(next.TurnID) |
| + pv := o.previewDispatch(cand) |
| + o.built("pw-pv-built", pv, digestA) |
| + o.previewDone("pw-pv-done", pv, wire.PreviewResult{Phase: wire.PreviewDone, App: "eq-" + id, URL: "https://eq-" + id + ".docs-t1.example.ts.net/", Digest: digestA, Outcome: wire.PreviewDeployed}) |
| + _ = id |
| + return request |
| +} |