|
1 | 1 | import { describe, expect, it } from "@effect/vitest"; |
| 2 | +import * as Effect from "effect/Effect"; |
| 3 | +import * as Layer from "effect/Layer"; |
| 4 | +import * as Sink from "effect/Sink"; |
| 5 | +import * as Stream from "effect/Stream"; |
| 6 | +import { ChildProcessSpawner } from "effect/unstable/process"; |
2 | 7 |
|
3 | | -import { parseGrokInspectSkills } from "./GrokSkills.ts"; |
| 8 | +import { discoverGrokSkills, parseGrokInspectSkills } from "./GrokSkills.ts"; |
4 | 9 |
|
5 | 10 | const inspectPayload = (skills: ReadonlyArray<unknown>) => JSON.stringify({ skills }); |
6 | 11 |
|
@@ -86,3 +91,45 @@ describe("parseGrokInspectSkills", () => { |
86 | 91 | expect(parseGrokInspectSkills(JSON.stringify({}))).toEqual([]); |
87 | 92 | }); |
88 | 93 | }); |
| 94 | + |
| 95 | +describe("discoverGrokSkills", () => { |
| 96 | + it.effect("spawns the inspect probe in the configured cwd", () => { |
| 97 | + const spawnCwds: Array<string | undefined> = []; |
| 98 | + const spawner = ChildProcessSpawner.make((command) => { |
| 99 | + spawnCwds.push(command._tag === "StandardCommand" ? command.options.cwd : undefined); |
| 100 | + return Effect.succeed( |
| 101 | + ChildProcessSpawner.makeHandle({ |
| 102 | + pid: ChildProcessSpawner.ProcessId(1), |
| 103 | + exitCode: Effect.succeed(ChildProcessSpawner.ExitCode(0)), |
| 104 | + isRunning: Effect.succeed(false), |
| 105 | + kill: () => Effect.void, |
| 106 | + unref: Effect.succeed(Effect.void), |
| 107 | + stdin: Sink.drain, |
| 108 | + stdout: Stream.encodeText( |
| 109 | + Stream.make( |
| 110 | + inspectPayload([ |
| 111 | + { |
| 112 | + name: "kept", |
| 113 | + source: { type: "project", path: "/workspaces/demo/.grok/skills/kept/SKILL.md" }, |
| 114 | + }, |
| 115 | + ]), |
| 116 | + ), |
| 117 | + ), |
| 118 | + stderr: Stream.empty, |
| 119 | + all: Stream.empty, |
| 120 | + getInputFd: () => Sink.drain, |
| 121 | + getOutputFd: () => Stream.empty, |
| 122 | + }), |
| 123 | + ); |
| 124 | + }); |
| 125 | + |
| 126 | + return Effect.gen(function* () { |
| 127 | + const skills = yield* discoverGrokSkills({ binaryPath: "grok" }, {}, "/workspaces/demo").pipe( |
| 128 | + Effect.provide(Layer.succeed(ChildProcessSpawner.ChildProcessSpawner, spawner)), |
| 129 | + ); |
| 130 | + |
| 131 | + expect(spawnCwds).toEqual(["/workspaces/demo"]); |
| 132 | + expect(skills.map((skill) => skill.name)).toEqual(["kept"]); |
| 133 | + }); |
| 134 | + }); |
| 135 | +}); |
0 commit comments