diff --git a/packages/opencode/src/reference.ts b/packages/opencode/src/reference.ts
index cb9df487ea2..4dd5c4780e1 100644
--- a/packages/opencode/src/reference.ts
+++ b/packages/opencode/src/reference.ts
@@ -93,9 +93,7 @@ export const layer = Layer.effect(
return Service.of({
init: Effect.fn("Reference.init")(function* () {
- yield* InstanceState.get(state)
- // 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)
+ yield* ensure().pipe(Effect.forkIn(scope), Effect.asVoid)
}),
list: Effect.fn("Reference.list")(function* () {
return yield* InstanceState.useEffect(state, (service) => service.list())
diff --git a/packages/opencode/test/fixture/repository.ts b/packages/opencode/test/fixture/repository.ts
new file mode 100644
index 00000000000..f9d1042fc54
--- /dev/null
+++ b/packages/opencode/test/fixture/repository.ts
@@ -0,0 +1,20 @@
+import { Effect, Semaphore } from "effect"
+
+const lock = Semaphore.makeUnsafe(1)
+
+export const githubBase = (url: string, self: Effect.Effect) =>
+ 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
+ }),
+ ),
+ )
diff --git a/packages/opencode/test/reference/reference.test.ts b/packages/opencode/test/reference/reference.test.ts
index 907d7d1a3f8..b7645b83d2a 100644
--- a/packages/opencode/test/reference/reference.test.ts
+++ b/packages/opencode/test/reference/reference.test.ts
@@ -1,6 +1,5 @@
import { afterEach, describe, expect } from "bun:test"
import path from "path"
-import { pathToFileURL } from "url"
import { Effect, Layer } from "effect"
import { FSUtil } from "@opencode-ai/core/fs-util"
import { CrossSpawnSpawner } from "@opencode-ai/core/cross-spawn-spawner"
@@ -12,6 +11,7 @@ import { Git } from "../../src/git"
import { Reference } from "../../src/reference"
import { RepositoryCache } from "@opencode-ai/core/repository-cache"
import { disposeAllInstances, provideTmpdirInstance, tmpdirScoped } from "../fixture/fixture"
+import { githubBase } from "../fixture/repository"
import { testEffect } from "../lib/effect"
afterEach(async () => {
@@ -32,21 +32,6 @@ const references = testEffect(
),
)
-const githubBase = (url: string, self: Effect.Effect) =>
- 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 = (self: Effect.Effect) =>
Effect.acquireUseRelease(
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", () =>
Effect.gen(function* () {
const root = path.resolve("opencode-reference-root")
diff --git a/packages/opencode/test/tool/glob.test.ts b/packages/opencode/test/tool/glob.test.ts
index 757b6648fc1..fc6463edb81 100644
--- a/packages/opencode/test/tool/glob.test.ts
+++ b/packages/opencode/test/tool/glob.test.ts
@@ -12,6 +12,7 @@ import { Truncate } from "@/tool/truncate"
import { Agent } from "../../src/agent/agent"
import { TestInstance, tmpdirScoped } from "../fixture/fixture"
import { testEffect } from "../lib/effect"
+import { githubBase } from "../fixture/repository"
import { Reference } from "@/reference"
import { RepositoryCache } from "@opencode-ai/core/repository-cache"
import { Config } from "@/config/config"
@@ -61,21 +62,6 @@ const asks = () => {
}
}
-const githubBase = (url: string, self: Effect.Effect) =>
- 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[]) {
return yield* Effect.promise(async () => {
const proc = Bun.spawn(["git", ...args], {
diff --git a/packages/opencode/test/tool/grep.test.ts b/packages/opencode/test/tool/grep.test.ts
index 525ffb0fc1a..0435a6fff88 100644
--- a/packages/opencode/test/tool/grep.test.ts
+++ b/packages/opencode/test/tool/grep.test.ts
@@ -14,6 +14,7 @@ import { Agent } from "../../src/agent/agent"
import { Ripgrep } from "@opencode-ai/core/filesystem/ripgrep"
import { FSUtil } from "@opencode-ai/core/fs-util"
import { testEffect } from "../lib/effect"
+import { githubBase } from "../fixture/repository"
import { Reference } from "@/reference"
import { RepositoryCache } from "@opencode-ai/core/repository-cache"
import { Permission } from "../../src/permission"
@@ -54,21 +55,6 @@ const ctx = {
const root = path.join(__dirname, "../..")
const full = (p: string) => (process.platform === "win32" ? Filesystem.normalizePath(p) : p)
-const githubBase = (url: string, self: Effect.Effect) =>
- 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[]) {
return yield* Effect.promise(async () => {
const proc = Bun.spawn(["git", ...args], {
diff --git a/packages/opencode/test/tool/read.test.ts b/packages/opencode/test/tool/read.test.ts
index c54329621b9..5a3b0c519ad 100644
--- a/packages/opencode/test/tool/read.test.ts
+++ b/packages/opencode/test/tool/read.test.ts
@@ -24,6 +24,7 @@ import {
tmpdirScoped,
} from "../fixture/fixture"
import { testEffect } from "../lib/effect"
+import { githubBase } from "../fixture/repository"
import { Reference } from "@/reference"
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 glob = (p: string) =>
process.platform === "win32" ? Filesystem.normalizePathPattern(p) : p.replaceAll("\\", "/")
-const githubBase = (url: string, self: Effect.Effect) =>
- 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[]) {
return yield* Effect.promise(async () => {
const proc = Bun.spawn(["git", ...args], {