Skip to content

Commit 789b5aa

Browse files
committed
Preserve structured WP-CLI recipe results
1 parent 6aa2b97 commit 789b5aa

3 files changed

Lines changed: 88 additions & 1 deletion

File tree

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,7 @@
275275
"test:cache-churn-observation-contracts": "tsx tests/cache-churn-observation-contracts.test.ts",
276276
"test:wordpress-db-contracts": "tsx tests/wordpress-db-contracts.test.ts",
277277
"test:wp-cli-temporary-script": "tsx tests/wp-cli-temporary-script.test.ts",
278+
"test:wp-cli-recipe-result": "tsx tests/wp-cli-recipe-result.test.ts",
278279
"test:browser-sdk-facade": "tsx tests/browser-sdk-facade.test.ts",
279280
"check": "npm run test:production-boundary-enforcement && npm run smoke -- --group=check"
280281
},

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1480,7 +1480,10 @@ class PlaygroundRuntime implements Runtime {
14801480
},
14811481
this.runtimeId,
14821482
argv,
1483-
(scriptPath) => this.runPlaygroundCommand("wordpress.wp-cli", server, { scriptPath }),
1483+
async (scriptPath) => {
1484+
const response = await this.runPlaygroundCommand("wordpress.wp-cli", server, { scriptPath })
1485+
return { ...response, text: response.text }
1486+
},
14841487
)
14851488
}
14861489

tests/wp-cli-recipe-result.test.ts

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import assert from "node:assert/strict"
2+
import { mkdtemp, rm } from "node:fs/promises"
3+
import { tmpdir } from "node:os"
4+
import { join } from "node:path"
5+
import { createRuntime } from "../packages/runtime-core/src/index.js"
6+
import { executeRecipeWorkflowStep } from "../packages/cli/src/commands/recipe-run-workflow-evidence.js"
7+
import { createPlaygroundRuntimeBackend } from "../packages/runtime-playground/src/index.js"
8+
import type { PlaygroundCliModule } from "../packages/runtime-playground/src/playground-cli-runner.js"
9+
10+
const root = await mkdtemp(join(tmpdir(), "wp-codebox-wp-cli-result-"))
11+
const wordpressDirectory = join(root, "wordpress")
12+
const files = new Map<string, string>()
13+
const payload = { schema: "example/validation-result/v1", status: "ok", evidence: { retained: true } }
14+
let wrapperPath = ""
15+
16+
const cliModule: PlaygroundCliModule = {
17+
async runCLI() {
18+
return {
19+
serverUrl: "http://127.0.0.1:9404",
20+
playground: {
21+
async writeFile(path, contents) {
22+
files.set(path, contents)
23+
wrapperPath = path
24+
},
25+
unlink(path) {
26+
files.delete(path)
27+
},
28+
async run(options) {
29+
assert.ok("scriptPath" in options)
30+
const scriptPath = options.scriptPath
31+
assert.equal(files.has(scriptPath), true, "WP-CLI wrapper must exist while the command runs")
32+
return {
33+
exitCode: 0,
34+
errors: "",
35+
get text() {
36+
return files.has(scriptPath) ? `${JSON.stringify(payload)}\n` : ""
37+
},
38+
}
39+
},
40+
},
41+
async [Symbol.asyncDispose]() {},
42+
}
43+
},
44+
}
45+
46+
const runtime = await createRuntime({
47+
backend: "wordpress-playground",
48+
artifactsDirectory: join(root, "artifacts"),
49+
environment: {
50+
kind: "wordpress",
51+
name: "wp-cli-result",
52+
version: "mounted-wordpress-source",
53+
phpVersion: "8.4",
54+
wordpressInstallMode: "do-not-attempt-installing",
55+
assets: { wordpressDirectory },
56+
blueprint: {},
57+
},
58+
policy: {
59+
network: "deny",
60+
filesystem: "sandbox",
61+
commands: ["wordpress.wp-cli"],
62+
secrets: "none",
63+
approvals: "never",
64+
},
65+
}, createPlaygroundRuntimeBackend({ cliModule }))
66+
67+
try {
68+
const execution = await executeRecipeWorkflowStep(runtime, {
69+
phase: "steps",
70+
index: 0,
71+
step: { command: "wordpress.wp-cli", args: ["command=example validate --format=json"] },
72+
}, root)
73+
74+
assert.equal(execution.exitCode, 0)
75+
assert.equal(files.has(wrapperPath), false, "completed WP-CLI wrappers must be cleaned up")
76+
assert.equal(execution.stdout, `${JSON.stringify(payload)}\n`)
77+
assert.deepEqual(execution.result?.json, payload, "recipe output must retain successful structured WP-CLI output")
78+
} finally {
79+
await runtime.destroy()
80+
await rm(root, { recursive: true, force: true })
81+
}
82+
83+
console.log("WP-CLI recipe result survives temporary wrapper cleanup")

0 commit comments

Comments
 (0)