Skip to content

Commit 6af3d29

Browse files
test(dogfood): re-point the runAs and anonymous-guest flow pins to flow start admission's record rule (#29451)
<!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi97CjkpAhpM1mjM36Rm8Fvqz)_ Fixes #29426 ## 维护者速读 - 改了什么:只改两个 dogfood 测试文件和一个测试 fixture,让它们按 #29365 已落地的规则断言;运行时代码一行未动。 - 为什么改:#29365 之后 main 的 Dogfood Regression Gate 一直红,这四个用例断言的是该规则有意改掉的旧行为(dogfood 分片在 PR 和合并队列里不跑,所以落地前没暴露)。 - 风险与回滚:仅测试面,无发布内容(skip-changeset);回滚即 revert 本 PR,main 会重新变红。 - 先看:`packages/qa/dogfood/test/fixtures/flow-runas-fixture.ts`(新增只读策略与"定义自选行"的读流程)、`packages/qa/dogfood/test/flow-runas.dogfood.test.ts`(拒收断言与读写提权证明)、`packages/qa/dogfood/test/declarative-endpoint-anonymous-guest.dogfood.test.ts`。 - 两分钟验证:构建 dogfood 依赖闭包后运行 `cd packages/qa/dogfood && pnpm exec vitest run test/flow-runas.dogfood.test.ts test/declarative-endpoint-anonymous-guest.dogfood.test.ts`,预期 17/17 通过。 - 需要你做的:无,席位落地。 ## What changes The rule these pins now follow: **a start input the definition reads as a record id is judged as the caller, for every runAs, before the run exists (#29365).** Four dogfood cases asserted the behaviour that rule deliberately replaced. They are re-pointed, and the proofs they carried are kept with inputs the rule admits. `flow-runas-fixture.ts` (shared with `flow-runas-schedule.dogfood.test.ts`, which is unaffected): - A select-only RLS policy (`runas_note_shared_read`) makes an admin note whose `status` is `shared` readable to the member. No write policy admits it, so the member still cannot write it. - Three new flows: `runas_system_read_sealed`, `runas_user_read_sealed` and `runas_system_read_sealed_via_parent`. Their definition fixes the row with a literal `name` filter and takes no start input. - `viaParent` gains an option to hand no input. `flow-runas.dogfood.test.ts`: - **Write elevation and de-elevation** now use a shared admin note, which the member can read but not write. The `runAs: 'system'` child writes it. The `runAs: 'user'` run fails on its node with `400 FLOW_FAILED`. Because the member can read the row, the node's refusal is now the record layer's access refusal: `update_record(runas_note) failed` with `details.innerRefusal.code` `PERMISSION_DENIED`. It used to be the read door's not-found. - **Read elevation** now uses the sealed flows. The elevated run returns the admin note, and the user-mode run returns nothing. - New case: a member can read the note, and a read flow returns it under either runAs. - New precondition: the member can read a shared note but its direct write is refused. - **Re-pointed refusals** (two cases, write and read): a member start that hands an unreadable note id to the `runAs: 'system'` child (through the user-mode parent's `subflow`) or to the `runAs: 'user'` flow gets this full answer: - `404 RECORD_NOT_FOUND` in the ADR-0112 envelope; - no `data`, and no field of the note in the body (the id in the message is the caller's own input); - no run recorded for the started flow or its child; - the note unchanged. `declarative-endpoint-anonymous-guest.dogfood.test.ts`: - The executor-is-handed-the-guest pin now uses a start that names no row. Admission has nothing to load, so the executor is reached and the user-less `runAs: 'user'` refusal answers, as before. - New case: a guest start that names the seeded row gets `404 RECORD_NOT_FOUND` before the run exists. The executor is never called, the seeded row's name is not in the body, every engine call the door's load made carries the guest context (`principalKind: 'guest'`, `isSystem: false`), and the driver is never reached. Forced test edits (each one named): `memberTriggerExpectingAccessRefusal`'s message assertion (not-found → access refusal plus `innerRefusal.code`); the rows the four elevation and de-elevation legs use; the guest flow pin's start params (`{ noteId }` → `{}`). ## Tests All on head `b237bdc7b` (origin/main `f95d0dbad` merged in), with the dogfood closure rebuilt (`turbo run build --filter='./packages/**'`, 78/78), under `scripts/pm/os-verify-lock.sh`: - The two files: `cd packages/qa/dogfood && pnpm exec vitest run test/flow-runas.dogfood.test.ts test/declarative-endpoint-anonymous-guest.dogfood.test.ts` gives **17/17 passed**. On main `d93acbbe` before this change it gave 4 failed and 8 passed. - Every dogfood file that starts a flow or declares `runAs` (`grep -l "/automation/\|runAs" packages/qa/dogfood/test/*.test.ts`, 42 files, including `flow-runas-schedule`, which shares the fixture) gives **Test Files 42/42, Tests 428/428 passed**. - `pnpm --filter @objectstack/dogfood typecheck` exits 0. Root eslint `--no-inline-config` on the three files exits 0. <details><summary>Ablations (one per negative pin family; each leg mutated through scripts/ablation-replace.mjs, rebuilt, proved in dist/ by scripts/ablation-dist-preflight.mjs, restored and proved absent)</summary> 1. Flow start admission off (`refuseUnreadableFlowStartRecords` returns at once, `@objectstack/runtime`): **3 failed | 14 passed**. Red: both member refusal cases and the guest refusal case. Restored: `git diff HEAD` empty, marker absent from dist. 2. De-elevation off (`resolveRunDataContext` treats `runAs: 'user'` as `system`, `@objectstack/service-automation`): **2 failed | 15 passed**. Red: the user-mode write leg (no longer `400 FLOW_FAILED`) and the user-mode sealed read (returned the row). Restored the same way. </details> ## Acceptance notes - No runtime change. Every case is a test that asserted what #29365 changed on purpose. Its code and docs already settle each one: the rule covers user runs and inputs passed down through `subflow`, and the guest is judged like any other caller. - `skip-changeset`: the diff only touches `packages/qa/dogfood/test/**` (private package, publishes nothing). - The claim carries no `Clause-②:` / `Metadata-protocol:` lines, so none are written here. ## Verification - Gate readings for the 51 derived families, and their `--ran` reconciliation, are in the os-dev-report on #29426. - CI: the Dogfood Regression Gate runs on `main` only. These files are proven by the local runs above, and the first `main` push after merge confirms them. --- _Generated by [Claude Code](https://claude.ai/code/session_01ADHkmSoKQWHgd1oZe8j7Pu)_ Co-authored-by: Claude <noreply@anthropic.com>
1 parent cafe8ee commit 6af3d29

