diff --git a/packages/core/src/location-service-map.ts b/packages/core/src/location-service-map.ts index c24adc3b6d9..60e0f2c57e6 100644 --- a/packages/core/src/location-service-map.ts +++ b/packages/core/src/location-service-map.ts @@ -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, }) } diff --git a/packages/core/src/session.ts b/packages/core/src/session.ts index 73135b5f99b..7738259f56b 100644 --- a/packages/core/src/session.ts +++ b/packages/core/src/session.ts @@ -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) diff --git a/packages/core/test/location-layer.test.ts b/packages/core/test/location-layer.test.ts index 06550852305..930bbc2f151 100644 --- a/packages/core/test/location-layer.test.ts +++ b/packages/core/test/location-layer.test.ts @@ -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()) diff --git a/packages/core/test/session-create.test.ts b/packages/core/test/session-create.test.ts index 8e440f761a5..41ed037b9b7 100644 --- a/packages/core/test/session-create.test.ts +++ b/packages/core/test/session-create.test.ts @@ -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