Skip to content

test(sdk_tests): cover the stdlib json type in type_shapes#3937

Open
sxlijin wants to merge 1 commit into
canaryfrom
sam/sdk-tests-json-type
Open

test(sdk_tests): cover the stdlib json type in type_shapes#3937
sxlijin wants to merge 1 commit into
canaryfrom
sam/sdk-tests-json-type

Conversation

@sxlijin

@sxlijin sxlijin commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Adds SDK e2e coverage for the stdlib json type (baml.json.json).

Changes

  • New fixture sdk_tests/fixtures/type_shapes/baml_src/ns_json_values/types.baml: every function is declared to return json, but each returns a differently-shaped value — null, bool, int, float, string, array, object, and a nested object. Also includes a round_trip_json(j: json) -> json encode/decode pair and a JsonContainer class with a json field.
  • Python roundtrip tests (crates/python_pydantic2/type_shapes/customizable/roundtrip_tests/test_json_values.py): asserts each shape decodes to the expected Python value and survives the encode → FFI → decode round trip, including a heterogeneous array.
  • TypeScript roundtrip tests (crates/typescript_node/type_shapes/customizable/roundtrip_json_values.test.ts): same coverage ported to vitest.

The namespace is ns_json_values (→ baml_sdk.json_values) rather than ns_json to avoid colliding with the stdlib baml.json namespace and the Python stdlib json module.

Test plan

  • cargo nextest run -p sdk_test_python_pydantic2 -p sdk_test_typescript_node — 29/29 pass locally (ruff, pyright, pytest, tsc, esm_output, vitest across all fixtures).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added broader roundtrip coverage for JSON-shaped values across Python and TypeScript test suites.
    • Included support for null, booleans, numbers, strings, arrays, objects, nested objects, and container-wrapped JSON values.
  • Tests
    • Added new fixture and test cases to verify JSON values preserve their shape and content through encode/decode cycles.

Adds a `ns_json_values` fixture whose functions are all declared to
return `json` (`baml.json.json`) but each return a differently-shaped
value — null, bool, int, float, string, array, object, and a nested
object — plus a `round_trip_json` encode/decode pair and a
`JsonContainer` class with a `json` field.

Host-language roundtrip tests assert each shape survives the
encode → FFI → decode round trip in both the python/pydantic2 and
typescript/node SDKs.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@vercel

vercel Bot commented Jul 7, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
beps Ready Ready Preview, Comment Jul 7, 2026 11:43pm
promptfiddle Ready Ready Preview, Comment Jul 7, 2026 11:43pm
promptfiddle2 Ready Ready Preview, Comment Jul 7, 2026 11:43pm

Request Review

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

⏭️ Performance benchmarks were skipped

Perf benchmarks (CodSpeed) are opt-in on pull requests — they no longer run on every push. They always run automatically after merge to canary/main.

To run them on this PR, do any of the following, then push a commit (or re-run CI):

  • Add RUN_CODSPEED=1 to the PR description, or
  • Include run-perf or /perf in the PR title or any commit message.

@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds a new BAML fixture defining a recursive json type and JsonContainer class with functions returning specific JSON shapes and roundtrip functions, along with matching Python and TypeScript test suites verifying decode and full encode/decode roundtrip behavior.

Changes

JSON Type Shape Support and Tests

Layer / File(s) Summary
BAML fixture definitions
baml_language/sdk_tests/fixtures/type_shapes/baml_src/ns_json_values/types.baml
Defines the recursive json type, JsonContainer class with data json field, return_json_* functions for each JSON shape, and round_trip_json/round_trip_json_container functions.
Python roundtrip tests
baml_language/sdk_tests/crates/python_pydantic2/type_shapes/customizable/roundtrip_tests/test_json_values.py
Adds decode-only tests for return_json_* outputs and full roundtrip tests for round_trip_json and round_trip_json_container.
TypeScript roundtrip tests
baml_language/sdk_tests/crates/typescript_node/type_shapes/customizable/roundtrip_json_values.test.ts
Adds a vitest suite validating return_json_* outputs and round_trip_json/round_trip_json_container behavior, including instance type checks.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Poem

A json field, both deep and wide,
Null, bool, and arrays side by side 🐰
I hopped through Python, hopped through TS,
Roundtrips passing, nothing less,
Carrots and containers, both verified!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding type_shapes coverage for the stdlib json type.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sam/sdk-tests-json-type

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
baml_language/sdk_tests/fixtures/type_shapes/baml_src/ns_json_values/types.baml (1)

11-41: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Consider adding falsy-value shape coverage.

Current shapes cover null/true/42/3.14/"hello"/array/object/nested, but omit falsy edge cases: 0, "", [], {}. These are valuable because decode paths that mistakenly check truthiness instead of is not None/presence would silently pass all current tests while failing on these values.

♻️ Suggested additional functions
 function return_json_nested() -> json {
   {"a": 1, "b": [2, 3], "c": {"nested": null}}
 }
+
+function return_json_zero() -> json {
+  0
+}
+
+function return_json_empty_string() -> json {
+  ""
+}
+
+function return_json_empty_array() -> json {
+  []
+}
+
+function return_json_empty_object() -> json {
+  {}
+}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@baml_language/sdk_tests/fixtures/type_shapes/baml_src/ns_json_values/types.baml`
around lines 11 - 41, Add shape coverage for falsy JSON values in the
ns_json_values fixtures by extending the existing return_json_* functions in
types.baml with cases for 0, empty string, empty array, and empty object. Keep
the current naming/style alongside return_json_null, return_json_bool, and
return_json_object, and ensure the fixture exercises these values so decode
logic in the json type path is verified against truthiness bugs.
baml_language/sdk_tests/crates/python_pydantic2/type_shapes/customizable/roundtrip_tests/test_json_values.py (1)

26-90: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Falsy-value roundtrip coverage gap (downstream of fixture).

Same gap as the fixture: no test exercises 0, "", [], or {} through round_trip_json/return_json_*, which are the values most likely to expose truthiness-check bugs in decode logic. Once the corresponding fixture functions exist, mirror the existing test pattern for them (e.g., assert round_trip_json(j=0) == 0 and assert round_trip_json(j=0) is not None).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@baml_language/sdk_tests/crates/python_pydantic2/type_shapes/customizable/roundtrip_tests/test_json_values.py`
around lines 26 - 90, Add roundtrip tests in test_json_values for falsy JSON
values that are currently uncovered, using the existing round_trip_json and
return_json_* helpers. After the corresponding fixture functions are available,
verify 0, empty string, empty array, and empty object survive decoding/encoding
without being treated as missing values, following the same assertion style as
the existing test_round_trip_json_* cases.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In
`@baml_language/sdk_tests/crates/python_pydantic2/type_shapes/customizable/roundtrip_tests/test_json_values.py`:
- Around line 26-90: Add roundtrip tests in test_json_values for falsy JSON
values that are currently uncovered, using the existing round_trip_json and
return_json_* helpers. After the corresponding fixture functions are available,
verify 0, empty string, empty array, and empty object survive decoding/encoding
without being treated as missing values, following the same assertion style as
the existing test_round_trip_json_* cases.

In
`@baml_language/sdk_tests/fixtures/type_shapes/baml_src/ns_json_values/types.baml`:
- Around line 11-41: Add shape coverage for falsy JSON values in the
ns_json_values fixtures by extending the existing return_json_* functions in
types.baml with cases for 0, empty string, empty array, and empty object. Keep
the current naming/style alongside return_json_null, return_json_bool, and
return_json_object, and ensure the fixture exercises these values so decode
logic in the json type path is verified against truthiness bugs.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 025c3a58-f85b-4a05-bc67-1ffdcfda5afb

📥 Commits

Reviewing files that changed from the base of the PR and between 8afbddd and f9a5123.

📒 Files selected for processing (3)
  • baml_language/sdk_tests/crates/python_pydantic2/type_shapes/customizable/roundtrip_tests/test_json_values.py
  • baml_language/sdk_tests/crates/typescript_node/type_shapes/customizable/roundtrip_json_values.test.ts
  • baml_language/sdk_tests/fixtures/type_shapes/baml_src/ns_json_values/types.baml

@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

Binary size checks passed

7 passed

Artifact Platform File Gzip Gated on Baseline Delta Status
baml-cli Linux 🔒 21.7 MB 9.3 MB file 21.5 MB +207.9 KB (+1.0%) OK
packed-program Linux 🔒 15.9 MB 6.7 MB file 15.6 MB +258.2 KB (+1.7%) OK
baml-cli macOS 🔒 16.7 MB 8.1 MB file 16.6 MB +182.2 KB (+1.1%) OK
packed-program macOS 🔒 12.3 MB 5.8 MB file 12.1 MB +198.9 KB (+1.6%) OK
baml-cli Windows 🔒 18.3 MB 8.3 MB file 18.1 MB +169.0 KB (+0.9%) OK
packed-program Windows 🔒 13.2 MB 5.9 MB file 13.0 MB +204.5 KB (+1.6%) OK
bridge_wasm WASM 14.6 MB 🔒 4.1 MB gzip 4.1 MB +88.8 KB (+2.2%) OK

🔒 = the size this artifact is GATED on (ceiling + delta). Binaries gate on file size (installed binary); WASM gates on gzip (download size). The other size is shown for information only.


Generated by cargo size-gate · workflow run

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