test(reference): serialize github base overrides
This commit is contained in:
parent
330faabf9a
commit
1bb7b299e5
6 changed files with 25 additions and 91 deletions
|
|
@ -93,9 +93,7 @@ export const layer = Layer.effect(
|
||||||
|
|
||||||
return Service.of({
|
return Service.of({
|
||||||
init: Effect.fn("Reference.init")(function* () {
|
init: Effect.fn("Reference.init")(function* () {
|
||||||
yield* InstanceState.get(state)
|
yield* ensure().pipe(Effect.forkIn(scope), Effect.asVoid)
|
||||||
// Own the cached warmup from the long-lived legacy scope before the core layer's scheduled fork can claim it.
|
|
||||||
yield* ensure().pipe(Effect.forkIn(scope, { startImmediately: true }), Effect.asVoid)
|
|
||||||
}),
|
}),
|
||||||
list: Effect.fn("Reference.list")(function* () {
|
list: Effect.fn("Reference.list")(function* () {
|
||||||
return yield* InstanceState.useEffect(state, (service) => service.list())
|
return yield* InstanceState.useEffect(state, (service) => service.list())
|
||||||
|
|
|
||||||
20
packages/opencode/test/fixture/repository.ts
Normal file
20
packages/opencode/test/fixture/repository.ts
Normal file
|
|
@ -0,0 +1,20 @@
|
||||||
|
import { Effect, Semaphore } from "effect"
|
||||||
|
|
||||||
|
const lock = Semaphore.makeUnsafe(1)
|
||||||
|
|
||||||
|
export const githubBase = <A, E, R>(url: string, self: Effect.Effect<A, E, R>) =>
|
||||||
|
lock.withPermit(
|
||||||
|
Effect.acquireUseRelease(
|
||||||
|
Effect.sync(() => {
|
||||||
|
const previous = process.env.OPENCODE_REPO_CLONE_GITHUB_BASE_URL
|
||||||
|
process.env.OPENCODE_REPO_CLONE_GITHUB_BASE_URL = url
|
||||||
|
return previous
|
||||||
|
}),
|
||||||
|
() => self,
|
||||||
|
(previous) =>
|
||||||
|
Effect.sync(() => {
|
||||||
|
if (previous === undefined) delete process.env.OPENCODE_REPO_CLONE_GITHUB_BASE_URL
|
||||||
|
else process.env.OPENCODE_REPO_CLONE_GITHUB_BASE_URL = previous
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
import { afterEach, describe, expect } from "bun:test"
|
import { afterEach, describe, expect } from "bun:test"
|
||||||
import path from "path"
|
import path from "path"
|
||||||
import { pathToFileURL } from "url"
|
|
||||||
import { Effect, Layer } from "effect"
|
import { Effect, Layer } from "effect"
|
||||||
import { FSUtil } from "@opencode-ai/core/fs-util"
|
import { FSUtil } from "@opencode-ai/core/fs-util"
|
||||||
import { CrossSpawnSpawner } from "@opencode-ai/core/cross-spawn-spawner"
|
import { CrossSpawnSpawner } from "@opencode-ai/core/cross-spawn-spawner"
|
||||||
|
|
@ -12,6 +11,7 @@ import { Git } from "../../src/git"
|
||||||
import { Reference } from "../../src/reference"
|
import { Reference } from "../../src/reference"
|
||||||
import { RepositoryCache } from "@opencode-ai/core/repository-cache"
|
import { RepositoryCache } from "@opencode-ai/core/repository-cache"
|
||||||
import { disposeAllInstances, provideTmpdirInstance, tmpdirScoped } from "../fixture/fixture"
|
import { disposeAllInstances, provideTmpdirInstance, tmpdirScoped } from "../fixture/fixture"
|
||||||
|
import { githubBase } from "../fixture/repository"
|
||||||
import { testEffect } from "../lib/effect"
|
import { testEffect } from "../lib/effect"
|
||||||
|
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
|
|
@ -32,21 +32,6 @@ const references = testEffect(
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
const githubBase = <A, E, R>(url: string, self: Effect.Effect<A, E, R>) =>
|
|
||||||
Effect.acquireUseRelease(
|
|
||||||
Effect.sync(() => {
|
|
||||||
const previous = process.env.OPENCODE_REPO_CLONE_GITHUB_BASE_URL
|
|
||||||
process.env.OPENCODE_REPO_CLONE_GITHUB_BASE_URL = url
|
|
||||||
return previous
|
|
||||||
}),
|
|
||||||
() => self,
|
|
||||||
(previous) =>
|
|
||||||
Effect.sync(() => {
|
|
||||||
if (previous) process.env.OPENCODE_REPO_CLONE_GITHUB_BASE_URL = previous
|
|
||||||
else delete process.env.OPENCODE_REPO_CLONE_GITHUB_BASE_URL
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
|
|
||||||
const withReferences = <A, E, R>(self: Effect.Effect<A, E, R>) =>
|
const withReferences = <A, E, R>(self: Effect.Effect<A, E, R>) =>
|
||||||
Effect.acquireUseRelease(
|
Effect.acquireUseRelease(
|
||||||
Effect.sync(() => process.env.OPENCODE_EXPERIMENTAL_REFERENCES),
|
Effect.sync(() => process.env.OPENCODE_EXPERIMENTAL_REFERENCES),
|
||||||
|
|
@ -191,34 +176,6 @@ describe("reference", () => {
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
references.live("resolves configured remotes before init returns", () =>
|
|
||||||
withReferences(
|
|
||||||
provideTmpdirInstance(
|
|
||||||
(_dir) =>
|
|
||||||
Effect.gen(function* () {
|
|
||||||
const remoteRoot = yield* tmpdirScoped()
|
|
||||||
const reference = yield* Reference.Service
|
|
||||||
yield* githubBase(`file://${remoteRoot}/`, reference.init())
|
|
||||||
|
|
||||||
const resolved = yield* reference.get("docs")
|
|
||||||
expect(resolved?.kind).toBe("git")
|
|
||||||
if (resolved?.kind === "git") {
|
|
||||||
expect(resolved.reference.remote).toBe(
|
|
||||||
new URL("opencode-reference-init/repo.git", pathToFileURL(remoteRoot + path.sep)).href,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}),
|
|
||||||
{
|
|
||||||
config: {
|
|
||||||
reference: {
|
|
||||||
docs: "opencode-reference-init/repo",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
|
|
||||||
it.live("marks same-cache references with different branches invalid", () =>
|
it.live("marks same-cache references with different branches invalid", () =>
|
||||||
Effect.gen(function* () {
|
Effect.gen(function* () {
|
||||||
const root = path.resolve("opencode-reference-root")
|
const root = path.resolve("opencode-reference-root")
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ import { Truncate } from "@/tool/truncate"
|
||||||
import { Agent } from "../../src/agent/agent"
|
import { Agent } from "../../src/agent/agent"
|
||||||
import { TestInstance, tmpdirScoped } from "../fixture/fixture"
|
import { TestInstance, tmpdirScoped } from "../fixture/fixture"
|
||||||
import { testEffect } from "../lib/effect"
|
import { testEffect } from "../lib/effect"
|
||||||
|
import { githubBase } from "../fixture/repository"
|
||||||
import { Reference } from "@/reference"
|
import { Reference } from "@/reference"
|
||||||
import { RepositoryCache } from "@opencode-ai/core/repository-cache"
|
import { RepositoryCache } from "@opencode-ai/core/repository-cache"
|
||||||
import { Config } from "@/config/config"
|
import { Config } from "@/config/config"
|
||||||
|
|
@ -61,21 +62,6 @@ const asks = () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const githubBase = <A, E, R>(url: string, self: Effect.Effect<A, E, R>) =>
|
|
||||||
Effect.acquireUseRelease(
|
|
||||||
Effect.sync(() => {
|
|
||||||
const previous = process.env.OPENCODE_REPO_CLONE_GITHUB_BASE_URL
|
|
||||||
process.env.OPENCODE_REPO_CLONE_GITHUB_BASE_URL = url
|
|
||||||
return previous
|
|
||||||
}),
|
|
||||||
() => self,
|
|
||||||
(previous) =>
|
|
||||||
Effect.sync(() => {
|
|
||||||
if (previous) process.env.OPENCODE_REPO_CLONE_GITHUB_BASE_URL = previous
|
|
||||||
else delete process.env.OPENCODE_REPO_CLONE_GITHUB_BASE_URL
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
|
|
||||||
const git = Effect.fn("GlobToolTest.git")(function* (cwd: string, args: string[]) {
|
const git = Effect.fn("GlobToolTest.git")(function* (cwd: string, args: string[]) {
|
||||||
return yield* Effect.promise(async () => {
|
return yield* Effect.promise(async () => {
|
||||||
const proc = Bun.spawn(["git", ...args], {
|
const proc = Bun.spawn(["git", ...args], {
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ import { Agent } from "../../src/agent/agent"
|
||||||
import { Ripgrep } from "@opencode-ai/core/filesystem/ripgrep"
|
import { Ripgrep } from "@opencode-ai/core/filesystem/ripgrep"
|
||||||
import { FSUtil } from "@opencode-ai/core/fs-util"
|
import { FSUtil } from "@opencode-ai/core/fs-util"
|
||||||
import { testEffect } from "../lib/effect"
|
import { testEffect } from "../lib/effect"
|
||||||
|
import { githubBase } from "../fixture/repository"
|
||||||
import { Reference } from "@/reference"
|
import { Reference } from "@/reference"
|
||||||
import { RepositoryCache } from "@opencode-ai/core/repository-cache"
|
import { RepositoryCache } from "@opencode-ai/core/repository-cache"
|
||||||
import { Permission } from "../../src/permission"
|
import { Permission } from "../../src/permission"
|
||||||
|
|
@ -54,21 +55,6 @@ const ctx = {
|
||||||
const root = path.join(__dirname, "../..")
|
const root = path.join(__dirname, "../..")
|
||||||
const full = (p: string) => (process.platform === "win32" ? Filesystem.normalizePath(p) : p)
|
const full = (p: string) => (process.platform === "win32" ? Filesystem.normalizePath(p) : p)
|
||||||
|
|
||||||
const githubBase = <A, E, R>(url: string, self: Effect.Effect<A, E, R>) =>
|
|
||||||
Effect.acquireUseRelease(
|
|
||||||
Effect.sync(() => {
|
|
||||||
const previous = process.env.OPENCODE_REPO_CLONE_GITHUB_BASE_URL
|
|
||||||
process.env.OPENCODE_REPO_CLONE_GITHUB_BASE_URL = url
|
|
||||||
return previous
|
|
||||||
}),
|
|
||||||
() => self,
|
|
||||||
(previous) =>
|
|
||||||
Effect.sync(() => {
|
|
||||||
if (previous) process.env.OPENCODE_REPO_CLONE_GITHUB_BASE_URL = previous
|
|
||||||
else delete process.env.OPENCODE_REPO_CLONE_GITHUB_BASE_URL
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
|
|
||||||
const git = Effect.fn("GrepToolTest.git")(function* (cwd: string, args: string[]) {
|
const git = Effect.fn("GrepToolTest.git")(function* (cwd: string, args: string[]) {
|
||||||
return yield* Effect.promise(async () => {
|
return yield* Effect.promise(async () => {
|
||||||
const proc = Bun.spawn(["git", ...args], {
|
const proc = Bun.spawn(["git", ...args], {
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ import {
|
||||||
tmpdirScoped,
|
tmpdirScoped,
|
||||||
} from "../fixture/fixture"
|
} from "../fixture/fixture"
|
||||||
import { testEffect } from "../lib/effect"
|
import { testEffect } from "../lib/effect"
|
||||||
|
import { githubBase } from "../fixture/repository"
|
||||||
import { Reference } from "@/reference"
|
import { Reference } from "@/reference"
|
||||||
import { RepositoryCache } from "@opencode-ai/core/repository-cache"
|
import { RepositoryCache } from "@opencode-ai/core/repository-cache"
|
||||||
|
|
||||||
|
|
@ -97,20 +98,6 @@ const fail = Effect.fn("ReadToolTest.fail")(function* (
|
||||||
const full = (p: string) => (process.platform === "win32" ? Filesystem.normalizePath(p) : p)
|
const full = (p: string) => (process.platform === "win32" ? Filesystem.normalizePath(p) : p)
|
||||||
const glob = (p: string) =>
|
const glob = (p: string) =>
|
||||||
process.platform === "win32" ? Filesystem.normalizePathPattern(p) : p.replaceAll("\\", "/")
|
process.platform === "win32" ? Filesystem.normalizePathPattern(p) : p.replaceAll("\\", "/")
|
||||||
const githubBase = <A, E, R>(url: string, self: Effect.Effect<A, E, R>) =>
|
|
||||||
Effect.acquireUseRelease(
|
|
||||||
Effect.sync(() => {
|
|
||||||
const previous = process.env.OPENCODE_REPO_CLONE_GITHUB_BASE_URL
|
|
||||||
process.env.OPENCODE_REPO_CLONE_GITHUB_BASE_URL = url
|
|
||||||
return previous
|
|
||||||
}),
|
|
||||||
() => self,
|
|
||||||
(previous) =>
|
|
||||||
Effect.sync(() => {
|
|
||||||
if (previous) process.env.OPENCODE_REPO_CLONE_GITHUB_BASE_URL = previous
|
|
||||||
else delete process.env.OPENCODE_REPO_CLONE_GITHUB_BASE_URL
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
const git = Effect.fn("ReadToolTest.git")(function* (cwd: string, args: string[]) {
|
const git = Effect.fn("ReadToolTest.git")(function* (cwd: string, args: string[]) {
|
||||||
return yield* Effect.promise(async () => {
|
return yield* Effect.promise(async () => {
|
||||||
const proc = Bun.spawn(["git", ...args], {
|
const proc = Bun.spawn(["git", ...args], {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue