Skip to content

fix(api): a query-string "false" is false — the office Jobs list was filtering out every job - #862

Merged
thinkclay merged 1 commit into
mainfrom
fix/857-coerce-boolean
Sep 22, 2026
Merged

thinkclay merged 1 commit into
mainfrom
fix/857-coerce-boolean

Conversation

@thinkclay

Copy link
Copy Markdown
Contributor

Closes #857. Found by the release-1 route sweep (#852).

The bug

GET /v1/office/jobs validated myTeamsOnly with z.coerce.boolean(), which is Boolean(value). A query string carries only strings, and Boolean("false") is true, so every value of the flag arrived as on.

That compounds at office-jobs.ts:106: a truthy myTeamsOnly switches the job_team_assignments embed to an inner join, and :160 then filters to the caller's own team memberships. The office Jobs screen always sends the param — it is useState(false) in office-jobs-list.tsx:106,127 — so the list could never show a job.

Measured locally against thirteen seeded jobs:

Query Jobs returned
?limit=100 13
?limit=100&myTeamsOnly=false 0
?limit=100&myTeamsOnly=true 0

No error, no warning — just "No jobs found" on a screen with thirteen jobs behind it.

The fix

booleanQueryParam in functions/_shared/query-schemas.ts:

Input z.coerce.boolean() booleanQueryParam
"true" true true
"false" true false
"1" true true
"0" true false
"yes" true rejected
absent undefined undefined

Written as a preprocess around z.boolean() so a real boolean passes through and .default(false) works at the call site. work-logs.ts:564 had the same z.coerce.boolean() on includeArchived and moves onto it too; those were the only two in the routes.

Three other routes hand-roll the same parse correctly (notifications.ts:59, teams.ts:87, organizations-extended.ts:981). Left alone here — unifying them is a tidy-up, not a fix, and each has its own behaviour on a garbage value worth reading before changing.

Verification

  • tests/unit/query-schemas.test.ts — 8 tests, run and passing. Pins "false" → false, the numeric and uppercase spellings, a real boolean passing through, rejection of unrecognised values, and absent staying distinct from false.
  • tests/routers/office-jobs-rest.test.ts — 3 tests, written, not run here. They exercise the real handler and assert the equivalence that matters: myTeamsOnly=false returns what omitting it returns. The local edge runtime serves the main checkout, not this worktree, so these run in the normal api-test flow rather than in this session. Both files typecheck under the tests' deno config.
  • pnpm prepush clean.

🤖 Generated with Claude Code

…filtering out every job

`GET /v1/office/jobs` validated `myTeamsOnly` with `z.coerce.boolean()`,
which is `Boolean(value)`. A query string carries only strings, and
`Boolean("false")` is `true`, so every value of the flag arrived as on.

That compounds: a truthy `myTeamsOnly` switches the `job_team_assignments`
embed to an inner join and then filters to the caller's own team
memberships. The office Jobs screen always sends the param — it is
`useState(false)` in `office-jobs-list.tsx` — so the list could never
show a job. Measured locally against thirteen seeded jobs:

  ?limit=100                    -> 13
  ?limit=100&myTeamsOnly=false  ->  0
  ?limit=100&myTeamsOnly=true   ->  0

No error, no warning: just "No jobs found".

`booleanQueryParam` in `_shared/query-schemas.ts` replaces it. It reads
`true`/`false` and `1`/`0`, case- and whitespace-insensitively, passes a
real boolean through so `.default(false)` works, and rejects anything
else with a validation error rather than guessing. `work-logs.ts` had the
same `z.coerce.boolean()` on `includeArchived` and moves onto it too;
those were the only two in the routes.

Three other routes hand-roll the same parse correctly
(notifications.ts:59, teams.ts:87, organizations-extended.ts:981). They
are left alone here — unifying them is a tidy-up, not a fix, and each has
its own default-on-garbage behaviour worth reading before changing.

Closes #857

Co-Authored-By: Claude Opus 5 <[email protected]>
@github-actions

Copy link
Copy Markdown
Contributor

📊 Performance Benchmark Results


@thinkclay
thinkclay merged commit 6423f4d into main Sep 22, 2026
14 checks passed
@thinkclay
thinkclay deleted the fix/857-coerce-boolean branch September 22, 2026 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(api): /office/cms/jobs is permanently empty — z.coerce.boolean() reads the string "false" as true

1 participant