






















@@ -42,6 +42,30 @@ function createUniqueResponseSchema(index: number) {
4242};
4343}
444445+function requireRecord(value: unknown, label: string): Record<string, unknown> {
46+if (value === null || typeof value !== "object" || Array.isArray(value)) {
47+throw new Error(`expected ${label} to be a record`);
48+}
49+return value as Record<string, unknown>;
50+}
51+52+function requireFirstCallParam(calls: ReadonlyArray<readonly unknown[]>, label: string) {
53+const call = calls[0];
54+if (!call) {
55+throw new Error(`expected ${label} call`);
56+}
57+return call[0];
58+}
59+60+function expectToolContext(value: unknown, expected: { cwd?: string; mode: "tool" }) {
61+const ctx = requireRecord(value, "tool context");
62+if (expected.cwd !== undefined) {
63+expect(ctx.cwd).toBe(expected.cwd);
64+}
65+expect(ctx.mode).toBe(expected.mode);
66+expect(ctx.signal).toBeInstanceOf(AbortSignal);
67+}
68+4569describe("resolveLobsterCwd", () => {
4670it("defaults to the current working directory", () => {
4771expect(resolveLobsterCwd(undefined)).toBe(process.cwd());
@@ -84,14 +108,12 @@ describe("createEmbeddedLobsterRunner", () => {
84108});
8510986110expect(runtime.runToolRequest).toHaveBeenCalledTimes(1);
87-expect(runtime.runToolRequest).toHaveBeenCalledWith({
88-pipeline: "exec --json=true echo hi",
89-ctx: expect.objectContaining({
90-cwd: process.cwd(),
91-mode: "tool",
92-signal: expect.any(AbortSignal),
93-}),
94-});
111+const request = requireRecord(
112+requireFirstCallParam(runtime.runToolRequest.mock.calls, "run tool request"),
113+"run tool request",
114+);
115+expect(request.pipeline).toBe("exec --json=true echo hi");
116+expectToolContext(request.ctx, { cwd: process.cwd(), mode: "tool" });
95117expect(envelope).toEqual({
96118ok: true,
97119status: "ok",
@@ -130,14 +152,14 @@ describe("createEmbeddedLobsterRunner", () => {
130152maxStdoutBytes: 4096,
131153});
132154133-expect(runtime.runToolRequest).toHaveBeenCalledWith({
134- filePath: workflowPath,
135-args: { limit: 3 },
136-ctx: expect.objectContaining({
137- cwd: tempDir,
138- mode: "tool",
139- }),
140-});
155+expect(runtime.runToolRequest).toHaveBeenCalledOnce();
156+const request = requireRecord(
157+requireFirstCallParam(runtime.runToolRequest.mock.calls, "workflow run tool request"),
158+"workflow run tool request",
159+);
160+expect(request.filePath).toBe(workflowPath);
161+expect(request.args).toEqual({ limit: 3 });
162+expectToolContext(request.ctx, { cwd: tempDir, mode: "tool" });
141163} finally {
142164await fs.rm(tempDir, { recursive: true, force: true });
143165}
@@ -257,15 +279,14 @@ describe("createEmbeddedLobsterRunner", () => {
257279maxStdoutBytes: 4096,
258280});
259281260-expect(runtime.resumeToolRequest).toHaveBeenCalledWith({
261-token: "resume-token",
262-approved: false,
263-ctx: expect.objectContaining({
264-cwd: process.cwd(),
265-mode: "tool",
266-signal: expect.any(AbortSignal),
267-}),
268-});
282+expect(runtime.resumeToolRequest).toHaveBeenCalledOnce();
283+const request = requireRecord(
284+requireFirstCallParam(runtime.resumeToolRequest.mock.calls, "resume tool request"),
285+"resume tool request",
286+);
287+expect(request.token).toBe("resume-token");
288+expect(request.approved).toBe(false);
289+expectToolContext(request.ctx, { cwd: process.cwd(), mode: "tool" });
269290expect(envelope).toEqual({
270291ok: true,
271292status: "cancelled",
@@ -299,11 +320,14 @@ describe("createEmbeddedLobsterRunner", () => {
299320maxStdoutBytes: 4096,
300321});
301322302-expect(runtime.resumeToolRequest).toHaveBeenCalledWith({
303-approvalId: "dbc98d05",
304-approved: true,
305-ctx: expect.objectContaining({ mode: "tool" }),
306-});
323+expect(runtime.resumeToolRequest).toHaveBeenCalledOnce();
324+const request = requireRecord(
325+requireFirstCallParam(runtime.resumeToolRequest.mock.calls, "approval resume tool request"),
326+"approval resume tool request",
327+);
328+expect(request.approvalId).toBe("dbc98d05");
329+expect(request.approved).toBe(true);
330+expectToolContext(request.ctx, { mode: "tool" });
307331});
308332309333it("passes approvalId through the normalized needs_approval envelope", async () => {
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。