oficina / equipo Public

preview: Open live frames only an option a link offers

Final review M3 (Fable 7). The /tasks/{id}/preview?step=&option=
route checked only that the step was a done, pushed maker step of the
deployed candidate with options; the link (keptRound via the
direction's rounds) also needs a step bound to a specialist, not a
rebase, whose candidate Review approved. A crafted query could frame a
folder no link offered (same origin and deployment, so no new origin).

previewOptionPage now takes the option from the task's direction: a
live kept round (task.Direction.Rounds, built by designRounds with
keptRound, the links' own source) for that step and candidate, its
folder valid. Anything else is 404.

The tests' optionRig is now a real kept round (an exploration, the
maker step bound to a specialist, an approving Review; the preview's
expiry set past the chat store's wall clock, which the direction
reads), so the existing cases run against the link's rule.

Tests (RED first):
  go test ./internal/equipo/ -run TestPreviewOptionOnlyKeptRounds
    RED: unbound, rebase, not approved and no review each framed (200)
    GREEN: ok; -run 'TestPreview|TestOpenLive|TestHeaderRefused|
    Direction' ok
Mutation (restored): the route as it was (step's own options, no
round check) -> all four subtests FAIL. The round's Live and
candidate checks repeat the step's candidate check above them and
cannot fail on their own (noted, kept as belt and braces).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 486f33279d65280fa4fa86725649d41e7fb221e7 parent 2ba5575
2 files changed, +64 −12
  • internal/equipo/preview_option_test.go +49 −6
  • internal/equipo/preview_wrapper.go +15 −6
diff --git a/internal/equipo/preview_option_test.go b/internal/equipo/preview_option_test.go
index 6b494e2b..064bd629 100644
--- a/internal/equipo/preview_option_test.go
+++ b/internal/equipo/preview_option_test.go
@@ -46,9 +46,11 @@ func keptOptions(candidate string, pages ...string) string {
return string(raw)
}
-// optionRig is the preview-pass rig whose maker step kept three options
-// (calm, bold, writing-desk) at the deployed preview's candidate, and a
-// second task whose maker step kept the same.
+// optionRig is the preview-pass rig as an exploration whose Design
+// round (its maker step bound to a specialist) kept three options (calm,
+// bold, writing-desk) at the deployed preview's candidate, which Review
+// approved: a kept round, the one whose options open live. And a second
+// task whose maker step kept the same.
func optionRig(t *testing.T) *previewPassRig {
t.Helper()
r := newPreviewPassRig(t)
@@ -58,12 +60,25 @@ func optionRig(t *testing.T) *previewPassRig {
t.Fatal(e)
}
}
- exec("UPDATE chat_steps SET design_options=? WHERE id='eng_preview'", keptOptions(passCandidate, "calm", "bold", "writing-desk"))
+ exec("UPDATE chat_tasks SET kind='explore' WHERE id='tk_preview'")
+ // The direction reads the preview's expiry on the chat store's own
+ // clock (the wall clock), not the rig's.
+ exec("UPDATE chat_steps SET preview=json_set(preview,'$.expires_at','2999-01-01T00:00:00Z') WHERE id='preview_step'")
+ exec("UPDATE chat_steps SET design_options=?, specialist_id='sp_design' WHERE id='eng_preview'", keptOptions(passCandidate, "calm", "bold", "writing-desk"))
+ approve(t, r, "review_preview", 1, passCandidate)
exec("INSERT INTO chat_tasks(id,project_id,title,stage,creator,revision) VALUES('tk_other','p_preview','Other','in_review',?,1)", r.principal.Address)
exec("INSERT INTO chat_steps(id,task_id,idx,specialist,state,attempt,candidate_sha,pushed,terminated,revision,design_options) VALUES('eng_other','tk_other',0,'engineering','done',1,?,1,1,1,?)", passCandidate, keptOptions(passCandidate, "calm", "bold", "writing-desk"))
return r
}
+// approve adds Review's approval of candidate to tk_preview at idx.
+func approve(t *testing.T, r *previewPassRig, id string, idx int, candidate string) {
+ t.Helper()
+ if _, e := r.s.db.Writer().Exec("INSERT INTO chat_steps(id,task_id,idx,specialist,state,attempt,candidate_sha,verdict,kind,revision) VALUES(?,'tk_preview',?,'review','done',1,?,'approve','explore',1)", id, idx, candidate); e != nil {
+ t.Fatal(e)
+ }
+}
+
// browserGet is GET path on the session lane, signed in as the rig's
// person.
func browserGet(t *testing.T, r *previewPassRig, path string) *httptest.ResponseRecorder {
@@ -230,8 +245,9 @@ func TestPreviewOldLinkAfterRedeploy(t *testing.T) {
t.Fatal(e)
}
}
- exec("INSERT INTO chat_steps(id,task_id,idx,specialist,state,attempt,candidate_sha,pushed,terminated,revision,design_options) VALUES('eng_round2','tk_preview',2,'engineering','done',1,?,1,1,1,?)", passSecondCandidate, keptOptions(passSecondCandidate, "night", "field-notes", "paper"))
- exec("INSERT INTO chat_steps(id,task_id,idx,specialist,state,attempt,candidate_sha,preview,revision) SELECT 'preview_round2','tk_preview',3,'preview','done',1,?,preview,1 FROM chat_steps WHERE id='preview_step'", passSecondCandidate)
+ exec("INSERT INTO chat_steps(id,task_id,idx,specialist,state,attempt,candidate_sha,pushed,terminated,revision,design_options,specialist_id) VALUES('eng_round2','tk_preview',2,'engineering','done',1,?,1,1,1,?,'sp_design')", passSecondCandidate, keptOptions(passSecondCandidate, "night", "field-notes", "paper"))
+ approve(t, r, "review_round2", 3, passSecondCandidate)
+ exec("INSERT INTO chat_steps(id,task_id,idx,specialist,state,attempt,candidate_sha,preview,revision) SELECT 'preview_round2','tk_preview',4,'preview','done',1,?,preview,1 FROM chat_steps WHERE id='preview_step'", passSecondCandidate)
if w := browserGet(t, r, "/tasks/tk_preview/preview?step=eng_round2&option=1"); w.Code != 200 || framed(w.Body.String()) != "https://eq-preview.example.test/field-notes/" {
t.Fatalf("round 2: %d %s", w.Code, w.Body)
}
@@ -240,6 +256,33 @@ func TestPreviewOldLinkAfterRedeploy(t *testing.T) {
}
}
+// TestPreviewOptionOnlyKeptRounds (final review, M3 / Fable 7): the
+// route frames only an option an Open live link offers, by the link's
+// own rule (a kept round: a maker step bound to a specialist, not a
+// rebase, whose candidate Review approved). A crafted step=&option= for
+// a step of the deployed candidate that no link offers is 404.
+func TestPreviewOptionOnlyKeptRounds(t *testing.T) {
+ for _, c := range []struct{ name, update string }{
+ {"unbound", "UPDATE chat_steps SET specialist_id='' WHERE id='eng_preview'"},
+ {"rebase", "UPDATE chat_steps SET rebase=1 WHERE id='eng_preview'"},
+ {"not approved", "UPDATE chat_steps SET verdict='changes' WHERE id='review_preview'"},
+ {"no review", "DELETE FROM chat_steps WHERE id='review_preview'"},
+ } {
+ t.Run(c.name, func(t *testing.T) {
+ r := optionRig(t)
+ if w := browserGet(t, r, "/tasks/tk_preview/preview?step=eng_preview&option=1"); w.Code != 200 {
+ t.Fatalf("the kept round before: %d %s", w.Code, w.Body)
+ }
+ if _, e := r.s.db.Writer().Exec(c.update); e != nil {
+ t.Fatal(e)
+ }
+ if w := browserGet(t, r, "/tasks/tk_preview/preview?step=eng_preview&option=1"); w.Code != 404 || strings.Contains(w.Body.String(), "<iframe") {
+ t.Fatalf("%s: %d %s", c.name, w.Code, w.Body)
+ }
+ })
+ }
+}
+
// TestPreviewOptionNotDeployed: with no deployed preview, or one the
// host refused for its headers, an option link is 404 (never the
// unsafe confirmation).
diff --git a/internal/equipo/preview_wrapper.go b/internal/equipo/preview_wrapper.go
index dcc70c70..a1e94041 100644
--- a/internal/equipo/preview_wrapper.go
+++ b/internal/equipo/preview_wrapper.go
@@ -70,9 +70,12 @@ func parsePreviewOption(raw string) (previewOptionQuery, bool) {
// previewOptionPage is the folder an Open live query frames, under the
// deployed preview step: "" for no query. ok only when the step is one
// of the task's maker steps, done and pushed, whose candidate is the
-// one the deployed preview is of, Index is one of its kept options, and
-// that option's folder is valid. Anything else (another task's step, an
-// earlier round after a later one deployed) is not.
+// one the deployed preview is of, and an Open live link offers it: a
+// kept round of the direction (the link's own rule: a maker step bound
+// to a specialist, not a rebase, whose candidate Review approved) that
+// is live; Index is one of that round's options, and its folder is
+// valid. Anything else (another task's step, an earlier round after a
+// later one deployed, a step no link offers) is not.
func previewOptionPage(task wire.Task, preview wire.Step, q previewOptionQuery) (string, bool) {
if !q.Set {
return "", true
@@ -81,11 +84,17 @@ func previewOptionPage(task wire.Task, preview wire.Step, q previewOptionQuery)
if s.ID != q.Step {
continue
}
- if s.Specialist != wire.SpecialistEngineering || s.State != wire.StepDone || !s.Pushed || s.CandidateSHA == "" || s.CandidateSHA != preview.CandidateSHA || s.Design == nil || q.Index >= len(s.Design.Options) {
+ if s.Specialist != wire.SpecialistEngineering || s.State != wire.StepDone || !s.Pushed || s.CandidateSHA == "" || s.CandidateSHA != preview.CandidateSHA || task.Direction == nil {
return "", false
}
- page := s.Design.Options[q.Index].Page
- return page, wire.ValidPage(page)
+ for _, r := range task.Direction.Rounds {
+ if r.Step != s.ID || !r.Live || r.Candidate != s.CandidateSHA || q.Index >= len(r.Options) {
+ continue
+ }
+ page := r.Options[q.Index].Page
+ return page, wire.ValidPage(page)
+ }
+ return "", false
}
return "", false
}