feat(adr-0244): Phase 5c — §2.10 scheduler quasi-periodicity audit

Pin the load-bearing §2.10 claim, not just the structure. The existing
test_adr_0242_fibonacci_word.py covers recurrence/length/sovereignty; §2.10's
actual promise is "reduce harmonic phase-locking," which comes from the Fibonacci
word's Sturmian properties. tests/test_adr_0244_scheduler_quasiperiodicity.py (32
cases) pins:

- golden-ratio letter density (count(A)=F_n, count(B)=F_{n-1}; A/B → φ) — a
  maximally-irrational duty cycle resists resonance with periodic cadences;
- no harmonic clustering (no "BB", no "AAA") — neither action forms a locally
  periodic burst;
- aperiodicity (no period p ≤ |W|/2) — genuinely quasi-periodic, not a disguised
  periodic schedule.

A future refactor to a periodic schedule would pass the structure tests but fail
these. Audit-only; no production change (the module already satisfies the spec).

Verified: 32 new cases pass. Full smoke + fast lane at Phase 5 close.
This commit is contained in:
Shay 2026-07-17 19:51:34 -07:00
parent 4a550c1d03
commit eacea087b2

View file

@ -0,0 +1,61 @@
"""ADR-0244 §2.10 — the Fibonacci-word scheduler actually reduces phase-locking.
The existing `test_adr_0242_fibonacci_word.py` pins the *structure* (recurrence,
length, sovereignty). This audit pins the *load-bearing spec claim*: §2.10 says
the schedule is chosen "to reduce harmonic phase-locking with external batching /
eval fixtures / compiler cadences." That property is not free — it comes from the
Fibonacci word being a Sturmian sequence with golden-ratio letter density and no
short-scale clustering. If a future refactor swapped the recurrence for something
periodic, structure tests might still pass while the anti-phase-locking guarantee
silently died; these tests fail first.
"""
from __future__ import annotations
import pytest
from core.physics.fibonacci_word_schedule import fibonacci_word, word_length
_PHI = (1.0 + 5.0**0.5) / 2.0
def _fib(k: int) -> int:
a, b = 0, 1
for _ in range(k):
a, b = b, a + b
return a
@pytest.mark.parametrize("n", range(2, 16))
def test_letter_density_is_the_golden_ratio(n: int):
# count(A) = F_n, count(B) = F_{n-1}; A/B → φ. A maximally-irrational duty
# cycle is what avoids resonance with any periodic external cadence.
w = fibonacci_word(n)
assert w.count("A") == _fib(n)
assert w.count("B") == _fib(n - 1)
assert len(w) == word_length(n)
def test_ratio_converges_to_phi():
w = fibonacci_word(15)
assert abs(w.count("A") / w.count("B") - _PHI) < 1e-4
@pytest.mark.parametrize("n", range(2, 18))
def test_no_harmonic_clustering(n: int):
# The high-cost B check never bunches (no "BB"); low-cost A runs are bounded
# at 2 (no "AAA"). Both are classic Fibonacci-word properties and are exactly
# what "reduce harmonic phase-locking" means operationally: neither action
# forms a locally periodic burst.
w = fibonacci_word(n)
assert "BB" not in w
assert "AAA" not in w
def test_word_is_aperiodic():
# A long Fibonacci word has no period p ≤ |W|/2 — it is genuinely
# quasi-periodic, not a disguised periodic schedule.
w = fibonacci_word(16)
length = len(w)
for p in range(1, length // 2 + 1):
assert not all(w[i] == w[i + p] for i in range(length - p)), f"period {p}"