Skip to content
This repository was archived by the owner on Nov 4, 2026. It is now read-only.

test(console): take the app-shell barrel out of three vi.mock factories (#6580) - #7315

Merged
yinlianghui merged 1 commit into
mainfrom
claude/issue-6580-app-shell-import-original
Sep 2, 2026
Merged

yinlianghui merged 1 commit into
mainfrom
claude/issue-6580-app-shell-import-original

Conversation

@yinlianghui

Copy link
Copy Markdown
Contributor

Fixes #6580

1. Measurement first — the population is 3, not 12

The card was explicit that 12 was a path-intersection upper bound, because a file
lands in it if it mocks @object-ui/app-shell and uses importOriginal anywhere.
Attributing each importOriginal call to the factory it actually sits in (paren-balanced
scan over every vi.mock call, then confirmed by reading the three survivors):

Ripgrep over apps/console finds 22 files mocking the package — one more than the
card's GitHub code-search figure of 21, so the index was indeed lagging.

file importOriginal belongs to affected
components/FormPage.predicateScope.test.tsx @object-ui/app-shell, @object-ui/auth YES
components/SetupRoute.test.tsx @object-ui/app-shell, @object-ui/auth, packages/auth/src/useAuth, packages/app-shell/src/providers/MetadataProvider YES
components/StudioRoute.test.tsx @object-ui/app-shell, @object-ui/auth, packages/auth/src/useAuth YES
pages/system/ApprovalsInboxPage.cellIdentity.test.tsx ../../services/approvalsApi no
pages/system/ApprovalsInboxPage.characterizationPins.test.tsx ../../services/approvalsApi no
pages/system/ApprovalsInboxPage.hiddenFieldTrim.test.tsx ../../services/approvalsApi no
pages/system/ApprovalsInboxPage.queueHiddenAmount.test.tsx ../../services/approvalsApi no
pages/system/ApprovalsInboxPage.rawPayloadGate.test.tsx ../../services/approvalsApi no
pages/system/ApprovalsInboxPage.recordLink.test.tsx ../../services/approvalsApi no
pages/system/ApprovalsInboxPage.stepProgressVertical.test.tsx ../../services/approvalsApi no
pages/system/__tests__/AppManagementPage.i18n.test.tsx @object-ui/i18n no
pages/system/__tests__/AppManagementPage.mutations.test.tsx @object-ui/i18n no
pages/system/__tests__/AppManagementPage.search.test.tsx @object-ui/i18n no
the remaining 9 files no importOriginal at all no

N = 3. The card's own caveat was right: nine of the twelve candidates carry an
importOriginal that belongs to approvalsApi or @object-ui/i18n, not to the barrel.

2. Cost, re-measured on this tree

performance.now() around the call, in a throwaway probe file that was deleted before
the commit (a vi.hoisted holder carries the number out of the hoisted factory):

PROBE6580 app-shell=10019ms auth=237ms

That reproduces the card's 10204ms / 240ms independently. Two of the card's structural
numbers have grown since it was filed and are corrected here: the barrel is 447 lines
carrying 13 bare side-effect imports, not 385 and 8.

3. Which lever, and why the other two are not it

(a) alias the test build to built output — not viable. .github/workflows/ci.yml
runs pnpm install --frozen-lockfile and then pnpm test --shard=N/4 with no build
step
, and packages/app-shell/dist does not exist at test time. The alias table in
apps/console/vite.config.ts points every @object-ui/* entry at source, so this would
also be a single inconsistent entry.

(b) trim the barrel's side-effect imports — stopped, per the dispatch ruling. Those
13 imports are registration side effects of the published package; removing or deferring
them changes what a consumer gets from importing the barrel. Making only the test alias
avoid them requires a second entry point, which is lever (a) wearing a different hat.
Not landed here.

(c) drop importOriginal for this package in the factories — chosen. Confined to the
three test files, no published surface touched.

What decided it: each submodule these factories actually need was timed individually, and
then the barrel was timed after all of them were already loaded.

module cold cost
chrome/index 549 ms
console/ConsoleShell 1477 ms
providers/ExpressionProvider 0 ms
providers/expressionUser 4 ms
utils/index 0 ms
providers/MetadataProvider 0 ms
the barrel, with all six already loaded 7828 ms

So ~7.8 s of the ~10 s is graph these three files never touch. The factories now spread
the submodules the real exports live in.

4. Why this is not fragile — a static coverage proof

Dropping the whole-barrel spread risks a name silently becoming undefined on a path no
test exercises. So the covering set was derived statically, over the full transitive
module graph of each test file (~1237 modules once NodeNext .js specifiers resolve to
their TypeScript sources), not from the paths the tests happen to run. Every name any
module in the graph imports from @object-ui/app-shell must be an override, a type-only
barrel export, or an export of a spread submodule:

file union of names read from the barrel uncovered
SetupRoute.test.tsx ConnectedShell, LoadingFallback, MetadataTypeStatus, RedirectWithSplash, RequireOrganization, SETUP_APP_NAME, SETUP_APP_PACKAGE_ID, SetupRedirect, useMetadata 0
StudioRoute.test.tsx BuilderLanding, ConnectedShell, LoadingFallback, LoadingScreen, RedirectWithSplash, RequireOrganization, StudioDesignSurface, getProductName 0
FormPage.predicateScope.test.tsx DefaultHomeLayout, ExpressionProvider, FormFieldSpec, FormSectionSpec, FormViewSpec, buildExpressionUser, resolveHostAppSegment, useMetadata, useNavigationContext 0

The same scan confirms no module inside any workspace package imports the barrel by its
package name, so the consumer set is exactly those console files.

One subtlety worth flagging for review: SetupRoute.test.tsx mocks
packages/app-shell/src/providers/MetadataProvider separately, but RootLandingRedirect
reads useMetadata through the barrel. The old whole-barrel spread covered that by
re-exporting the already-mocked provider. The replacement spells the same stub out in the
app-shell factory rather than importing the provider module, so console's tsc program
gains no new cross-package source edge; the comment there says the two must stay in step.

5. Before / after

Same three files, same flags, same command, from the repo root:

pnpm exec vitest run --project @object-ui/console --no-file-parallelism --reporter=verbose \
  apps/console/src/components/SetupRoute.test.tsx \
  apps/console/src/components/StudioRoute.test.tsx \
  apps/console/src/components/FormPage.predicateScope.test.tsx
before after
import 13.07 s 2.64 s
transform 17.09 s 11.27 s
tests 560 ms 473 ms
total duration 40.21 s 30.52 s
result 3 files / 37 tests passed 3 files / 37 tests passed

These are shared-box seconds — the runs went through the shared verification lock, which
excludes other locked runs but not unlocked sibling work, so read the ratio (import phase
down ~5x) rather than the absolutes.

6. Verification

All from the repo root of the task worktree, exit codes captured before any pipe.

  • tests, final tree: Test Files 3 passed (3) / Tests 37 passed (37), lock VERDICT command-exit 0
  • pnpm --filter @object-ui/console run type-check -> exit 0, 0 error TS. Run after
    pnpm --workspace-concurrency=4 --filter "@object-ui/console^..." run build so the
    dependency closure was real; tsc --noEmit --listFiles confirms all three edited files
    are in the program (1 hit each), so "type-check clean" actually covers them.
  • pnpm exec eslint on the three changed files -> exit 0. One pre-existing
    no-explicit-any warning at line 188 of FormPage.predicateScope.test.tsx, outside
    every hunk in this diff.
  • pnpm check:control-bytes -> exit 0, scanned 6009 tracked text file(s).
  • node scripts/check-changeset-presence.mjs -> exit 0: "Every one of them has an
    EMPTY frontmatter — declared as releasing nothing, which is the explicit exemption".
    pnpm changeset:check -> exit 0.
  • pnpm lint:coverage -> exit 0 (46/46). pnpm type-check:coverage -> exit 0.

Not run locally, left to CI: the full apps/console project and the repo-wide lint farm.
This is a declared narrowing — the diff is three test files plus an empty-frontmatter
changeset, and CI runs the farm exactly once regardless.

7. Not touched

apps/console/vitest.config.ts, root vitest.config.mts and root vitest.setup.* are
owned by in-flight PRs #7291 and #7304. No timeout was raised, nothing was added to
heavyDomTests, and nothing was skipped or quarantined.

🤖 Generated with Claude Code

https://claude.ai/code/session_01BGMDbrVa8JjZcCQ7DWYH1b


Generated by Claude Code

`@object-ui/app-shell` is aliased to `packages/app-shell/src` in
`apps/console/vite.config.ts`, so a `vi.mock` factory that calls
`importOriginal()` on it transforms the whole barrel graph on demand —
447 lines and thirteen bare side-effect imports. Re-measured on this
tree with `performance.now()` around the call: 10019ms, against 237ms
for `@object-ui/auth` in the same file.

A per-file read of every console test that mocks the package attributes
each `importOriginal` to the factory it sits in. The population is three
files, not the twelve the path-intersection upper bound suggested: the
other nineteen either use no `importOriginal` at all or use it for
`../../services/approvalsApi`, `@object-ui/i18n` or `@object-ui/auth`.

Each of the three factories overrides most of what its graph reads from
the barrel and needs only a handful of real exports, all of which live
in submodules that cost ~2.0s together. Timed individually, the barrel
still costs 7828ms AFTER every one of those submodules is already
loaded — that residue is the side-effect imports and the rest of the
package, none of which these tests touch. So the factories now spread
those submodules instead of the barrel.

Which names each file's graph reads from the barrel was enumerated
statically over the whole transitive module graph (~1237 modules per
file), not from the paths the tests happen to exercise, and every one
of them is an override, a type-only export, or an export of a spread
submodule.

Three files, same 37 tests, same flags, from the repo root:
import phase 13.07s -> 2.64s, transform 17.09s -> 11.27s.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BGMDbrVa8JjZcCQ7DWYH1b
@github-actions

github-actions Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

✅ Console Performance Budget

Metric Value Budget
Eager closure (gzip, 48 chunks) 3160.2 KB 3191.4 KB
Main entry chunk (gzip) 142.6 KB 350 KB
Entry file index-BOEfHVe7.js —
Status PASS —

The eager closure is every chunk the entry reaches through static imports — what the browser fetches and parses before the app renders. The entry chunk on its own is a small fraction of it.


📦 Bundle Size Report

Package Size Gzipped
app-shell (consoleActionDispatch.js) 0.20KB 0.19KB
app-shell (index.js) 15.33KB 5.59KB
app-shell (runtime-config.js) 20.68KB 7.36KB
app-shell (types.js) 0.01KB 0.04KB
app-shell (urlParams.js) 10.06KB 3.86KB
auth (ActiveOrganizationStorage.js) 25.05KB 9.16KB
auth (AuthContext.js) 0.31KB 0.24KB
auth (AuthGuard.js) 2.07KB 1.00KB
auth (AuthProvider.js) 40.18KB 10.59KB
auth (AuthShell.js) 3.49KB 1.40KB
auth (ForgotPasswordForm.js) 12.21KB 3.45KB
auth (LoginForm.js) 18.15KB 5.39KB
auth (PreviewBanner.js) 0.90KB 0.50KB
auth (RegisterForm.js) 6.65KB 2.22KB
auth (SocialSignInButtons.js) 9.61KB 3.89KB
auth (UserMenu.js) 3.41KB 1.23KB
auth (auth-gate-events.js) 1.29KB 0.66KB
auth (authStyles.js) 5.04KB 1.72KB
auth (createAuthClient.js) 40.21KB 10.80KB
auth (createAuthenticatedFetch.js) 8.46KB 3.43KB
auth (index.js) 3.19KB 1.44KB
auth (invitation-status.js) 1.22KB 0.70KB
auth (org-roles.js) 6.66KB 2.78KB
auth (phone-identifier.js) 1.11KB 0.66KB
auth (types.js) 0.59KB 0.35KB
auth (useAuth.js) 5.30KB 1.02KB
auth (useWorkspaceAdminStatus.js) 5.13KB 2.35KB
collaboration (CommentThread.js) 26.08KB 7.56KB
collaboration (LiveCursors.js) 3.17KB 1.27KB
collaboration (PresenceAvatars.js) 6.49KB 2.64KB
collaboration (PresenceProvider.js) 2.79KB 1.13KB
collaboration (index.js) 1.68KB 0.73KB
collaboration (useCollaborationTranslation.js) 6.05KB 2.52KB
collaboration (useCommentSearch.js) 1.98KB 0.88KB
collaboration (useConflictResolution.js) 7.75KB 1.86KB
collaboration (useMentionNotifications.js) 1.81KB 0.68KB
collaboration (usePresence.js) 6.33KB 1.84KB
collaboration (useRealtimeSubscription.js) 7.91KB 2.01KB
components (index.js) 514.46KB 117.29KB
core (index.js) 5.55KB 2.23KB
create-plugin (index.js) 10.08KB 3.26KB
data-objectstack (index.js) 178.20KB 49.60KB
fields (index.js) 244.25KB 61.73KB
i18n (LocalizationContext.js) 1.76KB 0.96KB
i18n (currency.js) 1.22KB 0.64KB
i18n (fallbackInterpolation.js) 6.25KB 2.77KB
i18n (i18n.js) 4.28KB 1.75KB
i18n (index.js) 3.44KB 1.39KB
i18n (pickLocalized.js) 7.62KB 3.26KB
i18n (provider.js) 26.89KB 9.04KB
i18n (useDisplayLocale.js) 2.85KB 1.45KB
i18n (useObjectLabel.js) 33.40KB 8.71KB
i18n (useSafeTranslation.js) 5.60KB 2.33KB
layout (index.js) 38.98KB 10.98KB
mobile (MobileProvider.js) 0.92KB 0.49KB
mobile (ResponsiveContainer.js) 0.94KB 0.38KB
mobile (breakpoints.js) 1.51KB 0.70KB
mobile (createOfflineDataSource.js) 5.61KB 1.75KB
mobile (index.js) 1.55KB 0.62KB
mobile (offlineQueue.js) 3.91KB 1.35KB
mobile (pwa.js) 0.97KB 0.49KB
mobile (serviceWorker.js) 1.48KB 0.62KB
mobile (serviceWorkerSource.js) 3.41KB 1.48KB
mobile (useBreakpoint.js) 1.54KB 0.65KB
mobile (useGesture.js) 6.96KB 1.98KB
mobile (useOfflineSync.js) 1.99KB 0.72KB
mobile (usePullToRefresh.js) 2.53KB 0.85KB
mobile (useResponsive.js) 0.72KB 0.42KB
mobile (useResponsiveConfig.js) 1.37KB 0.63KB
mobile (useSpecGesture.js) 4.32KB 1.64KB
mobile (useTouchTarget.js) 1.01KB 0.54KB
permissions (MePermissionsProvider.js) 11.71KB 4.29KB
permissions (PermissionContext.js) 0.31KB 0.25KB
permissions (PermissionGuard.js) 0.89KB 0.45KB
permissions (PermissionProvider.js) 6.24KB 2.16KB
permissions (discardProofCache.js) 1.04KB 0.55KB
permissions (evaluator.js) 5.12KB 1.74KB
permissions (index.js) 0.93KB 0.41KB
permissions (store.js) 0.91KB 0.42KB
permissions (useFieldPermissions.js) 1.28KB 0.53KB
permissions (usePermissions.js) 4.83KB 2.27KB
plugin-ai (index.js) 15.75KB 3.80KB
plugin-calendar (index.js) 46.92KB 12.93KB
plugin-charts (index.js) 70.02KB 19.44KB
plugin-chatbot (index.js) 190.53KB 45.18KB
plugin-dashboard (index.js) 132.63KB 34.56KB
plugin-designer (index.js) 212.87KB 43.19KB
plugin-detail (index.js) 250.65KB 63.91KB
plugin-editor (index.js) 2.46KB 1.10KB
plugin-form (index.js) 132.78KB 32.58KB
plugin-gantt (index.js) 166.77KB 40.76KB
plugin-grid (index.js) 208.88KB 56.59KB
plugin-kanban (index.js) 53.21KB 14.66KB
plugin-list (index.js) 113.51KB 27.67KB
plugin-map (index.js) 20.20KB 6.66KB
plugin-markdown (index.js) 13.72KB 4.69KB
plugin-report (index.js) 43.51KB 11.94KB
plugin-timeline (index.js) 29.34KB 8.47KB
plugin-tree (index.js) 8.98KB 3.08KB
plugin-view (index.js) 85.90KB 21.12KB
providers (DataSourceProvider.js) 0.75KB 0.39KB
providers (MetadataProvider.js) 1.37KB 0.59KB
providers (ThemeProvider.js) 1.90KB 0.85KB
providers (UploadProvider.js) 11.66KB 3.50KB
providers (index.js) 0.45KB 0.23KB
providers (types.js) 0.01KB 0.04KB
react-runtime (index.js) 5.62KB 2.34KB
react (LazyPluginLoader.js) 4.47KB 1.63KB
react (SchemaRenderer.js) 81.07KB 26.86KB
react (data-invalidation.js) 5.05KB 2.08KB
react (index.js) 3.11KB 1.48KB
react (schema-input.js) 2.32KB 1.24KB
react (spec-input.js) 0.20KB 0.18KB
sdui-parser (codegen.js) 5.41KB 2.34KB
sdui-parser (dashboard-widget-options.js) 3.08KB 1.30KB
sdui-parser (index.js) 4.93KB 2.24KB
sdui-parser (input-type.js) 2.84KB 1.40KB
sdui-parser (parse.js) 20.57KB 5.88KB
sdui-parser (provenance.js) 3.66KB 1.82KB
sdui-parser (types.js) 0.28KB 0.23KB
sdui-parser (validate.js) 10.35KB 3.60KB
types (ai.js) 0.20KB 0.17KB
types (api-types.js) 0.20KB 0.18KB
types (app.js) 2.87KB 0.99KB
types (base.js) 0.20KB 0.18KB
types (blocks.js) 0.20KB 0.18KB
types (complex.js) 2.74KB 1.41KB
types (crud.js) 0.20KB 0.18KB
types (dashboard-filter-alias.js) 6.23KB 2.74KB
types (data-display.js) 3.75KB 1.85KB
types (data-protocol.js) 0.20KB 0.19KB
types (data.js) 0.20KB 0.18KB
types (designer.js) 1.85KB 0.85KB
types (disclosure.js) 0.20KB 0.18KB
types (error-code.js) 1.54KB 0.88KB
types (feedback.js) 0.20KB 0.18KB
types (field-types.js) 0.20KB 0.18KB
types (form.js) 0.20KB 0.18KB
types (http-inflight.js) 8.87KB 3.73KB
types (http-retry.js) 4.32KB 2.02KB
types (icon-key-migration.js) 4.26KB 1.63KB
types (index.js) 4.72KB 2.24KB
types (layout.js) 0.20KB 0.18KB
types (managed-by.js) 0.19KB 0.18KB
types (mobile.js) 2.59KB 1.31KB
types (navigation.js) 0.20KB 0.18KB
types (objectql.js) 0.20KB 0.18KB
types (overlay.js) 0.20KB 0.18KB
types (permissions.js) 0.20KB 0.18KB
types (plugin-scope.js) 0.20KB 0.18KB
types (record-components.js) 0.20KB 0.19KB
types (record-semantics.js) 1.28KB 0.67KB
types (registry.js) 0.20KB 0.18KB
types (reports.js) 0.20KB 0.18KB
types (spec-report.js) 5.05KB 1.93KB
types (spec-ui-namespace.js) 0.20KB 0.19KB
types (system-fields.js) 3.33KB 1.54KB
types (theme.js) 6.28KB 2.87KB
types (ui-action.js) 3.40KB 1.71KB
types (views.js) 0.20KB 0.18KB
types (widget.js) 0.20KB 0.18KB

Size Limits

  • ✅ Core packages should be < 50KB gzipped
  • ✅ Component packages should be < 100KB gzipped
  • ⚠️ Plugin packages should be < 150KB gzipped

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

2 participants