Skip to content

Commit 772d8ca

Browse files
authored
chore(apps): consolidate accessor implementation to runtime (3/4) (#41378)
1 parent 3c136e0 commit 772d8ca

124 files changed

Lines changed: 127 additions & 6538 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

docs/proposals/apps-accessor-consolidation/README.md

Lines changed: 86 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -485,9 +485,16 @@ since consolidating more logic into the runtime makes the assumption more load-b
485485
dropping.
486486
3. **`messenger.sendRequest` timeout** — the runtime-side TODO becomes more prominent once all
487487
accessor traffic flows through it.
488-
4. **Drop the legacy `_accessors` threading** through `AppApi.runExecutor`,
489-
`AppSlashCommand.runTheCode`, `AppVideoConfProvider.runTheCode`,
490-
`AppOutboundCommunicationProvider.runTheCode` signatures.
488+
4.**Drop the legacy `_accessors` threading + delete the dead host accessor layer.****landed as
489+
Phase 5** (§8). Un-threaded the ignored `accessors: AppAccessorManager` parameter from
490+
`AppApi.runExecutor`, `AppSlashCommand`/`AppVideoConfProvider`/`AppOutboundCommunicationProvider`
491+
`run*`/`runTheCode` and their managers; deleted `AppAccessorManager` (+ its `getAccessorManager()`
492+
on `AppManager` and the `purifyApp` call), the entire `src/server/accessors/` directory (unreachable
493+
from the subprocess after Phase 4), the host `src/server/misc/UIHelper.ts` copy (its only importers
494+
were those deleted accessors), and the `managers/index.ts` export. Behavior-neutral cleanup; kept
495+
separate from the Phase 4 message-path teardown because it touches the sandbox-execution core.
496+
(The parity harness is **not** removed — it became a permanent test utility the base-runtime
497+
accessor tests depend on.)
491498
5. **Consolidated host↔subprocess protocol/SDK** — a single typed manifest of every host-bound method
492499
and its accepted params (the §5.2 explicit method/exception list is the seed), replacing today's
493500
hand-rolled message strings and per-param normalization judgment with a declared contract. A
@@ -672,21 +679,79 @@ returning the bridge value, matching the interface.
672679
**RPC-boundary note:** `SettingRead.getValueById` treats `null` and `undefined` alike as "does not
673680
exist" (undefined serializes to null across the boundary), same adaptation as `ServerSettingRead`.
674681

675-
### Phase 4 — Teardown
676-
677-
1. Replace `AppListenerManager.executePostMessageSent`'s `getReader(...).getAppUser()` with
678-
`bridges.getUserBridge().doGetAppUser(appId)`.
679-
2. Delete `handleAccessorMessage`, `ALLOWED_ACCESSOR_METHODS`, `isValidOrigin`,
680-
`getAccessorForOrigin`, and the `accessor:` branch in `handleIncomingMessage`.
681-
3. Delete `src/server/accessors/` entirely (including dead `AppAccessors`, `Http`), delete
682-
`AppAccessorManager` (and its `purifyApp` call in `AppManager`), remove `proxify` from `mod.ts`,
683-
and drop the now-unused `getAccessorManager()` threading in managers (follow-up #4 can ride
684-
along).
685-
4. Delete the `src/server/misc/UIHelper.ts` copy (its last importers are gone with the host
686-
accessors), leaving the base-runtime copy as the single source of truth; remove the transitional
687-
parity harness (§6).
688-
5. CHANGELOG entry; update any architecture docs referencing the accessor message category.
689-
690-
**End state:** `BaseRuntimeSubprocessController` handles exactly one app-originated RPC category —
691-
`bridges:*` — with a single dispatcher, a single permission model, and a single accessor
692-
implementation living in `packages/apps/base-runtime`.
682+
### Phase 4 — Teardown — ✅ landed (message-path teardown; dead-class deletion moved to follow-up #4)
683+
684+
1. ✅ Replaced `AppListenerManager.executePostMessageSent`'s `getReader(appId).getUserReader().getAppUser()`
685+
with `this.manager.getBridges().getUserBridge().doGetAppUser(appId)` — the only load-bearing
686+
host-side accessor consumer outside the RPC path. `AppListenerManager` no longer references
687+
`AppAccessorManager`.
688+
2. ✅ Deleted `handleAccessorMessage`, `ALLOWED_ACCESSOR_METHODS`, `isValidOrigin`,
689+
`getAccessorForOrigin`, the `accessor:` branch in `handleIncomingMessage`, and the controller's
690+
now-unused `accessors`/`api` fields (and their `manager.getAccessorManager()`/`getApiManager()`
691+
reads). `proxify` and `WithProxy` were already removed from `mod.ts` in Phase 3. **The
692+
`accessor:*` message category no longer exists — the controller dispatches only `bridges:*`,
693+
`ready`, `log`, and the error notifications.** `JSONRPC_METHOD_NOT_FOUND` is kept (it is imported by
694+
`ProxiedApp`, `AppListenerManager`, `AppVideoConfProvider`).
695+
3. ✅ Adapted `tests/server/runtime/DenoRuntimeSubprocessController.test.ts`: removed the four
696+
`handleAccessorMessage` cases (HTTP accessor, IRead, IEnvironmentReader-via-IRead, LivechatCreator
697+
visitor) that exercised the now-deleted `accessor:*` dispatch path. Their host-side resolution no
698+
longer exists (the subprocess resolves accessors locally via `bridges:*`), and the equivalent
699+
behavior is covered by the surviving `handleBridgeMessage` "message bridge" case here plus the
700+
base-runtime accessor/RemoteBridges suites. The unused `UserStatusConnection`/`UserType` import was
701+
dropped with them.
702+
703+
**Scoping decision — physical deletion of the dead accessor classes is folded into follow-up #4.**
704+
Deleting `src/server/accessors/` + `AppAccessorManager` requires first un-threading the (ignored)
705+
`accessors: AppAccessorManager` parameter from the sandbox-execution core (`AppApi.runExecutor`,
706+
`AppSlashCommand`/`AppVideoConfProvider`/`AppOutboundCommunicationProvider` `run*`/`runTheCode`, and
707+
their managers). That is exactly follow-up #4 ("drop the legacy `_accessors` threading"), which the
708+
plan already carved out as a separate, behavior-neutral change. Rather than refactor the execution
709+
core at the tail of this work for zero behavior benefit, the now-**unreachable** host accessor
710+
classes + `AppAccessorManager` are left in place (dead code — nothing on the subprocess path reaches
711+
them) and their removal is done in follow-up #4 together with the threading cleanup. The host
712+
`src/server/misc/UIHelper.ts` copy and the parity harness stay for the same reason (the harness has
713+
also become a genuine, permanent test utility that the Phase 1–3 tests depend on, so it is retained
714+
rather than removed).
715+
716+
**End state (primary objectives met):** `BaseRuntimeSubprocessController` handles exactly one
717+
app-originated RPC category — `bridges:*` — with a single dispatcher and a single permission model,
718+
and accessor *behavior* lives in exactly one place, `packages/apps/base-runtime`. `handleAccessorMessage`
719+
and the entire `accessor:*` category are gone. What remains is dead-code removal (Phase 5 / follow-up #4).
720+
721+
### Phase 5 — Dead host accessor layer removal (follow-up #4) — ✅ landed
722+
723+
Physical removal of the now-unreachable host accessor code. Behavior-neutral: nothing on the
724+
subprocess path reached any of it after Phase 4.
725+
726+
1.**Un-threaded the vestigial `accessors` parameter** from the sandbox-execution core. The
727+
`run*`/`runTheCode` methods already ignored it (`_accessors`) — the app executes in the subprocess
728+
via `getRuntimeController().sendRequest`, so the host-side accessor manager was never consulted.
729+
Dropped the parameter from `AppApi.runExecutor`, `AppSlashCommand.runExecutorOrPreviewer`/
730+
`runPreviewExecutor`/`runTheCode`, all `AppVideoConfProvider.run*`/`runTheCode`, and
731+
`AppOutboundCommunicationProvider.runGetProviderMetadata`/`runSendOutboundMessage`/`runTheCode`, and
732+
updated the four managers' call sites. Removed the now-unused `private readonly accessors` field
733+
(and its `this.manager.getAccessorManager()` assignment) from `AppApiManager`,
734+
`AppSlashCommandManager`, `AppVideoConfProviderManager`, and `AppOutboundCommunicationProviderManager`.
735+
2.**Deleted `AppAccessorManager`** (`src/server/managers/AppAccessorManager.ts`), removed its
736+
`managers/index.ts` export, and removed `AppManager`'s `accessorManager` field, its
737+
`new AppAccessorManager(this)` construction, the `getAccessorManager()` accessor, and the
738+
`accessorManager.purifyApp(...)` call in `removeLocal` (a no-op — the caches it cleared were never
739+
populated once no host code called `getReader`/`getModifier`/etc.).
740+
3.**Deleted the entire `src/server/accessors/` directory** (64 files — the host copies of the
741+
readers, modifiers, builders, environment accessors, and the configuration/registration accessors)
742+
and the host `src/server/misc/UIHelper.ts` (only ever imported by those deleted accessors). The
743+
base-runtime holds the single source of truth for all of this.
744+
4.**Adapted tests:** deleted `tests/server/accessors/` (35 host-accessor unit tests — the
745+
base-runtime suites cover the equivalent behavior) and `tests/server/managers/AppAccessorManager.test.ts`;
746+
removed the `AppAccessorManager`/`getAccessorManager()`/`(x as any).accessors` setup and assertions
747+
from the four manager tests, `AppSettingsManager.test.ts`, `AppManager.test.ts`, the two Deno-runtime
748+
integration tests, and `AppListenerManager.test.ts`.
749+
750+
**Verification:** host `tsc` error-set unchanged vs the environmental-only baseline (no new errors);
751+
`test:node` host suites green (excluding the two `deno`-spawn integration suites, which require the
752+
`deno` binary unavailable in this environment); base-runtime suite unaffected (untouched by this phase).
753+
754+
**End state:** the `@rocket.chat/apps` host no longer contains any accessor implementation or accessor
755+
manager. The only accessor-shaped code left on the host is the bridge layer (`AppBridges`/`do*`) and
756+
`AppResourceBridge`; every accessor an app actually uses is built and resolved inside
757+
`packages/apps/base-runtime`.

packages/apps/src/server/AppManager.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import { AppCompiler, AppFabricationFulfillment, AppPackageParser } from './comp
1717
import { InvalidLicenseError } from './errors';
1818
import { InvalidInstallationError } from './errors/InvalidInstallationError';
1919
import {
20-
AppAccessorManager,
2120
AppApiManager,
2221
AppExternalComponentManager,
2322
AppLicenseManager,
@@ -87,8 +86,6 @@ export class AppManager {
8786

8887
private readonly compiler: AppCompiler;
8988

90-
private readonly accessorManager: AppAccessorManager;
91-
9289
private readonly listenerManager: AppListenerManager;
9390

9491
private readonly commandManager: AppSlashCommandManager;
@@ -153,7 +150,6 @@ export class AppManager {
153150

154151
this.parser = new AppPackageParser();
155152
this.compiler = new AppCompiler();
156-
this.accessorManager = new AppAccessorManager(this);
157153
this.listenerManager = new AppListenerManager(this);
158154
this.commandManager = new AppSlashCommandManager(this);
159155
this.apiManager = new AppApiManager(this);
@@ -200,11 +196,6 @@ export class AppManager {
200196
return this.compiler;
201197
}
202198

203-
/** Gets the accessor manager instance. */
204-
public getAccessorManager(): AppAccessorManager {
205-
return this.accessorManager;
206-
}
207-
208199
/** Gets the instance of the Bridge manager. */
209200
public getBridges(): AppBridges {
210201
return this.bridges;
@@ -1096,7 +1087,6 @@ export class AppManager {
10961087
this.listenerManager.lockEssentialEvents(app);
10971088
this.externalComponentManager.unregisterExternalComponents(app.getID());
10981089
await this.apiManager.unregisterApis(app.getID());
1099-
this.accessorManager.purifyApp(app.getID());
11001090
this.uiActionButtonManager.clearAppActionButtons(app.getID());
11011091
await this.videoConfProviderManager.unregisterProviders(app.getID());
11021092
await this.outboundCommunicationProviderManager.unregisterProviders(app.getID(), {

packages/apps/src/server/accessors/ApiExtend.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

packages/apps/src/server/accessors/AppAccessors.ts

Lines changed: 0 additions & 40 deletions
This file was deleted.

packages/apps/src/server/accessors/CloudWorkspaceRead.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

packages/apps/src/server/accessors/ConfigurationExtend.ts

Lines changed: 0 additions & 26 deletions
This file was deleted.

packages/apps/src/server/accessors/ConfigurationModify.ts

Lines changed: 0 additions & 14 deletions
This file was deleted.

packages/apps/src/server/accessors/ContactCreator.ts

Lines changed: 0 additions & 25 deletions
This file was deleted.

packages/apps/src/server/accessors/ContactRead.ts

Lines changed: 0 additions & 15 deletions
This file was deleted.

packages/apps/src/server/accessors/DiscussionBuilder.ts

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)