mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-26 02:05:31 +00:00
fix(server): preserve block when opening a pre-upgrade retained checkout
Opening a pre-upgrade retained checkout directory whose last unapproved workspace was already archived before this change has no active workspace on the path and no `untrustedSource` in `paseo/worktree.json`. In `resolveCheckoutUntrustedSource`, prefer `paseo/worktree.json`, then active workspaces on the checkout when any exist (so a fresh approved worktree at a reused path stays approved), and only when zero active workspaces exist on the directory fall back to the most recently archived record for that path.
This commit is contained in:
+31
@@ -1390,3 +1390,34 @@ test("unarchiving an old unapproved workspace onto a live approved checkout drop
|
||||
expect(unarchived.untrustedSource).toBeUndefined();
|
||||
expect((await workspaceRegistry.get(oldUntrusted.workspaceId))?.untrustedSource).toBeUndefined();
|
||||
});
|
||||
|
||||
test("creating a directory workspace on a pre-upgrade retained unapproved checkout inherits untrustedSource when no active workspace owns the path", async () => {
|
||||
const sourceCwd = path.join(tmpDir, "repo-pre-upgrade-retained-dir");
|
||||
const worktreePath = path.join(tmpDir, "worktree-pre-upgrade-retained-dir");
|
||||
mkdirSync(sourceCwd, { recursive: true });
|
||||
mkdirSync(worktreePath, { recursive: true });
|
||||
gitRoots.add(sourceCwd);
|
||||
gitRoots.add(worktreePath);
|
||||
|
||||
const untrustedSource = {
|
||||
kind: "change_request" as const,
|
||||
forge: "github",
|
||||
number: 60,
|
||||
headRepository: "contributor/repo",
|
||||
};
|
||||
const retainedUntrusted = await provisioning.createWorkspaceForWorktree({
|
||||
sourceCwd,
|
||||
repoRoot: sourceCwd,
|
||||
cwd: worktreePath,
|
||||
worktreeRoot: worktreePath,
|
||||
branch: "contributor/pr-60",
|
||||
baseBranch: "main",
|
||||
title: null,
|
||||
untrustedSource,
|
||||
});
|
||||
await workspaceRegistry.archive(retainedUntrusted.workspaceId, ARCHIVED_AT);
|
||||
|
||||
const reopened = await provisioning.createWorkspaceForDirectory(worktreePath);
|
||||
|
||||
expect(reopened.untrustedSource).toEqual(untrustedSource);
|
||||
});
|
||||
|
||||
+14
-6
@@ -438,12 +438,20 @@ export function createWorkspaceProvisioningService(deps: {
|
||||
return metadataUntrustedSource;
|
||||
}
|
||||
const matchesCheckout = createRealpathAwarePathMatcher(checkoutRoot);
|
||||
const active = await workspaceRegistry.listActive();
|
||||
return active.find(
|
||||
(candidate) =>
|
||||
Boolean(candidate.untrustedSource) &&
|
||||
matchesCheckout(candidate.worktreeRoot ?? candidate.cwd),
|
||||
)?.untrustedSource;
|
||||
const matching = (await workspaceRegistry.listAll()).filter((candidate) =>
|
||||
matchesCheckout(candidate.worktreeRoot ?? candidate.cwd),
|
||||
);
|
||||
const active = matching.filter((candidate) => !candidate.archivedAt);
|
||||
if (active.length > 0) {
|
||||
return active.find((candidate) => Boolean(candidate.untrustedSource))?.untrustedSource;
|
||||
}
|
||||
// No active workspace owns this existing directory yet (for example, a
|
||||
// checkout retained on disk from before metadata persisted untrustedSource):
|
||||
// fall back to the most recently archived record for this path.
|
||||
const latestArchived = matching
|
||||
.filter((candidate) => Boolean(candidate.archivedAt))
|
||||
.sort((a, b) => (b.archivedAt ?? "").localeCompare(a.archivedAt ?? ""))[0];
|
||||
return latestArchived?.untrustedSource;
|
||||
}
|
||||
|
||||
async function syncUnarchivedCheckoutUntrustedSource(
|
||||
|
||||
Reference in New Issue
Block a user