fix(core): resolve local references from location root
This commit is contained in:
parent
56ec4b6912
commit
0ce1866e8e
3 changed files with 73 additions and 4 deletions
|
|
@ -73,7 +73,7 @@ export const layer = Layer.effect(
|
||||||
references: ConfigReference.normalize(
|
references: ConfigReference.normalize(
|
||||||
Object.assign({}, ...(yield* config.get()).map((document) => document.info.references ?? {})),
|
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,
|
home: global.home,
|
||||||
repos: global.repos,
|
repos: global.repos,
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -2,11 +2,14 @@ import { Location } from "@opencode-ai/core/location"
|
||||||
import { Project } from "@opencode-ai/core/project"
|
import { Project } from "@opencode-ai/core/project"
|
||||||
import { AbsolutePath } from "@opencode-ai/core/schema"
|
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 {
|
return {
|
||||||
directory: ref.directory,
|
directory: ref.directory,
|
||||||
workspaceID: ref.workspaceID,
|
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,
|
vcs: input.vcs,
|
||||||
} satisfies Location.Interface
|
} satisfies Location.Interface
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import { FSUtil } from "@opencode-ai/core/fs-util"
|
||||||
import { Flag } from "@opencode-ai/core/flag/flag"
|
import { Flag } from "@opencode-ai/core/flag/flag"
|
||||||
import { Global } from "@opencode-ai/core/global"
|
import { Global } from "@opencode-ai/core/global"
|
||||||
import { Location } from "@opencode-ai/core/location"
|
import { Location } from "@opencode-ai/core/location"
|
||||||
|
import { Project } from "@opencode-ai/core/project"
|
||||||
import { ProjectReference } from "@opencode-ai/core/project-reference"
|
import { ProjectReference } from "@opencode-ai/core/project-reference"
|
||||||
import { Repository } from "@opencode-ai/core/repository"
|
import { Repository } from "@opencode-ai/core/repository"
|
||||||
import { RepositoryCache } from "@opencode-ai/core/repository-cache"
|
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", () =>
|
it.live("merges config aliases and exposes mention and managed-path operations", () =>
|
||||||
withoutReferences(
|
withoutReferences(
|
||||||
withTmp((tmp) => {
|
withTmp((tmp) => {
|
||||||
|
|
@ -139,6 +198,7 @@ describe("ProjectReference", () => {
|
||||||
testLayer({
|
testLayer({
|
||||||
directory: nested,
|
directory: nested,
|
||||||
project,
|
project,
|
||||||
|
vcs: { type: "git", store: AbsolutePath.make(path.join(project, ".git")) },
|
||||||
repos,
|
repos,
|
||||||
documents: [
|
documents: [
|
||||||
document({ docs: { path: "./old-docs" }, sdk: "owner/old" }),
|
document({ docs: { path: "./old-docs" }, sdk: "owner/old" }),
|
||||||
|
|
@ -236,6 +296,8 @@ function result(
|
||||||
function testLayer(input: {
|
function testLayer(input: {
|
||||||
directory: string
|
directory: string
|
||||||
project: string
|
project: string
|
||||||
|
projectID?: Project.ID
|
||||||
|
vcs?: Project.Vcs
|
||||||
repos: string
|
repos: string
|
||||||
documents: Config.Loaded[]
|
documents: Config.Loaded[]
|
||||||
ensure: RepositoryCache.Interface["ensure"]
|
ensure: RepositoryCache.Interface["ensure"]
|
||||||
|
|
@ -250,7 +312,11 @@ function testLayer(input: {
|
||||||
Location.Service.of(
|
Location.Service.of(
|
||||||
location(
|
location(
|
||||||
{ directory: AbsolutePath.make(input.directory) },
|
{ 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,
|
||||||
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue