|
|
@@ -1,5 +1,5 @@
|
|
|
import { randomUUID } from 'node:crypto'
|
|
|
-import { mkdir, mkdtemp, readFile, stat, writeFile } from 'node:fs/promises'
|
|
|
+import { mkdir, mkdtemp, readFile, stat, symlink, writeFile } from 'node:fs/promises'
|
|
|
import { tmpdir } from 'node:os'
|
|
|
import { fileURLToPath } from 'node:url'
|
|
|
import { dirname, join } from 'node:path'
|
|
|
@@ -9,7 +9,7 @@ import { provideCmdline } from '@deepseek-ai/dsh-cmdline'
|
|
|
import { SessionId } from '@deepseek-ai/dsh-session'
|
|
|
import type { Agent } from '@deepseek-ai/dsh-agent'
|
|
|
import type { PatchOptions } from '@deepseek-ai/cordis-plugin-include'
|
|
|
-import { afterAll, beforeAll, describe, expect, it } from 'vitest'
|
|
|
+import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest'
|
|
|
import { settingsNamespace } from '@deepseek-ai/dsh-settings'
|
|
|
import { resolveSessionPreset, SETTINGS_NAMESPACE } from '@deepseek-ai/dsh-agent-presets'
|
|
|
import { applyChildComposition, childSessionMeta } from '@deepseek-ai/dsh-subagent'
|
|
|
@@ -26,6 +26,8 @@ const REPO_ROOT = fileURLToPath(new URL('../../..', import.meta.url))
|
|
|
/** The shipped Web surface: the dsh-base and dsh-web-app bundle patches over an empty preset root. */
|
|
|
const BASE_PATCH = join(REPO_ROOT, 'packages/bundle/base/cordis.patch.yml')
|
|
|
const WEB_PATCH = join(REPO_ROOT, 'packages/bundle/web-app/cordis.patch.yml')
|
|
|
+const CODEX_PATCH = join(REPO_ROOT, 'packages/subagent/subagent-codex/cordis.patch.yml')
|
|
|
+const CLAUDE_CODE_PATCH = join(REPO_ROOT, 'packages/subagent/subagent-claude-code/cordis.patch.yml')
|
|
|
/** The installation anchor whose dependency surface the preset module fallback mirrors. */
|
|
|
const INSTALL_ANCHOR = join(REPO_ROOT, 'apps/cli/package.json')
|
|
|
const MINIMAL_PROMPT = 'You are a helpful software engineer assistant.'
|
|
|
@@ -43,7 +45,11 @@ const MINIMAL_BASH_DESCRIPTION = `Run commands in a bash shell
|
|
|
* touch the network, or write outside the test. Everything that decides an
|
|
|
* agent's capabilities is the real thing, including both shipped presets.
|
|
|
*/
|
|
|
-async function bootWeb(settingsFile: string, extra: PatchOptions[] = []): Promise<Context> {
|
|
|
+async function bootWeb(
|
|
|
+ settingsFile: string,
|
|
|
+ extra: PatchOptions[] = [],
|
|
|
+ profilePackages: readonly string[] = [],
|
|
|
+): Promise<Context> {
|
|
|
const storageRoot = join(dirname(settingsFile), 'storages')
|
|
|
const patches: PatchOptions[] = [
|
|
|
...loadOverlayPatches('dsh-test', BASE_PATCH),
|
|
|
@@ -112,6 +118,16 @@ async function bootWeb(settingsFile: string, extra: PatchOptions[] = []): Promis
|
|
|
healProfilesModuleFallback(INSTALL_ANCHOR, home)
|
|
|
const profileDir = join(home, 'profiles', 'spec')
|
|
|
await mkdir(profileDir, { recursive: true })
|
|
|
+ // Product Bundles are installed into the Profile, not the dsh app. Model
|
|
|
+ // pnpm's package link for only the selected products; their own production
|
|
|
+ // dependencies resolve from the linked workspace packages, while shared
|
|
|
+ // peers still resolve through the installation fallback above.
|
|
|
+ for (const packageDir of profilePackages) {
|
|
|
+ const manifest = JSON.parse(await readFile(join(packageDir, 'package.json'), 'utf8')) as { name: string }
|
|
|
+ const link = join(profileDir, 'node_modules', manifest.name)
|
|
|
+ await mkdir(dirname(link), { recursive: true })
|
|
|
+ await symlink(packageDir, link, 'junction')
|
|
|
+ }
|
|
|
const rootConfig = join(profileDir, 'cordis.yml')
|
|
|
await writeFile(rootConfig, '[]\n')
|
|
|
return await boot('dsh-test', rootConfig, patches, (bootCtx) => {
|
|
|
@@ -416,17 +432,17 @@ describe('the shipped Web composition', () => {
|
|
|
})
|
|
|
})
|
|
|
|
|
|
-describe('product subagent rows in user presets', () => {
|
|
|
- let productCtx: Context
|
|
|
- const ids = ['products-none', 'products-codex', 'products-claude', 'products-both'] as const
|
|
|
+describe('product subagent Bundle and user-preset intersection', () => {
|
|
|
+ const presetIds = ['products-none', 'products-codex', 'products-claude', 'products-both'] as const
|
|
|
+ type Product = 'codex' | 'claude-code'
|
|
|
|
|
|
- beforeAll(async () => {
|
|
|
+ async function bootProducts(installed: readonly Product[]): Promise<Context> {
|
|
|
const root = await mkdtemp(join(tmpdir(), 'dsh-product-presets-'))
|
|
|
const userRoot = join(root, 'presets')
|
|
|
const settingsFile = join(root, 'settings.yaml')
|
|
|
const standard = await readFile(join(CONFIG_DIR, 'agent-presets', 'standard', 'agent.cordis.yml'), 'utf8')
|
|
|
await writeFile(settingsFile, '{}\n')
|
|
|
- for (const id of ids) {
|
|
|
+ for (const id of presetIds) {
|
|
|
let composition = standard
|
|
|
if (id === 'products-codex' || id === 'products-both') {
|
|
|
composition = enablePresetTool(composition, 'tool-subagent-codex')
|
|
|
@@ -438,50 +454,75 @@ describe('product subagent rows in user presets', () => {
|
|
|
await mkdir(directory, { recursive: true })
|
|
|
await writeFile(join(directory, 'agent.cordis.yml'), composition)
|
|
|
}
|
|
|
- productCtx = await bootWeb(settingsFile, [{
|
|
|
- id: 'agent-presets',
|
|
|
- config: {
|
|
|
- default: 'standard',
|
|
|
- roots: [
|
|
|
- { path: join(CONFIG_DIR, 'agent-presets'), trust: 'system' },
|
|
|
- { path: userRoot, trust: 'user' },
|
|
|
- ],
|
|
|
- includeUserRoot: false,
|
|
|
+ const productPatches = installed.flatMap(product => loadOverlayPatches(
|
|
|
+ 'dsh-test',
|
|
|
+ product === 'codex' ? CODEX_PATCH : CLAUDE_CODE_PATCH,
|
|
|
+ ))
|
|
|
+ return await bootWeb(settingsFile, [
|
|
|
+ ...productPatches,
|
|
|
+ {
|
|
|
+ id: 'agent-presets',
|
|
|
+ config: {
|
|
|
+ default: 'standard',
|
|
|
+ roots: [
|
|
|
+ { path: join(CONFIG_DIR, 'agent-presets'), trust: 'system' },
|
|
|
+ { path: userRoot, trust: 'user' },
|
|
|
+ ],
|
|
|
+ includeUserRoot: false,
|
|
|
+ },
|
|
|
},
|
|
|
- }])
|
|
|
- }, 120_000)
|
|
|
-
|
|
|
- afterAll(async () => {
|
|
|
- await productCtx.fiber.dispose()
|
|
|
- })
|
|
|
+ ], installed.map(product => dirname(product === 'codex' ? CODEX_PATCH : CLAUDE_CODE_PATCH)))
|
|
|
+ }
|
|
|
|
|
|
- it('composes none, either product, or both without changing the shared host registry', async () => {
|
|
|
- const expected = new Map<string, string[]>([
|
|
|
+ it('composes the intersection of installed Bundles and enabled preset rows', async () => {
|
|
|
+ const enabledByPreset = new Map<string, Product[]>([
|
|
|
['products-none', []],
|
|
|
- ['products-codex', ['subagent_codex']],
|
|
|
- ['products-claude', ['subagent_claude_code']],
|
|
|
- ['products-both', ['subagent_claude_code', 'subagent_codex']],
|
|
|
+ ['products-codex', ['codex']],
|
|
|
+ ['products-claude', ['claude-code']],
|
|
|
+ ['products-both', ['codex', 'claude-code']],
|
|
|
])
|
|
|
- expect(productCtx.subagents.list()).toEqual(expect.arrayContaining([
|
|
|
- 'spawn', 'fork', 'codex', 'claude-code',
|
|
|
- ]))
|
|
|
-
|
|
|
- for (const [id, productTools] of expected) {
|
|
|
- const handle = await productCtx.agents.create({
|
|
|
- sessionId: SessionId(`preset-${id}`),
|
|
|
- setup: agentCtx => productCtx.agentPresets.mount(agentCtx, id).then(() => undefined),
|
|
|
- })
|
|
|
+ const installations: Product[][] = [
|
|
|
+ [],
|
|
|
+ ['codex'],
|
|
|
+ ['claude-code'],
|
|
|
+ ['codex', 'claude-code'],
|
|
|
+ ]
|
|
|
+
|
|
|
+ for (const installed of installations) {
|
|
|
+ const productCtx = await bootProducts(installed)
|
|
|
+ const spawn = vi.spyOn(productCtx.subprocess, 'spawn')
|
|
|
try {
|
|
|
- const tools = toolNames(productCtx, handle.agent)
|
|
|
- expect(tools.filter(name => name === 'subagent_codex' || name === 'subagent_claude_code'))
|
|
|
- .toEqual(productTools)
|
|
|
+ expect(productCtx.subagents.list()
|
|
|
+ .filter(name => name === 'codex' || name === 'claude-code')
|
|
|
+ .sort())
|
|
|
+ .toEqual([...installed].sort())
|
|
|
+ for (const [id, enabled] of enabledByPreset) {
|
|
|
+ const handle = await productCtx.agents.create({
|
|
|
+ sessionId: SessionId(`preset-${id}-${installed.join('-') || 'none'}-${randomUUID()}`),
|
|
|
+ setup: agentCtx => productCtx.agentPresets.mount(agentCtx, id).then(() => undefined),
|
|
|
+ })
|
|
|
+ try {
|
|
|
+ const expectedTools = enabled
|
|
|
+ .filter(product => installed.includes(product))
|
|
|
+ .map(product => product === 'codex' ? 'subagent_codex' : 'subagent_claude_code')
|
|
|
+ .sort()
|
|
|
+ expect(toolNames(productCtx, handle.agent)
|
|
|
+ .filter(name => name === 'subagent_codex' || name === 'subagent_claude_code'))
|
|
|
+ .toEqual(expectedTools)
|
|
|
+ } finally {
|
|
|
+ await handle.dispose()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ expect(spawn).not.toHaveBeenCalled()
|
|
|
} finally {
|
|
|
- await handle.dispose()
|
|
|
+ spawn.mockRestore()
|
|
|
+ await productCtx.fiber.dispose()
|
|
|
}
|
|
|
}
|
|
|
- })
|
|
|
+ }, 120_000)
|
|
|
|
|
|
it('applies a product-row edit only to later sessions on the preset', async () => {
|
|
|
+ const productCtx = await bootProducts(['codex'])
|
|
|
const preset = await productCtx.agentPresets.resolve('products-none')
|
|
|
const original = await readFile(preset.path, 'utf8')
|
|
|
const existing = await productCtx.agents.create({
|
|
|
@@ -505,8 +546,9 @@ describe('product subagent rows in user presets', () => {
|
|
|
} finally {
|
|
|
await existing.dispose()
|
|
|
await writeFile(preset.path, original)
|
|
|
+ await productCtx.fiber.dispose()
|
|
|
}
|
|
|
- })
|
|
|
+ }, 120_000)
|
|
|
})
|
|
|
|
|
|
describe('a switch survives the session', () => {
|