oficina / equipo Public

web: Open live per option through the preview wrapper

Design feedback 1, Task 12 (spec 8.5). /tasks/{id}/preview?step=S&option=N
frames the deployed preview's root plus option N's folder and "/", built
with url.URL; the CSP frame-src stays the root's origin and previewWrapper
still refuses any root that is not a bare https origin. S must be one of
the task's maker steps, done and pushed, whose candidate is the deployed
preview's; N one of its kept options; the folder must match the page
pattern (wire.ValidPage). Any other query, or one on a refused or
missing preview, is 404. No query: unchanged. The native grant lane takes
the same query for its own task only.

directionView marks the round of the deployed candidate Live; the card
and task page show "Open live" (work.captures.open_live, pending) on its
options, new tab, rel="noopener noreferrer". A newest preview of the
candidate refused for preview_headers or preview_header_missing sets
PreviewRefused (no link): the card and task page say "The preview host
needs a CARLOS update before previews open." No key held that text, so
it is new: work.preview.host_outdated, pending.

TDD: CGO_ENABLED=0 go test ./internal/equipo/ -run 'TestPreviewOption|
TestPreviewWrapperPage|TestPreviewOldLink|TestOpenLiveOnlyDeployed|
TestHeaderRefusedLine' first failed: option queries framed the root (200)
for every forged case, the grant lane 404ed a valid option, no Open live
link, no host_outdated words. go test ./internal/equipo/chat/ -run
'TestDirectionLiveRound|TestDirectionPreviewRefused' failed: no round
live, PreviewRefused false with the preview URL still set. Both PASS now.

Mutations (break, run, restore), all killed unless noted:
M1 wrapper page pattern off: TestPreviewWrapperPage
M2 wrapper ignores page: TestPreviewOptionFrames, TestPreviewWrapperPage
M3 query key count: TestPreviewOptionForged, TestPreviewOptionGrantLane
M4/M5 repeated step/option: TestPreviewOptionForged
M6 negative index: TestPreviewOptionForged (panic)
M7 canonical index ("01", "+1"): TestPreviewOptionForged
M8 step id shape: SURVIVED (equivalent: an id no step has is 404 anyway)
M9 maker specialist: SURVIVED (equivalent: only maker steps carry Design)
M10 step done / M11 pushed: TestPreviewOptionStepNotKept
M12 candidate is the deployed one: TestPreviewOldLinkAfterRedeploy
M13 index in range: TestPreviewOptionForged (panic)
M14 folder valid on the route: TestPreviewOptionForged
M15 browser lane junk query: TestPreviewOptionForged
M16 browser lane option check: TestPreviewOptionForged, OldLink
M17 refused branch takes option: TestPreviewOptionNotDeployed
M18 grant lane query shape: TestPreviewOptionGrantLane, TestReviewPathTricks
M19 grant lane option check / M20 frames root: TestPreviewOptionGrantLane
M33 browser lane frames root: TestPreviewOptionFrames
M21 Live on any round / M22 folderless option: TestOpenLiveOnlyDeployed
M23 target/rel dropped: TestOpenLiveOnlyDeployed
M24 card line / M25 task page line: TestHeaderRefusedLine
M26 every round live / M27 markLive not called: TestDirectionLiveRound
M28 candidate filter, M29 terminal, M30/M31 reasons, M32 link kept:
TestDirectionPreviewRefused
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 5490715dd7e42ba3be8c1f6603cc13808cbcbfd2 parent 3f81f09
17 files changed, +594 −14
  • docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md +2 −0
  • internal/equipo/chat/direction_live.go +30 −0
  • internal/equipo/chat/direction_live_test.go +106 −0
  • internal/equipo/chat/explore.go +8 −1
  • internal/equipo/chat_page.go +6 −0
  • internal/equipo/copy.go +6 −0
  • internal/equipo/design_views.go +5 −0
  • internal/equipo/preview_option_test.go +322 −0
  • internal/equipo/preview_pass_http.go +11 −2
  • internal/equipo/preview_pass_store.go +1 −1
  • internal/equipo/preview_wrapper.go +84 −5
  • internal/equipo/preview_wrapper_browser_test.go +1 −1
  • internal/equipo/preview_wrapper_test.go +2 −2
  • internal/equipo/templates/chat.html +1 −1
  • internal/equipo/templates/work_parts.html +1 −1
  • internal/equipo/work_views.go +4 −0
  • internal/wire/design.go +4 −0
