-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplayground-cli-runner-bootstrap-ini.test.ts
More file actions
129 lines (116 loc) · 5.06 KB
/
Copy pathplayground-cli-runner-bootstrap-ini.test.ts
File metadata and controls
129 lines (116 loc) · 5.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import assert from "node:assert/strict"
import { mkdtemp, readFile, rm, stat } from "node:fs/promises"
import { join } from "node:path"
import { tmpdir } from "node:os"
import { startPlaygroundCliServer, type PlaygroundCliModule } from "../packages/runtime-playground/src/playground-cli-runner.js"
import type { RuntimeCreateSpec } from "../packages/runtime-core/src/index.js"
const wordpressDevelopDirectory = await mkdtemp(join(tmpdir(), "wp-codebox-wordpress-develop-"))
const artifactsDirectory = await mkdtemp(join(tmpdir(), "wp-codebox-artifacts-"))
const calls: Parameters<PlaygroundCliModule["runCLI"]>[0][] = []
const cliModule: PlaygroundCliModule = {
async runCLI(options) {
calls.push(options)
return {
serverUrl: "http://127.0.0.1:65535",
playground: {
async run() {
return { text: "" }
},
},
async [Symbol.asyncDispose]() {},
}
},
}
try {
const spec: RuntimeCreateSpec = {
backend: "wordpress-playground",
environment: {
version: "mounted-wordpress-source",
phpVersion: "8.4",
wordpressInstallMode: "do-not-attempt-installing",
assets: { wordpressDirectory: wordpressDevelopDirectory },
extensions: [{ manifest: "/tmp/sodium/manifest.json" }],
blueprint: {},
},
policy: {
network: "deny",
filesystem: "readwrite-mounts",
commands: ["wordpress.run-php"],
secrets: "none",
approvals: "never",
},
metadata: {
recipe: {
inputs: {
pluginRuntime: {
php: {
iniEntries: { memory_limit: "512M" },
bootstrapIniEntries: { "opcache.file_cache": "/tmp/opcache" },
},
},
},
},
},
artifactsDirectory,
}
const server = await startPlaygroundCliServer(spec, [], { cliModule })
await server[Symbol.asyncDispose]()
assert.equal(calls.length, 1)
assert.equal(calls[0]["mount-before-install"]?.length, 2)
assert.equal(calls[0]["mount-before-install"]?.[0]?.vfsPath, "/internal/shared")
// A wordpress-develop checkout is the runtime root, not an ordinary post-startup mount.
assert.deepEqual(calls[0]["mount-before-install"]?.[1], { hostPath: wordpressDevelopDirectory, vfsPath: "/wordpress" })
assert.deepEqual(calls[0].mount, [])
assert.equal(calls[0].workers, 6)
assert.equal(calls[0].wordpressInstallMode, "do-not-attempt-installing")
assert.deepEqual(calls[0].phpIniEntries, { memory_limit: "512M" })
assert.deepEqual(calls[0].phpExtension, ["/tmp/sodium/manifest.json"])
const sharedMount = calls[0]["mount-before-install"]?.[0]?.hostPath
assert.equal(typeof sharedMount, "string")
const sharedPhpIni = await readFile(join(sharedMount as string, "php.ini"), "utf8")
assert.match(sharedPhpIni, /opcache\.file_cache = \/tmp\/opcache/)
// The runtime default memory ceiling stays high enough for collect_artifacts to
// base64 heavy snapshot/declared-artifact files without a hard PHP fatal.
assert.match(sharedPhpIni, /memory_limit=512M/)
assert.match(await readFile(join(sharedMount as string, "auto_prepend_file.php"), "utf8"), /<\?php/)
assert.equal((await stat(join(sharedMount as string, "mu-plugins"))).isDirectory(), true)
assert.equal((await stat(join(sharedMount as string, "preload"))).isDirectory(), true)
calls.length = 0
const defaultRuntimeIniSpec: RuntimeCreateSpec = {
...spec,
metadata: {},
}
const defaultRuntimeIniServer = await startPlaygroundCliServer(defaultRuntimeIniSpec, [], { cliModule })
await defaultRuntimeIniServer[Symbol.asyncDispose]()
assert.equal(calls.length, 1)
assert.deepEqual(calls[0].phpIniEntries, { memory_limit: "512M" })
calls.length = 0
const distributionOnlySpec: RuntimeCreateSpec = {
...spec,
metadata: {
recipe: {
distribution: {
name: "branch-preview",
wordpress: { root: "/wordpress" },
env: { WPCOM_BRANCH: "feature/example", FEATURE_ENABLED: true, EMPTY_VALUE: null },
constants: { WPCOM_IS_BRANCH_PREVIEW: true, WPCOM_BRANCH_ID: 123 },
},
},
},
}
const distributionOnlyServer = await startPlaygroundCliServer(distributionOnlySpec, [], { cliModule })
await distributionOnlyServer[Symbol.asyncDispose]()
assert.equal(calls.length, 1)
const distributionSharedMount = calls[0]["mount-before-install"]?.[0]?.hostPath
assert.equal(typeof distributionSharedMount, "string")
const distributionAutoPrepend = await readFile(join(distributionSharedMount as string, "auto_prepend_file.php"), "utf8")
assert.match(distributionAutoPrepend, /putenv\("WPCOM_BRANCH=feature\/example"\);/)
assert.match(distributionAutoPrepend, /putenv\("FEATURE_ENABLED=true"\);/)
assert.match(distributionAutoPrepend, /putenv\("EMPTY_VALUE="\);/)
assert.match(distributionAutoPrepend, /define\("WPCOM_IS_BRANCH_PREVIEW", true\)/)
assert.match(distributionAutoPrepend, /define\("WPCOM_BRANCH_ID", 123\)/)
} finally {
await rm(wordpressDevelopDirectory, { recursive: true, force: true })
await rm(artifactsDirectory, { recursive: true, force: true })
}
console.log("playground cli runner bootstrap ini ok")