Skip to content

Commit d656d62

Browse files
feat(app-shell): Setup › Installed Apps shows app updates, folds modules under their app, and leaves the developer doors to Studio (#34815)
<!-- claude-projects-attribution: {"github_login":"os-support-ai"} --> _Requested by **Yibo Wang** · [project thread](https://claude.ai/code/project/chan_01BVUyyPie8gHwoPM18iABwB?thread=cmsg_01BVUyyPie8gHwoPM18iABwBA6p6wR5XRGmnECFZqr87FM)_ Fixes #34722 Clause-②: yes (widening — locale keys only) Metadata-protocol: none ## 维护者速读 - **改了什么**:设置 › 已安装应用现在会标出应用市场里有新版本的应用("有可用更新 → vX",点击进入该应用的市场页去升级),页首说明有几个应用可升级;一个应用一行,它带的模块包折叠在应用下面按需展开;列改为名称/版本/状态/来源/更新;导入、新建包、平台包开关和"显示全部"只留在 Studio 的包页。 - **为什么改**:管理员在已安装应用里看不到哪些应用该升级,也被内部 ID、Scope、开发者按钮和逐个模块的长列表淹没(#34722,ADR-0146 D1 / ADR-0130 D2)。 - **风险与回滚**:只改前端一个页面在 `?source=marketplace` 时的绘制,Studio 包页(同一组件、不带 source)不变;市场读不到时列表照常显示并加一行说明,绝不显示"已是最新"。回滚=回退本 PR,无数据或接口变化。 - **先看**:`ui/packages/app-shell/src/views/metadata-admin/PackagesPage.tsx` 的 `readUpdateTargets`(何时算"读不到")与 `appOfModule`(模块归属哪个应用);`console/marketplace/__tests__/marketplaceNamespaceBoundary.test.ts` 新增的 hook-gated 门;`PackagesPage.installedAppsUpdates-34722.test.tsx`。 - **两分钟验证**:`pnpm --dir ui exec vitest run packages/app-shell/src/views/metadata-admin/PackagesPage.installedAppsUpdates-34722.test.tsx`,预期 16 passed。 - **需要你做的**:无,席位落地 ## What changes Setup › Installed Apps is the `developer:packages` component opened with `?source=marketplace` (Setup's `nav_marketplace_installed`); Studio › Packages is the same component with no params. The view is told apart by the existing `installedAppsView` flag, so Studio's door is untouched. | | Before | After (Setup › Installed Apps only) | |---|---|---| | Update information | none | the marketplace's own `UpdateAvailableBadge` ("Update available → v6.4.0") plus "Upgrade", linked to `/system/marketplace/PACKAGE_ID` (the route the Details action already opens); a header line "N apps have a newer version in the marketplace." | | Catalog unreadable / no marketplace | n/a | the list renders as before plus one line: "Update information can’t be read from the marketplace right now, so this list can’t say which apps have a newer version." Never drawn as up to date. | | Modules | every package its own row | a `type: 'module'` package that declares exactly one installed app (same source) in `manifest.dependencies` is folded under that app's line; a toggle (aria-expanded, aria-controls) shows it. This is the same tie the server's `isDisableableAppModule` reads. A module declaring two apps, or none in view, stays its own line. A search that hits a module shows it under its app. | | Columns | Name, ID, Version, Scope, Status, Source, Actions | Name, Version, Status, Source, Update, Actions | | Developer doors | Import, New Package, Show platform packages, "Source: Marketplace · Show all" chip | none of them on this view; Studio › Packages keeps all four | How the update is decided: for each app line that has an install-ledger entry, `getMarketplacePackage(packageId)` is read once. The latest version is `package.latest_version?.version ?? versions[0]?.version`, and the badge shows only when `updateTarget(installed, latest)` (the marketplace pages' own rule) answers a version. A 404 means not listed (no badge, no note). Any other failure, or `isMarketplaceEnabled()` false, means unavailable (the note). Modules are never asked about. The namespace gate (decision Q1 = A on the claim amendment): the badge's words live only in the lazy `marketplace` namespace. `InstalledAppUpdateCell` calls `useMarketplaceNamespace()`. While the read or the namespace is loading, the cell holds a skeleton placeholder, never an empty "up to date" cell. When the namespace is ready, it draws `UpdateAvailableBadge`. When the namespace fails, it still shows "→ v6.4.0" and the Upgrade link. `marketplaceNamespaceBoundary.test.ts` gains one declared hook-gated door (`UpdateAvailableBadge.tsx` drawn only from `PackagesPage.tsx`) and asserts through the TypeScript AST that the importer imports and calls the hook. The eager language pack does not grow: this branch has 0 diff lines under `ui/packages/i18n/src/locales/`. Strings: nine keys added to the lazy `studio` namespace in en and zh (`engine.packages.installedApps.col.update`, `.upgrade`, `.updatesSummaryOne`, `.updatesSummary`, `.updatesUnavailable`, `.modulesOne`, `.modules`, `.showModules`, `.hideModules`). Docs: `content/docs/deployment/marketplace-handbook.mdx` said Installed Apps lists "each package of a suite as its own row", which this change makes false. Two sentences now say one line per app, with modules folded under it. Not done here, as the card says: the upgrade flow itself (the link lands on the existing marketplace page), plans and permissions, and the packaged-actions page (#34724). ### Narrowing: the developer doors leave Setup › Installed Apps Import, New Package, the platform-packages switch and the Source chip's "Show all" are no longer drawn when the page is opened with `?source=marketplace` (Q2 = A for the chip). Studio › Packages keeps all of them. These tests pin it: - `PackagesPage.installedAppsUpdates-34722.test.tsx` › "the two doors (objectstack#34722)": - "Setup → Installed Apps draws the administrator columns and none of the developer doors" - "Studio → Packages keeps Import, New Package, the platform switch and the developer columns, and asks no catalog" - "Studio → Packages filtered to another Source keeps its Show all chip" - `PackagesPage.source-12675.test.tsx`: - "`?source=marketplace` shows only the marketplace rows, with no Show all that clears it" (replaces the old pin, which asserted Show all on this door) - "another `?source=` shows only its rows, and Show all clears it" Measured live: the developer door is the same component opened without `source` (Import 1, New Package 1, platform switch 1, columns including ID and Scope). The Studio app shell itself is NOT MEASURED live, because the fixture runtime does not serve the Studio app ("This app can't be opened"). ## Tests All on `ef65831e5c` unless noted; the pushed head `53503c6a26` is the same tree (only a commit message was reworded). - `PackagesPage.installedAppsUpdates-34722.test.tsx` (new, 16 tests): badge plus href plus click; up to date gives no badge and no summary; 404 gives no badge and no note; counts two apps; 502 gives the note with rows still listed; marketplace disabled gives no catalog read plus the note; apps only are asked; zh badge "有可用更新 → v6.4.0"; namespace loading gives a placeholder; namespace failed gives "→ v6.4.0" plus the link; HotCRM one line, with four modules on demand; two-apps, orphan and code-app modules stay unfolded; search "cpq" shows the module under its app; plus the three door tests above. - `PackagesPage.source-12675.test.tsx`: one pin replaced, one added (24 tests). - `marketplaceNamespaceBoundary.test.ts`: new `it.each` "%s is drawn only by importers that ask for the namespace themselves (objectstack#34722)" (6 tests). - Final run: `os-verify-lock.sh -c "pnpm --dir ui exec vitest run --maxWorkers=2 PackagesPage.installedAppsUpdates-34722 PackagesPage.source-12675 marketplaceNamespaceBoundary"`, `VERDICT command-exit 0`, Test Files 3 passed (3), Tests 46 passed (46). - Wider related run (earlier head `a175016b49`): PackagesPage.*, ResourceListPage.*, Create/EditPackageDialog, `console/marketplace/__tests__`, spec-symbol-parity, the product-neutral ratchet, the studio and marketplace namespace suites, and en/zh and all-locales parity. 98 files, 1047/1048 passed; the one failure was the source-12675 pin the Q2 decision changes, since fixed. - Type-check: `pnpm --filter @object-ui/app-shell type-check` (tsc and tsconfig.test.json), TC_EXIT=0 on `8fc8e215a5` (`ef65831e5c` adds docs only). <details><summary>Ablations (each red, each restored to blob == HEAD with `git diff HEAD` empty)</summary> Run with `node scripts/ablation-replace.mjs` (anchor hit x1 to x0, auto-restore, blob verified against HEAD `5356cfce1ec3` of PackagesPage.tsx). These are vitest-from-source suites, so no `dist/` leg applies. | Mutation | Result | |---|---| | `updateTarget(...)` replaced by `null` (badge) | 5 failed / 16 | | catalog failure no longer sets unavailable | 1 failed / 16 | | marketplace-disabled no longer sets unavailable | 1 failed / 16 | | `appOfModule` returns null (no folding) | 2 failed / 16 | | header actions drawn on both doors | 1 failed / 16 | | namespace-loading no longer holds the placeholder | 1 failed / 16 | | Show-all chip drawn on both doors | 1 failed / 16 | | `useMarketplaceNamespace()` call removed (boundary suite) | 2 failed / 6 | </details> ## Acceptance notes - **Acceptance 4 is measured on a fixture, not on HotCRM.** The live fold was read on `examples/app-multi-package`, whose served `com.example.multi.orders` row is `{"type":"module","dependencies":{"com.example.multi.core":"^1.0.0"}}`: one module under one app. HotCRM's four-module shape is pinned only in the unit suite. HotCRM itself is NOT MEASURED live. - **Live readings used a stubbed catalog** (allowed by the brief). The page requests were intercepted to mark the two example rows `source: marketplace` at 6.2.0, with an install-ledger entry `pkg_multi_core` and the catalog answering 6.4.0 / 6.2.0 / 502. Everything else came from the real backend. - **Modules have no Update cell and no row action.** An app's update covers the modules it brought (ADR-0130 D2). A module row still opens the detail sheet, where Disable lives, as before. - **Out of scope, observed (class a, user-visible truncation):** on the developer door (`/apps/setup/component/developer/packages`, no `source`) at a 1400 px viewport, the Actions column is clipped by the table's overflow. This is unchanged by this PR (that table branch is untouched). Reach: live screenshot of that URL at 1400x900. Reported to the seat to file. Dedupe words: packages table actions column clipped, overflow, Studio packages. ## Verification - `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` at `ef65831e5c` (same tree as head `53503c6a26`): 71 families derived, all run locally, each exit code below. `--ran` reconciliation: see details. - `check-eager-closure-budget` (after `pnpm --filter '@object-ui/console^...' build` and `pnpm --filter @object-ui/console build`, lock `VERDICT command-exit 0`): **i18n-locale-en 60.2 KB / 60.5 KB ceiling (headroom 0.4 KB)**; the aggregate eager closure is 1893.2 KB / 2431.6 KB. The headroom is the existing headroom: this branch changes no file under `ui/packages/i18n/src/locales/`. - `node scripts/pm/overlap-check.mjs --branch=claude/issue-34722-installed-apps-updates`: `VERDICT clean exit 0` before each push. - Not run locally, CI-owned: `test:repo`, repo-wide lint, the full lint-workflow farm. Full dogfood is not owed (no `!` in the title, no narrowing arm on Clause-②). <details><summary>Derived gate families, 71 of 71, exit codes</summary> Run on `ef65831e5c`. `53503c6a26` (the pushed head) is the same tree, `0607e32a0d`; only the docs commit message was reworded. - `node scripts/check-adr-0087-registration.mjs --base origin/main` · exit 0 - `node scripts/check-adr-0087-registration.mjs --self-test` · exit 0 - `node scripts/check-adr-links.mjs` · exit 0 - `node scripts/check-adr-links.mjs --self-test` · exit 0 - `node scripts/check-changeset-no-major.mjs --base origin/main` · exit 0 - `node scripts/check-closing-keyword-parity.mjs` · exit 0 - `node scripts/check-closing-keyword-parity.mjs --self-test` · exit 0 - `node scripts/check-comment-mask-corpus.mjs` · exit 0 - `node scripts/check-doc-route-spelling.mjs --advisory` · exit 0 - `node scripts/check-doc-route-spelling.mjs --self-test` · exit 0 - `node scripts/check-docs-section-name.mjs` · exit 0 - `node scripts/check-docs-section-name.mjs --self-test` · exit 0 - `node scripts/check-empty-changeset.mjs --base origin/main` · exit 0 - `node scripts/check-empty-changeset.mjs --self-test` · exit 0 - `node scripts/check-sdui-manifest.mjs` · exit 0 - `node scripts/check-sdui-manifest.mjs --self-test` · exit 0 - `node scripts/check-section-landing-index.mjs` · exit 0 - `node scripts/check-section-landing-index.mjs --self-test` · exit 0 - `node scripts/ci/plan-test-core-shards.mjs --self-test` · exit 0 - `node scripts/ci/snapshot-next.mjs --self-test` · exit 0 - `node scripts/pm/check-governed-queue-guard.mjs --self-test` · exit 0 - `node scripts/pm/release-rehearsal-clone.mjs --self-test` · exit 0 - `node scripts/release-pending-publish.mjs --self-test` · exit 0 - `pnpm --dir ui exec vitest run scripts/` · exit 0 - `pnpm --filter @objectstack/lint run check:doc-formula-expressions` · exit 0 - `pnpm --filter @objectstack/lint run check:doc-security-posture` · exit 0 - `pnpm --filter @objectstack/spec run check:docs` · exit 0 - `pnpm --filter @objectstack/spec run check:duration-unit-keys` · exit 0 - `pnpm --filter @objectstack/spec run check:empty-state` · exit 0 - `pnpm --filter @objectstack/spec run check:error-code-provenance` · exit 0 - `pnpm --filter @objectstack/spec run check:liveness` · exit 0 - `pnpm --filter @objectstack/spec run check:skill-examples` · exit 0 - `pnpm --filter @objectstack/spec run check:strictness-ledger` · exit 0 - `pnpm --filter @objectstack/spec run check:variant-docs` · exit 0 - `pnpm --filter @objectstack/spec run check:yaml-examples` · exit 0 - `pnpm check:adr-anchors` · exit 0 - `pnpm check:changeset-gate-self-tests` · exit 0 - `pnpm check:ci-filter-parity` · exit 0 - `pnpm check:closed-ceremony-text` · exit 0 - `pnpm check:corpus-claim-drift` · exit 0 - `pnpm check:cross-package-test-inputs` · exit 0 - `pnpm check:dispatcher-error-vocabulary` · exit 0 - `pnpm check:doc-anchors` · exit 0 - `pnpm check:doc-authoring` · exit 0 - `pnpm check:doc-frontmatter` · exit 0 - `pnpm check:docs-audit-scope` · exit 0 - `pnpm check:docs-redirects` · exit 0 - `pnpm check:docs-single-h1` · exit 0 - `pnpm check:docs-spec-enumerations` · exit 0 - `pnpm check:docs-transcript-drift` · exit 0 - `pnpm check:driver-memory-census` · exit 0 - `pnpm check:engine-double-contract` · exit 0 - `pnpm check:gitlink-declared` · exit 0 - `pnpm check:nul-bytes` · exit 0 - `pnpm check:published-files` · exit 0 - `pnpm check:published-readme-links` · exit 0 - `pnpm check:query-options-erasure` · exit 0 - `pnpm check:react-page-adapter-contract` · exit 0 - `pnpm check:refd-timer-probe` · exit 0 - `pnpm check:registry-log-declared` · exit 0 - `pnpm check:rest-log-spy-declared` · exit 0 - `pnpm check:role-word` · exit 0 - `pnpm check:skill-identifier-liveness` · exit 0 - `pnpm check:test-source-alias` · exit 0 - `pnpm check:tier-file-adoption` · exit 0 - `pnpm check:type-check-coverage` · exit 0 - `pnpm check:type-check-debt` · exit 0 - `pnpm check:undeclared-dep-imports` · exit 0 - `pnpm check:vendor-version-stamps` · exit 0 - `pnpm check:watch-hint-literal` · exit 0 - `pnpm check:where-matcher` · exit 0 `pnpm --dir ui exec vitest run scripts/` (under the lock): Test Files 171 passed, 2 skipped (173); Tests 5077 passed, 2 skipped (5079). `dispatch-gates --ran`: "Run reconciliation — 71 derived, 71 run, 0 NOT-MEASURED, 0 UNRUN", exit 0. `node scripts/check-nul-bytes.mjs`: OK, exit 0. </details> <details><summary>Live readings (Chromium, fixture runtime plus Console dev server)</summary> Fixture: `examples/app-multi-package`, booted with `objectstack dev --seed-admin --fresh`; Console vite dev server proxied to it. These readings were taken from the working tree that was committed as `8fc8e215a5` 46 s later, with the Console serving source. `ef65831e5c` adds docs only. - A1, update available: cell text "Update available → v6.4.0" + "Upgrade"; href `/apps/com.objectstack.setup/system/marketplace/pkg_multi_core`; the click lands on that path; summary "1 app has a newer version in the marketplace."; one catalog read, `/api/v1/marketplace/packages/pkg_multi_core`; headers Name, Version, Status, Source, Update, Actions; Import 0, New Package 0, platform switch 0, Source chip 0. - A2, up to date (catalog 6.2.0): badge 0, summary 0, unavailable note 0. - A3, catalog 502: app row listed 1; note "Update information can’t be read from the marketplace right now, so this list can’t say which apps have a newer version."; badge 0. - A4, folding: orders row 0 before, toggle aria-expanded "false"; after the click, orders row 1 with `data-module-of="com.example.multi.core"`. - Developer door (same component without `source`): Import 1, New Package 1, platform switch 1; headers Name, ID, Version, Scope, Status, Source, Actions; orders row 1; catalog reads 0. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01WGufziunkXbDT7wUWqfmWz)_ <!-- signed: repo:objectstack#3 · os-support-ai · session_01WGufziunkXbDT7wUWqfmWz --> --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>
1 parent 4fb8790 commit d656d62

8 files changed

Lines changed: 913 additions & 12 deletions

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
'@object-ui/i18n': patch
4+
---
5+
6+
feat(app-shell): Setup › Installed Apps shows which apps have a newer version, links to their upgrade, and folds module packages under their app
7+
8+
Clause-②: yes (widening — locale keys only)
9+
Metadata-protocol: none
10+
11+
Setup › Installed Apps (the Packages page opened with `?source=marketplace`) is now the administrator's view of installed apps:
12+
13+
- **Update available.** When the marketplace lists an app at a higher version than the one installed, the app's line shows the marketplace's own "Update available → vX" badge, decided by the same rule the marketplace pages use. The badge links to the app's marketplace page, where the upgrade runs unchanged. The page also says how many apps have a newer version. An app that is up to date, or that the catalog does not list, has no badge.
14+
- **Catalog unavailable.** When the catalog cannot be read, or the runtime has no marketplace, the list is drawn as before with one line saying the update information cannot be read. It is never drawn as "up to date".
15+
- **One line per app.** A module package (`type: 'module'`) that declares its app in `manifest.dependencies` is folded under that app's line and shown on demand. The tie is the one the server's disable door already reads. No new key is involved.
16+
- **Administrator columns.** The columns are Name, Version, Status, Source and Update. The package id and the Scope badge stay on Studio's Packages.
17+
- **Developer doors stay in Studio.** Import, New Package, the platform packages switch and the Source chip's "Show all" are not drawn on this view. Studio › Overview › Packages, the same page without `source`, keeps all of them.
18+
19+
The badge's words stay in the lazy `marketplace` namespace, which this view now loads. The console's eager language pack does not grow. Nine new strings are added to the lazy `studio` namespace, in English and Chinese.

‎content/docs/deployment/marketplace-handbook.mdx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,9 @@ the detail.
234234
with `?keepData=true` every row stays, sample rows included, and no door
235235
tells them apart any more, so purge first if you want them gone.
236236
7. **Enable and disable.** **Setup → Installed Apps** lists the apps installed
237-
from the marketplace, each package of a suite as its own row. An admin with
237+
from the marketplace, one line per app: a module package that declares
238+
exactly one installed app in its `manifest.dependencies` is folded under
239+
that app's line, and the app's toggle shows it. An admin with
238240
`manage_metadata` may disable a writable package, and a **module of an
239241
installed app**: a `type: 'module'` package that declares an installed
240242
`type: 'app'` package in its `manifest.dependencies`
@@ -296,7 +298,7 @@ An app ships extras in one of two shapes:
296298
A customer who does not use one of your modules can switch it off, per
297299
environment, with `PATCH /api/v1/packages/:id/disable`, and back on with
298300
`PATCH /api/v1/packages/:id/enable`. In the Console, the admin opens the
299-
module's row in **Setup → Installed Apps** (or **Setup → Packages** for a suite
301+
module's row under its app's line in **Setup → Installed Apps** (or **Setup → Packages** for a suite
300302
booted from code) and presses **Disable**, then confirms. The row's
301303
`disableable` key on `GET /api/v1/packages` is the runtime's own answer to
302304
whether the disable door accepts the package, and the Console offers

‎ui/packages/app-shell/src/console/marketplace/__tests__/marketplaceNamespaceBoundary.test.ts‎

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@
2121
* 3. walks every OTHER door's relative imports inside this directory
2222
* (transitively) and holds that every `marketplace.*` key those files
2323
* spell is in the RESIDENT pack — the package entry's `en`, which holds no
24-
* namespace key.
24+
* namespace key;
25+
* 4. treats a door as gated by its importers only when it is DECLARED in
26+
* {@link HOOK_GATED_DOORS}: every file outside this directory that imports
27+
* it is listed there, and each listed file asks for the namespace itself
28+
* (`useMarketplaceNamespace()`), drawing the door's component only once it
29+
* is ready (objectstack#34722). An undeclared importer makes the door an
30+
* ordinary ungated one again, so step 3 reads its keys.
2531
*
2632
* TypeScript's own parser reads the sources, so a key or an import written in
2733
* a comment is never read as code.
@@ -42,6 +48,22 @@ const rel = (file: string) => relative(UI_ROOT, file).split(sep).join('/');
4248
/** The pages behind the frame: what reaches them is gated by construction. */
4349
const GATED_PAGES = ['MarketplacePage.tsx', 'MarketplacePackagePage.tsx'].map((f) => join(MARKETPLACE_DIR, f));
4450

51+
/**
52+
* Doors whose every outside importer asks for the namespace itself, door by
53+
* door (step 4): the door file, then the files allowed to import it.
54+
*/
55+
const HOOK_GATED_DOORS = new Map<string, readonly string[]>([
56+
[
57+
join(MARKETPLACE_DIR, 'UpdateAvailableBadge.tsx'),
58+
// Setup → Installed Apps draws the badge in its Update cell (objectstack#34722).
59+
['packages/app-shell/src/views/metadata-admin/PackagesPage.tsx'],
60+
],
61+
]);
62+
63+
/** The namespace module, and the hook a hook-gated importer must call from it. */
64+
const NAMESPACE_MODULE = '@object-ui/i18n/namespaces/marketplace';
65+
const NAMESPACE_HOOK = 'useMarketplaceNamespace';
66+
4567
const isSource = (name: string) =>
4668
/\.(ts|tsx)$/.test(name) && !/\.(test|spec)\.(ts|tsx)$/.test(name) && !name.endsWith('.d.ts');
4769

@@ -155,10 +177,48 @@ for (const file of allSources()) {
155177
}
156178
}
157179

180+
/**
181+
* A declared hook-gated door whose outside importers are all declared for it
182+
* and all call the namespace hook (step 4); anything less leaves it ungated.
183+
*/
184+
const isHookGated = (file: string) => {
185+
const allowed = HOOK_GATED_DOORS.get(file);
186+
return (
187+
!!allowed &&
188+
[...(doors.get(file) ?? [])].every(
189+
(importer) => allowed.includes(importer) && callsNamespaceHook(join(UI_ROOT, importer)),
190+
)
191+
);
192+
};
193+
194+
/** Whether `file` imports {@link NAMESPACE_HOOK} from {@link NAMESPACE_MODULE} and calls it. */
195+
function callsNamespaceHook(file: string): boolean {
196+
const sf = parse(file);
197+
let imported = false;
198+
let called = false;
199+
const visit = (node: ts.Node) => {
200+
if (
201+
ts.isImportDeclaration(node) &&
202+
ts.isStringLiteral(node.moduleSpecifier) &&
203+
node.moduleSpecifier.text === NAMESPACE_MODULE &&
204+
node.importClause?.namedBindings &&
205+
ts.isNamedImports(node.importClause.namedBindings) &&
206+
node.importClause.namedBindings.elements.some((e) => e.name.text === NAMESPACE_HOOK && !e.propertyName)
207+
) {
208+
imported = true;
209+
} else if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === NAMESPACE_HOOK) {
210+
called = true;
211+
}
212+
ts.forEachChild(node, visit);
213+
};
214+
visit(sf);
215+
return imported && called;
216+
}
217+
158218
/** Every file in this directory reachable from an ungated door, following relative imports inside it. */
159219
const ungated = new Set<string>();
160220
{
161-
const queue = [...doors.keys()].filter((file) => !GATED_PAGES.includes(file));
221+
const queue = [...doors.keys()].filter((file) => !GATED_PAGES.includes(file) && !isHookGated(file));
162222
while (queue.length > 0) {
163223
const file = queue.pop()!;
164224
if (ungated.has(file) || GATED_PAGES.includes(file)) continue;
@@ -218,6 +278,23 @@ describe('the marketplace namespace boundary (objectstack#30588)', () => {
218278
expect(outside).toEqual([]);
219279
});
220280

281+
it.each([...HOOK_GATED_DOORS].map(([door, importers]) => [rel(door), door, importers] as const))(
282+
'%s is drawn only by importers that ask for the namespace themselves (objectstack#34722)',
283+
(_name, door, importers) => {
284+
// Lit control: the door really is imported from outside this directory.
285+
const actual = [...(doors.get(door) ?? [])];
286+
expect(actual.length).toBeGreaterThan(0);
287+
// Every outside importer is declared for it — an undeclared one would
288+
// draw the door's keys without the namespace.
289+
expect(actual.filter((importer) => !importers.includes(importer))).toEqual([]);
290+
for (const importer of importers) {
291+
expect(callsNamespaceHook(join(UI_ROOT, importer)), `${importer} calls ${NAMESPACE_HOOK}()`).toBe(true);
292+
}
293+
// And the door is outside the resident-key walk only because of this.
294+
expect(ungated.has(door)).toBe(false);
295+
},
296+
);
297+
221298
it('the probe key the frame waits on is NOT resident (the pack really is lighter)', () => {
222299
expect(lookup(en, 'marketplace.title')).toBeUndefined();
223300
expect(typeof lookup(en, 'marketplace.action.uninstall')).toBe('string');

0 commit comments

Comments
 (0)