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

Closed opened this in answer to
Closed without merging

scout/forge:scout/869-apps-asks-private-app-access-once-per-ro → main 1 commit fork

  • Closed without merging. Nothing was applied to main.

Review

Sign in to review this change.
3 files changed +29 −6
src/web/studio/shelf.ts +2
@@ -217,6 +217,8 @@ export async function shelfRows(
217217 record,
218218 history,
219219 viewer: ctx.auth.user,
220 // Only an enterable app (or a plain repository) reaches this far.
221 enterable: true,
220222 };
221223 const agentWord =
222224 useOpenPull || latest === undefined
src/web/studio/words.ts +11 −6
@@ -86,6 +86,9 @@ export interface WordCtx {
8686 readonly history: ServingHistory;
8787 /** Who is reading: a private app's production is theirs only if they may enter it. */
8888 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;
8992 }
9093
9194 /**
@@ -195,12 +198,14 @@ export async function pullWord(
195198 return { word: "shipped", note: "merged" };
196199 // A private app's production — its state, its deploy's error — is for
197200 // 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" };
204209 const production = ctx.runtime
205210 .status(ctx.record)
206211 .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", () => {
343343 expect(await pullWord(ctxFor(carol), merged)).toEqual({ word: "shipped", note: "merged" });
344344 expect(await pullWord(ctxFor(undefined), merged)).toEqual({ word: "shipped", note: "merged" });
345345 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 });
346362 });
347363
348364 test("the MCP's now and the tell page show a private app's runs only to those who may enter it", async () => {

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs