fix: correct checkout-diff-manager test file contents

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Mohamed Boudra
2026-04-01 04:49:03 +00:00
co-authored by Claude Opus 4.6
parent 4b12ebd5c0
commit 8d55764313
@@ -1,153 +1,134 @@
commit 07b077f1a28e7126f9d2b48be03bca8486173aac import path from "node:path";
Author: Mohamed Boudra <boudra.moha@gmail.com> import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
Date: Wed Apr 1 04:38:45 2026 +0000
fix: Linux checkout diff watchers and rewind command ordering const { execMock, getCheckoutDiffMock, resolveCheckoutGitDirMock, readdirMock, watchCalls } =
vi.hoisted(() => {
Use non-recursive directory watchers on Linux since recursive fs.watch const hoistedWatchCalls: Array<{ path: string; close: ReturnType<typeof vi.fn> }> = [];
is not supported. Dynamically discover and watch subdirectories, refreshing return {
the watcher tree on changes. Also pin rewind command first in the slash execMock: vi.fn((_command: string, _options: unknown, callback: (error: null, result: { stdout: string; stderr: string }) => void) => {
command list and remove stale .gitignore entry. callback(null, { stdout: "/tmp/repo\n", stderr: "" });
}),
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> getCheckoutDiffMock: vi.fn(async () => ({ diff: "", structured: [] })),
resolveCheckoutGitDirMock: vi.fn(async () => "/tmp/repo/.git"),
readdirMock: vi.fn(async (directory: string) => {
if (directory === "/tmp/repo") {
return [
{ name: "packages", isDirectory: () => true },
{ name: ".git", isDirectory: () => true },
{ name: "README.md", isDirectory: () => false },
];
}
if (directory === path.join("/tmp/repo", "packages")) {
return [
{ name: "server", isDirectory: () => true },
{ name: "app", isDirectory: () => true },
];
}
if (directory === path.join("/tmp/repo", "packages", "server")) {
return [{ name: "src", isDirectory: () => true }];
}
if (directory === path.join("/tmp/repo", "packages", "server", "src")) {
return [{ name: "server", isDirectory: () => true }];
}
return [];
}),
watchCalls: hoistedWatchCalls,
};
});
diff --git a/packages/server/src/server/checkout-diff-manager.test.ts b/packages/server/src/server/checkout-diff-manager.test.ts vi.mock("child_process", () => ({
new file mode 100644 exec: execMock,
index 00000000..22f0fda8 }));
--- /dev/null
+++ b/packages/server/src/server/checkout-diff-manager.test.ts vi.mock("node:fs/promises", async () => {
@@ -0,0 +1,134 @@ const actual = await vi.importActual<typeof import("node:fs/promises")>("node:fs/promises");
+import path from "node:path"; return {
+import { afterEach, beforeEach, describe, expect, test, vi } from "vitest"; ...actual,
+ readdir: readdirMock,
+const { execMock, getCheckoutDiffMock, resolveCheckoutGitDirMock, readdirMock, watchCalls } = };
+ vi.hoisted(() => { });
+ const hoistedWatchCalls: Array<{ path: string; close: ReturnType<typeof vi.fn> }> = [];
+ return { vi.mock("node:fs", async () => {
+ execMock: vi.fn((_command: string, _options: unknown, callback: (error: null, result: { stdout: string; stderr: string }) => void) => { const actual = await vi.importActual<typeof import("node:fs")>("node:fs");
+ callback(null, { stdout: "/tmp/repo\n", stderr: "" }); return {
+ }), ...actual,
+ getCheckoutDiffMock: vi.fn(async () => ({ diff: "", structured: [] })), watch: vi.fn((watchPath: string) => {
+ resolveCheckoutGitDirMock: vi.fn(async () => "/tmp/repo/.git"), const close = vi.fn();
+ readdirMock: vi.fn(async (directory: string) => { watchCalls.push({ path: watchPath, close });
+ if (directory === "/tmp/repo") { return {
+ return [ close,
+ { name: "packages", isDirectory: () => true }, on: vi.fn().mockReturnThis(),
+ { name: ".git", isDirectory: () => true }, } as any;
+ { name: "README.md", isDirectory: () => false }, }),
+ ]; };
+ } });
+ if (directory === path.join("/tmp/repo", "packages")) {
+ return [ vi.mock("../utils/checkout-git.js", () => ({
+ { name: "server", isDirectory: () => true }, getCheckoutDiff: getCheckoutDiffMock,
+ { name: "app", isDirectory: () => true }, }));
+ ];
+ } vi.mock("./checkout-git-utils.js", () => ({
+ if (directory === path.join("/tmp/repo", "packages", "server")) { READ_ONLY_GIT_ENV: {},
+ return [{ name: "src", isDirectory: () => true }]; resolveCheckoutGitDir: resolveCheckoutGitDirMock,
+ } toCheckoutError: vi.fn((error: unknown) => ({
+ if (directory === path.join("/tmp/repo", "packages", "server", "src")) { message: error instanceof Error ? error.message : String(error),
+ return [{ name: "server", isDirectory: () => true }]; })),
+ } }));
+ return [];
+ }), import { CheckoutDiffManager } from "./checkout-diff-manager.js";
+ watchCalls: hoistedWatchCalls,
+ }; describe("CheckoutDiffManager Linux watchers", () => {
+ }); const originalPlatform = process.platform;
+
+vi.mock("child_process", () => ({ beforeEach(() => {
+ exec: execMock, watchCalls.length = 0;
+})); execMock.mockClear();
+ getCheckoutDiffMock.mockClear();
+vi.mock("node:fs/promises", async () => { resolveCheckoutGitDirMock.mockClear();
+ const actual = await vi.importActual<typeof import("node:fs/promises")>("node:fs/promises"); readdirMock.mockClear();
+ return { Object.defineProperty(process, "platform", {
+ ...actual, configurable: true,
+ readdir: readdirMock, value: "linux",
+ }; });
+}); });
+
+vi.mock("node:fs", async () => { afterEach(() => {
+ const actual = await vi.importActual<typeof import("node:fs")>("node:fs"); Object.defineProperty(process, "platform", {
+ return { configurable: true,
+ ...actual, value: originalPlatform,
+ watch: vi.fn((watchPath: string) => { });
+ const close = vi.fn(); });
+ watchCalls.push({ path: watchPath, close });
+ return { test("watches nested repository directories on Linux", async () => {
+ close, const logger = {
+ on: vi.fn().mockReturnThis(), child: () => logger,
+ } as any; warn: vi.fn(),
+ }), };
+ }; const manager = new CheckoutDiffManager({
+}); logger: logger as any,
+ paseoHome: "/tmp/paseo-test",
+vi.mock("../utils/checkout-git.js", () => ({ });
+ getCheckoutDiff: getCheckoutDiffMock,
+})); const subscription = await manager.subscribe(
+ {
+vi.mock("./checkout-git-utils.js", () => ({ cwd: path.join("/tmp/repo", "packages", "server"),
+ READ_ONLY_GIT_ENV: {}, compare: { mode: "uncommitted" },
+ resolveCheckoutGitDir: resolveCheckoutGitDirMock, },
+ toCheckoutError: vi.fn((error: unknown) => ({ () => {},
+ message: error instanceof Error ? error.message : String(error), );
+ })),
+})); expect(subscription.initial.error).toBeNull();
+ expect(watchCalls.map((entry) => entry.path).sort()).toEqual([
+import { CheckoutDiffManager } from "./checkout-diff-manager.js"; "/tmp/repo",
+ "/tmp/repo/.git",
+describe("CheckoutDiffManager Linux watchers", () => { "/tmp/repo/packages",
+ const originalPlatform = process.platform; "/tmp/repo/packages/app",
+ "/tmp/repo/packages/server",
+ beforeEach(() => { "/tmp/repo/packages/server/src",
+ watchCalls.length = 0; "/tmp/repo/packages/server/src/server",
+ execMock.mockClear(); ]);
+ getCheckoutDiffMock.mockClear();
+ resolveCheckoutGitDirMock.mockClear(); subscription.unsubscribe();
+ readdirMock.mockClear(); manager.dispose();
+ Object.defineProperty(process, "platform", { });
+ configurable: true, });
+ value: "linux",
+ });
+ });
+
+ afterEach(() => {
+ Object.defineProperty(process, "platform", {
+ configurable: true,
+ value: originalPlatform,
+ });
+ });
+
+ test("watches nested repository directories on Linux", async () => {
+ const logger = {
+ child: () => logger,
+ warn: vi.fn(),
+ };
+ const manager = new CheckoutDiffManager({
+ logger: logger as any,
+ paseoHome: "/tmp/paseo-test",
+ });
+
+ const subscription = await manager.subscribe(
+ {
+ cwd: path.join("/tmp/repo", "packages", "server"),
+ compare: { mode: "uncommitted" },
+ },
+ () => {},
+ );
+
+ expect(subscription.initial.error).toBeNull();
+ expect(watchCalls.map((entry) => entry.path).sort()).toEqual([
+ "/tmp/repo",
+ "/tmp/repo/.git",
+ "/tmp/repo/packages",
+ "/tmp/repo/packages/app",
+ "/tmp/repo/packages/server",
+ "/tmp/repo/packages/server/src",
+ "/tmp/repo/packages/server/src/server",
+ ]);
+
+ subscription.unsubscribe();
+ manager.dispose();
+ });
+});