Skip to content

test(baml_tests): add native coverage for Rust VM tests - #4234

Closed
codeshaunted wants to merge 2 commits into
canaryfrom
codex/native-baml-test-audit
Closed

codeshaunted wants to merge 2 commits into
canaryfrom
codex/native-baml-test-audit

Conversation

@codeshaunted

@codeshaunted codeshaunted commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Add 35 native BAML tests covering 29 Rust baml_test! call sites.
  • Remove those 29 migrated Rust macro sites, reducing the active count from 421 to 392.
  • Cover string escapes, error rendering, generic union parsing, interface aliases, typed JSON unions, narrow bindings, parse companions, and reflect.call_any.
  • Add namespace bytecode snapshots.
  • Leave the 266 pre-existing native/Rust duplicates for a separate deletion PR.

Scope note

The forced-GC cleanup case remains Rust-only. Native top-level tests run in parallel, and this case was not reliable when forced collection overlapped the wider corpus.

Testing

  • Full native BAML corpus: 2601 passed, 0 failed.
  • Focused changed namespaces: 49 passed, 0 failed.
  • Bytecode snapshot test passed in non-update mode.
  • Remaining errorcontext and parse_companions Rust tests: 14 passed, 0 failed.
  • Remaining string-literal diagnostic Rust test: 1 passed, 0 failed.
  • Cargo fmt check passed.

Summary by CodeRabbit

  • Tests
    • Expanded BAML-level regression coverage for error-context rendering (including recursive/large structures with truncation), dynamic calls/signatures, structured pattern narrowing, $parse JSON vs plain text, string literal escaping/raw strings, and generic union/nullable handling.
    • Added typed JSON serialization tests for class/enum/media unions, plus validation that invalid union members raise the expected error.
    • Streamlined existing runtime Rust integration tests by shifting the covered assertions into BAML test modules (and trimming redundant Rust test files).

@vercel

vercel Bot commented Jul 27, 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 28, 2026 12:08am
promptfiddle Ready Ready Preview, Comment Jul 28, 2026 12:08am
promptfiddle2 Ready Ready Preview, Comment Jul 28, 2026 12:08am

Request Review

@github-actions

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.

@vercel
vercel Bot temporarily deployed to Preview – beps July 27, 2026 23:42 Inactive
@coderabbitai

coderabbitai Bot commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The PR adds BAML test coverage for ErrorContext rendering, reflection dispatch and signatures, union and interface type handling, typed JSON serialization, string parsing, and escaped/raw string literal semantics, while removing corresponding Rust integration tests.

Changes

Language behavior regression tests

