Files
anomalyco_opencode/packages/opencode/test/session/system.test.ts
T
Kit Langton 30edf5aa42 refactor(session): convert SystemPrompt facade calls to effectful versions
Replace `Effect.promise(() => SystemPrompt.skills(...))` and
`Effect.promise(() => SystemPrompt.environment(...))` with direct
effectful calls. `environment` is now a plain sync function (the async
Ripgrep.tree call was dead code behind `&& false`). `skills` is now an
`Effect.fn` that takes the Skill service as a parameter.
2026-04-10 23:40:14 -04:00

67 lines
2.0 KiB
TypeScript

import { describe, expect, test } from "bun:test"
import path from "path"
import { Effect } from "effect"
import { Agent } from "../../src/agent/agent"
import { Instance } from "../../src/project/instance"
import { Skill } from "../../src/skill"
import { SystemPrompt } from "../../src/session/system"
import { tmpdir } from "../fixture/fixture"
describe("session.system", () => {
test("skills output is sorted by name and stable across calls", async () => {
await using tmp = await tmpdir({
git: true,
init: async (dir) => {
for (const [name, description] of [
["zeta-skill", "Zeta skill."],
["alpha-skill", "Alpha skill."],
["middle-skill", "Middle skill."],
]) {
const skillDir = path.join(dir, ".opencode", "skill", name)
await Bun.write(
path.join(skillDir, "SKILL.md"),
`---
name: ${name}
description: ${description}
---
# ${name}
`,
)
}
},
})
const home = process.env.OPENCODE_TEST_HOME
process.env.OPENCODE_TEST_HOME = tmp.path
try {
await Instance.provide({
directory: tmp.path,
fn: async () => {
const build = await Agent.get("build")
const runSkills = Effect.gen(function* () {
const svc = yield* Skill.Service
return yield* SystemPrompt.skills(build!, svc)
}).pipe(Effect.provide(Skill.defaultLayer))
const first = await Effect.runPromise(runSkills)
const second = await Effect.runPromise(runSkills)
expect(first).toBe(second)
const alpha = first!.indexOf("<name>alpha-skill</name>")
const middle = first!.indexOf("<name>middle-skill</name>")
const zeta = first!.indexOf("<name>zeta-skill</name>")
expect(alpha).toBeGreaterThan(-1)
expect(middle).toBeGreaterThan(alpha)
expect(zeta).toBeGreaterThan(middle)
},
})
} finally {
process.env.OPENCODE_TEST_HOME = home
}
})
})