Skip to content

StringIO / buffer IO: advance MRI 4.0.6 conformance - #561

Merged
tannevaled merged 7 commits into
mainfrom
feat/agent-stringio
Sep 5, 2026
Merged

tannevaled merged 7 commits into
mainfrom
feat/agent-stringio

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

Advances MRI Ruby 4.0.6 (stringio 3.2.0) conformance for the in-memory StringIO / buffer-backed IO paths, entirely CGO-free. Work is confined to internal/vm/io.go (+ one post-prelude hook line in vm.go) and a new internal/vm/stringio_residuals_test.go; no OS-fd, socket, pipe, select, or subprocess paths were touched.

What changed

  • Construction: StringIO.allocate now yields a real StringIO backend; #initialize is a private instance method; .new and .open share the same setup. .open with a block yields self, then closes it and drops the backing string (#string ⇒ nil), even on exception.
  • Backing-string identity: the passed String is held and mutated in place, so #string returns that same object and writes/truncation are visible through it (matching MRI).
  • #reopen (String / StringIO / #to_strio / two-arg mode forms), #string=, #each_codepoint.
  • Mode handling decodes Integer flag sets directly (IO::WRONLY no longer truncates; IO::TRUNC / O_APPEND honored); frozen backing string raises Errno::EACCES (writable mode) or FrozenError (truncating mode); :mode/:binmode/:textmode/:encoding options with conflict detection.
  • Argument coercion & bounds: #seek/#pos=/#truncate take #to_int, raise Errno::EINVAL on negative/bad-whence, IOError on closed/unwritable; #rewind resets lineno.
  • Overrides / aliases: #sync always true, #binmode sets ASCII-8BIT, #close_read/#close_write raise IOError on the wrong mode, #fcntl ⇒ NotImplementedError; true aliases #size/#tell/#eof/#isatty; StringIO::VERSION = "3.2.0"; StringIO mixes in Enumerable.

Conformance deltas (rubyspec, vs main)

  • library/stringio: 467 → 577 pass (+110)
  • core/io: 728 → 738 pass (+10), zero per-spec regressions

Notable per-spec: initialize 3→26, open 0→20, reopen 0→29, each_codepoint 0→7, string 2→7, seek 4→8, truncate 6→9, sync 0→2, plus binmode/close_read/close_write/eof/isatty/size/tell/fcntl/read/sysread/stringio.

Remaining failures are encoding-subsystem (default_external / string-encoding tracking), overwrite-semantics #ungetc/#ungetbyte, and OS-dependent fd/nonblock paths — reported, not in scope for the buffer subset.

Gates

  • go test ./internal/vm/ and go test ./... green.
  • wasip1/wasm build OK; gofmt -l clean.
  • Every function changed is 100% in the merged -coverpkg profile; no shadowed dead code (methods edited in place / overridden per-class), every new branch tested. The one sub-100% line is a pre-existing setLineGlobals nil-guard inside defStringIORead, byte-identical to main and unreachable via the public API.

🤖 Generated with Claude Code

tannevaled and others added 7 commits September 4, 2026 23:03
…limit)

Committed to protect against scratchpad purge; to be finished, verified and
squashed before the PR is opened.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…ode+seek fixes

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…dual tests

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…tra (fix coverage)

The per-StringIO close_read/close_write overrides shadowed defIOReadExtra's, leaving those closures uncovered (89.4%). Move the rdModeOff/wrModeOff IOError guard into the single shared definition (only StringIO sets those fields), removing the shadow.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@tannevaled
tannevaled merged commit 3a9c9a0 into main Sep 5, 2026
7 checks passed
@tannevaled
tannevaled deleted the feat/agent-stringio branch September 5, 2026 16:53
tannevaled added a commit that referenced this pull request Sep 5, 2026
Locks in #561 (StringIO / buffer IO), #562 (String non-encoding methods) and
#563 (Time). Measured 18650 passing on the pinned corpus, up from 18582.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
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