mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-28 20:21:50 +01:00
Guard reused execution workspaces against stale bases
This commit is contained in:
1 parent
cdb8b90c8b
commit
773ced1bdb
5 files changed
+292
-5
No files matched your search
@@ -170,6 +170,8 @@ describe("mergeExecutionWorkspaceMetadataForPersistence", () => {
|
||||
provisionCommand: "bash ./scripts/provision.sh",
|
||||
},
|
||||
shouldReuseExisting: false,
|
||||
baseRef: null,
|
||||
baseRefSha: null,
|
||||
})).toEqual({
|
||||
source: "task_session",
|
||||
createdByRuntime: true,
|
||||
@@ -200,6 +202,8 @@ describe("mergeExecutionWorkspaceMetadataForPersistence", () => {
|
||||
provisionCommand: "bash ./scripts/new-provision.sh",
|
||||
},
|
||||
shouldReuseExisting: true,
|
||||
baseRef: null,
|
||||
baseRefSha: null,
|
||||
})).toEqual({
|
||||
config: {
|
||||
environmentId: "env-old",
|
||||
@@ -209,6 +213,25 @@ describe("mergeExecutionWorkspaceMetadataForPersistence", () => {
|
||||
createdByRuntime: false,
|
||||
});
|
||||
});
|
||||
|
||||
it("records the resolved base ref SHA for newly realized workspaces", () => {
|
||||
expect(mergeExecutionWorkspaceMetadataForPersistence({
|
||||
existingMetadata: null,
|
||||
source: "task_session",
|
||||
createdByRuntime: true,
|
||||
configSnapshot: null,
|
||||
shouldReuseExisting: false,
|
||||
baseRef: "origin/main",
|
||||
baseRefSha: "abc1234567890",
|
||||
})).toEqual({
|
||||
source: "task_session",
|
||||
createdByRuntime: true,
|
||||
baseRefSnapshot: {
|
||||
baseRef: "origin/main",
|
||||
resolvedSha: "abc1234567890",
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("buildRealizedExecutionWorkspaceFromPersisted", () => {
|
||||
|
||||
@@ -372,6 +372,75 @@ describe("realizeExecutionWorkspace", () => {
|
||||
expect(second.branchName).toBe(first.branchName);
|
||||
});
|
||||
|
||||
it("warns when reusing a git worktree whose base ref has advanced", async () => {
|
||||
const repoRoot = await createTempRepo();
|
||||
|
||||
const initial = await realizeExecutionWorkspace({
|
||||
base: {
|
||||
baseCwd: repoRoot,
|
||||
source: "project_primary",
|
||||
projectId: "project-1",
|
||||
workspaceId: "workspace-1",
|
||||
repoUrl: null,
|
||||
repoRef: "main",
|
||||
},
|
||||
config: {
|
||||
workspaceStrategy: {
|
||||
type: "git_worktree",
|
||||
branchTemplate: "{{issue.identifier}}-{{slug}}",
|
||||
},
|
||||
},
|
||||
issue: {
|
||||
id: "issue-1",
|
||||
identifier: "PAP-447",
|
||||
title: "Add Worktree Support",
|
||||
},
|
||||
agent: {
|
||||
id: "agent-1",
|
||||
name: "Codex Coder",
|
||||
companyId: "company-1",
|
||||
},
|
||||
});
|
||||
expect(initial.baseRefSha).toMatch(/^[0-9a-f]{40}$/);
|
||||
|
||||
await fs.writeFile(path.join(repoRoot, "server-auth-fix.txt"), "cookie fix\n", "utf8");
|
||||
await runGit(repoRoot, ["add", "server-auth-fix.txt"]);
|
||||
await runGit(repoRoot, ["commit", "-m", "Add auth runtime fix"]);
|
||||
|
||||
const reused = await realizeExecutionWorkspace({
|
||||
base: {
|
||||
baseCwd: repoRoot,
|
||||
source: "project_primary",
|
||||
projectId: "project-1",
|
||||
workspaceId: "workspace-1",
|
||||
repoUrl: null,
|
||||
repoRef: "main",
|
||||
},
|
||||
config: {
|
||||
workspaceStrategy: {
|
||||
type: "git_worktree",
|
||||
branchTemplate: "{{issue.identifier}}-{{slug}}",
|
||||
},
|
||||
},
|
||||
issue: {
|
||||
id: "issue-1",
|
||||
identifier: "PAP-447",
|
||||
title: "Add Worktree Support",
|
||||
},
|
||||
agent: {
|
||||
id: "agent-1",
|
||||
name: "Codex Coder",
|
||||
companyId: "company-1",
|
||||
},
|
||||
});
|
||||
|
||||
expect(reused.created).toBe(false);
|
||||
expect(reused.cwd).toBe(initial.cwd);
|
||||
expect(reused.warnings).toEqual([
|
||||
expect.stringContaining("is behind main by 1 commit"),
|
||||
]);
|
||||
});
|
||||
|
||||
it("rejects reusing an empty directory that only looks like a worktree because it sits inside the repo", async () => {
|
||||
const repoRoot = await createTempRepo();
|
||||
const branchName = "PAP-447-add-worktree-support";
|
||||
|
||||
Reference in new issue
Block a user