feat(agent): 完善分析编排与结果传输
This commit is contained in:
@@ -117,58 +117,6 @@ describe("OpencodeRuntimeAdapter.subscribeEvents", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("OpencodeRuntimeAdapter.prompt", () => {
|
||||
it("forwards the final answer schema", async () => {
|
||||
const calls: unknown[] = [];
|
||||
const client = {
|
||||
session: {
|
||||
prompt: async (input: unknown) => {
|
||||
calls.push(input);
|
||||
return { data: {} };
|
||||
},
|
||||
},
|
||||
} as unknown as OpencodeClient;
|
||||
const runtime = Object.assign(Object.create(OpencodeRuntimeAdapter.prototype), {
|
||||
ensureClient: async () => client,
|
||||
}) as OpencodeRuntimeAdapter;
|
||||
|
||||
await runtime.prompt(
|
||||
"session-1",
|
||||
"分析供水分区",
|
||||
{ providerID: "deepseek", modelID: "deepseek-v4-flash" },
|
||||
{
|
||||
format: {
|
||||
type: "json_schema",
|
||||
schema: {
|
||||
type: "object",
|
||||
properties: { answer: { type: "string" } },
|
||||
required: ["answer"],
|
||||
},
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
expect(calls).toEqual([
|
||||
{
|
||||
sessionID: "session-1",
|
||||
model: {
|
||||
providerID: "deepseek",
|
||||
modelID: "deepseek-v4-flash",
|
||||
},
|
||||
format: {
|
||||
type: "json_schema",
|
||||
schema: {
|
||||
type: "object",
|
||||
properties: { answer: { type: "string" } },
|
||||
required: ["answer"],
|
||||
},
|
||||
},
|
||||
parts: [{ type: "text", text: "分析供水分区" }],
|
||||
},
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("OpencodeRuntimeAdapter interaction replies", () => {
|
||||
it("replies to permissions in the conversation workspace directory", async () => {
|
||||
const calls: unknown[] = [];
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from "bun:test";
|
||||
import { readFile } from "node:fs/promises";
|
||||
import { readFile, readdir } from "node:fs/promises";
|
||||
import sandboxBash from "../../.opencode/tools/bash.js";
|
||||
import tjwaterCli from "../../.opencode/tools/tjwater_cli.js";
|
||||
import storeRenderRef, {
|
||||
@@ -37,6 +37,8 @@ describe("internal OpenCode permissions", () => {
|
||||
expect(permission.external_directory).toBe("deny");
|
||||
expect(permission.task).toBe("deny");
|
||||
expect(permission.question).toBe("allow");
|
||||
expect(permission.activity_update).toBe("allow");
|
||||
expect(permission.final_answer).toBe("allow");
|
||||
expect(permission.todowrite).toBe("allow");
|
||||
expect(read?.["*"]).toBe("allow");
|
||||
expect(read?.["data/**"]).toBe("deny");
|
||||
@@ -56,6 +58,22 @@ describe("internal OpenCode permissions", () => {
|
||||
expect(bash?.["*data/*"]).toBeUndefined();
|
||||
expect(bash?.["*logs/*"]).toBeUndefined();
|
||||
});
|
||||
|
||||
it("keeps reason only on the activity grouping tool", async () => {
|
||||
const toolFiles = (await readdir(".opencode/tools"))
|
||||
.filter((file) => file.endsWith(".ts"));
|
||||
const sources = await Promise.all(
|
||||
toolFiles.map(async (file) => ({
|
||||
file,
|
||||
source: await readFile(`.opencode/tools/${file}`, "utf8"),
|
||||
})),
|
||||
);
|
||||
const reasonSchemaFiles = sources
|
||||
.filter(({ source }) => /reason:\s*tool\.schema/u.test(source))
|
||||
.map(({ file }) => file);
|
||||
|
||||
expect(reasonSchemaFiles).toEqual(["activity_update.ts"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("store_render_ref arguments", () => {
|
||||
@@ -154,6 +172,20 @@ describe("sandbox bash tool", () => {
|
||||
});
|
||||
|
||||
describe("tjwater_cli storage request", () => {
|
||||
it("keeps command discovery rules in the always-visible tool contract", () => {
|
||||
const definition = tjwaterCli as unknown as {
|
||||
description: string;
|
||||
args: { command: { description?: string } };
|
||||
};
|
||||
|
||||
expect(definition.description).toContain("help");
|
||||
expect(definition.args.command.description).toContain("禁止类推");
|
||||
expect(definition.args.command.description).toContain("simulation runs list");
|
||||
expect(definition.args.command.description).not.toContain(
|
||||
"示例:'analysis runs list'",
|
||||
);
|
||||
});
|
||||
|
||||
it("forwards store_result so small workflow inputs can be staged", async () => {
|
||||
const originalFetch = globalThis.fetch;
|
||||
let requestBody: unknown;
|
||||
@@ -168,7 +200,6 @@ describe("tjwater_cli storage request", () => {
|
||||
await definition.execute(
|
||||
{
|
||||
command: "network get-all-reservoirs-properties",
|
||||
reason: "prepare workflow input",
|
||||
store_result: true,
|
||||
},
|
||||
{ sessionID: "session-test" } as never,
|
||||
|
||||
Reference in New Issue
Block a user