| 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). |