fix(cli-run): move resolveRunModel inside try block
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
/// <reference types="bun-types" />
|
/// <reference types="bun-types" />
|
||||||
|
|
||||||
import { describe, it, expect } from "bun:test"
|
import { describe, it, expect, beforeEach, afterEach, vi } from "bun:test"
|
||||||
import type { OhMyOpenCodeConfig } from "../../config"
|
import type { OhMyOpenCodeConfig } from "../../config"
|
||||||
import { resolveRunAgent, waitForEventProcessorShutdown } from "./runner"
|
import { resolveRunAgent, waitForEventProcessorShutdown } from "./runner"
|
||||||
|
|
||||||
@@ -83,7 +83,6 @@ describe("resolveRunAgent", () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe("waitForEventProcessorShutdown", () => {
|
describe("waitForEventProcessorShutdown", () => {
|
||||||
|
|
||||||
it("returns quickly when event processor completes", async () => {
|
it("returns quickly when event processor completes", async () => {
|
||||||
//#given
|
//#given
|
||||||
const eventProcessor = new Promise<void>((resolve) => {
|
const eventProcessor = new Promise<void>((resolve) => {
|
||||||
@@ -115,3 +114,44 @@ describe("waitForEventProcessorShutdown", () => {
|
|||||||
expect(elapsed).toBeGreaterThanOrEqual(timeoutMs - 10)
|
expect(elapsed).toBeGreaterThanOrEqual(timeoutMs - 10)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe("run with invalid model", () => {
|
||||||
|
it("given invalid --model value, when run, then returns exit code 1 with error message", async () => {
|
||||||
|
// given
|
||||||
|
const originalExit = process.exit
|
||||||
|
const originalError = console.error
|
||||||
|
const errorMessages: string[] = []
|
||||||
|
const exitCodes: number[] = []
|
||||||
|
|
||||||
|
console.error = (...args: unknown[]) => {
|
||||||
|
errorMessages.push(args.map(String).join(" "))
|
||||||
|
}
|
||||||
|
process.exit = ((code?: number) => {
|
||||||
|
exitCodes.push(code ?? 0)
|
||||||
|
throw new Error("exit")
|
||||||
|
}) as typeof process.exit
|
||||||
|
|
||||||
|
try {
|
||||||
|
// when
|
||||||
|
// Note: This will actually try to run - but the issue is that resolveRunModel
|
||||||
|
// is called BEFORE the try block, so it throws an unhandled exception
|
||||||
|
// We're testing the runner's error handling
|
||||||
|
const { run } = await import("./runner")
|
||||||
|
|
||||||
|
// This will throw because model "invalid" is invalid format
|
||||||
|
try {
|
||||||
|
await run({
|
||||||
|
message: "test",
|
||||||
|
model: "invalid",
|
||||||
|
})
|
||||||
|
} catch {
|
||||||
|
// Expected to potentially throw due to unhandled model resolution error
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
// then - verify error handling
|
||||||
|
// Currently this will fail because the error is not caught properly
|
||||||
|
console.error = originalError
|
||||||
|
process.exit = originalExit
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|||||||
@@ -47,10 +47,11 @@ export async function run(options: RunOptions): Promise<number> {
|
|||||||
|
|
||||||
const pluginConfig = loadPluginConfig(directory, { command: "run" })
|
const pluginConfig = loadPluginConfig(directory, { command: "run" })
|
||||||
const resolvedAgent = resolveRunAgent(options, pluginConfig)
|
const resolvedAgent = resolveRunAgent(options, pluginConfig)
|
||||||
const resolvedModel = resolveRunModel(options.model)
|
|
||||||
const abortController = new AbortController()
|
const abortController = new AbortController()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
const resolvedModel = resolveRunModel(options.model)
|
||||||
|
|
||||||
const { client, cleanup: serverCleanup } = await createServerConnection({
|
const { client, cleanup: serverCleanup } = await createServerConnection({
|
||||||
port: options.port,
|
port: options.port,
|
||||||
attach: options.attach,
|
attach: options.attach,
|
||||||
|
|||||||
Reference in New Issue
Block a user