Skip to content

Commit 288a350

Browse files
committed
remove useless
1 parent 1384b01 commit 288a350

4 files changed

Lines changed: 53 additions & 20 deletions

File tree

packages/opencode/src/sandbox/policy.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ export namespace SandboxPolicy {
1515
extra_deny_paths?: string[]
1616
opencode_roots?: string[]
1717
allow_network?: boolean
18-
allow_unix_sockets?: boolean
1918
}
2019

2120
export interface Output {
@@ -96,13 +95,6 @@ export namespace SandboxPolicy {
9695
...deny(denyRoots),
9796
...denyWrite(protectedRoots),
9897
...(input.allow_network ? ["(allow network*)"] : []),
99-
...(input.allow_unix_sockets
100-
? [
101-
"(allow system-socket (socket-domain AF_UNIX))",
102-
"(allow network-bind (local unix-socket))",
103-
"(allow network-outbound (remote unix-socket))",
104-
]
105-
: []),
10698
].join("\n")
10799
return {
108100
profile,

packages/opencode/src/sandbox/spawn.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ export namespace SandboxSpawn {
3434
write_roots: string[]
3535
unsafe_roots: string[]
3636
allow_network: boolean
37-
allow_unix_sockets: boolean
3837
}
3938

4039
export interface Settings {
@@ -59,7 +58,6 @@ export namespace SandboxSpawn {
5958
preset?: string
6059
mode?: Mode
6160
allow_network?: boolean
62-
allow_unix_sockets?: boolean
6361
}
6462

6563
export interface PlanInput extends ResolveInput {
@@ -224,7 +222,6 @@ export namespace SandboxSpawn {
224222
write_roots: [],
225223
unsafe_roots: [],
226224
allow_network: input.allow_network === true,
227-
allow_unix_sockets: input.allow_unix_sockets === true,
228225
} satisfies Diag
229226
}
230227

@@ -370,7 +367,6 @@ export namespace SandboxSpawn {
370367
opencode_roots: input.opencode_roots,
371368
mode: input.mode,
372369
allow_network: input.allow_network,
373-
allow_unix_sockets: input.allow_unix_sockets,
374370
})
375371

376372
const diag = {
@@ -384,7 +380,6 @@ export namespace SandboxSpawn {
384380
write_roots: policy.write,
385381
unsafe_roots: [],
386382
allow_network: input.allow_network === true,
387-
allow_unix_sockets: input.allow_unix_sockets === true,
388383
} satisfies Diag
389384

390385
return {
@@ -444,7 +439,6 @@ export namespace SandboxSpawn {
444439
extra_write_roots: mode === "read-only" ? writeRoots : [...writeRoots, ...temp],
445440
extra_deny_paths: raw.extra_deny_paths.map(Filesystem.resolve),
446441
allow_network: allowNetwork,
447-
allow_unix_sockets: input.allow_unix_sockets,
448442
})
449443

450444
if (out.active) log.debug("sandbox active", out.diag)

packages/opencode/test/pty/pty-session.test.ts

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
1-
import { describe, expect, test } from "bun:test"
1+
import { afterEach, describe, expect, test } from "bun:test"
2+
import fs from "fs/promises"
3+
import path from "path"
24
import { Bus } from "../../src/bus"
35
import { Instance } from "../../src/project/instance"
46
import { Pty } from "../../src/pty"
57
import type { PtyID } from "../../src/pty/schema"
68
import { tmpdir } from "../fixture/fixture"
79
import { setTimeout as sleep } from "node:timers/promises"
810

11+
const env = {
12+
HOME: process.env.HOME,
13+
}
14+
15+
afterEach(() => {
16+
if (env.HOME === undefined) delete process.env.HOME
17+
else process.env.HOME = env.HOME
18+
})
19+
920
const wait = async (fn: () => boolean, ms = 5000) => {
1021
const end = Date.now() + ms
1122
while (Date.now() < end) {
@@ -129,6 +140,43 @@ describe("pty", () => {
129140
})
130141
})
131142

143+
test("keeps pty shell startup deterministic in sandbox mode", async () => {
144+
if (process.platform !== "darwin") return
145+
146+
await using home = await tmpdir({
147+
init: async (dir) => {
148+
await Bun.write(path.join(dir, ".bashrc"), 'printf hit > "$HOME/bashrc-hit"\n')
149+
},
150+
})
151+
await using dir = await tmpdir({
152+
config: {
153+
experimental: {
154+
sandbox: {
155+
enabled: true,
156+
},
157+
},
158+
},
159+
})
160+
process.env.HOME = home.path
161+
162+
await Instance.provide({
163+
directory: dir.path,
164+
fn: async () => {
165+
const info = await Pty.create({ command: "/bin/bash", title: "bash" })
166+
try {
167+
await sleep(150)
168+
const hit = await fs
169+
.access(path.join(home.path, "bashrc-hit"))
170+
.then(() => true)
171+
.catch(() => false)
172+
expect(hit).toBe(false)
173+
} finally {
174+
await Pty.remove(info.id)
175+
}
176+
},
177+
})
178+
})
179+
132180
test("blocks excluded commands on initial pty spawn", async () => {
133181
await using dir = await tmpdir({
134182
config: {

packages/opencode/test/sandbox/policy.test.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,20 +41,19 @@ describe("sandbox.policy", () => {
4141
expect(out.profile).toContain('(subpath "/opt/homebrew")')
4242
})
4343

44-
test("adds network and unix socket rules only when requested", () => {
44+
test("adds network rules only when requested", () => {
4545
const out = SandboxPolicy.build({
4646
cwd: "/tmp/project",
4747
project_root: "/tmp/project",
4848
worktree_root: "/tmp/project",
4949
home: "/Users/tester",
5050
allow_network: true,
51-
allow_unix_sockets: true,
5251
})
5352

5453
expect(out.profile).toContain("(allow network*)")
55-
expect(out.profile).toContain("AF_UNIX")
56-
expect(out.profile).toContain("network-bind")
57-
expect(out.profile).toContain("network-outbound")
54+
expect(out.profile).not.toContain("AF_UNIX")
55+
expect(out.profile).not.toContain("network-bind")
56+
expect(out.profile).not.toContain("network-outbound")
5857
})
5958

6059
test("supports read-only mode without project write roots", () => {

0 commit comments

Comments
 (0)