Public: anyone can read this; the crew can change it.
Ship, decline, say and decide stay on the page they were taken from #1129
scout/forge:scout/1110-ship-decline-say-and-decide-stay-on-the → main 4 commits fork 7 threads · 7 unresolved
README.md +1
| @@ -9,6 +9,7 @@ that pull's own preview — its own URL, on its own copy of production's data | ||
| 9 | 9 | and every deploy is the check on that pull. No agent can move the default |
| 10 | 10 | branch, so the only way code reaches production is a merge a person made: the |
| 11 | 11 | crew proposes, you decide what ships. |
| 12 | Ship, close, say and comment return to the page they were taken from, with a one-line flash and a link; the form carries a same-forge `back` path, never the Referer. | |
| 12 | 13 | |
| 13 | 14 | That view is the **studio**, and it is the front door — a browser with no |
| 14 | 15 | `forge_mode` cookie lands there. It speaks four words for the whole loop: |
src/web/flash.ts +23
| @@ -12,6 +12,16 @@ | ||
| 12 | 12 | |
| 13 | 13 | import { cookieValue } from "../http/context.ts"; |
| 14 | 14 | |
| 15 | /** Whether `to` is a path on this forge: one slash, no scheme, no control bytes. */ | |
| 16 | export function localPath(to: string): boolean { | |
| 17 | return ( | |
| 18 | to.length <= 512 && | |
| 19 | /^\/(?![/\\])/.test(to) && | |
| 20 | // eslint-disable-next-line no-control-regex | |
| 21 | !/[\u0000-\u001f\u007f]/.test(to) | |
| 22 | ); | |
| 23 | } | |
| 24 | ||
| 15 | 25 | export const FLASH_COOKIE = "forge_flash"; |
| 16 | 26 | |
| 17 | 27 | export interface Flash { |
| @@ -19,6 +29,8 @@ export interface Flash { | ||
| 19 | 29 | message: string; |
| 20 | 30 | /** A one-time value rendered in a copyable monospace block. */ |
| 21 | 31 | code?: string; |
| 32 | /** The one place worth going to look: a path on this forge, and its words. */ | |
| 33 | link?: { href: string; label: string }; | |
| 22 | 34 | } |
| 23 | 35 | |
| 24 | 36 | // Cookies cap out around 4KB; a flash is a sentence, not a payload. |
| @@ -55,6 +67,16 @@ export function readFlash(request: Request): Flash | undefined { | ||
| 55 | 67 | if (typeof value.message !== "string" || value.message === "") |
| 56 | 68 | return undefined; |
| 57 | 69 | const tone = value.tone; |
| 70 | const l = value.link as Record<string, unknown> | null | undefined; | |
| 71 | const link = | |
| 72 | typeof l === "object" && | |
| 73 | l !== null && | |
| 74 | typeof l.href === "string" && | |
| 75 | typeof l.label === "string" && | |
| 76 | localPath(l.href) && | |
| 77 | l.label !== "" | |
| 78 | ? { href: l.href, label: l.label.slice(0, 80) } | |
| 79 | : undefined; | |
| 58 | 80 | return { |
| 59 | 81 | message: value.message.slice(0, MAX_FLASH), |
| 60 | 82 | ...(tone === "success" || tone === "danger" || tone === "attn" |
| @@ -63,5 +85,6 @@ export function readFlash(request: Request): Flash | undefined { | ||
| 63 | 85 | ...(typeof value.code === "string" && value.code !== "" |
| 64 | 86 | ? { code: value.code.slice(0, 512) } |
| 65 | 87 | : {}), |
| 88 | ...(link !== undefined ? { link } : {}), | |
| 66 | 89 | }; |
| 67 | 90 | } |
src/web/form.ts +18
| @@ -11,6 +11,8 @@ | ||
| 11 | 11 | import { BODY_MAX, readBounded, STRANGER_MAX } from "../http/limits.ts"; |
| 12 | 12 | import { scopeAllows, type TokenScope } from "../core/tokens.ts"; |
| 13 | 13 | import { crossOrigin, type Ctx } from "../http/context.ts"; |
| 14 | import { localPath } from "./flash.ts"; | |
| 15 | import { html, type Html } from "./html.ts"; | |
| 14 | 16 | |
| 15 | 17 | export type Form = Awaited<ReturnType<Request["formData"]>>; |
| 16 | 18 | |
| @@ -63,3 +65,19 @@ export function field(form: Form, name: string): string { | ||
| 63 | 65 | export function prefersJson(ctx: Ctx): boolean { |
| 64 | 66 | return (ctx.request.headers.get("accept") ?? "").includes("application/json"); |
| 65 | 67 | } |
| 68 | ||
| 69 | /** | |
| 70 | * Where a decision was taken: the form's own `back` field when it is a path | |
| 71 | * on this forge, else `fallback`. The Referer is never consulted — it is | |
| 72 | * absent under some privacy settings, and a field a form carries is the page | |
| 73 | * saying where it wants to be. | |
| 74 | */ | |
| 75 | export function formBack(form: Form, fallback: string): string { | |
| 76 | const back = field(form, "back"); | |
| 77 | return localPath(back) ? back : fallback; | |
| 78 | } | |
| 79 | ||
| 80 | /** The hidden field that makes a form come back to the page it is on. */ | |
| 81 | export function backInput(ctx: Ctx): Html { | |
| 82 | return html`<input type="hidden" name="back" value="${ctx.url.pathname}${ctx.url.search}" />`; | |
| 83 | } |
src/web/layout.ts +4
| @@ -392,6 +392,10 @@ function flashToast(flash: Flash): Html { | ||
| 392 | 392 | ${icon(glyph)} |
| 393 | 393 | <div class="toast-body"> |
| 394 | 394 | ${flash.message} |
| 395 | ${when( | |
| 396 | flash.link, | |
| 397 | (link) => html` · <a href="${link.href}">${link.label}</a>`, | |
| 398 | )} | |
| 395 | 399 | ${when( |
| 396 | 400 | flash.code, |
| 397 | 401 | (code) => |
src/web/pages/board.ts +1 −1
| @@ -501,7 +501,7 @@ function declinedStrip(ctx: Ctx, scope: BoardScope): Html | null { | ||
| 501 | 501 | ><b>${d.repo.name}</b>: the planner declined the direction and waits |
| 502 | 502 | for you. <q>${d.words}</q></span |
| 503 | 503 | > |
| 504 | <input type="hidden" name="back" value="board" /> | |
| 504 | <input type="hidden" name="back" value="/board" /> | |
| 505 | 505 | <input |
| 506 | 506 | class="input" |
| 507 | 507 | name="body" |
src/web/pages/issues.ts +13 −11
| @@ -24,7 +24,7 @@ import { | ||
| 24 | 24 | signInFirst, |
| 25 | 25 | signInHref, |
| 26 | 26 | } from "../chrome.ts"; |
| 27 | import { field, readForm } from "../form.ts"; | |
| 27 | import { field, formBack, readForm } from "../form.ts"; | |
| 28 | 28 | import { html, raw, when, type Html } from "../html.ts"; |
| 29 | 29 | import { flashTo, page, redirect } from "../layout.ts"; |
| 30 | 30 | import { btn, empty, icon, field as formField } from "../ui.ts"; |
| @@ -291,13 +291,13 @@ export async function issueCommentSubmit(ctx: Ctx): Promise<Response> { | ||
| 291 | 291 | const form = await readForm(ctx, "rw"); |
| 292 | 292 | if (form instanceof Response) return form; |
| 293 | 293 | |
| 294 | // A comment posted from the board's "the planner declined" line returns to | |
| 295 | // the board. A fixed word, never a URL from the form: no open redirect. | |
| 296 | const back = field(form, "back") === "board" ? "/board" : undefined; | |
| 294 | // A comment returns to the page whose form posted it (`formBack`: a path on | |
| 295 | // this forge, never a URL), the board's "the planner declined" line included. | |
| 297 | 296 | const dest = `${repoBase(found.repo)}/issues/${found.issue.number}`; |
| 297 | const back = formBack(form, dest); | |
| 298 | 298 | const body = field(form, "body"); |
| 299 | 299 | if (body.trim() === "") |
| 300 | return flashTo(ctx, dest, { | |
| 300 | return flashTo(ctx, back, { | |
| 301 | 301 | tone: "danger", |
| 302 | 302 | message: "A comment needs something in it.", |
| 303 | 303 | }); |
| @@ -309,15 +309,17 @@ export async function issueCommentSubmit(ctx: Ctx): Promise<Response> { | ||
| 309 | 309 | body, |
| 310 | 310 | ); |
| 311 | 311 | if (!added.ok) |
| 312 | return flashTo(ctx, dest, { | |
| 312 | return flashTo(ctx, back, { | |
| 313 | 313 | tone: "danger", |
| 314 | 314 | message: originError(added.error) ?? "That comment could not be posted.", |
| 315 | 315 | }); |
| 316 | return back === undefined | |
| 317 | ? flashTo(ctx, `${dest}#conversation`, { message: "Comment posted." }) | |
| 318 | : flashTo(ctx, back, { | |
| 319 | message: `Answered on #${found.issue.number}. The planner plans again.`, | |
| 320 | }); | |
| 316 | if (back === "/board") | |
The special case |
||
| 317 | return flashTo(ctx, back, { | |
| 318 | message: `Answered on #${found.issue.number}. The planner plans again.`, | |
| 319 | }); | |
| 320 | return flashTo(ctx, back === dest ? `${dest}#conversation` : back, { | |
| 321 | message: "Comment posted.", | |
| 322 | }); | |
| 321 | 323 | } |
| 322 | 324 | |
| 323 | 325 | export { parseNumber }; |
src/web/pages/pull.ts +7 −4
| @@ -60,7 +60,7 @@ import { | ||
| 60 | 60 | type DiffViewOptions, |
| 61 | 61 | type ThreadView, |
| 62 | 62 | } from "../diff-view.ts"; |
| 63 | import { field, readForm } from "../form.ts"; | |
| 63 | import { field, formBack, readForm } from "../form.ts"; | |
| 64 | 64 | import { html, raw, when, type Html } from "../html.ts"; |
| 65 | 65 | import { flashTo, page, redirect } from "../layout.ts"; |
| 66 | 66 | import { liveClientJs, liveMount } from "../live.ts"; |
| @@ -798,9 +798,10 @@ export async function pullCommentSubmit(ctx: Ctx): Promise<Response> { | ||
| 798 | 798 | if (form instanceof Response) return form; |
| 799 | 799 | |
| 800 | 800 | const dest = `${repoBase(found.repo)}/pulls/${found.pull.number}`; |
| 801 | const back = formBack(form, dest); | |
| 801 | 802 | const bodyText = field(form, "body"); |
| 802 | 803 | if (bodyText.trim() === "") |
| 803 | return flashTo(ctx, dest, { | |
| 804 | return flashTo(ctx, back, { | |
| 804 | 805 | tone: "danger", |
| 805 | 806 | message: "A comment needs something in it.", |
| 806 | 807 | }); |
| @@ -812,11 +813,13 @@ export async function pullCommentSubmit(ctx: Ctx): Promise<Response> { | ||
| 812 | 813 | bodyText, |
| 813 | 814 | ); |
| 814 | 815 | if (!added.ok) |
| 815 | return flashTo(ctx, dest, { | |
| 816 | return flashTo(ctx, back, { | |
| 816 | 817 | tone: "danger", |
| 817 | 818 | message: originError(added.error) ?? "That comment could not be posted.", |
| 818 | 819 | }); |
| 819 | return flashTo(ctx, `${dest}`, { message: "Comment posted." }); | |
| 820 | return flashTo(ctx, back === dest ? `${dest}` : back, { | |
| 821 | message: "Comment posted.", | |
| 822 | }); | |
| 820 | 823 | } |
| 821 | 824 | |
| 822 | 825 | /** Match the diff viewer's per-file anchor id, so the redirect lands there. */ |
src/web/pages/thread.ts +6 −4
| @@ -49,7 +49,7 @@ import { | ||
| 49 | 49 | } from "../../core/users.ts"; |
| 50 | 50 | import type { Ctx } from "../../http/context.ts"; |
| 51 | 51 | import { commentCard } from "../comments.ts"; |
| 52 | import { field, readForm } from "../form.ts"; | |
| 52 | import { backInput, field, formBack, readForm } from "../form.ts"; | |
| 53 | 53 | import { html, raw, when, type Html } from "../html.ts"; |
| 54 | 54 | import { flashOrJson, flashTo } from "../layout.ts"; |
| 55 | 55 | import { |
| @@ -482,6 +482,7 @@ export function composer(ctx: Ctx, o: ComposerOptions): Html { | ||
| 482 | 482 | data-box="Write a comment" |
| 483 | 483 | data-submit-key |
| 484 | 484 | > |
| 485 | ${backInput(ctx)} | |
| 485 | 486 | <label class="sr-only" for="comment-body">Comment</label> |
| 486 | 487 | <textarea |
| 487 | 488 | class="input" |
| @@ -725,6 +726,7 @@ export async function stateSubmit( | ||
| 725 | 726 | |
| 726 | 727 | const wanted = field(form, "state") === "closed" ? "closed" : "open"; |
| 727 | 728 | const dest = `${repoBase(found.repo)}/${kind === "pull" ? "pulls" : "issues"}/${found.issue.number}`; |
| 729 | const back = formBack(form, dest); | |
| 728 | 730 | const why = field(form, "reason"); |
| 729 | 731 | const intoText = field(form, "into").trim(); |
| 730 | 732 | const into = intoText |
| @@ -736,7 +738,7 @@ export async function stateSubmit( | ||
| 736 | 738 | into.length > 50 || |
| 737 | 739 | !into.every((n) => Number.isInteger(n) && n > 0) |
| 738 | 740 | ) |
| 739 | return flashOrJson(ctx, dest, { | |
| 741 | return flashOrJson(ctx, back, { | |
| 740 | 742 | tone: "danger", |
| 741 | 743 | message: "Close as done, dropped, or split into issue numbers.", |
| 742 | 744 | }); |
| @@ -771,9 +773,9 @@ export async function stateSubmit( | ||
| 771 | 773 | : changed.error === "forbidden" |
| 772 | 774 | ? "Only the author or someone with write access can do that." |
| 773 | 775 | : "That could not be changed."); |
| 774 | return flashOrJson(ctx, dest, { tone: "danger", message }); | |
| 776 | return flashOrJson(ctx, back, { tone: "danger", message }); | |
| 775 | 777 | } |
| 776 | return flashOrJson(ctx, dest, { | |
| 778 | return flashOrJson(ctx, back, { | |
| 777 | 779 | message: wanted === "closed" ? "Closed." : "Reopened.", |
| 778 | 780 | }); |
| 779 | 781 | } |
src/web/studio/actions.ts +19 −6
| @@ -16,11 +16,12 @@ import { DIRECTION_NOTE } from "../../crew/direct.ts"; | ||
| 16 | 16 | import { mergePull } from "../../actions/pulls.ts"; |
| 17 | 17 | import { revertPull, type RevertPullError } from "../../actions/revert.ts"; |
| 18 | 18 | import { getPull } from "../../core/pulls.ts"; |
| 19 | import { getAppByRepo } from "../../core/apps.ts"; | |
| 19 | 20 | import { canRead, getRepo, type Repo } from "../../core/repos.ts"; |
| 20 | 21 | import { bringUpToDate } from "../../crew/autonomy.ts"; |
| 21 | 22 | import type { Ctx } from "../../http/context.ts"; |
| 22 | 23 | import { loadRepo, notFoundPage, repoBase, signInFirst } from "../chrome.ts"; |
| 23 | import { field, readForm, type Form } from "../form.ts"; | |
| 24 | import { field, formBack, readForm, type Form } from "../form.ts"; | |
| 24 | 25 | import { flashOrJson, flashTo } from "../layout.ts"; |
| 25 | 26 | import { changeHref } from "./nouns.ts"; |
| 26 | 27 | |
| @@ -109,6 +110,7 @@ export async function shipSubmit(ctx: Ctx): Promise<Response> { | ||
| 109 | 110 | const form = await readForm(ctx, "rw"); |
| 110 | 111 | if (form instanceof Response) return form; |
| 111 | 112 | const base = repoBase(repo); |
| 113 | const back = formBack(form, base); | |
| 112 | 114 | const number = Number(ctx.params.number); |
| 113 | 115 | const pull = Number.isInteger(number) |
| 114 | 116 | ? getPull(ctx.app.db, repo.id, number) |
| @@ -124,7 +126,7 @@ export async function shipSubmit(ctx: Ctx): Promise<Response> { | ||
| 124 | 126 | merged.error.kind === "conflict" |
| 125 | 127 | ) { |
| 126 | 128 | const who = bringUpToDate(ctx.app, repo, pull, merged.error.files); |
| 127 | return flashOrJson(ctx, base, { | |
| 129 | return flashOrJson(ctx, back, { | |
| 128 | 130 | tone: "danger" as const, |
| 129 | 131 | message: |
| 130 | 132 | who === undefined |
| @@ -132,9 +134,19 @@ export async function shipSubmit(ctx: Ctx): Promise<Response> { | ||
| 132 | 134 | : `It conflicts with main (${merged.error.files.join(", ")}); ${who} is bringing it up to date${repo.autonomy === "autonomous" ? ", then it lands on its own" : ", then it comes back to you"}.`, |
| 133 | 135 | }); |
| 134 | 136 | } |
| 135 | return flashOrJson(ctx, base, { | |
| 137 | return flashOrJson(ctx, back, { | |
| 136 | 138 | ...(merged.ok |
| 137 | ? { message: `Shipped "${pull.title}". Production is redeploying.` } | |
| 139 | ? { | |
| 140 | ...(getAppByRepo(ctx.app.db, repo.id) === undefined | |
outdated
Old message told the owner production is redeploying; the new one says only This getAppByRepo branch, the 'production is redeploying' wording and the /app/production/open link have no test. Cover them with a repo that has an app. |
||
| 141 | ? { | |
| 142 | message: `Shipped "${pull.title}".`, | |
| 143 | link: { href: `${base}/pulls/${pull.number}`, label: "see it" }, | |
| 144 | } | |
| 145 | : { | |
| 146 | message: `Shipped "${pull.title}"; production is redeploying.`, | |
| 147 | link: { href: `${base}/app/production/open`, label: "see it live" }, | |
| 148 | }), | |
| 149 | } | |
| 138 | 150 | : { |
| 139 | 151 | tone: "danger" as const, |
| 140 | 152 | message: `That could not ship: ${mergeWords(merged.error)}.`, |
| @@ -216,6 +228,7 @@ export async function saySubmit(ctx: Ctx): Promise<Response> { | ||
| 216 | 228 | const form = await readForm(ctx, "rw"); |
| 217 | 229 | if (form instanceof Response) return form; |
| 218 | 230 | const base = repoBase(repo); |
| 231 | const back = formBack(form, base); | |
| 219 | 232 | const number = Number(ctx.params.number); |
| 220 | 233 | const pull = Number.isInteger(number) |
| 221 | 234 | ? getPull(ctx.app.db, repo.id, number) |
| @@ -224,12 +237,12 @@ export async function saySubmit(ctx: Ctx): Promise<Response> { | ||
| 224 | 237 | return notFoundPage(ctx); |
| 225 | 238 | const text = field(form, "text").trim(); |
| 226 | 239 | if (text === "") |
| 227 | return flashTo(ctx, base, { | |
| 240 | return flashTo(ctx, back, { | |
This |
||
| 228 | 241 | tone: "danger", |
| 229 | 242 | message: "Say something first.", |
| 230 | 243 | }); |
| 231 | 244 | const said = addComment(ctx.app, ctx.auth.user, repo, pull, text); |
| 232 | return flashOrJson(ctx, base, { | |
| 245 | return flashOrJson(ctx, back, { | |
| 233 | 246 | ...(said.ok |
| 234 | 247 | ? { message: `Told ${pull.authorName}. It picks the change back up.` } |
| 235 | 248 | : { tone: "danger" as const, message: "That could not be said." }), |
src/web/studio/asks.ts +4 −1
| @@ -51,6 +51,7 @@ import { waitsForPerson, type ReviewWait } from "../../crew/review.ts"; | ||
| 51 | 51 | import type { Ctx } from "../../http/context.ts"; |
| 52 | 52 | import { vitals } from "../../kernel/vitals.ts"; |
| 53 | 53 | import { repoBase } from "../chrome.ts"; |
| 54 | import { backInput } from "../form.ts"; | |
| 54 | 55 | import { html, when, type Html } from "../html.ts"; |
| 55 | 56 | import { btn, card, icon, row } from "../ui.ts"; |
| 56 | 57 | import { lookUrl } from "../../core/looks.ts"; |
| @@ -851,7 +852,7 @@ const askFormId = (d: Decision): string => `ask-${d.id}`; | ||
| 851 | 852 | * It sits after the panel's form, because a form inside a form is not |
| 852 | 853 | * HTML; the button reaches it by id. |
| 853 | 854 | */ |
| 854 | export function decisionForm(d: Decision): Html | null { | |
| 855 | export function decisionForm(ctx: Ctx, d: Decision): Html | null { | |
| 855 | 856 | const pull = d.pull; |
| 856 | 857 | if (pull === undefined) return null; |
| 857 | 858 | const base = repoBase(d.repo); |
| @@ -859,10 +860,12 @@ export function decisionForm(d: Decision): Html | null { | ||
| 859 | 860 | if (d.kind === "stopped") |
| 860 | 861 | return html`<form ${own} action="${base}/pulls/${pull.number}/state"> |
| 861 | 862 | <input type="hidden" name="state" value="closed" /> |
| 863 | ${backInput(ctx)} | |
| 862 | 864 | </form>`; |
| 863 | 865 | if (d.kind === "look" || d.kind === "review") |
| 864 | 866 | return html`<form ${own} action="${base}/pulls/${pull.number}/ship"> |
| 865 | 867 | <input type="hidden" name="pull" value="${pull.number}" /> |
| 868 | ${backInput(ctx)} | |
| 866 | 869 | </form>`; |
| 867 | 870 | return null; |
| 868 | 871 | } |
src/web/studio/asks_page.ts +1 −1
| @@ -268,7 +268,7 @@ export function needsYouSection( | ||
| 268 | 268 | ${btn("Preview", { size: "sm" })} |
| 269 | 269 | <span class="muted small">on the selected asks</span> |
| 270 | 270 | </form>`} |
| 271 | ${decisions.map((d) => decisionForm(d))} | |
| 271 | ${decisions.map((d) => decisionForm(ctx, d))} | |
| 272 | 272 | </section>`; |
| 273 | 273 | return { body, scriptJs: pickable < 2 ? "" : SELECT_ALL_JS }; |
| 274 | 274 | } |
src/web/studio/change.ts +3 −1
| @@ -37,6 +37,7 @@ import { | ||
| 37 | 37 | repoHeader, |
| 38 | 38 | repoPalette, |
| 39 | 39 | } from "../chrome.ts"; |
| 40 | import { backInput } from "../form.ts"; | |
| 40 | 41 | import { html, when, type Html } from "../html.ts"; |
| 41 | 42 | import type { IconName as Glyph } from "../icons.ts"; |
| 42 | 43 | import { page, redirect } from "../layout.ts"; |
| @@ -432,6 +433,7 @@ async function changeConversation( | ||
| 432 | 433 | )}.</p> |
| 433 | 434 | <div class="bar mt"> |
| 434 | 435 | <form method="post" action="${thread}/ship"> |
| 436 | ${backInput(ctx)} | |
| 435 | 437 | ${btn("Bring up to date", { size: "sm", variant: "primary" })} |
| 436 | 438 | </form> |
| 437 | 439 | </div>` |
| @@ -520,7 +522,7 @@ async function changeConversation( | ||
| 520 | 522 | </div> |
| 521 | 523 | <aside>${when(record, () => previewCard(ctx, repo, pull))}</aside> |
| 522 | 524 | </div> |
| 523 | ${decision ? decisionForm(decision) : null} | |
| 525 | ${decision ? decisionForm(ctx, decision) : null} | |
| 524 | 526 | ${liveMount({ |
| 525 | 527 | repo: base, |
| 526 | 528 | thread: "pull", |
test/planner-declined.test.ts +2 −2
| @@ -233,7 +233,7 @@ describe("the planner declined, waiting for a person", () => { | ||
| 233 | 233 | { |
| 234 | 234 | method: "POST", |
| 235 | 235 | headers: { cookie, origin: servers.url }, |
| 236 | body: new URLSearchParams({ back: "board", body: "Plan the next season: herbs." }), | |
| 236 | body: new URLSearchParams({ back: "/board", body: "Plan the next season: herbs." }), | |
| 237 | 237 | redirect: "manual", |
| 238 | 238 | }, |
| 239 | 239 | ); |
| @@ -247,7 +247,7 @@ describe("the planner declined, waiting for a person", () => { | ||
| 247 | 247 | "waits for you", |
| 248 | 248 | ); |
| 249 | 249 | }); |
| 250 | test("`back` is a fixed word: anything else returns to the issue, never elsewhere", async () => { | |
| 250 | test("`back` is a path on this forge: anything else returns to the issue, never elsewhere", async () => { | |
| 251 | 251 | const cookie = await signIn("alice"); |
| 252 | 252 | const res = await fetch( |
| 253 | 253 | `${servers.url}/alice/garden/issues/${direction.number}/comments`, |
test/studio.test.ts +106
| @@ -398,6 +398,112 @@ describe("the studio", () => { | ||
| 398 | 398 | expect(getUserByName(app.db, "scout")).toBeDefined(); |
| 399 | 399 | }); |
| 400 | 400 | |
| 401 | test("a decision lands back on the page it was taken from, and says so with a link", async () => { | |
| 402 | const openGreen = async (name: string) => { | |
| 403 | const branch = await commitToBranch(app, alice, repo, { | |
| 404 | branch: `feature/${name}`, | |
| 405 | base: "main", | |
| 406 | message: name, | |
| 407 | files: [{ path: `${name}.md`, content: `${name}\n` }], | |
| 408 | }); | |
| 409 | if (!branch.ok) throw new Error(JSON.stringify(branch.error)); | |
| 410 | const opened = await openPull(app, alice, repo, { | |
| 411 | title: name, | |
| 412 | body: "", | |
| 413 | baseBranch: "main", | |
| 414 | headBranch: `feature/${name}`, | |
| 415 | }); | |
| 416 | if (!opened.ok) throw new Error(String(opened.error)); | |
| 417 | const run = createRun(app.db, { | |
| 418 | repoId: repo.id, | |
| 419 | kind: "check", | |
| 420 | issueId: opened.value.id, | |
| 421 | env: `pull-${opened.value.number}`, | |
| 422 | commitOid: opened.value.headOid, | |
| 423 | reason: "pull", | |
| 424 | }); | |
| 425 | claimRun(app.db, run.id); | |
| 426 | finishRun(app.db, run.id, { state: "ok", summary: "check passed" }); | |
| 427 | return opened.value; | |
| 428 | }; | |
| 429 | const home = await openGreen("from-home"); | |
| 430 | const shipped = await post(`/alice/notes/pulls/${home.number}/ship`, { | |
| 431 | back: "/", | |
| 432 | }); | |
| 433 | expect(shipped.headers.get("location")).toBe("/"); | |
| 434 | expect(getPull(app.db, repo.id, home.number)?.mergedAt).not.toBeNull(); | |
| 435 | // The flash names what happened, with the one link that matters. | |
| 436 | const flash = shipped.headers.get("set-cookie")?.split(";")[0] ?? ""; | |
| 437 | const page = await (await get("/", { cookie: `${cookie}; ${flash}` })).text(); | |
| 438 | expect(page).toContain(`Shipped "from-home"`); | |
| 439 | // notes is an app: shipping redeploys production, and the link goes there. | |
| 440 | expect(getAppByRepo(app.db, repo.id)).toBeDefined(); | |
| 441 | expect(page).toContain("; production is redeploying."); | |
| 442 | expect(page).toContain(`<a href="/alice/notes/app/production/open">see it live`); | |
| 443 | ||
outdated
The |
||
| 444 | const there = await openGreen("from-pull"); | |
| 445 | const at = `/alice/notes/pulls/${there.number}`; | |
| 446 | const stayed = await post(`${at}/ship`, { back: at }); | |
| 447 | expect(stayed.headers.get("location")).toBe(at); | |
| 448 | ||
| 449 | // A comment through the form the page really renders comes back to that page. | |
| 450 | const rendered = await (await get(at)).text(); | |
| 451 | const form = rendered.match(/<form[^>]*class="card comment-form"[\s\S]*?<\/form>/)?.[0] ?? ""; | |
| 452 | const action = form.match(/action="([^"]+)"/)?.[1] ?? ""; | |
| 453 | const backField = form.match(/name="back" value="([^"]+)"/)?.[1] ?? ""; | |
| 454 | expect(action).toBe(`${at}/comments`); | |
| 455 | expect(backField).toBe(at); | |
| 456 | const commented = await post(action, { back: backField, body: "Looks good." }); | |
| 457 | expect(commented.status).toBe(303); | |
| 458 | expect(commented.headers.get("location")).toBe(`${at}#conversation`); | |
| 459 | const hostile = await post(action, { back: "//evil.example", body: "Still fine." }); | |
| 460 | expect(hostile.headers.get("location")).toBe(`${at}#conversation`); | |
| 461 | ||
| 462 | // A back that is not a path on this forge is ignored, never followed. | |
| 463 | for (const [i, back] of [ | |
| 464 | "//evil.example", | |
| 465 | "https://evil.example/", | |
| 466 | "/\\evil", | |
| 467 | "/ok\u0001path", | |
| 468 | ].entries()) { | |
| 469 | const third = await openGreen(`from-elsewhere-${i}`); | |
| 470 | const odd = await post(`/alice/notes/pulls/${third.number}/ship`, { back }); | |
| 471 | expect(odd.headers.get("location")).toBe("/alice/notes"); | |
| 472 | expect(getPull(app.db, repo.id, third.number)?.mergedAt).not.toBeNull(); | |
| 473 | } | |
| 474 | ||
| 475 | // Saying and closing stay put too. | |
| 476 | const fourth = await openGreen("said"); | |
| 477 | const said = await post(`/alice/notes/pulls/${fourth.number}/say`, { | |
| 478 | text: "Not quite.", | |
| 479 | back: "/asks", | |
| 480 | }); | |
| 481 | expect(said.headers.get("location")).toBe("/asks"); | |
| 482 | const closed = await post(`/alice/notes/pulls/${fourth.number}/state`, { | |
| 483 | state: "closed", | |
| 484 | back: "/asks", | |
| 485 | }); | |
| 486 | expect(closed.headers.get("location")).toBe("/asks"); | |
| 487 | ||
| 488 | // Failures stay put too: a bad reason and a refused merge both flash on | |
| 489 | // the page the decision was taken from. | |
| 490 | const badReason = await post(`/alice/notes/pulls/${fourth.number}/state`, { | |
| 491 | state: "closed", | |
| 492 | reason: "nonsense", | |
| 493 | back: "/asks", | |
| 494 | }); | |
| 495 | expect(badReason.headers.get("location")).toBe("/asks"); | |
| 496 | const badFlash = badReason.headers.get("set-cookie")?.split(";")[0] ?? ""; | |
| 497 | expect(await (await get("/asks", { cookie: `${cookie}; ${badFlash}` })).text()).toContain( | |
| 498 | "Close as done, dropped, or split", | |
| 499 | ); | |
| 500 | const refused = await post(`/alice/notes/pulls/${fourth.number}/ship`, { | |
| 501 | back: "/asks", | |
| 502 | }); | |
| 503 | expect(refused.headers.get("location")).toBe("/asks"); | |
| 504 | expect(refused.headers.get("set-cookie")).toContain("forge_flash"); | |
| 505 | }); | |
| 506 | ||
| 401 | 507 | test("a tell shipped long ago still reads shipped once it is buried under 250 later events", async () => { |
| 402 | 508 | const told = openIssue(app, alice, repo, { |
| 403 | 509 | title: "Buried tell", |
Two meanings of
backnow exist:"board"in issues.ts:296 and a local path here. Unify them so the board form sends/boardand goes through this helper.