@zyro-sec/server 1.0.2 → 1.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +8 -8
- package/script/build.ts +28 -28
- package/script/pack.ts +5 -5
- package/script/workerd-probe.ts +59 -59
- package/src/api.ts +12 -12
- package/src/auth.ts +70 -70
- package/src/content-headers.ts +32 -32
- package/src/cors.ts +34 -34
- package/src/event-feed.ts +93 -93
- package/src/fetch.ts +67 -67
- package/src/handlers/agent.ts +23 -23
- package/src/handlers/artifact.ts +242 -242
- package/src/handlers/automation.ts +63 -63
- package/src/handlers/blob.ts +55 -55
- package/src/handlers/command.ts +8 -8
- package/src/handlers/config.ts +26 -26
- package/src/handlers/credential.ts +87 -87
- package/src/handlers/debug.ts +57 -57
- package/src/handlers/event.ts +38 -38
- package/src/handlers/form.ts +15 -15
- package/src/handlers/fs.ts +180 -180
- package/src/handlers/generate.ts +117 -117
- package/src/handlers/integration.ts +310 -310
- package/src/handlers/job.ts +29 -29
- package/src/handlers/location.ts +33 -33
- package/src/handlers/machine.ts +336 -336
- package/src/handlers/mcp.ts +160 -160
- package/src/handlers/media.ts +44 -44
- package/src/handlers/message.ts +82 -82
- package/src/handlers/migration.ts +13 -13
- package/src/handlers/model.ts +25 -25
- package/src/handlers/permission.ts +131 -131
- package/src/handlers/persistent-pty.ts +285 -285
- package/src/handlers/plugin.ts +97 -97
- package/src/handlers/project.ts +23 -23
- package/src/handlers/provider.ts +32 -32
- package/src/handlers/pty-socket.ts +47 -47
- package/src/handlers/pty.ts +181 -181
- package/src/handlers/push.ts +67 -67
- package/src/handlers/reference.ts +8 -8
- package/src/handlers/rpc.ts +31 -31
- package/src/handlers/server.ts +58 -58
- package/src/handlers/session-error.ts +47 -47
- package/src/handlers/session.ts +722 -722
- package/src/handlers/shell.ts +72 -72
- package/src/handlers/skill.ts +34 -34
- package/src/handlers/usage.ts +23 -23
- package/src/handlers/vcs.ts +104 -104
- package/src/handlers/voice.ts +50 -50
- package/src/handlers/websearch.ts +50 -50
- package/src/handlers/worktree.ts +60 -60
- package/src/handlers.ts +69 -69
- package/src/location.ts +86 -86
- package/src/media-uri.ts +13 -13
- package/src/middleware/authorization.ts +111 -111
- package/src/middleware/defect-response.ts +39 -39
- package/src/middleware/form-location.ts +44 -44
- package/src/middleware/schema-error.ts +49 -49
- package/src/middleware/session-location.ts +30 -30
- package/src/options.ts +61 -61
- package/src/pairing.ts +36 -36
- package/src/process.ts +274 -274
- package/src/range.ts +16 -16
- package/src/request-site.ts +36 -36
- package/src/request-tracing.ts +9 -9
- package/src/routes.ts +261 -261
- package/src/server-info.ts +41 -41
- package/src/service-status.ts +30 -30
- package/src/workerd.ts +184 -184
- package/test/fixture/mcp-starts.cjs +20 -20
- package/test/fixture/routes.ts +37 -37
- package/test/fixture/server.ts +20 -20
- package/test/fixture/worktree-delegate/index.ts +13 -13
- package/test/fixture/worktree-plugin/index.ts +47 -47
- package/tsconfig.build.json +15 -15
- package/tsconfig.json +11 -11
- package/test/artifact.test.ts +0 -224
- package/test/auth.test.ts +0 -24
- package/test/automation.test.ts +0 -315
- package/test/client-mcp.test.ts +0 -369
- package/test/codemode-api.test.ts +0 -88
- package/test/config.test.ts +0 -104
- package/test/cors.test.ts +0 -24
- package/test/defect-response.test.ts +0 -83
- package/test/event-feed.test.ts +0 -201
- package/test/fetch-option.test.ts +0 -104
- package/test/fetch.test.ts +0 -698
- package/test/flag-channel.test.ts +0 -126
- package/test/fs.test.ts +0 -439
- package/test/generate.test.ts +0 -132
- package/test/handler-policy.test.ts +0 -43
- package/test/heap-dump.test.ts +0 -137
- package/test/integration-policy.test.ts +0 -93
- package/test/job.test.ts +0 -186
- package/test/machine-iroh.test.ts +0 -259
- package/test/machine-link.test.ts +0 -1234
- package/test/machine-routes.test.ts +0 -198
- package/test/media.test.ts +0 -343
- package/test/message.test.ts +0 -105
- package/test/model.test.ts +0 -62
- package/test/options.test.ts +0 -42
- package/test/permission-saved.test.ts +0 -73
- package/test/persistent-pty.test.ts +0 -1007
- package/test/process.test.ts +0 -261
- package/test/provider.test.ts +0 -88
- package/test/pty-socket.property.test.ts +0 -240
- package/test/pty-socket.test.ts +0 -89
- package/test/pty-transport.test.ts +0 -200
- package/test/push-routes.test.ts +0 -157
- package/test/request-site.test.ts +0 -71
- package/test/request-tracing.test.ts +0 -87
- package/test/rpc-handler-errors.test.ts +0 -76
- package/test/schema-error.test.ts +0 -68
- package/test/service-status.test.ts +0 -34
- package/test/session-admit-location.test.ts +0 -92
- package/test/session-create.test.ts +0 -65
- package/test/session-diff.test.ts +0 -100
- package/test/session-form.test.ts +0 -50
- package/test/session-import.test.ts +0 -152
- package/test/session-instances.test.ts +0 -335
- package/test/session-unarchive.test.ts +0 -73
- package/test/session-update.test.ts +0 -66
- package/test/skill.test.ts +0 -57
- package/test/sse-failure.test.ts +0 -71
- package/test/usage.test.ts +0 -88
- package/test/vcs.test.ts +0 -356
- package/test/video-generate.test.ts +0 -131
- package/test/voice.test.ts +0 -170
- package/test/workerd.test.ts +0 -227
- package/test/worktree.test.ts +0 -333
package/test/voice.test.ts
DELETED
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
import fs from "node:fs/promises"
|
|
2
|
-
import path from "node:path"
|
|
3
|
-
import { expect } from "bun:test"
|
|
4
|
-
import { Voice } from "@zyro-sec/core/voice"
|
|
5
|
-
import { makeLocationNode } from "@zyro-sec/util/effect/app-node"
|
|
6
|
-
import { Effect, Layer } from "effect"
|
|
7
|
-
import { tmpdir } from "../../core/test/fixture/tmpdir"
|
|
8
|
-
import { it } from "../../core/test/lib/effect"
|
|
9
|
-
import { ServerFetch } from "../src/fetch"
|
|
10
|
-
|
|
11
|
-
const voice = makeLocationNode({
|
|
12
|
-
service: Voice.Service,
|
|
13
|
-
layer: Layer.succeed(
|
|
14
|
-
Voice.Service,
|
|
15
|
-
Voice.Service.of({
|
|
16
|
-
models: () =>
|
|
17
|
-
Effect.succeed({
|
|
18
|
-
models: [
|
|
19
|
-
{
|
|
20
|
-
model: "gpt-live-1",
|
|
21
|
-
name: "GPT-Live 1",
|
|
22
|
-
engine: "openai-live",
|
|
23
|
-
provider: "openai",
|
|
24
|
-
transports: ["webrtc"],
|
|
25
|
-
available: true,
|
|
26
|
-
},
|
|
27
|
-
{
|
|
28
|
-
model: "gpt-realtime-2.1",
|
|
29
|
-
name: "GPT-Realtime-2.1",
|
|
30
|
-
engine: "openai-realtime",
|
|
31
|
-
provider: "openai",
|
|
32
|
-
transports: ["webrtc", "websocket"],
|
|
33
|
-
available: true,
|
|
34
|
-
},
|
|
35
|
-
{
|
|
36
|
-
model: "grok-voice-3.0",
|
|
37
|
-
name: "Grok Voice 3.0",
|
|
38
|
-
engine: "xai-realtime",
|
|
39
|
-
provider: "xai",
|
|
40
|
-
transports: ["websocket"],
|
|
41
|
-
available: false,
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
model: "gemini-3.8-live",
|
|
45
|
-
name: "Gemini 3.8 Live",
|
|
46
|
-
engine: "gemini-live",
|
|
47
|
-
provider: "google",
|
|
48
|
-
transports: ["websocket"],
|
|
49
|
-
available: false,
|
|
50
|
-
},
|
|
51
|
-
],
|
|
52
|
-
default: "gpt-live-1",
|
|
53
|
-
}),
|
|
54
|
-
session: (input) => {
|
|
55
|
-
if (input.model === "invalid")
|
|
56
|
-
return Effect.fail(new Voice.InvalidRequestError({ message: "Unsupported voice model" }))
|
|
57
|
-
if (input.model === "unavailable")
|
|
58
|
-
return Effect.fail(new Voice.UnavailableError({ message: "OpenAI API key is required", service: "openai" }))
|
|
59
|
-
return Effect.succeed(
|
|
60
|
-
input.transport.type === "webrtc"
|
|
61
|
-
? { type: "webrtc" as const, sdp: `answer:${input.model}:${input.transport.sdp}` }
|
|
62
|
-
: {
|
|
63
|
-
type: "websocket" as const,
|
|
64
|
-
url: `wss://api.x.ai/v1/realtime?model=${input.model}`,
|
|
65
|
-
token: "ek_test",
|
|
66
|
-
expiresAt: 1760000000,
|
|
67
|
-
},
|
|
68
|
-
)
|
|
69
|
-
},
|
|
70
|
-
}),
|
|
71
|
-
),
|
|
72
|
-
deps: [],
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
it.live("routes experimental voice models and session endpoints", () =>
|
|
76
|
-
Effect.gen(function* () {
|
|
77
|
-
const tmp = yield* Effect.acquireDisposable(Effect.promise(() => tmpdir("opencode-voice-endpoint-")))
|
|
78
|
-
const global = path.join(tmp.path, "global")
|
|
79
|
-
yield* Effect.promise(() => fs.mkdir(global))
|
|
80
|
-
const handler = yield* ServerFetch.make(
|
|
81
|
-
{
|
|
82
|
-
database: { path: ":memory:" },
|
|
83
|
-
config: { directory: global },
|
|
84
|
-
fs: { filewatcher: false },
|
|
85
|
-
models: { fetch: false },
|
|
86
|
-
},
|
|
87
|
-
{ overrides: [Voice.node.replace(voice)] },
|
|
88
|
-
)
|
|
89
|
-
const modelsRes = yield* Effect.promise(() =>
|
|
90
|
-
handler(new Request("http://opencode.local/api/experimental/voice/models")),
|
|
91
|
-
)
|
|
92
|
-
expect(modelsRes.status).toBe(200)
|
|
93
|
-
expect(yield* Effect.promise(() => modelsRes.json())).toEqual({
|
|
94
|
-
data: {
|
|
95
|
-
models: [
|
|
96
|
-
{
|
|
97
|
-
model: "gpt-live-1",
|
|
98
|
-
name: "GPT-Live 1",
|
|
99
|
-
engine: "openai-live",
|
|
100
|
-
provider: "openai",
|
|
101
|
-
transports: ["webrtc"],
|
|
102
|
-
available: true,
|
|
103
|
-
},
|
|
104
|
-
{
|
|
105
|
-
model: "gpt-realtime-2.1",
|
|
106
|
-
name: "GPT-Realtime-2.1",
|
|
107
|
-
engine: "openai-realtime",
|
|
108
|
-
provider: "openai",
|
|
109
|
-
transports: ["webrtc", "websocket"],
|
|
110
|
-
available: true,
|
|
111
|
-
},
|
|
112
|
-
{
|
|
113
|
-
model: "grok-voice-3.0",
|
|
114
|
-
name: "Grok Voice 3.0",
|
|
115
|
-
engine: "xai-realtime",
|
|
116
|
-
provider: "xai",
|
|
117
|
-
transports: ["websocket"],
|
|
118
|
-
available: false,
|
|
119
|
-
},
|
|
120
|
-
{
|
|
121
|
-
model: "gemini-3.8-live",
|
|
122
|
-
name: "Gemini 3.8 Live",
|
|
123
|
-
engine: "gemini-live",
|
|
124
|
-
provider: "google",
|
|
125
|
-
transports: ["websocket"],
|
|
126
|
-
available: false,
|
|
127
|
-
},
|
|
128
|
-
],
|
|
129
|
-
default: "gpt-live-1",
|
|
130
|
-
},
|
|
131
|
-
})
|
|
132
|
-
|
|
133
|
-
const post = (body: unknown) =>
|
|
134
|
-
Effect.promise(() =>
|
|
135
|
-
handler(
|
|
136
|
-
new Request("http://opencode.local/api/experimental/voice/session", {
|
|
137
|
-
method: "POST",
|
|
138
|
-
headers: { "content-type": "application/json" },
|
|
139
|
-
body: JSON.stringify(body),
|
|
140
|
-
}),
|
|
141
|
-
),
|
|
142
|
-
)
|
|
143
|
-
|
|
144
|
-
const rtcRes = yield* post({
|
|
145
|
-
model: "gpt-live-1",
|
|
146
|
-
session: { voice: "marin" },
|
|
147
|
-
transport: { type: "webrtc", sdp: "v=0", dcid: 4 },
|
|
148
|
-
})
|
|
149
|
-
expect(rtcRes.status).toBe(200)
|
|
150
|
-
expect(yield* Effect.promise(() => rtcRes.json())).toEqual({
|
|
151
|
-
data: { transport: { type: "webrtc", sdp: "answer:gpt-live-1:v=0" } },
|
|
152
|
-
})
|
|
153
|
-
|
|
154
|
-
const wsRes = yield* post({ model: "grok-voice-3.0", transport: { type: "websocket" } })
|
|
155
|
-
expect(wsRes.status).toBe(200)
|
|
156
|
-
expect(yield* Effect.promise(() => wsRes.json())).toEqual({
|
|
157
|
-
data: {
|
|
158
|
-
transport: {
|
|
159
|
-
type: "websocket",
|
|
160
|
-
url: "wss://api.x.ai/v1/realtime?model=grok-voice-3.0",
|
|
161
|
-
token: "ek_test",
|
|
162
|
-
expiresAt: 1760000000,
|
|
163
|
-
},
|
|
164
|
-
},
|
|
165
|
-
})
|
|
166
|
-
|
|
167
|
-
expect((yield* post({ model: "invalid", transport: { type: "websocket" } })).status).toBe(400)
|
|
168
|
-
expect((yield* post({ model: "unavailable", transport: { type: "websocket" } })).status).toBe(503)
|
|
169
|
-
}),
|
|
170
|
-
)
|
package/test/workerd.test.ts
DELETED
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
import { expect } from "bun:test"
|
|
2
|
-
import { Cause, Effect, Exit, Layer, Sink, Stream } from "effect"
|
|
3
|
-
import { ChildProcessSpawner } from "effect/process"
|
|
4
|
-
import { TestClock } from "effect/testing"
|
|
5
|
-
import { AppNodeBuilder } from "@zyro-sec/core/effect/app-node-builder"
|
|
6
|
-
import { Environment, makeFiles, makeMemoryDriver } from "@zyro-sec/core/environment/index"
|
|
7
|
-
import { FileSystem } from "@zyro-sec/core/filesystem"
|
|
8
|
-
import { Location } from "@zyro-sec/core/location"
|
|
9
|
-
import { Identity } from "@zyro-sec/core/machine/identity"
|
|
10
|
-
import { AbsolutePath, RelativePath } from "@zyro-sec/core/schema"
|
|
11
|
-
import { Workspace } from "@zyro-sec/core/workspace"
|
|
12
|
-
import { WorkspaceDriver } from "@zyro-sec/core/workspace/driver"
|
|
13
|
-
import { Npm } from "@zyro-sec/util/npm"
|
|
14
|
-
import { makeDurableObjectStorage } from "../../core/test/fixture/durable-object-storage"
|
|
15
|
-
import { location } from "../../core/test/fixture/location"
|
|
16
|
-
import { it } from "../../core/test/lib/effect"
|
|
17
|
-
import { ServerWorkerd } from "../src/workerd"
|
|
18
|
-
|
|
19
|
-
// Covers the profile's replacement graph composing and the database booting
|
|
20
|
-
// through the injected Durable Object storage.
|
|
21
|
-
it.live("boots the workerd profile over durable object storage", () =>
|
|
22
|
-
Effect.gen(function* () {
|
|
23
|
-
const handler = yield* ServerWorkerd.create({
|
|
24
|
-
storage: makeDurableObjectStorage(),
|
|
25
|
-
password: "secret",
|
|
26
|
-
app: { version: "workerd-test" },
|
|
27
|
-
config: { content: "{}" },
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
const unauthorized = yield* Effect.promise(() => handler(new Request("http://opencode.local/api/info")))
|
|
31
|
-
expect(unauthorized.status).toBe(401)
|
|
32
|
-
|
|
33
|
-
const status = yield* Effect.promise(() =>
|
|
34
|
-
handler(
|
|
35
|
-
new Request("http://opencode.local/api/info", {
|
|
36
|
-
headers: { authorization: `Basic ${btoa("opencode:secret")}` },
|
|
37
|
-
}),
|
|
38
|
-
),
|
|
39
|
-
)
|
|
40
|
-
expect(status.status).toBe(200)
|
|
41
|
-
|
|
42
|
-
const body: unknown = yield* Effect.promise(() => status.json())
|
|
43
|
-
expect(body).toMatchObject({ version: "workerd-test" })
|
|
44
|
-
|
|
45
|
-
// alarm() runs cleanly as a no-op when no workspaces are pending suspension.
|
|
46
|
-
yield* Effect.promise(() => handler.alarm())
|
|
47
|
-
}),
|
|
48
|
-
)
|
|
49
|
-
|
|
50
|
-
it.effect("fails Npm.add with a clear workerd error instead of running the installer", () =>
|
|
51
|
-
Effect.gen(function* () {
|
|
52
|
-
const npm = yield* Npm.Service
|
|
53
|
-
const error = yield* npm.add("some-package").pipe(Effect.flip)
|
|
54
|
-
expect(error).toBeInstanceOf(Npm.InstallFailedError)
|
|
55
|
-
expect(String(error.cause)).toContain("Npm.add is unavailable in the workerd profile")
|
|
56
|
-
}).pipe(
|
|
57
|
-
Effect.provide(AppNodeBuilder.build(Npm.node, ServerWorkerd.replacements({ storage: makeDurableObjectStorage() }))),
|
|
58
|
-
),
|
|
59
|
-
)
|
|
60
|
-
|
|
61
|
-
it.effect("marks the workerd environment non-local and omits rg", () =>
|
|
62
|
-
Effect.gen(function* () {
|
|
63
|
-
const environment = yield* Environment.Service
|
|
64
|
-
expect(environment.id).toBe(Environment.localID)
|
|
65
|
-
expect(environment.local).toBe(false)
|
|
66
|
-
expect(environment.rg).toBeUndefined()
|
|
67
|
-
}).pipe(
|
|
68
|
-
Effect.provide(
|
|
69
|
-
AppNodeBuilder.build(Environment.node, [
|
|
70
|
-
...ServerWorkerd.replacements({ storage: makeDurableObjectStorage() }),
|
|
71
|
-
Location.node.replace(
|
|
72
|
-
Layer.succeed(Location.Service, Location.Service.of(location({ directory: AbsolutePath.make("/") }))),
|
|
73
|
-
),
|
|
74
|
-
]),
|
|
75
|
-
),
|
|
76
|
-
),
|
|
77
|
-
)
|
|
78
|
-
|
|
79
|
-
it.effect("persists machine Identity in Durable Object KV storage without filesystem access", () =>
|
|
80
|
-
Effect.gen(function* () {
|
|
81
|
-
const storage = makeDurableObjectStorage()
|
|
82
|
-
const layer = AppNodeBuilder.build(Identity.node, ServerWorkerd.replacements({ storage }))
|
|
83
|
-
const first = yield* Effect.flatMap(Identity.Service, (id) => id.publicKey()).pipe(Effect.provide(layer))
|
|
84
|
-
expect(first.length).toBe(32)
|
|
85
|
-
|
|
86
|
-
const restarted = AppNodeBuilder.build(Identity.node, ServerWorkerd.replacements({ storage }))
|
|
87
|
-
const second = yield* Effect.flatMap(Identity.Service, (id) => id.publicKey()).pipe(Effect.provide(restarted))
|
|
88
|
-
expect(second).toEqual(first)
|
|
89
|
-
}),
|
|
90
|
-
)
|
|
91
|
-
|
|
92
|
-
it.effect("closes workerd workspace connections immediately and suspends idle workspaces via DO storage alarm", () =>
|
|
93
|
-
Effect.gen(function* () {
|
|
94
|
-
const storage = makeDurableObjectStorage()
|
|
95
|
-
const suspended: Workspace.ID[] = []
|
|
96
|
-
const memory = makeMemoryDriver()
|
|
97
|
-
const fakeDriver = WorkspaceDriver.make({
|
|
98
|
-
create: (input) => Effect.succeed({ binding: { workspaceID: input.workspaceID } }),
|
|
99
|
-
connect: () => Effect.succeed(memory),
|
|
100
|
-
suspendForIdle: (input) => Effect.sync(() => void suspended.push(input.workspaceID)),
|
|
101
|
-
destroy: () => Effect.void,
|
|
102
|
-
})
|
|
103
|
-
const layer = AppNodeBuilder.build(Workspace.node, [
|
|
104
|
-
...ServerWorkerd.replacements({ storage }),
|
|
105
|
-
WorkspaceDriver.node.replace(WorkspaceDriver.registryNode({ fake: fakeDriver })),
|
|
106
|
-
])
|
|
107
|
-
|
|
108
|
-
const workspaceID = yield* Workspace.Service.use((workspace) =>
|
|
109
|
-
Effect.gen(function* () {
|
|
110
|
-
const id = yield* workspace.attach({ provider: "fake", binding: { host: "sandbox" } })
|
|
111
|
-
yield* makeFiles(yield* workspace.connect(id)).mkdir("/workerd-workspace")
|
|
112
|
-
expect(yield* workspace.connected(id)).toBe(false)
|
|
113
|
-
return id
|
|
114
|
-
}),
|
|
115
|
-
).pipe(Effect.provide(layer))
|
|
116
|
-
|
|
117
|
-
expect(yield* Effect.promise(() => storage.getAlarm())).toBe(20 * 60 * 1000)
|
|
118
|
-
|
|
119
|
-
// After eviction, a fresh instance's suspendIdle (driven by DO alarm()) suspends the workspace.
|
|
120
|
-
yield* TestClock.adjust("20 minutes")
|
|
121
|
-
const result = yield* Workspace.Service.use((workspace) => workspace.suspendIdle()).pipe(Effect.provide(layer))
|
|
122
|
-
expect(result).toEqual([workspaceID])
|
|
123
|
-
expect(suspended).toEqual([workspaceID])
|
|
124
|
-
}),
|
|
125
|
-
)
|
|
126
|
-
|
|
127
|
-
it.effect(
|
|
128
|
-
"routes workerd FileSystem and search through an attached remote workspace and fails cleanly on bare locations",
|
|
129
|
-
() =>
|
|
130
|
-
Effect.gen(function* () {
|
|
131
|
-
const storage = makeDurableObjectStorage()
|
|
132
|
-
const memory = makeMemoryDriver()
|
|
133
|
-
const workspaceID = Workspace.ID.make("wrk_workerd_fs")
|
|
134
|
-
const fakeRgSpawner = ChildProcessSpawner.make(() =>
|
|
135
|
-
Effect.succeed(
|
|
136
|
-
ChildProcessSpawner.makeHandle({
|
|
137
|
-
pid: ChildProcessSpawner.ProcessId(1),
|
|
138
|
-
exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(0)),
|
|
139
|
-
isRunning: Effect.succeed(false),
|
|
140
|
-
kill: () => Effect.void,
|
|
141
|
-
stdin: Sink.drain,
|
|
142
|
-
stdout: Stream.make(new TextEncoder().encode("src/app.ts\n")),
|
|
143
|
-
stderr: Stream.empty,
|
|
144
|
-
all: Stream.make(new TextEncoder().encode("src/app.ts\n")),
|
|
145
|
-
getInputFd: () => Sink.drain,
|
|
146
|
-
getOutputFd: () => Stream.empty,
|
|
147
|
-
unref: Effect.succeed(Effect.void),
|
|
148
|
-
}),
|
|
149
|
-
),
|
|
150
|
-
)
|
|
151
|
-
const fakeDriver = WorkspaceDriver.make({
|
|
152
|
-
create: (input) => Effect.succeed({ binding: { workspaceID: input.workspaceID } }),
|
|
153
|
-
connect: () => Effect.succeed({ spawner: fakeRgSpawner, overrides: memory.overrides }),
|
|
154
|
-
suspendForIdle: () => Effect.void,
|
|
155
|
-
destroy: () => Effect.void,
|
|
156
|
-
})
|
|
157
|
-
|
|
158
|
-
const workspaceLayer = AppNodeBuilder.build(FileSystem.node, [
|
|
159
|
-
...ServerWorkerd.replacements({ storage }),
|
|
160
|
-
WorkspaceDriver.node.replace(WorkspaceDriver.registryNode({ fake: fakeDriver })),
|
|
161
|
-
Location.node.replace(
|
|
162
|
-
Layer.succeed(
|
|
163
|
-
Location.Service,
|
|
164
|
-
Location.Service.of(location({ directory: AbsolutePath.make("/workspace"), workspaceID })),
|
|
165
|
-
),
|
|
166
|
-
),
|
|
167
|
-
])
|
|
168
|
-
|
|
169
|
-
const setupLayer = AppNodeBuilder.build(Workspace.node, [
|
|
170
|
-
...ServerWorkerd.replacements({ storage }),
|
|
171
|
-
WorkspaceDriver.node.replace(WorkspaceDriver.registryNode({ fake: fakeDriver })),
|
|
172
|
-
])
|
|
173
|
-
yield* Workspace.Service.use((ws) =>
|
|
174
|
-
ws.attach({ id: workspaceID, provider: "fake", binding: { host: "sandbox" } }),
|
|
175
|
-
).pipe(Effect.provide(setupLayer))
|
|
176
|
-
|
|
177
|
-
yield* FileSystem.Service.use((fs) =>
|
|
178
|
-
Effect.gen(function* () {
|
|
179
|
-
yield* fs.write({ path: "src/app.ts", data: new TextEncoder().encode("export const ok = true") })
|
|
180
|
-
const read = yield* fs.read({ path: RelativePath.make("src/app.ts") })
|
|
181
|
-
expect(new TextDecoder().decode(yield* Stream.mkUint8Array(read.stream()))).toBe("export const ok = true")
|
|
182
|
-
const entries = yield* fs.list()
|
|
183
|
-
expect(entries.map((entry) => ({ path: entry.path, type: entry.type }))).toEqual([
|
|
184
|
-
{ path: RelativePath.make("src/"), type: "directory" },
|
|
185
|
-
])
|
|
186
|
-
const found = yield* fs.find({ query: "app" })
|
|
187
|
-
expect(found.map((entry) => ({ path: entry.path, type: entry.type }))).toEqual([
|
|
188
|
-
{ path: RelativePath.make("src/app.ts"), type: "file" },
|
|
189
|
-
])
|
|
190
|
-
}),
|
|
191
|
-
).pipe(Effect.provide(workspaceLayer))
|
|
192
|
-
|
|
193
|
-
// Bare workerd location (no workspace) dies cleanly without touching node:fs across read, list, write, and find.
|
|
194
|
-
const bareLayer = AppNodeBuilder.build(FileSystem.node, [
|
|
195
|
-
...ServerWorkerd.replacements({ storage }),
|
|
196
|
-
Location.node.replace(
|
|
197
|
-
Layer.succeed(Location.Service, Location.Service.of(location({ directory: AbsolutePath.make("/") }))),
|
|
198
|
-
),
|
|
199
|
-
])
|
|
200
|
-
const expectDefectContaining = (effect: Effect.Effect<unknown, unknown, FileSystem.Service>, expected: string) =>
|
|
201
|
-
effect.pipe(
|
|
202
|
-
Effect.provide(bareLayer),
|
|
203
|
-
Effect.exit,
|
|
204
|
-
Effect.map((exit) => {
|
|
205
|
-
expect(Exit.isFailure(exit) && Cause.hasDies(exit.cause)).toBe(true)
|
|
206
|
-
if (Exit.isFailure(exit)) expect(Cause.pretty(exit.cause)).toContain(expected)
|
|
207
|
-
}),
|
|
208
|
-
)
|
|
209
|
-
|
|
210
|
-
yield* expectDefectContaining(
|
|
211
|
-
FileSystem.Service.use((fs) => fs.list()),
|
|
212
|
-
"no execution plane",
|
|
213
|
-
)
|
|
214
|
-
yield* expectDefectContaining(
|
|
215
|
-
FileSystem.Service.use((fs) => fs.read({ path: RelativePath.make("a.txt") })),
|
|
216
|
-
"no execution plane",
|
|
217
|
-
)
|
|
218
|
-
yield* expectDefectContaining(
|
|
219
|
-
FileSystem.Service.use((fs) => fs.write({ path: "a.txt", data: new Uint8Array([1]) })),
|
|
220
|
-
"no execution plane",
|
|
221
|
-
)
|
|
222
|
-
yield* expectDefectContaining(
|
|
223
|
-
FileSystem.Service.use((fs) => fs.find({ query: "a" })),
|
|
224
|
-
"Search is not available",
|
|
225
|
-
)
|
|
226
|
-
}),
|
|
227
|
-
)
|