Layer / File(s) Summary
ErrorContext rendering coverage
baml_language/crates/baml_tests/baml_src/ns_errorcontext/errorcontext.baml, baml_language/crates/baml_tests/tests/errorcontext.rs
Adds structural, qualified-name, cycle, depth, and node-budget rendering tests while removing the corresponding Rust cases.
Reflection dispatch and signatures
baml_language/crates/baml_tests/baml_src/ns_reflect_call_any/reflect_call_any.baml, baml_language/crates/baml_tests/tests/reflect_call_any.rs
Adds AnyFunction, argument validation, typed-error, callable, and signature coverage while removing the Rust integration suite.
Type and serialization behavior
baml_language/crates/baml_tests/baml_src/ns_interface_type_alias_iteration/*, baml_language/crates/baml_tests/baml_src/ns_narrow_bind/*, baml_language/crates/baml_tests/baml_src/ns_generic_union_returns/*, baml_language/crates/baml_tests/baml_src/ns_json_typed_union/*, baml_language/crates/baml_tests/tests/*
Adds BAML tests for interface aliases, pattern binding, generic unions, and typed JSON serialization, replacing removed Rust tests.
Parsing and string literal semantics
baml_language/crates/baml_tests/baml_src/ns_parse_companions/*, baml_language/crates/baml_tests/baml_src/ns_string_literals/*, baml_language/crates/baml_tests/src/string_literals.rs, baml_language/crates/baml_tests/tests/parse_companions.rs
Adds BAML coverage for parsing and string semantics, retains Rust invalid-literal diagnostics, and removes superseded Rust runtime tests.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

Suggested reviewers: antoniosarosi

Poem

A rabbit hops through tests so bright,
Through unions, strings, and errors at night.
Cycles shrink and calls dispatch,
Raw slashes sparkle in a flash.
New BAML checks go thump-thump-thump!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: migrating Rust VM test coverage to native BAML tests.
✨ 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 codex/native-baml-test-audit

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.

@vercel
vercel Bot temporarily deployed to Preview – beps July 27, 2026 23:48 Inactive

@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.

Actionable comments posted: 2

🤖 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.

Inline comments:
In `@baml_language/crates/baml_tests/baml_src/ns_errorcontext/errorcontext.baml`:
- Around line 516-520: Update errorcontext_budget_rendering_check to assert that
wide_hex contains exactly two truncation markers by requiring
wide_hex.split(marker).length() == 3, while preserving the existing deep_hex and
wide_hex marker checks.

In
`@baml_language/crates/baml_tests/baml_src/ns_parse_companions/parse_companions.baml`:
- Around line 67-68: Update the function directives in ParseCompanionsTestClient
usage by removing the colons from client and prompt, matching the syntax used by
the sibling ParseCompanionsParseAliasPayload function so the BAML parser accepts
them.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 5e3ee9b6-4dfb-4ebc-8aec-421eeaf03e3c

📥 Commits

Reviewing files that changed from the base of the PR and between 73e0871 and ea9e92c.

⛔ Files ignored due to path filters (9)
  • baml_language/crates/baml_tests/snapshots/baml_src/_root.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/baml_src/errorcontext.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/baml_src/generic_union_returns.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/baml_src/interface_type_alias_iteration.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/baml_src/json_typed_union.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/baml_src/narrow_bind.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/baml_src/parse_companions.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/baml_src/reflect_call_any.snap is excluded by !**/*.snap
  • baml_language/crates/baml_tests/snapshots/baml_src/string_literals.snap is excluded by !**/*.snap
📒 Files selected for processing (8)
  • baml_language/crates/baml_tests/baml_src/ns_errorcontext/errorcontext.baml
  • baml_language/crates/baml_tests/baml_src/ns_generic_union_returns/generic_union_returns.baml
  • baml_language/crates/baml_tests/baml_src/ns_interface_type_alias_iteration/interface_type_alias_iteration.baml
  • baml_language/crates/baml_tests/baml_src/ns_json_typed_union/json_typed_union.baml
  • baml_language/crates/baml_tests/baml_src/ns_narrow_bind/narrow_bind.baml
  • baml_language/crates/baml_tests/baml_src/ns_parse_companions/parse_companions.baml
  • baml_language/crates/baml_tests/baml_src/ns_reflect_call_any/reflect_call_any.baml
  • baml_language/crates/baml_tests/baml_src/ns_string_literals/string_literals.baml

Comment on lines +516 to +520
function errorcontext_budget_rendering_check() -> bool {
let deep_hex = errorcontext_render_deep().to_utf8().to_hex();
let wide_hex = errorcontext_render_wide().to_utf8().to_hex();
let marker = "e280a6";
deep_hex.includes(marker) && wide_hex.includes(marker) && wide_hex.split(marker).length() == 2

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Assert two truncation markers correctly.

Line 520 accepts exactly one marker: two occurrences produce three split parts. This lets a single-marker render pass while rejecting the intended two-marker output.

Proposed fix
-    deep_hex.includes(marker) && wide_hex.includes(marker) && wide_hex.split(marker).length() == 2
+    deep_hex.includes(marker) && wide_hex.includes(marker) && wide_hex.split(marker).length() == 3
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
function errorcontext_budget_rendering_check() -> bool {
let deep_hex = errorcontext_render_deep().to_utf8().to_hex();
let wide_hex = errorcontext_render_wide().to_utf8().to_hex();
let marker = "e280a6";
deep_hex.includes(marker) && wide_hex.includes(marker) && wide_hex.split(marker).length() == 2
function errorcontext_budget_rendering_check() -> bool {
let deep_hex = errorcontext_render_deep().to_utf8().to_hex();
let wide_hex = errorcontext_render_wide().to_utf8().to_hex();
let marker = "e280a6";
deep_hex.includes(marker) && wide_hex.includes(marker) && wide_hex.split(marker).length() == 3
🤖 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/crates/baml_tests/baml_src/ns_errorcontext/errorcontext.baml`
around lines 516 - 520, Update errorcontext_budget_rendering_check to assert
that wide_hex contains exactly two truncation markers by requiring
wide_hex.split(marker).length() == 3, while preserving the existing deep_hex and
wide_hex marker checks.

@vercel
vercel Bot temporarily deployed to Preview – promptfiddle2 July 27, 2026 23:56 Inactive
@github-actions

Copy link
Copy Markdown

Binary size checks passed

✅ 7 passed

Artifact Platform File Gzip Gated on Baseline Delta Status
✅ baml-cli Linux 🔒 27.3 MB 11.6 MB file 27.3 MB +8.4 KB (+0.0%) OK
✅ packed-program Linux 🔒 17.7 MB 7.3 MB file 17.7 MB +12.6 KB (+0.1%) OK
✅ baml-cli macOS 🔒 21.2 MB 10.1 MB file 21.2 MB +32 B (+0.0%) OK
✅ packed-program macOS 🔒 13.8 MB 6.4 MB file 13.8 MB +16 B (+0.0%) OK
✅ baml-cli Windows 🔒 22.8 MB 10.3 MB file 22.8 MB +6.7 KB (+0.0%) OK
✅ packed-program Windows 🔒 14.7 MB 6.5 MB file 14.7 MB +10.5 KB (+0.1%) OK
✅ bridge_wasm WASM 16.6 MB 🔒 4.5 MB gzip 4.5 MB +3.7 KB (+0.1%) 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

@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.

Actionable comments posted: 1

🤖 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.

Inline comments:
In `@baml_language/crates/baml_tests/src/string_literals.rs`:
- Around line 10-15: Update the string-literal error assertions in the test
cases around the cases array to verify the diagnostic kind is UnexpectedEof and
its message is “unexpected end of file” for each unterminated-string fixture,
rather than accepting any error; retain the existing labels for failure context.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 8172495c-efb7-4a2a-8cc8-dbbf29cb0d81

📥 Commits

Reviewing files that changed from the base of the PR and between ea9e92c and 50cdd73.

📒 Files selected for processing (8)
  • baml_language/crates/baml_tests/src/string_literals.rs
  • baml_language/crates/baml_tests/tests/errorcontext.rs
  • baml_language/crates/baml_tests/tests/generic_union_returns.rs
  • baml_language/crates/baml_tests/tests/interface_type_alias_iteration.rs
  • baml_language/crates/baml_tests/tests/json_typed_union.rs
  • baml_language/crates/baml_tests/tests/narrow_bind.rs
  • baml_language/crates/baml_tests/tests/parse_companions.rs
  • baml_language/crates/baml_tests/tests/reflect_call_any.rs
💤 Files with no reviewable changes (7)
  • baml_language/crates/baml_tests/tests/interface_type_alias_iteration.rs
  • baml_language/crates/baml_tests/tests/json_typed_union.rs
  • baml_language/crates/baml_tests/tests/narrow_bind.rs
  • baml_language/crates/baml_tests/tests/reflect_call_any.rs
  • baml_language/crates/baml_tests/tests/generic_union_returns.rs
  • baml_language/crates/baml_tests/tests/parse_companions.rs
  • baml_language/crates/baml_tests/tests/errorcontext.rs

Comment on lines 10 to 15
let cases = [
// Unterminated string — no closing quote at all
(
r#"function f() -> string { "hello }"#,
"unterminated string",
),
// Backslash at EOF — backslash escapes nothing, string never closes
(r#"function f() -> string { "hello\"#, "backslash at EOF"),

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Assert the expected diagnostic, not merely any error.

label is only printed on failure; any unrelated parse or semantic error makes these regressions pass. Assert the expected UnexpectedEof/"unexpected end of file" diagnostic for each fixture.

Proposed fix
 let cases = [
     (
         r#"function f() -> string { "hello }"#,
-        "unterminated string",
+        "unterminated string",
+        "unexpected end of file",
     ),
-    (r#"function f() -> string { "hello\"#, "backslash at EOF"),
+    (
+        r#"function f() -> string { "hello\"#,
+        "backslash at EOF",
+        "unexpected end of file",
+    ),
 ];
 
-for (source, label) in &cases {
+for (source, label, expected_message) in &cases {
     let db = setup_test_db(source);
     let diagnostics = collect_diagnostics(&db);
-    let has_error = diagnostics
+    let has_expected_error = diagnostics
         .iter()
-        .any(|d| matches!(d.severity, Severity::Error));
+        .any(|d| {
+            matches!(d.severity, Severity::Error)
+                && d.message.to_string().contains(expected_message)
+        });
     assert!(
-        has_error,
+        has_expected_error,
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let cases = [
// Unterminated string — no closing quote at all
(
r#"function f() -> string { "hello }"#,
"unterminated string",
),
// Backslash at EOF — backslash escapes nothing, string never closes
(r#"function f() -> string { "hello\"#, "backslash at EOF"),
let cases = [
(
r#"function f() -> string { "hello }"#,
"unterminated string",
"unexpected end of file",
),
(
r#"function f() -> string { "hello\"#,
"backslash at EOF",
"unexpected end of file",
),
];
🤖 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/crates/baml_tests/src/string_literals.rs` around lines 10 - 15,
Update the string-literal error assertions in the test cases around the cases
array to verify the diagnostic kind is UnexpectedEof and its message is
“unexpected end of file” for each unterminated-string fixture, rather than
accepting any error; retain the existing labels for failure context.

This branch was previously deployed

3 inactive deployments
Preview – promptfiddle — 50cdd733 Deployed Jul 28, 2026 by vercel[bot]
Preview – promptfiddle2 — 50cdd733 Deployed Jul 27, 2026 by vercel[bot]
Preview – beps — 50cdd733 Deployed Jul 27, 2026 by vercel[bot]
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