Add non-blocking simulation status checks
This commit is contained in:
1 parent
0b10a70924
commit
995b9fa81e
6 files changed
+87
-6
No files matched your search
@@ -501,7 +501,12 @@ describe("simulation tool handlers", () => {
|
||||
sourceSystem: "hosecloud"
|
||||
});
|
||||
expect(postedBody).not.toHaveProperty("limit");
|
||||
expect(result).toMatchObject({ batchId: "batch-1", created: true });
|
||||
expect(result).toMatchObject({
|
||||
batchId: "batch-1",
|
||||
created: true,
|
||||
noWait: true,
|
||||
asyncTicket: "batch-1"
|
||||
});
|
||||
});
|
||||
|
||||
test("create tool surface exposes mode, flowIds, and rawParams", () => {
|
||||
@@ -509,18 +514,44 @@ describe("simulation tool handlers", () => {
|
||||
const { z } = require("zod") as typeof import("zod");
|
||||
const schema = z.toJSONSchema(tool!.parameters) as { properties?: Record<string, unknown> };
|
||||
expect(Object.keys(schema.properties ?? {})).toEqual(
|
||||
expect.arrayContaining(["mode", "flowIds", "rawParams", "schemaConfig", "packageIds"])
|
||||
expect.arrayContaining(["mode", "flowIds", "rawParams", "schemaConfig", "packageIds", "noWait"])
|
||||
);
|
||||
});
|
||||
|
||||
test("includes the simulation management tool set", () => {
|
||||
expect(sealTools.find((item) => item.name === "seal_simulation_batches_list")).toBeDefined();
|
||||
expect(sealTools.find((item) => item.name === "seal_simulation_batch_get")).toBeDefined();
|
||||
expect(sealTools.find((item) => item.name === "seal_simulation_batch_status")).toBeDefined();
|
||||
expect(sealTools.find((item) => item.name === "seal_simulation_templates_get")).toBeDefined();
|
||||
expect(sealTools.find((item) => item.name === "seal_simulation_integrations_get")).toBeDefined();
|
||||
expect(sealTools.find((item) => item.name === "seal_simulation_batch_records_get")).toBeDefined();
|
||||
expect(sealTools.find((item) => item.name === "seal_simulation_material_package_upload")).toBeDefined();
|
||||
});
|
||||
|
||||
test("status tool performs one non-blocking check and exposes the next action", async () => {
|
||||
const tool = sealTools.find((item) => item.name === "seal_simulation_batch_status");
|
||||
expect(tool).toBeDefined();
|
||||
|
||||
const client = {
|
||||
get: (url: string) => {
|
||||
expect(url).toBe("api/v1/simulation/batch/batch-1");
|
||||
return { json: async () => ({ data: { ...hosecloudBatchFixture, id: "batch-1" } }) };
|
||||
}
|
||||
} as unknown as KyInstance;
|
||||
|
||||
const handler = tool!.handler as ToolHandler;
|
||||
const result = await handler(client, { batchId: "batch-1" }, fakeContext()) as Record<string, unknown>;
|
||||
|
||||
expect(result).toMatchObject({
|
||||
batchId: "batch-1",
|
||||
status: "SYNCING",
|
||||
terminal: false,
|
||||
next: {
|
||||
status: "seal-use simulation status batch-1",
|
||||
wait: "seal-use simulation wait batch-1"
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("simulation response schemas", () => {
|
||||
|
||||
@@ -1423,6 +1423,7 @@ export const sealTools = [
|
||||
packageIds: z.array(z.string()).optional().describe("材料包模式: 材料包 id 列表(来自 material-packages upload 响应)"),
|
||||
templateId: z.string().optional().describe("材料包模板 id, 例如 conference_reimbursement_v1; 缺省取 schemaConfig.id"),
|
||||
schemaConfig: z.record(z.string(), z.unknown()).optional().describe("材料包字段映射(确认参数), 建议使用 material-packages upload 返回的 schemaConfig"),
|
||||
noWait: z.boolean().optional().describe("创建后立即返回异步票据,不等待批次完成"),
|
||||
rawParams: z.record(z.string(), z.unknown()).optional().describe("预留: 其他取数模式(如时间范围 startTime/endTime)透传参数, 覆盖上述构建结果")
|
||||
}),
|
||||
handler: async (
|
||||
@@ -1439,6 +1440,7 @@ export const sealTools = [
|
||||
packageIds?: string[];
|
||||
templateId?: string;
|
||||
schemaConfig?: Record<string, unknown>;
|
||||
noWait?: boolean;
|
||||
rawParams?: Record<string, unknown>;
|
||||
}
|
||||
) => {
|
||||
@@ -1474,7 +1476,11 @@ export const sealTools = [
|
||||
return {
|
||||
...result,
|
||||
created: true,
|
||||
noWait: params.noWait ?? true,
|
||||
asyncTicket: result.batchId,
|
||||
next: {
|
||||
status: `seal-use simulation status ${result.batchId}`,
|
||||
wait: `seal-use simulation wait ${result.batchId}`,
|
||||
getBatch: "seal-home simulation get <batchId>",
|
||||
getRecords: "seal-home simulation batch-records <batchId>",
|
||||
listBatches: "seal-home simulation list"
|
||||
@@ -1516,6 +1522,32 @@ export const sealTools = [
|
||||
};
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "seal_simulation_batch_status",
|
||||
description: "单次读取 Seal 模拟批次状态,不阻塞等待;适合根据异步票据轮询",
|
||||
parameters: z.object({
|
||||
batchId: z.string().describe("simulation batch ID")
|
||||
}),
|
||||
handler: async (client: KyInstance, params: { batchId: string }) => {
|
||||
const batch = await api.getSimulationBatch(client, params.batchId);
|
||||
const status = String(batch.status ?? "UNKNOWN").toUpperCase();
|
||||
const terminal = ["COMPLETED", "FAILED", "CANCELLED", "CANCELED"].includes(status);
|
||||
return {
|
||||
batchId: params.batchId,
|
||||
status,
|
||||
terminal,
|
||||
totalCount: batch.totalCount,
|
||||
processedCount: batch.processedCount,
|
||||
successCount: batch.successCount,
|
||||
failedCount: batch.failedCount,
|
||||
createdAt: batch.createdAt,
|
||||
updatedAt: batch.updatedAt,
|
||||
next: terminal
|
||||
? { getRecords: `seal-use simulation batch-records ${params.batchId}` }
|
||||
: { status: `seal-use simulation status ${params.batchId}`, wait: `seal-use simulation wait ${params.batchId}` }
|
||||
};
|
||||
}
|
||||
},
|
||||
{
|
||||
name: "seal_simulation_templates_get",
|
||||
description: "列出 Seal 模拟测试模板(我的模板,保存常用配置快速复用)",
|
||||
|
||||
Reference in new issue
Block a user