Repository navigation
fix(api): five routers addressed tables that do not exist, and one test entry was a phantom - #711
Merged
Merged
Conversation
…st entry was a phantom Part of #660. The sweep behind #651 left a machine-checkable list — `BASELINE_BROKEN` in table-references-exist.test.ts, which reads the generated types.ts and needs no database. It counted 32 broken references across 12 table names. This takes it to 17 across 5. **#656 — the O*NET router addressed the wrong schema entirely.** `core .onet_occupations` and `core.onet_skills` exist in no schema; the data lives in `onet`, whose key column is `onetsoc_code`, not `onet_code`. Four occupation reads now select from `onet.occupation_data`, aliasing `onet_code:onetsoc_code` so the response shape the SDK consumes does not change. The skills endpoint needed more than a rename. `onet.skills` is raw O*NET measure data — one row per (onetsoc_code, element_id, scale_id), scale "IM" being importance and "LV" level — with no skill name and no `category` column, where the handler assumed a flat table with `importance` and `category`. It now reads the IM rows, resolves names from `onet.content_model_reference` in a second query (there is no declared FK, so PostgREST cannot embed it), and derives `category` from the element-id prefix, which is the actual O*NET taxonomy. The wire fields `importance` and `category` are preserved. **#657 — four wrong-schema references,** each verified against the running database rather than only against types.ts: public.webhooks exists; core.webhooks does not core.job_team_assignments exists; core.team_job_assignments does not core.certifications exists; public.certifications does not core.user_education exists; public.user_education does not The last two carried no `.schema()` call at all, so they defaulted to public and returned `count: null` rather than erroring — which is why the university student count silently read 0 for every university instead of failing. **#657's fifth row was not a real defect.** office-communities.ts:146 already read `.schema("core").from("users")`. The test reported it as `community.users` because its parser buffers to the next semicolon and takes the *first* `.schema()` in the statement — and that line sits in a `Promise.all([...])` whose first element is `.schema("community")`. One statement, two chains, one schema. The parser now takes the nearest `.schema()` *preceding* each `.from()`, which still catches the office-users.ts delete-cascade bug it was written for (those are separate statements, so each lands in its own buffer). A regression test covers the multi-chain case, and the phantom entry is gone. **#659 — a 500 where a 404 was already declared.** `GET /v1/user-profiles/ {userId}` used `.single()`, and PostgREST answers that with "Cannot coerce the result to a single JSON object" on zero rows, which arrived as an error and was reported as a server fault. A profile that does not exist is an ordinary outcome, and a 500 makes the client retry something that can never succeed. Now `.maybeSingle()` with an explicit 404, query errors still separate. Verified: the reference test passes with 6 entries removed and the new regression case; `deno check` over functions/api stays at 411 errors, so none of this adds any. Not verified: the O*NET tables are empty in the local seed, so the row-level behaviour of the rewritten skills endpoint is unexercised. The shape is checked against information_schema and the generated types; the scale ids come from the O*NET content model. #656's "returns real rows for a seeded code" cannot be met until that data is loaded. Closes #656 Closes #657 Closes #659 Co-Authored-By: Claude Opus 5 <[email protected]>
…en routes The reference test fails on unmodified main: routes/moderation.ts reads core.content_reports and core.user_blocks, and neither is in types.ts. Both tables exist in the database — #703 shipped their migrations without regenerating the checked-in types, so the routes are right and the catalogue is stale. Regenerating is not the fix and was tried: `supa:generate` against the local stack adds the three expected objects and also deletes the application_status enum, which the local database does not have and types.ts does. See #707. Listed rather than excused, so the count still only goes down — once types.ts is regenerated these go stale and the test demands their removal. Refs #707 Co-Authored-By: Claude Opus 5 <[email protected]>
Contributor
📊 Performance Benchmark Results |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #660. The sweep behind #651 left a machine-checkable list:
BASELINE_BROKENintable-references-exist.test.ts, which reads the generatedtypes.tsand needs no database.32 broken references across 12 table names → 17 across 5.
#656 — the O*NET router addressed the wrong schema entirely
core.onet_occupationsandcore.onet_skillsexist in no schema (confirmed againstinformation_schema). The data lives inonet, keyed ononetsoc_code.Four occupation reads now select from
onet.occupation_data, aliasingonet_code:onetsoc_codeso the response shape the SDK consumes is unchanged.The skills endpoint needed more than a rename.
onet.skillsis raw O*NET measure data — one row per(onetsoc_code, element_id, scale_id), scaleIMimportance andLVlevel — with no skill name and nocategorycolumn, where the handler assumed a flat table with both. It now reads theIMrows, resolves names fromonet.content_model_referencein a second query (no declared FK, so PostgREST cannot embed it), and derivescategoryfrom the element-id prefix, which is the actual O*NET taxonomy. The wire fieldsimportanceandcategoryare preserved.#657 — four wrong-schema references
Each verified against the running database, not only
types.ts:public.webhookscore.webhookscore.job_team_assignmentscore.team_job_assignmentscore.certificationspublic.certificationscore.user_educationpublic.user_educationThe last two carried no
.schema()call at all, so they defaulted topublicand returnedcount: nullrather than erroring — which is why the university student count silently read 0 for every university instead of failing visibly.#657's fifth row was not a real defect
office-communities.ts:146already read.schema("core").from("users"). The test reported it ascommunity.usersbecause its parser buffers to the next semicolon and takes the first.schema()in the statement — and that line sits inside aPromise.all([...])whose first element is.schema("community"). One statement, two chains, one schema.The parser now takes the nearest
.schema()preceding each.from(). That still catches theoffice-users.tsdelete-cascade bug it was written for — those are separate statements, so each lands in its own buffer and only the first sees a.schema()at all. A regression test covers the multi-chain case, and the phantom entry is removed.#659 — a 500 where a 404 was already declared
GET /v1/user-profiles/{userId}used.single(). PostgREST answers that with "Cannot coerce the result to a single JSON object" on zero rows, which arrived as anerrorand was reported as a server fault. A profile that does not exist is an ordinary outcome, and a 500 makes the client retry something that can never succeed. Now.maybeSingle()with an explicit 404; query errors stay separate.A third thing the test caught, which is not mine
routes/moderation.tsreadscore.content_reportsandcore.user_blocks, and neither is intypes.ts. This fails on unmodifiedmain— I checked outmainclean and reproduced it. Both tables exist in the database; #703 shipped their migrations without regenerating the checked-in types.Regenerating is not the fix and was tried:
supa:generateagainst the local stack adds the three expected objects and deletes theapplication_statusenum, which the local database does not have andtypes.tsdoes. Filed as #707. Both references are listed inBASELINE_BROKENwith that explanation, so the list's invariant still holds — once types are regenerated correctly those entries go stale and the test demands their removal.Verified / not verified
Verified: the reference test passes with six entries removed plus the new regression case;
deno checkoverfunctions/apiunchanged, so none of this adds errors;deno fmt --checkclean.Not verified: the O*NET tables are empty in the local seed, so the row-level behaviour of the rewritten skills endpoint is unexercised. The shape is checked against
information_schemaand the generated types; the scale ids come from the O*NET content model rather than from this database. #656's acceptance criterion "returns real rows for a seeded O*NET code" cannot be met until that data is loaded — worth its own issue if the seed is meant to carry it.Closes #656
Closes #657
Closes #659