Skip to content

Commit 4d1a7fd

Browse files
tannevaledclaude
andauthored
conformance: derive CUR_VERSION from RUBY_VERSION — one fact, one place (#845)
Closes the last item of #799: the version the gate resolves `ruby_version_is` guards at stops being a second hardcoded copy of what the runtime already reports. -CUR_VERSION = "3.4.1" +CUR_VERSION = RUBY_VERSION ## Why this is worth a PR of its own `CUR_VERSION` selects the **population** the whole conformance figure is counted over. At 3.4.1 every example behind a `ruby_version_is "4.0"` guard is removed from the suite before anything runs — 61 block guards and 5 inline sites at that boundary, and 41 guards asserting what 4.0 changed away from (#836's census). The two copies agreed, so nothing was wrong on any given day. The defect #799 names is that **half a version change could land**: `rubyVersion` bumped in internal/vm/kernel_introspect.go, this file forgotten, and the gate goes on measuring the 3.4 population while every page claims the new version. Both halves look correct read on their own, which is exactly why nothing would have said so. This lands **before** the move to 4.0.x rather than with it, so the move is a one-line change to one place whose effect the ratchet can then attribute cleanly. ## Measured: a true no-op today `RUBY_VERSION` is `"3.4.1"`, the same string the literal held, so the population does not move. Measured rather than asserted — the derived shim run against `main`'s own binary (3a3fb81, so nothing else of mine is in the reading), on a private two-file corpus: $ rbgo core/builtin_constants/builtin_constants_spec.rb RBGO_RESULT pass=17 fail=0 error=0 skip=0 `BASELINE` records `17` for that file. **A green ratchet on this PR is therefore itself the proof of equivalence**, across all 2,206 files rather than the one I could run here. ## Upstream behaviour, not a local convenience mspec reads RUBY_VERSION for this too. The chain, at mspec b79c65e: guards/version.rb:67 VersionGuard.new(VersionGuard::FULL_RUBY_VERSION, …) guards/version.rb:6 FULL_RUBY_VERSION = SpecVersion.new SpecGuard.ruby_version(:full) guards/guard.rb:41 def self.ruby_version(which = :minor) guards/guard.rb:51 RUBY_VERSION.split('.')[0,n].join('.') # n = 3 for :full i.e. RUBY_VERSION itself for a three-part version. A consequence worth having: run under a different interpreter, the shim now measures at THAT interpreter's version. ## Two tests, and what each one cannot see `TestShimVersionIsTheRuntimesNotASecondCopy` asserts the equality through the **real shim** rather than by matching the file's text, because what matters is not how the line is spelled but what the constant holds at run time. `TestShimVersionGuardsResolveAtThatVersion` proves CUR_VERSION actually feeds `_version_in_range`: a guard at the running version keeps its example, one above it removes its example (removes, not skips — a block guard below the threshold deletes rather than counting, so the deliberately-failing example inside it contributes to no counter). ⛔ **The control, planted:** with the shim set back to a literal `CUR_VERSION = "9.9.9"`, the first test fails and names the disagreement (`expected "9.9.9" to == "3.4.1"`) — while **the second still passes**, because a guard at `>= RUBY_VERSION` is satisfied by any higher value. So the second test proves the wiring and the first proves the value; reading the second alone as the guard against a hardcode would be wrong, and the comment says so at the site. ## Not in this PR - The move to 4.0.x itself. #799 asks for it with the baseline **not** regenerated, so the ratchet names every file that shifts in both directions; that reading is only clean once missing capabilities have landed separately (#844 is the first). - `PLATFORMS = [:darwin, :bsd, :unix]`, three lines below and the same shape of defect — a hardcoded copy of something `RUBY_PLATFORM` already knows (#837). It is left alone deliberately: unlike this change it is **not** a no-op, it moves the population on the Linux lane, and it needs its own measurement. The documentation side is go-embedded-ruby/docs#41, which makes the stated version a checked claim and already recognises this derived spelling — so that guard does not break on the day this merges. Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
1 parent 30d788d commit 4d1a7fd

2 files changed

Lines changed: 86 additions & 1 deletion

File tree

‎internal/vm/rubyspec_shim_test.go‎

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,3 +246,64 @@ describe "TIME_TOLERANCE (mspec constant)" do
246246
end`
247247
assertShimResult(t, runShim(t, "", src), "pass=2 fail=0 error=0 skip=0")
248248
}
249+
250+
// ⛔ CUR_VERSION selects the POPULATION the whole conformance figure is counted
251+
// over, and it used to be a second hardcoded copy of what
252+
// kernel_introspect.go's `rubyVersion` already says (#799). They agreed, so
253+
// nothing was wrong on any given day; the defect was that half a version change
254+
// could land — the runtime bumped, the shim forgotten — and the gate would go on
255+
// measuring the old population while every page claimed the new version. Both
256+
// halves look right on their own, which is why nothing would have said so.
257+
//
258+
// This is the test that makes that state impossible to commit. It asserts the
259+
// equality through the REAL shim rather than by matching the file's text,
260+
// because the thing that matters is not how the line is spelled but what the
261+
// constant holds at run time.
262+
func TestShimVersionIsTheRuntimesNotASecondCopy(t *testing.T) {
263+
src := `
264+
describe "CUR_VERSION" do
265+
it "is the version this interpreter reports, not a second copy of it" do
266+
CUR_VERSION.should == RUBY_VERSION
267+
end
268+
end`
269+
assertShimResult(t, runShim(t, "", src), "pass=1 fail=0 error=0 skip=0")
270+
}
271+
272+
// And the constant has to actually GOVERN the guard: an equality that nothing
273+
// reads would satisfy the test above while the guards resolved against
274+
// something else entirely. mspec's chain is
275+
// guards/version.rb -> SpecGuard.ruby_version(:full) -> RUBY_VERSION
276+
// (guard.rb:41-52, at mspec b79c65e); here it is CUR_VERSION, and this proves
277+
// _version_in_range is fed by it.
278+
//
279+
// A guard AT the running version must keep its examples; one above it must
280+
// remove them — note "remove", not "skip": a block guard below the threshold
281+
// deletes the examples rather than counting them as skipped, so the failing
282+
// example inside the second block contributes nothing to any counter. If it
283+
// ever did run, `1.should == 2` makes that visible as fail=1 instead of a
284+
// silently absent example.
285+
//
286+
// ⛔ WHAT THIS ONE CANNOT SEE, measured by planting it: with the shim set back
287+
// to a literal `CUR_VERSION = "9.9.9"`, this test still PASSES — a guard at
288+
// `>= RUBY_VERSION` is satisfied by any higher value and `"99.0"` still removes
289+
// its block. Only the test above catches that, and it did, naming the
290+
// disagreement (`expected "9.9.9" to == "3.4.1"`). So this test proves the
291+
// WIRING and the one above proves the VALUE; neither substitutes for the other,
292+
// and reading this one alone as the guard against a hardcode would be wrong.
293+
func TestShimVersionGuardsResolveAtThatVersion(t *testing.T) {
294+
src := `
295+
describe "version guards" do
296+
ruby_version_is RUBY_VERSION do
297+
it "keeps an example guarded at exactly the running version" do
298+
1.should == 1
299+
end
300+
end
301+
302+
ruby_version_is "99.0" do
303+
it "removes an example guarded above it" do
304+
1.should == 2
305+
end
306+
end
307+
end`
308+
assertShimResult(t, runShim(t, "", src), "pass=1 fail=0 error=0 skip=0")
309+
}

‎scripts/conformance/rubyspec/spec_helper.rb‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,31 @@ class SpecSkip < Exception; end
1919
$mock_registry = nil
2020
$mock_installs = nil
2121

22-
CUR_VERSION = "3.4.1"
22+
# ⛔ DERIVED, never typed again (#799). This selects the POPULATION the whole
23+
# conformance figure is counted over: at 3.4.1 every example behind a
24+
# `ruby_version_is "4.0"` guard is removed from the suite before anything runs
25+
# -- 61 block guards and 5 inline sites at that boundary, and 41 guards
26+
# asserting what 4.0 changed away from (censused by cmd/guards).
27+
#
28+
# It used to read `"3.4.1"`, a second hardcoded copy of what
29+
# internal/vm/kernel_introspect.go's `rubyVersion` already says. They agreed, so
30+
# nothing was wrong today; the defect was that half a version change could land
31+
# -- the runtime bumped, this file forgotten -- and the gate would go on
32+
# measuring the old population while every page claimed the new version. Both
33+
# halves look correct on their own, which is why nothing would have said so.
34+
#
35+
# Reading RUBY_VERSION is also what mspec itself does, so this is the upstream
36+
# behaviour rather than a local convenience. The chain, at mspec b79c65e:
37+
#
38+
# guards/version.rb:67 VersionGuard.new(VersionGuard::FULL_RUBY_VERSION, …)
39+
# guards/version.rb:6 FULL_RUBY_VERSION = SpecVersion.new SpecGuard.ruby_version(:full)
40+
# guards/guard.rb:41 def self.ruby_version(which = :minor)
41+
# guards/guard.rb:51 RUBY_VERSION.split('.')[0,n].join('.') # n = 3 for :full
42+
#
43+
# i.e. RUBY_VERSION itself for a three-part version. Run under a different
44+
# interpreter, the shim then measures at THAT interpreter's version, which is the
45+
# only answer that is ever right.
46+
CUR_VERSION = RUBY_VERSION
2347
PLATFORMS = [:darwin, :bsd, :unix]
2448
WORDSIZE = 64
2549
ENDIAN = :little

0 commit comments

Comments
 (0)