-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstaged-input-materialization.test.ts
More file actions
123 lines (109 loc) · 5.19 KB
/
Copy pathstaged-input-materialization.test.ts
File metadata and controls
123 lines (109 loc) · 5.19 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
import assert from "node:assert/strict"
import { mkdir, writeFile } from "node:fs/promises"
import { join } from "node:path"
import { materializePlaygroundStagedInputs } from "../packages/runtime-playground/src/mount-materialization.js"
import { withTempDir } from "../scripts/test-kit.js"
await withTempDir("wp-codebox-staged-input-materialization-", async (root) => {
const source = join(root, "store-idea-agent")
await mkdir(join(source, "flows"), { recursive: true })
await writeFile(join(source, "manifest.json"), `${JSON.stringify({ schema: "test/runtime-bundle/v1" })}\n`)
await writeFile(join(source, "flows", "store.json"), `${JSON.stringify({ id: "store" })}\n`)
const written = new Map<string, string>()
const server = {
playground: {
async run({ code }: { code: string }) {
return code.includes("wp-codebox/host-mount-verification/v1")
? { text: JSON.stringify({ schema: "wp-codebox/host-mount-verification/v1", repaired: 0, skipped: 0 }) }
: { text: JSON.stringify({ schema: "wp-codebox/host-mount-directory-materialization/v1", created: 2, skipped: 0 }) }
},
async writeFile(path: string, contents: string) {
written.set(path, contents)
},
},
}
const result = await materializePlaygroundStagedInputs(server as never, [{
type: "directory",
source,
target: "/workspace/wp-site-generator/bundles/store-idea-agent",
mode: "readwrite",
metadata: { kind: "runtime-package-source" },
}])
assert.equal(result.materialized, 2)
assert.equal(result.deleted, 0)
assert.equal(result.skipped, 0)
assert.equal(result.phaseResult.phase, "playground-staged-input-materialization")
assert.equal(written.get("/workspace/wp-site-generator/bundles/store-idea-agent/manifest.json"), `${JSON.stringify({ schema: "test/runtime-bundle/v1" })}\n`)
assert.equal(written.get("/workspace/wp-site-generator/bundles/store-idea-agent/flows/store.json"), `${JSON.stringify({ id: "store" })}\n`)
})
await withTempDir("wp-codebox-staged-input-materialization-fallback-", async (root) => {
const source = join(root, "store-idea-agent")
await mkdir(join(source, "flows"), { recursive: true })
await writeFile(join(source, "manifest.json"), `${JSON.stringify({ schema: "test/runtime-bundle/v1" })}\n`)
await writeFile(join(source, "flows", "store.json"), `${JSON.stringify({ id: "store" })}\n`)
const written = new Map<string, string>()
let fallbackWrites = 0
const server = {
playground: {
async run({ code }: { code: string }) {
if (code.includes("wp-codebox/host-mount-verification/v1")) {
return { text: JSON.stringify({ schema: "wp-codebox/host-mount-verification/v1", repaired: 0, skipped: 0 }) }
}
if (code.includes("wp-codebox/host-mount-materialization/v1")) {
fallbackWrites++
return { text: JSON.stringify({ schema: "wp-codebox/host-mount-materialization/v1", materialized: 1, skipped: 0 }) }
}
return { text: JSON.stringify({ schema: "wp-codebox/host-mount-directory-materialization/v1", created: 1, skipped: 0 }) }
},
async writeFile(path: string, contents: string) {
if (path.endsWith("/flows/store.json")) {
throw new Error("persistent writer unavailable for nested file")
}
written.set(path, contents)
},
},
}
const result = await materializePlaygroundStagedInputs(server as never, [{
type: "directory",
source,
target: "/workspace/wp-site-generator/bundles/store-idea-agent",
mode: "readwrite",
metadata: { kind: "runtime-package-source" },
}])
assert.equal(result.materialized, 2)
assert.equal(result.deleted, 0)
assert.equal(result.skipped, 0)
assert.equal(fallbackWrites, 1)
assert.equal(written.get("/workspace/wp-site-generator/bundles/store-idea-agent/manifest.json"), `${JSON.stringify({ schema: "test/runtime-bundle/v1" })}\n`)
})
await withTempDir("wp-codebox-staged-input-materialization-binary-", async (root) => {
const source = join(root, "image.bin")
const contents = Buffer.from([0xff, 0xd8, 0xff, 0xe0, 0x00, 0x10, 0x80, 0xfe])
await writeFile(source, contents)
let directWrites = 0
let binaryWriteCode = ""
const server = {
playground: {
async run({ code }: { code: string }) {
if (code.includes("wp-codebox/host-mount-materialization/v1")) {
binaryWriteCode = code
return { text: JSON.stringify({ schema: "wp-codebox/host-mount-materialization/v1", materialized: 1, created: 0, skipped: 0 }) }
}
return { text: JSON.stringify({ schema: "wp-codebox/host-mount-directory-materialization/v1", created: 1, skipped: 0 }) }
},
async writeFile() {
directWrites++
},
},
}
const result = await materializePlaygroundStagedInputs(server as never, [{
type: "file",
source,
target: "/wordpress/wp-content/uploads/image.bin",
mode: "readwrite",
}])
assert.equal(result.materialized, 1)
assert.equal(result.skipped, 0)
assert.equal(directWrites, 0, "arbitrary bytes bypass the UTF-8-only direct writer")
assert.ok(binaryWriteCode.includes(contents.toString("base64")), "the PHP materializer receives the exact base64 payload")
})
console.log("staged input materialization ok")