Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(desktop): speed up checkpoint test setup (#96245)

Paul D'Ambra0a5d6ccf207c
diff --git a/products/desktop/packages/git/src/sagas/checkpoint.test.ts b/products/desktop/packages/git/src/sagas/checkpoint.test.ts
index e05dfcf5cd2c..8f45e0ad97d8 100644
--- a/products/desktop/packages/git/src/sagas/checkpoint.test.ts
+++ b/products/desktop/packages/git/src/sagas/checkpoint.test.ts
@@ -1,7 +1,7 @@
-import { mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
+import { cp, mkdir, mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import path from "node:path";
-import { describe, expect, it } from "vitest";
+import { afterAll, beforeAll, describe, expect, it } from "vitest";
import { createGitClient } from "../client";
import {
CaptureCheckpointSaga,
@@ -12,7 +12,7 @@ import {
RevertCheckpointSaga,
} from "./checkpoint";
-async function setupRepo(): Promise<string> {
+async function createRepoTemplate(): Promise<string> {
const dir = await mkdtemp(path.join(tmpdir(), "posthog-code-checkpoint-"));
const git = createGitClient(dir);
await git.init();
@@ -28,6 +28,17 @@ async function setupRepo(): Promise<string> {
return dir;
}
+let repoTemplate: string;
+
+async function setupRepo(): Promise<string> {
+ const dir = await mkdtemp(path.join(tmpdir(), "posthog-code-checkpoint-"));
+ await cp(repoTemplate, dir, {
+ recursive: true,
+ filter: (source) => !source.endsWith("fsmonitor--daemon.ipc"),
+ });
+ return dir;
+}
+
async function withRepo<T>(fn: (repoPath: string) => Promise<T>): Promise<T> {
const repoPath = await setupRepo();
try {
@@ -82,6 +93,13 @@ async function revertCheckpoint(
}
describe("checkpoint sagas", () => {
+ beforeAll(async () => {
+ repoTemplate = await createRepoTemplate();
+ });
+
+ afterAll(async () => {
+ await rm(repoTemplate, { recursive: true, force: true });
+ });
it("captures and reverts worktree + index + untracked", async () => {
await withRepo(async (repoPath) => {
const git = createGitClient(repoPath);