mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 04:44:21 +01:00
fix(sandbox): verify worktree back-links, fail fast on root lookup, and tidy settings saves
This commit is contained in:
1 parent
1d001bc43e
commit
2d2921a6c6
10 files changed
+290
-51
No files matched your search
@@ -380,4 +380,60 @@ describe('SandboxSettings', () => {
|
||||
|
||||
expect(vi.mocked(showToast.error)).toHaveBeenCalledWith('Default memory exceeds the host memory')
|
||||
})
|
||||
|
||||
it('does not save CPUs when blurred without a change', async () => {
|
||||
const { updateSettingsAsync } = mockUseSettings({ preferences: { sandbox: { enabled: true, cpus: 4 } } })
|
||||
mockHealth({ available: true, enforced: false })
|
||||
|
||||
const user = await renderSandbox()
|
||||
const cpus = screen.getByLabelText('Default CPUs')
|
||||
await user.click(cpus)
|
||||
await user.tab()
|
||||
|
||||
expect(updateSettingsAsync).not.toHaveBeenCalled()
|
||||
expect(vi.mocked(showToast.success)).not.toHaveBeenCalled()
|
||||
expect(vi.mocked(showToast.error)).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('does not save CPUs when a blank value already uses the server default', async () => {
|
||||
const { updateSettingsAsync } = mockUseSettings({ preferences: { sandbox: { enabled: true } } })
|
||||
mockHealth({ available: true, enforced: false })
|
||||
|
||||
const user = await renderSandbox()
|
||||
const cpus = screen.getByLabelText('Default CPUs')
|
||||
await user.click(cpus)
|
||||
await user.tab()
|
||||
|
||||
expect(updateSettingsAsync).not.toHaveBeenCalled()
|
||||
expect(vi.mocked(showToast.success)).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('does not save memory when blurred without a change', async () => {
|
||||
const { updateSettingsAsync } = mockUseSettings({
|
||||
preferences: { sandbox: { enabled: true, memoryMib: 4096 } },
|
||||
})
|
||||
mockHealth({ available: true, enforced: false })
|
||||
|
||||
const user = await renderSandbox()
|
||||
const memory = screen.getByLabelText('Default memory (GiB)')
|
||||
await user.click(memory)
|
||||
await user.tab()
|
||||
|
||||
expect(updateSettingsAsync).not.toHaveBeenCalled()
|
||||
expect(vi.mocked(showToast.success)).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('does not save idle stop or max running VMs when blurred at the defaults', async () => {
|
||||
const { updateSettingsAsync } = mockUseSettings({ preferences: { sandbox: { enabled: true } } })
|
||||
mockHealth({ available: true, enforced: false })
|
||||
|
||||
const user = await renderSandbox()
|
||||
await user.click(screen.getByLabelText('Remove idle sandbox VMs after (minutes)'))
|
||||
await user.tab()
|
||||
await user.click(screen.getByLabelText('Max running sandbox VMs'))
|
||||
await user.tab()
|
||||
|
||||
expect(updateSettingsAsync).not.toHaveBeenCalled()
|
||||
expect(vi.mocked(showToast.success)).not.toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
@@ -96,6 +96,7 @@ export function SandboxSettings() {
|
||||
const commitCpus = () => {
|
||||
const trimmed = draft.cpus.trim()
|
||||
if (trimmed === '') {
|
||||
if (sandboxPreferences?.cpus === undefined) return
|
||||
void saveSandbox({ cpus: undefined }, 'Default CPUs reset to the server default')
|
||||
return
|
||||
}
|
||||
@@ -108,12 +109,14 @@ export function SandboxSettings() {
|
||||
}))
|
||||
return
|
||||
}
|
||||
if (value === sandboxPreferences?.cpus) return
|
||||
void saveSandbox({ cpus: value }, 'Default CPUs saved')
|
||||
}
|
||||
|
||||
const commitMemory = () => {
|
||||
const trimmed = draft.memoryGib.trim()
|
||||
if (trimmed === '') {
|
||||
if (sandboxPreferences?.memoryMib === undefined) return
|
||||
void saveSandbox({ memoryMib: undefined }, 'Default memory reset to the server default')
|
||||
return
|
||||
}
|
||||
@@ -129,6 +132,7 @@ export function SandboxSettings() {
|
||||
}))
|
||||
return
|
||||
}
|
||||
if (memoryMib === sandboxPreferences?.memoryMib) return
|
||||
void saveSandbox({ memoryMib }, 'Default memory saved')
|
||||
}
|
||||
|
||||
@@ -144,6 +148,7 @@ export function SandboxSettings() {
|
||||
}))
|
||||
return
|
||||
}
|
||||
if (value === (sandboxPreferences?.idleStopMinutes ?? DEFAULT_SANDBOX_IDLE_STOP_MINUTES)) return
|
||||
void saveSandbox({ idleStopMinutes: value }, 'Idle removal timeout saved')
|
||||
}
|
||||
|
||||
@@ -159,6 +164,7 @@ export function SandboxSettings() {
|
||||
}))
|
||||
return
|
||||
}
|
||||
if (value === (sandboxPreferences?.maxRunningVms ?? DEFAULT_SANDBOX_MAX_RUNNING_VMS)) return
|
||||
void saveSandbox({ maxRunningVms: value }, 'Max running sandbox VMs saved')
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user