From 980fde146c0889172e7643a6307a6e3b1c2e800d Mon Sep 17 00:00:00 2001 From: qkhalk Date: Wed, 19 Aug 2026 08:44:41 +0700 Subject: [PATCH 1/7] feat(opencode): add `oc kit` CLI (list, validate) on Phase 1 domain model Implement OC Kit Phase 2 as a strictly additive CLI surface. `oc kit list` prints installed kits (id/name/version + declaration counts) sourced from Registry.Service; `oc kit validate ` loads a manifest and checks its declaration structure via the shared validator. No live execution path. - src/ockit/validator.ts: pure validateKit over a decoded Kit (every workflow step must reference a declared skill; per-kind ids resolve through Resolver). - src/ockit/cli.ts: OCKitCommand via effectCmd; provides Registry.node explicitly (it is not in AppRuntime) with instance: true. - register OCKitCommand in src/index.ts; re-export OCKitCli from ockit/index.ts. - tests: validator.test.ts (pure) + cli.test.ts (mocked Registry.Service). CI-first: not run locally; gated by `bun turbo test` + typecheck in CI. --- packages/opencode/src/index.ts | 2 + packages/opencode/src/ockit/cli.ts | 119 +++++++++++++++++ packages/opencode/src/ockit/index.ts | 1 + packages/opencode/src/ockit/validator.ts | 78 +++++++++++ packages/opencode/test/ockit/cli.test.ts | 125 ++++++++++++++++++ .../opencode/test/ockit/validator.test.ts | 64 +++++++++ 6 files changed, 389 insertions(+) create mode 100644 packages/opencode/src/ockit/cli.ts create mode 100644 packages/opencode/src/ockit/validator.ts create mode 100644 packages/opencode/test/ockit/cli.test.ts create mode 100644 packages/opencode/test/ockit/validator.test.ts diff --git a/packages/opencode/src/index.ts b/packages/opencode/src/index.ts index 13540a73a3..d06f7895c3 100644 --- a/packages/opencode/src/index.ts +++ b/packages/opencode/src/index.ts @@ -28,6 +28,7 @@ import { SessionCommand } from "./cli/cmd/session" import { DbCommand } from "./cli/cmd/db" import { errorMessage } from "./util/error" import { PluginCommand } from "./cli/cmd/plug" +import { OCKitCommand } from "./ockit/cli" import { Heap } from "./cli/heap" const args = hideBin(process.argv) @@ -100,6 +101,7 @@ const cli = yargs(args) .command(PrCommand) .command(SessionCommand) .command(PluginCommand) + .command(OCKitCommand) .command(DbCommand) .fail((msg, err) => { if ( diff --git a/packages/opencode/src/ockit/cli.ts b/packages/opencode/src/ockit/cli.ts new file mode 100644 index 0000000000..b4861946b3 --- /dev/null +++ b/packages/opencode/src/ockit/cli.ts @@ -0,0 +1,119 @@ +// OC Kit CLI (`oc kit list` / `oc kit validate`). Surfaces the Phase 1 domain +// model: `list` prints installed kits discovered through `Registry.Service`, +// `validate` loads a kit's manifest (from a directory or by id) and checks its +// declaration structure via the validator. No live execution — strictly a +// read/validate surface over the already-landed registry/manifest/resolver. +// +// The two command bodies are exported as standalone Effects (`listKits`, +// `validateTarget`) so they can be unit-tested with a mocked `Registry.Service` +// without going through yargs. The `effectCmd` wrappers only add the +// `registryLayer` provision (the registry is a LayerNode that is NOT part of +// AppRuntime) and the yargs command tree. + +import type { Argv } from "yargs" +import { EOL } from "os" +import { Effect } from "effect" +import { cmd } from "../cli/cmd/cmd" +import { effectCmd, fail } from "../cli/effect-cmd" +import { LayerNode } from "@opencode-ai/core/effect/layer-node" +import { FSUtil } from "@opencode-ai/core/fs-util" +import { Service as Registry, node as registryNode, NotFoundError } from "./registry" +import { loadManifest } from "./manifest" +import { validateKit } from "./validator" +import { Kit } from "./types" + +const registryLayer = LayerNode.compile(registryNode) + +/** Count how many of each declaration a kit carries (for compact `list` rows). */ +function counts(kit: Kit) { + return { + skills: kit.skills?.length ?? 0, + agents: kit.agents?.length ?? 0, + workflows: kit.workflows?.length ?? 0, + hooks: kit.hooks?.length ?? 0, + } +} + +/** Print all installed kits. Requires `Registry.Service`. */ +export const listKits = Effect.fn("Cli.kit.list")(function* () { + const registry = yield* Registry + const kits = yield* registry.all() + if (kits.length === 0) { + process.stdout.write(`No OC Kit kits installed.` + EOL) + return + } + for (const kit of kits.toSorted((a, b) => a.id.localeCompare(b.id))) { + const c = counts(kit) + process.stdout.write(`${kit.id} (${kit.name}@${kit.version})` + EOL) + process.stdout.write(` skills:${c.skills} agents:${c.agents} workflows:${c.workflows} hooks:${c.hooks}` + EOL) + } +}) + +export interface ValidateArgs { + readonly target: string +} + +/** Validate a kit by directory (prefers a manifest file) or by installed id. */ +export const validateTarget = Effect.fn("Cli.kit.validate")(function* (args: ValidateArgs) { + const fs = yield* FSUtil.Service + const registry = yield* Registry + + const isDir = yield* fs.isDir(args.target) + const kit = isDir + ? yield* loadManifest(args.target).pipe( + Effect.catchTag("OCKitManifestError", (err) => + fail( + `Invalid kit manifest in "${args.target}": ${err.message ?? "unable to read manifest"}`, + ), + ), + ) + : yield* registry.require(args.target).pipe( + Effect.catchTag("OCKit.NotFoundError", (err: NotFoundError) => + fail( + `No kit "${err.id}" installed. Available: ${err.available.length > 0 ? err.available.join(", ") : "(none)"}`, + ), + ), + ) + + const result = yield* validateKit(kit) + if (!result.ok) { + for (const issue of result.issues) { + process.stderr.write(` ✗ ${issue.kind} "${issue.id}": ${issue.message}` + EOL) + } + return yield* fail(`Kit "${kit.id}" is invalid (${result.issues.length} issue(s)).`) + } + + const c = counts(kit) + process.stdout.write( + `Kit "${kit.id}" (${kit.name}@${kit.version}) is valid — skills:${c.skills} agents:${c.agents} workflows:${c.workflows} hooks:${c.hooks}` + + EOL, + ) +}) + +const ListCommand = effectCmd({ + command: "list", + describe: "list installed OC Kit kits", + handler: () => listKits.pipe(Effect.provide(registryLayer)), +}) + +const ValidateCommand = effectCmd({ + command: "validate ", + describe: "validate an OC Kit manifest by directory or id", + builder: (yargs: Argv) => + yargs.positional("target", { + type: "string", + description: "kit directory (contains kit.json/kit.yaml) or installed kit id", + demandOption: true, + }), + handler: (args) => validateTarget({ target: args.target }).pipe(Effect.provide(registryLayer)), +}) + +export const OCKitCommand = cmd({ + command: "kit", + describe: "manage OC Kit workflows, skills, and agents", + builder: (yargs) => yargs.command(ListCommand).command(ValidateCommand).demandCommand(), + async handler() {}, +}) + +// Re-export the dependency node so `index.ts` can wire it without re-importing registry. +export { registryNode } diff --git a/packages/opencode/src/ockit/index.ts b/packages/opencode/src/ockit/index.ts index 4e9d252903..a7e4185800 100644 --- a/packages/opencode/src/ockit/index.ts +++ b/packages/opencode/src/ockit/index.ts @@ -29,3 +29,4 @@ export { } from "./types" export { Service as Registry, node as registryNode } from "./registry" +export * as OCKitCli from "./cli" diff --git a/packages/opencode/src/ockit/validator.ts b/packages/opencode/src/ockit/validator.ts new file mode 100644 index 0000000000..cb4f25792b --- /dev/null +++ b/packages/opencode/src/ockit/validator.ts @@ -0,0 +1,78 @@ +// OC Kit kit validator. Validates a typed `Kit` manifest against its own +// declarative structure: every workflow step must reference a skill declared by +// the kit, and each skill/agent/workflow/hook must be internally well-formed. +// Pure — operates on the already-decoded `Kit` schema, no disk I/O — so it is +// trivially unit-testable and reused by the `oc kit validate` CLI command. + +import { Effect } from "effect" +import { Kit, KitSkill, KitAgent, Workflow, KitHook } from "./types" +import { indexKit, resolveFromKit } from "./resolver" + +export interface ValidationIssue { + readonly kind: "skill" | "agent" | "workflow" | "hook" + readonly id: string + readonly message: string +} + +export type ValidationResult = { readonly ok: true } | { readonly ok: false; readonly issues: ValidationIssue[] } + +/** + * Validate a decoded kit manifest. Returns `ok` when every declared id resolves + * and every workflow step references a declared skill; otherwise lists the + * typed issues (each carries a `kind` + `id` for precise surfacing). + */ +export const validateKit = Effect.fn("OCKit.validate")(function* (kit: Kit) { + const index = indexKit(kit) + const issues: ValidationIssue[] = [] + + // Every skill/agent/workflow/hook id must be present (the index itself is the + // source of truth — a missing entry means the kind array was malformed). + for (const skill of kit.skills ?? []) { + try { + resolveFromKit(index, "skills", skill.id) + } catch { + issues.push({ kind: "skill", id: skill.id, message: `undeclared skill "${skill.id}"` }) + } + } + for (const agent of kit.agents ?? []) { + try { + resolveFromKit(index, "agents", agent.id) + } catch { + issues.push({ kind: "agent", id: agent.id, message: `undeclared agent "${agent.id}"` }) + } + } + for (const workflow of kit.workflows ?? []) { + try { + resolveFromKit(index, "workflows", workflow.id) + } catch { + issues.push({ kind: "workflow", id: workflow.id, message: `undeclared workflow "${workflow.id}"` }) + } + } + for (const hook of kit.hooks ?? []) { + try { + resolveFromKit(index, "hooks", hook.event) + } catch { + issues.push({ kind: "hook", id: hook.event, message: `undeclared hook "${hook.event}"` }) + } + } + + // Each workflow step must reference a declared skill. + for (const workflow of kit.workflows ?? []) { + for (const step of workflow.steps) { + if (index.skills.get(step.skill) === undefined) { + issues.push({ + kind: "workflow", + id: workflow.id, + message: `workflow "${workflow.id}" references undeclared skill "${step.skill}"`, + }) + } + } + } + + if (issues.length > 0) return { ok: false, issues } + return { ok: true } +}) + +// Re-export the consumed schemas so callers build fixtures without reaching into +// `./types` directly. Not strictly required, but keeps the validator self-contained. +export { Kit, KitSkill, KitAgent, Workflow, KitHook } diff --git a/packages/opencode/test/ockit/cli.test.ts b/packages/opencode/test/ockit/cli.test.ts new file mode 100644 index 0000000000..7c59a4ed81 --- /dev/null +++ b/packages/opencode/test/ockit/cli.test.ts @@ -0,0 +1,125 @@ +import { afterEach, beforeEach, describe, expect, spyOn } from "bun:test" +import { Effect, Layer } from "effect" +import { FSUtil } from "@opencode-ai/core/fs-util" +import { NotFoundError, Service as Registry } from "../../src/ockit/registry" +import { listKits, validateTarget } from "../../src/ockit/cli" +import type { Kit } from "../../src/ockit/types" + +const ENGINEER: Kit = { + id: "engineer", + name: "OC Engineer Kit", + version: "1.0.0", + runtime: "opencode", + skills: [{ id: "plan", description: "Plan" }], + workflows: [{ id: "ship", steps: [{ skill: "plan" }] }], +} + +const DESIGNER: Kit = { + id: "designer", + name: "Designer Kit", + version: "0.4.0", + skills: [{ id: "draw", description: "Draw" }], + hooks: [{ event: "post-edit", command: "echo hi" }], +} + +function registryLayer(kits: Kit[]) { + return Layer.succeed( + Registry, + Registry.of({ + all: Effect.succeed(kits), + get: Effect.fn(function* (id: string) { + return kits.find((k) => k.id === id) + }), + require: Effect.fn(function* (id: string) { + const kit = kits.find((k) => k.id === id) + if (kit) return kit + return yield* new NotFoundError({ id, available: kits.map((k) => k.id).toSorted() }) + }), + dirs: Effect.succeed([]), + }), + ) +} + +// FSUtil mock that treats every path as "not a directory" so validateTarget +// routes through the registry (by-id) branch and never touches disk. +const fsLayer = Layer.succeed( + FSUtil.Service, + FSUtil.Service.of({ + isDir: () => Effect.succeed(false), + } as unknown as FSUtil.Interface), +) + +let writes: string[] +let stdoutSpy: ReturnType +let stderrSpy: ReturnType + +beforeEach(() => { + writes = [] + stdoutSpy = spyOn(process.stdout, "write").mockImplementation((chunk: string | Uint8Array) => { + writes.push(String(chunk)) + return true + }) + stderrSpy = spyOn(process.stderr, "write").mockImplementation(() => true) +}) + +afterEach(() => { + stdoutSpy.mockRestore() + stderrSpy.mockRestore() +}) + +function out() { + return writes.join("") +} + +describe("oc kit list", () => { + it("prints every installed kit with declaration counts", async () => { + await Effect.runPromise(listKits.pipe(Effect.provide(registryLayer([ENGINEER, DESIGNER])))) + const text = out() + expect(text).toContain("engineer (OC Engineer Kit@1.0.0)") + expect(text).toContain("designer (Designer Kit@0.4.0)") + expect(text).toContain("skills:1 agents:0 workflows:1 hooks:0") + expect(text).toContain("skills:1 agents:0 workflows:0 hooks:1") + }) + + it("reports when no kits are installed", async () => { + await Effect.runPromise(listKits.pipe(Effect.provide(registryLayer([])))) + expect(out()).toContain("No OC Kit kits installed.") + }) +}) + +describe("oc kit validate", () => { + it("passes a valid installed kit", async () => { + await Effect.runPromise( + validateTarget({ target: "engineer" }).pipe(Effect.provide(registryLayer([ENGINEER, DESIGNER])), Effect.provide(fsLayer)), + ) + expect(out()).toContain('Kit "engineer" (OC Engineer Kit@1.0.0) is valid') + }) + + it("fails when the kit id is not installed", async () => { + const result = await Effect.runPromiseExit( + validateTarget({ target: "missing" }).pipe( + Effect.provide(registryLayer([ENGINEER])), + Effect.provide(fsLayer), + ), + ) + expect(result._tag).toBe("Failure") + expect(out()).toContain('No kit "missing" installed.') + }) + + it("reports validation issues for a broken installed kit", async () => { + const broken: Kit = { + id: "broken", + name: "Broken Kit", + version: "1.0.0", + workflows: [{ id: "ship", steps: [{ skill: "ghost" }] }], + } + const result = await Effect.runPromiseExit( + validateTarget({ target: "broken" }).pipe( + Effect.provide(registryLayer([broken])), + Effect.provide(fsLayer), + ), + ) + expect(result._tag).toBe("Failure") + expect(out()).toContain('undeclared skill "ghost"') + }) +}) diff --git a/packages/opencode/test/ockit/validator.test.ts b/packages/opencode/test/ockit/validator.test.ts new file mode 100644 index 0000000000..516dfb94b5 --- /dev/null +++ b/packages/opencode/test/ockit/validator.test.ts @@ -0,0 +1,64 @@ +import { describe, expect } from "bun:test" +import { Effect } from "effect" +import { validateKit } from "../../src/ockit/validator" +import type { Kit } from "../../src/ockit/types" + +const VALID_KIT: Kit = { + id: "engineer", + name: "OC Engineer Kit", + version: "1.0.0", + runtime: "opencode", + skills: [{ id: "plan", description: "Create an implementation plan" }], + agents: [{ id: "planner", role: "plans" }], + workflows: [ + { id: "ship", steps: [{ skill: "plan" }] }, + ], + hooks: [{ event: "post-edit", command: "echo ok" }], +} + +describe("ockit validator", () => { + it("passes a well-formed kit", async () => { + const result = await Effect.runPromise(validateKit(VALID_KIT)) + expect(result.ok).toBe(true) + }) + + it("flags a workflow step that references an undeclared skill", async () => { + const broken: Kit = { + ...VALID_KIT, + workflows: [{ id: "ship", steps: [{ skill: "missing-skill" }] }], + } + const result = await Effect.runPromise(validateKit(broken)) + expect(result.ok).toBe(false) + if (!result.ok) { + expect(result.issues).toHaveLength(1) + expect(result.issues[0]).toMatchObject({ kind: "workflow", id: "ship" }) + expect(result.issues[0].message).toContain("missing-skill") + } + }) + + it("flags an undeclared skill in the skills array", async () => { + // A skills entry whose id cannot be resolved by indexKit — exercises the + // per-kind resolution guard (e.g. a duplicate-id collision kept the first). + const result = await Effect.runPromise( + validateKit({ ...VALID_KIT, skills: [{ id: "plan" }, { id: "plan" }] }), + ) + if (!result.ok) { + expect(result.issues.some((i) => i.kind === "skill" && i.id === "plan")).toBe(true) + } else { + // duplicate id collapses to one entry; still valid structurally. + expect(result.ok).toBe(true) + } + }) + + it("flags a hook whose event is not declared", async () => { + const broken: Kit = { + ...VALID_KIT, + hooks: [{ event: "ghost-event", command: "echo nope" }], + } + const result = await Effect.runPromise(validateKit(broken)) + expect(result.ok).toBe(false) + if (!result.ok) { + expect(result.issues.some((i) => i.kind === "hook" && i.id === "ghost-event")).toBe(true) + } + }) +}) From 6d011837628f8bccc09385d88a98b88edca0133e Mon Sep 17 00:00:00 2001 From: qkhalk Date: Wed, 19 Aug 2026 09:19:02 +0700 Subject: [PATCH 2/7] fix(opencode): make ockit validator checks real and testable The previous per-kind loops validated each entry against an index built from the same array, so they could never flag an issue (dead code), and the "undeclared hook" test encoded a rule the validator cannot enforce. Replace with detectable checks: unique ids within each kind, every workflow step references a declared skill, every agent's skills reference declared skills, and every skill's backing agent references a declared agent. Update validator.test.ts to exercise those real checks. --- packages/opencode/src/ockit/validator.ts | 87 +++++++++++-------- .../opencode/test/ockit/validator.test.ts | 28 +++--- 2 files changed, 69 insertions(+), 46 deletions(-) diff --git a/packages/opencode/src/ockit/validator.ts b/packages/opencode/src/ockit/validator.ts index cb4f25792b..f5ef552389 100644 --- a/packages/opencode/src/ockit/validator.ts +++ b/packages/opencode/src/ockit/validator.ts @@ -1,12 +1,18 @@ // OC Kit kit validator. Validates a typed `Kit` manifest against its own -// declarative structure: every workflow step must reference a skill declared by -// the kit, and each skill/agent/workflow/hook must be internally well-formed. -// Pure — operates on the already-decoded `Kit` schema, no disk I/O — so it is -// trivially unit-testable and reused by the `oc kit validate` CLI command. +// declarative structure. Pure — operates on the already-decoded `Kit` schema, +// no disk I/O — so it is trivially unit-testable and reused by the +// `oc kit validate` CLI command. +// +// Checks performed: +// - unique ids within each kind (skills/agents/workflows/hooks); the index +// silently collapses duplicates, so the original array is checked directly. +// - every workflow step references a skill declared by the kit. +// - every agent's `skills` reference declared skills. +// - every skill's `agent` references a declared agent. import { Effect } from "effect" import { Kit, KitSkill, KitAgent, Workflow, KitHook } from "./types" -import { indexKit, resolveFromKit } from "./resolver" +import { indexKit } from "./resolver" export interface ValidationIssue { readonly kind: "skill" | "agent" | "workflow" | "hook" @@ -17,44 +23,29 @@ export interface ValidationIssue { export type ValidationResult = { readonly ok: true } | { readonly ok: false; readonly issues: ValidationIssue[] } /** - * Validate a decoded kit manifest. Returns `ok` when every declared id resolves - * and every workflow step references a declared skill; otherwise lists the - * typed issues (each carries a `kind` + `id` for precise surfacing). + * Validate a decoded kit manifest. Returns `ok` when every declared id is unique + * and every cross-reference resolves; otherwise lists the typed issues (each + * carries a `kind` + `id` for precise surfacing). */ export const validateKit = Effect.fn("OCKit.validate")(function* (kit: Kit) { const index = indexKit(kit) const issues: ValidationIssue[] = [] - // Every skill/agent/workflow/hook id must be present (the index itself is the - // source of truth — a missing entry means the kind array was malformed). - for (const skill of kit.skills ?? []) { - try { - resolveFromKit(index, "skills", skill.id) - } catch { - issues.push({ kind: "skill", id: skill.id, message: `undeclared skill "${skill.id}"` }) - } - } - for (const agent of kit.agents ?? []) { - try { - resolveFromKit(index, "agents", agent.id) - } catch { - issues.push({ kind: "agent", id: agent.id, message: `undeclared agent "${agent.id}"` }) - } - } - for (const workflow of kit.workflows ?? []) { - try { - resolveFromKit(index, "workflows", workflow.id) - } catch { - issues.push({ kind: "workflow", id: workflow.id, message: `undeclared workflow "${workflow.id}"` }) - } - } - for (const hook of kit.hooks ?? []) { - try { - resolveFromKit(index, "hooks", hook.event) - } catch { - issues.push({ kind: "hook", id: hook.event, message: `undeclared hook "${hook.event}"` }) + // Duplicate ids within a kind are silently collapsed by the index, so check + // the source arrays directly — a duplicate means a malformed manifest. + const checkUnique = (values: ReadonlyArray<{ readonly id: string }>, kind: ValidationIssue["kind"], label: string) => { + const seen = new Set() + for (const value of values) { + if (seen.has(value.id)) { + issues.push({ kind, id: value.id, message: `duplicate ${label} id "${value.id}"` }) + } + seen.add(value.id) } } + checkUnique(kit.skills ?? [], "skill", "skill") + checkUnique(kit.agents ?? [], "agent", "agent") + checkUnique(kit.workflows ?? [], "workflow", "workflow") + checkUnique(kit.hooks ?? [], "hook", "hook") // Each workflow step must reference a declared skill. for (const workflow of kit.workflows ?? []) { @@ -69,6 +60,30 @@ export const validateKit = Effect.fn("OCKit.validate")(function* (kit: Kit) { } } + // Each agent's declared skills must be declared by the kit. + for (const agent of kit.agents ?? []) { + for (const skillId of agent.skills ?? []) { + if (index.skills.get(skillId) === undefined) { + issues.push({ + kind: "agent", + id: agent.id, + message: `agent "${agent.id}" references undeclared skill "${skillId}"`, + }) + } + } + } + + // Each skill's backing agent must be declared by the kit. + for (const skill of kit.skills ?? []) { + if (skill.agent !== undefined && index.agents.get(skill.agent) === undefined) { + issues.push({ + kind: "skill", + id: skill.id, + message: `skill "${skill.id}" references undeclared agent "${skill.agent}"`, + }) + } + } + if (issues.length > 0) return { ok: false, issues } return { ok: true } }) diff --git a/packages/opencode/test/ockit/validator.test.ts b/packages/opencode/test/ockit/validator.test.ts index 516dfb94b5..bd337a8e71 100644 --- a/packages/opencode/test/ockit/validator.test.ts +++ b/packages/opencode/test/ockit/validator.test.ts @@ -9,7 +9,7 @@ const VALID_KIT: Kit = { version: "1.0.0", runtime: "opencode", skills: [{ id: "plan", description: "Create an implementation plan" }], - agents: [{ id: "planner", role: "plans" }], + agents: [{ id: "planner", role: "plans", skills: ["plan"] }], workflows: [ { id: "ship", steps: [{ skill: "plan" }] }, ], @@ -36,29 +36,37 @@ describe("ockit validator", () => { } }) - it("flags an undeclared skill in the skills array", async () => { - // A skills entry whose id cannot be resolved by indexKit — exercises the - // per-kind resolution guard (e.g. a duplicate-id collision kept the first). + it("flags a duplicate skill id", async () => { const result = await Effect.runPromise( validateKit({ ...VALID_KIT, skills: [{ id: "plan" }, { id: "plan" }] }), ) + expect(result.ok).toBe(false) if (!result.ok) { expect(result.issues.some((i) => i.kind === "skill" && i.id === "plan")).toBe(true) - } else { - // duplicate id collapses to one entry; still valid structurally. - expect(result.ok).toBe(true) } }) - it("flags a hook whose event is not declared", async () => { + it("flags an agent that references an undeclared skill", async () => { const broken: Kit = { ...VALID_KIT, - hooks: [{ event: "ghost-event", command: "echo nope" }], + agents: [{ id: "planner", role: "plans", skills: ["ghost-skill"] }], } const result = await Effect.runPromise(validateKit(broken)) expect(result.ok).toBe(false) if (!result.ok) { - expect(result.issues.some((i) => i.kind === "hook" && i.id === "ghost-event")).toBe(true) + expect(result.issues.some((i) => i.kind === "agent" && i.id === "planner")).toBe(true) + } + }) + + it("flags a skill that references an undeclared agent", async () => { + const broken: Kit = { + ...VALID_KIT, + skills: [{ id: "plan", description: "Plan", agent: "ghost-agent" }], + } + const result = await Effect.runPromise(validateKit(broken)) + expect(result.ok).toBe(false) + if (!result.ok) { + expect(result.issues.some((i) => i.kind === "skill" && i.id === "plan")).toBe(true) } }) }) From a53b1195f3d9f8286537b8d3b53d628cfced5647 Mon Sep 17 00:00:00 2001 From: qkhalk Date: Wed, 19 Aug 2026 15:11:05 +0700 Subject: [PATCH 3/7] fix(opencode): import `it` in ockit Phase 2 test files `validator.test.ts` and `cli.test.ts` used `it(...)` inside `describe` blocks but only imported `describe`/`expect`, so every test threw `ReferenceError: it is not defined` and the required `unit(linux)` job failed. Add `it` to the `bun:test` import in both files. --- packages/opencode/test/ockit/cli.test.ts | 2 +- packages/opencode/test/ockit/validator.test.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/opencode/test/ockit/cli.test.ts b/packages/opencode/test/ockit/cli.test.ts index 7c59a4ed81..e80b9b3c23 100644 --- a/packages/opencode/test/ockit/cli.test.ts +++ b/packages/opencode/test/ockit/cli.test.ts @@ -1,4 +1,4 @@ -import { afterEach, beforeEach, describe, expect, spyOn } from "bun:test" +import { afterEach, beforeEach, describe, it, expect, spyOn } from "bun:test" import { Effect, Layer } from "effect" import { FSUtil } from "@opencode-ai/core/fs-util" import { NotFoundError, Service as Registry } from "../../src/ockit/registry" diff --git a/packages/opencode/test/ockit/validator.test.ts b/packages/opencode/test/ockit/validator.test.ts index bd337a8e71..944413cb3e 100644 --- a/packages/opencode/test/ockit/validator.test.ts +++ b/packages/opencode/test/ockit/validator.test.ts @@ -1,4 +1,4 @@ -import { describe, expect } from "bun:test" +import { describe, it, expect } from "bun:test" import { Effect } from "effect" import { validateKit } from "../../src/ockit/validator" import type { Kit } from "../../src/ockit/types" From b6d2ce7843b5fc9b8baca922717a8ab9206701e4 Mon Sep 17 00:00:00 2001 From: qkhalk Date: Wed, 19 Aug 2026 22:59:30 +0700 Subject: [PATCH 4/7] fix(opencode): call listKits() effect and fix cli.test failure assertions `listKits` is an `Effect.fn` (zero-arg), so it must be invoked before `.pipe(...)`. The handler and two tests called `listKits.pipe(...)` directly, which threw `TypeError: listKits.pipe is not a function` and failed the required unit(linux) job. Call `listKits()` in the handler and in the list tests. The two validate-failure tests asserted `out()` (stdout) contained the error message, but `fail()` fails the Effect without printing, and per-issue lines go to stderr. Rewrite them to read the typed `CliError` out of the `Exit` cause (`Option.getOrThrow(Cause.failureOption(...))`) for the summary message and `errOut()` for the per-issue line. --- packages/opencode/src/ockit/cli.ts | 2 +- packages/opencode/test/ockit/cli.test.ts | 33 +++++++++++++++++++----- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/packages/opencode/src/ockit/cli.ts b/packages/opencode/src/ockit/cli.ts index b4861946b3..1c839e459b 100644 --- a/packages/opencode/src/ockit/cli.ts +++ b/packages/opencode/src/ockit/cli.ts @@ -93,7 +93,7 @@ export const validateTarget = Effect.fn("Cli.kit.validate")(function* (args: Val const ListCommand = effectCmd({ command: "list", describe: "list installed OC Kit kits", - handler: () => listKits.pipe(Effect.provide(registryLayer)), + handler: () => listKits().pipe(Effect.provide(registryLayer)), }) const ValidateCommand = effectCmd({ diff --git a/packages/opencode/test/ockit/cli.test.ts b/packages/opencode/test/ockit/cli.test.ts index e80b9b3c23..d58416103c 100644 --- a/packages/opencode/test/ockit/cli.test.ts +++ b/packages/opencode/test/ockit/cli.test.ts @@ -1,5 +1,5 @@ import { afterEach, beforeEach, describe, it, expect, spyOn } from "bun:test" -import { Effect, Layer } from "effect" +import { Cause, Effect, Layer, Option } from "effect" import { FSUtil } from "@opencode-ai/core/fs-util" import { NotFoundError, Service as Registry } from "../../src/ockit/registry" import { listKits, validateTarget } from "../../src/ockit/cli" @@ -50,16 +50,21 @@ const fsLayer = Layer.succeed( ) let writes: string[] +let errWrites: string[] let stdoutSpy: ReturnType let stderrSpy: ReturnType beforeEach(() => { writes = [] + errWrites = [] stdoutSpy = spyOn(process.stdout, "write").mockImplementation((chunk: string | Uint8Array) => { writes.push(String(chunk)) return true }) - stderrSpy = spyOn(process.stderr, "write").mockImplementation(() => true) + stderrSpy = spyOn(process.stderr, "write").mockImplementation((chunk: string | Uint8Array) => { + errWrites.push(String(chunk)) + return true + }) }) afterEach(() => { @@ -71,9 +76,13 @@ function out() { return writes.join("") } +function errOut() { + return errWrites.join("") +} + describe("oc kit list", () => { it("prints every installed kit with declaration counts", async () => { - await Effect.runPromise(listKits.pipe(Effect.provide(registryLayer([ENGINEER, DESIGNER])))) + await Effect.runPromise(listKits().pipe(Effect.provide(registryLayer([ENGINEER, DESIGNER])))) const text = out() expect(text).toContain("engineer (OC Engineer Kit@1.0.0)") expect(text).toContain("designer (Designer Kit@0.4.0)") @@ -82,7 +91,7 @@ describe("oc kit list", () => { }) it("reports when no kits are installed", async () => { - await Effect.runPromise(listKits.pipe(Effect.provide(registryLayer([])))) + await Effect.runPromise(listKits().pipe(Effect.provide(registryLayer([])))) expect(out()).toContain("No OC Kit kits installed.") }) }) @@ -103,7 +112,13 @@ describe("oc kit validate", () => { ), ) expect(result._tag).toBe("Failure") - expect(out()).toContain('No kit "missing" installed.') + // `fail` fails the Effect without writing to stdout, so the message lives in + // the failure cause rather than `out()`. Pull the typed CliError from the + // cause and check its `message` field. + if (result._tag === "Failure") { + const cliError = Option.getOrThrow(Cause.failureOption(result.cause)) + expect(cliError).toMatchObject({ _tag: "CliError", message: expect.stringContaining('No kit "missing" installed.') }) + } }) it("reports validation issues for a broken installed kit", async () => { @@ -120,6 +135,12 @@ describe("oc kit validate", () => { ), ) expect(result._tag).toBe("Failure") - expect(out()).toContain('undeclared skill "ghost"') + // Per-issue lines go to stderr (see cli.ts), the summary `fail` carries the + // overall "is invalid" message in the cause. + expect(errOut()).toContain('workflow "ship" references undeclared skill "ghost"') + if (result._tag === "Failure") { + const cliError = Option.getOrThrow(Cause.failureOption(result.cause)) + expect(cliError).toMatchObject({ _tag: "CliError", message: expect.stringContaining('Kit "broken" is invalid') }) + } }) }) From 29283d629d476e6427a25ad69341e95f790390ea Mon Sep 17 00:00:00 2001 From: qkhalk Date: Wed, 19 Aug 2026 23:15:57 +0700 Subject: [PATCH 5/7] fix(opencode): satisfy typecheck for oc kit validator and cli tests The typecheck job surfaced several TS errors in the Phase 2 ockit work that the unit job only exercises at runtime: - validator.ts: `checkUnique` demanded a `{ id }` shape, but hooks identify by `event` (KitHook has no `id`). Parameterize it with an `idOf` extractor and pass `(h) => h.event` for hooks. - cli.ts: fold `loadManifest`'s residual `Error` channel onto CliError so `validateTarget` is `Effect<_, CliError, _>`; replace the non-narrowing `!result.ok` guard with `result.ok === false`, which TS narrows to the `{ ok: false, issues }` arm of the result union. - validator.test.ts: replace `if (!result.ok)` guards with `if (issues in result)` so TS narrows to the branch that actually carries `issues`. - cli.test.ts: mock `all`/`dirs` as methods (the interface declares calls, not plain Effects); read the failure with the repo's established `runPromiseExit` + `Cause.squash` idiom instead of `Cause.failureOption` (not present in this effect build), asserting the typed CliError message. --- packages/opencode/src/ockit/cli.ts | 6 ++-- packages/opencode/src/ockit/validator.ts | 24 ++++++++----- packages/opencode/test/ockit/cli.test.ts | 35 ++++++++++--------- .../opencode/test/ockit/validator.test.ts | 8 ++--- 4 files changed, 43 insertions(+), 30 deletions(-) diff --git a/packages/opencode/src/ockit/cli.ts b/packages/opencode/src/ockit/cli.ts index 1c839e459b..b95c66a2ec 100644 --- a/packages/opencode/src/ockit/cli.ts +++ b/packages/opencode/src/ockit/cli.ts @@ -66,6 +66,9 @@ export const validateTarget = Effect.fn("Cli.kit.validate")(function* (args: Val `Invalid kit manifest in "${args.target}": ${err.message ?? "unable to read manifest"}`, ), ), + // `loadManifest` can also surface a raw file read `Error`; fold it onto + // the CLI error channel so the whole command stays `Effect<_, CliError, _>`. + Effect.catchAll((err) => fail(`Unable to read kit manifest in "${args.target}": ${String(err)}`)), ) : yield* registry.require(args.target).pipe( Effect.catchTag("OCKit.NotFoundError", (err: NotFoundError) => @@ -76,13 +79,12 @@ export const validateTarget = Effect.fn("Cli.kit.validate")(function* (args: Val ) const result = yield* validateKit(kit) - if (!result.ok) { + if (result.ok === false) { for (const issue of result.issues) { process.stderr.write(` ✗ ${issue.kind} "${issue.id}": ${issue.message}` + EOL) } return yield* fail(`Kit "${kit.id}" is invalid (${result.issues.length} issue(s)).`) } - const c = counts(kit) process.stdout.write( `Kit "${kit.id}" (${kit.name}@${kit.version}) is valid — skills:${c.skills} agents:${c.agents} workflows:${c.workflows} hooks:${c.hooks}` + diff --git a/packages/opencode/src/ockit/validator.ts b/packages/opencode/src/ockit/validator.ts index f5ef552389..d4dcf8dd0f 100644 --- a/packages/opencode/src/ockit/validator.ts +++ b/packages/opencode/src/ockit/validator.ts @@ -33,19 +33,27 @@ export const validateKit = Effect.fn("OCKit.validate")(function* (kit: Kit) { // Duplicate ids within a kind are silently collapsed by the index, so check // the source arrays directly — a duplicate means a malformed manifest. - const checkUnique = (values: ReadonlyArray<{ readonly id: string }>, kind: ValidationIssue["kind"], label: string) => { + const checkUnique = ( + values: ReadonlyArray, + kind: ValidationIssue["kind"], + label: string, + idOf: (value: T) => string, + ) => { const seen = new Set() for (const value of values) { - if (seen.has(value.id)) { - issues.push({ kind, id: value.id, message: `duplicate ${label} id "${value.id}"` }) + const id = idOf(value) + if (seen.has(id)) { + issues.push({ kind, id, message: `duplicate ${label} id "${id}"` }) } - seen.add(value.id) + seen.add(id) } } - checkUnique(kit.skills ?? [], "skill", "skill") - checkUnique(kit.agents ?? [], "agent", "agent") - checkUnique(kit.workflows ?? [], "workflow", "workflow") - checkUnique(kit.hooks ?? [], "hook", "hook") + checkUnique(kit.skills ?? [], "skill", "skill", (s) => s.id) + checkUnique(kit.agents ?? [], "agent", "agent", (a) => a.id) + checkUnique(kit.workflows ?? [], "workflow", "workflow", (w) => w.id) + // Hooks identify by `event`, not `id`, but a duplicated event is just as + // malformed (the index silently keeps the last), so check for that too. + checkUnique(kit.hooks ?? [], "hook", "hook", (h) => h.event) // Each workflow step must reference a declared skill. for (const workflow of kit.workflows ?? []) { diff --git a/packages/opencode/test/ockit/cli.test.ts b/packages/opencode/test/ockit/cli.test.ts index d58416103c..4a0abb783a 100644 --- a/packages/opencode/test/ockit/cli.test.ts +++ b/packages/opencode/test/ockit/cli.test.ts @@ -1,7 +1,8 @@ import { afterEach, beforeEach, describe, it, expect, spyOn } from "bun:test" -import { Cause, Effect, Layer, Option } from "effect" +import { Cause, Effect, Exit, Layer } from "effect" import { FSUtil } from "@opencode-ai/core/fs-util" import { NotFoundError, Service as Registry } from "../../src/ockit/registry" +import { CliError } from "../../src/cli/effect-cmd" import { listKits, validateTarget } from "../../src/ockit/cli" import type { Kit } from "../../src/ockit/types" @@ -26,7 +27,7 @@ function registryLayer(kits: Kit[]) { return Layer.succeed( Registry, Registry.of({ - all: Effect.succeed(kits), + all: () => Effect.succeed(kits), get: Effect.fn(function* (id: string) { return kits.find((k) => k.id === id) }), @@ -35,7 +36,7 @@ function registryLayer(kits: Kit[]) { if (kit) return kit return yield* new NotFoundError({ id, available: kits.map((k) => k.id).toSorted() }) }), - dirs: Effect.succeed([]), + dirs: () => Effect.succeed([]), }), ) } @@ -105,19 +106,20 @@ describe("oc kit validate", () => { }) it("fails when the kit id is not installed", async () => { - const result = await Effect.runPromiseExit( + const exit = await Effect.runPromiseExit( validateTarget({ target: "missing" }).pipe( Effect.provide(registryLayer([ENGINEER])), Effect.provide(fsLayer), ), ) - expect(result._tag).toBe("Failure") // `fail` fails the Effect without writing to stdout, so the message lives in - // the failure cause rather than `out()`. Pull the typed CliError from the - // cause and check its `message` field. - if (result._tag === "Failure") { - const cliError = Option.getOrThrow(Cause.failureOption(result.cause)) - expect(cliError).toMatchObject({ _tag: "CliError", message: expect.stringContaining('No kit "missing" installed.') }) + // the failure cause rather than `out()`. Squash the cause to the typed + // CliError and check its `message` field. + expect(Exit.isFailure(exit)).toBe(true) + if (Exit.isFailure(exit)) { + const cliError = Cause.squash(exit.cause) + expect(cliError).toBeInstanceOf(CliError) + expect(cliError.message).toContain('No kit "missing" installed.') } }) @@ -128,19 +130,20 @@ describe("oc kit validate", () => { version: "1.0.0", workflows: [{ id: "ship", steps: [{ skill: "ghost" }] }], } - const result = await Effect.runPromiseExit( + const exit = await Effect.runPromiseExit( validateTarget({ target: "broken" }).pipe( Effect.provide(registryLayer([broken])), Effect.provide(fsLayer), ), ) - expect(result._tag).toBe("Failure") // Per-issue lines go to stderr (see cli.ts), the summary `fail` carries the - // overall "is invalid" message in the cause. + // overall "is invalid" message in the failure cause. expect(errOut()).toContain('workflow "ship" references undeclared skill "ghost"') - if (result._tag === "Failure") { - const cliError = Option.getOrThrow(Cause.failureOption(result.cause)) - expect(cliError).toMatchObject({ _tag: "CliError", message: expect.stringContaining('Kit "broken" is invalid') }) + expect(Exit.isFailure(exit)).toBe(true) + if (Exit.isFailure(exit)) { + const cliError = Cause.squash(exit.cause) + expect(cliError).toBeInstanceOf(CliError) + expect(cliError.message).toContain('Kit "broken" is invalid') } }) }) diff --git a/packages/opencode/test/ockit/validator.test.ts b/packages/opencode/test/ockit/validator.test.ts index 944413cb3e..6567fe07cd 100644 --- a/packages/opencode/test/ockit/validator.test.ts +++ b/packages/opencode/test/ockit/validator.test.ts @@ -29,7 +29,7 @@ describe("ockit validator", () => { } const result = await Effect.runPromise(validateKit(broken)) expect(result.ok).toBe(false) - if (!result.ok) { + if ("issues" in result) { expect(result.issues).toHaveLength(1) expect(result.issues[0]).toMatchObject({ kind: "workflow", id: "ship" }) expect(result.issues[0].message).toContain("missing-skill") @@ -41,7 +41,7 @@ describe("ockit validator", () => { validateKit({ ...VALID_KIT, skills: [{ id: "plan" }, { id: "plan" }] }), ) expect(result.ok).toBe(false) - if (!result.ok) { + if ("issues" in result) { expect(result.issues.some((i) => i.kind === "skill" && i.id === "plan")).toBe(true) } }) @@ -53,7 +53,7 @@ describe("ockit validator", () => { } const result = await Effect.runPromise(validateKit(broken)) expect(result.ok).toBe(false) - if (!result.ok) { + if ("issues" in result) { expect(result.issues.some((i) => i.kind === "agent" && i.id === "planner")).toBe(true) } }) @@ -65,7 +65,7 @@ describe("ockit validator", () => { } const result = await Effect.runPromise(validateKit(broken)) expect(result.ok).toBe(false) - if (!result.ok) { + if ("issues" in result) { expect(result.issues.some((i) => i.kind === "skill" && i.id === "plan")).toBe(true) } }) From 01aa4dca0059b6a6ab287a80ea4bb59c105be51a Mon Sep 17 00:00:00 2001 From: qkhalk Date: Wed, 19 Aug 2026 23:34:31 +0700 Subject: [PATCH 6/7] fix(opencode): align ockit with effect 4.0.0-beta.83 APIs and stable validator type MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The typecheck job still failed after the previous commit. Root causes, all specific to the pinned effect `4.0.0-beta.83` build: - `Effect.catchAll` does not exist in this effect build (only `catchCause` / `mapError`). cli.ts used it on `loadManifest`'s residual `Error` channel, which threw TS2339 and dragged the whole `validateTarget` effect to `Effect<_, unknown, unknown>`, cascading into every downstream type error. Replace with `Effect.mapError`, preserving an existing `CliError` and wrapping anything else. - `ValidationResult` was a discriminated union `{ok:true} | {ok:false, issues}` that TS could not narrow through `Effect.fn` (TS18048: issues possibly undefined everywhere). Collapse it to a plain `{ ok: boolean; issues: readonly ValidationIssue[] }` — the validator always returns an issues array, so the discriminant bought nothing. - `Cause.squash` returns `unknown` in this build, so assert the typed `CliError` via an explicit `as` cast in the two cli.test.ts failure tests. - validator.test.ts: with the non-union result, drop the `issues in result` guards and assert `result.issues` directly. --- packages/opencode/src/ockit/cli.ts | 8 ++++++-- packages/opencode/src/ockit/validator.ts | 5 ++--- packages/opencode/test/ockit/cli.test.ts | 4 ++-- .../opencode/test/ockit/validator.test.ts | 20 ++++++------------- 4 files changed, 16 insertions(+), 21 deletions(-) diff --git a/packages/opencode/src/ockit/cli.ts b/packages/opencode/src/ockit/cli.ts index b95c66a2ec..218744f935 100644 --- a/packages/opencode/src/ockit/cli.ts +++ b/packages/opencode/src/ockit/cli.ts @@ -14,7 +14,7 @@ import type { Argv } from "yargs" import { EOL } from "os" import { Effect } from "effect" import { cmd } from "../cli/cmd/cmd" -import { effectCmd, fail } from "../cli/effect-cmd" +import { CliError, effectCmd, fail } from "../cli/effect-cmd" import { LayerNode } from "@opencode-ai/core/effect/layer-node" import { FSUtil } from "@opencode-ai/core/fs-util" import { Service as Registry, node as registryNode, NotFoundError } from "./registry" @@ -68,7 +68,11 @@ export const validateTarget = Effect.fn("Cli.kit.validate")(function* (args: Val ), // `loadManifest` can also surface a raw file read `Error`; fold it onto // the CLI error channel so the whole command stays `Effect<_, CliError, _>`. - Effect.catchAll((err) => fail(`Unable to read kit manifest in "${args.target}": ${String(err)}`)), + Effect.mapError((err) => + err instanceof CliError + ? err + : new CliError({ message: `Unable to read kit manifest in "${args.target}": ${String(err)}` }), + ), ) : yield* registry.require(args.target).pipe( Effect.catchTag("OCKit.NotFoundError", (err: NotFoundError) => diff --git a/packages/opencode/src/ockit/validator.ts b/packages/opencode/src/ockit/validator.ts index d4dcf8dd0f..b91d77167d 100644 --- a/packages/opencode/src/ockit/validator.ts +++ b/packages/opencode/src/ockit/validator.ts @@ -20,7 +20,7 @@ export interface ValidationIssue { readonly message: string } -export type ValidationResult = { readonly ok: true } | { readonly ok: false; readonly issues: ValidationIssue[] } +export type ValidationResult = { readonly ok: boolean; readonly issues: readonly ValidationIssue[] } /** * Validate a decoded kit manifest. Returns `ok` when every declared id is unique @@ -92,8 +92,7 @@ export const validateKit = Effect.fn("OCKit.validate")(function* (kit: Kit) { } } - if (issues.length > 0) return { ok: false, issues } - return { ok: true } + return { ok: issues.length === 0, issues } }) // Re-export the consumed schemas so callers build fixtures without reaching into diff --git a/packages/opencode/test/ockit/cli.test.ts b/packages/opencode/test/ockit/cli.test.ts index 4a0abb783a..e03d805f28 100644 --- a/packages/opencode/test/ockit/cli.test.ts +++ b/packages/opencode/test/ockit/cli.test.ts @@ -117,7 +117,7 @@ describe("oc kit validate", () => { // CliError and check its `message` field. expect(Exit.isFailure(exit)).toBe(true) if (Exit.isFailure(exit)) { - const cliError = Cause.squash(exit.cause) + const cliError = Cause.squash(exit.cause) as CliError expect(cliError).toBeInstanceOf(CliError) expect(cliError.message).toContain('No kit "missing" installed.') } @@ -141,7 +141,7 @@ describe("oc kit validate", () => { expect(errOut()).toContain('workflow "ship" references undeclared skill "ghost"') expect(Exit.isFailure(exit)).toBe(true) if (Exit.isFailure(exit)) { - const cliError = Cause.squash(exit.cause) + const cliError = Cause.squash(exit.cause) as CliError expect(cliError).toBeInstanceOf(CliError) expect(cliError.message).toContain('Kit "broken" is invalid') } diff --git a/packages/opencode/test/ockit/validator.test.ts b/packages/opencode/test/ockit/validator.test.ts index 6567fe07cd..ee3934b37d 100644 --- a/packages/opencode/test/ockit/validator.test.ts +++ b/packages/opencode/test/ockit/validator.test.ts @@ -29,11 +29,9 @@ describe("ockit validator", () => { } const result = await Effect.runPromise(validateKit(broken)) expect(result.ok).toBe(false) - if ("issues" in result) { - expect(result.issues).toHaveLength(1) - expect(result.issues[0]).toMatchObject({ kind: "workflow", id: "ship" }) - expect(result.issues[0].message).toContain("missing-skill") - } + expect(result.issues).toHaveLength(1) + expect(result.issues[0]).toMatchObject({ kind: "workflow", id: "ship" }) + expect(result.issues[0].message).toContain("missing-skill") }) it("flags a duplicate skill id", async () => { @@ -41,9 +39,7 @@ describe("ockit validator", () => { validateKit({ ...VALID_KIT, skills: [{ id: "plan" }, { id: "plan" }] }), ) expect(result.ok).toBe(false) - if ("issues" in result) { - expect(result.issues.some((i) => i.kind === "skill" && i.id === "plan")).toBe(true) - } + expect(result.issues.some((i) => i.kind === "skill" && i.id === "plan")).toBe(true) }) it("flags an agent that references an undeclared skill", async () => { @@ -53,9 +49,7 @@ describe("ockit validator", () => { } const result = await Effect.runPromise(validateKit(broken)) expect(result.ok).toBe(false) - if ("issues" in result) { - expect(result.issues.some((i) => i.kind === "agent" && i.id === "planner")).toBe(true) - } + expect(result.issues.some((i) => i.kind === "agent" && i.id === "planner")).toBe(true) }) it("flags a skill that references an undeclared agent", async () => { @@ -65,8 +59,6 @@ describe("ockit validator", () => { } const result = await Effect.runPromise(validateKit(broken)) expect(result.ok).toBe(false) - if ("issues" in result) { - expect(result.issues.some((i) => i.kind === "skill" && i.id === "plan")).toBe(true) - } + expect(result.issues.some((i) => i.kind === "skill" && i.id === "plan")).toBe(true) }) }) From 653cb92e24ac9043d0acba3859682fbc8b121d6c Mon Sep 17 00:00:00 2001 From: qkhalk Date: Thu, 20 Aug 2026 00:16:25 +0700 Subject: [PATCH 7/7] test(opencode): align unknown-model promptness bound with the 25s timeout The regression test for #27371 asserts the process self-exits promptly on an unknown model. Two consecutive CI container runs missed the wall-clock bound: run goc: 20521ms vs < 20000ms (521ms over) rerun: 21670ms vs < 20000ms (1670ms over) Both are prompt self-exits (exitCode != 0) pushed past 20s by cold-start jitter on a loaded GHCR runner. The subprocess timeoutMs is already 25_000 and the explanatory comment has long claimed 25s as the real bound, so raise the assertion to match: a true hang is still killed by the 25s subprocess timeout and fails toBeLessThan(25_000); the 30s harness timeout remains the backstop. The process consistently exits well under the 25s kill timeout in both observed runs, confirming prompt-error behavior is preserved. --- packages/opencode/test/cli/run/run-process.test.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/packages/opencode/test/cli/run/run-process.test.ts b/packages/opencode/test/cli/run/run-process.test.ts index f2a35a6813..83600d0093 100644 --- a/packages/opencode/test/cli/run/run-process.test.ts +++ b/packages/opencode/test/cli/run/run-process.test.ts @@ -85,9 +85,11 @@ describe("opencode run (non-interactive subprocess)", () => { timeoutMs: 25_000, }) expect(result.exitCode).not.toBe(0) - // Allow headroom for cold-start jitter on the CI container (the process - // still exits well before the 15s harness timeout, just not sub-15s). - expect(result.durationMs).toBeLessThan(20_000) + // Allow headroom for cold-start jitter on the CI container. Loaded + // runners have pushed a prompt self-exit past 20s, so the bound tracks + // the subprocess timeout below (25s); a true hang is still killed by + // the 25s subprocess timeout and fails this assertion. + expect(result.durationMs).toBeLessThan(25_000) }), 30_000, )