瀏覽代碼

test(fs-search): make loader guard rg-independent

Dudu-0223 2 月之前
父節點
當前提交
faae2d389b
共有 1 個文件被更改,包括 62 次插入 和 2 次删除
  1. 62 2
      packages/fs/tool-fs-search/tests/load-path.spec.ts

+ 62 - 2
packages/fs/tool-fs-search/tests/load-path.spec.ts

@@ -18,9 +18,69 @@ import { Context } from 'cordis'
 import Loader from '@cordisjs/plugin-loader'
 import SystemPrompt from '@deepseek-ai/dsh-system-prompt'
 import ToolRegistry from '@deepseek-ai/dsh-tools'
-import { LocalBashExecutor } from '@deepseek-ai/dsh-bash-local'
+import { BashExecutor } from '@deepseek-ai/dsh-bash'
+import type { BashExecRequest, BashExecSpec, BashRunResult, BashTask, BashTaskId, BashTaskRead, OwnerToken } from '@deepseek-ai/dsh-bash'
 import * as toolFsSearch from '@deepseek-ai/dsh-tool-fs-search'
 
+const RG_PROBE_COMMAND = 'command -v rg >/dev/null 2>&1'
+
+/**
+ * Deterministic bash service for this Loader guard: the test wants to exercise
+ * the real unwrap/inject path, not depend on whether the host image has rg.
+ */
+class ProbeSuccessBashExecutor extends BashExecutor {
+  override resolve(request: BashExecRequest): BashExecSpec {
+    return {
+      command: request.command,
+      workdir: request.workdir ?? '/work',
+      timeoutMs: request.timeoutMs ?? 60_000,
+      stdoutMaxBytes: request.stdoutMaxBytes ?? 64_000,
+      signal: request.signal,
+      owner: request.owner,
+      sandboxMode: request.sandboxMode,
+    }
+  }
+
+  override run(spec: BashExecSpec): Promise<BashRunResult> {
+    if (spec.command !== RG_PROBE_COMMAND) {
+      throw new Error(`unexpected command in load-path guard: ${spec.command}`)
+    }
+    return Promise.resolve({
+      exitCode: 0,
+      signal: null,
+      timedOut: false,
+      aborted: false,
+      timeoutMs: spec.timeoutMs,
+      stdout: { text: '', truncated: false },
+      stderr: { text: '', truncated: false },
+    })
+  }
+
+  override start(): BashTask {
+    throw new Error('load-path guard must not start bash tasks')
+  }
+
+  override get(): BashTask | undefined {
+    return undefined
+  }
+
+  override ownerOf(): OwnerToken | undefined {
+    return undefined
+  }
+
+  override list(): BashTask[] {
+    return []
+  }
+
+  override readOutput(id: BashTaskId): BashTaskRead {
+    throw new Error(`unknown bash task ${id}`)
+  }
+
+  override kill(id: BashTaskId): boolean {
+    throw new Error(`unknown bash task ${id}`)
+  }
+}
+
 describe('dsh-tool-fs-search real-load-path guard', () => {
   it('has no default export and keeps name/inject/Config through unwrapExports', () => {
     expect('default' in toolFsSearch).toBe(false)
@@ -38,7 +98,7 @@ describe('dsh-tool-fs-search real-load-path guard', () => {
     const ctx = new Context()
     await ctx.plugin(SystemPrompt)
     await ctx.plugin(ToolRegistry)
-    await ctx.plugin(LocalBashExecutor, {})
+    await ctx.plugin(ProbeSuccessBashExecutor)
 
     const loader = Object.create(Loader.prototype) as Loader
     const unwrapped = loader.unwrapExports(toolFsSearch) as Parameters<Context['plugin']>[0]