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
@@ -62,6 +62,7 @@ export async function handleSimulationCommand(
|
||||
stringOption(args.options.signKey) ??
|
||||
stringOption(args.options["sign-key"]) ??
|
||||
stringOption(args.options.integration);
|
||||
const noWait = booleanOption(args.options.noWait) ?? booleanOption(args.options["no-wait"]);
|
||||
|
||||
await runTool(
|
||||
"seal_simulation_batch_create",
|
||||
@@ -91,6 +92,7 @@ export async function handleSimulationCommand(
|
||||
endTime: numberOption(args.options.endTime) ?? numberOption(args.options["end-time"]),
|
||||
status: splitOption(args.options.status),
|
||||
limit: numberOption(args.options.limit),
|
||||
noWait,
|
||||
rawParams: inputPayload
|
||||
},
|
||||
outputOptions(args.options)
|
||||
@@ -115,6 +117,19 @@ export async function handleSimulationCommand(
|
||||
return;
|
||||
}
|
||||
|
||||
if (action === "status") {
|
||||
const batchId = maybeName ?? stringOption(args.options.batchId) ?? stringOption(args.options["batch-id"]);
|
||||
if (!batchId) throw new Error("Usage: seal-use simulation status <batchId>");
|
||||
await runTool(
|
||||
"seal_simulation_batch_status",
|
||||
client,
|
||||
corp,
|
||||
{ batchId },
|
||||
outputOptions(args.options)
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (action === "clean" || action === "delete") {
|
||||
const batchId = maybeName ?? stringOption(args.options.batchId) ?? stringOption(args.options["batch-id"]);
|
||||
if (!batchId) throw new Error("Usage: seal-use simulation clean <batchId>");
|
||||
|
||||
+2
-1
@@ -167,9 +167,10 @@ Usage:
|
||||
seal-use approval-runs url --sourceDocumentSN B26022501 [--corp <corpId>]
|
||||
seal-use approval-runs bridge [--sourceDocumentSN B26001887] [--corp <corpId>]
|
||||
seal-use simulation batch-records <batchId> [--corp <corpId>]
|
||||
seal-use simulation create --mode hosecloud --flow-ids "B26017701,B26022501" [--reject-node 财务] [--thinking-depth default|medium|high] [--skip-invoice-generation|--skip-invoice-generation false] [--corp <corpId>]
|
||||
seal-use simulation create --mode hosecloud --flow-ids "B26017701,B26022501" [--reject-node 财务] [--thinking-depth default|medium|high] [--skip-invoice-generation|--skip-invoice-generation false] [--no-wait] [--corp <corpId>]
|
||||
seal-use simulation create --mode material_pack --package-ids <materialPackageId> [--template-id conference_reimbursement_v1] [--schema-config file.json] [--corp <corpId>]
|
||||
seal-use simulation create --source-system weaver --request-ids "req-01,req-02" [--corp <corpId>]
|
||||
seal-use simulation status <batchId> [--corp <corpId>]
|
||||
seal-use simulation wait <batchId> [--timeout 10m] [--poll-interval 2s] [--corp <corpId>]
|
||||
seal-use simulation clean <batchId> [--corp <corpId>]
|
||||
seal-use simulation specifications [--integration <sign-key>] [--corp <corpId>]
|
||||
|
||||
@@ -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