Skip to content

Commit 17ef9de

Browse files
committed
test(server): add tree and watcher regression coverage
1 parent 04b82b6 commit 17ef9de

2 files changed

Lines changed: 44 additions & 1 deletion

File tree

packages/server/src/__tests__/file-commands.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,33 @@ describe("File Commands", () => {
141141
expect(files).toHaveLength(0);
142142
});
143143

144+
it("shows dotfiles and node_modules in file.readTree while still hiding .git", async () => {
145+
await writeFile(join(testDir, ".gitignore"), "*.log\nnode_modules/\n");
146+
await writeFile(join(testDir, ".env"), "secret\n");
147+
await writeFile(join(testDir, "ignored.log"), "log\n");
148+
await mkdir(join(testDir, "node_modules", "pkg"), { recursive: true });
149+
await mkdir(join(testDir, ".git"), { recursive: true });
150+
151+
const result = await dispatch(
152+
{
153+
kind: "command",
154+
id: "file-tree-1",
155+
op: "file.readTree",
156+
args: {
157+
workspaceId,
158+
},
159+
},
160+
ctx
161+
);
162+
163+
expect(result.ok).toBe(true);
164+
const children = (result.data as { children: Array<{ name: string }> }).children;
165+
expect(children.some((item) => item.name === ".env")).toBe(true);
166+
expect(children.some((item) => item.name === "ignored.log")).toBe(true);
167+
expect(children.some((item) => item.name === "node_modules")).toBe(true);
168+
expect(children.some((item) => item.name === ".git")).toBe(false);
169+
});
170+
144171
it("emits fs.dirty after file writes", async () => {
145172
const result = await dispatch(
146173
{

packages/server/src/__tests__/fs/watcher.test.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import { Topics } from "@coder-studio/core";
99
import chokidar, { type FSWatcher } from "chokidar";
10-
import { mkdtemp, rm } from "fs/promises";
10+
import { mkdtemp, rm, writeFile } from "fs/promises";
1111
import { tmpdir } from "os";
1212
import { join } from "path";
1313
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
@@ -93,6 +93,22 @@ describe("WorkspaceWatcher", () => {
9393
expect(ignored?.(join(testDir, "src/index.ts"))).toBe(false);
9494
});
9595

96+
it("continues to respect .gitignore entries after tree visibility was relaxed", async () => {
97+
await writeFile(join(testDir, ".gitignore"), "dist/\n*.log\n");
98+
99+
new WorkspaceWatcher("test-workspace-id", testDir, broadcaster);
100+
101+
expect(watchSpy).toHaveBeenCalledTimes(1);
102+
const options = watchSpy.mock.calls[0]?.[1];
103+
const ignored = options?.ignored;
104+
105+
expect(typeof ignored).toBe("function");
106+
expect(ignored?.(join(testDir, "dist", "bundle.js"))).toBe(true);
107+
expect(ignored?.(join(testDir, "debug.log"))).toBe(true);
108+
expect(ignored?.(join(testDir, ".git", "index"))).toBe(false);
109+
expect(ignored?.(join(testDir, "src", "index.ts"))).toBe(false);
110+
});
111+
96112
it("broadcasts fs.dirty after git metadata events settle", async () => {
97113
vi.useFakeTimers();
98114
new WorkspaceWatcher("test-workspace-id", testDir, broadcaster);

0 commit comments

Comments
 (0)