@zyro-sec/server 0.0.0-stage → 1.0.1
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 +40 -4
- package/script/build.ts +28 -0
- package/script/pack.ts +5 -0
- package/script/workerd-probe.ts +59 -0
- package/src/api.ts +12 -0
- package/src/auth.ts +70 -0
- package/src/content-headers.ts +32 -0
- package/src/cors.ts +34 -0
- package/src/event-feed.ts +93 -0
- package/src/fetch.ts +67 -0
- package/src/handlers/agent.ts +23 -0
- package/src/handlers/artifact.ts +242 -0
- package/src/handlers/automation.ts +63 -0
- package/src/handlers/blob.ts +55 -0
- package/src/handlers/command.ts +8 -0
- package/src/handlers/config.ts +26 -0
- package/src/handlers/credential.ts +87 -0
- package/src/handlers/debug.ts +57 -0
- package/src/handlers/event.ts +38 -0
- package/src/handlers/form.ts +15 -0
- package/src/handlers/fs.ts +180 -0
- package/src/handlers/generate.ts +117 -0
- package/src/handlers/integration.ts +310 -0
- package/src/handlers/job.ts +29 -0
- package/src/handlers/location.ts +33 -0
- package/src/handlers/machine.ts +336 -0
- package/src/handlers/mcp.ts +160 -0
- package/src/handlers/media.ts +44 -0
- package/src/handlers/message.ts +82 -0
- package/src/handlers/migration.ts +13 -0
- package/src/handlers/model.ts +25 -0
- package/src/handlers/permission.ts +131 -0
- package/src/handlers/persistent-pty.ts +285 -0
- package/src/handlers/plugin.ts +97 -0
- package/src/handlers/project.ts +23 -0
- package/src/handlers/provider.ts +32 -0
- package/src/handlers/pty-socket.ts +47 -0
- package/src/handlers/pty.ts +181 -0
- package/src/handlers/push.ts +67 -0
- package/src/handlers/reference.ts +8 -0
- package/src/handlers/rpc.ts +31 -0
- package/src/handlers/server.ts +58 -0
- package/src/handlers/session-error.ts +47 -0
- package/src/handlers/session.ts +722 -0
- package/src/handlers/shell.ts +72 -0
- package/src/handlers/skill.ts +34 -0
- package/src/handlers/usage.ts +23 -0
- package/src/handlers/vcs.ts +104 -0
- package/src/handlers/voice.ts +50 -0
- package/src/handlers/websearch.ts +50 -0
- package/src/handlers/worktree.ts +60 -0
- package/src/handlers.ts +69 -0
- package/src/location.ts +86 -0
- package/src/media-uri.ts +13 -0
- package/src/middleware/authorization.ts +111 -0
- package/src/middleware/defect-response.ts +39 -0
- package/src/middleware/form-location.ts +44 -0
- package/src/middleware/schema-error.ts +49 -0
- package/src/middleware/session-location.ts +30 -0
- package/src/options.ts +61 -0
- package/src/pairing.ts +36 -0
- package/src/process.ts +274 -0
- package/src/range.ts +16 -0
- package/src/request-site.ts +36 -0
- package/src/request-tracing.ts +9 -0
- package/src/routes.ts +261 -0
- package/src/server-info.ts +41 -0
- package/src/service-status.ts +30 -0
- package/src/workerd.ts +184 -0
- package/test/artifact.test.ts +224 -0
- package/test/auth.test.ts +24 -0
- package/test/automation.test.ts +315 -0
- package/test/client-mcp.test.ts +369 -0
- package/test/codemode-api.test.ts +88 -0
- package/test/config.test.ts +104 -0
- package/test/cors.test.ts +24 -0
- package/test/defect-response.test.ts +83 -0
- package/test/event-feed.test.ts +201 -0
- package/test/fetch-option.test.ts +104 -0
- package/test/fetch.test.ts +698 -0
- package/test/fixture/mcp-starts.cjs +20 -0
- package/test/fixture/routes.ts +37 -0
- package/test/fixture/server.ts +20 -0
- package/test/fixture/worktree-delegate/index.ts +13 -0
- package/test/fixture/worktree-plugin/index.ts +47 -0
- package/test/flag-channel.test.ts +126 -0
- package/test/fs.test.ts +439 -0
- package/test/generate.test.ts +132 -0
- package/test/handler-policy.test.ts +43 -0
- package/test/heap-dump.test.ts +137 -0
- package/test/integration-policy.test.ts +93 -0
- package/test/job.test.ts +186 -0
- package/test/machine-iroh.test.ts +259 -0
- package/test/machine-link.test.ts +1234 -0
- package/test/machine-routes.test.ts +198 -0
- package/test/media.test.ts +343 -0
- package/test/message.test.ts +105 -0
- package/test/model.test.ts +62 -0
- package/test/options.test.ts +42 -0
- package/test/permission-saved.test.ts +73 -0
- package/test/persistent-pty.test.ts +1007 -0
- package/test/process.test.ts +261 -0
- package/test/provider.test.ts +88 -0
- package/test/pty-socket.property.test.ts +240 -0
- package/test/pty-socket.test.ts +89 -0
- package/test/pty-transport.test.ts +200 -0
- package/test/push-routes.test.ts +157 -0
- package/test/request-site.test.ts +71 -0
- package/test/request-tracing.test.ts +87 -0
- package/test/rpc-handler-errors.test.ts +76 -0
- package/test/schema-error.test.ts +68 -0
- package/test/service-status.test.ts +34 -0
- package/test/session-admit-location.test.ts +92 -0
- package/test/session-create.test.ts +65 -0
- package/test/session-diff.test.ts +100 -0
- package/test/session-form.test.ts +50 -0
- package/test/session-import.test.ts +152 -0
- package/test/session-instances.test.ts +335 -0
- package/test/session-unarchive.test.ts +73 -0
- package/test/session-update.test.ts +66 -0
- package/test/skill.test.ts +57 -0
- package/test/sse-failure.test.ts +71 -0
- package/test/usage.test.ts +88 -0
- package/test/vcs.test.ts +356 -0
- package/test/video-generate.test.ts +131 -0
- package/test/voice.test.ts +170 -0
- package/test/workerd.test.ts +227 -0
- package/test/worktree.test.ts +333 -0
- package/tsconfig.build.json +15 -0
- package/tsconfig.json +11 -0
- package/README.md +0 -3
|
@@ -0,0 +1,170 @@
|
|
|
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
|
+
)
|
|
@@ -0,0 +1,227 @@
|
|
|
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
|
+
)
|