Repository navigation
test(postgrest-typegen): cover the untested TypeScript generator fallbacks - #144
Merged
Merged
Conversation
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Team Run ID: Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🟢 Approval recommended
The tests cover the intended branches; the inaccurate fixture comment is non-blocking.
Pull request overview
Adds regression coverage for previously untested TypeScript generator fallbacks.
Changes:
- Tests out-of-schema enum, composite, and relation fallbacks.
- Tests non-updatable writable-view columns in
Update.
File summaries
| File | Description |
|---|---|
packages/postgrest-typegen/test/generation/typescript.test.ts |
Adds targeted TypeScript generator tests. |
Review details
- Files reviewed: 1/1 changed files
- Comments generated: 1
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…backs Four branches of the TypeScript generator produced real, user-visible output that no test asserted. Three are the same theme: a column can reference an enum, a composite type or a relation owned by a schema the caller did not ask to generate. Emitting Database["other"][...] there would dangle, so each degrades instead. An enum inlines its variants as a string union, since the values travel with the type; composites and relations go to unknown, since their shape lives in the schema that was skipped. The fourth is a non-updatable column on a writable view, which has to be spelled ?: never in Update. The Insert side and both table equivalents were already covered; only the view Update path was not. Every assertion was verified by inverting the branch it targets and confirming the test fails, rather than by trusting the coverage report. That matters here: bun attributes the four identical ?: never lines unreliably, and it stopped reporting line 897 as uncovered merely because an unrelated test was added, while mutating that line still broke nothing. No source or golden changes; tests only.
spydon
force-pushed
the
test/cover-non-generated-schema-fallbacks
branch
from
September 2, 2026 14:58
b17218b to
666b06c
Compare
spydon
added a commit
that referenced
this pull request
Sep 2, 2026
Closes SDK-1721. Sibling of #144. ## What Six reachable branches of the Swift generator were asserted by nothing. Break `int2 -> Int16` before this commit and the whole suite stayed green. **Four scalar mappings no fixture column reached:** | Postgres | Swift | | --- | --- | | `bool` | `Bool` | | `int2` | `Int16` | | `float4` | `Float` | | `float8` | `Double` | Nothing else in the fixture declares a `bool`, `smallint`, `real` or `double precision` column, so those arms were never generated by any test. **Two in `formatForSwiftTypeName`:** the leading underscore that has to survive pascal-casing (`_key_id_context -> _KeyIdContext`, which the doc comment promises), and the empty words a leading or trailing separator produces. A *run* of separators collapses to a single delimiter and produces none, so `a--b` yields two words rather than three. ## How A new `scalar_type_test` fixture table pins the four scalars end to end through the parity goldens, following the `interval_test` precedent of a small table dedicated to a type mapping. Goldens regenerated for all four languages. Swift and Go both map the integer and float families to distinct widths, so both goldens gain from these columns. Python collapses each family onto `int` and `float` and is unaffected either way: ```go type PublicScalarTypeTestSelect struct { DoublePrecision *float64 `json:"double_precision"` Flag bool `json:"flag"` SinglePrecision *float32 `json:"single_precision"` SmallInt *int16 `json:"small_int"` } ``` The two name-formatting cases are unit tests in `swift.test.ts`, since a deliberately mis-named relation belongs there rather than in the shared fixture. ## `void` and `record` stay untested on purpose They are **unreachable, not missed**. Both are pseudo-types, and this generator renders only columns and composite attributes. Verified against a real Postgres rather than assumed: ``` rejected: create table t_void (c void) -> column "c" has pseudo-type void rejected: create table t_record (c record) -> column "c" has pseudo-type record rejected: create type ct_void as (c void) -> column "c" has pseudo-type void ``` Left in place with a comment explaining why, since they are the right mappings if Swift ever emits functions. They are the only lines still uncovered in the file. ## Verified by mutation, not by the coverage report Every branch above was checked by mutating it and confirming the suite fails. That is deliberate: as #144 documents, bun's line attribution in this package is unreliable, and it once stopped reporting a line as uncovered merely because an unrelated test was added while mutating that line still broke nothing. ``` before src/generation/swift.ts 100% funcs 97.26% lines after src/generation/swift.ts 100% funcs 99.45% lines (only the two pseudo-type lines) ``` ## Testing 131 pass, 0 fail against a real database, parity gate included. `check-types`, `oxfmt`, `oxlint`, `knip`, `build` all clean. Golden diff is additive only: +42 Swift, +24 Go, +24 TypeScript, +21 Python, no deletions. ## Review follow-up Three inaccurate comments I had written were caught in review and corrected; all three claims were verified before accepting them. No behaviour changed, comments and one commit message only. - Go does **not** collapse the numeric families. It maps `int2`/`int4`/`int8` and `float4`/`float8` to distinct widths, exactly as the new Go golden shows. Only Python collapses. The fixture comment claimed otherwise. - A doubled separator does **not** produce an empty word, since the split pattern matches a run. Only a leading or trailing one does.
Tr00d
approved these changes
Sep 3, 2026
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.
Closes SDK-1720.
What
Four branches of the TypeScript generator produced real, user-visible output that no test asserted. Tests only, no source or golden changes.
Three are one theme: a type owned by a schema that is not being generated. A column can reference an enum, a composite type, or a relation living in a schema the caller did not ask for. Emitting
Database["other"][...]there would dangle, since nootherkey is written, so each kind degrades instead:"happy" | "sad"unknownunknownThe fourth is unrelated but found the same way: a non-updatable column on a writable view has to be spelled
?: neverinUpdate, so writing one is a type error rather than a runtime rejection. TheInsertside and both table equivalents were already covered; only the viewUpdatepath was not.Every assertion is mutation-verified
Each test was checked by inverting the branch it targets and confirming the test fails. That was not paranoia here:
So the coverage delta below is reported for context, not as the evidence. Mutation testing is the evidence.
Of the three lines still listed as uncovered,
55-59is theoxfmtfailure throw,304-305is one arm of the PostgREST-resolvability filter, and469is theunknownfallback when a function's return type id misses. Those are follow-up material, not part of this change.Testing
131 pass, 0 fail against a real database, parity gate included.
check-types,oxfmt,oxlint,knip, andbuildall clean. Goldens untouched, as expected for a test-only change.Context
Came out of an audit prompted by #143, which shipped a resolver whose
unknownbranch had no test. Sibling ticket SDK-1721 covers the Swift generator's scalar mapping table, whereBool,Int16,Float, andDoubleare similarly unexercised.