mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-06 12:54:20 +01:00
feat(sandbox): add git credential forwarding toggle to settings
This commit is contained in:
1 parent
19b91ac24f
commit
d7f4f2f110
8 files changed
+135
-26
No files matched your search
@@ -217,12 +217,12 @@ function needsOpenCodeRestart(
|
||||
return ['agent', 'plugin', 'skills', 'provider'].some((field) => didConfigFieldChange(previous, next, field))
|
||||
}
|
||||
|
||||
function sandboxPreferenceChanged(
|
||||
function sandboxEnforcementChanged(
|
||||
previous: SandboxPreferences | undefined,
|
||||
next: SandboxPreferences | undefined,
|
||||
): boolean {
|
||||
if (next === undefined) return false
|
||||
return JSON.stringify(previous ?? {}) !== JSON.stringify(next)
|
||||
return (previous?.enabled ?? false) !== next.enabled
|
||||
}
|
||||
|
||||
function parseOptionalRepoId(value: string | undefined): number | undefined {
|
||||
@@ -396,7 +396,7 @@ export function createSettingsRoutes(db: Database, gitAuthService: GitAuthServic
|
||||
const currentSettings = settingsService.getSettings(userId)
|
||||
const settings = settingsService.updateSettings(validated.preferences, userId)
|
||||
|
||||
const sandboxChanged = sandboxPreferenceChanged(currentSettings.preferences.sandbox, validated.preferences.sandbox)
|
||||
const sandboxChanged = sandboxEnforcementChanged(currentSettings.preferences.sandbox, validated.preferences.sandbox)
|
||||
|
||||
const credentialsChanged = validated.preferences.gitCredentials !== undefined &&
|
||||
JSON.stringify(currentSettings.preferences.gitCredentials || []) !== JSON.stringify(validated.preferences.gitCredentials)
|
||||
@@ -435,9 +435,9 @@ export function createSettingsRoutes(db: Database, gitAuthService: GitAuthServic
|
||||
const currentSettings = settingsService.getSettings(userId)
|
||||
const settings = settingsService.resetSettings(userId)
|
||||
|
||||
const sandboxChanged = sandboxPreferenceChanged(currentSettings.preferences.sandbox, settings.preferences.sandbox)
|
||||
const sandboxChanged = sandboxEnforcementChanged(currentSettings.preferences.sandbox, settings.preferences.sandbox)
|
||||
if (sandboxChanged) {
|
||||
logger.info('Sandbox preference changed, marking OpenCode server restart as pending')
|
||||
logger.info('Sandbox enforcement changed, marking OpenCode server restart as pending')
|
||||
opencodeServerManager.markRestartPending()
|
||||
}
|
||||
|
||||
|
||||
@@ -1733,6 +1733,27 @@ describe('Settings Routes - OpenCode Upgrade', () => {
|
||||
expect(opencodeServerManager.markRestartPending).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('does not mark the OpenCode server restart pending when only sandbox.gitCredentials changes', async () => {
|
||||
mockGetSettings.mockReturnValue({
|
||||
preferences: { sandbox: { enabled: true, gitCredentials: false } },
|
||||
updatedAt: 1,
|
||||
})
|
||||
mockUpdateSettings.mockReturnValue({
|
||||
preferences: { sandbox: { enabled: true, gitCredentials: true } },
|
||||
updatedAt: 2,
|
||||
})
|
||||
|
||||
const req = new Request('http://localhost/', {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ preferences: { sandbox: { enabled: true, gitCredentials: true } } }),
|
||||
})
|
||||
const res = await settingsApp.fetch(req)
|
||||
|
||||
expect(res.status).toBe(200)
|
||||
expect(opencodeServerManager.markRestartPending).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('does not mark the OpenCode server restart pending when sandbox is absent from the patch', async () => {
|
||||
mockGetSettings.mockReturnValue({
|
||||
preferences: { sandbox: { enabled: true } },
|
||||
|
||||
@@ -227,6 +227,9 @@ describe('docker lifecycle scripts', () => {
|
||||
describe('sandbox compose overlay', () => {
|
||||
const overlayPath = join(repoRoot, 'docker-compose.sandbox.yml')
|
||||
const overlay = read(overlayPath)
|
||||
const overlayDirectives = overlay
|
||||
.split('\n')
|
||||
.filter((line) => line.trim() !== '' && !line.trimStart().startsWith('#'))
|
||||
|
||||
it('defaults SANDBOX_EXEC_USER from PUID so the guest identity tracks the workspace owner', () => {
|
||||
expect(overlay).toContain('- SANDBOX_EXEC_USER=${SANDBOX_EXEC_USER:-${PUID:-1000}}')
|
||||
@@ -239,11 +242,30 @@ describe('sandbox compose overlay', () => {
|
||||
})
|
||||
|
||||
it('grants KVM and persists microsandbox state only in the overlay', () => {
|
||||
expect(overlay).toContain('privileged: true')
|
||||
expect(overlay).toContain('"/dev/kvm:/dev/kvm"')
|
||||
expect(overlay).toContain('"/dev/net/tun:/dev/net/tun"')
|
||||
expect(overlay).toContain('- NET_ADMIN')
|
||||
expect(overlay).toContain('microsandbox-data:/home/node/.microsandbox')
|
||||
expect(overlay).toMatch(/^volumes:\n(?:.*\n)*?\s+microsandbox-data:/m)
|
||||
})
|
||||
|
||||
it('grants only the devices and capability msb needs, never full container privilege', () => {
|
||||
expect(overlayDirectives.join('\n')).not.toContain('privileged')
|
||||
})
|
||||
|
||||
it('keeps the sandbox overlay docs snippet in sync with docker-compose.sandbox.yml', () => {
|
||||
const docs = read(dockerDocsPath)
|
||||
const docsOverlay = [...docs.matchAll(/```yaml\n([\s\S]*?)\n```/g)]
|
||||
.map((match) => match[1]!)
|
||||
.find((block) => block.includes('microsandbox-data'))
|
||||
|
||||
expect(docsOverlay, 'docs must contain the sandbox overlay yaml block').toBeDefined()
|
||||
|
||||
const significantLines = (source: string[]) =>
|
||||
source.filter((line) => line.trim() !== '').map((line) => line.replace(/\s+$/, '')).join('\n')
|
||||
|
||||
expect(significantLines(docsOverlay!.split('\n'))).toBe(significantLines(overlayDirectives))
|
||||
})
|
||||
})
|
||||
|
||||
describe('named-volume migration recipe', () => {
|
||||
|
||||
Reference in new issue
Block a user