Skip to content

test(app-shell): skip fetch-free files before parsing in the bearer ratchet scan - #38148

Merged
objectstack-fleet[bot] merged 2 commits into
mainfrom
claude/issue-38101-bearer-ratchet-scan-speed
Nov 28, 2026
Merged

objectstack-fleet[bot] merged 2 commits into
mainfrom
claude/issue-38101-bearer-ratchet-scan-speed

Conversation

@objectstack-fleet

Copy link
Copy Markdown
Contributor

Requested by Elon · project thread

Fixes #38101

Clause-②: no
Metadata-protocol: none

维护者速读

  • 用户无感:只改了一条界面代码的自检测试,让它跑得更快,产品行为不变。
  • 为什么做:这条自检在持续集成上跑到 15 秒超时,挡住了必过的界面测试分片。
  • 出错会怎样:最坏是这条自检漏看某个文件;已用全量对照证明前后结果一字不差,可直接撤回。
  • 要你做什么:无。

What changes

ui/packages/app-shell/src/sameServerFetch.bearer.ratchet.test.ts only. The scan was already computed once per run and shared by the two cases that read it; the time went to the TypeScript parse of every scanned file.

Measured on this container (2464 scanned files, about 41 MB of source): walk 22 ms, read 146 ms, parse of every file about 3.5 s, AST visits about 0.2 s. So the parse is the cost, and two changes cut it:

  1. Skip a file before parsing it when it holds neither fetch as a whole word nor sharedGetJson (MAY_HOLD_A_COUNTED_CALL). Every transport the detector counts is matched on its written text (fetch, window.fetch, globalThis.fetch, self.fetch, an alias whose initializer is one of those, or sharedGetJson), so a file without either token cannot produce a row. 397 of 2464 files are kept.
  2. Parse without JSDoc and without parent links (jsDocParsingMode: ParseNone, setParentNodes: false). The detector reads neither; every getText / getStart call is handed the source file.

The scanned set is unchanged, and so are the counted rows (proof below). A new assertion in the detector case pins the pre-filter: every positive detector spelling must pass MAY_HOLD_A_COUNTED_CALL, so narrowing the filter reds the file.

Tests

