Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/runtime-playground/src/playground-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,10 @@ export interface PlaygroundRuntimeBackendOptions {
cliModule?: PlaygroundCliModule
}

export function materializePlaygroundRunResponse(response: PlaygroundRunResponse): PlaygroundRunResponse {
return { ...response, text: response.text }
}

class PlaygroundRuntime implements Runtime {
private status: RuntimeInfo["status"] = "created"
private readonly runtimeId = id("runtime")
Expand Down Expand Up @@ -1788,7 +1792,8 @@ class PlaygroundRuntime implements Runtime {
const response = await this.executeRequestWorker(server, options.code, requestWorkerEnvironment, this.executionSignals.getStore())
return { text: response.text, exitCode: response.ok ? 0 : 1, ...(!response.ok ? { errors: response.text } : {}) }
}
return await abortable(server.playground.run(options), this.executionSignals.getStore())
const response = await abortable(server.playground.run(options), this.executionSignals.getStore())
return materializePlaygroundRunResponse(response)
} catch (error) {
const payload = "code" in options ? options.code : options.scriptPath
throw new PlaygroundCommandCrashError(command, error, {
Expand Down
23 changes: 23 additions & 0 deletions tests/plugin-state-command.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import assert from "node:assert/strict"
import { commandRegistry } from "../packages/runtime-core/src/command-registry.js"
import { pluginStateInputFromArgs, pluginStatePhpCode } from "../packages/runtime-playground/src/plugin-state-command-handlers.js"
import { materializePlaygroundRunResponse } from "../packages/runtime-playground/src/playground-runtime.js"
import { runPluginStateCommand } from "../packages/runtime-playground/src/wordpress-command-runners.js"

const command = commandRegistry.find((definition) => definition.id === "wordpress.plugin-state")
const ensureCommand = commandRegistry.find((definition) => definition.id === "wordpress.ensure-plugin-active")
Expand Down Expand Up @@ -37,4 +39,25 @@ assert.match(php, /networkActivePluginsAfter/)
assert.match(php, /artifactRefs/)
assert.doesNotMatch(JSON.stringify(command), /homeboy|woocommerce|hbx/i)

const pluginStateJson = JSON.stringify({ schema: "wp-codebox/wordpress-plugin-state/v1", active_plugins: ["example/example.php"] })
let responseAvailable = true
const lazyResponse = new Proxy({ exitCode: 0 }, {
get(target, property, receiver) {
return property === "text" ? responseAvailable ? pluginStateJson : "\0" : Reflect.get(target, property, receiver)
},
})
const materializedResponse = materializePlaygroundRunResponse(lazyResponse as never)
responseAvailable = false
assert.equal(typeof materializedResponse.text, "string")
assert.deepEqual(JSON.parse(materializedResponse.text), JSON.parse(pluginStateJson))

const pluginStateOutput = await runPluginStateCommand({
runPlaygroundCommand: async () => materializedResponse,
runtimeSpec: { environment: { kind: "wordpress" } } as never,
server: {} as never,
spec: { command: "wordpress.plugin-state", args: ["plugin=example"] } as never,
})
assert.equal(typeof pluginStateOutput, "string")
assert.deepEqual(JSON.parse(pluginStateOutput), JSON.parse(pluginStateJson))

console.log("plugin-state command ok")
Loading