fix(sandbox): guard enable path and harden UI rendering performance (#341)

* fix(sandbox): guard enable path and harden UI rendering performance

* chore(deps): allow esbuild postinstall in pnpm onlyBuiltDependencies

* fix(sandbox): align availability reporting and address PR review feedback

* fix(sandbox): block planning without process attestation
This commit is contained in:
Chris Scott authored and GitHub committed 2026-08-27 08:58:23 -04:00
1 parent ba8e8f4b29
commit d63198ec8a
19 files changed
+501 -82

No files matched your search

+14
View File
@@ -32,6 +32,8 @@ import { opencodeServerManager, ConfigReloadError, resolveOpenCodeExecutable } f
import { getOrCreateInternalToken, rotateInternalToken } from '../services/internal-token'
import { sseAggregator } from '../services/sse-aggregator'
import type { OpenCodeSupervisor } from '../services/opencode-supervisor'
import { detectSandboxCapability } from '../services/sandbox/capability'
import { getProcessIdentityAttestationError } from '../services/opencode/process-identity'
import { restartOpenCode, restartOpenCodeAfterCommit, reloadOpenCodeConfig, getOpenCodeRestartCoordinator } from '../services/opencode-restart'
import type { GitAuthService } from '../services/git-auth'
import { DEFAULT_AGENTS_MD } from '../constants'
@@ -394,6 +396,18 @@ export function createSettingsRoutes(db: Database, gitAuthService: GitAuthServic
}
const currentSettings = settingsService.getSettings(userId)
if (currentSettings.preferences.sandbox?.enabled !== true && validated.preferences.sandbox?.enabled === true) {
const capability = detectSandboxCapability()
if (capability.available === false) {
return c.json({ error: `Cannot enable sandboxing: ${capability.reason}` }, 400)
}
const attestationError = getProcessIdentityAttestationError()
if (attestationError !== null) {
return c.json({ error: `Cannot enable sandboxing: ${attestationError}` }, 400)
}
}
const settings = settingsService.updateSettings(validated.preferences, userId)
const sandboxChanged = sandboxEnforcementChanged(currentSettings.preferences.sandbox, validated.preferences.sandbox)
+68 -37
View File
@@ -1,10 +1,11 @@
import type { Database } from 'bun:sqlite'
import type { GitCredential, Repo } from '@opencode-manager/shared'
import type { GitCredential, Repo, UserPreferences } from '@opencode-manager/shared'
import { SettingsService } from './settings'
import {
findPatCredentialForHost,
getSSHCredentialsForHost,
createGitEnv,
createGhCliEnv,
findGitHubCredential,
type ResolvedGitCredential,
} from '../utils/git-auth'
@@ -22,6 +23,12 @@ interface CredentialResolutionOptions {
repoId?: number
}
interface CredentialResolutionContext {
preferences: UserPreferences
credentials: GitCredential[]
repo: Repo | null
}
export class CredentialProvider {
private settingsService: SettingsService
private database: Database
@@ -32,8 +39,7 @@ export class CredentialProvider {
}
getGitCredentials(): GitCredential[] {
const settings = this.settingsService.getSettings('default')
return (settings.preferences.gitCredentials || []) as GitCredential[]
return this.getCredentials(this.getPreferences())
}
getGitCredentialById(credentialId: string | undefined): GitCredential | null {
@@ -42,10 +48,10 @@ export class CredentialProvider {
}
getPatCredentialForHost(hostname: string, options: CredentialResolutionOptions = {}): ResolvedGitCredential | null {
const credentials = this.getGitCredentials()
const selectedCredential = this.getSelectedCredential(options, credentials)
const context = this.resolveContext(options)
const selectedCredential = this.getSelectedCredential(context)
const selectedMatch = selectedCredential ? findPatCredentialForHost([selectedCredential], hostname) : null
return selectedMatch ?? findPatCredentialForHost(credentials, hostname)
return selectedMatch ?? findPatCredentialForHost(context.credentials, hostname)
}
getSshCredentialsForHost(host: string): GitCredential[] {
@@ -57,24 +63,22 @@ export class CredentialProvider {
}
getGitEnv(options: CredentialResolutionOptions = {}): Record<string, string> {
const credentials = this.getGitCredentials()
return createGitEnv(credentials, this.getSelectedCredential(options, credentials))
return this.getGitEnvForContext(this.resolveContext(options))
}
isSandboxGitCredentialsAllowed(options: CredentialResolutionOptions = {}): boolean {
const repo = this.resolveRepo(options)
if (repo) {
const repoOverride = getRepoSandboxGitCredentials(this.database, repo.id)
if (repoOverride !== null) return repoOverride
}
return this.settingsService.getSettings('default').preferences.sandbox?.gitCredentials === true
return this.getSandboxGitCredentialsAllowed(options)
}
getSandboxGitEnv(options: CredentialResolutionOptions = {}): Record<string, string> {
if (!this.isSandboxGitCredentialsAllowed(options)) return {}
const repo = this.resolveRepo(options)
const repoOverride = repo ? getRepoSandboxGitCredentials(this.database, repo.id) : null
if (repoOverride === false) return {}
const gitEnv = this.getGitEnv(options)
const context = this.resolveContext(options, repo)
if (repoOverride !== true && context.preferences.sandbox?.gitCredentials !== true) return {}
const gitEnv = this.getGitEnvForContext(context)
if (gitEnv.GIT_CONFIG_COUNT === '0') return {}
const { env, dropped } = limitForwardedGitConfigs(gitEnv)
@@ -84,7 +88,43 @@ export class CredentialProvider {
)
}
return { ...env, ...this.getGhCliEnv(options) }
return { ...env, ...this.getGhCliEnvForContext(context) }
}
getGhCliEnv(options: CredentialResolutionOptions = {}): Record<string, string> {
return this.getGhCliEnvForContext(this.resolveContext(options))
}
private resolveContext(options: CredentialResolutionOptions, repo = this.resolveRepo(options)): CredentialResolutionContext {
const preferences = this.getPreferences()
return {
preferences,
credentials: this.getCredentials(preferences),
repo,
}
}
private getPreferences(): UserPreferences {
return this.settingsService.getSettings('default').preferences
}
private getCredentials(preferences: UserPreferences): GitCredential[] {
return (preferences.gitCredentials || []) as GitCredential[]
}
private getGitEnvForContext(context: CredentialResolutionContext): Record<string, string> {
return createGitEnv(context.credentials, this.getSelectedCredential(context))
}
private getGhCliEnvForContext(context: CredentialResolutionContext): Record<string, string> {
const credential = this.getGhCliCredential(context)
return createGhCliEnv(credential ? [credential] : [])
}
private getSandboxGitCredentialsAllowed(options: CredentialResolutionOptions): boolean {
const repo = this.resolveRepo(options)
const repoOverride = repo ? getRepoSandboxGitCredentials(this.database, repo.id) : null
return repoOverride ?? (this.getPreferences().sandbox?.gitCredentials === true)
}
private resolveRepo(options: CredentialResolutionOptions): Repo | null {
@@ -94,34 +134,25 @@ export class CredentialProvider {
return options.cwd ? getRepoByDirectory(this.database, options.cwd) : null
}
getGhCliEnv(options: CredentialResolutionOptions = {}): Record<string, string> {
const credential = this.getGhCliCredential(options)
if (!credential?.token) return {}
return { GH_TOKEN: credential.token, GITHUB_TOKEN: credential.token }
}
private getGhCliCredential(options: CredentialResolutionOptions): GitCredential | null {
const credentials = this.getGitCredentials()
const selectedCredential = this.getSelectedCredential(options, credentials)
private getGhCliCredential(context: CredentialResolutionContext): GitCredential | null {
const selectedCredential = this.getSelectedCredential(context)
if (this.isGithubPatCredential(selectedCredential)) return selectedCredential
return findGitHubCredential(credentials)
return findGitHubCredential(context.credentials)
}
private getSelectedCredential(options: CredentialResolutionOptions, credentials: GitCredential[]): GitCredential | null {
const repoCredential = this.getRepoCredential(options, credentials)
private getSelectedCredential(context: CredentialResolutionContext): GitCredential | null {
const repoCredential = this.getRepoCredential(context)
if (repoCredential) return repoCredential
const settings = this.settingsService.getSettings('default')
return credentials.find((credential) => credential.id === settings.preferences.defaultGitCredentialId) ?? null
return context.credentials.find((credential) => credential.id === context.preferences.defaultGitCredentialId) ?? null
}
private getRepoCredential(options: CredentialResolutionOptions, credentials: GitCredential[]): GitCredential | null {
const repo = this.resolveRepo(options)
if (!repo) return null
private getRepoCredential(context: CredentialResolutionContext): GitCredential | null {
if (!context.repo) return null
const credentialId = getRepoGitCredentialId(this.database, repo.id)
return credentials.find((credential) => credential.id === credentialId) ?? null
const credentialId = getRepoGitCredentialId(this.database, context.repo.id)
return context.credentials.find((credential) => credential.id === credentialId) ?? null
}
private isGithubPatCredential(credential: GitCredential | null): credential is GitCredential {
@@ -77,6 +77,12 @@ export function resolveProcessIdentityProvider(): ProcessIdentityProvider {
return cachedProvider
}
export function getProcessIdentityAttestationError(): string | null {
return resolveProcessIdentityProvider().attested
? null
: 'process identity attestation is unavailable on this platform (Linux /proc is required)'
}
export function resetProcessIdentityProvider(): void {
cachedProvider = null
}
+9 -2
View File
@@ -7,6 +7,7 @@ import { mkdirSafe } from '../../utils/fs-safe'
import { logger } from '../../utils/logger'
import { SettingsService } from '../settings'
import { CredentialProvider } from '../credential-provider'
import { getProcessIdentityAttestationError } from '../opencode/process-identity'
import { detectSandboxCapability } from './capability'
import {
WORKSPACE_SANDBOX_NAME,
@@ -624,10 +625,12 @@ export class SandboxRuntimeService {
getStatus(): SandboxStatus {
const capability = detectSandboxCapability()
const attestationError = capability.available ? getProcessIdentityAttestationError() : null
const reason = capability.reason ?? attestationError
return {
available: capability.available,
available: capability.available && attestationError === null,
enabled: this.isEnabled(),
...(capability.reason !== undefined ? { reason: capability.reason } : {}),
...(reason !== null && reason !== undefined ? { reason } : {}),
...(capability.msbVersion !== undefined ? { msbVersion: capability.msbVersion } : {}),
}
}
@@ -640,6 +643,10 @@ export class SandboxRuntimeService {
if (!capability.available) {
return { mode: 'blocked', reason: capability.reason ?? 'Sandbox capability is unavailable' }
}
const attestationError = getProcessIdentityAttestationError()
if (attestationError !== null) {
return { mode: 'blocked', reason: attestationError }
}
const workDirectory = await resolveSandboxWorkDirectory(directory)
if (workDirectory === null) {
return {
+115
View File
@@ -145,6 +145,15 @@ vi.mock('../../src/services/sandbox/runtime', () => ({
SandboxRuntimeService: sandboxRuntimeServiceMock.SandboxRuntimeService,
}))
const capabilityMock = vi.hoisted(() => ({
detectSandboxCapability: vi.fn(),
}))
vi.mock('../../src/services/sandbox/capability', () => ({
detectSandboxCapability: capabilityMock.detectSandboxCapability,
resetSandboxCapabilityCache: vi.fn(),
}))
vi.mock('@opencode-manager/shared/config/env', () => ({
getWorkspacePath: vi.fn(() => '/tmp/test-workspace'),
getReposPath: vi.fn(() => '/tmp/test-repos'),
@@ -176,6 +185,8 @@ import { getImportedSessionDirectories, getOpenCodeImportStatus, OpenCodeImportP
import { relinkReposFromSessionDirectories } from '../../src/services/repo'
import { opencodeServerManager, ConfigReloadError } from '../../src/services/opencode-single-server'
import { patchConfigWithRecovery } from '../../src/services/opencode/config-recovery'
import { detectSandboxCapability } from '../../src/services/sandbox/capability'
import { forceProcessAttestation } from '../../src/services/opencode/process-identity'
const mockSpawnSync = spawnSync as ReturnType<typeof vi.fn>
const mockGetVersion = opencodeServerManager.getVersion as ReturnType<typeof vi.fn>
@@ -191,6 +202,7 @@ const mockGetImportedSessionDirectories = getImportedSessionDirectories as Retur
const mockRelinkReposFromSessionDirectories = relinkReposFromSessionDirectories as ReturnType<typeof vi.fn>
const mockWriteFileContent = writeFileContent as ReturnType<typeof vi.fn>
const mockPatchConfigWithRecovery = patchConfigWithRecovery as ReturnType<typeof vi.fn>
const mockDetectSandboxCapability = detectSandboxCapability as ReturnType<typeof vi.fn>
describe('Settings Routes - OpenCode Upgrade', () => {
let settingsApp: ReturnType<typeof createSettingsRoutes>
@@ -219,6 +231,9 @@ describe('Settings Routes - OpenCode Upgrade', () => {
mockRelinkReposFromSessionDirectories.mockReset()
mockWriteFileContent.mockReset()
mockPatchConfigWithRecovery.mockReset()
mockDetectSandboxCapability.mockReset()
mockDetectSandboxCapability.mockReturnValue({ available: true, msbVersion: 'msb 1.0.0' })
forceProcessAttestation(true)
sandboxRuntimeServiceMock.SandboxRuntimeService.mockReset()
sandboxRuntimeServiceMock.SandboxRuntimeService.mockImplementation(() => ({
isEnabled: () => false,
@@ -1848,6 +1863,106 @@ describe('Settings Routes - OpenCode Upgrade', () => {
})
})
describe('PATCH / - sandbox enable guard', () => {
afterEach(() => {
forceProcessAttestation(null)
})
it('rejects enabling sandboxing with 400 when sandbox capability is unavailable and does not persist settings', async () => {
mockDetectSandboxCapability.mockReturnValue({
available: false,
reason: '/dev/kvm is not available or not writable; pass --device /dev/kvm and run on a KVM-capable Linux host',
})
mockGetSettings.mockReturnValue({
preferences: { sandbox: { enabled: false } },
updatedAt: 1,
})
const req = new Request('http://localhost/', {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ preferences: { sandbox: { enabled: true } } }),
})
const res = await settingsApp.fetch(req)
const json = await res.json() as { error: string }
expect(res.status).toBe(400)
expect(json.error).toBe('Cannot enable sandboxing: /dev/kvm is not available or not writable; pass --device /dev/kvm and run on a KVM-capable Linux host')
expect(mockUpdateSettings).not.toHaveBeenCalled()
expect(opencodeServerManager.markRestartPending).not.toHaveBeenCalled()
})
it('rejects enabling sandboxing with 400 when capability is available but process identity is not attested', async () => {
forceProcessAttestation(false)
mockGetSettings.mockReturnValue({
preferences: { sandbox: { enabled: false } },
updatedAt: 1,
})
const req = new Request('http://localhost/', {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ preferences: { sandbox: { enabled: true } } }),
})
const res = await settingsApp.fetch(req)
const json = await res.json() as { error: string }
expect(res.status).toBe(400)
expect(json.error).toBe('Cannot enable sandboxing: process identity attestation is unavailable on this platform (Linux /proc is required)')
expect(mockUpdateSettings).not.toHaveBeenCalled()
expect(opencodeServerManager.markRestartPending).not.toHaveBeenCalled()
})
it('enables sandboxing with 200 when capability is available and process identity is attested', async () => {
mockGetSettings.mockReturnValue({
preferences: { sandbox: { enabled: false } },
updatedAt: 1,
})
mockUpdateSettings.mockReturnValue({
preferences: { sandbox: { enabled: true } },
updatedAt: 2,
})
const req = new Request('http://localhost/', {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ preferences: { sandbox: { enabled: true } } }),
})
const res = await settingsApp.fetch(req)
expect(res.status).toBe(200)
expect(mockUpdateSettings).toHaveBeenCalledWith({ sandbox: { enabled: true } }, 'default')
expect(opencodeServerManager.markRestartPending).toHaveBeenCalledTimes(1)
})
it('allows disabling sandboxing with 200 even when capability is unavailable and identity is not attested', async () => {
mockDetectSandboxCapability.mockReturnValue({
available: false,
reason: '/dev/kvm is not available or not writable; pass --device /dev/kvm and run on a KVM-capable Linux host',
})
forceProcessAttestation(false)
mockGetSettings.mockReturnValue({
preferences: { sandbox: { enabled: true } },
updatedAt: 1,
})
mockUpdateSettings.mockReturnValue({
preferences: { sandbox: { enabled: false } },
updatedAt: 2,
})
const req = new Request('http://localhost/', {
method: 'PATCH',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ preferences: { sandbox: { enabled: false } } }),
})
const res = await settingsApp.fetch(req)
expect(res.status).toBe(200)
expect(mockUpdateSettings).toHaveBeenCalledWith({ sandbox: { enabled: false } }, 'default')
expect(opencodeServerManager.markRestartPending).toHaveBeenCalledTimes(1)
})
})
describe('DELETE / - sandbox preference restart pending', () => {
it('marks the OpenCode server restart pending when resetting disables sandboxing', async () => {
mockGetSettings.mockReturnValue({
+2 -2
View File
@@ -85,7 +85,7 @@ describe('microsandbox runtime install', () => {
const dockerfile = read(dockerfilePath)
it('declares MICROSANDBOX_VERSION next to the other tool args', () => {
expect(dockerfile).toMatch(/ARG MICROSANDBOX_VERSION=0\.6\.8/)
expect(dockerfile).toMatch(/ARG MICROSANDBOX_VERSION=0\.6\.15/)
})
it('resolves the release URL from MICROSANDBOX_VERSION, not only the log message', () => {
@@ -103,7 +103,7 @@ describe('microsandbox runtime install', () => {
it('passes the same MICROSANDBOX_VERSION from the docker-build workflow', () => {
const workflow = read(join(repoRoot, '.github/workflows/docker-build.yml'))
expect(workflow).toContain('MICROSANDBOX_VERSION=0.6.8')
expect(workflow).toContain('MICROSANDBOX_VERSION=0.6.15')
expect(workflow).toContain('MICROSANDBOX_VERSION=${{ steps.versions.outputs.microsandbox }}')
})
@@ -1,4 +1,4 @@
import { describe, it, expect, beforeEach } from 'vitest'
import { describe, it, expect, beforeEach, vi } from 'vitest'
import { Database } from 'bun:sqlite'
import { migrate } from '../../src/db/migration-runner'
import { allMigrations } from '../../src/db/migrations'
@@ -275,8 +275,14 @@ describe('CredentialProvider', () => {
const repo = createGithubRepo()
setRepoSandboxGitCredentials(db, repo.id, false)
expect(provider.isSandboxGitCredentialsAllowed({ cwd: repo.fullPath })).toBe(false)
expect(provider.getSandboxGitEnv({ cwd: repo.fullPath })).toEqual({})
const getSettingsSpy = vi.spyOn(SettingsService.prototype, 'getSettings')
try {
expect(provider.isSandboxGitCredentialsAllowed({ cwd: repo.fullPath })).toBe(false)
expect(provider.getSandboxGitEnv({ cwd: repo.fullPath })).toEqual({})
expect(getSettingsSpy).not.toHaveBeenCalled()
} finally {
getSettingsSpy.mockRestore()
}
})
it('lets a per-repo override grant credentials while the global toggle is off', () => {
@@ -296,5 +302,18 @@ describe('CredentialProvider', () => {
expect(env.GIT_CONFIG_COUNT).toBe('1')
expect(env.GIT_CONFIG_KEY_0).toBe('http.https://github.com/.extraheader')
})
it('resolves settings once per getSandboxGitEnv invocation', () => {
settingsService.updateSettings({ sandbox: { enabled: true, gitCredentials: true } })
const repo = createGithubRepo()
const getSettingsSpy = vi.spyOn(SettingsService.prototype, 'getSettings')
try {
provider.getSandboxGitEnv({ cwd: repo.fullPath })
expect(getSettingsSpy).toHaveBeenCalledTimes(1)
} finally {
getSettingsSpy.mockRestore()
}
})
})
})
+37 -3
View File
@@ -12,6 +12,7 @@ import { SandboxRuntimeService, resetSandboxRuntimeState, stopWorkspaceSandboxOn
import { executeCommand } from '../../../src/utils/process'
import { detectSandboxCapability } from '../../../src/services/sandbox/capability'
import { logger } from '../../../src/utils/logger'
import { forceProcessAttestation } from '../../../src/services/opencode/process-identity'
vi.mock('../../../src/utils/process', () => ({
executeCommand: vi.fn(),
@@ -78,7 +79,7 @@ describe('SandboxRuntimeService', () => {
function enableEnforcement(): void {
settingsService.updateSettings({ sandbox: { enabled: true } })
mockDetectSandboxCapability.mockReturnValue({ available: true, msbVersion: 'msb 0.6.8' })
mockDetectSandboxCapability.mockReturnValue({ available: true, msbVersion: 'msb 0.6.15' })
}
function memoryMib(): number {
@@ -980,7 +981,7 @@ describe('SandboxRuntimeService', () => {
expect(mockExecuteCommand.mock.calls.filter((call) => call[0].includes('run'))).toHaveLength(0)
})
it('accepts the full image-resolved v0.6.8 config shape without recreating the sandbox', async () => {
it('accepts the full image-resolved v0.6.15 config shape without recreating the sandbox', async () => {
enableEnforcement()
const resolvedConfig = realInspectConfig({
image: {
@@ -1903,6 +1904,23 @@ describe('SandboxRuntimeService', () => {
expect(mockExecuteCommand).not.toHaveBeenCalled()
})
it('blocks an enforced request when process identity cannot be attested', async () => {
mockDetectSandboxCapability.mockReturnValue({ available: true, msbVersion: 'msb 0.6.15' })
forceProcessAttestation(false)
try {
const plan = await service.planShell(repoADir, true)
expect(plan).toEqual({
mode: 'blocked',
reason: 'process identity attestation is unavailable on this platform (Linux /proc is required)',
})
expect(mockExecuteCommand).not.toHaveBeenCalled()
} finally {
forceProcessAttestation(null)
}
})
it('uses a directory created after boot without recreating the sandbox', async () => {
enableEnforcement()
mockExecuteCommand.mockImplementation(async (args: string[]) => {
@@ -1940,9 +1958,25 @@ describe('SandboxRuntimeService', () => {
expect(service.getStatus()).toEqual({ available: false, enabled: true, reason: '/dev/kvm is not available' })
})
it('reports sandboxing unavailable when process identity cannot be attested', () => {
mockDetectSandboxCapability.mockReturnValue({ available: true, msbVersion: 'msb 0.6.15' })
forceProcessAttestation(false)
try {
expect(service.getStatus()).toEqual({
available: false,
enabled: false,
reason: 'process identity attestation is unavailable on this platform (Linux /proc is required)',
msbVersion: 'msb 0.6.15',
})
} finally {
forceProcessAttestation(null)
}
})
it('fails closed when the capability becomes unavailable after the toggle was enabled', async () => {
settingsService.updateSettings({ sandbox: { enabled: true } })
mockDetectSandboxCapability.mockReturnValue({ available: true, msbVersion: 'msb 0.6.8' })
mockDetectSandboxCapability.mockReturnValue({ available: true, msbVersion: 'msb 0.6.15' })
mockExecuteCommand.mockImplementation(async (args: string[]) => {
if (args.includes('inspect')) return { exitCode: 0, stdout: runningInspectOutput(realInspectConfig()), stderr: '' }
return { exitCode: 0, stdout: '[]', stderr: '' }
@@ -33,6 +33,12 @@ function writeArgvCapturingFakeMsb(msbPath: string, captureFile: string): void {
)
}
function sandboxShellEnv(overrides: NodeJS.ProcessEnv): NodeJS.ProcessEnv {
const env = { ...process.env }
for (const name of SANDBOX_FORWARDED_ENV_NAMES) delete env[name]
return { ...env, ...overrides }
}
describe('sandbox shell shim', () => {
it('execs msb through the shim with the working directory and a byte-for-byte guest payload', async () => {
const fakeBin = mkdtempSync(path.join(tmpdir(), 'ocm-shim-msb-'))
@@ -54,7 +60,7 @@ describe('sandbox shell shim', () => {
const command = 'echo "it\'s a test" && echo line2 | tr a-z A-Z\necho after-newline'
const result = spawnSync(shimPath, ['-c', command], {
encoding: 'utf8',
env: { ...process.env, [SANDBOX_SHELL_ENV_WORKDIR]: directory },
env: sandboxShellEnv({ [SANDBOX_SHELL_ENV_WORKDIR]: directory }),
})
expect(result.status).toBe(0)
expect(result.stdout).toBe("it's a test\nLINE2\nafter-newline\n")
@@ -107,14 +113,13 @@ describe('sandbox shell shim', () => {
const extraheaderValue = 'AUTHORIZATION: basic eDphYmMgZGVm'
const result = spawnSync(shimPath, ['-c', 'echo -e sentinel'], {
encoding: 'utf8',
env: {
...process.env,
env: sandboxShellEnv({
[SANDBOX_SHELL_ENV_WORKDIR]: directory,
GIT_CONFIG_COUNT: '1',
GIT_CONFIG_KEY_0: 'http.https://github.com/.extraheader',
GIT_CONFIG_VALUE_0: extraheaderValue,
OCM_INTERNAL_TOKEN: 'must-not-be-forwarded',
},
}),
})
expect(result.status).toBe(0)
@@ -168,7 +173,7 @@ describe('sandbox shell shim', () => {
const command = 'echo hostile-ok'
const result = spawnSync(shimPath, ['-c', command], {
encoding: 'utf8',
env: { ...process.env, [SANDBOX_SHELL_ENV_WORKDIR]: directory },
env: sandboxShellEnv({ [SANDBOX_SHELL_ENV_WORKDIR]: directory }),
})
expect(result.status).toBe(0)
expect(result.stdout).toBe('hostile-ok\n')