diff --git a/packages/core/src/project-reference.ts b/packages/core/src/project-reference.ts index ac7eb6d8c5a..7e1fac79318 100644 --- a/packages/core/src/project-reference.ts +++ b/packages/core/src/project-reference.ts @@ -73,7 +73,7 @@ export const layer = Layer.effect( references: ConfigReference.normalize( Object.assign({}, ...(yield* config.get()).map((document) => document.info.references ?? {})), ), - directory: location.project.directory, + directory: location.vcs ? location.project.directory : location.directory, home: global.home, repos: global.repos, }) diff --git a/packages/core/test/fixture/location.ts b/packages/core/test/fixture/location.ts index 00b3ffbd13f..9313df088af 100644 --- a/packages/core/test/fixture/location.ts +++ b/packages/core/test/fixture/location.ts @@ -2,11 +2,14 @@ import { Location } from "@opencode-ai/core/location" import { Project } from "@opencode-ai/core/project" import { AbsolutePath } from "@opencode-ai/core/schema" -export function location(ref: Location.Ref, input: { projectDirectory?: AbsolutePath; vcs?: Project.Vcs } = {}) { +export function location( + ref: Location.Ref, + input: { projectID?: Project.ID; projectDirectory?: AbsolutePath; vcs?: Project.Vcs } = {}, +) { return { directory: ref.directory, workspaceID: ref.workspaceID, - project: { id: Project.ID.global, directory: input.projectDirectory ?? ref.directory }, + project: { id: input.projectID ?? Project.ID.global, directory: input.projectDirectory ?? ref.directory }, vcs: input.vcs, } satisfies Location.Interface } diff --git a/packages/core/test/project-reference.test.ts b/packages/core/test/project-reference.test.ts index a9c25e51389..afd09f0e410 100644 --- a/packages/core/test/project-reference.test.ts +++ b/packages/core/test/project-reference.test.ts @@ -8,6 +8,7 @@ import { FSUtil } from "@opencode-ai/core/fs-util" import { Flag } from "@opencode-ai/core/flag/flag" import { Global } from "@opencode-ai/core/global" import { Location } from "@opencode-ai/core/location" +import { Project } from "@opencode-ai/core/project" import { ProjectReference } from "@opencode-ai/core/project-reference" import { Repository } from "@opencode-ai/core/repository" import { RepositoryCache } from "@opencode-ai/core/repository-cache" @@ -86,6 +87,64 @@ describe("ProjectReference", () => { }), ) + it.live("resolves local references from the opened directory for global locations", () => + withoutReferences( + withTmp((tmp) => + withReferences( + Effect.gen(function* () { + const references = yield* ProjectReference.Service + expect(yield* references.get("docs")).toMatchObject({ + name: "docs", + kind: "local", + path: path.join(tmp.path, "opened", "docs"), + }) + }).pipe( + Effect.provide( + testLayer({ + directory: path.join(tmp.path, "opened"), + project: "/", + projectID: Project.ID.global, + repos: path.join(tmp.path, "repos"), + documents: [document({ docs: "./docs" })], + ensure: () => Effect.die("unexpected ensure"), + }), + ), + ), + ), + ), + ), + ) + + it.live("resolves local references from the project root for global-id Git locations", () => + withoutReferences( + withTmp((tmp) => { + const project = path.join(tmp.path, "project") + return withReferences( + Effect.gen(function* () { + const references = yield* ProjectReference.Service + expect(yield* references.get("docs")).toMatchObject({ + name: "docs", + kind: "local", + path: path.join(project, "docs"), + }) + }).pipe( + Effect.provide( + testLayer({ + directory: path.join(project, "nested"), + project, + projectID: Project.ID.global, + vcs: { type: "git", store: AbsolutePath.make(path.join(project, ".git")) }, + repos: path.join(tmp.path, "repos"), + documents: [document({ docs: "./docs" })], + ensure: () => Effect.die("unexpected ensure"), + }), + ), + ), + ) + }), + ), + ) + it.live("merges config aliases and exposes mention and managed-path operations", () => withoutReferences( withTmp((tmp) => { @@ -139,6 +198,7 @@ describe("ProjectReference", () => { testLayer({ directory: nested, project, + vcs: { type: "git", store: AbsolutePath.make(path.join(project, ".git")) }, repos, documents: [ document({ docs: { path: "./old-docs" }, sdk: "owner/old" }), @@ -236,6 +296,8 @@ function result( function testLayer(input: { directory: string project: string + projectID?: Project.ID + vcs?: Project.Vcs repos: string documents: Config.Loaded[] ensure: RepositoryCache.Interface["ensure"] @@ -250,7 +312,11 @@ function testLayer(input: { Location.Service.of( location( { directory: AbsolutePath.make(input.directory) }, - { projectDirectory: AbsolutePath.make(input.project) }, + { + projectID: input.projectID ?? Project.ID.make("project"), + projectDirectory: AbsolutePath.make(input.project), + vcs: input.vcs, + }, ), ), ),