Skip to content

Commit 728ec91

Browse files
committed
Add overflow-boundary ordering specs for ContinuousBuildCodeFormatter
Lock in the documented guarantee that ordering holds when the build number exceeds 10^build_digits (overflow only costs human-readability, not ordering), and guard against a future regression such as masking the build number with `% 10**build_digits`.
1 parent 25146e6 commit 728ec91

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

spec/continuous_build_code_formatter_spec.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,35 @@
3434
end
3535
end
3636

37+
# The build number is allowed to exceed 10^build_digits. The docstring guarantees ordering still
38+
# holds in that case (overflow "only costs human-readability, not ordering") *because* the build
39+
# number is globally monotonic. These lock that in — and guard against a future change such as
40+
# masking the build number with `% 10**build_digits`, which would silently break ordering.
41+
context 'when the build number overflows its reserved digits (10^build_digits)' do
42+
it 'still increases within the same version across the overflow boundary' do
43+
formatter = described_class.new(build_digits: 4) # 10^4 = 10_000
44+
# 269 * 10_000 + 10_000 = 2_700_000 vs 269 * 10_000 + 9_999 = 2_699_999
45+
expect(formatter.build_code(major: 26, minor: 9, build_number: 10_000))
46+
.to be > formatter.build_code(major: 26, minor: 9, build_number: 9_999)
47+
end
48+
49+
it 'still increases across a version bump while both build numbers are past the overflow point' do
50+
formatter = described_class.new(build_digits: 4) # 10^4 = 10_000
51+
# 270 * 10_000 + 25_001 = 2_725_001 vs 269 * 10_000 + 25_000 = 2_715_000
52+
expect(formatter.build_code(major: 27, minor: 0, build_number: 25_001))
53+
.to be > formatter.build_code(major: 26, minor: 9, build_number: 25_000)
54+
end
55+
56+
it 'can render identically to a later version once overflowed — the documented readability cost, which is harmless under a monotonic build number' do
57+
formatter = described_class.new(build_digits: 4) # 10^4 = 10_000
58+
# Overflow makes the digits ambiguous: 26.9 build 10_000 and 27.0 build 0 both come out as 2_700_000.
59+
# That's the "only costs human-readability" caveat — and it's safe because a globally monotonic
60+
# build number means (27, 0, build: 0) never *follows* (26, 9, build: 10_000); the counter only goes up.
61+
expect(formatter.build_code(major: 26, minor: 9, build_number: 10_000))
62+
.to eq(formatter.build_code(major: 27, minor: 0, build_number: 0))
63+
end
64+
end
65+
3766
describe 'validation' do
3867
it 'raises when minor is greater than 9' do
3968
expect { described_class.new.build_code(major: 26, minor: 10, build_number: 1) }

0 commit comments

Comments
 (0)