mirror of
https://github.com/deepseek-ai/deepseek-harness
synced 2026-08-15 21:04:50 +00:00
Machine-produced by `pnpm run rescope-vendor --apply` plus the regeneration it prints: `pnpm install` for the lockfile, `pnpm run gen-third-party-notices`, `verify-translation-pairing --write` for the touched bilingual pairs, `gen-doc-graphs`, and one typert snapshot whose ids embed character offsets. `pnpm run rescope-vendor --check` verifies the result. Renames nine vendored packages (cordis, cosmokit, schemastery and the six @cordisjs plugins) and every reference that resolves them: manifest names and dependency keys, module specifiers including declare-module merges, cordis.yml plugin names, tsconfig paths, every Markdown fence, and `docs/` prose. Directory names, upstream versions, and dependency ranges are unchanged, so vendor/README.md still reads as an upstream snapshot; its manifest table gains an upstream-name column so THIRD_PARTY_NOTICES keeps MIT attribution pointed at each fork's origin. The tutorial tier follows the rename end to end: its yaml fences named plugins the Loader can no longer resolve, its `ts ignore-check` fences disagreed with the compiled fences beside them, and its prose quoted both. The contracts that told readers to keep upstream names — the root convention and the vendoring cookbook's tree comment and manifest invariant — now say to rescope instead. Two rules read `@deepseek-ai/` as "another workspace plugin": the client bundle purity gate now names the vendored libraries a browser bundle inlines, and the files where a bare `cordis` is an agent-preset id keep that product data.
109 lines
5.2 KiB
TypeScript
109 lines
5.2 KiB
TypeScript
import { spawnSync } from 'node:child_process'
|
|
import { existsSync, readFileSync, rmSync } from 'node:fs'
|
|
import { mkdtemp, rm } from 'node:fs/promises'
|
|
import { homedir, tmpdir } from 'node:os'
|
|
import { join } from 'node:path'
|
|
import { afterEach, describe, expect, it } from 'vitest'
|
|
import { Context } from '@deepseek-ai/cordis'
|
|
import type { SandboxPolicy } from '@deepseek-ai/dsh-sandbox'
|
|
import { LocalSandboxProvider } from '@deepseek-ai/dsh-sandbox-local'
|
|
import { bwrapProfileArgs } from '../src/profiles.ts'
|
|
|
|
/**
|
|
* Keyless backend integration through `confine()` and a real bwrap process. With no rung forced,
|
|
* a passing probe must select the first rung. Tests assert world effects, wrap shape, and that the
|
|
* kernel denial matches the advertised dialect; consumer coverage lives in dsh-bash-sandbox.
|
|
* Skips when bwrap or user namespaces are unavailable. HOME-based workspaces avoid bwrap's
|
|
* ephemeral `/tmp`, so workspace-write actually proves the workspace-root rebind.
|
|
*/
|
|
|
|
const probe = spawnSync('bwrap', [...bwrapProfileArgs({ mode: 'read-only', workspaceRoot: '/' }), '--', 'true'], { timeout: 5_000, stdio: 'ignore' })
|
|
const bwrapUsable = probe.status === 0
|
|
|
|
let ctx: Context | undefined
|
|
const tempDirs: string[] = []
|
|
const tempFiles: string[] = []
|
|
|
|
afterEach(async () => {
|
|
await ctx?.fiber.dispose()
|
|
ctx = undefined
|
|
await Promise.all(tempDirs.splice(0).map(dir => rm(dir, { recursive: true, force: true })))
|
|
for (const file of tempFiles.splice(0)) rmSync(file, { force: true })
|
|
})
|
|
|
|
async function tempDir(base: string): Promise<string> {
|
|
const dir = await mkdtemp(join(base, 'dsh-bwrap-e2e-'))
|
|
tempDirs.push(dir)
|
|
return dir
|
|
}
|
|
|
|
async function provider(): Promise<LocalSandboxProvider> {
|
|
ctx = new Context()
|
|
await ctx.plugin(LocalSandboxProvider, {})
|
|
return ctx.sandbox as LocalSandboxProvider
|
|
}
|
|
|
|
/** Confine a shell command under `policy` and run it for real; returns the spawn result and the wrap's facts. */
|
|
function runConfined(sandbox: LocalSandboxProvider, command: string, policy: SandboxPolicy) {
|
|
const confined = sandbox.confine(['bash', '-c', command], policy)
|
|
const result = spawnSync(confined.argv[0] as string, confined.argv.slice(1), { timeout: 30_000, encoding: 'utf8' })
|
|
return { result, confined }
|
|
}
|
|
|
|
describe.skipIf(!bwrapUsable)('sandbox-local: real bwrap confinement', () => {
|
|
it('the passing probe selects the bwrap rung naturally — first in the ladder, full enforcement, EROFS dialect', async () => {
|
|
const workdir = await tempDir(tmpdir())
|
|
const sandbox = await provider()
|
|
const confined = sandbox.confine(['true'], { mode: 'read-only', workspaceRoot: workdir })
|
|
expect(confined.argv[0]).toBe('bwrap')
|
|
expect(confined.enforcement).toBe('full')
|
|
expect(confined.denialSignatures).toEqual(['read-only file system'])
|
|
})
|
|
|
|
it('read-only denies a write — the file must NOT exist, and the kernel speaks the advertised dialect', async () => {
|
|
const workdir = await tempDir(tmpdir())
|
|
const sandbox = await provider()
|
|
const { result } = runConfined(sandbox, `echo hi > ${workdir}/denied.txt`, { mode: 'read-only', workspaceRoot: workdir })
|
|
expect(result.status).not.toBe(0)
|
|
// The wrap's denialSignatures must be what the kernel actually prints.
|
|
expect(result.stderr.toLowerCase()).toContain('read-only file system')
|
|
expect(existsSync(join(workdir, 'denied.txt'))).toBe(false)
|
|
})
|
|
|
|
it('read-only keeps the tree readable/executable and the fresh /dev/null writable', async () => {
|
|
const workdir = await tempDir(tmpdir())
|
|
const sandbox = await provider()
|
|
const { result } = runConfined(sandbox, 'ls / > /dev/null && echo dev-ok', { mode: 'read-only', workspaceRoot: workdir })
|
|
expect(result.status).toBe(0)
|
|
expect(result.stdout).toBe('dev-ok\n')
|
|
})
|
|
|
|
it('workspace-write lands a write inside the workspace root and still denies one beside it', async () => {
|
|
const workdir = await tempDir(homedir())
|
|
const outside = await tempDir(homedir())
|
|
const sandbox = await provider()
|
|
|
|
const inside = runConfined(sandbox, `printf bwrap-ok > ${workdir}/allowed.txt`, { mode: 'workspace-write', workspaceRoot: workdir })
|
|
expect(inside.result.status).toBe(0)
|
|
expect(readFileSync(join(workdir, 'allowed.txt'), 'utf8')).toBe('bwrap-ok')
|
|
|
|
const denied = runConfined(sandbox, `echo hi > ${outside}/denied.txt`, { mode: 'workspace-write', workspaceRoot: workdir })
|
|
expect(denied.result.status).not.toBe(0)
|
|
expect(existsSync(join(outside, 'denied.txt'))).toBe(false)
|
|
})
|
|
|
|
it('workspace-write mounts an EPHEMERAL /tmp: the write succeeds inside, the host /tmp stays untouched', async () => {
|
|
// The documented bwrap-profile difference: Landlock and Seatbelt grant
|
|
// the HOST temp areas, bwrap swaps in a fresh tmpfs that dies with the
|
|
// process — the strongest of the three temp semantics.
|
|
const workdir = await tempDir(homedir())
|
|
const target = `/tmp/dsh-bwrap-e2e-ephemeral-${process.pid}.txt`
|
|
tempFiles.push(target)
|
|
const sandbox = await provider()
|
|
const { result } = runConfined(sandbox, `printf tmp-ok > ${target} && cat ${target}`, { mode: 'workspace-write', workspaceRoot: workdir })
|
|
expect(result.status).toBe(0)
|
|
expect(result.stdout).toBe('tmp-ok')
|
|
expect(existsSync(target)).toBe(false)
|
|
})
|
|
})
|