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

opened this

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

  • Merged. torque/18541-on-a-repository-s-crew-page-adding-a-mem was merged into main as 5a6b787.

Review

Sign in to review this change.
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> {
103103 const agent = getAgentByName(ctx.app.db, ctx.params.username ?? "");
104104 const role = field(form, "role");
105105 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);
110108 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 );
114115 }
115116
116117 // POST /:owner/:name/settings/pillars
src/web/studio/crew.ts +25 −18
@@ -179,6 +179,30 @@ const SEAT_TITLE: Record<CrewRole, string> = {
179179 /** Where one seat's fragment is read: the same row the card draws, alone (`seatFragment`). */
180180 const seatUrl = (base: string, role: string): string => `${base}/settings/crew/seat/${role}`;
181181
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" />

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.

197 ${btn(`Make ${u} the reviewer`, { size: "sm" })}
198 </form>`,
199 )}`,
200 }
201 : {}),
202 data: { gap: "reviewer" },
203 });
204 }
205
182206 /**
183207 * Each seat's row, by role (what the card lists and what a redraw sends), with the facts it read.
184208 */
@@ -229,6 +253,7 @@ function seatRows(ctx: Ctx, repo: Repo, base: string, admin: boolean, everyone:
229253 data: { seat: p.role, state: p.state, fragment: seatUrl(base, p.role) },
230254 children: [
231255 ...members,
256 ...(p.role === "reviewer" ? [noReviewerRow(ctx, repo, base, admin)].filter((x): x is Html => x !== null) : []),
232257 row({
233258 title: paused ? "Paused" : `${String(slots.slots)} ${SEAT_UNIT[p.role]}`,
234259 meta: html`${seatSlotsWords(slots)}`,
@@ -274,29 +299,11 @@ function teamCard(
274299 ? `Auto mode is on (${team.mode}): the team works on its own.`
275300 : "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.";
276301 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 }`;
294302 return html`<section class="settings-block" id="team">
295303 <h2>Your team</h2>
296304 <p class="small" id="auto-mode" data-auto="${team.auto ? "on" : "off"}">
297305 ${intro}
298306 </p>
299 ${noReviewer}
300307 ${nobody}
301308 <ul class="list setting-list">
302309 ${rows}
test/crew-in-place.test.ts +25 −2
@@ -45,8 +45,8 @@ describe("crew card in place", () => {
4545 if (!a.ok || !b.ok) throw new Error("users");
4646 const made = await createRepo(app, a.value, { name: "yard", visibility: "public" });
4747 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" } : {}) });
5050 if (!bot.ok) throw new Error("agent");
5151 }
5252 admin = await signIn("alice");
@@ -97,6 +97,29 @@ describe("crew card in place", () => {
9797 expect(gone.redraw.map((u) => u.split("/").pop())).toEqual(["reviewer"]);
9898 });
9999
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("&lt;script&gt;alert(1)");
118 expect(text).toContain("<details");
119 expect(text).not.toContain("<details open");
120 expect(text).not.toMatch(/<script/i);
121 });
122
100123 test("without script the POST still redirects to the crew card", async () => {
101124 const res = await post("/crew", { agent: "both", role: "builder" }, { json: false });
102125 expect(res.status).toBe(303);
test/in-place-offenders.json −1
@@ -494,7 +494,6 @@
494494 "src/web/studio/crash_card.ts POST :/settings/report-key",
495495 "src/web/studio/crew.ts POST :/settings",
496496 "src/web/studio/crew.ts POST :/settings/autonomy",
497 "src/web/studio/crew.ts POST :/settings/crew/:/role",
498497 "src/web/studio/crew_budgets.ts POST (form 1)",

Box 3 is not met: the crew page's own forms (studio/crew.ts /settings, /settings/autonomy, and the crew_budgets, crew_fallback and crew_key forms) are still listed. Move them in place and remove these entries.

499498 "src/web/studio/crew_fallback.ts POST (form 1)",
500499 "src/web/studio/crew_fallback.ts POST (form 2)",

Search
↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs