From 02515739d94431d4c2979cd3f5829df11ee4da03 Mon Sep 17 00:00:00 2001 From: Jacob Prall Date: Sun, 25 Oct 2026 13:54:34 -0700 Subject: [PATCH] Preserve Workflows context in autopilot subtasks --- app/workflows/autopilot/index.ts | 5 ++--- tests/autopilot.test.ts | 6 ++++-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/workflows/autopilot/index.ts b/app/workflows/autopilot/index.ts index f26dd27..076c5a4 100644 --- a/app/workflows/autopilot/index.ts +++ b/app/workflows/autopilot/index.ts @@ -57,9 +57,8 @@ async function autopilot(claim: Claim, input: TriageInput, deps: AutopilotDeps, workflow: { task: TaskDefinition<[raw: unknown], TaskResult> }, ): ((input: Input) => Promise>) => { if (override) return override; - const run = ctx.run; - if (!run) throw new Error("autopilot requires a Workflows task context"); - return (stageInput) => run(workflow.task, stageInput); + if (!ctx.run) throw new Error("autopilot requires a Workflows task context"); + return (stageInput) => ctx.run?.(workflow.task, stageInput) as Promise>; }; const runTriage = child(deps.triage, triageWorkflow); diff --git a/tests/autopilot.test.ts b/tests/autopilot.test.ts index 9be28c2..4d6b1d2 100644 --- a/tests/autopilot.test.ts +++ b/tests/autopilot.test.ts @@ -106,7 +106,9 @@ describe("autopilot", () => { const names: string[] = []; const workflowCtx = { metadata: ctx.metadata, - run: vi.fn(async (definition: { name: string }, stageInput: unknown) => { + bound: true, + async run(this: { bound: boolean }, definition: { name: string }, stageInput: unknown) { + expect(this.bound).toBe(true); names.push(definition.name); if (definition.name === "triage") { return result("trn-triage", "drafted", { @@ -123,7 +125,7 @@ describe("autopilot", () => { } expect(stageInput).toMatchObject({ pr: 34, workflowIssue: 12 }); return result("trn-review", "reviewed"); - }), + }, } as unknown as Pick; const output = await runAutopilot(workflowCtx, input, { gh: asClient(gh) });