fix(core): skip non-vcs location watcher

Co-authored-by: opencode-agent[bot] <opencode-agent[bot]@users.noreply.github.com>
This commit is contained in:
Kit Langton 2026-07-08 00:31:14 +00:00
commit e6aaba8f4a
2 changed files with 23 additions and 21 deletions

View file

@ -29,6 +29,7 @@ const layer = Layer.effect(
Service, Service,
Effect.gen(function* () { Effect.gen(function* () {
const location = yield* Location.Service const location = yield* Location.Service
if (!location.vcs) return Service.of({})
const watcher = yield* Watcher.Service const watcher = yield* Watcher.Service
const events = yield* EventV2.Service const events = yield* EventV2.Service
const fs = yield* FSUtil.Service const fs = yield* FSUtil.Service

View file

@ -185,35 +185,33 @@ describeWatcher("LocationWatcher", () => {
), ),
) )
it.live("watches non-git roots", () => it.live("skips non-VCS roots", () =>
withTmp((directory) => withTmp((directory) =>
Effect.gen(function* () { Effect.gen(function* () {
const fs = yield* FSUtil.Service const fs = yield* FSUtil.Service
const file = path.join(directory, "plain.txt") const file = path.join(directory, "plain.txt")
yield* ready(directory) yield* noUpdate((event) => event.file === file, fs.writeFileString(file, "plain"))
expect(yield* nextUpdate((event) => event.file === file, fs.writeFileString(file, "plain"))).toEqual({
file,
event: "add",
})
}), }),
), ),
) )
it.live("ignores dependency, VCS, and build directories at any depth", () => it.live("ignores dependency, VCS, and build directories at any depth", () =>
withTmp((directory) => withTmp(
Effect.gen(function* () { (directory) =>
const afs = yield* FSUtil.Service Effect.gen(function* () {
yield* ready(directory) const afs = yield* FSUtil.Service
const roots = ["node_modules", ".git", "dist"].map((name) => path.join(directory, "nested", name)) yield* ready(directory)
const files = roots.map((root) => path.join(root, "package", "index.js")) const roots = ["node_modules", ".git", "dist"].map((name) => path.join(directory, "nested", name))
yield* noUpdate( const files = roots.map((root) => path.join(root, "package", "index.js"))
(event) => roots.some((root) => event.file === root || event.file.startsWith(`${root}${path.sep}`)), yield* noUpdate(
Effect.forEach(files, (file) => afs.writeWithDirs(file, "ignored"), { (event) => roots.some((root) => event.file === root || event.file.startsWith(`${root}${path.sep}`)),
concurrency: "unbounded", Effect.forEach(files, (file) => afs.writeWithDirs(file, "ignored"), {
discard: true, concurrency: "unbounded",
}), discard: true,
) }),
}), )
}),
{ git: true },
), ),
) )
@ -225,7 +223,10 @@ describeWatcher("LocationWatcher", () => {
Effect.promise(() => tmpdir()), Effect.promise(() => tmpdir()),
(tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()), (tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()),
) )
yield* ready(tmp.path).pipe(provide(tmp.path), Effect.scoped) yield* ready(tmp.path).pipe(
provide(tmp.path, { type: "git", store: AbsolutePath.make(path.join(tmp.path, ".git")) }),
Effect.scoped,
)
const file = path.join(tmp.path, "after-dispose.txt") const file = path.join(tmp.path, "after-dispose.txt")
yield* noUpdate((event) => event.file === file, fs.writeFileString(file, "gone")).pipe( yield* noUpdate((event) => event.file === file, fs.writeFileString(file, "gone")).pipe(
Effect.provideService(EventV2.Service, events), Effect.provideService(EventV2.Service, events),