diff --git a/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md b/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md
index ae7fdeac..335bb6b7 100644
--- a/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md
+++ b/docs/superpowers/plans/CONTROLLER-REPORT-plan-3.md
@@ -7251,6 +7251,8 @@ records remain unchanged.
| `work.explore.choice_like` | Asked for more like Design's option %s. Design's direction for it: %s | Copy specialist | COPY REVIEW PENDING |
| `work.explore.choice_build_name` | Chose to build Design's option %s. | Copy specialist | COPY REVIEW PENDING |
| `work.explore.choice_like_name` | Asked for more like Design's option %s. | Copy specialist | COPY REVIEW PENDING |
+| `work.captures.open_live` | Open live | Copy specialist | COPY REVIEW PENDING |
+| `work.preview.host_outdated` | The preview host needs a CARLOS update before previews open. | Copy specialist | COPY REVIEW PENDING |
## Task 21
diff --git a/internal/equipo/chat/direction_live.go b/internal/equipo/chat/direction_live.go
new file mode 100644
index 00000000..76e75dba
--- /dev/null
+++ b/internal/equipo/chat/direction_live.go
@@ -0,0 +1,30 @@
+package chat
+
+import "amadan.net/oficina/equipo/internal/wire"
+
+// Design feedback 1, Task 12 (dynamic specialists spec, section 8.5):
+// the live mockups are the candidate's deployed preview. The round whose
+// candidate it is opens each option live; a preview the host refused
+// for its headers says so instead of nothing.
+
+// previewRefused: the newest preview step of the candidate ended refused
+// for its headers (preview_headers or preview_header_missing): the host
+// needs a CARLOS update before previews open.
+func previewRefused(steps []stepRecord, candidate string) bool {
+ for i := len(steps) - 1; i >= 0; i-- {
+ s := steps[i]
+ if s.Specialist != wire.SpecialistPreview || s.CandidateSHA != candidate {
+ continue
+ }
+ return wire.StepTerminal(s.State) && (s.Reason == "preview_headers" || s.Reason == "preview_header_missing")
+ }
+ return false
+}
+
+// markLive marks the kept round of candidate, whose preview is
+// deployed, live (directionView calls it only then).
+func markLive(d *wire.TaskDirection, candidate string) {
+ for i := range d.Rounds {
+ d.Rounds[i].Live = d.Rounds[i].Candidate == candidate
+ }
+}
diff --git a/internal/equipo/chat/direction_live_test.go b/internal/equipo/chat/direction_live_test.go
new file mode 100644
index 00000000..6a184ff0
--- /dev/null
+++ b/internal/equipo/chat/direction_live_test.go
@@ -0,0 +1,106 @@
+package chat
+
+import (
+ "encoding/json"
+ "testing"
+ "time"
+
+ "amadan.net/oficina/equipo/internal/wire"
+)
+
+// Design feedback 1, Task 12 (spec 8.5): the direction says which kept
+// round is the deployed preview's (each of its options opens live), and
+// whether the host refused the candidate's preview for its headers.
+
+// previewOf records a preview step of task on sha, newest, ended in
+// state with reason and outcome.
+func (r *hkRig) previewOf(task, sha, state, reason, outcome string) {
+ r.t.Helper()
+ var last stepRecord
+ r.must(r.s.db.G.Where("task_id = ?", task).Order("idx DESC").First(&last).Error)
+ expires := time.Now().Add(time.Hour)
+ raw, _ := json.Marshal(wire.PreviewResult{Phase: wire.PreviewDone, Outcome: outcome, URL: "https://eq-" + task + ".dev.example/", App: "eq-" + task, Digest: digestA, ExpiresAt: &expires})
+ s := stepRecord{ID: newID("s_"), TaskID: task, Idx: last.Idx + 1, Specialist: wire.SpecialistPreview, State: state, Reason: reason, Attempt: 1, CandidateSHA: sha, Terminated: true, Preview: string(raw), Revision: 1}
+ r.must(r.s.db.G.Create(&s).Error)
+}
+
+// liveRounds is which of the direction's rounds are live, by step.
+func liveRounds(d *wire.TaskDirection) map[string]bool {
+ out := map[string]bool{}
+ for _, round := range d.Rounds {
+ if round.Live {
+ out[round.Step] = true
+ }
+ }
+ return out
+}
+
+// TestDirectionLiveRound: only the round whose candidate is the deployed
+// preview's is live; none before a preview deploys, and round 1 is no
+// longer live once round 2's candidate is deployed.
+func TestDirectionLiveRound(t *testing.T) {
+ r, l, task, first, c := roundOfThree(t)
+ v, err := r.s.Task(r.ctx, paul, task)
+ r.must(err)
+ if live := liveRounds(v.Direction); len(live) != 0 || v.Direction.PreviewRefused {
+ t.Fatalf("live with no preview: %v %+v", live, v.Direction)
+ }
+ r.previewOf(task, candidateSHA, wire.StepDone, "", wire.PreviewDeployed)
+ v, err = r.s.Task(r.ctx, paul, task)
+ r.must(err)
+ if live := liveRounds(v.Direction); len(live) != 1 || !live[first.ID] || v.Direction.PreviewURL == "" {
+ t.Fatalf("round 1 deployed: %v %+v", live, v.Direction)
+ }
+ r.must(r.answerCard(c, wire.AnswerCard{Choice: wire.ChoiceMore}))
+ second := r.startRound(l, task, secondSHA)
+ r.keptRound(l, task, second, secondSHA, wire.VerdictApprove, "Night shift", "Field notes", "Paper")
+ v, err = r.s.Task(r.ctx, paul, task)
+ r.must(err)
+ if live := liveRounds(v.Direction); len(v.Direction.Rounds) != 2 || len(live) != 0 {
+ t.Fatalf("round 1's preview is not round 2's: %v %+v", live, v.Direction)
+ }
+ r.previewOf(task, secondSHA, wire.StepDone, "", wire.PreviewDeployed)
+ v, err = r.s.Task(r.ctx, paul, task)
+ r.must(err)
+ if live := liveRounds(v.Direction); len(live) != 1 || !live[second.ID] {
+ t.Fatalf("round 2 deployed: %v %+v", live, v.Direction)
+ }
+}
+
+// TestDirectionPreviewRefused: the newest preview of the candidate ended
+// refused for its headers (either reason): PreviewRefused, and no
+// preview link or live round. A refusal of an earlier candidate, or one
+// still running, is not.
+func TestDirectionPreviewRefused(t *testing.T) {
+ for _, reason := range []string{"preview_headers", "preview_header_missing"} {
+ t.Run(reason, func(t *testing.T) {
+ r, _, task, _, _ := roundOfThree(t)
+ r.previewOf(task, candidateSHA, wire.StepDone, "", wire.PreviewDeployed)
+ r.previewOf(task, candidateSHA, wire.StepDone, reason, wire.PreviewUnconfirmed)
+ v, err := r.s.Task(r.ctx, paul, task)
+ r.must(err)
+ if d := v.Direction; !d.PreviewRefused || d.PreviewURL != "" || len(liveRounds(d)) != 0 {
+ t.Fatalf("refused: %+v", d)
+ }
+ })
+ }
+ r, _, task, _, _ := roundOfThree(t)
+ r.previewOf(task, candidateSHA, wire.StepRunning, "preview_headers", wire.PreviewUnconfirmed)
+ v, err := r.s.Task(r.ctx, paul, task)
+ r.must(err)
+ if v.Direction.PreviewRefused {
+ t.Fatalf("a running refusal: %+v", v.Direction)
+ }
+ r.previewOf(task, secondSHA, wire.StepDone, "preview_headers", wire.PreviewUnconfirmed)
+ v, err = r.s.Task(r.ctx, paul, task)
+ r.must(err)
+ if v.Direction.PreviewRefused {
+ t.Fatalf("another candidate's refusal: %+v", v.Direction)
+ }
+ r.previewOf(task, candidateSHA, wire.StepFailed, "preview_scanner", wire.PreviewUnconfirmed)
+ v, err = r.s.Task(r.ctx, paul, task)
+ r.must(err)
+ if v.Direction.PreviewRefused {
+ t.Fatalf("another reason: %+v", v.Direction)
+ }
+}
diff --git a/internal/equipo/chat/explore.go b/internal/equipo/chat/explore.go
index e1559400..220c25be 100644
--- a/internal/equipo/chat/explore.go
+++ b/internal/equipo/chat/explore.go
@@ -581,7 +581,9 @@ func (s *Store) ExploreOnce(ctx context.Context, id string) (switched bool, err
// directionView is what the direction card and the task page show: the
// candidate's deployed preview, else its branch on Amadan, and whether
// the primary (at protocol 10) says previews are off; and what the newest
-// Design attempt kept, by option, with whether Build this needs a note.
+// Design attempt kept, by option, with whether Build this needs a note;
+// the round of the deployed preview's candidate is Live, and a preview
+// the host refused for its headers is PreviewRefused, with no link.
func (t *txn) directionView(k taskRecord, repo string, steps []stepRecord, p progress) (*wire.TaskDirection, error) {
d := &wire.TaskDirection{BranchURL: BranchURL(repo, k.Branch)}
design, err := t.candidateDesign(p)
@@ -594,6 +596,10 @@ func (t *txn) directionView(k taskRecord, repo string, steps []stepRecord, p pro
if d.Rounds, err = t.designRounds(k, steps); err != nil {
return nil, err
}
+ if d.PreviewRefused = previewRefused(steps, p.candidate); d.PreviewRefused {
+ // The host refused the newest preview for its headers: no link.
+ return d, nil
+ }
now := t.now()
for i := len(steps) - 1; i >= 0; i-- {
s := steps[i]
@@ -602,6 +608,7 @@ func (t *txn) directionView(k taskRecord, repo string, steps []stepRecord, p pro
}
if r := decodePreview(s.Preview); r != nil && r.Outcome == wire.PreviewDeployed && r.URL != "" && (r.ExpiresAt == nil || r.ExpiresAt.After(now)) {
d.PreviewURL = r.URL
+ markLive(d, p.candidate)
return d, nil
}
}
diff --git a/internal/equipo/chat_page.go b/internal/equipo/chat_page.go
index 98f54881..12b3f4d2 100644
--- a/internal/equipo/chat_page.go
+++ b/internal/equipo/chat_page.go
@@ -123,6 +123,9 @@ type chatCard struct {
Gallery *designGallery
DirectionAnswers []string
BuildNote bool
+ // HostOutdated is an open direction card's line when the host refused
+ // the candidate's preview for its headers (spec 8.5); "" otherwise.
+ HostOutdated string
}
// placeChoice is one button of a place card.
@@ -267,6 +270,9 @@ func cardView(c wire.Card, choices []string, tasks map[string]wire.Task) chatCar
v.Gallery.Answer.Like = slices.Contains(c.Options, wire.ChoiceLike)
}
v.BuildNote = t.Direction.NoteNeeded
+ if t.Direction.PreviewRefused {
+ v.HostOutdated = copyText("work.preview.host_outdated")
+ }
}
for _, o := range []string{wire.ChoiceBuild, wire.ChoiceMore, wire.ChoiceAgain, wire.ChoiceDrop} {
if slices.Contains(c.Options, o) && (o != wire.ChoiceBuild || !v.Gallery.perOption()) {
diff --git a/internal/equipo/copy.go b/internal/equipo/copy.go
index 0ab88ece..8bf86037 100644
--- a/internal/equipo/copy.go
+++ b/internal/equipo/copy.go
@@ -2085,6 +2085,12 @@ var pageCopy = map[string]string{
"chat.card.like": "More like this", // COPY REVIEW PENDING
"chat.card.option_note": "Add a note (optional)", // COPY REVIEW PENDING
+ // Design feedback 1, task 12: each option of the deployed round opens
+ // live through the preview wrapper; a preview the host refused for
+ // its headers says why there is none (places spec, section 4).
+ "work.captures.open_live": "Open live", // COPY REVIEW PENDING
+ "work.preview.host_outdated": "The preview host needs a CARLOS update before previews open.", // COPY REVIEW PENDING
+
// COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context): preferences.title
"preferences.title": "Preferences",
// COPY ACCEPTED FOR NOW (Paul, 2026-11-04; iterate in context): preferences.confirmed
diff --git a/internal/equipo/design_views.go b/internal/equipo/design_views.go
index 2495b656..e55d29d7 100644
--- a/internal/equipo/design_views.go
+++ b/internal/equipo/design_views.go
@@ -72,6 +72,11 @@ func galleryOf(taskID string, rounds []wire.DirectionRound, open bool, cardID st
rv := designRoundView{Step: r.Step}
for i, o := range r.Options {
ov := designOptionView{Label: fmt.Sprintf(copyText("work.captures.option"), i+1, o.Name), Direction: o.Direction, Step: r.Step, Index: i}
+ if r.Live && r.Step != "" && wire.ValidPage(o.Page) {
+ // Its round is the deployed preview's: the option opens
+ // live through the wrapper (spec 8.5).
+ ov.Live = previewOptionLink(taskID, r.Step, i)
+ }
for _, c := range o.Captures {
caption := captionOf(c)
ov.Captures = append(ov.Captures, designCaptureView{
diff --git a/internal/equipo/preview_option_test.go b/internal/equipo/preview_option_test.go
new file mode 100644
index 00000000..6381d612
--- /dev/null
+++ b/internal/equipo/preview_option_test.go
@@ -0,0 +1,322 @@
+package equipo
+
+import (
+ "encoding/json"
+ "net/http"
+ "net/http/httptest"
+ "strings"
+ "testing"
+
+ "amadan.net/oficina/equipo/internal/equipo/identity"
+ "amadan.net/oficina/equipo/internal/wire"
+ "amadan.net/rastrillo/rastrillo/auth"
+ "github.com/go-chi/chi/v5"
+)
+
+// Design feedback 1, Task 12 (spec 2026-11-28-dynamic-specialists.md,
+// section 8.5): each option of the round whose candidate is the deployed
+// preview opens live through the preview wrapper, at
+// /tasks/{id}/preview?step=S&option=N, which frames the deployed root
+// plus the option's folder. S must be the maker step whose candidate the
+// deployed preview is of and N one of its kept options with a valid
+// folder; anything else is 404. A preview the host refused for its
+// headers says so on the direction card and the task page.
+
+const passSecondCandidate = "2222222222222222222222222222222222222222"
+
+// keptOptions is a maker step's design_options: three options kept by
+// attempt 1 at candidate, with their folders.
+func keptOptions(candidate string, pages ...string) string {
+ type option struct {
+ Name string `json:"name"`
+ Page string `json:"page,omitempty"`
+ Captures []string `json:"captures"`
+ }
+ kept := struct {
+ Attempt int64 `json:"attempt"`
+ Candidate string `json:"candidate"`
+ Explore bool `json:"explore"`
+ Options []option `json:"options"`
+ }{Attempt: 1, Candidate: candidate, Explore: true}
+ for _, p := range pages {
+ kept.Options = append(kept.Options, option{Name: p, Page: p, Captures: []string{}})
+ }
+ raw, _ := json.Marshal(kept)
+ 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.
+func optionRig(t *testing.T) *previewPassRig {
+ t.Helper()
+ r := newPreviewPassRig(t)
+ exec := func(q string, args ...any) {
+ t.Helper()
+ if _, e := r.s.db.Writer().Exec(q, args...); e != nil {
+ t.Fatal(e)
+ }
+ }
+ exec("UPDATE chat_steps SET design_options=? WHERE id='eng_preview'", keptOptions(passCandidate, "calm", "bold", "writing-desk"))
+ 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
+}
+
+// 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 {
+ t.Helper()
+ app := &application{store: r.s, origin: r.s.personOrigin}
+ route := chi.NewRouter()
+ route.Get("/tasks/{id}/preview", app.previewGrantOrBrowser(http.HandlerFunc(app.previewPage)).ServeHTTP)
+ req := httptest.NewRequest("GET", "https://equipo.example"+path, nil)
+ req = identity.With(req, auth.Identity{Address: r.principal.Address, At: r.clock.Now()})
+ w := httptest.NewRecorder()
+ route.ServeHTTP(w, req)
+ return w
+}
+
+// framed is the iframe's src in a wrapper page ("" for none).
+func framed(page string) string {
+ _, after, ok := strings.Cut(page, `<iframe `)
+ if !ok {
+ return ""
+ }
+ _, after, ok = strings.Cut(after, ` src="`)
+ if !ok {
+ return ""
+ }
+ src, _, _ := strings.Cut(after, `"`)
+ return src
+}
+
+// TestPreviewOptionFrames: option 2 frames the deployed root plus its
+// folder; the policy's frame origin is the root's, unchanged; with no
+// query the wrapper frames the root as before.
+func TestPreviewOptionFrames(t *testing.T) {
+ r := optionRig(t)
+ root := browserGet(t, r, "/tasks/tk_preview/preview")
+ if root.Code != 200 || framed(root.Body.String()) != "https://eq-preview.example.test/" {
+ t.Fatalf("root: %d %s", root.Code, root.Body)
+ }
+ w := browserGet(t, r, "/tasks/tk_preview/preview?step=eng_preview&option=2")
+ if w.Code != 200 || framed(w.Body.String()) != "https://eq-preview.example.test/writing-desk/" {
+ t.Fatalf("option 2: %d %s", w.Code, w.Body)
+ }
+ if got, want := w.Header().Get("Content-Security-Policy"), root.Header().Get("Content-Security-Policy"); got != want || !strings.Contains(got, "frame-src https://eq-preview.example.test;") {
+ t.Fatalf("policy %q, root's %q", got, want)
+ }
+ if w := browserGet(t, r, "/tasks/tk_preview/preview?option=0&step=eng_preview"); w.Code != 200 || framed(w.Body.String()) != "https://eq-preview.example.test/calm/" {
+ t.Fatalf("option 0: %d %s", w.Code, w.Body)
+ }
+}
+
+// TestPreviewWrapperPage: the wrapper frames only a valid folder under
+// the root, built from the root's origin.
+func TestPreviewWrapperPage(t *testing.T) {
+ policy, page, err := previewWrapper("https://eq-tk1.dev.example/", false, "writing-desk")
+ if err != nil || framed(page) != "https://eq-tk1.dev.example/writing-desk/" || !strings.Contains(policy, "frame-src https://eq-tk1.dev.example;") {
+ t.Fatalf("%v %q %s", err, policy, page)
+ }
+ for _, bad := range []string{"../x", "x/y", "Writing", "a--b", "-a", "a b", "a?b", "a#b", "%2e%2e", strings.Repeat("a", 61), "javascript:x", "//evil.test"} {
+ if _, _, err := previewWrapper("https://eq-tk1.dev.example/", false, bad); err == nil {
+ t.Errorf("page %q accepted", bad)
+ }
+ }
+}
+
+// TestPreviewOptionForged: a negative, past-the-end or malformed index,
+// a step of another task, a missing step and any other query are 404,
+// with nothing framed.
+func TestPreviewOptionForged(t *testing.T) {
+ r := optionRig(t)
+ for _, q := range []string{
+ "step=eng_preview&option=-1",
+ "step=eng_preview&option=3",
+ "step=eng_preview&option=9",
+ "step=eng_preview&option=abc",
+ "step=eng_preview&option=01",
+ "step=eng_preview&option=+1",
+ "step=eng_preview&option=",
+ "step=eng_preview",
+ "option=1",
+ "step=eng_other&option=1",
+ "step=preview_step&option=0",
+ "step=nope&option=1",
+ "step=&option=1",
+ "step=eng_preview&option=1&option=2",
+ "step=eng_preview&step=eng_preview&option=1",
+ "step=eng_preview&option=1&x=1",
+ "step=eng_preview;option=1",
+ "x=1",
+ } {
+ w := browserGet(t, r, "/tasks/tk_preview/preview?"+q)
+ if w.Code != 404 || strings.Contains(w.Body.String(), "<iframe") || strings.Contains(w.Body.String(), "eq-preview.example.test") {
+ t.Errorf("%s: %d %s", q, w.Code, w.Body)
+ }
+ }
+ // A folder that fails the pattern, though kept, never frames.
+ if _, e := r.s.db.Writer().Exec("UPDATE chat_steps SET design_options=? WHERE id='eng_preview'", keptOptions(passCandidate, "calm", "Bad..", "")); e != nil {
+ t.Fatal(e)
+ }
+ for _, q := range []string{"step=eng_preview&option=1", "step=eng_preview&option=2"} {
+ if w := browserGet(t, r, "/tasks/tk_preview/preview?"+q); w.Code != 404 || strings.Contains(w.Body.String(), "<iframe") {
+ t.Errorf("bad folder %s: %d %s", q, w.Code, w.Body)
+ }
+ }
+}
+
+// TestPreviewOptionStepNotKept: a maker step of the same candidate that
+// is not done and pushed opens nothing live, while the preview itself
+// still opens.
+func TestPreviewOptionStepNotKept(t *testing.T) {
+ for _, state := range []struct{ name, state, pushed string }{{"unpushed", "done", "0"}, {"failed", "failed", "1"}} {
+ t.Run(state.name, func(t *testing.T) {
+ r := optionRig(t)
+ if _, e := r.s.db.Writer().Exec("INSERT INTO chat_steps(id,task_id,idx,specialist,state,attempt,candidate_sha,pushed,terminated,revision,design_options) VALUES('eng_odd','tk_preview',0,'engineering',?,1,?,?,1,1,?)", state.state, passCandidate, state.pushed, keptOptions(passCandidate, "calm", "bold", "writing-desk")); e != nil {
+ t.Fatal(e)
+ }
+ if w := browserGet(t, r, "/tasks/tk_preview/preview"); w.Code != 200 {
+ t.Fatalf("root: %d %s", w.Code, w.Body)
+ }
+ if w := browserGet(t, r, "/tasks/tk_preview/preview?step=eng_odd&option=1"); w.Code != 404 || strings.Contains(w.Body.String(), "<iframe") {
+ t.Fatalf("%s: %d %s", state.name, w.Code, w.Body)
+ }
+ })
+ }
+}
+
+// TestPreviewOldLinkAfterRedeploy: once round 2's candidate is the
+// deployed preview, round 1's link is 404 and round 2's frames.
+func TestPreviewOldLinkAfterRedeploy(t *testing.T) {
+ r := optionRig(t)
+ old := "/tasks/tk_preview/preview?step=eng_preview&option=1"
+ if w := browserGet(t, r, old); w.Code != 200 {
+ t.Fatalf("round 1 before: %d %s", w.Code, w.Body)
+ }
+ exec := func(q string, args ...any) {
+ t.Helper()
+ if _, e := r.s.db.Writer().Exec(q, args...); e != nil {
+ 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)
+ 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)
+ }
+ if w := browserGet(t, r, old); w.Code != 404 || strings.Contains(w.Body.String(), "<iframe") {
+ t.Fatalf("round 1 after redeploy: %d %s", 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).
+func TestPreviewOptionNotDeployed(t *testing.T) {
+ r := optionRig(t)
+ if _, e := r.s.db.Writer().Exec("UPDATE chat_steps SET preview=json_set(preview,'$.outcome','failed'),reason='preview_headers' WHERE id='preview_step'"); 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(), "<form") {
+ t.Fatalf("refused: %d %s", w.Code, w.Body)
+ }
+}
+
+// TestPreviewOptionGrantLane: the native preview grant opens an option
+// of its own task, and refuses another task and any other query.
+func TestPreviewOptionGrantLane(t *testing.T) {
+ r := optionRig(t)
+ h := previewPassRouter(t, r)
+ _, cookie := reviewFlow(t, r, h)
+ w := reviewGet(h, "GET", "/tasks/tk_preview/preview?step=eng_preview&option=2", cookie)
+ if w.Code != 200 || framed(w.Body.String()) != "https://eq-preview.example.test/writing-desk/" || !strings.Contains(w.Header().Get("Content-Security-Policy"), "frame-src https://eq-preview.example.test;") {
+ t.Fatalf("grant option: %d %s", w.Code, w.Body)
+ }
+ if w := reviewGet(h, "GET", "/tasks/tk_preview/preview", cookie); w.Code != 200 || framed(w.Body.String()) != "https://eq-preview.example.test/" {
+ t.Fatalf("grant root: %d %s", w.Code, w.Body)
+ }
+ for _, path := range []string{
+ "/tasks/tk_other/preview?step=eng_other&option=2",
+ "/tasks/tk_other/preview?step=eng_preview&option=2",
+ "/tasks/tk_preview/preview?step=eng_other&option=2",
+ "/tasks/tk_preview/preview?step=eng_preview&option=3",
+ "/tasks/tk_preview/preview?step=eng_preview&option=-1",
+ "/tasks/tk_preview/preview?step=eng_preview&option=2&x=1",
+ "/tasks/tk_preview/preview?x=1",
+ } {
+ w := reviewGet(h, "GET", path, cookie)
+ if (w.Code >= 200 && w.Code < 300) || strings.Contains(w.Body.String(), "<iframe") {
+ t.Errorf("grant escaped: %s -> %d", path, w.Code)
+ }
+ }
+ if w := reviewGet(h, "POST", "/tasks/tk_preview/preview?step=eng_preview&option=2", cookie); w.Code >= 200 && w.Code < 300 {
+ t.Fatalf("grant POST: %d", w.Code)
+ }
+}
+
+// liveRound is a direction whose newest round (step st2) is the deployed
+// preview's, with options at folders calm and writing-desk and one from
+// before folders; the earlier round st1 is not.
+func liveRound() directionCase {
+ opts := []wire.StepDesignOption{{Name: "Calm", Page: "calm", Captures: designOptions()[0].Captures}, {Name: "Writing desk", Page: "writing-desk"}, {Name: "Old"}}
+ return feedbackTask([]wire.DirectionRound{{Step: "st2", Candidate: strings.Repeat("2", 40), Options: opts, Live: true}, {Step: "st1", Candidate: strings.Repeat("1", 40), Options: opts}})
+}
+
+// TestOpenLiveOnlyDeployed: Open live shows on each option of the
+// deployed round that has a folder, opening the wrapper in a new tab;
+// never on another round, an option without a folder, or when no round
+// is deployed.
+func TestOpenLiveOnlyDeployed(t *testing.T) {
+ c := liveRound()
+ g := galleryOf("tk1", c.task.Direction.Rounds, false, "", 0)
+ if g == nil || len(g.Rounds) != 2 {
+ t.Fatalf("gallery %+v", g)
+ }
+ if o := g.Rounds[0].Options; o[0].Live != "/tasks/tk1/preview?step=st2&option=0" || o[1].Live != "/tasks/tk1/preview?step=st2&option=1" || o[2].Live != "" {
+ t.Fatalf("deployed round %+v", o)
+ }
+ for _, o := range g.Rounds[1].Options {
+ if o.Live != "" {
+ t.Fatalf("earlier round %+v", o)
+ }
+ }
+ link := `<a equipo-link href="/tasks/tk1/preview?step=st2&amp;option=1" target="_blank" rel="noopener noreferrer" data-open-live>` + copyText("work.captures.open_live") + `</a>`
+ for name, page := range map[string]string{"card": renderDirectionCard(t, c), "task page": renderDirectionDecision(t, c)} {
+ mustContain(t, page, link, `href="/tasks/tk1/preview?step=st2&amp;option=0"`)
+ if n := strings.Count(page, "data-open-live"); n != 2 {
+ t.Errorf("%s: %d Open live links\n%s", name, n, page)
+ }
+ }
+ c.task.Direction.Rounds[0].Live = false
+ for name, page := range map[string]string{"card": renderDirectionCard(t, c), "task page": renderDirectionDecision(t, c)} {
+ if strings.Contains(page, "data-open-live") || strings.Contains(page, "?step=") {
+ t.Errorf("%s: Open live with no deployed round\n%s", name, page)
+ }
+ }
+}
+
+// TestHeaderRefusedLine: a preview the host refused for its headers
+// says the host needs a CARLOS update, on the direction card and the
+// task page, with no preview link.
+func TestHeaderRefusedLine(t *testing.T) {
+ c := liveRound()
+ c.task.Direction.Rounds[0].Live = false
+ c.task.Direction.PreviewRefused = true
+ line := copyText("work.preview.host_outdated")
+ if line == "" || line == "work.preview.host_outdated" {
+ t.Fatalf("no words for the line: %q", line)
+ }
+ card := renderDirectionCard(t, c)
+ mustContain(t, card, line)
+ d := decisionOf(c.task, taskLine{Task: c.task, Card: c.card})
+ if d == nil || d.LinkText != line || strings.Contains(d.Link, "/preview") {
+ t.Fatalf("decision %+v", d)
+ }
+ mustContain(t, renderDirectionDecision(t, c), line)
+ c.task.Direction.PreviewRefused = false
+ if strings.Contains(renderDirectionCard(t, c), line) || strings.Contains(renderDirectionDecision(t, c), line) {
+ t.Fatal("refused line without a refusal")
+ }
+}
diff --git a/internal/equipo/preview_pass_http.go b/internal/equipo/preview_pass_http.go
index fba148f7..bd9e48da 100644
--- a/internal/equipo/preview_pass_http.go
+++ b/internal/equipo/preview_pass_http.go
@@ -161,7 +161,11 @@ func (a *application) previewGrantOrBrowser(next http.Handler) http.Handler {
count++
}
}
- if count != 1 || r.Method != "GET" || r.URL.RawQuery != "" || !previewTaskID.MatchString(taskID) || r.URL.EscapedPath() != "/tasks/"+taskID+"/preview" {
+ // The grant opens this task's wrapper, or one option of it live
+ // (step and option, checked against the task below); no other
+ // query.
+ option, ok := parsePreviewOption(r.URL.RawQuery)
+ if count != 1 || r.Method != "GET" || !ok || !previewTaskID.MatchString(taskID) || r.URL.EscapedPath() != "/tasks/"+taskID+"/preview" {
previewErrorPage(w, ErrPreviewAccess)
return
}
@@ -175,7 +179,12 @@ func (a *application) previewGrantOrBrowser(next http.Handler) http.Handler {
previewErrorPage(w, ErrPreviewAccess)
return
}
- policy, page, e := previewWrapper(step.Preview.URL, step.Preview.Unsafe)
+ folder, ok := previewOptionPage(task, step, option)
+ if !ok {
+ previewErrorPage(w, ErrPreviewAccess)
+ return
+ }
+ policy, page, e := previewWrapper(step.Preview.URL, step.Preview.Unsafe, folder)
if e != nil {
previewErrorPage(w, ErrPreviewAccess)
return
diff --git a/internal/equipo/preview_pass_store.go b/internal/equipo/preview_pass_store.go
index f236fe96..27051617 100644
--- a/internal/equipo/preview_pass_store.go
+++ b/internal/equipo/preview_pass_store.go
@@ -105,7 +105,7 @@ func (s *Store) previewDeployment(task wire.Task) (wire.Step, string, error) {
if e != nil || ownErr != nil || canonicalPreviewHost(u.Hostname()) == "" || canonicalPreviewHost(u.Hostname()) == canonicalPreviewHost(own.Hostname()) {
return step, "", ErrPreviewAccess
}
- if _, _, err := previewWrapper(p.URL, p.Unsafe); err != nil {
+ if _, _, err := previewWrapper(p.URL, p.Unsafe, ""); err != nil {
return step, "", ErrPreviewAccess
}
raw, _ := json.Marshal(p)
diff --git a/internal/equipo/preview_wrapper.go b/internal/equipo/preview_wrapper.go
index a4c42989..dcc70c70 100644
--- a/internal/equipo/preview_wrapper.go
+++ b/internal/equipo/preview_wrapper.go
@@ -14,19 +14,86 @@ import (
"github.com/go-chi/chi/v5"
)
-func previewWrapper(raw string, unsafe bool) (string, string, error) {
+// previewWrapper is the page that frames a deployed preview: raw must be
+// a bare https origin (its root), and page "" (the root itself, as raw
+// says) or an option's folder (wire.ValidPage), framed at the root's
+// origin plus "/<page>/". The policy's frame origin is the root's
+// either way.
+func previewWrapper(raw string, unsafe bool, page string) (string, string, error) {
u, err := url.Parse(raw)
if err != nil || u.Scheme != "https" || u.Host == "" || u.User != nil || u.RawQuery != "" || u.Fragment != "" || (u.Path != "" && u.Path != "/") || strings.ContainsAny(u.Host, "* ;\r\n\t'\"\\") {
return "", "", errors.New("preview origin refused")
}
+ if page != "" && !wire.ValidPage(page) {
+ return "", "", errors.New("preview page refused")
+ }
origin := u.Scheme + "://" + u.Host
+ src := raw
+ if page != "" {
+ src = (&url.URL{Scheme: u.Scheme, Host: u.Host, Path: "/" + page + "/"}).String()
+ }
policy := "default-src 'none'; frame-src " + origin + "; style-src 'self'; font-src 'self'; base-uri 'none'; form-action 'self'; frame-ancestors 'self'"
note := ""
if unsafe {
note = "<p equipo-preview-note>" + html.EscapeString(copyText("preview.unsafe_help")) + "</p>"
}
- page := `<!doctype html><html lang="en"><meta charset="utf-8"><meta name="viewport" content="width=device-width"><link rel="stylesheet" href="/static/tokens.css"><link rel="stylesheet" href="/static/theme.css"><link rel="stylesheet" href="/static/equipo.css"><title>` + html.EscapeString(copyText("preview.wrapper_title")) + `</title><body equipo-preview>` + note + `<iframe title="` + html.EscapeString(copyText("preview.wrapper_title")) + `" src="` + html.EscapeString(raw) + `" sandbox="allow-scripts allow-same-origin" referrerpolicy="no-referrer"></iframe>`
- return policy, page, nil
+ doc := `<!doctype html><html lang="en"><meta charset="utf-8"><meta name="viewport" content="width=device-width"><link rel="stylesheet" href="/static/tokens.css"><link rel="stylesheet" href="/static/theme.css"><link rel="stylesheet" href="/static/equipo.css"><title>` + html.EscapeString(copyText("preview.wrapper_title")) + `</title><body equipo-preview>` + note + `<iframe title="` + html.EscapeString(copyText("preview.wrapper_title")) + `" src="` + html.EscapeString(src) + `" sandbox="allow-scripts allow-same-origin" referrerpolicy="no-referrer"></iframe>`
+ return policy, doc, nil
+}
+
+// previewOptionQuery is an Open live link's query (step=S&option=N),
+// by shape only: Set is false for no query. ok is false for anything
+// else: another key, a repeated one, a malformed step id, or an index
+// that is not a plain non-negative number ("01", "+1", "-1").
+type previewOptionQuery struct {
+ Set bool
+ Step string
+ Index int
+}
+
+func parsePreviewOption(raw string) (previewOptionQuery, bool) {
+ if raw == "" {
+ return previewOptionQuery{}, true
+ }
+ values, err := url.ParseQuery(raw)
+ if err != nil || len(values) != 2 || len(values["step"]) != 1 || len(values["option"]) != 1 {
+ return previewOptionQuery{}, false
+ }
+ step, option := values["step"][0], values["option"][0]
+ n, err := strconv.Atoi(option)
+ if err != nil || n < 0 || strconv.Itoa(n) != option || !previewTaskID.MatchString(step) {
+ return previewOptionQuery{}, false
+ }
+ return previewOptionQuery{Set: true, Step: step, Index: n}, true
+}
+
+// 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.
+func previewOptionPage(task wire.Task, preview wire.Step, q previewOptionQuery) (string, bool) {
+ if !q.Set {
+ return "", true
+ }
+ for _, s := range task.Steps {
+ 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) {
+ return "", false
+ }
+ page := s.Design.Options[q.Index].Page
+ return page, wire.ValidPage(page)
+ }
+ return "", false
+}
+
+// previewOptionLink is the Open live link of a task's option: the
+// wrapper route with the option's maker step and index (from 0).
+func previewOptionLink(taskID, step string, index int) string {
+ return "/tasks/" + taskID + "/preview?step=" + url.QueryEscape(step) + "&option=" + strconv.Itoa(index)
}
func (a *application) previewPage(w http.ResponseWriter, r *http.Request) {
@@ -43,6 +110,13 @@ func (a *application) previewPage(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Cache-Control", "no-store")
w.Header().Set("Referrer-Policy", "no-referrer")
w.Header().Set("Content-Type", "text/html; charset=utf-8")
+ // An Open live link (step and option) frames that option's folder of
+ // the deployed preview and nothing else; any other query is 404.
+ option, ok := parsePreviewOption(r.URL.RawQuery)
+ if !ok {
+ http.NotFound(w, r)
+ return
+ }
for i := len(task.Steps) - 1; i >= 0; i-- {
step := task.Steps[i]
p := step.Preview
@@ -56,7 +130,12 @@ func (a *application) previewPage(w http.ResponseWriter, r *http.Request) {
http.NotFound(w, r)
return
}
- policy, page, err := previewWrapper(p.URL, p.Unsafe)
+ folder, ok := previewOptionPage(task, selected, option)
+ if !ok {
+ http.NotFound(w, r)
+ return
+ }
+ policy, page, err := previewWrapper(p.URL, p.Unsafe, folder)
if err != nil {
a.failure(w, r, ErrForbidden)
return
@@ -65,7 +144,7 @@ func (a *application) previewPage(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte(page))
return
}
- if p != nil && (step.Reason == "preview_headers" || step.Reason == "preview_header_missing") {
+ if p != nil && !option.Set && (step.Reason == "preview_headers" || step.Reason == "preview_header_missing") {
member, err := a.store.Member(ctx, person)
if err != nil || !member.Active || member.Role != RoleOwner {
a.failure(w, r, ErrForbidden)
diff --git a/internal/equipo/preview_wrapper_browser_test.go b/internal/equipo/preview_wrapper_browser_test.go
index b0a0809f..a8ecfb86 100644
--- a/internal/equipo/preview_wrapper_browser_test.go
+++ b/internal/equipo/preview_wrapper_browser_test.go
@@ -40,7 +40,7 @@ func TestBrowserPreviewBlocksNavigation(t *testing.T) {
}
}))
defer preview.Close()
- policy, page, err := previewWrapper(preview.URL+"/", true)
+ policy, page, err := previewWrapper(preview.URL+"/", true, "")
if err != nil {
t.Fatal(err)
}
diff --git a/internal/equipo/preview_wrapper_test.go b/internal/equipo/preview_wrapper_test.go
index 24fa1482..a8ab1c0d 100644
--- a/internal/equipo/preview_wrapper_test.go
+++ b/internal/equipo/preview_wrapper_test.go
@@ -8,7 +8,7 @@ import (
)
func TestPreviewWrapperPinsOriginAndSandbox(t *testing.T) {
- policy, page, err := previewWrapper("https://eq-tk1.dev.example/", false)
+ policy, page, err := previewWrapper("https://eq-tk1.dev.example/", false, "")
if err != nil {
t.Fatal(err)
}
@@ -19,7 +19,7 @@ func TestPreviewWrapperPinsOriginAndSandbox(t *testing.T) {
t.Fatal(page)
}
for _, bad := range []string{"https://evil.test/path", "javascript:alert(1)", "https://good.test/; frame-src *", "https://user@host.test/", "https://*.host.test/"} {
- if _, _, err := previewWrapper(bad, false); err == nil {
+ if _, _, err := previewWrapper(bad, false, ""); err == nil {
t.Fatal("unsafe origin accepted", bad)
}
}
diff --git a/internal/equipo/templates/chat.html b/internal/equipo/templates/chat.html
index 68a2d5c8..274ebbaf 100644
--- a/internal/equipo/templates/chat.html
+++ b/internal/equipo/templates/chat.html
@@ -12,7 +12,7 @@
<div equipo-thread-list role="log" aria-live="polite"><div equipo-thread-turn data-first><span equipo-thread-avatar>{{if eq .AuthorIcon "sparkles"}}{{template "roster-mark" .}}{{else}}{{icon .AuthorIcon}}{{end}}</span><div equipo-thread-bubble><div equipo-thread-who>{{.Author}}</div><div equipo-thread-text>{{.Line}}</div></div></div>{{template "roster-thread-turns" .}}</div>
{{if .Open}}{{if .Options}}<form method="post" action="/conversation/cards/{{.ID}}/answer" data-card-form equipo-actions><input type="hidden" name="revision" value="{{.Revision}}">{{template "card-job" .}}{{template "project-name-confirm" .}}{{range .Options}}<button rst-btn name="choice" value="{{.}}" type="submit">{{.}}</button>{{end}}</form>{{else}}<form method="post" action="/conversation/cards/{{.ID}}/answer" data-card-form equipo-mini-composer><input type="hidden" name="revision" value="{{.Revision}}">{{template "card-job" .}}{{template "project-name-confirm" .}}<div equipo-mini-pill><textarea name="choice" required maxlength="2000" rows="1" aria-label="{{copy "chat.card.answer"}}" placeholder="{{copy "chat.card.answer"}}"></textarea><button type="submit" data-thread-send aria-label="{{copy "conversation.send_short"}}" data-busy-label="{{copy "roster.sending"}}">{{icon "arrow-up"}}</button></div></form>{{end}}{{else if not .Presentation.Waiting}}<form method="post" action="/conversation/cards/{{.ID}}/reply" data-card-form equipo-mini-composer><input type="hidden" name="request_id" value="{{.ReplyKey}}">{{template "card-job" .}}<div equipo-mini-pill><textarea name="body" required maxlength="2000" rows="1" aria-label="{{copy "roster.reply"}}" placeholder="{{copy "roster.reply"}}"></textarea><button type="submit" data-thread-send aria-label="{{copy "conversation.send_short"}}" data-busy-label="{{copy "roster.sending"}}">{{icon "arrow-up"}}</button></div></form>{{end}}</div>
{{else if eq .Kind "home"}}<p equipo-card-line>{{icon "folder"}}<span>{{.Line}}</span></p><form method="post" action="/conversation/cards/{{.ID}}/answer" data-card-form equipo-actions><input type="hidden" name="revision" value="{{.Revision}}">{{template "card-job" .}}<button rst-btn="primary" name="choice" value="confirm" type="submit">{{copy "chat.card.confirm"}}</button></form>
-{{else if eq .Kind "direction"}}<p equipo-card-line>{{.Line}}</p>{{template "design-gallery" .Gallery}}{{if .Open}}<div equipo-direction-actions>{{range .DirectionAnswers}}{{if eq . "build"}}{{if $.BuildNote}}<details equipo-subchat data-direction-build><summary rst-btn="primary">{{copy "chat.card.build"}}</summary><form method="post" action="/conversation/cards/{{$.ID}}/answer" data-card-form equipo-mini-composer data-draft-key="build"><input type="hidden" name="revision" value="{{$.Revision}}">{{template "card-job" $}}<input type="hidden" name="choice" value="build"><div equipo-mini-pill><textarea name="note" required maxlength="1000" rows="1" aria-label="{{copy "chat.card.build_note"}}" placeholder="{{copy "chat.card.build_note"}}"></textarea><button type="submit" data-thread-send data-direction-choice="build" aria-label="{{copy "chat.card.build"}}" data-busy-label="{{copy "roster.building"}}">{{icon "arrow-up"}}</button></div></form></details>{{else}}<form method="post" action="/conversation/cards/{{$.ID}}/answer" data-card-form><input type="hidden" name="revision" value="{{$.Revision}}">{{template "card-job" $}}{{template "project-name-confirm" $}}<button rst-btn="primary" name="choice" value="build" type="submit" data-direction-choice="build" data-busy-label="{{copy "roster.building"}}">{{copy "chat.card.build"}}</button></form>{{end}}{{else if eq . "more"}}<form method="post" action="/conversation/cards/{{$.ID}}/answer" data-card-form equipo-note-form data-direction-more data-draft-key="more"><input type="hidden" name="revision" value="{{$.Revision}}">{{template "card-job" $}}<input rst-input name="note" maxlength="1000" aria-label="{{copy "chat.card.option_note"}}" placeholder="{{copy "chat.card.option_note"}}"><button rst-btn name="choice" value="more" type="submit" data-direction-choice="more" data-busy-label="{{copy "roster.sending"}}">{{copy "chat.card.more_options"}}</button></form>{{else if eq . "again"}}<details equipo-subchat data-direction-thread><summary rst-btn>{{copy "chat.card.again"}}</summary><div equipo-thread-list role="log" aria-live="polite"><div equipo-thread-turn><span equipo-thread-avatar>{{icon $.AuthorIcon}}</span><div equipo-thread-bubble><div equipo-thread-who>{{$.Author}}</div><div equipo-thread-text>{{copy "roster.change"}}</div></div></div></div><form method="post" action="/conversation/cards/{{$.ID}}/answer" data-card-form equipo-mini-composer data-draft-key="again"><input type="hidden" name="revision" value="{{$.Revision}}">{{template "card-job" $}}<input type="hidden" name="choice" value="again"><div equipo-mini-pill><textarea name="note" required maxlength="1000" rows="1" aria-label="{{copy "roster.reply"}}" placeholder="{{copy "roster.reply"}}"></textarea><button type="submit" data-thread-send data-direction-choice="again" aria-label="{{copy "conversation.send_short"}}" data-busy-label="{{copy "roster.sending"}}">{{icon "arrow-up"}}</button></div></form></details>{{else}}<form method="post" action="/conversation/cards/{{$.ID}}/answer" data-card-form><input type="hidden" name="revision" value="{{$.Revision}}">{{template "card-job" $}}<button rst-btn name="choice" value="{{.}}" type="submit" data-direction-choice="{{.}}">{{copy (printf "chat.card.%s" .)}}</button></form>{{end}}{{end}}</div>{{else}}{{with .Note}}<p equipo-card-done role="status">{{.}}</p>{{end}}{{if .Presentation.Thread}}<div equipo-subchat data-roster-step="{{.Presentation.StepID}}"><div equipo-thread-list role="log" aria-live="polite">{{template "roster-thread-turns" .}}</div></div>{{end}}{{end}}
+{{else if eq .Kind "direction"}}<p equipo-card-line>{{.Line}}</p>{{with .HostOutdated}}<p equipo-card-note data-preview-refused>{{.}}</p>{{end}}{{template "design-gallery" .Gallery}}{{if .Open}}<div equipo-direction-actions>{{range .DirectionAnswers}}{{if eq . "build"}}{{if $.BuildNote}}<details equipo-subchat data-direction-build><summary rst-btn="primary">{{copy "chat.card.build"}}</summary><form method="post" action="/conversation/cards/{{$.ID}}/answer" data-card-form equipo-mini-composer data-draft-key="build"><input type="hidden" name="revision" value="{{$.Revision}}">{{template "card-job" $}}<input type="hidden" name="choice" value="build"><div equipo-mini-pill><textarea name="note" required maxlength="1000" rows="1" aria-label="{{copy "chat.card.build_note"}}" placeholder="{{copy "chat.card.build_note"}}"></textarea><button type="submit" data-thread-send data-direction-choice="build" aria-label="{{copy "chat.card.build"}}" data-busy-label="{{copy "roster.building"}}">{{icon "arrow-up"}}</button></div></form></details>{{else}}<form method="post" action="/conversation/cards/{{$.ID}}/answer" data-card-form><input type="hidden" name="revision" value="{{$.Revision}}">{{template "card-job" $}}{{template "project-name-confirm" $}}<button rst-btn="primary" name="choice" value="build" type="submit" data-direction-choice="build" data-busy-label="{{copy "roster.building"}}">{{copy "chat.card.build"}}</button></form>{{end}}{{else if eq . "more"}}<form method="post" action="/conversation/cards/{{$.ID}}/answer" data-card-form equipo-note-form data-direction-more data-draft-key="more"><input type="hidden" name="revision" value="{{$.Revision}}">{{template "card-job" $}}<input rst-input name="note" maxlength="1000" aria-label="{{copy "chat.card.option_note"}}" placeholder="{{copy "chat.card.option_note"}}"><button rst-btn name="choice" value="more" type="submit" data-direction-choice="more" data-busy-label="{{copy "roster.sending"}}">{{copy "chat.card.more_options"}}</button></form>{{else if eq . "again"}}<details equipo-subchat data-direction-thread><summary rst-btn>{{copy "chat.card.again"}}</summary><div equipo-thread-list role="log" aria-live="polite"><div equipo-thread-turn><span equipo-thread-avatar>{{icon $.AuthorIcon}}</span><div equipo-thread-bubble><div equipo-thread-who>{{$.Author}}</div><div equipo-thread-text>{{copy "roster.change"}}</div></div></div></div><form method="post" action="/conversation/cards/{{$.ID}}/answer" data-card-form equipo-mini-composer data-draft-key="again"><input type="hidden" name="revision" value="{{$.Revision}}">{{template "card-job" $}}<input type="hidden" name="choice" value="again"><div equipo-mini-pill><textarea name="note" required maxlength="1000" rows="1" aria-label="{{copy "roster.reply"}}" placeholder="{{copy "roster.reply"}}"></textarea><button type="submit" data-thread-send data-direction-choice="again" aria-label="{{copy "conversation.send_short"}}" data-busy-label="{{copy "roster.sending"}}">{{icon "arrow-up"}}</button></div></form></details>{{else}}<form method="post" action="/conversation/cards/{{$.ID}}/answer" data-card-form><input type="hidden" name="revision" value="{{$.Revision}}">{{template "card-job" $}}<button rst-btn name="choice" value="{{.}}" type="submit" data-direction-choice="{{.}}">{{copy (printf "chat.card.%s" .)}}</button></form>{{end}}{{end}}</div>{{else}}{{with .Note}}<p equipo-card-done role="status">{{.}}</p>{{end}}{{if .Presentation.Thread}}<div equipo-subchat data-roster-step="{{.Presentation.StepID}}"><div equipo-thread-list role="log" aria-live="polite">{{template "roster-thread-turns" .}}</div></div>{{end}}{{end}}
{{else if eq .Kind "specialist"}}<p equipo-card-line>{{.Line}}</p>{{with .Specialist}}{{range .Capabilities}}<p equipo-card-note data-capability="{{.ID}}">{{.Words}}</p>{{end}}<p equipo-card-note data-specialist-brief>{{printf (copy "chat.card.specialist_brief") .Brief}}</p>{{end}}{{if .Open}}<form method="post" action="/conversation/cards/{{.ID}}/answer" data-card-form equipo-actions><input type="hidden" name="revision" value="{{.Revision}}">{{template "card-job" .}}{{template "project-name-confirm" .}}{{range .Options}}<button rst-btn="{{if eq . "add"}}primary{{end}}" name="choice" value="{{.}}" type="submit" data-specialist-choice="{{.}}">{{copy (printf "chat.card.%s" .)}}</button>{{end}}</form>{{else}}{{with .Note}}<p equipo-card-note>{{.}}</p>{{end}}{{end}}
{{else if eq .Kind "research_sources"}}<p equipo-card-line>{{.Line}}</p>{{with .Name}}<p equipo-card-note data-research-task>{{printf (copy "chat.card.research_for") .}}</p>{{end}}{{with .Research}}<p equipo-card-note data-research-question>{{printf (copy "chat.card.research_looks_for") .Question}}</p><ul equipo-card-list data-research-urls>{{range .URLs}}<li><code>{{.}}</code></li>{{end}}</ul>{{end}}{{if .Open}}<form method="post" action="/conversation/cards/{{.ID}}/answer" data-card-form equipo-actions><input type="hidden" name="revision" value="{{.Revision}}">{{template "card-job" .}}{{template "project-name-confirm" .}}{{range .Options}}<button rst-btn="{{if eq . "allow"}}primary{{end}}" name="choice" value="{{.}}" type="submit" data-research-choice="{{.}}">{{copy (printf "chat.card.%s" .)}}</button>{{end}}</form>{{else}}{{with .Note}}<p equipo-card-note>{{.}}</p>{{end}}{{end}}
{{else if eq .Kind "instance_inventory"}}<p equipo-card-line>{{.Line}}</p>{{with .Inventory}}<ul equipo-card-list data-instance-addresses>{{range .Addresses}}<li><code>{{.}}</code></li>{{end}}</ul>{{end}}{{if .Open}}<form method="post" action="/conversation/cards/{{.ID}}/answer" data-card-form equipo-actions><input type="hidden" name="revision" value="{{.Revision}}"><button rst-btn="primary" name="choice" value="confirm" type="submit" data-instance-confirm>{{copy "services.inventory.confirm"}}</button></form>{{end}}{{else if eq .Kind "research_inventory"}}<p equipo-card-line>{{.Line}}</p>{{with .Inventory}}<ul equipo-card-list data-research-addresses>{{range .Addresses}}<li><code>{{.}}</code></li>{{end}}</ul>{{end}}{{if .Open}}<form method="post" action="/conversation/cards/{{.ID}}/answer" data-card-form equipo-actions><input type="hidden" name="revision" value="{{.Revision}}">{{template "card-job" .}}<button rst-btn="primary" name="choice" value="confirm" type="submit" data-inventory-confirm>{{copy "chat.card.inventory_confirm"}}</button></form>{{else}}{{with .Note}}<p equipo-card-note>{{.}}</p>{{end}}{{end}}
diff --git a/internal/equipo/templates/work_parts.html b/internal/equipo/templates/work_parts.html
index 41586cbe..8d2da4fc 100644
--- a/internal/equipo/templates/work_parts.html
+++ b/internal/equipo/templates/work_parts.html
@@ -57,4 +57,4 @@
instance's task-file route only (the task page and the direction
card). On an open direction card each option is a form of its own:
Build this one and More like this name it by step and index. */}}
-{{define "design-gallery"}}{{with .}}{{$a := .Answer}}<div equipo-captures data-captures>{{range .Rounds}}<div equipo-capture-round data-round="{{.Step}}">{{range .Options}}<section equipo-capture-option data-option><h3>{{.Label}}</h3>{{with .Direction}}<p equipo-direction>{{.}}</p>{{end}}{{if .Captures}}<ul equipo-kept>{{range .Captures}}<li><a href="{{.Src}}" target="_blank" rel="noopener" data-capture="{{.ID}}"><figure><img src="{{.Src}}" alt="{{.Alt}}" width="{{.Width}}" height="{{.Height}}" loading="lazy" decoding="async"><figcaption>{{.Caption}}</figcaption></figure></a></li>{{end}}</ul>{{else}}<p equipo-quiet>{{copy "work.captures.none"}}</p>{{end}}{{if and $a .Step}}<form method="post" action="/conversation/cards/{{$a.CardID}}/answer"{{if not $a.Task}} data-card-form{{end}} equipo-option-actions data-draft-key="option {{.Step}} {{.Index}}"><input type="hidden" name="revision" value="{{$a.Revision}}">{{with $a.From}}<input type="hidden" name="from" value="{{.}}">{{end}}{{with $a.Task}}<input type="hidden" name="task" value="{{.}}">{{end}}{{with $a.Job}}<input type="hidden" name="from" value="job"><input type="hidden" name="job" value="{{.}}">{{end}}<input type="hidden" name="option_step" value="{{.Step}}"><input type="hidden" name="option_index" value="{{.Index}}"><input rst-input name="note" maxlength="1000" aria-label="{{copy "chat.card.option_note"}}" placeholder="{{copy "chat.card.option_note"}}">{{if $a.Task}}<button equipo-btn data-primary type="submit" name="choice" value="build" data-option-choice="build">{{copy "chat.card.build"}}</button>{{if $a.Like}}<button equipo-btn type="submit" name="choice" value="like" data-option-choice="like">{{copy "chat.card.like"}}</button>{{end}}{{else}}<button rst-btn="primary" type="submit" name="choice" value="build" data-option-choice="build" data-busy-label="{{copy "roster.building"}}">{{copy "chat.card.build"}}</button>{{if $a.Like}}<button rst-btn type="submit" name="choice" value="like" data-option-choice="like" data-busy-label="{{copy "roster.sending"}}">{{copy "chat.card.like"}}</button>{{end}}{{end}}</form>{{end}}</section>{{end}}</div>{{end}}{{with .Earlier}}<p equipo-quiet data-earlier><a equipo-link href="{{.}}">{{copy "work.captures.earlier"}}</a></p>{{end}}</div>{{end}}{{end}}
+{{define "design-gallery"}}{{with .}}{{$a := .Answer}}<div equipo-captures data-captures>{{range .Rounds}}<div equipo-capture-round data-round="{{.Step}}">{{range .Options}}<section equipo-capture-option data-option><h3>{{.Label}}</h3>{{with .Direction}}<p equipo-direction>{{.}}</p>{{end}}{{if .Captures}}<ul equipo-kept>{{range .Captures}}<li><a href="{{.Src}}" target="_blank" rel="noopener" data-capture="{{.ID}}"><figure><img src="{{.Src}}" alt="{{.Alt}}" width="{{.Width}}" height="{{.Height}}" loading="lazy" decoding="async"><figcaption>{{.Caption}}</figcaption></figure></a></li>{{end}}</ul>{{else}}<p equipo-quiet>{{copy "work.captures.none"}}</p>{{end}}{{with .Live}}<p equipo-quiet><a equipo-link href="{{.}}" target="_blank" rel="noopener noreferrer" data-open-live>{{copy "work.captures.open_live"}}</a></p>{{end}}{{if and $a .Step}}<form method="post" action="/conversation/cards/{{$a.CardID}}/answer"{{if not $a.Task}} data-card-form{{end}} equipo-option-actions data-draft-key="option {{.Step}} {{.Index}}"><input type="hidden" name="revision" value="{{$a.Revision}}">{{with $a.From}}<input type="hidden" name="from" value="{{.}}">{{end}}{{with $a.Task}}<input type="hidden" name="task" value="{{.}}">{{end}}{{with $a.Job}}<input type="hidden" name="from" value="job"><input type="hidden" name="job" value="{{.}}">{{end}}<input type="hidden" name="option_step" value="{{.Step}}"><input type="hidden" name="option_index" value="{{.Index}}"><input rst-input name="note" maxlength="1000" aria-label="{{copy "chat.card.option_note"}}" placeholder="{{copy "chat.card.option_note"}}">{{if $a.Task}}<button equipo-btn data-primary type="submit" name="choice" value="build" data-option-choice="build">{{copy "chat.card.build"}}</button>{{if $a.Like}}<button equipo-btn type="submit" name="choice" value="like" data-option-choice="like">{{copy "chat.card.like"}}</button>{{end}}{{else}}<button rst-btn="primary" type="submit" name="choice" value="build" data-option-choice="build" data-busy-label="{{copy "roster.building"}}">{{copy "chat.card.build"}}</button>{{if $a.Like}}<button rst-btn type="submit" name="choice" value="like" data-option-choice="like" data-busy-label="{{copy "roster.sending"}}">{{copy "chat.card.like"}}</button>{{end}}{{end}}</form>{{end}}</section>{{end}}</div>{{end}}{{with .Earlier}}<p equipo-quiet data-earlier><a equipo-link href="{{.}}">{{copy "work.captures.earlier"}}</a></p>{{end}}</div>{{end}}{{end}}
diff --git a/internal/equipo/work_views.go b/internal/equipo/work_views.go
index fc537965..2e987d57 100644
--- a/internal/equipo/work_views.go
+++ b/internal/equipo/work_views.go
@@ -798,6 +798,10 @@ func decisionOf(t wire.Task, v taskLine) *decisionView {
d.Link, d.LinkLabel = "/tasks/"+t.ID+"/preview", fmt.Sprintf(copyText("work.card.preview_tailnet"), previewHostLabel(dir.PreviewURL))
case dir.PreviewURL != "":
d.Link, d.LinkLabel = "/tasks/"+t.ID+"/preview", fmt.Sprintf(copyText("work.card.preview_open"), previewHostLabel(dir.PreviewURL))
+ case dir.PreviewRefused:
+ // The host refused the preview for its headers: say why
+ // there is none, and the branch as before (spec 8.5).
+ d.LinkText, d.Link, d.LinkLabel = copyText("work.preview.host_outdated"), dir.BranchURL, copyText("work.direction.branch")
case dir.PreviewsOff:
// Nothing paired: how to pair one, and the branch as before.
d.LinkText, d.Link, d.LinkLabel = copyText("work.direction.previews_off"), "/conversation/settings/machines#previews", copyText("work.direction.pair")
diff --git a/internal/wire/design.go b/internal/wire/design.go
index a088fc50..b090faf3 100644
--- a/internal/wire/design.go
+++ b/internal/wire/design.go
@@ -643,6 +643,10 @@ func validDirection(s string) bool {
// validPage: an option's folder name, at most maxPage bytes.
func validPage(s string) bool { return len(s) <= maxPage && pageFolder.MatchString(s) }
+// ValidPage reports whether s is a valid option folder name (Page), as
+// the instance checks one before it frames it live.
+func ValidPage(s string) bool { return validPage(s) }
+
// validCapturePath: a page path as render_page takes one (SitePath, in
// short): absolute, printable ASCII without space, backslash or
// fragment, at most maxCapturePath bytes.