mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-16 05:01:03 +03:00
fix(core): treat trailing-slash directories as the same Location (#59327)
This commit is contained in:
committed by
GitHub
Unverified
parent
3a7ba7a988
commit
6135e07fae
@@ -37,8 +37,12 @@ export const reload = Effect.fn("LocationServiceMap.reload")(function* () {
|
||||
|
||||
/** Normalize equivalent placements before they become resource-cache keys. */
|
||||
export function canonical(ref: Location.Ref) {
|
||||
// Workspace refs can hold remote POSIX paths even on a Windows host.
|
||||
const flavor = process.platform === "win32" && !ref.directory.startsWith("/") ? path.win32 : path.posix
|
||||
const normalized = flavor.normalize(ref.directory)
|
||||
const trailing = normalized.endsWith(flavor.sep) && normalized.length > flavor.parse(normalized).root.length
|
||||
return Location.Ref.make({
|
||||
directory: AbsolutePath.make(process.platform === "win32" ? path.normalize(ref.directory) : ref.directory),
|
||||
directory: AbsolutePath.make(trailing ? normalized.slice(0, -1) : normalized),
|
||||
workspaceID: ref.workspaceID,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -300,7 +300,7 @@ const layer = Layer.effect(
|
||||
if (recorded) return recorded
|
||||
const parent = input.parentID ? yield* store.get(input.parentID) : undefined
|
||||
if (input.parentID && parent === undefined) return yield* new NotFoundError({ sessionID: input.parentID })
|
||||
const location = parent?.location ?? input.location
|
||||
const location = parent?.location ?? (input.location && LocationServiceMap.canonical(input.location))
|
||||
if (location === undefined)
|
||||
return yield* Effect.die(new Error("Session.create requires either location or an existing parentID"))
|
||||
const project = yield* projects.resolve(location.directory)
|
||||
|
||||
@@ -419,6 +419,23 @@ describe("LocationServiceMap", () => {
|
||||
Location.Ref.make({ directory, workspaceID: undefined }),
|
||||
])
|
||||
|
||||
const variants = [
|
||||
`${directory}${path.sep}`,
|
||||
`${directory}${path.sep}${path.sep}`,
|
||||
`${path.dirname(directory)}${path.sep}${path.sep}${path.basename(directory)}`,
|
||||
`${directory}${path.sep}.${path.sep}child${path.sep}..${path.sep}`,
|
||||
]
|
||||
for (const variant of variants) {
|
||||
const ref = Location.Ref.make({ directory: AbsolutePath.make(variant) })
|
||||
expect(LocationServiceMap.canonical(ref).directory).toBe(directory)
|
||||
expect(yield* locations.contextEffect(ref)).toBe(first)
|
||||
}
|
||||
expect(Array.from(yield* RcMap.keys(locations.rcMap))).toHaveLength(1)
|
||||
const root = path.parse(directory).root
|
||||
expect(
|
||||
LocationServiceMap.canonical(Location.Ref.make({ directory: AbsolutePath.make(root) })).directory,
|
||||
).toBe(AbsolutePath.make(root))
|
||||
|
||||
// Invalidating with the shape opposite to the one that booted must evict.
|
||||
yield* locations.invalidate(present)
|
||||
expect(yield* locations.contextEffectOption(absent)).toEqual(Option.none())
|
||||
|
||||
@@ -246,7 +246,7 @@ describe("Session.create", () => {
|
||||
})
|
||||
expect(aliasAdopted).toMatchObject({
|
||||
projectID: project.id,
|
||||
location: aliased,
|
||||
location: nested,
|
||||
subpath: RelativePath.make("packages/app"),
|
||||
})
|
||||
// Adoption is a project-domain fact; the session log records nothing new.
|
||||
@@ -351,6 +351,19 @@ describe("Session.create", () => {
|
||||
}),
|
||||
)
|
||||
|
||||
it.effect("stores a trailing-slash directory in the same session list", () =>
|
||||
Effect.gen(function* () {
|
||||
const session = yield* Session.Service
|
||||
|
||||
const created = yield* session.create({ location: { directory: AbsolutePath.make("/project/") } })
|
||||
|
||||
expect(created.location.directory).toBe(location.directory)
|
||||
expect((yield* session.list({ directory: location.directory })).data.map((item) => item.id)).toEqual([
|
||||
created.id,
|
||||
])
|
||||
}),
|
||||
)
|
||||
|
||||
it.effect("returns the original session when the ID is retried", () =>
|
||||
Effect.gen(function* () {
|
||||
const session = yield* Session.Service
|
||||
|
||||
Reference in New Issue
Block a user