Timings are from a shared 4-core box under os-verify-lock (load average about 4), so ratios are the reading to trust. The base file (a copy of origin/main's test) and the new file ran in the same process, one after the other, twice (--maxWorkers=1 --no-file-parallelism):

run base every bare cookie-only call… this PR
1 5394 ms 2060 ms
2 5420 ms 1422 ms

That is 0.26 to 0.38 of the base time. Applied to the 15202 ms CI reading on job 140828751977, that is about 4 to 5.8 s on a CI shard, well under the 15 s timeout. The CI figure on this PR's own Test UI shard is NOT MEASURED here: read it off the check-run.

Same counted rows before and after

A temporary case (not committed) ran the full unfiltered scan next to the filtered scan() and compared the two maps: FILES 2464 ROWFILES 15 CALLS 21 EQUAL true. It ran once against each commit's parse options. Both before and after, the allow-list case every allow-list row is still exact is green: all 15 rows (21 calls) match exactly.

Ablations (on disk, restored, tree clean afterwards)
  • Bare cookie-only call added to a scanned file that held no fetch token before the edit (ui/packages/fields/src/FieldEditWidget.tsx: await fetch('/api/v1/x', { credentials: 'include' })). The case every bare cookie-only call is a counted row… goes red with packages/fields/src/FieldEditWidget.tsx:495 :: fetch('/api/v1/x', …). The ratchet keeps its teeth.
  • MAY_HOLD_A_COUNTED_CALL narrowed to /sharedGetJson/. The detector case goes red ("kept": false), and so does every allow-list row is still exact.

Acceptance notes

  • No timeout raised, no vitest config touched, no product source touched.
  • skip-changeset: @object-ui/app-shell is private: true, and its files[] (dist, src/styles.css, …) does not ship this test file.

Verification

Files to read first:

  1. MAY_HOLD_A_COUNTED_CALL and its use in scan(). This is the risk hunk: a filter that is too narrow drops files without saying so. Check the claim that every counted transport is matched on written text containing fetch or sharedGetJson.
  2. The createSourceFile options in bareCookieOnlyCalls.

Two-minute check: pnpm --filter @object-ui/app-shell exec vitest run --root ../.. packages/app-shell/src/sameServerFetch.bearer.ratchet.test.ts. Expect 4 passed, with the counted-row case at about a third of its time on main.

🤖 Generated with Claude Code

https://claude.ai/code/session_016WV4cxRDKprCtjpEdtiPFW

@objectstack-fleet objectstack-fleet Bot added the skip-changeset PR has no user-facing published change; bypasses the changeset gate label Nov 28, 2026
@objectstack-fleet

Copy link
Copy Markdown
Contributor Author

repo:objectstack#1 · os-elon-musk · session_016WV4cxRDKprCtjpEdtiPFW

L1 verdict: ACCEPT (in-area self-review, area-lease.md 送审: ≤50 lines, test only, Clause-②: no) and landing · 2026-11-28T04:51Z · Head-sha 1334197b005c7c7a294f4240c04caedbdd819ea1 (Fixes #38101)

  • Shape: one file, ui/packages/app-shell/src/sameServerFetch.bearer.ratchet.test.ts, +20/-3. l1-face CLEAN; check-governed-merges NOT governed. Checks: 38 succeeded, 18 expected skips, 0 failed. No product source, no vitest config, no timeout raised.
  • Read: (1) a pre-parse skip of files holding neither fetch nor sharedGetJson; every transport the detector counts is written with one of those tokens, and each positive detector case is now pinned to pass the filter. (2) The parse drops JSDoc and parent links; the file has no .parent read and every getText/getStart is handed the source file.
  • Evidence: the dev's unfiltered-vs-filtered comparison gave the same 15 row files / 21 calls; ablation adding a bare cookie-only fetch to a scanned file reds the counted-row case (os-dev report, test(app-shell): sameServerFetch.bearer.ratchet "every bare cookie-only call is a counted row" scans the whole ui source tree in ~5 s locally and ~15 s on a CI shard, and times out the required Test UI (1/16) #38101 comment 7234082209). CI on this head: the whole file ran in 3955 ms on its Test UI shard (4 tests), against the measured 15202 ms for the one case before, under the card's 5 s target.
  • Action: ready and auto-merge, by area o1-F.

@objectstack-fleet
objectstack-fleet Bot marked this pull request as ready for review November 28, 2026 04:52
@objectstack-fleet
objectstack-fleet Bot added this pull request to the merge queue Nov 28, 2026
Merged via the queue into main with commit ebcec5c Nov 28, 2026
57 checks passed
@objectstack-fleet
objectstack-fleet Bot deleted the claude/issue-38101-bearer-ratchet-scan-speed branch November 28, 2026 05:31
Nenzyz pushed a commit to Nenzyz/objectstack that referenced this pull request Dec 1, 2026
…he bearer ratchet reads four more spellings (objectstack-ai#38173)

<!-- claude-projects-attribution: {"github_login":"os-tesla"} -->
_Requested by **Tesla** · [project
thread](https://claude.ai/code/project/chan_01AXsQkLFKRdQCqQ3RTr6Jao?thread=cmsg_01AXsQkLFKRdQCqQ3RTr6JaoDanEGNW6fHMedo6Br7tobU)_

Fixes objectstack-ai#37505
Fixes objectstack-ai#37506
Fixes objectstack-ai#37507
repo:objectstack#3 · os-tesla · session_01L9qic11DcdSCqDBNNUAXcb

Clause-②: no
Metadata-protocol: none

## 维护者速读
- 嵌入或云租户里只靠令牌登录的用户:数据适配器的两个上传方法以前只带 cookie,现在和其他请求一样带上令牌;控制台界面没有变化。
- 属于「纯令牌登录和分源部署下请求都带上身份」专题:补全检查「同服务器请求必须带令牌」的那条测试,它以前漏数四种写法。
-
只换了上传用哪个请求通道,地址、内容和连接状态都不变;有问题可以直接撤回。顺带发现标准服务端上这两个上传地址本身不存在,已另立卡,本次没有修。
- 无

## What changes
- `@object-ui/data-objectstack` (objectstack-ai#37506): `uploadFile` and `uploadFiles`
call the host's injected `fetch` as given (`uploadTransport`, kept aside
in the constructor), not the global `fetch`. The console hands
`createAuthenticatedFetch()`, so an upload under a bearer-only session
now carries the stored bearer like every other request of the adapter.
Both stay outside the connection-state observer (`observeServerAnswer`),
so an upload's outcome still does not move the connection state, as the
README says; only the README's "call the global `fetch`" wording
changes. URL, body and headers are unchanged. `metadata-client` has no
bare call left on main, so nothing changes there.
- The same-server bearer ratchet
(`sameServerFetch.bearer.ratchet.test.ts`, objectstack-ai#37505) now reads four
spellings that used to pass uncounted:
- a URL held in a `const` of the file (`const url = ` + template naming
`/api/`), and a `+` concatenation with an `/api/` part;
- `credentials: 'same-origin'` spelled out (the default: the cookie
alone);
- an init that spreads a `const` of the file (`{ ...COOKIE_INIT, method:
'POST' }`), with later keys overriding, as at run time. A spread of
anything else (`{ ...init }`) stays unknown and uncounted; a credentials
value written before such a spread is kept.
- Each spelling has pins in the detector case table (counted and
not-counted). The `ALLOWED` list is unchanged: on the widened detector
the whole tree matches it row for row.
- The ratchet gains `REGISTERED_CHANNELS` (objectstack-ai#37505, objectstack-ai#37507): three calls
that read like a bare fetch and are not one, each with its reason, and a
case that fails once a file no longer holds the registered spelling or
the scan starts counting a call in it:
- `react` `useDatasetDimensionLabels` and `useElementApiDataSource`:
`apiFetch ?? fetch`, the host's channel off `SchemaRendererContext`.
- `auth` `createAuthClient`: the stale-bearer self-heal retry of
`get-session`, token-less on purpose. Every other request of that client
already goes through `bearerFetch`, so objectstack-ai#37507 needs no production
change.
- `patch` changeset for `@object-ui/data-objectstack`.

Not here: objectstack-ai#38101 (the same test file's scan time) is claimed by another
seat; whichever lands second merges main.

## Tests
- New `uploadTransport-37506.test.ts`: the injected fetch adds a bearer
and records what reached the network; the global `fetch` is stubbed to
record and refuse (the control, the pre-fix transport). `uploadFile` and
`uploadFiles` each send exactly one `POST` to the upload URL carrying
the bearer, and never touch the global fetch; a refused upload leaves
the connection state at `connected` with no event.
- The ratchet: the detector case table gains 15 rows for the four
spellings and one row flips from 0 to 1 (`credentials: 'same-origin'` on
an `/api/` path); one new case for `REGISTERED_CHANNELS`.

<details><summary>Readings (base origin/main 581ae76)</summary>

- Premise, before any change: a port of the detector run over the whole
`ui` tree (2466 files) matched `ALLOWED` exactly (15 rows, 21 calls);
with the four spellings on, the only new hits were the two uploads in
`data-objectstack` (`uploadFile` and `uploadFiles`, `fetch(url, …)`).
- `uploadTransport-37506.test.ts`: `Tests 3 passed (3)`. Ablation (both
uploads put back to the global `fetch`, fix committed first, restored
with `git checkout HEAD`): `Tests 3 failed (3)`.
- `sameServerFetch.bearer.ratchet.test.ts`: `Tests 5 passed (5)`.
Ablations, one at a time against the committed file: uploads back to the
global `fetch` reds "every bare cookie-only call is a counted row" with
exactly the two upload lines; dropping the `+` branch, the URL-const
lookup, the `same-origin` reading or the spread reading each reds the
detector case for that spelling.
- `eslint` on the three changed `.ts` files: 0 errors; the warnings are
the existing `no-explicit-any` ones in `index.ts`, none on a changed
line.
- `@object-ui/data-objectstack` `type-check` (`tsc --noEmit`) exit 0,
after a build of its dependency closure.
- `dispatch-gates --commands` at 96332e4: 40 families derived, 40 run,
every one exit 0 (`--ran`: 0 NOT-MEASURED, a derived zero), `pnpm --dir
ui exec vitest run scripts/` included (`Tests 5144 passed | 2 skipped`).
- `overlap-check`: clean against origin/main 33a0d4f and against objectstack-ai#38148
(the scan-time change in the same test file). The ratchet with both
changes merged (`git merge-file`, not committed here): `Tests 5 passed
(5)`.
</details>

## Acceptance notes
- Out of scope: the upload route itself, see objectstack-ai#38163. On a stock stack
both upload methods' path answers 404 whatever the credentials; this PR
changes only which fetch carries them.
- No boot reading of an upload through the console; the pins drive the
adapter through an injected fetch double.

## Verification
Read first (by risk):
1. `data-objectstack/src/index.ts`: the `uploadTransport` field, its
assignment in the constructor, and the two `this.uploadTransport(url,
…)` calls.
2. The ratchet's `credentialsOf` and `namesApiPath`, and the new rows of
the detector case table.

Two-minute check: `pnpm --dir ui exec vitest run
packages/data-objectstack/src/uploadTransport-37506.test.ts
packages/app-shell/src/sameServerFetch.bearer.ratchet.test.ts` passes;
put either upload call back to `fetch(url, {` and both files red.

---
_Generated by [Claude
Code](https://claude.ai/code/session_01L9qic11DcdSCqDBNNUAXcb)_

---------

Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/s skip-changeset PR has no user-facing published change; bypasses the changeset gate tests

Projects

None yet

2 participants