Merge branch 'master' into feature/minimal-compact-image

This commit is contained in:
LogosVeritas committed 2026-10-13 10:32:01 +08:00
commit 00a007d833
734 files changed
+19749 -4630

No files matched your search

@@ -0,0 +1,203 @@
/** Credential selection through the shipped headless profile and real HTTP adapters. */
import { mkdir, readFile, writeFile } from 'node:fs/promises'
import { createServer } from 'node:http'
import { once } from 'node:events'
import type { AddressInfo } from 'node:net'
import { join } from 'node:path'
import { fileURLToPath } from 'node:url'
import { startMockLlmServer } from '@deepseek-ai/dsh-llm-mock-server'
import { runLoaderSmoke } from '@deepseek-ai/dsh-loader-smoke'
import { describe, expect, it } from 'vitest'
const binScript = fileURLToPath(new URL('../../../../../../apps/cli/src/bin.ts', import.meta.url))
const tsconfigPath = fileURLToPath(new URL('../../../../../../tsconfig.json', import.meta.url))
const savedKey = 'headless-saved-key'
const launchKey = 'headless-launch-key'
const projectKey = 'headless-project-key'
const homeKey = 'headless-home-key'
const processTimeoutMs = 60_000
/** Anthropic SDK events require the SSE event name beside the JSON payload. */
async function startAnthropicServer() {
const keys: Array<string | string[] | undefined> = []
const server = createServer((request, response) => {
keys.push(request.headers['x-api-key'])
request.resume()
response.writeHead(200, { 'content-type': 'text/event-stream' })
for (const event of [
{ type: 'message_start', message: { id: 'auth-test', type: 'message', role: 'assistant', model: 'headless-auth-model', content: [], usage: { input_tokens: 1, output_tokens: 0 } } },
{ type: 'content_block_start', index: 0, content_block: { type: 'text', text: '' } },
{ type: 'content_block_delta', index: 0, delta: { type: 'text_delta', text: 'mock response recovered' } },
{ type: 'content_block_stop', index: 0 },
{ type: 'message_delta', delta: { stop_reason: 'end_turn', stop_sequence: null }, usage: { output_tokens: 1 } },
{ type: 'message_stop' },
]) response.write(`event: ${event.type}\ndata: ${JSON.stringify(event)}\n\n`)
response.end()
})
server.listen(0, '127.0.0.1')
await once(server, 'listening')
return {
keys,
baseURL: `http://127.0.0.1:${(server.address() as AddressInfo).port}`,
async close() {
server.closeAllConnections()
await new Promise<void>((resolve, reject) => server.close((error) => {
if (error === undefined) resolve()
else reject(error)
}))
},
}
}
const credentials = JSON.stringify({
version: 1,
refs: { DEEPSEEK_API_KEY: savedKey, ANTHROPIC_API_KEY: savedKey },
records: {
'llm-pi-ai/anthropic': { kind: 'api-key', key: savedKey },
'llm-pi-ai/openai-codex': {
kind: 'grant', payload: { type: 'oauth', access: 'headless-saved-access', refresh: 'headless-saved-refresh', expires: 1 },
},
},
}) + '\n'
describe('headless credential policy', { retry: 0 }, () => {
it.each([
{ name: 'launch environment', launch: launchKey, project: projectKey, home: homeKey, expected: launchKey },
{ name: 'project .env', launch: undefined, project: projectKey, home: homeKey, expected: projectKey },
{ name: 'home .env', launch: undefined, project: undefined, home: homeKey, expected: homeKey },
])('uses $name instead of saved credentials', async (scenario) => {
const server = await startMockLlmServer({ sequence: ['success'], repeatLast: true, apiKey: scenario.expected })
try {
const result = await runLoaderSmoke({
label: `headless credentials: ${scenario.name}`,
tempDirPrefix: 'headless-credentials-', binScript, tsconfigPath, sourceImport: 'tsx/esm',
configPath: '', binArgs: ['headless', 'Reply briefly.'], processTimeoutMs,
env: {
DEEPSEEK_API_KEY: scenario.launch, DEEPSEEK_BASE_URL: server.baseURL, DSH_TELEMETRY_DISABLED: '1',
},
prepare: async (cwd) => {
await mkdir(join(cwd, '.dsh'), { recursive: true })
await writeFile(join(cwd, '.dsh', '.credentials.yaml'), credentials, { mode: 0o600 })
if (scenario.project !== undefined) await writeFile(join(cwd, '.env'), `DEEPSEEK_API_KEY=${scenario.project}\n`)
if (scenario.home !== undefined) await writeFile(join(cwd, '.dsh', '.env'), `DEEPSEEK_API_KEY=${scenario.home}\n`)
},
inspect: async (cwd) => {
expect(await readFile(join(cwd, '.dsh', '.credentials.yaml'), 'utf8')).toBe(credentials)
},
})
expect(result.stdout.trim()).toBe('mock response recovered')
expect(result.stderr).toBe('')
expect(server.requests.length).toBeGreaterThan(0)
expect(server.requests.every(request => request.headers['x-api-key'] === scenario.expected)).toBe(true)
} finally {
await server.close()
}
}, processTimeoutMs + 15_000)
it.each(['named reference', 'native discovery'] as const)('uses launch credentials for pi-ai %s', async (mode) => {
const server = await startAnthropicServer()
try {
const result = await runLoaderSmoke({
label: `headless pi-ai credentials: ${mode}`,
tempDirPrefix: 'headless-pi-credentials-', binScript, tsconfigPath, sourceImport: 'tsx/esm',
configPath: '', binArgs: ['headless', '--patch', './auth.patch.json', 'Reply briefly.'], processTimeoutMs,
env: {
ANTHROPIC_API_KEY: launchKey, ANTHROPIC_AUTH_TOKEN: undefined, ANTHROPIC_OAUTH_TOKEN: undefined,
ANTHROPIC_FEDERATION_RULE_ID: undefined, ANTHROPIC_ORGANIZATION_ID: undefined,
ANTHROPIC_IDENTITY_TOKEN_FILE: undefined, ANTHROPIC_SERVICE_ACCOUNT_ID: undefined, ANTHROPIC_WORKSPACE_ID: undefined,
DEEPSEEK_API_KEY: undefined, DSH_TELEMETRY_DISABLED: '1',
},
prepare: async (cwd) => {
await mkdir(join(cwd, '.dsh'), { recursive: true })
await writeFile(join(cwd, '.dsh', '.credentials.yaml'), credentials, { mode: 0o600 })
await writeFile(join(cwd, 'auth.patch.json'), JSON.stringify([
{ id: 'agent-default-model', config: { provider: 'anthropic', model: 'headless-auth-model' } },
{ id: 'llm-pi-ai', config: { providers: { anthropic: {
...mode === 'named reference' ? { apiKeyEnv: 'ANTHROPIC_API_KEY' } : {},
baseURL: server.baseURL,
models: [{ id: 'headless-auth-model', contextWindow: 32_768, maxTokens: 1024 }],
} } } },
]))
},
inspect: async (cwd) => {
expect(await readFile(join(cwd, '.dsh', '.credentials.yaml'), 'utf8')).toBe(credentials)
},
})
expect(result.stdout.trim()).toBe('mock response recovered')
expect(result.stderr).toBe('')
expect(server.keys.length).toBeGreaterThan(0)
expect(server.keys.every(key => key === launchKey)).toBe(true)
} finally {
await server.close()
}
}, processTimeoutMs + 15_000)
it.each(['no environment key', 'empty environment key', 'invalid stored document', 'restore stored credentials'] as const)('%s', async (mode) => {
const restoring = mode === 'restore stored credentials'
const empty = mode === 'empty environment key'
const missing = mode === 'no environment key' || empty
const document = mode === 'invalid stored document' ? 'invalid: [\n' : credentials
const server = await startMockLlmServer({ sequence: ['success'], repeatLast: true, apiKey: restoring ? savedKey : launchKey })
try {
const result = await runLoaderSmoke({
label: `headless credential boundary: ${mode}`,
tempDirPrefix: 'headless-credential-boundary-', binScript, tsconfigPath, sourceImport: 'tsx/esm',
configPath: '',
binArgs: ['headless', ...restoring ? ['--patch', './auth.patch.json'] : [], 'Reply briefly.'],
processTimeoutMs, expectedExitCode: missing ? 1 : 0,
env: { DEEPSEEK_API_KEY: empty ? '' : missing ? undefined : launchKey, DEEPSEEK_BASE_URL: server.baseURL, DSH_TELEMETRY_DISABLED: '1' },
prepare: async (cwd) => {
await mkdir(join(cwd, '.dsh'), { recursive: true })
await writeFile(join(cwd, '.dsh', '.credentials.yaml'), document, { mode: 0o600 })
if (empty) await writeFile(join(cwd, '.env'), `DEEPSEEK_API_KEY=${projectKey}\n`)
if (restoring) await writeFile(join(cwd, 'auth.patch.json'), JSON.stringify(
['credentials', 'authorization', 'deepseek-account'].map(id => ({ id, disabled: false })),
))
},
inspect: async (cwd) => {
expect(await readFile(join(cwd, '.dsh', '.credentials.yaml'), 'utf8')).toBe(document)
},
})
if (missing) {
expect(result.stdout).toBe('\n')
expect(result.stderr).toContain('MISSING_CREDENTIAL')
expect(server.requests).toHaveLength(0)
} else {
expect(result.stdout.trim()).toBe('mock response recovered')
expect(result.stderr).toBe('')
expect(server.requests.length).toBeGreaterThan(0)
}
} finally {
await server.close()
}
}, processTimeoutMs + 15_000)
it.each([
{ provider: 'deepseek-account', model: 'deepseek-v4-flash', code: 'ACCOUNT_SIGN_IN_REQUIRED' },
{ provider: 'openai-codex', model: 'gpt-5.4', code: 'PI_AI_ERROR: Provider is not configured: openai-codex' },
])('fails without saved sign-in for $provider', async ({ provider, model, code }) => {
const result = await runLoaderSmoke({
label: `headless saved sign-in: ${provider}`,
tempDirPrefix: 'headless-saved-sign-in-', binScript, tsconfigPath, sourceImport: 'tsx/esm',
configPath: '', binArgs: ['headless', '--patch', './auth.patch.json', 'Reply briefly.'],
processTimeoutMs, expectedExitCode: 1,
env: { DEEPSEEK_API_KEY: undefined, OPENAI_API_KEY: undefined, DSH_TELEMETRY_DISABLED: '1' },
prepare: async (cwd) => {
await mkdir(join(cwd, '.dsh'), { recursive: true })
await writeFile(join(cwd, '.dsh', '.credentials.yaml'), credentials, { mode: 0o600 })
await writeFile(join(cwd, 'auth.patch.json'), JSON.stringify([
{ id: 'agent-default-model', config: { provider, model } },
...provider === 'openai-codex' ? [{ id: 'llm-pi-ai', config: { providers: {
[provider]: { models: [{ id: model, contextWindow: 32_768, maxTokens: 1024 }] },
} } }] : [],
]))
},
inspect: async (cwd) => {
expect(await readFile(join(cwd, '.dsh', '.credentials.yaml'), 'utf8')).toBe(credentials)
},
})
expect(result.stdout).toBe('\n')
expect(result.stderr).toContain(code)
expect(result.stderr).not.toContain('pending')
}, processTimeoutMs + 15_000)
})
@@ -15,6 +15,8 @@
{"type":"session/title-llm-request","data":{"titleProvider":"session-title-first-prompt-llm","messageSeqs":[8],"route":{"provider":"cli-mock","model":"cli-mock"},"system":"Create a concise title for an AI coding-assistant session from the supplied human messages.\nReturn only the title on one line, **in plain text of natural language**, with no quotes, prefix, explanation, Markdown, XML, or terminal control codes. No code is allowed.\nUse the language of the messages.\nAim for about 5 words in non-CJK languages or 10 CJK characters.\nIf the messages give little to name, still return a short best-effort title, such as Greeting, instead of explaining.","messages":[{"content":[{"type":"text","text":"Generate the session title from this JSON array of human messages:\n[{\"seq\":8,\"text\":\"Prove the product headless profile path with one real tool round trip.\"}]"}],"source":{"kind":"dsh-session-title-llm"},"role":"user","id":"{{sessionId}}"}],"maxTokens":4096,"reasoningEffort":"off"}}
{"type":"assistant/message","data":{"turn":1,"step":1,"message":{"role":"assistant","content":[{"type":"reasoning","text":"Inspecting the task before the tool call."},{"type":"tool-call","id":"cli-smoke-call","name":"bash","arguments":"{\"command\":\"printf CLI_TOOL_ROUND_TRIP\",\"description\":\"Prove the CLI tool round trip.\"}"}],"source":{"kind":"model","provider":"cli-mock","model":"cli-mock"},"id":"{{sessionId}}"},"usage":{"inputTokens":11,"outputTokens":3,"cacheReadTokens":2},"stream":[{"type":"chunk","time":0,"chunk":{"type":"block-start","index":0,"blockType":"reasoning"}},{"type":"reasoning-chunks","time0":0,"index":0,"dt":[],"texts":["Inspecting the task before the tool call."]},{"type":"chunk","time":0,"chunk":{"type":"block-end","index":0,"block":{"type":"reasoning","text":"Inspecting the task before the tool call."}}},{"type":"chunk","time":0,"chunk":{"type":"block-start","index":1,"blockType":"tool-call"}},{"type":"tool-call-chunks","time0":0,"index":1,"dt":[],"id":"cli-smoke-call","name":"bash","args":["{\"command\":\"printf CLI_TOOL_ROUND_TRIP\",\"description\":\"Prove the CLI tool round trip.\"}"]},{"type":"chunk","time":0,"chunk":{"type":"block-end","index":1,"block":{"type":"tool-call","id":"cli-smoke-call","name":"bash","arguments":"{\"command\":\"printf CLI_TOOL_ROUND_TRIP\",\"description\":\"Prove the CLI tool round trip.\"}"}}},{"type":"chunk","time":0,"chunk":{"type":"usage","usage":{"inputTokens":11,"outputTokens":3,"cacheReadTokens":2}}},{"type":"chunk","time":0,"chunk":{"type":"finish","reason":{"kind":"tool-calls"}}}]},"surfaceOp":"append"}
{"type":"tool/call","data":{"turn":1,"step":1,"callId":"cli-smoke-call","name":"bash","arguments":"{\"command\":\"printf CLI_TOOL_ROUND_TRIP\",\"description\":\"Prove the CLI tool round trip.\"}"}}
{"type":"job/registered","data":{"jobId":"{{id:1}}","owner":"{{sessionId}}","kind":"bash","label":"printf CLI_TOOL_ROUND_TRIP","startedAt":0,"toolCall":{"callId":"cli-smoke-call","rootCallId":"cli-smoke-call"}}}
{"type":"job/settled","data":{"jobId":"{{id:1}}","owner":"{{sessionId}}","kind":"bash","label":"printf CLI_TOOL_ROUND_TRIP","startedAt":0,"toolCall":{"callId":"cli-smoke-call","rootCallId":"cli-smoke-call"},"finishedAt":0,"status":"completed","cause":"producer","producerReported":true,"detail":"exit code: 0"}}
{"type":"tool/result","data":{"turn":1,"step":1,"message":{"role":"tool","source":{"kind":"tool","callId":"cli-smoke-call"},"toolCallId":"cli-smoke-call","content":[{"type":"text","text":"CLI_TOOL_ROUND_TRIP"}],"isError":false,"id":"{{sessionId}}"},"meta":{"cwd":"{{cwd}}"}},"sourceEventSeqs":[15],"surfaceOp":"append"}
{"type":"step/end","data":{"turn":1,"step":1}}
{"type":"step/start","data":{"turn":1,"step":2}}
@@ -11,7 +11,7 @@ import * as ToolTodo from '@deepseek-ai/dsh-tool-todo'
import * as LlmDeepSeek from '@deepseek-ai/dsh-llm-deepseek-api-key'
import TokenMeter from '@deepseek-ai/dsh-token-meter'
import ToolResultPruner from '@deepseek-ai/dsh-compaction-tool-result-pruner'
import JsonlSessionPersistence from '@deepseek-ai/dsh-session-persistence-jsonl'
import * as JsonlSessionPersistence from '@deepseek-ai/dsh-session-persistence-jsonl'
import * as SessionCheckpointPolicy from '@deepseek-ai/dsh-session-checkpoint-policy'
import { BasicCompactionEngine } from '@deepseek-ai/dsh-compaction-basic'
import type { BasicCompactionConfig } from '@deepseek-ai/dsh-compaction-basic'
@@ -212,7 +212,7 @@ describe('PTC mode typed values: keyless real-process contracts', () => {
});
return started.jobId;
`))
expect(jobId).toBe('bash-1')
expect(jobId).toMatch(/^bash-[0-9a-f]{16}$/)
const polled = completion(await runCode(ctx, `
return await tools.job_output({ job_id: ${JSON.stringify(jobId)}, wait: true, timeout_ms: 5000 });
@@ -257,7 +257,8 @@ describe('PTC mode typed values: keyless real-process contracts', () => {
}),
])
const job = ctx.jobs.list()[0]
expect(job).toMatchObject({ id: 'bash-1', status: 'running' })
expect(job).toMatchObject({ status: 'running' })
expect(job?.id).toMatch(/^bash-[0-9a-f]{16}$/)
afterPublication.abort('outer-call-cancelled')
expect((await running).isError).toBe(true)
expect(ctx.jobs.list()[0]).toMatchObject({ id: job!.id, status: 'running' })
@@ -11,7 +11,7 @@ import {
import { LOADER_SMOKE_TEST_TIMEOUT_MS, runLoaderSmoke } from '@deepseek-ai/dsh-loader-smoke'
import { createUserMessage, ToolCallId, createMessage } from '@deepseek-ai/dsh-llm'
import { SessionSeq, SESSION_FORMAT_VERSION, SessionId, type SessionEvent, type SessionHeader } from '@deepseek-ai/dsh-session'
import JsonlSessionPersistence from '@deepseek-ai/dsh-session-persistence-jsonl'
import * as JsonlSessionPersistence from '@deepseek-ai/dsh-session-persistence-jsonl'
import { logPath } from '../../../../../../packages/session/session-persistence-jsonl/src/format.ts'
import { describe, expect, it } from 'vitest'
@@ -17,7 +17,7 @@ import {
type SessionEvent,
type SessionHeader,
} from '@deepseek-ai/dsh-session'
import JsonlSessionPersistence from '@deepseek-ai/dsh-session-persistence-jsonl'
import * as JsonlSessionPersistence from '@deepseek-ai/dsh-session-persistence-jsonl'
import {
generationLogFilename,
generationLogPath,
@@ -16,7 +16,7 @@ import {
import { LOADER_SMOKE_TEST_TIMEOUT_MS, runLoaderSmoke } from '@deepseek-ai/dsh-loader-smoke'
import { createMessage, createUserMessage } from '@deepseek-ai/dsh-llm'
import { SessionSeq, SESSION_FORMAT_VERSION, SessionId, type SessionEvent, type SessionHeader } from '@deepseek-ai/dsh-session'
import JsonlSessionPersistence from '@deepseek-ai/dsh-session-persistence-jsonl'
import * as JsonlSessionPersistence from '@deepseek-ai/dsh-session-persistence-jsonl'
import { describe, expect, it } from 'vitest'
const fixtureDir = fileURLToPath(new URL('./expected/subagent-diagnostic', import.meta.url))
@@ -16,7 +16,7 @@ import {
import { LOADER_SMOKE_TEST_TIMEOUT_MS, runLoaderSmoke } from '@deepseek-ai/dsh-loader-smoke'
import { createMessage, createUserMessage, ReasoningEffortId } from '@deepseek-ai/dsh-llm'
import { SessionSeq, SESSION_FORMAT_VERSION, SessionId, type SessionEvent, type SessionHeader } from '@deepseek-ai/dsh-session'
import JsonlSessionPersistence from '@deepseek-ai/dsh-session-persistence-jsonl'
import * as JsonlSessionPersistence from '@deepseek-ai/dsh-session-persistence-jsonl'
import { describe, expect, it } from 'vitest'
const fixtureDir = fileURLToPath(new URL('./expected/subagent-inheritance', import.meta.url))
@@ -23,7 +23,7 @@ import {
type SessionEvent,
type SessionHeader,
} from '@deepseek-ai/dsh-session'
import JsonlSessionPersistence from '@deepseek-ai/dsh-session-persistence-jsonl'
import * as JsonlSessionPersistence from '@deepseek-ai/dsh-session-persistence-jsonl'
import { logPath } from '../../../../../../packages/session/session-persistence-jsonl/src/format.ts'
import { renderAgentInstructions } from '@deepseek-ai/dsh-agent-instructions'
import { resolveConfig, workspaceBaselineIdentity } from '@deepseek-ai/dsh-agent-instructions/src/config.ts'
@@ -530,8 +530,11 @@ it.each(['unset', 'empty', 'bundled', 'full', 'python-only', 'python-only-no-cli
}, () => stderr)
const names = (requests[0]!.tools as { name: string }[]).map(value => value.name)
expect(names.includes('load_workspace_dependencies')).toBe(enabled)
expect(JSON.stringify(requests[0]!.messages).includes('`office`')).toBe(enabled && mode !== 'missing-assets')
expect(names).not.toContain('office_tools')
expect(names).not.toContain('render_document')
for (const name of ['office-docx', 'office-pptx', 'office-xlsx']) {
expect(JSON.stringify(requests[0]!.messages).includes(name)).toBe(enabled && mode !== 'missing-assets' && mode !== 'python-only')
expect(JSON.stringify(requests[0]!.messages).includes(name)).toBe(enabled && mode !== 'missing-assets')
}
if (mode === 'wrong-type') {
expect(requests).toHaveLength(2)
@@ -560,8 +563,8 @@ it.each(['unset', 'empty', 'bundled', 'full', 'python-only', 'python-only-no-cli
expect.objectContaining({ role: 'user', content }),
]))
}
if (mode === 'python-only') expect(stderr).toContain('node')
if (mode === 'missing-assets') expect(stderr).toContain('check_office.py')
if (mode === 'python-only') expect(stderr).not.toContain('ENOENT')
if (mode === 'missing-assets') expect(stderr).toContain('SKILL.md')
await send(3, 'shutdown')
const exit = await child
expect(exit.timedOut).toBe(false)
+11 -12
View File
@@ -2,7 +2,7 @@
* Agent discovery of the installed Office CLI through the shipped SDK profile.
* Defaults to built Node packages. DSH_OFFICE_TEST_EXECUTABLE/ENTRY select a
* relocated Node or Electron carrier; CARRIER=sdk selects the standalone executable.
* NODE/CLI/ASSETS under the same prefix supply Desktop resources outside ASAR.
* NODE/CLI/ASSETS under the same prefix select Desktop command and skill resources outside ASAR.
* API=openai-completions selects a development gateway instead of the default Messages API.
*/
import { access, mkdir, mkdtemp, readFile, rm, symlink, writeFile, chmod } from 'node:fs/promises'
@@ -29,16 +29,13 @@ it.skipIf(!process.env.DEEPSEEK_API_KEY || process.platform === 'win32')(`agent
'word/document.xml': strToU8('<?xml version="1.0"?><w:document xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:body><w:p><w:r><w:t>Office CLI discovery</w:t></w:r></w:p><w:sectPr/></w:body></w:document>'),
}))
const patch = join(root, 'office.patch.yml')
const node = process.env.DSH_OFFICE_TEST_NODE, cli = process.env.DSH_OFFICE_TEST_CLI
const assetRoot = process.env.DSH_OFFICE_TEST_ASSETS
await writeFile(patch, JSON.stringify([
...(process.env.DSH_OFFICE_TEST_API === 'openai-completions' ? [{ id: 'llm-deepseek', disabled: true }, { id: 'llm-pi-ai', config: { providers: { 'office-test': { api: 'openai-completions', apiKeyEnv: 'DEEPSEEK_API_KEY', baseURL: process.env.DEEPSEEK_BASE_URL, compat: { thinkingFormat: 'deepseek' }, models: [{ id: process.env.MODEL_NAME ?? 'deepseek-v4-flash', contextWindow: 128000, maxTokens: 8000 }] } } } }] : []),
{ id: 'session-persistence-jsonl', config: { root: join(root, 'sessions'), compression: 'none' } },
...carrier === 'sdk' ? [] : [{ insert: [{
id: 'office-cli-discovery', name: '@deepseek-ai/dsh-skill-office', config: {
...(process.env.DSH_OFFICE_TEST_NODE ? { node: process.env.DSH_OFFICE_TEST_NODE } : {}),
...(process.env.DSH_OFFICE_TEST_CLI ? { cli: process.env.DSH_OFFICE_TEST_CLI } : {}),
...(process.env.DSH_OFFICE_TEST_ASSETS ? { assetRoot: process.env.DSH_OFFICE_TEST_ASSETS } : {}),
},
}] }],
{ id: 'skill-office', disabled: false },
{ id: 'skill-office', config: { ...assetRoot === undefined ? {} : { assetRoot }, ...node === undefined ? {} : { node }, ...cli === undefined ? {} : { cli } } },
]))
// A private POSIX tool directory also excludes /usr/bin/node on Linux.
const path = join(root, 'bin')
@@ -54,7 +51,7 @@ it.skipIf(!process.env.DEEPSEEK_API_KEY || process.platform === 'win32')(`agent
await writeFile(decoy, '#!/bin/sh\nprintf invoked > ' + "'" + decoyMarker.replaceAll("'", "'\\''") + "'" + '\nexit 86\n')
await chmod(decoy, 0o755)
}
const lookup = await execa('/bin/sh', ['-c', 'command -v node || command -v libreoffice-kit'], { env: { PATH: path }, reject: false })
const lookup = await execa('/bin/sh', ['-c', 'command -v node || command -v dsoffice'], { env: { PATH: path }, reject: false })
expect(lookup.exitCode, 'the fixture must not expose Node or the Office CLI through PATH').not.toBe(0)
const child = execa(executable, [
...carrier === 'sdk' ? [] : [entry], '--profile', 'sdk', '--patch', patch,
@@ -103,10 +100,12 @@ it.skipIf(!process.env.DEEPSEEK_API_KEY || process.platform === 'win32')(`agent
const commands = calls.filter(call => call.name === 'bash')
expect(commands.length, diagnostic).toBeGreaterThan(0)
expect(calls.findIndex(call => call.name === 'skill'), diagnostic).toBeLessThan(calls.findIndex(call => call.name === 'bash'))
const commandText = JSON.stringify(commands)
for (const fragment of ['cli.js', 'capabilities', 'convert']) expect(commandText, diagnostic).toContain(fragment)
const commandText = commands.map((call) => {
if (typeof call.arguments !== 'string') throw new Error('Shell tool call did not contain serialized arguments')
return (JSON.parse(call.arguments) as { command: string }).command
}).join('\n')
for (const operation of ['capabilities', 'convert']) expect(commandText, diagnostic).toMatch(new RegExp(`\\s${operation}\\b`, 'u'))
expect(existsSync(decoyMarker), 'the agent must not invoke system Office when the bundled CLI is supplied').toBe(false)
expect(commandText, 'the skill supplies an entry; searching for other Office binaries is unnecessary').not.toMatch(/(?:which|whereis|command -v|find).{0,100}(?:libreoffice|soffice)/iu)
const capabilities = JSON.parse(await readFile(join(root, 'capabilities.json'), 'utf8')) as { runtime: { version: string; cliPath: string } }
expect(capabilities.runtime.version).toBe('0.1.5')
expect(capabilities.runtime.cliPath).toMatch(/lib[/\\]cli\.js$/u)
@@ -0,0 +1,12 @@
/** Ordinary Web leaves Office authoring composition to its carrier. */
import { expect, it } from 'vitest'
import { withDefaultWeb } from './default-web-process.ts'
it('does not mount Office skills, commands, or authoring dependencies in ordinary Web', async (test) => {
await withDefaultWeb(test, async ({ request }) => {
const roster = await request('roster')
for (const name of ['skill-office', 'office-commands', 'tool-workspace-dependencies']) {
expect(roster.plugins.some(plugin => plugin.name === name)).toBe(false)
}
})
})