Skip to content

test(postgrest-typegen): exercise the Swift scalar type mappings - #145

Merged
spydon merged 1 commit into
mainfrom
test/cover-swift-scalar-mappings
Sep 2, 2026
Merged

spydon merged 1 commit into
mainfrom
test/cover-swift-scalar-mappings

Conversation

@spydon

@spydon spydon commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

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:

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 requested a review from a team as a code owner September 2, 2026 14:29
@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: 3c9feaf7-2244-4ead-acd1-065f564a8075


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 test coverage is sound; only minor documentation inaccuracies remain.

Pull request overview

Adds regression coverage for Swift scalar mappings and name formatting.

Changes:

  • Adds a scalar fixture and parity goldens for four generators.
  • Tests Swift underscore and separator handling.
  • Documents unreachable pseudo-type mappings.
File summaries
File Description
test/introspection/fixtures/00-init.sql Adds scalar fixture data.
test/generation/swift.test.ts Adds Swift naming tests.
src/generation/swift.ts Documents pseudo-type branches.
test/parity/expected/swift.txt Captures Swift mappings.
test/parity/expected/go.txt Captures Go mappings.
test/parity/expected/python.txt Captures Python mappings.
test/parity/expected/typescript.txt Captures TypeScript mappings.
Review details
  • Files reviewed: 7/7 changed files
  • Comments generated: 2
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Six reachable branches of the Swift generator were asserted by nothing. Verified by mutation, not by reading the coverage report, since that report has already proven unreliable at line granularity in this package.

Four are scalar mappings that no fixture column reached: bool -> Bool, int2 -> Int16, float4 -> Float and float8 -> Double. Nothing in the fixture declared a bool, smallint, real or double precision column, so those arms were never generated. Break int2 -> Int16 before this commit and the whole suite stayed green.

A new scalar_type_test fixture table covers them end to end through the parity goldens, following the interval_test precedent of a small table dedicated to pinning a type mapping. Swift and Go both map the integer and float families to distinct widths, so both goldens gain; Python collapses each family onto int and float and is unaffected.

The other two are in formatForSwiftTypeName: the leading underscore that has to survive pascal-casing, and the empty words that a leading or trailing separator produces. A run of separators collapses to a single delimiter and produces none.

void and record stay untested because they are unreachable rather than missed: they are pseudo-types, and Postgres rejects them as a column or composite attribute type, which is all this generator renders. Verified against a real database and recorded as a comment so the next reader does not chase them.
@spydon
spydon force-pushed the test/cover-swift-scalar-mappings branch from 86ced01 to 795685e Compare September 2, 2026 14:58
@spydon
spydon merged commit 1eb8de2 into main Sep 2, 2026
6 checks passed
@spydon
spydon deleted the test/cover-swift-scalar-mappings branch September 2, 2026 17:18
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