Abilities phase 2: Astra round 3 fixes (2 P1, 2 P2)
- A Preview rebuilt on a finished task is held while building is off; only Publish is spared (stepHeld takes the step, not the task). - Oficina's token refresh checks apps_read inside the connector, right before the request, after the per-person lock. - The page's answer gate lets Publish and Not now through under the build hold; go_live governs them. - The build hold marks the exact attempt it refused (chat_steps. ability_held); resuming gives each one a fresh attempt through its own dispatch, Research included.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
11 files changed,
+139
−62
.rastrillo/budgets.txt+2 −2internal/equipo/chat/ability_hold.go+27 −37internal/equipo/chat/ability_hold_test.go+43 −0internal/equipo/chat/projects.go+3 −2internal/equipo/chat/runners.go+2 −2internal/equipo/chat/tasks.go+20 −17internal/equipo/chat_wiring.go+1 −0internal/equipo/migrations/0115_assistant_abilities.sql+4 −1internal/equipo/migrations/schema.sql+1 −1internal/equipo/oficina/connect.go+19 −0internal/equipo/oficina/connect_test.go+17 −0
diff --git a/.rastrillo/budgets.txt b/.rastrillo/budgets.txt| index 08b4f316..c4cf7cba 100644 |
| --- a/.rastrillo/budgets.txt |
| +++ b/.rastrillo/budgets.txt |
| @@ -14,7 +14,7 @@ perf GET /* skip Unknown private paths render 404; this fallback contains no scr |
| time internal/equipo/team 60s Plan 3 loaded CI measured 45.985s; niced serial reruns measured 18.079s and 22.031s. Keep migration, recovery, accounting and concurrency assertions; 60s leaves 30 percent headroom above loaded CI. |
| time internal/equipotest 300s Final fix package rerun measured 187.035s (review 172.4s); 300s gives 60 percent headroom for HTTP, sandbox, authority and final regression coverage. |
| -size internal/equipo 24062 - Preview grants, retry/timeline, no-access merges, kept work, check-db copy, notification actions, places page and its superseded card, GitHub owner routes, the Assistant's abilities (EQUIPO_ABILITIES, checked Oficina connect, ability copy); measured 24062 source lines. |
| +size internal/equipo 24063 - Preview grants, retry/timeline, no-access merges, kept work, check-db copy, notification actions, places page and its superseded card, GitHub owner routes, the Assistant's abilities (EQUIPO_ABILITIES, checked Oficina connect, ability copy); measured 24063 source lines. |
| size internal/wire 8283 - Protocol 31 facts, 32 unfinished work, task evidence, CI units, notification inputs, 33 Assistant files, 34 places, 35 diffs, the Assistant's abilities; measured 8283 source lines. |
| size internal/equipotest - 12683 GitHub connect value search, lifecycle and sweep-log contracts; Task 21 migration fixtures and Rastrillo asset contract; measured 0/12683 source/test lines. |
| time internal/runner/checks 90s CI worker measured 44.553s (44.6s rounded); |
| @@ -56,7 +56,7 @@ perf GET /api/v1/tasks/{id} skip Thin v1 person API: bearer-only JSON for device |
| perf GET /api/v1/assistant/snapshot skip Assistant person API: bearer-only JSON for Base's chat, not a browser screen. |
| perf GET /api/v1/assistant/messages skip Assistant person API: bearer-only JSON for Base's chat, not a browser screen. |
| perf GET /api/v1/assistant/events skip Assistant event stream (Server-Sent Events), bearer-only and long-lived; not a screen. |
| -size internal/equipo/chat 39515 13248 File facts/diffs, previews, merge authority, unfinished work, CI feedback, notification receipts, Assistant files, places and where their cards land, waiting cards, the Assistant's abilities (board fetch, switches, send gate, holds, go-live checks); measured 39515/13248. |
| +size internal/equipo/chat 39515 13291 File facts/diffs, previews, merge authority, unfinished work, CI feedback, notification receipts, Assistant files, places and where their cards land, waiting cards, the Assistant's abilities (board fetch, switches, send gate, holds, go-live checks); source capped at 39515; measured 13291 test lines. |
| perf GET /api/v1/questions/{id} skip Thin v1 person API: bearer-only JSON for devices; the browser reads questions on /tasks/{id}. |
| perf GET /api/v1/steps/{id}/log skip Thin v1 person API: bearer-only JSON for devices; the browser shows the log tail on /tasks/{id}. |
| perf GET /api/v1/connections/preference skip Connections slice 1 person API: bearer-only JSON for devices; the browser shows the preference on /conversation/connections. |
diff --git a/internal/equipo/chat/ability_hold.go b/internal/equipo/chat/ability_hold.go| index 7fc3ccbf..e8a08903 100644 |
| --- a/internal/equipo/chat/ability_hold.go |
| +++ b/internal/equipo/chat/ability_hold.go |
| @@ -1,7 +1,6 @@ |
| package chat |
| import ( |
| - "errors" |
| "fmt" |
| "slices" |
| @@ -77,23 +76,15 @@ func (t *txn) laneHeld(lane string) (bool, error) { |
| return t.abilityHeld(h) |
| } |
| -// taskHeld reports whether task is followed by a held job. A finished |
| -// task's steps (its Publish) are going live, which go_live and its own |
| -// last checks govern, not building. |
| -func (t *txn) taskHeld(task string) (bool, error) { |
| - if task == "" { |
| +// stepHeld reports whether st's start is held: its task is followed by |
| +// a held job. A Publish is going live, which go_live and its own last |
| +// checks govern, not building; every other step (a Preview rebuilt on a |
| +// finished task included) is building. |
| +func (t *txn) stepHeld(st stepRecord) (bool, error) { |
| + if st.TaskID == "" || st.Specialist == wire.SpecialistPublish { |
| return false, nil |
| } |
| - k, err := t.loadTask(task) |
| - if errors.Is(err, ErrNotFound) { |
| - return false, nil |
| - } else if err != nil { |
| - return false, err |
| - } |
| - if wire.FinalStage(k.Stage) { |
| - return false, nil |
| - } |
| - h, ok, err := t.handoffOf("", task) |
| + h, ok, err := t.handoffOf("", st.TaskID) |
| if err != nil || !ok { |
| return false, err |
| } |
| @@ -161,32 +152,15 @@ func (t *txn) resumeAbilityHold(h handoffRecord) error { |
| return err |
| } |
| for _, k := range tasks { |
| - if wire.FinalStage(k.Stage) { |
| - continue |
| - } |
| - steps, err := t.steps(k.ID) |
| - if err != nil { |
| + var refused []stepRecord |
| + if err := t.db.Where("task_id = ? AND ability_held = ?", k.ID, true).Find(&refused).Error; err != nil { |
| return err |
| } |
| - // The attempt that ended without ever being granted its start: |
| - // the one the hold refused. |
| - if len(steps) == 0 { |
| - continue |
| - } |
| - last := steps[len(steps)-1] |
| - if !wire.StepTerminal(last.State) || last.State == wire.StepDone || last.StartedAt != nil { |
| - continue |
| - } |
| - // It did no work: it failed to start, which a retry runs afresh |
| - // (a runner reports a start refused as cancelled). |
| - if last.State == wire.StepCancelled { |
| - if err := t.db.Model(&stepRecord{}).Where("id = ? AND attempt = ?", last.ID, last.Attempt).Update("state", wire.StepFailed).Error; err != nil { |
| + for i := range refused { |
| + if err := t.freshAttempt(&k, &refused[i]); err != nil { |
| return err |
| } |
| } |
| - if _, err := t.retryStep(&k, h.Person); err != nil && !errors.Is(err, ErrNotRetryable) && !errors.Is(err, ErrForbidden) { |
| - return err |
| - } |
| } |
| if h.Lane != "" { |
| if err := t.dispatchNext(h.Person, h.Lane); err != nil { |
| @@ -285,3 +259,19 @@ func (t *txn) turnHeld(turn, lane string) (bool, error) { |
| } |
| return t.abilityHeld(h) |
| } |
| + |
| +// freshAttempt runs again an attempt the build hold refused at its |
| +// start: it did no work, so its next attempt starts from where it was, |
| +// through the step's own dispatch. |
| +func (t *txn) freshAttempt(k *taskRecord, st *stepRecord) error { |
| + if !wire.StepTerminal(st.State) || st.StartedAt != nil { |
| + return nil |
| + } |
| + st.Attempt++ |
| + st.State, st.Reason, st.Terminated, st.FinishedAt, st.AbilityHeld = wire.StepQueued, "", false, nil, false |
| + st.Withdrawn, st.RefusedBy = false, "" |
| + if err := t.dispatchStep(k, st); err != nil { |
| + return err |
| + } |
| + return t.saveStep(st, k) |
| +} |
diff --git a/internal/equipo/chat/ability_hold_test.go b/internal/equipo/chat/ability_hold_test.go| new file mode 100644 |
| index 00000000..0ce41e3a |
| --- /dev/null |
| +++ b/internal/equipo/chat/ability_hold_test.go |
| @@ -0,0 +1,43 @@ |
| +package chat |
| + |
| +import ( |
| + "context" |
| + "testing" |
| + |
| + "amadan.net/oficina/equipo/internal/wire" |
| +) |
| + |
| +// With building off, a held job's steps are refused their start, a |
| +// Preview rebuilt on its finished task included; only its Publish (going |
| +// live) isn't (Astra phase 2 round 3, P1). |
| +func TestStepHeldSparesOnlyPublish(t *testing.T) { |
| + h, base := boardBase(t) |
| + refresh(t, h) |
| + for _, r := range []any{ |
| + &handoffRecord{ID: "h_p", Person: abPerson, State: handoffOpen, LedgerKey: "k-p", CreatedAt: h.now(), UpdatedAt: h.now()}, |
| + &handoffTaskRecord{HandoffID: "h_p", TaskID: "tk_done", Created: true}, |
| + } { |
| + if err := h.s.db.G.Create(r).Error; err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + base.set(func(f *fakeBoardBase) { f.board.Abilities["build"], f.board.Revision = false, 2 }) |
| + refresh(t, h) |
| + held := func(specialist string) bool { |
| + var out bool |
| + if err := h.s.tx(context.Background(), func(tx *txn) error { |
| + var err error |
| + out, err = tx.stepHeld(stepRecord{ID: "s_" + specialist, TaskID: "tk_done", Specialist: specialist}) |
| + return err |
| + }); err != nil { |
| + t.Fatal(err) |
| + } |
| + return out |
| + } |
| + if !held(wire.SpecialistPreview) { |
| + t.Error("a Preview rebuilt with building off wasn't held") |
| + } |
| + if held(wire.SpecialistPublish) { |
| + t.Error("a Publish was held for building") |
| + } |
| +} |
diff --git a/internal/equipo/chat/projects.go b/internal/equipo/chat/projects.go| index f1d71674..cfa65c6f 100644 |
| --- a/internal/equipo/chat/projects.go |
| +++ b/internal/equipo/chat/projects.go |
| @@ -716,8 +716,9 @@ func (s *Store) AnswerDevice(ctx context.Context, person, credential, id string, |
| return err |
| } |
| // A card in a held job's thread that would start or change |
| - // work can't be answered; dropping the job still can. |
| - if in.Choice != "drop" { |
| + // work can't be answered; dropping the job still can, and so |
| + // can Publish and Not now (going live, which go_live governs). |
| + if in.Choice != "drop" && in.Choice != wire.ChoicePublish && in.Choice != wire.ChoiceNotNow { |
| if held, err := t.turnHeld(c.TurnID, c.Lane); err != nil || held { |
| if held { |
| return ErrAbilityOff |
diff --git a/internal/equipo/chat/runners.go b/internal/equipo/chat/runners.go| index 21c1339f..99544bb2 100644 |
| --- a/internal/equipo/chat/runners.go |
| +++ b/internal/equipo/chat/runners.go |
| @@ -659,7 +659,7 @@ func (s *Store) Authorize(ctx context.Context, l Lease, stepID string, attempt i |
| // have building done: refused here, where the start would be |
| // recorded, so it never starts; a step already started keeps its |
| // grant and finishes (abilities §6.3). |
| - if held, err := t.taskHeld(st.TaskID); err != nil || held { |
| + if held, err := t.stepHeld(st); err != nil || held { |
| if err != nil { |
| return err |
| } |
| @@ -670,7 +670,7 @@ func (s *Store) Authorize(ctx context.Context, l Lease, stepID string, attempt i |
| return err |
| } |
| now := t.now() |
| - st.State, st.Reason, st.Terminated, st.FinishedAt = wire.StepCancelled, "cancelled", true, &now |
| + st.State, st.Reason, st.Terminated, st.FinishedAt, st.AbilityHeld = wire.StepCancelled, "cancelled", true, &now, true |
| if err := t.saveStep(&st, &k); err != nil { |
| return err |
| } |
diff --git a/internal/equipo/chat/tasks.go b/internal/equipo/chat/tasks.go| index e51bfdba..0ce460f4 100644 |
| --- a/internal/equipo/chat/tasks.go |
| +++ b/internal/equipo/chat/tasks.go |
| @@ -143,22 +143,25 @@ type stepRecord struct { |
| TaskID string `gorm:"index:chat_step_task"` |
| Idx int |
| Specialist string |
| - Person string |
| - State string |
| - Reason string |
| - Attempt int64 |
| - BaseSHA string |
| - CandidateSHA string |
| - Pushed bool |
| - Terminated bool |
| - Summary string |
| - Headline string |
| - LogTail string |
| - StartedAt *time.Time |
| - FinishedAt *time.Time |
| - Revision int64 |
| - CreatedAt time.Time |
| - UpdatedAt time.Time |
| + // AbilityHeld marks an attempt the build hold refused at its start |
| + // (resumeAbilityHold gives it a fresh attempt). |
| + AbilityHeld bool |
| + Person string |
| + State string |
| + Reason string |
| + Attempt int64 |
| + BaseSHA string |
| + CandidateSHA string |
| + Pushed bool |
| + Terminated bool |
| + Summary string |
| + Headline string |
| + LogTail string |
| + StartedAt *time.Time |
| + FinishedAt *time.Time |
| + Revision int64 |
| + CreatedAt time.Time |
| + UpdatedAt time.Time |
| // Round is the fix round; Family and Account what ran it. Checks and |
| // review judge CandidateSHA, set when they are dispatched; their |
| // results are stored here, beside that SHA. Findings is JSON. |
| @@ -796,7 +799,7 @@ func (t *txn) writeStep(s *stepRecord) error { |
| } |
| s.Revision++ |
| s.UpdatedAt = t.now() |
| - if err := t.db.Model(&stepRecord{}).Where("id = ?", s.ID).Select("base_checks", "base_checks_sha", "copy_owner", "copy_revision", "copy_result", "failure_signature", "state", "reason", "attempt", "base_sha", "candidate_sha", "pushed", "terminated", "summary", "log_tail", "started_at", "finished_at", "revision", "updated_at", "headline", "family", "account", "verdict", "review_label", "findings", "checks", "gate", "exit_code", "output", "republish", "from_attempt", "askable", "rebase", "from_base", "from_candidate", "merge_sha", "merge_into", "merge_strategy", "without_checks", "switched", "activity", "runner_id", "needs", "placement", "waiting_since", "refused_by", "withdrawn", "termination_kind", "publication", "publication_id", "apple", "checks_sandbox", "change_files", "change_facts", "decided_by", "merge_source", "merge_parents", "hosted_ci", "kind", "note", "sandbox_runner", "unsandboxed_by", "unsandboxed_at", "unsandboxed_attempt", "unsandboxed_runner", "has_preview", "preview", "boundary", "question", "request_turn", "sources_card", "sources_hash", "research_grant", "research_grant_revision", "hold", "housekeeping_attempt", "coordinator_attempt", "held_at", "publish", "model").Updates(s).Error; err != nil { |
| + if err := t.db.Model(&stepRecord{}).Where("id = ?", s.ID).Select("base_checks", "base_checks_sha", "copy_owner", "copy_revision", "copy_result", "failure_signature", "state", "reason", "attempt", "base_sha", "candidate_sha", "pushed", "terminated", "summary", "log_tail", "started_at", "finished_at", "revision", "updated_at", "headline", "family", "account", "verdict", "review_label", "findings", "checks", "gate", "exit_code", "output", "republish", "from_attempt", "askable", "rebase", "from_base", "from_candidate", "merge_sha", "merge_into", "merge_strategy", "without_checks", "switched", "activity", "runner_id", "needs", "placement", "waiting_since", "refused_by", "withdrawn", "termination_kind", "publication", "publication_id", "apple", "checks_sandbox", "change_files", "change_facts", "decided_by", "merge_source", "merge_parents", "hosted_ci", "kind", "note", "sandbox_runner", "unsandboxed_by", "unsandboxed_at", "unsandboxed_attempt", "unsandboxed_runner", "has_preview", "preview", "boundary", "question", "request_turn", "sources_card", "sources_hash", "research_grant", "research_grant_revision", "hold", "housekeeping_attempt", "coordinator_attempt", "held_at", "publish", "model", "ability_held").Updates(s).Error; err != nil { |
| return err |
| } |
| if s.Retired { |
diff --git a/internal/equipo/chat_wiring.go b/internal/equipo/chat_wiring.go| index 2bfac227..2a61bfaa 100644 |
| --- a/internal/equipo/chat_wiring.go |
| +++ b/internal/equipo/chat_wiring.go |
| @@ -91,6 +91,7 @@ func (s *Store) assistRegistry(logger *slog.Logger) *assist.Registry { |
| c := s.chat.store |
| providers := []assist.Provider{assist.NewHTTPProvider("base", c.Host, nil), c.TeamProvider()} |
| if s.oficina != nil { |
| + s.oficina.SetAllowed(c.AllowedFor(wire.AbilityAppsRead)) |
| providers = append(providers, assist.NewOficinaProvider(oficinaProvider, s.oficina, nil, c.AllowedFor(wire.AbilityAppsRead))) |
| } |
| r := assist.NewRegistry(providers...) |
diff --git a/internal/equipo/migrations/0115_assistant_abilities.sql b/internal/equipo/migrations/0115_assistant_abilities.sql| index b59712ef..475b7eaa 100644 |
| --- a/internal/equipo/migrations/0115_assistant_abilities.sql |
| +++ b/internal/equipo/migrations/0115_assistant_abilities.sql |
| @@ -5,7 +5,7 @@ |
| -- authoritative_seen: the origin has ever answered the board, never |
| -- cleared. A job held because building was off records when |
| -- (ability_held_at, §6.3), and a host the newest Base-Capabilities it |
| --- sent (capabilities). |
| +-- sent (capabilities). A refused step attempt is marked (ability_held). |
| CREATE TABLE chat_assistant_abilities ( |
| person text, origin text, revision integer, abilities text, admin numeric, ask text, source text, |
| fetch_seq integer, confirmed_at datetime, revoked_at datetime, authoritative_seen numeric, |
| @@ -13,3 +13,6 @@ CREATE TABLE chat_assistant_abilities ( |
| ); |
| ALTER TABLE chat_handoffs ADD COLUMN ability_held_at datetime; |
| ALTER TABLE chat_assistant_hosts ADD COLUMN capabilities text; |
| +-- A step attempt the build hold refused at its start: Carry on gives |
| +-- exactly these a fresh attempt. |
| +ALTER TABLE chat_steps ADD COLUMN ability_held numeric; |
diff --git a/internal/equipo/migrations/schema.sql b/internal/equipo/migrations/schema.sql| index 83612a9d..4db9931a 100644 |
| --- a/internal/equipo/migrations/schema.sql |
| +++ b/internal/equipo/migrations/schema.sql |
| @@ -610,7 +610,7 @@ CREATE TABLE chat_project_attachments (project_id text, kind text, ref text, nam |
| CREATE TABLE chat_tasks (id text PRIMARY KEY, project_id text, title text, brief text, stage text, branch text, base_sha text, creator text, turn_id text, cancel_requested numeric, revision integer, created_at datetime, updated_at datetime, watching text, moved_from text, branch_head text, merge_asked text, merged_sha text, merged_into text, merge_strategy text, merged_without_checks numeric, merged_at datetime, ready_sha text, merge_eligible text, done_at datetime, duplicate_of text, folded_into text, folded_stage text, folded_at datetime, engineering_runner text, merge_hold text, merge_verified numeric, revert_of text, revert_sha text, kind text, direction_asked text, built_as text, explored_from text, priority text, due_by datetime, priority_set_by text, priority_revision integer, publish_asked text, repair_round integer, copy_hold numeric, copy_recovery text, lane text); |
| CREATE INDEX chat_task_project ON chat_tasks(project_id); |
| CREATE INDEX chat_task_lane ON chat_tasks(lane); |
| -CREATE TABLE chat_steps (id text PRIMARY KEY, task_id text, idx integer, specialist text, person text, state text, reason text, attempt integer, base_sha text, candidate_sha text, pushed numeric, terminated numeric, summary text, log_tail text, started_at datetime, finished_at datetime, revision integer, created_at datetime, updated_at datetime, round integer, family text, account text, verdict text, review_label text, findings text, checks text, gate text, exit_code integer, output text, republish numeric, from_attempt integer, askable numeric, rebase numeric, from_base text, from_candidate text, merge_sha text, merge_into text, merge_strategy text, without_checks numeric, activity text, switched text, headline text, runner_id text, needs text, placement text, waiting_since datetime, refused_by text, withdrawn numeric, termination_kind text, publication text, publication_id text, apple numeric, checks_sandbox text, recheck_by text, change_facts text, decided_by text, merge_source text, merge_parents text, hosted_ci text, sandbox_runner text, unsandboxed_by text, unsandboxed_at datetime, unsandboxed_attempt integer, unsandboxed_runner text, has_preview numeric, preview text, kind text, note text, boundary text, question text, request_turn text, sources_card text, sources_hash text, research_grant text, research_grant_revision integer, hold text, housekeeping_attempt integer, held_at datetime, publish text, model text, copy_owner text, copy_revision integer, copy_result text, failure_signature text); |
| +CREATE TABLE chat_steps (id text PRIMARY KEY, task_id text, idx integer, specialist text, person text, state text, reason text, attempt integer, base_sha text, candidate_sha text, pushed numeric, terminated numeric, summary text, log_tail text, started_at datetime, finished_at datetime, revision integer, created_at datetime, updated_at datetime, round integer, family text, account text, verdict text, review_label text, findings text, checks text, gate text, exit_code integer, output text, republish numeric, from_attempt integer, askable numeric, rebase numeric, from_base text, from_candidate text, merge_sha text, merge_into text, merge_strategy text, without_checks numeric, activity text, switched text, headline text, runner_id text, needs text, placement text, waiting_since datetime, refused_by text, withdrawn numeric, termination_kind text, publication text, publication_id text, apple numeric, checks_sandbox text, recheck_by text, change_facts text, decided_by text, merge_source text, merge_parents text, hosted_ci text, sandbox_runner text, unsandboxed_by text, unsandboxed_at datetime, unsandboxed_attempt integer, unsandboxed_runner text, has_preview numeric, preview text, kind text, note text, boundary text, question text, request_turn text, sources_card text, sources_hash text, research_grant text, research_grant_revision integer, hold text, housekeeping_attempt integer, held_at datetime, publish text, model text, copy_owner text, copy_revision integer, copy_result text, failure_signature text, ability_held numeric); |
| CREATE INDEX chat_step_task ON chat_steps(task_id); |
| CREATE TABLE chat_task_entries (id text PRIMARY KEY, task_id text, idempotency_key text, kind text, author text, text text, repo text, path text, line integer, created_at datetime, headline text, folded_from text); |
| CREATE INDEX chat_entry_task ON chat_task_entries(task_id); |
diff --git a/internal/equipo/oficina/connect.go b/internal/equipo/oficina/connect.go| index 87972f13..8c480978 100644 |
| --- a/internal/equipo/oficina/connect.go |
| +++ b/internal/equipo/oficina/connect.go |
| @@ -127,6 +127,17 @@ type Connector struct { |
| pending map[string]pending // sha256 of the state -> who started it |
| sessions map[string]*session |
| locks map[string]*sync.Mutex |
| + // allowed, when set (SetAllowed), is asked right before a token |
| + // refresh is sent, after the person's lock is held: a person who may |
| + // not read their apps has no refresh made (abilities §6.1). |
| + allowed func(ctx context.Context, person string) error |
| +} |
| + |
| +// SetAllowed sets the check run right before every token refresh. |
| +func (c *Connector) SetAllowed(f func(ctx context.Context, person string) error) { |
| + c.mu.Lock() |
| + defer c.mu.Unlock() |
| + c.allowed = f |
| } |
| // New checks cfg and returns its connector. |
| @@ -364,6 +375,14 @@ func (c *Connector) Host(ctx context.Context, person string) (origin, token stri |
| return "", "", false, err |
| } |
| } |
| + c.mu.Lock() |
| + allowed := c.allowed |
| + c.mu.Unlock() |
| + if allowed != nil { |
| + if err := allowed(ctx, person); err != nil { |
| + return "", "", false, err |
| + } |
| + } |
| form := url.Values{} |
| form.Set("grant_type", "refresh_token") |
| form.Set("refresh_token", refresh) |
diff --git a/internal/equipo/oficina/connect_test.go b/internal/equipo/oficina/connect_test.go| index 2fcd6d04..6dd577db 100644 |
| --- a/internal/equipo/oficina/connect_test.go |
| +++ b/internal/equipo/oficina/connect_test.go |
| @@ -493,3 +493,20 @@ func TestConnectConfig(t *testing.T) { |
| t.Error(err) |
| } |
| } |
| + |
| +// With reading off for the person (checked after their lock is held, |
| +// right before the request), no token refresh is sent (abilities §6.1). |
| +func TestConnectRefreshNeedsAllowed(t *testing.T) { |
| + r := newRig(t) |
| + ctx := context.Background() |
| + r.connect(t, "ana@example.com") |
| + off := errors.New("reading off") |
| + r.c.SetAllowed(func(context.Context, string) error { return off }) |
| + r.clock.add(5 * time.Minute) |
| + if _, _, ok, err := r.c.Host(ctx, "ana@example.com"); !errors.Is(err, off) || ok { |
| + t.Fatalf("refresh with reading off: %v %v", ok, err) |
| + } |
| + if _, n := r.fake.Counts(); n != 0 { |
| + t.Errorf("%d refreshes sent", n) |
| + } |
| +} |