| 19 | } |
| 20 | |
| 21 | function makeRuntime(options: { |
| 22 | cwd?: string; |
| 23 | env?: Record<string, string | undefined>; |
| 24 | files?: string[]; |
| 25 | commands?: Record<string, MockCommand>; |
| 26 | pathDelimiter?: string; |
| 27 | platform?: NodeJS.Platform; |
| 28 | } = {}): SemanticDiffRuntime & { calls: Array<{ command: string; args: string[]; input?: string }> } { |
| 29 | const calls: Array<{ command: string; args: string[]; input?: string }> = []; |
| 30 | const files = new Set(options.files ?? []); |
| 31 | const commands = options.commands ?? {}; |
| 32 | |
| 33 | return { |
| 34 | calls, |
| 35 | env: options.env ?? {}, |
| 36 | cwd: options.cwd ?? "/repo", |
| 37 | dataDir: "/home/user/.plannotator", |
| 38 | pathDelimiter: options.pathDelimiter ?? ":", |
| 39 | platform: options.platform ?? "linux", |
| 40 | fileExists(path) { |
| 41 | return files.has(path); |
| 42 | }, |
| 43 | async runCommand(command, args, runOptions) { |
| 44 | calls.push({ command, args, input: runOptions?.input }); |
| 45 | const mock = commands[command]; |
| 46 | if (!mock) return { stdout: "", stderr: "not found", exitCode: 1, error: "not found" }; |
| 47 | if (args.includes("--version")) { |
| 48 | return { stdout: mock.version ?? "", stderr: "", exitCode: mock.version ? 0 : 1 }; |
| 49 | } |
| 50 | return { |
| 51 | stdout: mock.diff ?? "", |
| 52 | stderr: mock.stderr ?? "", |
| 53 | exitCode: mock.exitCode ?? 0, |
| 54 | }; |
| 55 | }, |
| 56 | }; |
| 57 | } |
| 58 | |
| 59 | describe("semantic diff runner", () => { |
| 60 | test("parses real sem version output and rejects other sem commands", () => { |