fix(plugin-dev): load setup/account through literal specifiers, so init() makes no main-process round trip under vitest - #20452
Conversation
…it() makes no main-process round trip under vitest The setup / account app-package loop in DevPlugin.init() imported through one variable specifier (`import(spec[0])`). Under vitest a variable specifier is resolved at call time by a round trip to the main process, even when the package is mocked, so every init() in every plugin-dev suite made two such round trips. Under CPU load they were the load-dependent term in the suites' clocked windows. Each loop entry now carries its own literal loader. The try/catch and reportOptionalLoadFailure around each load are unchanged. A family pin (dev-plugin-literal-imports.pin.test.ts) holds that every dynamic import in dev-plugin.ts is literal, except the ADR-0132 organizations one. Claude-Session: https://claude.ai/code/session_01UYBdGBzWSrAMzpW8ah3GbP Co-authored-by: Claude <noreply@anthropic.com>
…the build config compiles src as CommonJS `import.meta` is TS1470 under this package's NodeNext/CommonJS build config, which `tsc --noEmit` also reads for tests. Vitest's evaluator provides `__dirname`, the spelling the sibling plugin-auth pins use. Claude-Session: https://claude.ai/code/session_01UYBdGBzWSrAMzpW8ah3GbP Co-authored-by: Claude <noreply@anthropic.com>
…ugin-dev-cold-start
…d round-trip counts in the pin and changeset
The takeover's re-verification of the two pushed commits corrects three
statements and adds the absent-arm preservation pin the fix was missing:
- dev-plugin-optional-load-failure.test.ts: one case holding that
@objectstack/setup and @objectstack/account, when they cannot be
imported, still reach the absent arm once each at warn, with the
resolver's code and the failing specifier, never at error. No existing
pin covered that loop's failure path.
- dev-plugin-literal-imports.pin.test.ts: the header now states the
counts re-measured on this tree (20 main-process requests over six
init()s through the variable specifier, 0 with literal ones; 18 in the
mount-refusal suite) and the CI job reading, in place of timing figures
carried from an earlier run that this takeover did not re-measure.
- dev-plugin.ts comment and the changeset: the organizations load is a
deliberate variable specifier, so "like every other load" becomes
"every other declared-dependency load"; the build keeps a native
import("...") inside an arrow, not "await import".
Claude-Session: https://claude.ai/code/session_local_1d2a197c-c20e-4e90-9be8-413d4d432289
Co-authored-by: Claude <noreply@anthropic.com>
…, not a private comment stripper check:comment-mask-adoption refused the pin's regex comment mask (regex-block, regex-line) as a new private comment stripper. The pin now walks the file's syntax tree: a dynamic import is a call node whose callee is the import keyword, so a comment, a string or a regex that mentions import( is never read as one, and a leading bundler hint is trivia. The exception check (organizationsPkg) reads the variable declaration's initializer instead of a source regex. typescript is already a devDependency of this package; the file surface is unchanged. Claude-Session: https://claude.ai/code/session_local_1d2a197c-c20e-4e90-9be8-413d4d432289 Co-authored-by: Claude <noreply@anthropic.com>
…o source in the vitest config check:test-source-alias reds on the literal specifiers: dev-plugin.ts now names both packages statically, and unaliased they resolve through exports to dist/, so a test verdict would depend on build state. Two anchored entries, exactly as the gate prescribes; both packages' own imports (platform-objects/apps, spec/system) are already aliased. Every suite mocks both packages, and the mocks resolve through the same entries: the full suite stays green and the six-init probe still shows zero main-process requests in the test phase. Claude-Session: https://claude.ai/code/session_local_1d2a197c-c20e-4e90-9be8-413d4d432289 Co-authored-by: Claude <noreply@anthropic.com>
📓 Docs Drift CheckThis PR changes 1 package(s): 1 hand-written doc(s) NAME something this change touched and may need an implementation-accuracy re-verification:
What this run could not see
Coarse fallback — 3 page(s) merely mention a changed package (the pre-#9192 predicate, kept for the deliberately-wide backstop): Which tree this was computed onThis run read A worktree cut from an older # while this PR is open — GitHub drops the merge commit once it closes
git fetch origin be1eb700e1845395fdc2cc1c35c7ba097e5f200b && git checkout be1eb700e1845395fdc2cc1c35c7ba097e5f200b
# afterwards, rebuild it from the two parents, which stay fetchable
git fetch origin 6e3e5462c6d1ad3e6b0e3e88bea17b69dfefef9d a24f6ea84c3b8dbf1a8b6bf81bc29c763b0dc444 && git checkout -B drift-repro 6e3e5462c6d1ad3e6b0e3e88bea17b69dfefef9d && git merge --no-ff a24f6ea84c3b8dbf1a8b6bf81bc29c763b0dc444
node scripts/docs-audit/affected-docs.mjs --json 6e3e5462c6d1ad3e6b0e3e88bea17b69dfefef9d
|
Contract reviewServed-tier: PR #20452 (draft, base Check-runs on the head, read at 13:45 UTC, newest run per name: 32 runs, 26 success, 3 skipped ( ① Derived judgments
Wrong: none found. The five files in the file list are the five the amended claim names, and nothing else. ② Semver level
③ Boundary flagsOpen questions.
Dev flags, final report (
Dev flags, round 1 ( Takeover flags (PR body). The continuation read the dead dev's two pushed commits as unverified work, kept the code lines, corrected the comment, changeset and pin header where they overstated ("like every other load", the Out-of-scope findings, noted and not filed.
Escalations: none. Pending, not escalated: the three in-progress check-runs named above. Implemented-by: VERDICT: PASS |
⛔ merge queue 构建失败 — 先分诊,再决定要不要重排队列构建 36433026729 红了。队列跑的是全量套件(PR 侧 CI 只跑 affected 子集), 失败的 job(日志抽取,best effort):
跨 PR 相同签名(24h,按失败测试文件聚合):
历史信号:
分诊清单:
Generated by Claude Code · merge-queue-triage workflow (#4859) |
⛔ merge queue 构建失败 — 先分诊,再决定要不要重排队列构建 36434111750 红了。队列跑的是全量套件(PR 侧 CI 只跑 affected 子集), 失败的 job(日志抽取,best effort):
跨 PR 相同签名(24h,按失败测试文件聚合):
历史信号:
分诊清单:
Generated by Claude Code · merge-queue-triage workflow (#4859) |
Fixes #20376
Clause-②: no
What this changes
DevPlugin.init()'s setup / account app-package loop imported both packages through one variable specifier,import(/* @vite-ignore */ spec[0]). Under vitest a variable specifier cannot be resolved whendev-plugin.tsis transformed, so every call went to the main vitest process, mocked packages included: two main-process round trips perinit(), inside every clocked test window that bootsDevPlugin. The main process is shared by the whole run, so on a busy CI shard those requests wait on other files' work. That is the shape of theTest Core (6/6)red on PR #20365 (job 108779589417): the mount-refusal suite's first case timed out at 5026 ms and its second took 2336 ms, while its other four took 16-72 ms, in a package run readingtransform 74.29s, import 137.46s, tests 11.87s.Route A of the seat's answer on the card: each loop entry now carries its own literal loader (
() => import('@objectstack/setup'),() => import('@objectstack/account')). Thetry/catchandreportOptionalLoadFailurearound each load are byte-for-byte unchanged. No timeout, retry or test-arrangement change.Files:
packages/plugins/plugin-dev/src/dev-plugin.ts: the loop only (two tuple entries, one call line, one comment block).packages/plugins/plugin-dev/src/dev-plugin-literal-imports.pin.test.ts(new): every dynamicimport()indev-plugin.tstakes a string literal, exceptorganizationsPkg(ADR-0132); read off the TypeScript AST.packages/plugins/plugin-dev/src/dev-plugin-optional-load-failure.test.ts: one case pinning that setup / account, when they cannot be imported, still reach the absent arm (one line each atwarn, with the resolver's code and the failing specifier, never aterror).packages/plugins/plugin-dev/vitest.config.ts: two anchored alias entries for@objectstack/setup/@objectstack/account, whichcheck:test-source-aliasrequires once the specifiers are literal (see Acceptance notes)..changeset/20376-plugin-dev-literal-app-imports.md:@objectstack/plugin-devpatch.Takeover record
This branch was started by a dev whose seat session ran out of tokens after pushing
952e1249and4160ecbe, with no PR and no report. This continuation read both commits hunk by hunk as unverified work, mergedorigin/main(0fcb10184c) and re-ran every measurement below itself.dev-plugin.tscode lines, the changeset's frontmatter andClause-②line, and the pin's__dirnameseed (4160ecbe).917a31bc72: thedev-plugin.tscomment and the changeset said the loop now loads "like every other load / package", which the deliberateorganizationsPkgvariable specifier contradicts (now: every other declared-dependency load); the changeset said the build keepsawait import("…"), whiledist/index.mjsanddist/index.jsboth keep a nativeimport("…")inside an arrow; the pin header carried the earlier run's load timings (44.5-102.0 ms perinit(), a 5048 ms local timeout), which this run did not re-measure, and now states the counts below plus the CI job reading, which this run read from the job log itself.35833d2a2c: the pin's private regex comment stripper was refused bycheck:comment-mask-adoption; the pin now walks the TypeScript syntax tree (typescriptis already a devDependency of this package).917a31bc72: the absent-arm pin (no existing pin covered this loop's failure path).a24f6ea84c: the two vitest alias entries (check:test-source-aliasred without them).Measurements (H1-H4)
H1: the round trips, counted. A throwaway vite plugin (deleted after) logged every
resolveIdandtransformthe main process served, around six back-to-backinit()s in a throwaway probe with every package mocked absent. Same method, same run shape, both legs:dev-plugin.tsinit()sinit()origin/main(blobb132ad3f4)resolveId, 2/@fsresolveId, 2dist/index.mjstransforms, 4resolveIds of their imports); each later: 2 (@objectstack/setup,@objectstack/account)a24f6ea84cThe real
dev-plugin-tenancy-mount-refusal.test.tsunder the same logger (importerdev-plugin.ts): onorigin/main, 9resolveIds of each package (nineinit()s, 18 in all) plus bothdisttransforms; on this branch, none in the test phase. Every leg logged both absent-app warnings on everyinit()(6 of 6).H2: the pin fails when the variable specifier comes back.
node scripts/ablation-replace.mjs, WRAP mode, at35833d2a2c:await import(/* @vite-ignore */ spec[0]): ① red (1 failed | 2 passed), received[ 'spec[0]', 'organizationsPkg' ];origin/mainblobb132ad3f4: ① and ③ red (2 failed | 1 passed; ③ reports 12 literal loads, none of them setup / account).Each restore was proven by the tool: blob after restore equals the HEAD blob (
1f1ac117f) andgit diff HEADis empty. The pin readsdev-plugin.ts's source text, so nodist/leg applies.H3: the absent-package path is unchanged. The new case is green on this branch and green with
dev-plugin.tsswapped to theorigin/mainblob (10 passedboth), so it pins behaviour the fix preserves. It goes red when that path breaks: a silentcatch(if (err) continue;) gives1 failed | 9 passed, and demoting the loop'sabsentLeveltoinfogives1 failed | 9 passed. Restores proven as above. (A first attempt at the silent-catch leg was refused by the tool, because its replacement contained its own anchor; no test ran, and it was retried with a different anchor.)H4: the suites pass.
pnpm --filter @objectstack/plugin-dev testata24f6ea84c:Test Files 9 passed (9),Tests 86 passed (86), mount-refusal 6/6, failfast 9/9, tenancy-posture 6/6, optional-load-failure 10/10, security-enforcement-warning 4/4, malformed-stack-posture 4/4,dev-plugin.test.ts24/24, i18n reader 20/20, the new pin 3/3.Verification at
a24f6ea84cpnpm turbo run build --filter='@objectstack/plugin-dev^...' --concurrency=2: 34/34.pnpm --filter @objectstack/plugin-dev typecheck: exit 0 (tsc --noEmitandcheck:test-typecheck;--listFilesshows both touched test files in both programs).node scripts/pm/dispatch-gates.mjs --repo objectstack-ai/objectstack --commands: 62 commands, all exit 0;--ranreconciliation: 62 derived, 62 run, 0 NOT-MEASURED, 0 UNRUN (a derived zero: every line carries its exit code). On the way:check:comment-mask-adoptionandcheck:test-source-aliaswere red on this branch's pushed state and are fixed above;check:dual-build-cjs-loadsandcheck:type-check-debtfirst answered PREREQUISITE NOT MET and were re-run afterpnpm exec turbo run build --filter='./packages/*' --filter='./packages/*/*' --concurrency=2(71/71).node scripts/check-issue-citations.mjs --base origin/main: exit 0 (also exit 0 with--base 0fcb10184c, the merge base).pnpm lint: exit 0, no findings.Test Core,Dogfood,Build CoreandTemporal Conformancejobs and the workspace type-check lanes the derivation lists as CI-only.Declared narrowing — verification ran UNLOCKED.
scripts/pm/os-verify-lock.shcould not take the shared verify lock on this host: no usable
flock. The sharedverify lock is declared Linux-only (
flockis util-linux, and a stock macOS doesnot ship it), so the command below was run directly, without the lock —
a declared narrowing, not a silent one. No serialization guarantee held for this
run, nor for any sibling agent in this container while it ran.
Acceptance notes
packages/plugins/plugin-dev/vitest.config.tsis not in the claim's listed surface. It is the mechanical consequence of route A: literal specifiers make both packages visible tocheck:test-source-alias, which then requires them aliased to source. The two entries are the ones the gate printed; both packages' own imports were already aliased. The absent-arm case indev-plugin-optional-load-failure.test.tsis the "smallest pin" the dispatch's H3 asked for.dev-plugin-malformed-stack-posture.test.tscase 4 pays a real cold load ofobjectqlanddriver-memoryinside a window widened by an explicit60_000, and the first case ofdev-i18n-packages-reader.test.tspays a first-use cost. Neither is failing (idle maxima ata24f6ea84c: 76 ms and 28 ms). No CPU-load generator was run on this shared host.packages/cli/src/commands/serve.ts(around line 4024) loads setup / account through the same kind of variable-specifier loop (withwebpackIgnore). In a spawned CLI process there is no vitest main process to call, so it costs nothing there; a vitest suite that ran that branch in-process would pay the same round trip. Not measured. Noted, not filed.dev-plugin.ts'sMODULE_NOT_FOUND_CODESdocblock says the CJS build resolves these loads throughrequire(). The currentdist/index.jskeeps a nativeimport("…")for every dynamic load. It is harmless, because both codes stay in the set. Noted, not filed.@objectstack/setupand@objectstack/accountstatically, as it already saw the twelve other literal loads. Both are declared dependencies.@objectstack/organizations, which no framework package may declare, keeps itswebpackIgnorevariable form.Generated by Claude Code