Skip to content

fix: add cyclic reference detection to TOML renderer and sync upstream test suites#961

Closed
He-Pin wants to merge 1 commit into
databricks:masterfrom
He-Pin:fix/toml-cyclic-detection-and-test-sync
Closed

fix: add cyclic reference detection to TOML renderer and sync upstream test suites#961
He-Pin wants to merge 1 commit into
databricks:masterfrom
He-Pin:fix/toml-cyclic-detection-and-test-sync

Conversation

@He-Pin

@He-Pin He-Pin commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add cyclic reference detection to std.manifestTomlEx: The TOML renderer had no cycle/depth protection, causing OutOfMemoryError on cyclic objects like {a: {b: $}}. JSON and YAML renderers already had this protection via the Materializer. This fix adds both an IdentityHashMap-based cycle detector and a depth limit check, with a StackOverflowError/OutOfMemoryError safety net in evalRhs.

  • Sync upstream test suites from google/go-jsonnet: 3 new cyclic reference tests were added from upstream, plus infrastructure fixes for golden file generation.

  • Fix golden file generation scripts: Strip Java runtime WARNING: lines (sun.misc.Unsafe deprecation on JDK 21+) from golden files, and regenerate error goldens for new test files using sjsonnet's error format.

Changes

File Change
ManifestModule.scala Add depth + IdentityHashMap cycle detection to renderTableInternal; wrap evalRhs in StackOverflowError/OutOfMemoryError catch
refresh_golden_outputs.sh Add sed '/^WARNING:/d' after each golden generation
sync_test_suites.sh Regenerate error goldens for new files via GOLDEN_REFRESH_FILES
.sync_ignore Document path-dependent tests (std.thisFile*) and behavioral differences (1.42 rendering, pow6, parseYaml)
3 new test files Cyclic reference tests for manifestJsonEx, manifestTomlEx, manifestYamlDoc

Behavioral differences documented in .sync_ignore

Test sjsonnet go-jsonnet Rationale
builtin_escapeStringJson 1.42 1.4199999999999999 Both are valid float64 JSON; sjsonnet uses shortest round-trip
pow6 agrees with jrsonnet different precision Rendering difference near MaxFloat64
parseYaml("---") null [null] YAML parser behavioral difference
std.thisFile* relative to suite dir testdata/ prefix Path-dependent on execution context

Test plan

  • All 103 tests pass (including 3 new cyclic reference tests)
  • std.manifestTomlEx({a: {b: $}}, " ") now produces error instead of OOM
  • std.manifestJsonEx({a: $}, " ") and std.manifestYamlDoc({a: $}) error tests pass
  • Golden file generation scripts produce clean output on JDK 21+

…m test suites

Motivation:
`std.manifestTomlEx({a: {b: $}}, " ")` caused OutOfMemoryError because the TOML
renderer had no cycle detection, unlike JSON/YAML renderers which go through the
Materializer's protection. Additionally, upstream test suites (google/go-jsonnet)
had new cyclic reference tests and updated golden files that needed syncing.

Modification:
- Add depth limit and IdentityHashMap-based cycle detection to
  ManifestTomlEx.renderTableInternal, matching the Materializer's approach
- Wrap ManifestTomlEx.evalRhs in StackOverflowError/OutOfMemoryError catch
- Fix refresh_golden_outputs.sh to strip Java runtime WARNING lines from
  golden files (sun.misc.Unsafe deprecation warnings on JDK 21+)
- Fix sync_test_suites.sh to regenerate error golden files for new test files
  using sjsonnet's error format instead of upstream's
- Add 3 new cyclic reference tests from go-jsonnet (JSON/TOML/YAML manifest)
- Update .sync_ignore with documented entries for path-dependent tests
  (std.thisFile) and behavioral differences (float rendering, pow6, parseYaml)

Result:
- std.manifestTomlEx now correctly detects cyclic references instead of OOM
- All 103 tests pass including 3 new cyclic reference tests
- Test sync infrastructure properly handles Java warnings and error format
- Golden files accurately reflect sjsonnet's behavior vs upstream differences
@He-Pin He-Pin closed this Jun 18, 2026
@He-Pin He-Pin deleted the fix/toml-cyclic-detection-and-test-sync branch June 18, 2026 06:26
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