summaryrefslogtreecommitdiffhomepage
path: root/packages/core
diff options
context:
space:
mode:
authorKit Langton <[email protected]>2026-04-30 11:48:13 -0400
committerGitHub <[email protected]>2026-04-30 11:48:13 -0400
commit65c15afe9f78f2b0d2f400e94fab3194e81c77cc (patch)
treedcbd0be583beeecf19d72231f7aef2991b2c78a5 /packages/core
parent8f57a2a46225109fbd1f74e545e22a9378f777b4 (diff)
downloadopencode-65c15afe9f78f2b0d2f400e94fab3194e81c77cc.tar.gz
opencode-65c15afe9f78f2b0d2f400e94fab3194e81c77cc.zip
test: use testEffect for instruction tests (#25046)
Diffstat (limited to 'packages/core')
-rw-r--r--packages/core/src/global.ts32
-rw-r--r--packages/core/test/fixture/effect-flock-worker.ts25
-rw-r--r--packages/core/test/util/effect-flock.test.ts21
3 files changed, 41 insertions, 37 deletions
diff --git a/packages/core/src/global.ts b/packages/core/src/global.ts
index 0c83e3a1f..42e0f1030 100644
--- a/packages/core/src/global.ts
+++ b/packages/core/src/global.ts
@@ -4,6 +4,7 @@ import { xdgData, xdgCache, xdgConfig, xdgState } from "xdg-basedir"
import os from "os"
import { Context, Effect, Layer } from "effect"
import { Flock } from "./util/flock"
+import { Flag } from "./flag/flag"
const app = "opencode"
const data = path.join(xdgData!, app)
@@ -47,19 +48,28 @@ export interface Interface {
readonly log: string
}
+export function make(input: Partial<Interface> = {}): Interface {
+ return {
+ home: Path.home,
+ data: Path.data,
+ cache: Path.cache,
+ config: Flag.OPENCODE_CONFIG_DIR ?? Path.config,
+ state: Path.state,
+ bin: Path.bin,
+ log: Path.log,
+ ...input,
+ }
+}
+
export const layer = Layer.effect(
Service,
- Effect.gen(function* () {
- return Service.of({
- home: Path.home,
- data: Path.data,
- cache: Path.cache,
- config: Path.config,
- state: Path.state,
- bin: Path.bin,
- log: Path.log,
- })
- }),
+ Effect.sync(() => Service.of(make())),
)
+export const layerWith = (input: Partial<Interface>) =>
+ Layer.effect(
+ Service,
+ Effect.sync(() => Service.of(make(input))),
+ )
+
export * as Global from "./global"
diff --git a/packages/core/test/fixture/effect-flock-worker.ts b/packages/core/test/fixture/effect-flock-worker.ts
index 3dc3ee2c8..c442a62cf 100644
--- a/packages/core/test/fixture/effect-flock-worker.ts
+++ b/packages/core/test/fixture/effect-flock-worker.ts
@@ -18,20 +18,17 @@ function sleep(ms: number) {
return new Promise<void>((resolve) => setTimeout(resolve, ms))
}
-const msg: Msg = JSON.parse(process.argv[2]!)
-
-const testGlobal = Layer.succeed(
- Global.Service,
- Global.Service.of({
- home: os.homedir(),
- data: os.tmpdir(),
- cache: os.tmpdir(),
- config: os.tmpdir(),
- state: os.tmpdir(),
- bin: os.tmpdir(),
- log: os.tmpdir(),
- }),
-)
+const msg: Msg = JSON.parse(process.argv[2])
+
+const testGlobal = Global.layerWith({
+ home: os.homedir(),
+ data: os.tmpdir(),
+ cache: os.tmpdir(),
+ config: os.tmpdir(),
+ state: os.tmpdir(),
+ bin: os.tmpdir(),
+ log: os.tmpdir(),
+})
const testLayer = EffectFlock.layer.pipe(Layer.provide(testGlobal), Layer.provide(AppFileSystem.defaultLayer))
diff --git a/packages/core/test/util/effect-flock.test.ts b/packages/core/test/util/effect-flock.test.ts
index 9e8bc24ac..76cee4f8e 100644
--- a/packages/core/test/util/effect-flock.test.ts
+++ b/packages/core/test/util/effect-flock.test.ts
@@ -93,18 +93,15 @@ async function waitForFile(file: string, timeout = 3_000) {
// Test layer
// ---------------------------------------------------------------------------
-const testGlobal = Layer.succeed(
- Global.Service,
- Global.Service.of({
- home: os.homedir(),
- data: os.tmpdir(),
- cache: os.tmpdir(),
- config: os.tmpdir(),
- state: os.tmpdir(),
- bin: os.tmpdir(),
- log: os.tmpdir(),
- }),
-)
+const testGlobal = Global.layerWith({
+ home: os.homedir(),
+ data: os.tmpdir(),
+ cache: os.tmpdir(),
+ config: os.tmpdir(),
+ state: os.tmpdir(),
+ bin: os.tmpdir(),
+ log: os.tmpdir(),
+})
const testLayer = EffectFlock.layer.pipe(Layer.provide(testGlobal), Layer.provide(AppFileSystem.defaultLayer))