Skip to content

test(postgrest-typegen): cover the untested TypeScript generator fallbacks - #144

Merged
spydon merged 1 commit into
mainfrom
test/cover-non-generated-schema-fallbacks
Sep 3, 2026
Merged

spydon merged 1 commit into
mainfrom
test/cover-non-generated-schema-fallbacks

Conversation

@spydon

@spydon spydon commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

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 no other key is written, so each kind degrades instead:

Referenced kind Fallback Why
enum inlines its variants, "happy" | "sad" the values travel with the type, so nothing is lost
composite type unknown its shape lives in the schema that was skipped
relation unknown same

The fourth is unrelated but found the same way: a non-updatable column on a writable view has to be spelled ?: never in Update, so writing one is a type error rather than a runtime rejection. The Insert side and both table equivalents were already covered; only the view Update path 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:

Bun's coverage stopped reporting line 897 as uncovered merely because an unrelated test was added, while mutating that line still broke nothing. It attributes the four identical ?: never lines unreliably.

So the coverage delta below is reported for context, not as the evidence. Mutation testing is the evidence.

before  src/generation/typescript.ts   97.50% funcs   98.14% lines
after   src/generation/typescript.ts   98.75% funcs   98.88% lines

Of the three lines still listed as uncovered, 55-59 is the oxfmt failure throw, 304-305 is one arm of the PostgREST-resolvability filter, and 469 is the unknown fallback 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, and build all clean. Goldens untouched, as expected for a test-only change.

Context

Came out of an audit prompted by #143, which shipped a resolver whose unknown branch had no test. Sibling ticket SDK-1721 covers the Swift generator's scalar mapping table, where Bool, Int16, Float, and Double are similarly unexercised.

@spydon
spydon requested a review from a team as a code owner September 2, 2026 14:01
@coderabbitai

coderabbitai Bot commented Sep 2, 2026 •

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: d694106d-5bbb-4fd3-8800-accc4dd57981


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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
spydon force-pushed the test/cover-non-generated-schema-fallbacks branch from b17218b to 666b06c Compare September 2, 2026 14:58
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.
@spydon
spydon merged commit 1e61b40 into main Sep 3, 2026
5 checks passed
@spydon
spydon deleted the test/cover-non-generated-schema-fallbacks branch September 3, 2026 06:34
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.

3 participants