mirror of
https://github.com/deepseek-ai/deepseek-harness
synced 2026-08-15 21:04:50 +00:00
# Conflicts: # docs/architecture.md # docs/config-catalog.md # docs/cordis-catalog/events.md # docs/cordis-catalog/services.md # docs/core-data-structures/core.md # docs/event-producer-consumer.md # docs/module-graph.md # examples/coding-agent/tests/code-mode.e2e.ts # examples/coding-agent/tests/coding-task.e2e.ts # examples/coding-agent/tests/compaction.e2e.ts # examples/coding-agent/tests/full-loop.e2e.ts # examples/coding-agent/tests/todo-write.e2e.ts # examples/cordis-agent/tests/cordis-tools.e2e.ts # packages/bash/tool-bash/tests/integration.spec.ts # packages/bash/tool-bash/tests/tools.spec.ts # packages/compact/compact-basic/tests/compact-loop-repro.spec.ts # packages/context/time-context/tests/time-context.spec.ts # packages/cordis/tool-cordis/src/api-catalog.ts # packages/cordis/tool-cordis/tests/integration.spec.ts # packages/core/agent-loop/README.md # packages/core/agent-loop/src/agent.ts # packages/core/agent-loop/src/index.ts # packages/core/agent-loop/tests/agent.spec.ts # packages/core/agent-loop/tests/cancel.spec.ts # packages/core/agent-loop/tests/config-session-id.spec.ts # packages/core/agent-loop/tests/contract-regressions.spec.ts # packages/core/agent-loop/tests/coverage-edges.spec.ts # packages/core/agent-loop/tests/interception.spec.ts # packages/core/agent-loop/tests/loop.spec.ts # packages/core/agent-loop/tests/properties.spec.ts # packages/core/agent-loop/tests/request-cache.e2e.ts # packages/core/agent-loop/tests/request-reconstruction.spec.ts # packages/core/agent-loop/tests/resume.spec.ts # packages/core/agent-loop/tests/scope-lifecycle.spec.ts # packages/core/agent-loop/tests/tool-order.spec.ts # packages/core/agent-loop/tests/turn-stop.spec.ts # packages/core/agent/src/types.ts # packages/examples/agent-spine-demo/README.md # packages/examples/agent-spine-demo/tests/agent-core.spec.ts # packages/examples/stdio-demo/README.md # packages/examples/stdio-demo/src/index.ts # packages/examples/stdio-demo/tests/stdio-agent.spec.ts # packages/fs/tool-fs/tests/fs-tools.e2e.ts # packages/guard/repeat-tool-guard/tests/repeat-tool-guard.spec.ts # packages/hooks/hooks-claude/tests/bridge.spec.ts # packages/hooks/hooks-claude/tests/coverage.spec.ts # packages/hooks/hooks-codex/tests/bridge.spec.ts # packages/hooks/hooks-codex/tests/coverage.spec.ts # packages/subagent/subagent-fork/tests/multi-subagent.spec.ts # packages/subagent/subagent-fork/tests/subagent-fork.spec.ts # packages/subagent/subagent-inprocess/tests/structured.spec.ts # packages/subagent/subagent-inprocess/tests/subagent-inprocess.spec.ts # packages/subagent/subagent-spawn/tests/spawn.e2e.ts # packages/subagent/subagent-spawn/tests/subagent-spawn.spec.ts # packages/todo/tool-todo/tests/integration.spec.ts # packages/ui/acp/tests/dispose.spec.ts # packages/ui/acp/tests/edges.spec.ts # packages/workflow/workflow-workerthread/tests/integration.spec.ts
83 lines
3.7 KiB
TypeScript
83 lines
3.7 KiB
TypeScript
import { mkdtemp, readFile, rm } from 'node:fs/promises'
|
|
import { tmpdir } from 'node:os'
|
|
import { join } from 'node:path'
|
|
import { afterEach, describe, expect, it } from 'vitest'
|
|
import type { Context } from 'cordis'
|
|
import { SessionId } from '@deepseek-ai/dsh-session'
|
|
import { fsHarness, waitForIdle } from './harness.ts'
|
|
|
|
/**
|
|
* With-key smoke for the filesystem tools: a REAL model drives the REAL
|
|
* read/write/edit tools (over the real local backend + policy gate), and we
|
|
* verify the WORLD — the file on disk — not the agent's self-report. This is the
|
|
* "green units, broken product" guard: mocks prove the plumbing, only a real
|
|
* model proves the tools actually work end-to-end. Key-gated (self-skips without
|
|
* DEEPSEEK_API_KEY).
|
|
*/
|
|
|
|
let ctx: Context | undefined
|
|
let workdir: string | undefined
|
|
|
|
afterEach(async () => {
|
|
await ctx?.fiber.dispose()
|
|
ctx = undefined
|
|
if (workdir !== undefined) await rm(workdir, { recursive: true, force: true })
|
|
workdir = undefined
|
|
})
|
|
|
|
const SYSTEM = 'You are a coding assistant. Use the write tool to create files, the read tool to inspect '
|
|
+ 'them, and the edit tool for literal replacements. Read a file before editing it. Keep replies terse.'
|
|
|
|
describe.skipIf(!process.env.DEEPSEEK_API_KEY)('fs tools with-key smoke', () => {
|
|
it('creates, reads, then edits a file — verified on disk', async () => {
|
|
workdir = await mkdtemp(join(tmpdir(), 'dsh-fs-e2e-'))
|
|
ctx = await fsHarness(workdir, SYSTEM)
|
|
// agentLoop.create prepares a session with no cwd, so the provider default
|
|
// (config.cwd = workdir) is the workspace.
|
|
const agent = ctx.agentLoop.create(SessionId('fs-e2e'), { provider: 'deepseek', model: 'deepseek-v4-flash' })
|
|
|
|
agent.send([{ type: 'text', text:
|
|
'Create a file named note.txt containing exactly the line: status: draft. '
|
|
+ 'Then read it back, then edit it to replace the literal word draft with final. '
|
|
+ 'Tell me when done.' }])
|
|
await waitForIdle(ctx, agent)
|
|
|
|
// Verify the WORLD: the edit landed on disk.
|
|
const content = await readFile(join(workdir, 'note.txt'), 'utf8')
|
|
expect(content).toContain('status: final')
|
|
expect(content).not.toContain('draft')
|
|
|
|
// The log records real read/write/edit tool calls (not bash).
|
|
const calls = [...agent.session.events].filter(e => e.type === 'tool/call').map(e => e.data.name)
|
|
expect(calls).toContain('write')
|
|
expect(calls).toContain('read')
|
|
expect(calls).toContain('edit')
|
|
}, 180_000)
|
|
|
|
it('resolves a relative path against the per-session cwd (factory meta.cwd)', async () => {
|
|
// config.cwd is the harness workdir, but the agent's SESSION cwd is a
|
|
// different dir; the write must land in the SESSION dir, proving the tool
|
|
// passes the per-session cwd (not the backend default).
|
|
const configDir = await mkdtemp(join(tmpdir(), 'dsh-fs-e2e-cfg-'))
|
|
workdir = configDir
|
|
const sessionDir = await mkdtemp(join(tmpdir(), 'dsh-fs-e2e-session-'))
|
|
try {
|
|
ctx = await fsHarness(configDir, SYSTEM)
|
|
const handle = await ctx.agents.create({
|
|
sessionId: SessionId(`fs-e2e-cwd-${Date.now()}`),
|
|
meta: { cwd: sessionDir },
|
|
agentOptions: { provider: 'deepseek', model: 'deepseek-v4-flash' },
|
|
})
|
|
handle.agent.send([{ type: 'text', text:
|
|
'Use the write tool to create a file named where.txt containing exactly the line: here. Tell me when done.' }])
|
|
await waitForIdle(ctx, handle.agent)
|
|
|
|
// The file is in the SESSION dir, not the config dir.
|
|
expect(await readFile(join(sessionDir, 'where.txt'), 'utf8')).toContain('here')
|
|
await expect(readFile(join(configDir, 'where.txt'), 'utf8')).rejects.toMatchObject({ code: 'ENOENT' })
|
|
} finally {
|
|
await rm(sessionDir, { recursive: true, force: true })
|
|
}
|
|
}, 180_000)
|
|
})
|