mirror of
https://github.com/MadsLorentzen/ai-job-search.git
synced 2026-09-17 08:36:25 +00:00
parseIntFlag used bare parseInt, so --jobage 0.5 truncated to 0, failed the jobage > 0 guard in search.ts, and posted_within_days was silently omitted from the outbound request while the CLI exited 0. Numeric flags now accept whole numbers >= 1 only, mirroring the Danish CLIs' z.coerce.number().int().min(1) contract, and reject everything else with the stderr-JSON BAD_ARG error. Five new validation cases, each verified to fail on the unfixed code.
This commit is contained in:
@@ -112,9 +112,16 @@ best-effort, no SLA. Override with FREEHIRE_API_URL to use a self-hosted backend
|
||||
`
|
||||
|
||||
function parseIntFlag(name: string, raw: string | boolean | string[]): number | null {
|
||||
const val = parseInt(raw as string, 10)
|
||||
if (isNaN(val)) {
|
||||
process.stderr.write(JSON.stringify({ error: `--${name} must be a number, got "${raw}"`, code: "BAD_ARG" }) + "\n")
|
||||
// Number(), not parseInt(): parseInt truncates, so "--jobage 0.5" became 0,
|
||||
// which fails search.ts's `jobage > 0` guard and silently drops
|
||||
// posted_within_days from the outbound request while exiting 0 (#373).
|
||||
// Whole numbers >= 1 only — the Danish CLIs' z.coerce.number().int().min(1)
|
||||
// contract; 0 is rejected rather than kept as a "no filter" alias.
|
||||
const val = typeof raw === "string" ? Number(raw.trim()) : NaN
|
||||
if (!Number.isInteger(val) || val < 1) {
|
||||
process.stderr.write(
|
||||
JSON.stringify({ error: `--${name} must be a whole number of at least 1, got "${raw}"`, code: "BAD_ARG" }) + "\n",
|
||||
)
|
||||
return null
|
||||
}
|
||||
return val
|
||||
|
||||
Reference in New Issue
Block a user