fix(core): pass site context to sandboxed plugins#2081
Conversation
🦋 Changeset detectedLatest commit: cb9c38e The changes in this PR will be included in the next version bump. This PR includes changesets to release 16 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
This is a focused, correct fix for #1872. The runtime was already reading site information during cold start, but the sandbox runner factory was being invoked without it, so the generated plugin wrapper baked an empty base URL into ctx.url(). The new createSandboxRunnerOptions helper reuses the same createSiteInfo normalization that trusted plugin contexts use, keeping sandboxed and trusted plugins consistent. The change threads siteInfo through all three runner construction sites (configured, marketplace, and registry plugins), adds a regression unit test for the helper and an integration test for the runtime wiring, and includes a patch changeset. No user-facing UI strings, migrations, SQL, or authorization changes are involved.
I checked the changed files, the adapter implementations (@emdash-cms/cloudflare, @emdash-cms/workerd), the virtual-module declarations, and the wrapper generators; the only remaining cleanup is a stale type cast in astro/middleware.ts that still describes the pre-refactor sandbox-runner signature.
Findings
-
[suggestion]
packages/core/src/astro/middleware.ts:203-215buildDependenciesstill castssandboxModule.createSandboxRunnerto the old inline signature that only knowsdbandmediaStorage. SinceRuntimeDependencies.createSandboxRunneris nowSandboxRunnerFactory, this narrower cast is stale and misleading — it obscures the fact that the runtime will call the factory withsiteInfotoo. Please switch the cast toSandboxRunnerFactory | nulland addSandboxRunnerFactoryto the existingplugins/sandbox/types.jsimport (replacing the now-unusedSandboxRunnerimport).Replace the cast on lines 203–215 with:
createSandboxRunner: sandboxModule.createSandboxRunner as SandboxRunnerFactory | null,And update the import on line 50 to:
import type { SandboxRunnerFactory } from "../plugins/sandbox/types.js";
There was a problem hiding this comment.
Re-review of #2081. The previous finding is fully resolved: packages/core/src/astro/middleware.ts now imports SandboxRunnerFactory and casts createSandboxRunner to SandboxRunnerFactory | null, removing the stale inline signature.
I re-read the diff, the full changed files, and the Cloudflare/workerd adapter implementations. The fix is correct and complete:
- The new
createSandboxRunnerOptionshelper reusescreateSiteInfofrom trusted plugin contexts, so sandboxed plugins get the same normalizedctx.site/ctx.url()behavior. siteInfois threaded through all three runner creation sites: configured sandboxed plugins (loadSandboxedPlugins), marketplace plugins, and registry plugins (both vialoadInstalledSandboxedPlugins).- Both platform runners (
CloudflareSandboxRunnerandWorkerdSandboxRunner) already consumedoptions.siteInfo, so passing it from the runtime is sufficient. - Regression coverage includes a unit test for the helper and an integration test verifying the runtime calls the factory with normalized site info.
- The patch changeset is user-facing and appropriate; no UI strings, SQL, migrations, or authorization changes are involved.
No new issues found. LGTM.
What does this PR do?
Forwards normalized site information to sandbox runners created for configured, marketplace, and registry-installed plugins. Sandboxed plugin contexts can now build absolute same-site URLs through
ctx.url(path)whenemdash:site_urlis configured.The runtime already resolved site information during cold start, but runner construction discarded it. The runner therefore generated plugin wrappers with an empty base URL.
Closes #1872
Type of change
Checklist
pnpm --filter emdash typecheckpassesValidation
pnpm --filter emdash typecheckpnpm --filter emdash buildpnpm --filter emdash checkvitest run tests/unit/plugins/sandbox-runner-options.test.ts tests/integration/runtime/create.test.tsoxlint --type-aware --deny-warningson changed source and test filesoxfmt --checkon changed source and test filesprettier --check .changeset/sandbox-plugin-site-context.md