refactor(server): split HttpApi exercise harness (#26385)
This commit is contained in:
44
packages/opencode/test/server/httpapi-exercise/routing.ts
Normal file
44
packages/opencode/test/server/httpapi-exercise/routing.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { OpenApiMethods, type OpenApiSpec, type Options, type Result, type Scenario } from "./types"
|
||||
|
||||
export function routeKeys(spec: OpenApiSpec) {
|
||||
return Object.entries(spec.paths ?? {})
|
||||
.flatMap(([path, item]) =>
|
||||
OpenApiMethods.filter((method) => item[method]).map((method) => `${method.toUpperCase()} ${path}`),
|
||||
)
|
||||
.sort()
|
||||
}
|
||||
|
||||
export function routeKey(scenario: Scenario) {
|
||||
return `${scenario.method} ${scenario.path}`
|
||||
}
|
||||
|
||||
export function coverageResult(scenario: Scenario): Result {
|
||||
if (scenario.kind === "todo") return { status: "skip", scenario }
|
||||
return { status: "pass", scenario }
|
||||
}
|
||||
|
||||
export function parseOptions(args: string[]): Options {
|
||||
const mode = option(args, "--mode") ?? "effect"
|
||||
if (mode !== "effect" && mode !== "parity" && mode !== "coverage") throw new Error(`invalid --mode ${mode}`)
|
||||
return {
|
||||
mode,
|
||||
include: option(args, "--include"),
|
||||
failOnMissing: args.includes("--fail-on-missing"),
|
||||
failOnSkip: args.includes("--fail-on-skip"),
|
||||
}
|
||||
}
|
||||
|
||||
export function matches(options: Options, scenario: Scenario) {
|
||||
if (!options.include) return true
|
||||
return (
|
||||
scenario.name.includes(options.include) ||
|
||||
scenario.path.includes(options.include) ||
|
||||
scenario.method.includes(options.include.toUpperCase())
|
||||
)
|
||||
}
|
||||
|
||||
function option(args: string[], name: string) {
|
||||
const index = args.indexOf(name)
|
||||
if (index === -1) return undefined
|
||||
return args[index + 1]
|
||||
}
|
||||
Reference in New Issue
Block a user