Public: anyone can read this; the crew can change it.

Talk's crew line shows a guest only work they stand in (#16487) #16488

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

fix/talk-crew-line-readable → main 0 commits

  • Merged. fix/talk-crew-line-readable was merged into main as bc6b43a.

Review

Sign in to review this change.
4 files changed +55 −7
docs/features/talk.md +1 −1
@@ -46,7 +46,7 @@ A tool call is stored once its result is known (`src/crew/conversation_calls.ts`
4646
4747 ## The crew's line
4848
49 `/talk` shows one line at the end of the thread, only while a run is live (idle is silence on the page, #15734), from the live runs only (`liveCrewRows` in `src/actions/crew_now.ts`, with `crewNow`'s visibility filters but none of its planner or review-wait reads, so the common request stays fast): "The crew is working: <who> on <what>" (with the count first when several, "(3)") while an agent run is live. It is rendered with the page, never polled, one line that clips with an ellipsis. The terminal twin is `ssh <forge> talk /crew`, which prints the same line (`crewLine()` in `src/web/crew_now.ts`); signed out it says the crew is idle.
49 `/talk` shows one line at the end of the thread, only while a run is live (idle is silence on the page, #15734), from the live runs only (`liveCrewRows` in `src/actions/crew_now.ts`, with `crewNow`'s visibility filters but none of its planner or review-wait reads, so the common request stays fast): "The crew is working: <who> on <what>" (with the count first when several, "(3)") while an agent run is live. It is rendered with the page, never polled, one line that clips with an ellipsis. The terminal twin is `ssh <forge> talk /crew`, which prints the same line (`crewLine()` in `src/web/crew_now.ts`, called from `src/tui/ssh-talk.ts`); signed out it says the crew is idle. The line is the viewer's crew: a guest hears only of repositories they stand in (their own, as a contributor, or through an organisation: `readsByStanding` in `src/core/repos.ts`), never of a public one they can merely see, so the owner's work never sits on a visiting guest's Talk; a member of the forge follows its crew (#16487). Proof: `test/talk-crew-now.test.ts`.
5050
5151 ## Naming the subject: `?about=` and `--about`
5252
src/actions/crew_now.ts +13 −3
@@ -8,7 +8,8 @@ import { mayViewId } from "../core/sealed.ts";
88 import { getIssueById, listOpenAgentPullsVisibleTo } from "../core/issues.ts";
99 import { reviewWaitsFor } from "../crew/review.ts";
1010 import { joinMany } from "../core/pulls.ts";
11 import { ownerFactRepoIds } from "../core/repos.ts";
11 import { ownerFactRepoIds, readsByStanding } from "../core/repos.ts";
12 import { roleOf } from "../core/roles.ts";
1213 import { reviewSays } from "../crew/review_says.ts";
1314 import { reviewerPaused } from "../crew/reviewer_paused.ts";
1415 import { plannerDeclines } from "../crew/autonomy.ts";
@@ -51,9 +52,18 @@ function liveRuns(ctx: Pick<Ctx, "app">, user: User) {
5152 return { repos, byId, live };
5253 }
5354
54 /** Who works on what, for the live runs only: the rows `crewLine` words. */
55 /**
56 * Who works on what, for the live runs only: the rows `crewLine` words on Talk's start (the page
57 * and `ssh talk /crew`). It is the viewer's crew: a guest hears only of repositories they stand
58 * in (`readsByStanding`), never of a public one they can merely see, as the owner's runs on the
59 * forge's own repository were on a visiting guest's Talk (#16487). A member follows the forge's.
60 * The runs a stranger may read stay readable where asked for (`now`, GET /api/v1/crew/now).
61 */
5562 export function liveCrewRows(ctx: Pick<Ctx, "app">, user: User) {
56 return liveRuns(ctx, user).live.map((l) => l.row);
63 const guest = user.kind === "user" && roleOf(ctx.app.db, user) === "guest";
64 return liveRuns(ctx, user)
65 .live.filter((l) => !guest || readsByStanding(ctx.app.db, l.repo, user))
66 .map((l) => l.row);
5767 }
5868
5969 /** Rows of the crew's work as `user` may see them (none for no one). */
src/core/repos.ts +9
@@ -1493,6 +1493,15 @@ export function contributes(db: Database, repo: Repo, user: User | undefined): b
14931493 return repo.contributed && user !== undefined && user.kind === "user" && isActive(user) && isContributor(db, repo.id, user.id);
14941494 }
14951495
1496 /**
1497 * Whether `user` reads `repo` by a standing of their own: its owner, the forge's admin, its crew,
1498 * a contributor, or a reader through its organisation. A public repository's reading by anyone is
1499 * not standing: a guest who merely can see it is not told what its crew is doing (#16487).
1500 */
1501 export function readsByStanding(db: Database, repo: Repo, user: User | undefined): boolean {
1502 return personalOrDirect(repo, user) || onCrew(db, repo, user) || contributes(db, repo, user) || accessAllows(orgAccessFor(db, repo, user), "read");
1503 }
1504
14961505 /** The repositories `userId` contributes to. */
14971506 function contributorRepoIds(db: Database, userId: string): Set<string> {
14981507 return new Set(
test/talk-crew-now.test.ts +32 −3
@@ -2,6 +2,9 @@
22 * /talk shows the crew's live work in one server-rendered line above the box, and says the crew
33 * is idle when no run is live (#13970).
44 */
5 import { setMember } from "../src/core/roles.ts";
6 import { inviteContributor } from "../src/actions/invites.ts";
7 import { getRepoById } from "../src/core/repos.ts";
58 import { afterAll, beforeAll, describe, expect, test } from "bun:test";
69 import { mkdtemp, rm } from "node:fs/promises";
710 import { tmpdir } from "node:os";
@@ -30,6 +33,7 @@ describe("/talk crew line", () => {
3033 let repoId: string;
3134 let userId: string;
3235 let bobCookie: string;
36 let bobId: string;
3337 const talk = async (c = cookie) => (await fetch(`${servers.url}/talk`, { headers: { cookie: c } })).text();
3438 const line = (h: string) => /<p class="talk-crew[^>]*>([^<]*)<\/p>/.exec(h)?.[1];
3539
@@ -49,6 +53,7 @@ describe("/talk crew line", () => {
4953 origin: "seed", trusted: true, username: "bob", email: "[email protected]", password: "a-good-passphrase",
5054 });
5155 if (!bob.ok) throw new Error(bob.error);
56 bobId = bob.value.id;
5257 bobCookie = `forge_session=${createSession(app.db, bob.value.id).token}`;
5358 });
5459 afterAll(async () => {
@@ -85,8 +90,30 @@ describe("/talk crew line", () => {
8590 createRun(app.db, { repoId, kind: "agent", issueId: issue.value.id, reason: "work" });
8691 const text = line(await talk());
8792 expect(text).toStartWith("The crew is working (3):");
88 // A public app's run on a plain issue is the non-member's to see.
89 expect(line(await talk(bobCookie))).toBe("The crew is working: the crew on #2 round the corners.");
93 // A guest who can merely see the public repository hears nothing of its crew on their Talk
94 // (#16487); made a member of the forge, they follow its crew like anyone on it.
95 expect(line(await talk(bobCookie))).toBe("");
96 setMember(app.db, bobId, true, userId, new Date());
97 try {
98 expect(line(await talk(bobCookie))).toBe("The crew is working: the crew on #2 round the corners.");
99 } finally {
100 setMember(app.db, bobId, false, userId, new Date());
101 }
102 });
103
104 test("a guest who contributes to the repository hears of its crew there, and only there (#16487)", async () => {
105 const ada = getUserById(app.db, userId)!;
106 const other = await createRepo(app, ada, { name: "garden", visibility: "public" });
107 if (!other.ok) throw new Error(String(other.error));
108 createAppRecord(app.db, { repoId: other.value.id, slug: "garden", access: "public" });
109 const made = createIssue(app.db, { repoId: other.value.id, authorId: userId, title: "water the beans" });
110 if (!made.ok) throw new Error("issue");
111 createRun(app.db, { repoId: other.value.id, kind: "agent", issueId: made.value.id, reason: "work" });
112 expect(line(await talk(bobCookie))).toBe("");
113 const bob = getUserById(app.db, bobId)!;
114 const invited = inviteContributor(app, ada, getRepoById(app.db, other.value.id)!, bob.username);
115 if (!invited.ok) throw new Error(String(invited.error));
116 expect(line(await talk(bobCookie))).toBe("The crew is working: the crew on #1 water the beans.");
90117 });
91118
92119 test("the terminal prints the same line: `talk /crew`", () => {
@@ -103,7 +130,9 @@ describe("/talk crew line", () => {
103130 return out;
104131 };
105132 const ada = getUserById(app.db, userId);
106 expect(run(ada)).toStartWith("The crew is working (3):");
133 expect(run(ada)).toStartWith("The crew is working (4):");
134 // The same rule: bob, a guest contributing to garden only, hears of garden's crew alone.
135 expect(run(getUserById(app.db, bobId))).toBe("The crew is working: the crew on #1 water the beans.\r\n");
107136 expect(run(undefined)).toBe(`${CREW_IDLE}\r\n`);
108137 });
109138

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs