Skip to content

Bring the extension libraries up to cel-go v0.33 - #14

Merged
5 commits merged into
emfga:mainfrom
lemuelroberto:cel-go-v0.33-libraries
Oct 30, 2026
Merged

5 commits merged into
emfga:mainfrom
lemuelroberto:cel-go-v0.33-libraries

Conversation

@lemuelroberto

Copy link
Copy Markdown
Member

Stacked on #13. Merge #13 first. Until it lands, this diff also includes #13's commit.

Implements the library surface added in cel-go v0.33.1 in PL/pgSQL. With this, the oracle runs every library at its latest version except encoders.

Implemented

Library Overloads Version
lists hasOnly, hasAny, hasAll, hasExactly (list_*_list) 5
encoders base64.encodeUrl, base64.decodeUrl 2
optionals optional.hasValue(v) (optional_hasValue_value) 3
optionals first(), last(), optional.unwrap, unwrapOpt 2, missing until now

The optionals v2 list helpers were already declared by the oracle in earlier releases but had never been registered here. No corpus case calls them, so nothing noticed until now. optMap / optFlatMap already expanded the way version 4 does, binding a non-identifier target exactly once, so only their comment changes.

Not implemented (encoders stays pinned at version 2)

json.encode (v1), json.parse (both overloads), yaml.encode, yaml.parse (both overloads). docs/CONFORMANCE.md gains a "Library coverage beyond the corpus" section that explains why:

  • YAML would need a YAML 1.2 parser and emitter, which is unreasonable to write in PL/pgSQL.
  • json.parse(s, T) converts through cel-go's type provider.
  • json.encode depends on Go-specific output details: float formatting, HTML-safe escaping, quoting integers above 2^53, and protojson for timestamps and durations.

A port that matched those only partly would return subtly different strings, which is worse than a function that clearly doesn't exist.

New tests

  • TestLibraryOverloads compares, for every env, the overload ids cel-go declares with the registry's env_item rows. It fails on:

    • anything cel-go declares that the registry lacks and that isn't in the printed known-missing list
    • anything the registry has that cel-go doesn't declare
    • known-missing entries that have gone stale

    Known-missing now holds __not_strictly_false__ (a deprecated alias), cel_block_list (cel-go-internal) and the six json/yaml ids. This is the test that would have caught the missing optionals helpers.

  • TestLibraryCases has 68 expressions the corpus never reaches. Each runs through cel-go, and cel-go's outcome becomes the expectation for cel4postgres. Every case also states which outcome it expects (value, evaluation error, or check error), so it can't pass just because both sides rejected an undeclared function. A mutation check confirmed it catches a wrong implementation: with hasAny swapped for hasAll, 4 cases fail.

  • internal/oracle/options.go: the ListsVersion(4) and OptionalTypesVersion(2) pins are gone; encoders is held at EncodersVersion(2).

Results

  • Conformance corpus: 1841 passed, 0 failed, 667 skipped, 10 divergences, unchanged. The corpus does not reach any of the new functions.
  • go test ./...: passes on a fresh install, and on 0.0.2 → this build upgraded through both plain and pg_tle (scripts/upgrade-check.sh from Test upgrades from the previous release #12).

The core scripts enable "every overload, type and macro registered
so far" in standard. On a fresh install that is the core alone,
because the extension scripts run afterwards. But the installer is
also the upgrade, and run over an installed schema the same sweep
picks up every extension's items and every consumer registration:
upgrading 0.0.2 in place put 139 extension overloads, 16 macros and
3 types into standard, plus the consumer's own overload. The suite
stayed green, because a wider env breaks no corpus case -- which is
exactly the failure CLAUDE.md warns about.

The sweep now takes only rows no env claims yet whose implementation
lives in the cel schema, and the installer drops from standard what
a shipped extension env also lists, repairing schemas already
reinstalled. A consumer row swept in earlier cannot be told from one
put in standard on purpose, so it stays. The upgrade check asserts
standard comes out of an upgrade as narrow as it went in.

The origin column of rds-distribution decision 7 is the general fix;
this guard is what the installer needs until it lands.
cel-go v0.33 added hasOnly, hasAny, hasAll and hasExactly as lists
library version 5. They are the sets library's contains / intersects /
equivalent spelled as list methods, which is the form an authorization
condition reaches for ("the token's scopes include all of these"),
so they are worth having rather than leaving the lists env a version
behind the reference.
base64.encodeUrl / decodeUrl arrived with encoders version 2. Tokens
and identifiers that reach a policy are usually base64url, and
re-alphabetising them in CEL by hand is error-prone. The rest of
version 2 (json and yaml) is deliberately left out; see
docs/CONFORMANCE.md.
first(), last(), optional.unwrap and unwrapOpt (version 2) had never
been registered -- the oracle enabled them, but no corpus case calls
them, so nothing noticed. optional.hasValue(v) is version 3. optMap /
optFlatMap already expanded the way version 4 does, binding a
non-identifier target once, so only the comment changes.
The corpus exercises a fraction of each extension library, and that
is how the optionals list helpers went missing unseen: the oracle
declared them, no case called them. TestLibraryOverloads now compares
each env's registry rows with the overload ids cel-go declares and
fails on any gap not named in a printed known-missing list;
TestLibraryCases runs the functions the corpus never reaches through
both implementations with cel-go's outcome as the expectation.

With that in place the oracle drops the version pins on lists and
optionals. encoders stays held at version 2: json.encode / json.parse
and the yaml functions are not implemented, and the reasons are in
docs/CONFORMANCE.md.
@lemuelroberto lemuelroberto closed this pull request by merging all changes into emfga:main in 1db81b6 Oct 30, 2026
@lemuelroberto
lemuelroberto deleted the cel-go-v0.33-libraries branch October 30, 2026 01:22
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.

1 participant