Skip to content
Open
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
1 change: 1 addition & 0 deletions apps/server/src/auth/RpcAuthorization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ export const RPC_REQUIRED_SCOPES = {
[WS_METHODS.vcsRefreshStatus]: AuthOrchestrationReadScope,
[WS_METHODS.gitResolvePullRequest]: AuthOrchestrationReadScope,
[WS_METHODS.vcsListRefs]: AuthOrchestrationReadScope,
[WS_METHODS.vcsListRepositories]: AuthOrchestrationReadScope,
[WS_METHODS.reviewGetDiffPreview]: AuthFilesystemReadScope,
[WS_METHODS.reviewGetDiffFileContents]: AuthFilesystemReadScope,
[WS_METHODS.terminalOpen]: AuthTerminalOperateScope,
Expand Down
134 changes: 130 additions & 4 deletions apps/server/src/checkpointing/CheckpointStore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ function buildLargeText(lineCount = 5_000): string {
}

it.layer(layerTest)("CheckpointStore.layer", (it) => {
describe("isGitRepository", () => {
describe("isCheckpointable", () => {
it.effect("returns false when no Git repository is detected", () =>
Effect.gen(function* () {
const tmp = yield* makeTmpDir();
const checkpointStore = yield* CheckpointStore.CheckpointStore;

expect(yield* checkpointStore.isGitRepository(tmp)).toBe(false);
expect(yield* checkpointStore.isCheckpointable(tmp)).toBe(false);
}),
);

Expand All @@ -111,7 +111,7 @@ it.layer(layerTest)("CheckpointStore.layer", (it) => {
yield* initRepoWithCommit(tmp);
const checkpointStore = yield* CheckpointStore.CheckpointStore;

expect(yield* checkpointStore.isGitRepository(tmp)).toBe(true);
expect(yield* checkpointStore.isCheckpointable(tmp)).toBe(true);
}),
);
});
Expand All @@ -124,9 +124,135 @@ it.layer(layerTest)("CheckpointStore.layer", (it) => {
const nested = NodePath.join(tmp, "packages", "nested");
yield* fileSystem.makeDirectory(nested, { recursive: true });
const checkpointStore = yield* CheckpointStore.CheckpointStore;
expect(yield* checkpointStore.isGitRepository(nested)).toBe(true);
expect(yield* checkpointStore.isCheckpointable(nested)).toBe(true);
}),
);
describe("multi-repo workspaces", () => {
const makeWorkspace = Effect.gen(function* () {
const fileSystem = yield* FileSystem.FileSystem;
const workspace = yield* makeTmpDir("checkpoint-store-workspace-");
for (const name of ["api", "web"]) {
const repo = NodePath.join(workspace, name);
yield* fileSystem.makeDirectory(repo);
yield* initRepoWithCommit(repo);
}
yield* writeTextFile(NodePath.join(workspace, "NOTES.md"), "not in any repository\n");
return workspace;
});

it.effect("captures, diffs and restores every repository as one workspace", () =>
Effect.gen(function* () {
const workspace = yield* makeWorkspace;
const fileSystem = yield* FileSystem.FileSystem;
const checkpointStore = yield* CheckpointStore.CheckpointStore;
const threadId = ThreadId.make("thread-multi-repo");
const fromCheckpointRef = checkpointRefForThreadTurn(threadId, 0);
const toCheckpointRef = checkpointRefForThreadTurn(threadId, 1);

expect(yield* checkpointStore.isCheckpointable(workspace)).toBe(true);
yield* checkpointStore.captureCheckpoint({
cwd: workspace,
checkpointRef: fromCheckpointRef,
});
yield* writeTextFile(NodePath.join(workspace, "api", "README.md"), "# api\n");
yield* writeTextFile(NodePath.join(workspace, "web", "app.ts"), "export {};\n");
yield* checkpointStore.captureCheckpoint({
cwd: workspace,
checkpointRef: toCheckpointRef,
});

const numstat = yield* checkpointStore.diffCheckpoints({
cwd: workspace,
fromCheckpointRef,
toCheckpointRef,
ignoreWhitespace: false,
format: "numstat",
});
expect(parseTurnDiffFilesFromNumstat(numstat)).toEqual([
{ path: "api/README.md", additions: 1, deletions: 1 },
{ path: "web/app.ts", additions: 1, deletions: 0 },
]);
const patch = yield* checkpointStore.diffCheckpoints({
cwd: workspace,
fromCheckpointRef,
toCheckpointRef,
ignoreWhitespace: false,
});
expect(patch).toContain("diff --git a/api/README.md b/api/README.md");
expect(patch).toContain("+++ b/web/app.ts");

expect(
yield* checkpointStore.restoreCheckpoint({
cwd: workspace,
checkpointRef: fromCheckpointRef,
}),
).toBe(true);
expect(yield* fileSystem.readFileString(NodePath.join(workspace, "api", "README.md"))).toBe(
"# test\n",
);
expect(yield* fileSystem.exists(NodePath.join(workspace, "web", "app.ts"))).toBe(false);
expect(yield* fileSystem.exists(NodePath.join(workspace, "NOTES.md"))).toBe(true);
}),
);

it.effect("restores nothing when a repository is missing the checkpoint", () =>
Effect.gen(function* () {
const workspace = yield* makeWorkspace;
const fileSystem = yield* FileSystem.FileSystem;
const checkpointStore = yield* CheckpointStore.CheckpointStore;
const threadId = ThreadId.make("thread-multi-repo-late-repo");
const checkpointRef = checkpointRefForThreadTurn(threadId, 0);

yield* checkpointStore.captureCheckpoint({ cwd: workspace, checkpointRef });
const late = NodePath.join(workspace, "late");
yield* fileSystem.makeDirectory(late);
yield* initRepoWithCommit(late);
yield* writeTextFile(NodePath.join(workspace, "api", "README.md"), "# edited\n");

expect(yield* checkpointStore.hasCheckpointRef({ cwd: workspace, checkpointRef })).toBe(
false,
);
expect(yield* checkpointStore.restoreCheckpoint({ cwd: workspace, checkpointRef })).toBe(
false,
);
expect(yield* fileSystem.readFileString(NodePath.join(workspace, "api", "README.md"))).toBe(
"# edited\n",
);
}),
);
it.effect("fills in a new repository without overwriting existing checkpoints", () =>
Effect.gen(function* () {
const workspace = yield* makeWorkspace;
const fileSystem = yield* FileSystem.FileSystem;
const checkpointStore = yield* CheckpointStore.CheckpointStore;
const threadId = ThreadId.make("thread-multi-repo-fill-in");
const checkpointRef = checkpointRefForThreadTurn(threadId, 0);

yield* checkpointStore.captureCheckpoint({ cwd: workspace, checkpointRef });
const late = NodePath.join(workspace, "late");
yield* fileSystem.makeDirectory(late);
yield* initRepoWithCommit(late);
yield* writeTextFile(NodePath.join(workspace, "api", "README.md"), "# edited\n");

yield* checkpointStore.captureCheckpoint({
cwd: workspace,
checkpointRef,
missingOnly: true,
});

expect(yield* checkpointStore.hasCheckpointRef({ cwd: workspace, checkpointRef })).toBe(
true,
);
expect(yield* checkpointStore.restoreCheckpoint({ cwd: workspace, checkpointRef })).toBe(
true,
);
expect(yield* fileSystem.readFileString(NodePath.join(workspace, "api", "README.md"))).toBe(
"# test\n",
);
}),
);
});

describe("diffCheckpoints", () => {
it.effect("returns full oversized checkpoint diffs without truncation", () =>
Effect.gen(function* () {
Expand Down
Loading
Loading