3 files changed

Lines changed: 207 additions & 27 deletions

File tree

‎packages/qa/dogfood/test/declarative-endpoint-anonymous-guest.dogfood.test.ts‎

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@
2121
// registered after boot runs last, right before the driver), and what the
2222
// caller is told (status, envelope, and that no byte of the row comes back).
2323
//
24+
// Flow start admission's third question (#29365) runs before the executor: a
25+
// start input the definition reads as a record id is judged as the caller, for
26+
// every runAs, before the run exists. The guest is a caller like any other
27+
// (`isSystem: false`), so a guest start naming a row it cannot read is refused
28+
// `404 RECORD_NOT_FOUND` and the executor is never asked; the executor pin
29+
// below uses a start that names no row.
30+
//
2431
// The fixture is inline and throwaway on purpose, like the policy fixture: it
2532
// exists only to be probed. Every anonymous endpoint carries the armed rate
2633
// limit ADR-0121 D6 makes its publish obligation, so booting at all is a
@@ -282,10 +289,12 @@ describe('[#22147] object_operation at authRequired:false — the anonymous requ
282289
describe('[#22147] flow at authRequired:false — the flow executor is handed the guest', () => {
283290
it('carries the guest position with no user and no elevation, and the run\'s data call never reaches the engine principal-less', async () => {
284291
resetProbes();
292+
// A start that names no row: flow start admission has nothing to load, so
293+
// the executor is reached and its own identity rule is what answers.
285294
const res = await stack.api('/apps/anonguest/read', {
286295
method: 'POST',
287296
headers: { 'content-type': 'application/json' },
288-
body: JSON.stringify({ params: { noteId: seededId } }),
297+
body: JSON.stringify({ params: {} }),
289298
});
290299
const text = await res.text();
291300

@@ -305,4 +314,27 @@ describe('[#22147] flow at authRequired:false — the flow executor is handed th
305314
expect(engineCalls).toEqual([]);
306315
expect(driverReached).toEqual([]);
307316
});
317+
318+
it('a guest start naming a row the guest cannot read is refused at the door as the guest — 404, no run, nothing disclosed', async () => {
319+
resetProbes();
320+
const res = await stack.api('/apps/anonguest/read', {
321+
method: 'POST',
322+
headers: { 'content-type': 'application/json' },
323+
body: JSON.stringify({ params: { noteId: seededId } }),
324+
});
325+
const text = await res.text();
326+
expect(res.status, text).toBe(404);
327+
const body = JSON.parse(text) as { success?: boolean; data?: unknown; error?: { code?: string } };
328+
expect(body.success).toBe(false);
329+
expect(body.error?.code).toBe('RECORD_NOT_FOUND');
330+
expect(body).not.toHaveProperty('data');
331+
expect(text).not.toContain(SEEDED_NAME);
332+
// Refused before the run exists: the executor was never asked.
333+
expect(flowContexts).toEqual([]);
334+
// The door's load of the row ran in the GUEST's scope — never principal-less,
335+
// never the system principal — and no security layer let it reach the driver.
336+
expect(engineCalls.length).toBeGreaterThan(0);
337+
for (const call of engineCalls) expectGuest(call.context);
338+
expect(driverReached).toEqual([]);
339+
});
308340
});

‎packages/qa/dogfood/test/fixtures/flow-runas-fixture.ts‎

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@
3434
// through a `runAs: 'user'` PARENT whose `subflow` node calls the elevated child
3535
// (`runas_system_touch_via_parent` / `runas_system_read_via_parent`). The
3636
// elevation the proof is about still belongs to the child; the parent adds none.
37+
//
38+
// Flow start admission's third question (#29365) judges every start input a
39+
// flow's definition reads as a record id (a CRUD node's `filter.id`, handed on
40+
// through `subflow`) in the CALLER's own scope, for every `runAs`, before the
41+
// run exists: an input the caller cannot read is refused 404 RECORD_NOT_FOUND.
42+
// So the proofs pick rows the rule admits:
43+
// • WRITE — an admin note marked `status: 'shared'`, which the member may
44+
// READ (a select-only policy) but still not WRITE (the owner policy): the
45+
// id passes the door, and the write is where the two `runAs` part ways.
46+
// • READ — `runas_<mode>_read_sealed`, whose definition fixes the row by a
47+
// literal (`SEALED_NOTE_NAME`), with no start input at all: the elevated
48+
// read sees an admin note the member cannot, the user-mode read does not.
3749

3850
import { defineStack } from '@objectstack/spec';
3951
import { ObjectSchema, Field } from '@objectstack/spec/data';
@@ -117,10 +129,48 @@ function readFlow(name: string, runAs: 'system' | 'user'): Flow {
117129
};
118130
}
119131

132+
/** The `name` of the admin note the sealed read flows fix by a literal. */
133+
export const SEALED_NOTE_NAME = 'runas-sealed-note';
134+
135+
/** The `status` that makes an admin note readable (never writable) to a member. */
136+
export const SHARED_STATUS = 'shared';
137+
138+
/**
139+
* `runas_<mode>_read_sealed` — start → get_record → end, where the DEFINITION
140+
* names the row (a literal `name` filter) and the start hands it nothing. The
141+
* read is the run's own choice of row, so it shows what the run's identity can
142+
* see, with no caller input for flow start admission to judge.
143+
*/
144+
function sealedReadFlow(name: string, runAs: 'system' | 'user'): Flow {
145+
return {
146+
name,
147+
label: `RunAs ${runAs} sealed read`,
148+
type: 'autolaunched',
149+
runAs,
150+
variables: [{ name: 'found', type: 'text', isOutput: true }],
151+
nodes: [
152+
{ id: 'start', type: 'start', label: 'Start' },
153+
{
154+
id: 'get',
155+
type: 'get_record',
156+
label: 'Get the sealed note',
157+
config: { objectName: 'runas_note', filter: { name: SEALED_NOTE_NAME }, outputVariable: 'found' },
158+
},
159+
{ id: 'end', type: 'end', label: 'End' },
160+
],
161+
edges: [
162+
{ id: 'e1', source: 'start', target: 'get' },
163+
{ id: 'e2', source: 'get', target: 'end' },
164+
],
165+
};
166+
}
167+
120168
export const runasSystemTouch = touchFlow('runas_system_touch', 'system', 'touched-system');
121169
export const runasUserTouch = touchFlow('runas_user_touch', 'user', 'touched-user');
122170
export const runasSystemRead = readFlow('runas_system_read', 'system');
123171
export const runasUserRead = readFlow('runas_user_read', 'user');
172+
export const runasSystemReadSealed = sealedReadFlow('runas_system_read_sealed', 'system');
173+
export const runasUserReadSealed = sealedReadFlow('runas_user_read_sealed', 'user');
124174

125175
/**
126176
* `<child>_via_parent` — start → subflow(child) → end, under `runAs: 'user'`:
@@ -129,14 +179,14 @@ export const runasUserRead = readFlow('runas_user_read', 'user');
129179
* land on the parent's `found` output (so a read child's own `found` arrives as
130180
* `output.found.found` on the trigger response).
131181
*/
132-
function viaParent(child: Flow, withOutput: boolean): Flow {
182+
function viaParent(child: Flow, withOutput: boolean, handsNoteId = true): Flow {
133183
return {
134184
name: `${child.name}_via_parent`,
135185
label: `${child.label} (via a user-mode parent)`,
136186
type: 'autolaunched',
137187
runAs: 'user',
138188
variables: [
139-
{ name: 'noteId', type: 'text', isInput: true },
189+
...(handsNoteId ? [{ name: 'noteId', type: 'text', isInput: true }] : []),
140190
...(withOutput ? [{ name: 'found', type: 'object', isOutput: true }] : []),
141191
],
142192
nodes: [
@@ -148,7 +198,7 @@ function viaParent(child: Flow, withOutput: boolean): Flow {
148198
config: {
149199
flowName: child.name,
150200
// `input.*` is a value slot (#19939): the parent's own input, as a CEL envelope.
151-
input: { noteId: { dialect: 'cel', source: 'noteId' } },
201+
input: handsNoteId ? { noteId: { dialect: 'cel', source: 'noteId' } } : {},
152202
...(withOutput ? { outputVariable: 'found' } : {}),
153203
},
154204
},
@@ -163,6 +213,7 @@ function viaParent(child: Flow, withOutput: boolean): Flow {
163213

164214
export const runasSystemTouchViaParent = viaParent(runasSystemTouch, false);
165215
export const runasSystemReadViaParent = viaParent(runasSystemRead, true);
216+
export const runasSystemReadSealedViaParent = viaParent(runasSystemReadSealed, true, false);
166217

167218
/** A minimal, self-contained app config the dogfood harness can boot. */
168219
export const runasFixtureStack = defineStack({
@@ -182,6 +233,9 @@ export const runasFixtureStack = defineStack({
182233
runasUserRead,
183234
runasSystemTouchViaParent,
184235
runasSystemReadViaParent,
236+
runasSystemReadSealed,
237+
runasUserReadSealed,
238+
runasSystemReadSealedViaParent,
185239
],
186240
});
187241

@@ -191,6 +245,11 @@ export const runasFixtureStack = defineStack({
191245
* owner RLS policy on ALL operations keyed on `created_by`. A member can read
192246
* and write their OWN notes, but neither read nor write the admin's — the exact
193247
* cross-owner isolation the runAs proof needs on both directions.
248+
*
249+
* One select-only policy widens READS alone: an admin note whose `status` is
250+
* `SHARED_STATUS` is readable to the member (read policies OR-combine), and
251+
* stays unwritable (no write policy admits it). That is the row the write
252+
* proof hands a flow: one the caller can show it reads, and cannot touch.
194253
*/
195254
const FIXTURE_MEMBER_SET = 'runas_fixture_member';
196255

@@ -200,7 +259,10 @@ export const runasMemberSet: PermissionSet = PermissionSetSchema.parse({
200259
objects: {
201260
runas_note: { allowRead: true, allowCreate: true, allowEdit: true, allowDelete: true },
202261
},
203-
rowLevelSecurity: [RLS.ownerPolicy('runas_note', 'created_by')],
262+
rowLevelSecurity: [
263+
RLS.ownerPolicy('runas_note', 'created_by'),
264+
{ name: 'runas_note_shared_read', object: 'runas_note', operation: 'select', using: `status == '${SHARED_STATUS}'` },
265+
],
204266
});
205267

206268
/**

0 commit comments

Comments
 (0)