Skip to content

Commit 3f0e3ac

Browse files
test(ui): the live member's API requests carry the member alone, not the inherited admin cookie (#31871)
<!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi96VGP7vMPA9C54zyjz2LMch)_ Fixes #31827 Clause-②: no Metadata-protocol: none ## 维护者速读 - 改了什么:夜间 live 层的成员夹具改为只用成员自己的凭据发 API 请求(成员自己的会话 cookie 加它的 Bearer),成员登录也从空状态开始;`read-only-member-record.spec.ts` 只换成调用新助手,断言一条未动。 - 为什么改:在 `@playwright/test` 里,不指定 `storageState` 新建的请求上下文会继承配置里的管理员 cookie,于是成员请求同时带着管理员 cookie 和成员 Bearer。#31469 起服务端拒绝这种「两个账号」的请求,数据路由回 401,夜间层因此变红。席位裁定:改夹具,不改产品。 - 风险与回滚:只动 `ui/e2e/live/` 下两个测试文件,不发布任何包,不动 `packages/`。回滚即 revert。 - 先看:`ui/e2e/live/member.ts` 的 `memberRequestContext` 和模块注释里的 ⛔ 段。 - 两分钟验证:起后端后跑 `OS_TEST_TIERS=nightly pnpm --filter @objectstack/example-showcase exec vitest run test/console-live-specs.live.test.ts`,预期 `28 passed`。 - 需要你做的:无,席位落地。 ## What changes - `ui/e2e/live/member.ts` gains `memberRequestContext(member)`: a request context carrying the member's own session cookie and its Bearer, with its `storageState` named so the config's administrator cookie is not inherited. - The member's sign-in context starts from an empty `storageState` (`{ cookies: [], origins: [] }`) instead of the inherited administrator cookie, so the sign-in request names the member only. - `read-only-member-record.spec.ts` builds its premise context with the helper. That is its only change: the `playwright` fixture it no longer uses leaves the destructuring, and no assertion moves. - The module comment states the trap: inside `@playwright/test`, `playwright.request.newContext()` and the imported `request.newContext()` both start with the config's `use.storageState`. No test was skipped, renamed or loosened. No change under `packages/`. ## Why The nightly live tier went red at `6be71abc` on `read-only-member-record.spec.ts:48`, premise step: the member's `GET /api/v1/data/showcase_inquiry/<id>` answered 401 where 200 was expected. Step 0 (seat ruling 6735238125): - **Bisect.** Each commit measured on a fresh backend booted by `ui/e2e/live/ci/start-backend.sh`, with the spec's request shape: | Commit | Result | |:--|:--| | `44a030bf` (last green nightly) | green, read 200 / write 403 | | `133f75aec0~1` | green, 200 / 403 | | `133f75aec0` #31469 | **red**, 401 / 401 | | `ed4b83226b` #31443 | red | | `59630d9357` #31622 | red | | `8c9260f79c` #31657 | red | | `f127b04e07` #31686 | red | | `6be71abc` (red nightly) | red | - **Cause.** The member's context was `playwright.request.newContext({ extraHTTPHeaders: { Authorization: 'Bearer <member>' } })`. Inside `@playwright/test` that context inherits the config's `use.storageState`, which is the global setup's administrator cookie. Measured: the context's cookie equals the administrator's. So each premise request carried two accounts' credentials. Before #31469 the bearer won. Since #31469 the session read refuses such a request with `CREDENTIALS_NAME_DIFFERENT_ACCOUNTS`, and the data route answers its own anonymous 401. #31469's acceptance notes describe exactly that data-route answer, so the product behaves as ruled and the fixture relied on what #31469 ruled out. ## Sweep (owed by the ruling) Every live spec and helper under `ui/e2e/live/` that builds a request context or sends a credential: | Site | Accounts it sends | Action | |:--|:--|:--| | `read-only-member-record.spec.ts` premise context | admin cookie (inherited) + member Bearer | **moved onto `memberRequestContext`** | | `member.ts` sign-in context (`request.newContext()`) | admin cookie (inherited) on the member's sign-in | **moved onto an empty `storageState`** | | `read-only-member-record.spec.ts` member browser context | member `storageState` named explicitly | one account, unchanged | | `global-setup.ts` sign-in context | none (global setup runs before any `use` state exists) | one account, unchanged | | `inline-edit-polish-2572.spec.ts` `request` + Bearer | admin cookie + admin token from the same `state.json` | one account, unchanged | | `studio-customize-journey.spec.ts` `request` override | `storageState` passed by name (admin), no other credential | one account, unchanged | | `studio-object-designer.spec.ts` in-page `fetch` | admin page's own cookie + its own localStorage token | one account, unchanged | | every other spec's `request.get/post/…` (cascading-options, grid-file-upload, list-row-action-cel, master-detail, record-form-direct-url, record-history-display) | admin `request` fixture alone | one account, unchanged | Measured for the two inherited sites: the imported `request.newContext()` and `playwright.request.newContext()` each start with 1 cookie under this config; with `storageState: { cookies: [], origins: [] }` they start with 0. ## Verification All heavy runs went through `scripts/pm/os-verify-lock.sh`. Head `86082eb9b5`, backend closure and `pnpm console:build` rebuilt at the head first. - **Nightly live file, head:** `OS_TEST_TIERS=nightly pnpm exec vitest run test/console-live-specs.live.test.ts` in `examples/app-showcase`: Playwright `28 passed (1.3m)`, vitest `Test Files 1 passed (1)`, `Tests 1 passed (1)`. - **Ablation:** `scripts/ablation-replace.mjs` deletes the helper's `storageState` line in `member.ts` (anchor 1 → 0, blob `d4e1a39d33f5` → `dc6c2ff0d686`), so the inherited administrator cookie is back. The same run: `✘ read-only-member-record.spec.ts:48`, `Expected: 200`, `Received: 401`, `Test Files 1 failed (1)`. Restored: blob equals HEAD's (`d4e1a39d33f5`), `git diff HEAD` empty, `git status --porcelain` empty. - **Before the fix, on main `3487ccc1`:** the same nightly run was red, 1 of 28, the same 401. - **Dispatch gates:** see the os-dev-report on #31827 for each command's exit code and the `--ran` reconciliation; `pnpm lint` and `eslint` over the two touched files are reported there too. No changeset: the diff publishes nothing (`ui/e2e/live/` only), so this PR carries `skip-changeset`. ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. (No `packages/spec` change.) - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` passes. - [x] 4. One issue, one branch off an up-to-date `main`, one pull request. - [x] 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset. (Publishes nothing; `skip-changeset`.) - [x] 6. `packages/spec` touched: n/a. - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English. (The 维护者速读 section is the seat's required Chinese summary.) - [x] The *Before Submitting* list in CONTRIBUTING.md is done. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01ADHkmPpwZNVKwJLQGotdJy --- _Generated by [Claude Code](https://claude.ai/code/session_01ADHkmPpwZNVKwJLQGotdJy)_ Co-authored-by: Claude <noreply@anthropic.com>
1 parent bf06a50 commit 3f0e3ac

