From 0440bd96be5bafb6b6d5f915e256290afc6340c6 Mon Sep 17 00:00:00 2001 From: Kit Langton Date: Thu, 27 Aug 2026 18:47:56 -0400 Subject: [PATCH] refactor(core): simplify Effect test setup (#45446) --- packages/core/test/instructions/index.test.ts | 116 ++++++++---------- .../core/test/session-instructions.test.ts | 12 +- 2 files changed, 59 insertions(+), 69 deletions(-) diff --git a/packages/core/test/instructions/index.test.ts b/packages/core/test/instructions/index.test.ts index 8c1b1f86053..e54483d6eaa 100644 --- a/packages/core/test/instructions/index.test.ts +++ b/packages/core/test/instructions/index.test.ts @@ -1,4 +1,4 @@ -import { describe, expect } from "bun:test" +import { describe, expect, test } from "bun:test" import { Cause, Effect, Exit, Option, Schema } from "effect" import { Instructions } from "@opencode-ai/core/instructions/index" import { it } from "../lib/effect" @@ -177,73 +177,63 @@ describe("Instructions", () => { }), ) - it.effect("hashes objects independently of key order", () => - Effect.sync(() => { - expect(Instructions.hash({ a: 1, b: { x: true, y: false } })).toBe( - Instructions.hash({ b: { y: false, x: true }, a: 1 }), - ) - }), - ) + test("hashes objects independently of key order", () => { + expect(Instructions.hash({ a: 1, b: { x: true, y: false } })).toBe( + Instructions.hash({ b: { y: false, x: true }, a: 1 }), + ) + }) - it.effect("renders sources in composition order", () => - Effect.sync(() => { - const instructions = Instructions.combine([ - source({ key: "core/date", value: "date" }), - source({ key: "core/location", value: "location" }), - ]) + test("renders sources in composition order", () => { + const instructions = Instructions.combine([ + source({ key: "core/date", value: "date" }), + source({ key: "core/location", value: "location" }), + ]) - expect(Instructions.renderInitial(instructions, { "core/date": "date", "core/location": "location" })).toBe( - "date\n\nlocation", - ) - }), - ) + expect(Instructions.renderInitial(instructions, { "core/date": "date", "core/location": "location" })).toBe( + "date\n\nlocation", + ) + }) - it.effect("rejects duplicate source keys", () => - Effect.sync(() => { - expect(() => - Instructions.combine([source({ key: "core/date", value: "one" }), source({ key: "core/date", value: "two" })]), - ).toThrow(new Instructions.DuplicateKeyError({ key: key("core/date") })) - }), - ) + test("rejects duplicate source keys", () => { + expect(() => + Instructions.combine([source({ key: "core/date", value: "one" }), source({ key: "core/date", value: "two" })]), + ).toThrow(new Instructions.DuplicateKeyError({ key: key("core/date") })) + }) - it.effect("rejects empty model-visible renderings", () => - Effect.sync(() => { - const instructions = source({ key: "core/empty", value: "value", initial: () => "" }) + test("rejects empty model-visible renderings", () => { + const instructions = source({ key: "core/empty", value: "value", initial: () => "" }) - expect(() => Instructions.renderInitial(instructions, { "core/empty": "value" })).toThrow( - "Instruction source core/empty rendered an empty initial", - ) - }), - ) + expect(() => Instructions.renderInitial(instructions, { "core/empty": "value" })).toThrow( + "Instruction source core/empty rendered an empty initial", + ) + }) - it.effect("diffs list values by key", () => - Effect.sync(() => { - const previous = [ - { name: "effect", description: "Build with Effect" }, - { name: "retired", description: "Old" }, - ] - const current = [ - { name: "effect", description: "Build with Effect v4" }, - { name: "writing", description: "Write prose" }, - ] + test("diffs list values by key", () => { + const previous = [ + { name: "effect", description: "Build with Effect" }, + { name: "retired", description: "Old" }, + ] + const current = [ + { name: "effect", description: "Build with Effect v4" }, + { name: "writing", description: "Write prose" }, + ] - expect( - Instructions.diffByKey( - previous, - current, - (value) => value.name, - (before, after) => before.description !== after.description, - ), - ).toEqual({ - added: [{ name: "writing", description: "Write prose" }], - removed: [{ name: "retired", description: "Old" }], - changed: [ - { - previous: { name: "effect", description: "Build with Effect" }, - current: { name: "effect", description: "Build with Effect v4" }, - }, - ], - }) - }), - ) + expect( + Instructions.diffByKey( + previous, + current, + (value) => value.name, + (before, after) => before.description !== after.description, + ), + ).toEqual({ + added: [{ name: "writing", description: "Write prose" }], + removed: [{ name: "retired", description: "Old" }], + changed: [ + { + previous: { name: "effect", description: "Build with Effect" }, + current: { name: "effect", description: "Build with Effect v4" }, + }, + ], + }) + }) }) diff --git a/packages/core/test/session-instructions.test.ts b/packages/core/test/session-instructions.test.ts index 0d7a2b99ae6..8035e4e08f7 100644 --- a/packages/core/test/session-instructions.test.ts +++ b/packages/core/test/session-instructions.test.ts @@ -119,7 +119,7 @@ const seedSynthetic = (sessionID: Session.ID, paths: string[]) => }) describe("SessionInstructions", () => { - it.effect("injects AGENTS.md files above a read, excludes the Location root, and dedups across reads", () => + it.live("injects AGENTS.md files above a read, excludes the Location root, and dedups across reads", () => Effect.gen(function* () { const location = yield* Location.Service const dir = location.directory @@ -169,7 +169,7 @@ describe("SessionInstructions", () => { }), ) - it.effect("does not re-inject paths already recorded in durable session history", () => + it.live("does not re-inject paths already recorded in durable session history", () => Effect.gen(function* () { const location = yield* Location.Service const dir = location.directory @@ -196,7 +196,7 @@ describe("SessionInstructions", () => { }), ) - it.effect( + it.live( "discovers AGENTS.md on a directory listing, including the listed directory's own, and dedups with a later file read", () => Effect.gen(function* () { @@ -232,7 +232,7 @@ describe("SessionInstructions", () => { }), ) - it.effect("re-injects nested instructions dropped from history by compaction", () => + it.live("re-injects nested instructions dropped from history by compaction", () => Effect.gen(function* () { const location = yield* Location.Service const dir = location.directory @@ -263,7 +263,7 @@ describe("SessionInstructions", () => { }), ) - it.effect("listing the Location root directory injects no instructions", () => + it.live("listing the Location root directory injects no instructions", () => Effect.gen(function* () { const location = yield* Location.Service const dir = location.directory @@ -285,7 +285,7 @@ describe("SessionInstructions", () => { }), ) - it.effect("loads instructions directly without a read", () => + it.live("loads instructions directly without a read", () => Effect.gen(function* () { const location = yield* Location.Service const dir = location.directory