Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,41 @@ describe("signed-commit tool handler", () => {
});
});

it("persists the branch when cwd uses an equivalent path representation", async () => {
await signedCommitTool.handler(
{
cwd: "/tmp/workspace/repos/posthog/code/.",
token: "ghs_x",
taskId: "task-1",
taskRunId: "run-1",
},
{ message: "chore: bump", cwd: "." },
);

expect(reportTaskRunBranch).toHaveBeenCalledWith({
taskId: "task-1",
taskRunId: "run-1",
branch: "posthog-code/feature",
});
});

it("does not persist a branch created in a sibling repository", async () => {
await signedCommitTool.handler(
{
cwd: "/tmp/workspace/repos/posthog/code",
token: "ghs_x",
taskId: "task-1",
taskRunId: "run-1",
},
{
message: "chore: bump",
cwd: "/tmp/workspace/repos/posthog/grafana-dashboards",
},
);

expect(reportTaskRunBranch).not.toHaveBeenCalled();
});

it("returns the no-token error without invoking createSignedCommit", async () => {
const savedGh = process.env.GH_TOKEN;
const savedGithub = process.env.GITHUB_TOKEN;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,14 @@ export function defineSignedGitTool<S extends z.ZodRawShape, R>(opts: {
string,
unknown
>;
const cwd = argCwd ? path.resolve(ctx.cwd, argCwd) : ctx.cwd;
const taskRepositoryCwd = path.resolve(ctx.cwd);
const cwd = argCwd
? path.resolve(taskRepositoryCwd, argCwd)
: taskRepositoryCwd;
return opts.run(
{
cwd,
taskRepositoryCwd,
token,
taskId: ctx.taskId,
taskRunId: ctx.taskRunId,
Expand Down
22 changes: 16 additions & 6 deletions packages/agent/src/adapters/signed-commit-shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,11 @@ export interface SignedCommitToolResult {
[key: string]: unknown;
}

export type SignedCommitToolCtx = SignedCommitCtx & { taskRunId?: string };
export type SignedCommitToolCtx = SignedCommitCtx & {
taskRunId?: string;
/** The task repository cwd, before a tool-call `cwd` override is applied. */
taskRepositoryCwd: string;
};

async function runSignedTool<A>(
toolName: string,
Expand Down Expand Up @@ -176,11 +180,17 @@ export function runSignedCommitTool(
SIGNED_COMMIT_TOOL_NAME,
async (c, a: SignedCommitInput) => {
const result = await createSignedCommit(c, a);
await reportTaskRunBranch({
taskId: ctx.taskId,
taskRunId: ctx.taskRunId,
branch: result.branch,
});
// TaskRun.branch is the branch that provisioning checks out in the task's
// repository on resume. A task can also commit to sibling repositories by
// passing `cwd`; persisting one of those branches here makes the next run
// try to clone the task repository at a branch that only exists elsewhere.
if (ctx.cwd === ctx.taskRepositoryCwd) {
await reportTaskRunBranch({
taskId: ctx.taskId,
taskRunId: ctx.taskRunId,
branch: result.branch,
});
}
// The "commit hook": every pushed commit becomes a `commit` artefact on the signal
// reports this task is associated with. Best-effort and awaited inside the tool's
// try/catch-free success path — reportCommitArtefacts never throws, so a failed
Expand Down
Loading