mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
feat(sandbox): per-session sandbox VMs with resource settings and provider arbitration
- Sandbox new root sessions by default with a per-session composer toggle; child sessions inherit their root session's mode (OM-82) - Run each sandboxed root session in its own microVM that mounts only the session's repository, with per-session CPU/memory overrides, Settings defaults, idle stop, and a cap on running VMs (OM-89) - Arbitrate shell sandboxing with other plugins (opencode-forge) through the shared opencode.sandbox-arbiter.v1 registry so exactly one provider sandboxes each call regardless of load order; fail closed on claim errors - Throw when another plugin rewrites a pinned sandbox shell setting - Tag sandboxed tool results with the owning provider and show it in the badge - Hint the agent to start Docker inside the VM only when OCM owns the session
This commit is contained in:
1 parent
ccdf75d803
commit
b21fdf5b94
48 files changed
+5666
-3375
No files matched your search
@@ -120,15 +120,15 @@ vi.mock('../../src/services/opencode-home', () => ({
|
||||
const sandboxRuntimeServiceMock = vi.hoisted(() => ({
|
||||
SandboxRuntimeService: vi.fn<() => {
|
||||
isEnabled: () => boolean
|
||||
stopWorkspaceSandboxForToggle?: () => Promise<void>
|
||||
prepareWorkspaceSandboxOnBoot?: () => Promise<void>
|
||||
stopAllSandboxesForToggle?: () => Promise<void>
|
||||
prepareSandboxOnBoot?: () => Promise<void>
|
||||
}>(() => ({ isEnabled: () => false })),
|
||||
}))
|
||||
|
||||
vi.mock('../../src/services/sandbox/runtime', () => ({
|
||||
SandboxRuntimeService: function SandboxRuntimeServiceStub() {
|
||||
return {
|
||||
prepareWorkspaceSandboxOnBoot: async () => undefined,
|
||||
prepareSandboxOnBoot: async () => undefined,
|
||||
...sandboxRuntimeServiceMock.SandboxRuntimeService(),
|
||||
}
|
||||
},
|
||||
@@ -1097,10 +1097,10 @@ describe('OpenCodeServerManager - server auth', () => {
|
||||
}, 15000)
|
||||
|
||||
it('stops the workspace sandbox when a restart disables enforcement', async () => {
|
||||
const stopWorkspaceSandboxForToggle = vi.fn().mockResolvedValue(undefined)
|
||||
const stopAllSandboxesForToggle = vi.fn().mockResolvedValue(undefined)
|
||||
sandboxRuntimeServiceMock.SandboxRuntimeService.mockImplementation(() => ({
|
||||
isEnabled: () => false,
|
||||
stopWorkspaceSandboxForToggle,
|
||||
stopAllSandboxesForToggle,
|
||||
}))
|
||||
const { OpenCodeServerManager } = await import('../../src/services/opencode-single-server')
|
||||
const manager = OpenCodeServerManager.getInstance()
|
||||
@@ -1109,7 +1109,7 @@ describe('OpenCodeServerManager - server auth', () => {
|
||||
|
||||
await manager.start()
|
||||
|
||||
expect(stopWorkspaceSandboxForToggle).toHaveBeenCalledTimes(1)
|
||||
expect(stopAllSandboxesForToggle).toHaveBeenCalledTimes(1)
|
||||
expect(spawnMock).toHaveBeenCalledWith(
|
||||
'opencode',
|
||||
expect.any(Array),
|
||||
@@ -1122,10 +1122,10 @@ describe('OpenCodeServerManager - server auth', () => {
|
||||
})
|
||||
|
||||
it('does not stop the workspace sandbox when the restarted server stays enforced', async () => {
|
||||
const stopWorkspaceSandboxForToggle = vi.fn().mockResolvedValue(undefined)
|
||||
const stopAllSandboxesForToggle = vi.fn().mockResolvedValue(undefined)
|
||||
sandboxRuntimeServiceMock.SandboxRuntimeService.mockImplementation(() => ({
|
||||
isEnabled: () => true,
|
||||
stopWorkspaceSandboxForToggle,
|
||||
stopAllSandboxesForToggle,
|
||||
}))
|
||||
execSyncMock.mockImplementation((cmd: string) => {
|
||||
if (cmd.includes('lsof')) return spawnMock.mock.calls.length > 0 ? '1234\n' : ''
|
||||
@@ -1139,7 +1139,7 @@ describe('OpenCodeServerManager - server auth', () => {
|
||||
|
||||
await manager.start()
|
||||
|
||||
expect(stopWorkspaceSandboxForToggle).not.toHaveBeenCalled()
|
||||
expect(stopAllSandboxesForToggle).not.toHaveBeenCalled()
|
||||
expect(spawnMock).toHaveBeenCalledWith(
|
||||
'opencode',
|
||||
expect.any(Array),
|
||||
@@ -1154,7 +1154,7 @@ describe('OpenCodeServerManager - server auth', () => {
|
||||
it('aborts the disabled restart when the workspace sandbox cannot be stopped', async () => {
|
||||
sandboxRuntimeServiceMock.SandboxRuntimeService.mockImplementation(() => ({
|
||||
isEnabled: () => false,
|
||||
stopWorkspaceSandboxForToggle: vi.fn().mockRejectedValue(new Error('msb stop failed; the managed microVM is still running')),
|
||||
stopAllSandboxesForToggle: vi.fn().mockRejectedValue(new Error('msb stop failed; the managed microVM is still running')),
|
||||
}))
|
||||
const { OpenCodeServerManager } = await import('../../src/services/opencode-single-server')
|
||||
const manager = OpenCodeServerManager.getInstance()
|
||||
|
||||
Reference in new issue
Block a user