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
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class HostFsWatchHandle implements IHostFsWatchHandle {
ignoreInitial: true,
persistent: false,
followSymlinks: false,
depth: options?.recursive === false ? 0 : undefined,
depth: options?.depth ?? (options?.recursive === false ? 0 : undefined),
ignored: options?.ignored ?? DEFAULT_IGNORED,
});
this.watcher.on('all', (eventName: string, absPath: string) => {
Expand Down
1 change: 1 addition & 0 deletions packages/agent-core-v2/src/os/interface/hostFsWatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface HostFsChange {
export interface HostFsWatchOptions {
readonly recursive?: boolean;
readonly ignored?: (path: string) => boolean;
readonly depth?: number;
readonly signal?: boolean;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,8 @@ describe('host filesystem change notifications', () => {

it('reports create / modify / delete for a file', async () => {
root = await mkdtemp(join(tmpdir(), 'hostfswatch-'));
const preexisting = join(root, 'pre.txt');
await writeFile(preexisting, 'v0');
const events = await start();

const file = join(root, 'a.txt');
Expand All @@ -247,6 +249,7 @@ describe('host filesystem change notifications', () => {
await rm(file);
await wait(300);

expect(events.some((e) => e.path === preexisting)).toBe(false);
const actions = events.filter((e) => e.path === file).map((e) => e.action);
expect(actions).toContain('created');
expect(actions).toContain('modified');
Expand All @@ -265,15 +268,22 @@ describe('host filesystem change notifications', () => {
expect(events.some((e) => e.path.includes('/.git/') || e.path.endsWith('/.git'))).toBe(false);
});

it('does not fire for pre-existing files (ignoreInitial)', async () => {
it('does not report changes below the configured depth', async () => {
root = await mkdtemp(join(tmpdir(), 'hostfswatch-'));
const preexisting = join(root, 'pre.txt');
await writeFile(preexisting, 'v0');
const events: HostFsChange[] = [];
const svc = new HostFsWatchService();
handle = svc.watch(root, { depth: 0 });
handle.onDidChange((e) => events.push(e));
await handle.ready;

const events = await start();
await mkdir(join(root, 'sub'));
await writeFile(join(root, 'top.txt'), 'x');
await writeFile(join(root, 'sub', 'nested.txt'), 'x');
await wait(300);

expect(events.some((e) => e.path === preexisting)).toBe(false);
expect(events.some((e) => e.path === join(root, 'top.txt'))).toBe(true);
expect(events.some((e) => e.path === join(root, 'sub'))).toBe(true);
expect(events.some((e) => e.path.endsWith('nested.txt'))).toBe(false);
});

it('stops firing after the handle is disposed', async () => {
Expand Down
2 changes: 1 addition & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading