fix(sandbox): bound lifecycle queue and harden install/backup paths

Bound the OpenCode supervisor lifecycle queue to one running plus one
pending operation so repeated restarts cannot stack unbounded HTTP
requests, while exempting stop() so shutdown is never dropped.

Reject enforcement backups that carry no recoverable removed sections,
matching the existing fail-closed handling of unparseable backups.

Install OpenCode through a private mktemp staging directory instead of
the predictable /tmp/opencode path.

Use named path/os imports in the files added by this branch.
This commit is contained in:
Chris Scott committed 2026-08-22 00:14:19 -04:00
1 parent 0481160f5e
commit 0215de9d92
9 files changed
+108 -28

No files matched your search

@@ -531,6 +531,31 @@ describe('opencode plugin quarantine', () => {
expect(await fs.readFile(backupPath, 'utf-8')).toBe(corrupt)
})
it('refuses to overwrite a backup that holds no recoverable removed sections', async () => {
writeConfig({
mcp: { local: { type: 'local', command: ['npx', 'evil-server'] } },
formatter: { typescript: { command: ['prettier'] } },
model: 'x',
})
await quarantineOpenCodePlugins(configHome, configPath)
const backupPath = `${configPath}.ocm-sandbox-backup`
writeFileSync(backupPath, '{}')
await expect(quarantineOpenCodePlugins(configHome, configPath)).rejects.toThrow(/refusing to overwrite it/)
expect(await fs.readFile(backupPath, 'utf-8')).toBe('{}')
})
it('accepts a legacy backup that recorded an empty plugin list', async () => {
writeConfig({ plugin: ['my-plugin'], model: 'x' })
await quarantineOpenCodePlugins(configHome, configPath)
const backupPath = `${configPath}.ocm-sandbox-backup`
writeFileSync(backupPath, JSON.stringify({ originalPlugins: [] }))
await expect(quarantineOpenCodePlugins(configHome, configPath)).resolves.toBeUndefined()
})
it('replaces a quarantined section with a newly supplied prohibited value while preserving other backed-up sections', async () => {
writeConfig({
mcp: { local: { type: 'local', command: ['npx', 'old-server'] } },