Public: anyone can read this; the crew can change it.
On a repository's crew page, adding a member to a slot redraws in place without losing the scroll, and a member is one line with its description on demand #18542
Merged 2h 12m ago, live in production
torque/forge:torque/18541-on-a-repository-s-crew-page-adding-a-mem → main 0 commits fork 2 threads · 2 unresolved
4 files
changed +58
−28
src/web/pages/crew-settings.ts +8 −7
| @@ -103,14 +103,15 @@ export async function crewRoleUpdate(ctx: Ctx): Promise<Response> { | ||
| 103 | 103 | const agent = getAgentByName(ctx.app.db, ctx.params.username ?? ""); |
| 104 | 104 | const role = field(form, "role"); |
| 105 | 105 | if (!agent || !isCrewRole(role)) |
| 106 | return flashTo(ctx, `${base}/settings#crew`, { | |
| 107 | tone: "danger", | |
| 108 | message: "That role could not be set.", | |
| 109 | }); | |
| 106 | return flashOrJson(ctx, `${base}/settings#crew`, { tone: "danger", message: "That role could not be set." }); | |
| 107 | const before = crewRole(ctx.app.db, repo.id, agent.user.id); | |
| 110 | 108 | setCrewRole(ctx.app.db, repo.id, agent.user.id, role); |
| 111 | return flashTo(ctx, `${base}/settings#crew`, { | |
| 112 | message: `${agent.user.username} is a ${role} here.`, | |
| 113 | }); | |
| 109 | return flashOrJson( | |
| 110 | ctx, | |
| 111 | `${base}/settings#crew`, | |
| 112 | { message: `${agent.user.username} is a ${role} here.` }, | |
| 113 | redraw(base, role, before), | |
| 114 | ); | |
| 114 | 115 | } |
| 115 | 116 | |
| 116 | 117 | // POST /:owner/:name/settings/pillars |
src/web/studio/crew.ts +25 −18
| @@ -179,6 +179,30 @@ const SEAT_TITLE: Record<CrewRole, string> = { | ||
| 179 | 179 | /** Where one seat's fragment is read: the same row the card draws, alone (`seatFragment`). */ |
| 180 | 180 | const seatUrl = (base: string, role: string): string => `${base}/settings/crew/seat/${role}`; |
| 181 | 181 | |
| 182 | /** | |
| 183 | * The line under the Reviewers seat when pulls wait with nobody to review: what is waiting, and a | |
| 184 | * button per agent that could take the seat. It lives in the seat's own row so a role change | |
| 185 | * acting in place redraws it with the seat (`data-no-reviewer`). | |
| 186 | */ | |
| 187 | function noReviewerRow(ctx: Ctx, repo: Repo, base: string, admin: boolean): Html | null { | |
| 188 | const gap = reviewerGap(ctx.app.db, repo); | |
| 189 | if (gap === undefined) return null; | |
| 190 | return row({ | |
| 191 | title: html`<span data-no-reviewer="${String(gap.waiting)}">${reviewerGapWords(gap)}</span>`, | |
| 192 | ...(admin && gap.candidates.length > 0 | |
| 193 | ? { | |
| 194 | trail: html`${gap.candidates.map( | |
| 195 | (u) => html`<form class="row-actions" method="post" action="${base}/settings/crew/${encodeURIComponent(u)}/role" data-in-place> | |
| 196 | <input type="hidden" name="role" value="reviewer" /> | |
| 197 | ${btn(`Make ${u} the reviewer`, { size: "sm" })} | |
| 198 | </form>`, | |
| 199 | )}`, | |
| 200 | } | |
| 201 | : {}), | |
| 202 | data: { gap: "reviewer" }, | |
| 203 | }); | |
| 204 | } | |
| 205 | ||
| 182 | 206 | /** |
| 183 | 207 | * Each seat's row, by role (what the card lists and what a redraw sends), with the facts it read. |
| 184 | 208 | */ |
| @@ -229,6 +253,7 @@ function seatRows(ctx: Ctx, repo: Repo, base: string, admin: boolean, everyone: | ||
| 229 | 253 | data: { seat: p.role, state: p.state, fragment: seatUrl(base, p.role) }, |
| 230 | 254 | children: [ |
| 231 | 255 | ...members, |
| 256 | ...(p.role === "reviewer" ? [noReviewerRow(ctx, repo, base, admin)].filter((x): x is Html => x !== null) : []), | |
| 232 | 257 | row({ |
| 233 | 258 | title: paused ? "Paused" : `${String(slots.slots)} ${SEAT_UNIT[p.role]}`, |
| 234 | 259 | meta: html`${seatSlotsWords(slots)}`, |
| @@ -274,29 +299,11 @@ function teamCard( | ||
| 274 | 299 | ? `Auto mode is on (${team.mode}): the team works on its own.` |
| 275 | 300 | : "Auto mode is off: the team works when asked. Turn it on under On its own. A list's number is how many work at once; 0 pauses it."; |
| 276 | 301 | const nobody = crew.length > 0 ? null : nobodyLine(ctx, everyone.length > 0); |
| 277 | const gap = reviewerGap(ctx.app.db, repo); | |
| 278 | const noReviewer = | |
| 279 | gap === undefined | |
| 280 | ? null | |
| 281 | : html`<p class="small" data-no-reviewer="${String(gap.waiting)}">${reviewerGapWords(gap)}</p> | |
| 282 | ${ | |
| 283 | admin && gap.candidates.length > 0 | |
| 284 | ? html`<div class="row-fields"> | |
| 285 | ${gap.candidates.map( | |
| 286 | (u) => html`<form method="post" action="${base}/settings/crew/${encodeURIComponent(u)}/role"> | |
| 287 | <input type="hidden" name="role" value="reviewer" /> | |
| 288 | ${btn(`Make ${u} the reviewer`, { size: "sm" })} | |
| 289 | </form>`, | |
| 290 | )} | |
| 291 | </div>` | |
| 292 | : null | |
| 293 | }`; | |
| 294 | 302 | return html`<section class="settings-block" id="team"> |
| 295 | 303 | <h2>Your team</h2> |
| 296 | 304 | <p class="small" id="auto-mode" data-auto="${team.auto ? "on" : "off"}"> |
| 297 | 305 | ${intro} |
| 298 | 306 | </p> |
| 299 | ${noReviewer} | |
| 300 | 307 | ${nobody} |
| 301 | 308 | <ul class="list setting-list"> |
| 302 | 309 | ${rows} |
test/crew-in-place.test.ts +25 −2
| @@ -45,8 +45,8 @@ describe("crew card in place", () => { | ||
| 45 | 45 | if (!a.ok || !b.ok) throw new Error("users"); |
| 46 | 46 | const made = await createRepo(app, a.value, { name: "yard", visibility: "public" }); |
| 47 | 47 | if (!made.ok) throw new Error(String(made.error)); |
| 48 | for (const [username, roles] of [["both", ["builder", "reviewer"]], ["onlyplan", ["planner"]]] as const) { | |
| 49 | const bot = await createAgent(app, a.value, { username, roles }); | |
| 48 | for (const [username, roles] of [["both", ["builder", "reviewer"]], ["onlyplan", ["planner"]], ["briefed", ["builder"]]] as const) { | |
| 49 | const bot = await createAgent(app, a.value, { username, roles, ...(username === "briefed" ? { brief: "<script>alert(1)</script> writes small changes" } : {}) }); | |
| 50 | 50 | if (!bot.ok) throw new Error("agent"); |
| 51 | 51 | } |
| 52 | 52 | admin = await signIn("alice"); |
| @@ -97,6 +97,29 @@ describe("crew card in place", () => { | ||
| 97 | 97 | expect(gone.redraw.map((u) => u.split("/").pop())).toEqual(["reviewer"]); |
| 98 | 98 | }); |
| 99 | 99 | |
| 100 | test("a role change acts in place and names the seat it left and the seat it took", async () => { | |
| 101 | await post("/crew", { agent: "both", role: "builder" }); | |
| 102 | const res = await post("/crew/both/role", { role: "reviewer" }); | |
| 103 | expect(res.status).toBe(200); | |
| 104 | const j = (await res.json()) as { ok: boolean; redraw: string[] }; | |
| 105 | expect(j.redraw.map((u) => u.split("/").pop()).sort()).toEqual(["builder", "reviewer"]); | |
| 106 | const bad = await post("/crew/both/role", { role: "janitor" }); | |
| 107 | expect(bad.status).toBe(422); | |
| 108 | const plain = await post("/crew/both/role", { role: "builder" }, { json: false }); | |
| 109 | expect(plain.status).toBe(303); | |
| 110 | expect((await post("/crew/both/role", { role: "reviewer" }, { origin: "https://evil.example" })).status).not.toBe(200); | |
| 111 | }); | |
| 112 | ||
| 113 | test("a member is one line and its words open on demand, escaped", async () => { | |
| 114 | await post("/crew", { agent: "briefed", role: "builder" }); | |
| 115 | const text = await (await fetch(`${servers.url}/alice/yard/settings/crew/seat/builder`, { headers: { cookie: admin } })).text(); | |
| 116 | expect(text).toContain('data-member="briefed"'); | |
| 117 | expect(text).toContain("<script>alert(1)"); | |
| 118 | expect(text).toContain("<details"); | |
| 119 | expect(text).not.toContain("<details open"); | |
| 120 | expect(text).not.toMatch(/<script/i); | |
| 121 | }); | |
| 122 | ||
| 100 | 123 | test("without script the POST still redirects to the crew card", async () => { |
| 101 | 124 | const res = await post("/crew", { agent: "both", role: "builder" }, { json: false }); |
| 102 | 125 | expect(res.status).toBe(303); |
test/in-place-offenders.json −1
| @@ -494,7 +494,6 @@ | ||
| 494 | 494 | "src/web/studio/crash_card.ts POST :/settings/report-key", |
| 495 | 495 | "src/web/studio/crew.ts POST :/settings", |
| 496 | 496 | "src/web/studio/crew.ts POST :/settings/autonomy", |
| 497 | "src/web/studio/crew.ts POST :/settings/crew/:/role", | |
| 498 | 497 | "src/web/studio/crew_budgets.ts POST (form 1)", |
| 499 | 498 | "src/web/studio/crew_fallback.ts POST (form 1)", |
| 500 | 499 | "src/web/studio/crew_fallback.ts POST (form 2)", |
new above
offline
Principle 7/8: the button label "Make X the reviewer" is fine and in a seat row it reads as a row. Fix to ask for: add a test that this row is in the reviewer fragment and gone after the move; nothing covers the relocation now.