Public: anyone can read this; the crew can change it.
Talk's crew line shows a guest only work they stand in (#16487) #16488
Check · Review · Land · Live done — Landed and live in production.
fix/talk-crew-line-readable → main 0 commits
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` | ||
| 46 | 46 | |
| 47 | 47 | ## The crew's line |
| 48 | 48 | |
| 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`. | |
| 50 | 50 | |
| 51 | 51 | ## Naming the subject: `?about=` and `--about` |
| 52 | 52 |
src/actions/crew_now.ts +13 −3
| @@ -8,7 +8,8 @@ import { mayViewId } from "../core/sealed.ts"; | ||
| 8 | 8 | import { getIssueById, listOpenAgentPullsVisibleTo } from "../core/issues.ts"; |
| 9 | 9 | import { reviewWaitsFor } from "../crew/review.ts"; |
| 10 | 10 | 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"; | |
| 12 | 13 | import { reviewSays } from "../crew/review_says.ts"; |
| 13 | 14 | import { reviewerPaused } from "../crew/reviewer_paused.ts"; |
| 14 | 15 | import { plannerDeclines } from "../crew/autonomy.ts"; |
| @@ -51,9 +52,18 @@ function liveRuns(ctx: Pick<Ctx, "app">, user: User) { | ||
| 51 | 52 | return { repos, byId, live }; |
| 52 | 53 | } |
| 53 | 54 | |
| 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 | */ | |
| 55 | 62 | 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); | |
| 57 | 67 | } |
| 58 | 68 | |
| 59 | 69 | /** 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 | ||
| 1493 | 1493 | return repo.contributed && user !== undefined && user.kind === "user" && isActive(user) && isContributor(db, repo.id, user.id); |
| 1494 | 1494 | } |
| 1495 | 1495 | |
| 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 | ||
| 1496 | 1505 | /** The repositories `userId` contributes to. */ |
| 1497 | 1506 | function contributorRepoIds(db: Database, userId: string): Set<string> { |
| 1498 | 1507 | return new Set( |
test/talk-crew-now.test.ts +32 −3
| @@ -2,6 +2,9 @@ | ||
| 2 | 2 | * /talk shows the crew's live work in one server-rendered line above the box, and says the crew |
| 3 | 3 | * is idle when no run is live (#13970). |
| 4 | 4 | */ |
| 5 | import { setMember } from "../src/core/roles.ts"; | |
| 6 | import { inviteContributor } from "../src/actions/invites.ts"; | |
| 7 | import { getRepoById } from "../src/core/repos.ts"; | |
| 5 | 8 | import { afterAll, beforeAll, describe, expect, test } from "bun:test"; |
| 6 | 9 | import { mkdtemp, rm } from "node:fs/promises"; |
| 7 | 10 | import { tmpdir } from "node:os"; |
| @@ -30,6 +33,7 @@ describe("/talk crew line", () => { | ||
| 30 | 33 | let repoId: string; |
| 31 | 34 | let userId: string; |
| 32 | 35 | let bobCookie: string; |
| 36 | let bobId: string; | |
| 33 | 37 | const talk = async (c = cookie) => (await fetch(`${servers.url}/talk`, { headers: { cookie: c } })).text(); |
| 34 | 38 | const line = (h: string) => /<p class="talk-crew[^>]*>([^<]*)<\/p>/.exec(h)?.[1]; |
| 35 | 39 | |
| @@ -49,6 +53,7 @@ describe("/talk crew line", () => { | ||
| 49 | 53 | origin: "seed", trusted: true, username: "bob", email: "[email protected]", password: "a-good-passphrase", |
| 50 | 54 | }); |
| 51 | 55 | if (!bob.ok) throw new Error(bob.error); |
| 56 | bobId = bob.value.id; | |
| 52 | 57 | bobCookie = `forge_session=${createSession(app.db, bob.value.id).token}`; |
| 53 | 58 | }); |
| 54 | 59 | afterAll(async () => { |
| @@ -85,8 +90,30 @@ describe("/talk crew line", () => { | ||
| 85 | 90 | createRun(app.db, { repoId, kind: "agent", issueId: issue.value.id, reason: "work" }); |
| 86 | 91 | const text = line(await talk()); |
| 87 | 92 | 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."); | |
| 90 | 117 | }); |
| 91 | 118 | |
| 92 | 119 | test("the terminal prints the same line: `talk /crew`", () => { |
| @@ -103,7 +130,9 @@ describe("/talk crew line", () => { | ||
| 103 | 130 | return out; |
| 104 | 131 | }; |
| 105 | 132 | 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"); | |
| 107 | 136 | expect(run(undefined)).toBe(`${CREW_IDLE}\r\n`); |
| 108 | 137 | }); |
| 109 | 138 |
new above
offline