Public: anyone can read this; the crew can change it.
/apps asks private-app access once per row: one grouped read, and the N+1 test green again #1012
scout/forge:scout/869-apps-asks-private-app-access-once-per-ro → main 1 commit fork
3 files
changed +29
−6
src/web/studio/shelf.ts +2
| @@ -217,6 +217,8 @@ export async function shelfRows( | ||
| 217 | 217 | record, |
| 218 | 218 | history, |
| 219 | 219 | viewer: ctx.auth.user, |
| 220 | // Only an enterable app (or a plain repository) reaches this far. | |
| 221 | enterable: true, | |
| 220 | 222 | }; |
| 221 | 223 | const agentWord = |
| 222 | 224 | useOpenPull || latest === undefined |
src/web/studio/words.ts +11 −6
| @@ -86,6 +86,9 @@ export interface WordCtx { | ||
| 86 | 86 | readonly history: ServingHistory; |
| 87 | 87 | /** Who is reading: a private app's production is theirs only if they may enter it. */ |
| 88 | 88 | readonly viewer: User | undefined; |
| 89 | /** The page's own grouped answer to "may the viewer enter this app?" | |
| 90 | * (`enterableApps`); when set, a word does not ask again per row. */ | |
| 91 | readonly enterable?: boolean; | |
| 89 | 92 | } |
| 90 | 93 | |
| 91 | 94 | /** |
| @@ -195,12 +198,14 @@ export async function pullWord( | ||
| 195 | 198 | return { word: "shipped", note: "merged" }; |
| 196 | 199 | // A private app's production — its state, its deploy's error — is for |
| 197 | 200 | // those who may enter it (`canEnterApp`); anyone else reads "merged". |
| 198 | const repo = getRepoById(ctx.db, ctx.record.repoId); | |
| 199 | if ( | |
| 200 | repo === undefined || | |
| 201 | !canEnterApp(ctx.db, repo, ctx.record, ctx.viewer, { named: false }) | |
| 202 | ) | |
| 203 | return { word: "shipped", note: "merged" }; | |
| 201 | if (ctx.enterable === undefined) { | |
| 202 | const repo = getRepoById(ctx.db, ctx.record.repoId); | |
| 203 | if ( | |
| 204 | repo === undefined || | |
| 205 | !canEnterApp(ctx.db, repo, ctx.record, ctx.viewer, { named: false }) | |
| 206 | ) | |
| 207 | return { word: "shipped", note: "merged" }; | |
| 208 | } else if (!ctx.enterable) return { word: "shipped", note: "merged" }; | |
| 204 | 209 | const production = ctx.runtime |
| 205 | 210 | .status(ctx.record) |
| 206 | 211 | .find((e) => e.env === "production"); |
test/private-app.test.ts +16
| @@ -343,6 +343,22 @@ describe("a private app on a public repository stays private", () => { | ||
| 343 | 343 | expect(await pullWord(ctxFor(carol), merged)).toEqual({ word: "shipped", note: "merged" }); |
| 344 | 344 | expect(await pullWord(ctxFor(undefined), merged)).toEqual({ word: "shipped", note: "merged" }); |
| 345 | 345 | expect((await pullWord(ctxFor(alice), merged)).note).toBe("production is serving it"); |
| 346 | // The page's grouped answer stands in for the per-row ask: no query, | |
| 347 | // and a "no" still tells a reader only that it merged. | |
| 348 | const quiet = { ...ctxFor(alice), enterable: true }; | |
| 349 | const query = app.db.query.bind(app.db); | |
| 350 | let asked = 0; | |
| 351 | (app.db as any).query = (sql: string) => (asked++, query(sql)); | |
| 352 | try { | |
| 353 | expect((await pullWord(quiet, merged)).note).toBe("production is serving it"); | |
| 354 | } finally { | |
| 355 | (app.db as any).query = query; | |
| 356 | } | |
| 357 | expect(asked).toBe(0); | |
| 358 | expect(await pullWord({ ...ctxFor(alice), enterable: false }, merged)).toEqual({ | |
| 359 | word: "shipped", | |
| 360 | note: "merged", | |
| 361 | }); | |
| 346 | 362 | }); |
| 347 | 363 | |
| 348 | 364 | test("the MCP's now and the tell page show a private app's runs only to those who may enter it", async () => { |
new above
offline