Skip to content

Commit 1f23ce2

Browse files
committed
fix: preserve passwordless database worker isolation
1 parent bf60423 commit 1f23ce2

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

packages/runtime-playground/src/playground-cli-runner.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export async function startPlaygroundCliServer(spec: RuntimeCreateSpec, mounts:
8080
const wordpressInstallMode = spec.environment.wordpressInstallMode ?? "install-from-existing-files"
8181
const bootstrapIniEntries = runtimeBootstrapPhpIniEntries(spec)
8282
const useProgrammaticRunner = shouldUseProgrammaticPlaygroundRunner(spec, options)
83-
const requestWorkerEndpoint = useProgrammaticRunner || spec.environment.databaseSetup === "external" ? undefined : {
83+
const requestWorkerEndpoint = useProgrammaticRunner || connectorSecretPassword(spec) !== undefined ? undefined : {
8484
route: `/wp-codebox-execute-${randomBytes(12).toString("hex")}.php`,
8585
token: randomBytes(32).toString("base64url"),
8686
payloadDirectory: join(spec.artifactsDirectory ?? "artifacts", "playground-internal-shared"),
@@ -480,7 +480,7 @@ require_once ABSPATH . 'wp-settings.php';
480480
}
481481

482482
function withConnectorSecretEnvironment(server: PlaygroundCliServer, spec: RuntimeCreateSpec): PlaygroundCliServer {
483-
const password = spec.environment.databaseSetup === "external" ? spec.secretEnv?.DB_PASSWORD : undefined
483+
const password = connectorSecretPassword(spec)
484484
if (password === undefined) return server
485485
return {
486486
...server,
@@ -493,6 +493,10 @@ function withConnectorSecretEnvironment(server: PlaygroundCliServer, spec: Runti
493493
}
494494
}
495495

496+
function connectorSecretPassword(spec: RuntimeCreateSpec): string | undefined {
497+
return spec.environment.databaseSetup === "external" ? spec.secretEnv?.DB_PASSWORD : undefined
498+
}
499+
496500
function distributionBootstrapPhp(spec: RuntimeCreateSpec): string {
497501
const distribution = recipeDistribution(spec)
498502
if (!distribution) {

tests/playground-cli-runner-bootstrap-ini.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ try {
103103
assert.match(externalWpConfig, /define\('DB_PASSWORD', \(string\) getenv\('DB_PASSWORD'\)\)/)
104104
assert.doesNotMatch(externalWpConfig, /secret/)
105105

106+
calls.length = 0
107+
const passwordlessExternalServer = await startPlaygroundCliServer({ ...spec, secretEnv: {} }, [], { cliModule })
108+
await passwordlessExternalServer[Symbol.asyncDispose]()
109+
assert.equal(calls[0]?.["mount-before-install"]?.some((mount) => mount.vfsPath === "/internal/wp-codebox"), true, "passwordless external databases retain isolated request workers")
110+
assert.equal(calls[0]?.["mount-before-install"]?.some((mount) => /^\/wordpress\/wp-codebox-execute-[a-f0-9]{24}\.php$/.test(mount.vfsPath)), true)
111+
106112
calls.length = 0
107113
const defaultRuntimeIniSpec: RuntimeCreateSpec = {
108114
...spec,

0 commit comments

Comments
 (0)