2 files changed

Lines changed: 27 additions & 4 deletions

File tree

‎ui/e2e/live/member.ts‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,16 @@ import { request, expect, type APIRequestContext } from '@playwright/test';
2626
* admin: the better-auth cookie for the API origin and the Bearer token the
2727
* console adapter reads from the APP origin's localStorage. It is returned,
2828
* never written to disk, so no path has to be rooted.
29+
*
30+
* ⛔ Every request context this module builds names its `storageState`. Inside
31+
* `@playwright/test`, a request context created without one inherits the
32+
* config's `use.storageState`, which is the global setup's ADMIN session
33+
* cookie (measured: `playwright.request.newContext()` and the imported
34+
* `request.newContext()` both start with that cookie). A member's Bearer sent
35+
* from such a context is a request signed in as two accounts, which the server
36+
* refuses since objectstack#31469 (`CREDENTIALS_NAME_DIFFERENT_ACCOUNTS`; a data
37+
* route answers its own 401). So the sign-in starts from an empty state, and a
38+
* spec acting as the member over the API uses {@link memberRequestContext}.
2939
*/
3040
const APP = process.env.LIVE_APP_URL || 'http://localhost:5180';
3141
const API = process.env.LIVE_API_URL || 'http://localhost:3000';
@@ -68,7 +78,8 @@ export async function signInMember(admin: APIRequestContext, permissionSet: stri
6878
).toBe('USER_ALREADY_EXISTS_USE_ANOTHER_EMAIL');
6979
}
7080

71-
const ctx = await request.newContext();
81+
// An empty state, not the inherited admin cookie: the sign-in names the member only.
82+
const ctx = await request.newContext({ storageState: { cookies: [], origins: [] } });
7283
try {
7384
const res = await ctx.post(`${API}/api/v1/auth/sign-in/email`, {
7485
data: { email, password: MEMBER_PASSWORD },
@@ -90,3 +101,16 @@ export async function signInMember(admin: APIRequestContext, permissionSet: stri
90101
await ctx.dispose();
91102
}
92103
}
104+
105+
/**
106+
* A request context that acts as `member` and as no one else: the member's own
107+
* session cookie and its Bearer token (objectstack#31827). Its `storageState`
108+
* is named so the config's admin cookie is not inherited (see the module
109+
* comment). The caller disposes it.
110+
*/
111+
export async function memberRequestContext(member: LiveMember): Promise<APIRequestContext> {
112+
return request.newContext({
113+
storageState: { cookies: member.storageState.cookies, origins: [] },
114+
extraHTTPHeaders: { Authorization: `Bearer ${member.token}` },
115+
});
116+
}

‎ui/e2e/live/read-only-member-record.spec.ts‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { test, expect, type Page } from '@playwright/test';
2-
import { signInMember } from './member';
2+
import { memberRequestContext, signInMember } from './member';
33
import { writesRecordsOf } from './data-writes';
44

55
/**
@@ -49,7 +49,6 @@ test('a member who may read but not write an inquiry gets a read-only form and n
4949
browser,
5050
page,
5151
request,
52-
playwright,
5352
}) => {
5453
// Three page loads in two browser contexts, one of them cold.
5554
test.setTimeout(120_000);
@@ -66,7 +65,7 @@ test('a member who may read but not write an inquiry gets a read-only form and n
6665
const member = await signInMember(request, 'showcase_manager');
6766

6867
await test.step('premise: the server lets the member read the record and refuses its update', async () => {
69-
const api = await playwright.request.newContext({ extraHTTPHeaders: { Authorization: `Bearer ${member.token}` } });
68+
const api = await memberRequestContext(member);
7069
try {
7170
const read = await api.get(`${API}/api/v1/data/${OBJECT}/${id}`);
7271
expect(read.status(), 'the member reads the admin-owned inquiry').toBe(200);

0 commit comments

Comments
 (0)