| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- /**
- * The shipped shell composition: the base bundle gates both shell stacks by
- * platform on its own rows (`disabled: !!js process.platform`), so exactly
- * one shell stack mounts per host and no separate platform layer exists —
- * the launcher applies nothing beyond the bundle layers. The spec composes
- * the REAL shipped bundle layers (dsh-base + dsh-web-app resolved from the
- * app installation anchor) through the boot's patch algorithm and pins the
- * effective per-platform roster, the preset-level gate that keeps tool-bash
- * out of win32 sessions, and the cold-start resolution closure for the pwsh
- * rows' bare plugin names.
- */
- import { afterEach, describe, expect, it } from 'vitest'
- import { mkdtempSync, rmSync, readFileSync } from 'node:fs'
- import { tmpdir } from 'node:os'
- import { join, resolve } from 'node:path'
- import { fileURLToPath } from 'node:url'
- import yaml from 'js-yaml'
- import { entryListSchema } from '@deepseek-ai/cordis-plugin-include'
- import { evaluate } from '@deepseek-ai/cordis-plugin-loader'
- import { composeEntries, initProfile, loadProfile, PROFILES_DIR } from '@deepseek-ai/dsh-app-boot'
- /**
- * The effective disabled state of one composed row on one platform: a `!!js`
- * expression evaluates with a platform-scoped context (the `with` scope
- * shadows the global `process`) so both outcomes pin on every host; a plain
- * boolean is the value itself.
- */
- function disabledOn(row: { disabled?: unknown }, platform: 'win32' | 'linux'): boolean {
- const value = row.disabled
- if (value !== null && typeof value === 'object' && '__jsExpr' in value) {
- return Boolean(evaluate({ process: { platform } }, (value as { __jsExpr: string }).__jsExpr))
- }
- return value === true
- }
- describe('the shipped shell composition (real bundle layers)', () => {
- let home: string
- afterEach(() => { if (home !== undefined) rmSync(home, { recursive: true, force: true }) })
- // The app installation anchor, mirroring profile-boot.ts: the bundle layers
- // resolve from the REAL dsh-base/dsh-web-app packages through it, so this
- // suite composes the shipped patch files, not test fixtures.
- const anchor = fileURLToPath(new URL('../package.json', import.meta.url))
- it('composes the confined pwsh roster on win32 and the bash roster on POSIX from the same rows', () => {
- home = mkdtempSync(join(tmpdir(), 'dsh-windows-home-'))
- initProfile(join(home, PROFILES_DIR, 'web'), ['@deepseek-ai/dsh-base', '@deepseek-ai/dsh-web-app'])
- const profile = loadProfile('dsh', 'web', anchor, home)
- const warnings: string[] = []
- const rows = composeEntries(
- profile.layers.map(layer => layer.patches),
- message => warnings.push(message),
- )
- const byId = new Map(rows.map(row => [row.id, row]))
- // One shared patch set, two rosters: the shell stacks gate themselves.
- for (const id of ['bash-sandbox', 'pwsh-sandbox', 'tool-pwsh']) {
- expect(byId.has(id), `row ${id}`).toBe(true)
- }
- expect(disabledOn(byId.get('bash-sandbox')!, 'win32'), 'bash-sandbox on win32').toBe(true)
- expect(disabledOn(byId.get('bash-sandbox')!, 'linux'), 'bash-sandbox on linux').toBe(false)
- expect(disabledOn(byId.get('pwsh-sandbox')!, 'win32'), 'pwsh-sandbox on win32').toBe(false)
- expect(disabledOn(byId.get('pwsh-sandbox')!, 'linux'), 'pwsh-sandbox on linux').toBe(true)
- expect(disabledOn(byId.get('tool-pwsh')!, 'win32'), 'tool-pwsh on win32').toBe(false)
- expect(disabledOn(byId.get('tool-pwsh')!, 'linux'), 'tool-pwsh on linux').toBe(true)
- // The Web surface owns the host tool-bash row on every platform: sessions
- // mount their own preset rows instead.
- expect(byId.get('tool-bash')?.disabled).toBe(true)
- // The permission surface never moves: the sandbox/policy rows, the
- // permission switcher, fs-sandbox, and the approval service stay enabled
- // exactly as on POSIX — the confined pwsh executor is what changes.
- for (const id of ['permission', 'ui-permission', 'sandbox', 'sandbox-policy', 'fs-sandbox', 'approval']) {
- expect(byId.get(id)?.disabled, `row ${id}`).not.toBe(true)
- }
- // The launcher's cold-start module fallback BFS-links the apps/cli
- // dependency closure into the profile's node_modules, so every bare
- // plugin name in the base patch must resolve from there.
- const cliManifest = JSON.parse(readFileSync(anchor, 'utf8')) as { dependencies?: Record<string, string> }
- for (const name of ['@deepseek-ai/dsh-pwsh-sandbox', '@deepseek-ai/dsh-tool-pwsh']) {
- expect(cliManifest.dependencies?.[name], `cold-start closure must reach ${name}`).toBeDefined()
- }
- expect(warnings).toEqual([])
- })
- it('base-only profiles carry both stacks with the same platform gating', () => {
- home = mkdtempSync(join(tmpdir(), 'dsh-windows-home-'))
- initProfile(join(home, PROFILES_DIR, 'base-only'), ['@deepseek-ai/dsh-base'])
- const profile = loadProfile('dsh', 'base-only', anchor, home)
- const warnings: string[] = []
- const rows = composeEntries(
- profile.layers.map(layer => layer.patches),
- message => warnings.push(message),
- )
- const byId = new Map(rows.map(row => [row.id, row]))
- for (const id of ['bash-sandbox', 'tool-bash', 'pwsh-sandbox', 'tool-pwsh']) {
- expect(byId.has(id), `row ${id}`).toBe(true)
- }
- // No web overlay: the tool rows keep their own gating too.
- expect(disabledOn(byId.get('tool-bash')!, 'win32'), 'tool-bash on win32').toBe(true)
- expect(disabledOn(byId.get('tool-bash')!, 'linux'), 'tool-bash on linux').toBe(false)
- expect(disabledOn(byId.get('tool-pwsh')!, 'win32'), 'tool-pwsh on win32').toBe(false)
- expect(disabledOn(byId.get('tool-pwsh')!, 'linux'), 'tool-pwsh on linux').toBe(true)
- expect(warnings).toEqual([])
- })
- })
- describe('shipped agent presets keep tool-bash off the win32 roster', () => {
- const presetRoot = resolve(fileURLToPath(new URL('../package.json', import.meta.url)), '..', 'config', 'agent-presets')
- it.each(['standard', 'code', 'cordis'])('preset %s gates its tool-bash row by platform', (preset) => {
- const entries: unknown = yaml.load(
- readFileSync(join(presetRoot, preset, 'agent.cordis.yml'), 'utf8'),
- { schema: entryListSchema },
- )
- if (!Array.isArray(entries)) throw new TypeError(`preset ${preset} must parse to an entry array`)
- const row = entries.find((entry): entry is Record<string, unknown> => (
- typeof entry === 'object' && entry !== null && (entry as Record<string, unknown>).id === 'tool-bash'
- ))
- if (row === undefined) throw new TypeError(`preset ${preset} must mount tool-bash`)
- expect(row.disabled).toMatchObject({ __jsExpr: expect.any(String) as string })
- // The base patch gates the host tool-bash row on win32; the preset row
- // must not re-enable it there. Evaluate the shipped expression with a
- // platform-scoped context (the `with` scope shadows the global
- // `process`) so both outcomes pin on every host.
- const expression = (row.disabled as { __jsExpr: string }).__jsExpr
- expect(Boolean(evaluate({ process: { platform: 'win32' } }, expression))).toBe(true)
- expect(Boolean(evaluate({ process: { platform: 'linux' } }, expression))).toBe(false)
- })
- it('minimal mounts no tool-bash row at all (its shell is the PTY stack)', () => {
- const entries: unknown = yaml.load(
- readFileSync(join(presetRoot, 'minimal', 'agent.cordis.yml'), 'utf8'),
- { schema: entryListSchema },
- )
- if (!Array.isArray(entries)) throw new TypeError('minimal preset must parse to an entry array')
- expect(entries.some(entry => (
- typeof entry === 'object' && entry !== null && (entry as Record<string, unknown>).id === 'tool-bash'
- ))).toBe(false)
- })
- })
|