Skip to content

yaml: back YAML with the go-ruby-yaml library - #43

Merged
tannevaled merged 1 commit into
mainfrom
bind-yaml-library
Jun 29, 2026
Merged

tannevaled merged 1 commit into
mainfrom
bind-yaml-library

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

Rewire rbgo's YAML/Psych standard library so its emitter and loader are the standalone github.com/go-ruby-yaml/yaml library — itself ported from rbgo's own internal yaml*.go, so it is behavior-compatible by construction — exactly as rbgo already binds go-ruby-regexp and go-ruby-erb.

What changed

  • Deleted the duplicated in-tree YAML logic now provided by the library: internal/vm/yaml_dump.go, internal/vm/yaml_load.go, internal/vm/yaml_object.go (~1568 lines), plus its white-box yaml_internal_test.go.
  • Added internal/vm/yaml_bind.go: the thin binding mapping rbgo's object graph to and from the library's value model (object.Value ⇄ any). It preserves shared / cyclic reference identity in both directions (a per-operation identity cache) so the library's anchor/alias emission and load round-trip work, and carries the !ruby/object: / !ruby/class / !ruby/module class-resolution helper.
  • Rewrote internal/vm/yaml.go to call yaml.Dump / yaml.Load / yaml.SafeLoad; threads safe_load's permitted_classes: through WithPermittedClasses; surfaces the library's SyntaxError as Psych::SyntaxError and the dump error as TypeError.

The Ruby-facing API (YAML.dump / load / safe_load / load_file / safe_load_file and Object#to_yaml) is identical.

Verification

  • All existing YAML tests pass; new white-box tests cover every binding value-mapping branch and error path.
  • Puppet apply clean-exit probe: grep -c "Error:" prints 0 — the state.yaml round-trip and report write still converge (catalog compiled, notify fired, catalog applied).
  • 100.0% cross-package coverage retained; full suite green; gofmt + go vet clean.

Library depended on: github.com/go-ruby-yaml/yaml v0.0.0-20260629093916-8035038027bd.

🤖 Generated with Claude Code

Rewire rbgo's YAML/Psych standard library onto the standalone
github.com/go-ruby-yaml/yaml emitter+loader (itself ported from rbgo's
own internal yaml*.go, so it is behavior-compatible by construction),
exactly as rbgo already binds go-ruby-regexp and go-ruby-erb.

- Delete the duplicated in-tree YAML logic (yaml_dump.go, yaml_load.go,
  yaml_object.go: ~1568 lines) and its white-box test (yaml_internal_test.go).
- Add yaml_bind.go: the thin binding that maps rbgo's object graph to and
  from the library's value model (object.Value <-> any), preserving shared /
  cyclic reference identity on both directions so anchors/aliases round-trip,
  plus the class-resolution helper.
- Rewrite yaml.go to call yaml.Dump / yaml.Load / yaml.SafeLoad; thread
  safe_load's permitted_classes: through WithPermittedClasses; surface library
  SyntaxError as Psych::SyntaxError and the dump error as TypeError.

The Ruby-facing API (YAML.dump/load/safe_load/load_file/safe_load_file and
Object#to_yaml) is unchanged; Puppet's state.yaml round-trip and report write
still converge with zero errors. 100.0% cross-package coverage retained.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@tannevaled
tannevaled merged commit 4cd15a5 into main Jun 29, 2026
9 checks passed
@tannevaled
tannevaled deleted the bind-yaml-library branch June 29, 2026 10:08
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