fix(core): stop instruction walk at case-variant Windows project roots (#53349)

This commit is contained in:
Filip
2026-10-05 15:10:22 +02:00
committed by GitHub
Unverified
parent e3c3786f43
commit 1732ce1eeb
3 changed files with 55 additions and 3 deletions
@@ -3,6 +3,7 @@ export * as ConfigInstructionPlugin from "./instruction.js"
import { define } from "@opencode/plugin/effect/plugin"
import { FSUtil } from "@opencode/util/fs-util"
import { Global } from "@opencode/util/global"
import { sameDirectory } from "@opencode/util/path"
import { dirname, join } from "path"
import { Effect, PubSub, Semaphore, Stream } from "effect"
import { Watcher } from "../../filesystem/watcher.js"
@@ -133,7 +134,10 @@ export const Plugin = define({
}),
})
// `start` keeps the client's spelling while `stop` may come from git, so a Windows drive
// letter can differ only in case (`c:\repo` vs `C:\repo`). Compare the way FSUtil.contains
// admitted `start` beneath `stop`, or the walk passes `stop` and recurses at the drive root.
function ancestorDirectories(start: string, stop: string): string[] {
if (start === stop) return [start]
if (sameDirectory(start, stop)) return [start]
return [start, ...ancestorDirectories(dirname(start), stop)]
}
@@ -364,6 +364,53 @@ describe("ConfigInstructionPlugin.Plugin", () => {
),
)
// A client CWD can spell the drive `c:` while git reports the project root as `C:`.
;(process.platform === "win32" ? it.live : it.live.skip)(
"stops at the project root when the location drive letter differs in case",
() =>
Effect.acquireRelease(
Effect.promise(() => tmpdir()),
(tmp) => Effect.promise(() => tmp[Symbol.asyncDispose]()),
).pipe(
Effect.flatMap((tmp) => {
const global = path.join(tmp.path, "global")
const home = path.join(tmp.path, "home")
const project = path.join(tmp.path, "repo")
const directory = project[0].toLowerCase() + project.slice(1)
return Effect.gen(function* () {
yield* Effect.promise(() => fs.mkdir(project, { recursive: true }))
yield* Effect.promise(() => fs.writeFile(path.join(project, "AGENTS.md"), "project"))
yield* Effect.promise(() => fs.writeFile(path.join(tmp.path, "AGENTS.md"), "outside"))
const discovery = yield* start()
const watcher = yield* Watcher.Test
expect(yield* watcher.subscriptions()).toEqual([
{ path: path.join(global, "AGENTS.md"), type: "file" },
{ path: path.join(directory, "AGENTS.md"), type: "file" },
])
expect((yield* readInitial(yield* discovery.load())).text).toBe(
`Instructions from: ${path.join(directory, "AGENTS.md")}\nproject`,
)
}).pipe(
Effect.provide(
instructionLayer({
config: global,
home,
locationServiceLayer: Layer.succeed(
Location.Service,
Location.Service.of(
location(
{ directory: AbsolutePath.make(directory) },
{ projectDirectory: AbsolutePath.make(project) },
),
),
),
}),
),
)
}),
),
)
it.effect("isolates source failure without failing activation", () => {
const failingFS = Layer.effect(
FSUtil.Service,
+3 -2
View File
@@ -8,6 +8,7 @@ import { Glob } from "./glob.js"
import { serviceUse } from "./effect/service-use.js"
import { makeGlobalNode } from "./effect/app-node.js"
import { filesystem } from "./effect/app-node-platform.js"
import { sameDirectory } from "./path.js"
export namespace FSUtil {
export class FileSystemError extends Schema.TaggedError<FileSystemError>()("FileSystemError", {
@@ -178,7 +179,7 @@ export namespace FSUtil {
if (options.mode === "first") return result
}
}
if (options.stop === current) break
if (options.stop && sameDirectory(options.stop, current)) break
const parent = dirname(current)
if (parent === current) break
current = parent
@@ -198,7 +199,7 @@ export namespace FSUtil {
Effect.orElseSucceed(() => [] as string[]),
)
result.push(...matches)
if (stop === current) break
if (stop && sameDirectory(stop, current)) break
const parent = dirname(current)
if (parent === current) break
current = parent