diff --git a/docs/ci-verification.md b/docs/ci-verification.md index 63ba3e9aa8..52b62d0481 100644 --- a/docs/ci-verification.md +++ b/docs/ci-verification.md @@ -1,8 +1,25 @@ # CI verification -## Current selected-family replay: #6030 +## Current selected-family replay: #7000 with #7001 The [selected record](../certificates/selected-result.json) binds conditional +κ = 0.00363005817 to the [application review](research/pr-intake-evidence/pr7000-application/PROOF-REVIEW.md), +[validation receipts](research/pr-intake-evidence/pr7000-application/VALIDATION.json), +and [explicit source closure](../certificates/frontier7000-source.json). +`make frontier7000-verify` follows that exact-source selected replay. The review +reuses eleven authenticated preceding executions and records seven fresh serial +application, scalar and complete native-catalogue executions. The earlier +monolithic timeout is retained separately and is not completed coverage. +Consult the receipts for exact commands, source heads and limits. + +The five inherited framework assumptions remain. No complete uniform word, +literal multiplier execution, independent human proof or formal-kernel proof +is asserted. Routine research submissions do not need to rerun this +selected-family replay. The sections below preserve historical checkpoints. + +## Historical selected-family replay: #6030 + +The [historical checkpoint](../certificates/checkpoints/frontier6030.json) binds conditional κ = 0.003125804 to the [proof review](research/pr-intake-evidence/pr6030-audit/PROOF-REVIEW.md), [validation receipts](research/pr-intake-evidence/pr6030-audit/VALIDATION.json), and [explicit source closure](../certificates/frontier6030-source.json). diff --git a/research/dense-quadratic-phase-stream/PROOF.md b/research/dense-quadratic-phase-stream/PROOF.md new file mode 100644 index 0000000000..5203bad64e --- /dev/null +++ b/research/dense-quadratic-phase-stream/PROOF.md @@ -0,0 +1,177 @@ +# A restored cofactor stream for dense quadratic phases + +This scoped constructive proof was produced by Nick Petalas. Apache-2.0. + +## Proposition and accounting model + +Let L be any nonnegative integer, N=2^L, and let all coefficients below +belong to Z/4. On Boolean arguments define + +```text +q(x) = c + sum_i a_i x_i + sum_(i0, the zero branch and then the one branch cover the two consecutive +binary-address halves exactly once. Each child restores its entry state, +and the explicit subtractions restore the parent's entry state. No +zero-initialization of the coefficient values is used. Every entry residue, +including the constant, may be arbitrary. The event storage itself is newly +allocated bookkeeping, not arbitrary dirty workspace supplied for free. + +For a Gaussian phase, the emitted q is interpreted as i^q. The proof keeps +the constant c and hence absolute phase. General Z/4 cross coefficients are +allowed. Restricting cross coefficients to 0 and 2 gives the usual Boolean +quadratic Clifford phase subclass. This inclusion does not establish that +every general phase in the larger class is a native Clifford operation. + +## Nonrecursive execution and exact counts + +An event is visit(j), enter-one(j) or leave-one(j). Expanding visit(j), j>0, +schedules the following chronological sequence on a last-in-first-out stack: + +```text +visit(j-1), enter-one(j), visit(j-1), leave-one(j). +``` + +The reference pushes these in reverse order. A leaf emits a single residue. +The complete binary tree has N leaves and N-1 internal vertices. Each +internal vertex contributes one visit and two update events. Thus the exact +number of processed events is N+3(N-1)=4N-3. This supplies an explicit loop +bound; no recursive Python call is used. + +There are 2^(L-j) internal vertices with j free bits. Each executes j updates +on entry to its one branch and j on exit. Therefore + +```text +U_L = 2 sum_(j=1..L) j 2^(L-j) + = 4*2^L - 2L - 4. +``` + +For example the identity follows from U_0=0 and U_L=2U_(L-1)+2L. +It proves fewer than four arithmetic updates per emitted phase, uniformly +in L. The linear-coefficient updates, and hence quadratic coefficient reads, +number + +```text +R_L = 2 sum_(j=1..L) (j-1) 2^(L-j) + = 2(2^L-L-1). +``` + +Each initial descent through an internal visit replaces one pending event by +four, increasing stack length by three. The first leaf therefore reaches +exactly 3L+1 pending events immediately before its visit. No later descent +can exceed it: at most three pending siblings/update events remain at each +ancestor level, plus the current visit. This also covers L=0, when the sole +pending event is visit(0). + +There are 2(N-1) reads of the current top linear coefficient for constant +updates, R_L reads of current lower linear coefficients, and U_L writes of +current residues. These are abstract array accesses. Their movement on a +fixed tape, the binary representation of levels, source serialization and +output-consumer costs are not certified here. + +Every implementation which explicitly emits N phase symbols requires at +least N output actions in a unit-output model. This construction has +O(L^2+N) abstract work, including initialization, and is order-optimal in +that model. The exact arithmetic constant is an upper bound, not a proved +minimum. No fixed-tape order-optimality follows. + +## The completed-return boundary + +Python yields at each leaf. After the last yield, the remaining leave-one +events still need execution. The return theorem therefore requires complete +iterator exhaustion, including the call that observes StopIteration. +Merely requesting exactly N yielded values does not meet that condition. +The verifier exercises this distinction. If a consumer stops early, cleanup +of the suspended stream's private cofactor state is unclaimed. Immutable +public input tuples are preserved at every prefix regardless. + +The mathematical construction works for every L. The supplied reference +intentionally validates 0<=L<=20 to bound executable memory and iteration +counts. Its finite checks establish only their enumerated cases; the +induction and sums above establish the quantified proposition. + +## Predecessors, new scope and remaining work + +Ali Romman's [#5375](https://github.com/CrocSwap/integer-mult-bounds/pull/5375) +supplies the physical sequential monomial phase producer, with fixed recipe +dimension, borrowed mask, complete counter and coefficient bills. Its +source-specific correctness and bills are cited results, not replayed here. +That package credits Jose Manuel / jmbarrancoml #2250, JoyboyBrian #5329, +Cinna Davis and Ryanson Jonathan #4325, together with their native lineage. +Their results and notices retain their attribution. + +Dugongue's [#4538](https://github.com/CrocSwap/integer-mult-bounds/pull/4538), +Theorem 2, already proves O(N+L) phase generation when cross coefficients +are even. Its representation packs the binary matrix columns and gradient +into address-width words, using one whole-gradient XOR per bit flip. +Ryanson Jonathan #4555 supplies a separate finite check of that theorem. +The published theorem is a cited predecessor, not a replay target. + +The new project contribution covers arbitrary Z/4 cross coefficients, +including odd coefficients, gives an exact count of individual unpacked +residue updates, and restores the cofactor state explicitly. It does not +claim the first linear-time phase stream or a faster packed-word algorithm. +Polynomial cofactoring and Shannon expansion are classical; no +literature-priority claim is made for those methods. We do not claim that +the input-matrix representation improves #5375's physical implementation. + +The three frozen predecessor documents are hashed live context inputs. No +predecessor executable is imported, and no selected source is changed. +Native recipe acquisition, fixed-tape source access and control, output +rotation, affine routing, common-grid/rounding, owned storage, the complete +caller invoice and all five multiplication-framework assumptions remain. +There is no new kappa, supplier admission or complete multiplication theorem. diff --git a/research/dense-quadratic-phase-stream/README.md b/research/dense-quadratic-phase-stream/README.md new file mode 100644 index 0000000000..8d53267776 --- /dev/null +++ b/research/dense-quadratic-phase-stream/README.md @@ -0,0 +1,114 @@ +# Dense quadratic phase streams with restored coefficients + +This contribution was produced by Nick Petalas. Apache-2.0. + +Claim type: scoped constructive written proof with exact finite corroboration. +For every L>=0, a supplied dense quadratic polynomial q on L Boolean address +bits, with coefficients in Z/4, can emit its N=2^L phases in binary-address +order using exactly + +```text +4N - 2L - 4 residue additions/subtractions, +2(N - L - 1) quadratic-coefficient reads, +4N - 3 control events, and at most 3L + 1 pending event records. +``` + +The current constant and L linear coefficients return to their entry values +after iterator exhaustion. The construction stores no N-entry phase table. +The supplied coefficient matrix uses O(L^2) bits; event records use +O(L log(L+2)) bits. Input validation and linear copying add +O(L^2) abstract work. [PROOF.md](PROOF.md) proves the all-L statement. +[stream.py](stream.py) is a nonrecursive bounded reference for L<=20. + +The new project result allows arbitrary Z/4 cross coefficients, including +odd coefficients, with fewer than four unpacked residue updates per emitted +phase and an explicit completed-return contract. Dugongue's +[#4538](https://github.com/CrocSwap/integer-mult-bounds/pull/4538), Theorem 2, +already gives O(N+L) packed-word phase generation for even cross coefficients. +We do not claim the first linear phase stream. The new exact bill uses +individual small residues and no packed gradient-word operations. +Ali Romman's [#5375](https://github.com/CrocSwap/integer-mult-bounds/pull/5375) +supplies the predecessor physical stream for fixed recipe dimension. Its +scientific executables and previous counts are not replayed. Polynomial +cofactoring and Shannon expansion are classical, with no literature-priority +claim here. This does not compare the new arithmetic count with the +predecessor's physical tape-action bill. + +## Evidence and scope + +The independent direct-polynomial expression agrees with the stream on every +coefficient choice through L=3: 16,660 cases and 132,132 output residues. +Another 72 generated fixtures at L=4..12 compare 65,408 output residues. +The zero polynomial at the L=20 capacity boundary emits all 1,048,576 phases +and executes 4,194,260 updates, with 4,194,301 events and stack peak 61. +Nine invalid-domain and six semantic/return controls pass. These counts +are enumerated by [verify.py](verify.py), which also checks three source +document hashes and emits a receipt bound to all seven package files. +The direct oracle was written with this package; it is not independent +human or formal proof-kernel acceptance. + +The input tuples remain immutable at every prefix. Restoring the private +cofactor state requires complete iterator exhaustion, including the call +that observes StopIteration after the last output. Early-abandonment cleanup, +literal tape lowering, input-matrix acquisition, output rotation, affine +routing, native ownership, rounding and the complete physical caller invoice +remain open. An input table may cost more than a fixed compiled recipe. +There is no new kappa, supplier admission, selected-frontier change or +complete multiplication theorem. + +## Reproduce + +From the repository root with the CPython 3.12 standard library: + +```sh +/Users/nick/git/integer-mult-bounds/.venv/bin/python3.12 -B scripts/research_package.py --package research/dense-quadratic-phase-stream +/Users/nick/git/integer-mult-bounds/.venv/bin/python3.12 -B -W error research/dense-quadratic-phase-stream/verify.py +/Users/nick/git/integer-mult-bounds/.venv/bin/python3.12 -B -O -W error research/dense-quadratic-phase-stream/verify.py +/Users/nick/git/integer-mult-bounds/.venv/bin/python3.12 -B scripts/check_research_commit.py --package research/dense-quadratic-phase-stream --check-modes --check-source-history +``` + +Both registered commands must print `PASS_DENSE_QUADRATIC_PHASE_STREAM`. +The source-pin wrapper needs Git history; direct verification also works in +an official Git-free export containing the three declared input documents. +No command writes a receipt or cache into the checkout. Environment metadata +is in [TASK.json](TASK.json). Hosted CI is separate from local evidence. + +## Open next questions + +- Can a fixed finite tape program realize the stream with a complete source + access and retirement bill? Start with a triangular serialized coefficient + layout and every access/return at L=4. No literal machine graph is supplied. +- Can one actual native recipe supply this coefficient table and consume the + phases affordably? Pin a recipe, derive the table preparation and output + contract, and compare the complete bill. Acquisition, storage and rotation + are current blockers. + +## Credit + +Credit Ali Romman #5375 for the physical phase-stream interface; retain +Jose Manuel / jmbarrancoml #2250, JoyboyBrian #5329, Cinna Davis, +Ryanson Jonathan #4325 and the original native/Clifford lineage. Credit +Dugongue #4538 for the prior packed-word theorem and Ryanson Jonathan +#4555 for its separately published finite check. Neither checker is replayed. +[SOURCES.json](SOURCES.json) pins the unchanged predecessor context at +canonical main e54523517d0f03e58352e647c403a5af3e525a57. No predecessor +construction is used as the new main step. The exact card is retained in +TASK.json and explicitly changes scope to this algebraic side result. + +## Implementation bounds + +All functions are below 60 physical lines. Production loops have explicit +bounds from L<=20, at most 4,194,301 events and at most 61 pending records. +There is no recursion, generated code, subprocess, network call or output +file write. State belongs to one generator and its caller-owned meter. +Exceptions propagate; normal and optimized executions enforce the same +contracts. Direct file reads cover seven small package files and at most +three source documents bounded by one MiB apiece. + +Python allocates tuples, integers and lists during execution. Validated +dimension, bounded stack and +the explicit event cap bound live state; the reference cannot accept an +unbounded input. A fixed-buffer runtime would be needed before claiming +allocation-free operation. Standard generator and SHA256 object dispatch +have fixed visible targets. Warning-strict normal/optimized execution and +in-memory compilation supply diagnostics. diff --git a/research/dense-quadratic-phase-stream/SOURCES.json b/research/dense-quadratic-phase-stream/SOURCES.json new file mode 100644 index 0000000000..eb0d2fa445 --- /dev/null +++ b/research/dense-quadratic-phase-stream/SOURCES.json @@ -0,0 +1,36 @@ +{ + "schema_version": 1, + "base_commit": "e54523517d0f03e58352e647c403a5af3e525a57", + "files": [ + { + "path": "certificates/selected-result.json", + "usage": "provenance", + "git_blob": "75d77b328ea02ded535e7f23aee5b1e55d0bb1a8", + "sha256": "154c3d30455d778fd3343b6b4851f0fa4665f0f7625b0adb3675e2bafbbf6bf1" + }, + { + "path": "docs/research/agent-task-catalog.json", + "usage": "provenance", + "git_blob": "3404fbdd5e7529a0674eef26114b5071e4586cec", + "sha256": "ead6cdc9d0af6d58e8a49744d8ec8c7c15e13d2ba93c276c434bcf9b51b93a81" + }, + { + "path": "research/sequential-monomial-phase/PROOF.md", + "usage": "input", + "git_blob": "42ffd4007c1416eb4a45e47d181194d3e87742bb", + "sha256": "aed63dc425a410627a290b2e0251b27bc1befce85614cefbb8a82f199a1d2764" + }, + { + "path": "research/sequential-monomial-phase/README.md", + "usage": "input", + "git_blob": "0ca3d57c2baa7161b1c8534ffd74c2bb640c815c", + "sha256": "e69fbf8f61b1d212be69ce5fe6f31c816bec497f8dd5b895d6b709127ca8f511" + }, + { + "path": "research/word-ram-transfer/cost/COST-THEOREMS.md", + "usage": "input", + "git_blob": "a5d940b20581ff2ddfd270026d5610cdb7ee4581", + "sha256": "79eef859eb2ae32a66879f294d626c3947bcfe55434b4a38a296d271b3aa9675" + } + ] +} diff --git a/research/dense-quadratic-phase-stream/TASK.json b/research/dense-quadratic-phase-stream/TASK.json new file mode 100644 index 0000000000..c6fb1e1263 --- /dev/null +++ b/research/dense-quadratic-phase-stream/TASK.json @@ -0,0 +1,115 @@ +{ + "schema_version": 1, + "task_id": "formal-interface-lemma", + "priority_revision": 8, + "base_commit": "e54523517d0f03e58352e647c403a5af3e525a57", + "original_card": { + "id": "formal-interface-lemma", + "question": "Can one uncovered interface implication be formalized with exact caller and certificate bindings?", + "starting_points": [ + "docs/research/research-family-status.md", + "certificates/selected-result.json", + "research/gate-operand-parity-lean/README.md", + "research/staged544-certified-endpoint/README.md", + "research/unconditional-batched-crt/README.md" + ], + "methods": [ + "Formalize a missing boundary lemma identified by the selected review.", + "Audit a formal theorem-to-certificate binding independently." + ], + "acceptance_gate": "State the exact formalized proposition and remaining assumptions; avoid duplicate arithmetic formalizations already present.", + "first_step": { + "command": [ + "python3", + "-B", + "scripts/research_selected_baseline.py" + ], + "expected": "PASS_RESEARCH_BASELINE_BINDINGS_ONLY", + "inspect": "Resolve the current selected review, separate complex/ordinary BIT/admitted BIT/outer budgets, and compare the card against live handoffs before starting. Historical ceilings require exact source/model equivalence.", + "scope": "Source-binding orientation only; not a scientific replay or all-size proof. Materialize selected inputs if this checkout is sparse." + }, + "first_experiment": "Write one missing statement with quantified hypotheses, actual caller and existing coverage. A compact-switch lemma is a candidate only after its mathematical contract is reviewed. Establish a bounded proof plan before a separately budgeted proof-assistant build; do not rerun large Lean jobs as orientation.", + "bottleneck_link": "A missing interface proof can reduce the conditional gap even if it does not change kappa.", + "allowed_variations": [ + "Narrow to one formal lemma or one theorem-to-certificate binding." + ], + "scope_change_triggers": [ + "Formalizing already-covered arithmetic and claiming the full multiplication theorem." + ], + "overlap_terms": [ + "hyperplane end", + "formal interface", + "Lean binding", + "3807", + "3857", + "4100", + "gate-operand-parity-lean", + "staged544-certified-endpoint", + "unconditional-batched-crt" + ], + "existing_checks": [ + { + "scope": "PR #3807: scoped gate-operand parity formalization.", + "evidence": "research/gate-operand-parity-lean/README.md", + "remaining": "Exact theorem-to-caller binding and genuinely uncovered interface lemmas.", + "status": "author-checked", + "source_commit": "4c3530f42a6abcc48e7a6bcffd6c901911dc8269", + "selected_record_sha256": "bb2eaa58647b353f88d0aec2eafb9d30df1be53589231b23e12ceef3e4bad129" + }, + { + "scope": "PR #3857: certified real-power moment/endpoint arithmetic.", + "evidence": "research/staged544-certified-endpoint/README.md", + "remaining": "Uniform algorithmic implications, not another endpoint digit.", + "status": "author-checked", + "source_commit": "ef4315b8caa605e47a2515004845eb2d2ed71a86", + "selected_record_sha256": "bb2eaa58647b353f88d0aec2eafb9d30df1be53589231b23e12ceef3e4bad129" + }, + { + "scope": "PR #4100: compact-switch formalization proposed as future validation.", + "evidence": "research/unconditional-batched-crt/README.md", + "remaining": "Audit the statement and assumptions before a formal proof campaign.", + "status": "author-checked", + "source_commit": "337d04939571a637aeab54a0f58f54fde811663a", + "selected_record_sha256": "bb2eaa58647b353f88d0aec2eafb9d30df1be53589231b23e12ceef3e4bad129" + } + ] + }, + "scope_status": "changed", + "actual_scope": "Written all-L construction for lexicographic dense Z/4 quadratic phases with arbitrary, including odd, cross coefficients; exact unpacked residue/event/read counts and cofactor restoration; bounded reference with direct-polynomial corroboration.", + "scope_change_reason": "Changes the formalization card to an algebraic phase-production side result. No proof-assistant or selected-caller binding is claimed. The predecessor fixes recipe dimension; this construction permits a supplied dense variable-dimension coefficient table.", + "bottleneck_link": "A phase producer is a component of native monomial service. This supplies a more general algebraic stream with a uniform arithmetic bound; fixed-tape lowering and a fully charged actual consumer remain separate.", + "budget_minutes": 60, + "stop_rule": "Stop at the first proved streaming construction and direct exact check. Package it without further construction or optimization.", + "outcome": "completed", + "evidence": "PROOF.md gives the cofactor induction and exact counts. verify.py compares the stream with a separately expressed direct polynomial oracle, exhausts all Z/4 quadratics through L=3, exercises L=4..12 and the L=20 capacity boundary, and checks three source-document hashes and rejection/return controls.", + "author": "Nick Petalas", + "ai_assistance": "Independent human and formal proof-kernel review are unclaimed.", + "open_questions": [ + { + "question": "Can a fixed finite tape program realize the cofactor stream with a complete source-access, level-control and retirement bill?", + "why_it_matters": "The uniform arithmetic count alone cannot replace the physical phase producer in a supplier invoice.", + "first_step": "Specify a triangular serialized coefficient layout and bound every access and return for L=4 before any larger lowering.", + "blocked_by": "No literal machine graph or complete physical cost certificate is supplied." + }, + { + "question": "Can one actual native recipe be supplied in this representation without coefficient preparation or storage consuming the benefit?", + "why_it_matters": "The dense input matrix trades stronger recipe generality for quadratic input storage.", + "first_step": "Choose one exact recipe head and derive its coefficient-table construction and output-consumer contract.", + "blocked_by": "Acquisition, output rotation, native binding and a complete matched caller bill remain unproved." + } + ], + "coordination": { + "source_pr": 5375, + "source_author": "aliromman", + "claim_url": "https://github.com/CrocSwap/integer-mult-bounds/discussions/1166#discussioncomment-19591502", + "source_context": "Three unchanged source documents at the canonical base; predecessor executables are not imported or replayed. The source phase interface motivates the question; the new main step does not reuse another contributor's construction.", + "overlap": "Live open PRs and handoffs checked; full cached snapshot covers 800 open PRs and 7404 Discussion records. Local overlap helper searches 213 of 10178 HEAD note paths; canonical-main grep searches supplement omissions. Filtered source helper remote refresh failed, so a direct live recent-account PR-body query was used and contained no 5375 reference. All searches remain advisory.", + "prior_general_n_result": "Dugongue #4538 Theorem 2 already gives O(N+L) packed-word phase generation for even cross coefficients. The present result does not claim the first linear stream. Its new deliverable is arbitrary Z/4 cross coefficients, an unpacked small-residue arithmetic bill, and exact cofactor restoration. Source theorem read and pinned; its checker was not replayed." + }, + "environment": { + "python": "CPython 3.12.15", + "platform": "macOS 27.0.1 arm64", + "dependencies": "standard library only", + "interpreter": "/Users/nick/git/integer-mult-bounds/.venv/bin/python3.12" + } +} diff --git a/research/dense-quadratic-phase-stream/VERIFY.json b/research/dense-quadratic-phase-stream/VERIFY.json new file mode 100644 index 0000000000..0f3a70651f --- /dev/null +++ b/research/dense-quadratic-phase-stream/VERIFY.json @@ -0,0 +1,36 @@ +{ + "schema_version": 1, + "status": "ready", + "python": "3.12", + "requirements": [], + "inputs": [ + "research/sequential-monomial-phase/PROOF.md", + "research/sequential-monomial-phase/README.md", + "research/word-ram-transfer/cost/COST-THEOREMS.md" + ], + "commands": [ + { + "argv": [ + "{python}", + "-B", + "-W", + "error", + "{package}/verify.py" + ], + "timeout_seconds": 120, + "checks": "Exact direct-polynomial comparison, restoration, arithmetic/event/read/space counts, complete L<=3 coefficient census, dense larger fixtures, capacity boundary and source/domain/semantic controls." + }, + { + "argv": [ + "{python}", + "-B", + "-O", + "-W", + "error", + "{package}/verify.py" + ], + "timeout_seconds": 120, + "checks": "The same complete finite checks with assertions disabled." + } + ] +} diff --git a/research/dense-quadratic-phase-stream/stream.py b/research/dense-quadratic-phase-stream/stream.py new file mode 100644 index 0000000000..2b80ead866 --- /dev/null +++ b/research/dense-quadratic-phase-stream/stream.py @@ -0,0 +1,81 @@ +"""Lexicographic Z/4 quadratic phases by reversible cofactoring. + +Rows of ``cross`` are strict lower triangular: cross[j][i] multiplies x_i*x_j. +The finite reference accepts at most 20 address bits. See PROOF.md for all L. +""" + +from typing import Iterator + +MAX_BITS = 20 + + +class Meter: + def __init__(self) -> None: + self.events = 0 + self.updates = 0 + self.matrix_reads = 0 + self.outputs = 0 + self.max_stack = 1 + self.restored = False + + +def require(condition: bool, message: str) -> None: + if not condition: + raise ValueError(message) + + +def validate(linear: tuple[int, ...], cross: tuple[tuple[int, ...], ...], + constant: int, meter: Meter) -> int: + require(type(linear) is tuple and type(cross) is tuple, "immutable tuples required") + n = len(linear) + require(n <= MAX_BITS and len(cross) == n, "dimension outside reference domain") + require(type(constant) is int and 0 <= constant < 4, "constant outside Z/4") + require(type(meter) is Meter, "meter type") + require((meter.events, meter.updates, meter.matrix_reads, meter.outputs, + meter.max_stack, meter.restored) == (0, 0, 0, 0, 1, False), + "fresh meter required") + for j in range(n): + require(type(cross[j]) is tuple and len(cross[j]) == j, "triangular shape") + for value in (linear[j], *cross[j]): + require(type(value) is int and 0 <= value < 4, "coefficient outside Z/4") + return n + + +def phase_stream(linear: tuple[int, ...], cross: tuple[tuple[int, ...], ...], + constant: int, meter: Meter) -> Iterator[int]: + """Yield q(0),...,q(2**L-1); exhausting the iterator restores its cofactors. + + This is a residue-operation model, not a fixed-tape implementation. + A caller that abandons the iterator has not completed the return contract. + """ + n = validate(linear, cross, constant, meter) + current = list(linear) + phase = constant + # visit=0, enter-one=1, leave-one=2. Lower-index bits vary fastest. + stack = [(0, n)] + for _ in range(4 * (1 << n) - 3): + require(bool(stack), "early event exhaustion") + action, j = stack.pop() + meter.events += 1 + if action == 0: + if j == 0: + meter.outputs += 1 + yield phase + else: + stack.extend(((2, j), (0, j - 1), (1, j), (0, j - 1))) + meter.max_stack = max(meter.max_stack, len(stack)) + else: + sign = 1 if action == 1 else -1 + phase = (phase + sign * current[j - 1]) % 4 + meter.updates += 1 + for i in range(j - 1): + current[i] = (current[i] + sign * cross[j - 1][i]) % 4 + meter.updates += 1 + meter.matrix_reads += 1 + require(not stack, "unconsumed events") + require(current == list(linear) and phase == constant, "cofactor restoration") + meter.restored = True + require(meter.outputs == 1 << n, "output census") + require(meter.updates == 4 * (1 << n) - 2 * n - 4, "arithmetic census") + require(meter.matrix_reads == 2 * ((1 << n) - n - 1), "matrix census") + require(meter.max_stack == 3 * n + 1, "stack census") diff --git a/research/dense-quadratic-phase-stream/verify.py b/research/dense-quadratic-phase-stream/verify.py new file mode 100644 index 0000000000..952ccc7ade --- /dev/null +++ b/research/dense-quadratic-phase-stream/verify.py @@ -0,0 +1,172 @@ +"""Finite exact checks, with a direct-polynomial oracle and generated hashes.""" + +import hashlib +import itertools +import json +from pathlib import Path + +from stream import MAX_BITS, Meter, phase_stream + + +def check(condition: bool, message: str) -> None: + if not condition: + raise RuntimeError(message) + + +def polynomial(code: int, linear: tuple[int, ...], + cross: tuple[tuple[int, ...], ...], constant: int) -> int: + bits = tuple((code >> i) & 1 for i in range(len(linear))) + result = constant + sum(a * x for a, x in zip(linear, bits)) + for j, row in enumerate(cross): + result += sum(a * bits[i] * bits[j] for i, a in enumerate(row)) + return result % 4 + + +def unpack(n: int, coefficients: tuple[int, ...]) -> tuple: + constant = coefficients[0] + linear = coefficients[1:n + 1] + cross = [] + position = n + 1 + for j in range(n): + cross.append(coefficients[position:position + j]) + position += j + check(position == len(coefficients), "coefficient cursor") + return linear, tuple(cross), constant + + +def one_case(linear: tuple, cross: tuple, constant: int, digest) -> tuple[int, int]: + meter = Meter() + original = (linear, cross, constant) + count = 0 + for code, phase in enumerate(phase_stream(linear, cross, constant, meter)): + check(phase == polynomial(code, linear, cross, constant), "direct polynomial") + digest.update(bytes((phase,))) + count += 1 + check(meter.restored and original == (linear, cross, constant), "return contract") + check(meter.events == 4 * count - 3, "event census") + return count, meter.updates + + +def exhaustive(digest) -> dict: + cases = outputs = updates = 0 + for n in range(4): + size = 1 + n + n * (n - 1) // 2 + for coefficients in itertools.product(range(4), repeat=size): + count, work = one_case(*unpack(n, coefficients), digest) + cases += 1 + outputs += count + updates += work + return {"cases": cases, "outputs": outputs, "updates": updates} + + +def dense_cases(digest) -> dict: + cases = outputs = updates = 0 + for n in range(4, 13): + size = 1 + n + n * (n - 1) // 2 + for seed in range(8): + coefficients = tuple((i * i + seed * i + seed + i // 3) % 4 + for i in range(size)) + count, work = one_case(*unpack(n, coefficients), digest) + cases += 1 + outputs += count + updates += work + return {"cases": cases, "outputs": outputs, "updates": updates} + + +def reject(args: tuple, label: str) -> None: + try: + list(phase_stream(*args)) + except ValueError: + return + raise RuntimeError("accepted invalid " + label) + + +def domain_controls() -> int: + used_meter = Meter() + used_meter.outputs = 1 + invalid = [ + ((1,), (), 0, Meter()), + ((1,), ((0,),), 0, Meter()), + ((True,), ((),), 0, Meter()), + ((1,), ((),), 4, Meter()), + ((1,), ((),), True, Meter()), + ([1], ((),), 0, Meter()), + ((0,) * (MAX_BITS + 1), ((),) * (MAX_BITS + 1), 0, Meter()), + ((1,), ((),), 0, used_meter), + ((1, 2), ((), (4,)), 0, Meter()), + ] + for index, args in enumerate(invalid): + reject(args, str(index)) + return len(invalid) + + +def semantic_controls() -> int: + linear, cross, constant = (1, 2, 3), ((), (1,), (3, 2)), 3 + correct = tuple(polynomial(x, linear, cross, constant) for x in range(8)) + alternatives = [ + tuple(polynomial(x, linear, cross, 0) for x in range(8)), + tuple(polynomial(x, (0, 0, 0), cross, constant) for x in range(8)), + tuple(polynomial(x, linear, ((), (0,), (0, 0)), constant) for x in range(8)), + tuple(polynomial(x, linear, cross, constant) % 2 for x in range(8)), + tuple(polynomial(7 - x, linear, cross, constant) for x in range(8)), + ] + for candidate in alternatives: + check(candidate != correct, "semantic control did not discriminate") + meter = Meter() + partial = phase_stream(linear, cross, constant, meter) + for _ in range(8): + next(partial) + check(not meter.restored, "last yield is not completed exhaustion") + check(next(partial, None) is None and meter.restored, "final cleanup") + partial.close() + return len(alternatives) + 1 + + +def capacity_case() -> dict: + linear = (0,) * MAX_BITS + cross = tuple((0,) * j for j in range(MAX_BITS)) + meter = Meter() + count = 0 + for phase in phase_stream(linear, cross, 0, meter): + check(phase == 0, "capacity zero polynomial") + count += 1 + check(count == 1 << MAX_BITS and meter.restored, "capacity return") + return {"bits": MAX_BITS, "outputs": count, "updates": meter.updates, + "events": meter.events, "max_stack": meter.max_stack} + + +def source_bindings(package: Path) -> int: + manifest = package / "SOURCES.json" + check(manifest.stat().st_size <= 1024 * 1024, "manifest size") + rows = json.loads(manifest.read_text())["files"] + check(len(rows) <= 16, "source count") + count = 0 + root = package.parents[1] + for row in rows: + if row["usage"] != "input": + continue + source = root / row["path"] + check(source.stat().st_size <= 1024 * 1024, "source size") + check(hashlib.sha256(source.read_bytes()).hexdigest() == row["sha256"], + "source binding " + row["path"]) + count += 1 + return count + + +def main() -> None: + package = Path(__file__).resolve().parent + digest = hashlib.sha256() + report = {"exhaustive": exhaustive(digest), "dense": dense_cases(digest), + "domain_controls": domain_controls(), + "semantic_controls": semantic_controls(), "capacity": capacity_case(), + "source_bindings": source_bindings(package)} + report["phase_sha256"] = digest.hexdigest() + names = ("README.md", "PROOF.md", "SOURCES.json", "TASK.json", "VERIFY.json", + "stream.py", "verify.py") + report["files"] = {name: hashlib.sha256((package / name).read_bytes()).hexdigest() + for name in names} + print("PASS_DENSE_QUADRATIC_PHASE_STREAM " + json.dumps(report, sort_keys=True)) + + +if __name__ == "__main__": + main() diff --git a/research/historical-selected-replay-gap/README.md b/research/historical-selected-replay-gap/README.md index 55d8cc3b49..36d9a873ca 100644 --- a/research/historical-selected-replay-gap/README.md +++ b/research/historical-selected-replay-gap/README.md @@ -69,7 +69,11 @@ python3 -B scripts/research_package.py --package research/historical-selected-re The direct command prints `PASS_HISTORICAL_SELECTED_REPLAY_GAP`. A registered replay prints `PASS_REGISTERED_RESEARCH_PACKAGE`. Both require Git history -containing the two inspected commits. +containing the two inspected commits and the source and manifest objects at +`2485805a6d47f36ea83ddde6327d453ac82d44dc`. The verifier uses a temporary +sparse checkout of that commit, checks the declared source digests there, and +uses its planner and manifest inventory. The recorded rejections and selection +therefore remain reproducible after later changes to the live Makefile or CI guide. ## Open next questions diff --git a/research/historical-selected-replay-gap/SOURCES.json b/research/historical-selected-replay-gap/SOURCES.json index c1010eec95..62bb8b3950 100644 --- a/research/historical-selected-replay-gap/SOURCES.json +++ b/research/historical-selected-replay-gap/SOURCES.json @@ -4,13 +4,13 @@ "files": [ { "path": "Makefile", - "usage": "input", + "usage": "provenance", "git_blob": "0d683a06b9e7ee162496108ce9a7c5d2ee94fccf", "sha256": "4f2d4f2dcd15139ec82658a975f85ed300897385f85799218539f4c8d60567da" }, { "path": "certificates/partial-swap-network.json", - "usage": "input", + "usage": "provenance", "git_blob": "eccafa830c16170c36faf93045ddf1f638f7bcd4", "sha256": "4c0b9d37e1034b2076e30a70f8e514416298c462d9ee98bc87fe6556b14df786" }, @@ -22,7 +22,7 @@ }, { "path": "docs/ci-verification.md", - "usage": "input", + "usage": "provenance", "git_blob": "63ba3e9aa8bdc5e942b56e34244b92b16f854085", "sha256": "c7d3027e9ad8bcbff68f07aa9576b30fb2f3c76c44d876d40c7fdbf4a3e2228a" }, @@ -34,163 +34,163 @@ }, { "path": "research/clifford-state-performance/SOURCE.json", - "usage": "input", + "usage": "provenance", "git_blob": "6f98a0061a5104dfab82c9e806f819b41811f684", "sha256": "396d0f08df24952248140d5c65c51b8c902ef1c580892ff7ea182890530f67ee" }, { "path": "research/community-batch1047-audit/CONTENT-COVERAGE.json", - "usage": "input", + "usage": "provenance", "git_blob": "5e0f92af463ec12c5e1dcc3effd44081a88af647", "sha256": "07a9daeaf2bda308a92e9a4684f13d5fc766c7772d74801fceb7f4599fdab226" }, { "path": "research/community-batch1099-audit/CONTENT-COVERAGE.json", - "usage": "input", + "usage": "provenance", "git_blob": "9e13266bf85e627f1b7dc225e9530ea69fd2c7f0", "sha256": "421e1211fb1897c45621dc6801c276e53f2e6f335583c9c9049e535f87c0a3b1" }, { "path": "research/community-batch932-audit/CONTENT-COVERAGE.json", - "usage": "input", + "usage": "provenance", "git_blob": "cc4d03eb59b9ab3f952735f7e88ff18c2d15d7af", "sha256": "184629cac91a5cfaca50330a88596008b824221433867dcf8117539c913c284a" }, { "path": "research/community-batch970-audit/CONTENT-COVERAGE.json", - "usage": "input", + "usage": "provenance", "git_blob": "8b9f4111badf7de5d97684799560b55110e9da79", "sha256": "23188ed920e38a54006cb883e181585620821c63bf7e8b5e05d32719417cc37e" }, { "path": "research/community-frontier741-audit/CONTENT-COVERAGE.json", - "usage": "input", + "usage": "provenance", "git_blob": "a5300d4e7a5381a3f443fc54c768ca6f0f236d68", "sha256": "3c820fb30e1b4d9bcfc6a7ab524375e5b2abd66b940af2c509146104f0bcd79c" }, { "path": "research/community-frontier890-audit/CONTENT-COVERAGE.json", - "usage": "input", + "usage": "provenance", "git_blob": "d7ff6d777b01d69b6ce84caf25d3b7e4a4d2f211", "sha256": "6b185a9902652f893f3ebd8ada92d2f11b6de6533a9a4d11718a8a4496101128" }, { "path": "research/community-hyperplane599-audit/SOURCE.json", - "usage": "input", + "usage": "provenance", "git_blob": "546f37d326d10a99910ae8f908e71ef768524d98", "sha256": "65099d764bfcc39bda5e4d9966783611b094c3522dbdd1435cd498d657a8ef8e" }, { "path": "research/community-k492-audit/SOURCE.json", - "usage": "input", + "usage": "provenance", "git_blob": "e538481e4cb16ed936d3195f2dfb5b5a9ca0a76b", "sha256": "2c0f4fa5bc150d05658af2e7c54c4d2c337dd52b7efd3d69530ae73bcbdf452a" }, { "path": "research/community-reconciliation92-audit/MANIFEST.json", - "usage": "input", + "usage": "provenance", "git_blob": "2a2e93685173d5f13cbb5abe740f5d90352e0228", "sha256": "5f501f3c118131e7d069f30ad77186eb2ad6961f9680a0ef105f4514ed41808a" }, { "path": "research/partial-swap-digest/baseline.py", - "usage": "input", + "usage": "provenance", "git_blob": "a2f0190704db83bd8ef48e46e723c49b925804fe", "sha256": "81e9af92cdf38243a540cdcff2062778e449467848d444da37a9553c12ca4c34" }, { "path": "research/r420-two-sided-basis/SOURCES.json", - "usage": "input", + "usage": "provenance", "git_blob": "5d718e11e62f4bcadecf1e02d6b61f87dbe190b0", "sha256": "d9810b0d139c5a1211fd2c1f0d142187cc1fca30026e1e7bc4f9ecfacf1596d1" }, { "path": "research/skip-clones/SOURCE.json", - "usage": "input", + "usage": "provenance", "git_blob": "8d1bb3b9c8189e35e5d8bfdfa632d7473e8be0d5", "sha256": "0b68e63e35a97ce6b0cdb6e291b88ebaa8f2dd4afb70b2498f10ee89428258dc" }, { "path": "research/split-skip/SOURCE.json", - "usage": "input", + "usage": "provenance", "git_blob": "2ab610b6ea2edd2865fda793ef2168b0c76afb4f", "sha256": "7c2b4646a3ecfef6f881da5c43e4bd0fa9a4d1b00548b8ab458d897e16735134" }, { "path": "scripts/historical-ci-inputs/Makefile", - "usage": "input", + "usage": "provenance", "git_blob": "aff68409021c9d401a6f8013b9dfd7dbcc30f2a8", "sha256": "ea8830dd79da493e2d75baf753d733ff7efbcf2b4794afe41fae0ac8f3055646" }, { "path": "scripts/historical-ci-inputs/ledger-batch932-run_isolated_tests.py", - "usage": "input", + "usage": "provenance", "git_blob": "65db599ab0b1dea0312c4ca048e0bd0f44c3736f", "sha256": "96ea543e6c707424afe247e77bd86c82152f90fc76a0773c4232145da5cdf8d1" }, { "path": "scripts/historical-ci-inputs/ledger-batch932-test_isolated_test_runner.py", - "usage": "input", + "usage": "provenance", "git_blob": "34820a8f24678f918f4d0e7a35380d8013fc3495", "sha256": "628391b6abfbc8674ceec1751867a4392f2cc0b5b66886243e139af86cf355ac" }, { "path": "scripts/historical-ci-inputs/ledger-batch970-verify_selected_result.py", - "usage": "input", + "usage": "provenance", "git_blob": "c755b76e0d44ba4917aa94440ebe54daefce5b2a", "sha256": "d7fd929726b326aeeaf0a3996475adec88eee9aac09ae0bebeeaa0bc1fc8f199" }, { "path": "scripts/historical-ci-inputs/ledger-frontier741-ci-verification.md", - "usage": "input", + "usage": "provenance", "git_blob": "7f3c012504187917a728b9fe87043f0fc8cd006a", "sha256": "a854022e0e1d5d4db4d60e586be3ea56005013ef14a1fc06d02bc06e8529c4b0" }, { "path": "scripts/historical-ci-inputs/partial-swap-context.json", - "usage": "input", + "usage": "provenance", "git_blob": "ad65114886bf34a4fd27e79f3be502389e689faa", "sha256": "833a9642f33aeab2ffea17ec9c6b82e0a953f90192b2c82e10bef21538dccba9" }, { "path": "scripts/historical-ci-inputs/partial-swap-network.json", - "usage": "input", + "usage": "provenance", "git_blob": "52075f2463f60af5e16571347f24274fce73a1ea", "sha256": "f3c4be597b2f2136da4ae2cc80c7454f63c90aa01f84e5b8131cee4dd55de815" }, { "path": "scripts/partial_swap/shared.py", - "usage": "input", + "usage": "provenance", "git_blob": "44a0e454c70f9c4b98e258b8443612e6a119904b", "sha256": "5a0646a50b9f3e8ea55168620a78e8853b0ab810517cefc8cfb8696aedee278a" }, { "path": "scripts/replay_historical_check.py", - "usage": "input", + "usage": "provenance", "git_blob": "1e92fff2782970ef71378f594f2350d245a4db26", "sha256": "5467619c78183d3adc82b0cb55af28e5c1a01fca2b0588677816244b53e2bafd" }, { "path": "scripts/research_package.py", - "usage": "input", + "usage": "provenance", "git_blob": "091b4c8f58bac9a9580d76025b887dc5c873d05f", "sha256": "e1256016e7f51827d04fa2179255989f639ae1d97afaa9c16265f85a0c6abd70" }, { "path": "scripts/run_isolated_tests.py", - "usage": "input", + "usage": "provenance", "git_blob": "a96ab35b315ce492e7fbbfd6c5ae211aa066b541", "sha256": "49eb56dd0fc0d8d8ffdb209970a7adf2176223580646f575d5c22e59543b381c" }, { "path": "scripts/verify_selected_result.py", - "usage": "input", + "usage": "provenance", "git_blob": "6882a4700e410dec569b51ae2eaf1a19cc019195", "sha256": "d6b305eac5b9bdb8172c469ad30a1655a60fa0aceac8b1bf610e1b73f51babd8" }, { "path": "tests/test_isolated_test_runner.py", - "usage": "input", + "usage": "provenance", "git_blob": "343b24abf6719b81805eba5a84c74e57634c8288", "sha256": "3a5470d0b139828b90e19bf9583ddeafcd69f8e34f2824664eb3a2958a52e34d" } diff --git a/research/historical-selected-replay-gap/VERIFY.json b/research/historical-selected-replay-gap/VERIFY.json index 98553e72ed..ab7efa3471 100644 --- a/research/historical-selected-replay-gap/VERIFY.json +++ b/research/historical-selected-replay-gap/VERIFY.json @@ -4,36 +4,7 @@ "python": "3.12", "requirements": [], "inputs": [ - "Makefile", - "certificates/partial-swap-network.json", - "docs/ci-verification.md", - "research/clifford-state-performance/SOURCE.json", - "research/community-batch1047-audit/CONTENT-COVERAGE.json", - "research/community-batch1099-audit/CONTENT-COVERAGE.json", - "research/community-batch932-audit/CONTENT-COVERAGE.json", - "research/community-batch970-audit/CONTENT-COVERAGE.json", - "research/community-frontier741-audit/CONTENT-COVERAGE.json", - "research/community-frontier890-audit/CONTENT-COVERAGE.json", - "research/community-hyperplane599-audit/SOURCE.json", - "research/community-k492-audit/SOURCE.json", - "research/community-reconciliation92-audit/MANIFEST.json", - "research/partial-swap-digest/baseline.py", - "research/r420-two-sided-basis/SOURCES.json", - "research/skip-clones/SOURCE.json", - "research/split-skip/SOURCE.json", - "scripts/historical-ci-inputs/Makefile", - "scripts/historical-ci-inputs/ledger-batch932-run_isolated_tests.py", - "scripts/historical-ci-inputs/ledger-batch932-test_isolated_test_runner.py", - "scripts/historical-ci-inputs/ledger-batch970-verify_selected_result.py", - "scripts/historical-ci-inputs/ledger-frontier741-ci-verification.md", - "scripts/historical-ci-inputs/partial-swap-context.json", - "scripts/historical-ci-inputs/partial-swap-network.json", - "scripts/partial_swap/shared.py", - "scripts/replay_historical_check.py", - "scripts/research_package.py", - "scripts/run_isolated_tests.py", - "scripts/verify_selected_result.py", - "tests/test_isolated_test_runner.py" + "scripts/research_package.py" ], "commands": [ { diff --git a/research/historical-selected-replay-gap/verify.py b/research/historical-selected-replay-gap/verify.py index 83b995941a..9d266c5a4e 100644 --- a/research/historical-selected-replay-gap/verify.py +++ b/research/historical-selected-replay-gap/verify.py @@ -6,8 +6,10 @@ """ import hashlib import importlib.util +import json import subprocess import sys +import tempfile from pathlib import Path ROOT = Path(__file__).resolve().parents[2] @@ -61,31 +63,47 @@ def require(ok, message): raise SystemExit(message) -def load_checker(): - path = ROOT / "scripts/replay_historical_check.py" - spec = importlib.util.spec_from_file_location("historical_selected_replay_gap_checker", path) +def load_module(path): + spec = importlib.util.spec_from_file_location(path.stem, path) module = importlib.util.module_from_spec(spec) spec.loader.exec_module(module) return module +def checkout_snapshot(snapshot, sources, runner, env): + paths = [runner.canonical_relative_path(row["path"]) for row in sources["files"]] + git = ["git", "-c", "maintenance.auto=false", "-c", "gc.auto=0", + "-c", "core.autocrlf=false"] + subprocess.run([*git, "clone", "--quiet", "--shared", "--no-tags", "--no-checkout", + "--", str(ROOT), str(snapshot)], cwd=ROOT, env=env, check=True) + subprocess.run([*git, "update-ref", "--no-deref", "HEAD", INSPECTED], + cwd=snapshot, env=env, check=True) + # The pinned planner reads omitted manifests from the sparse HEAD/index. + patterns = "".join(f"/{path.as_posix()}\n" for path in paths) + subprocess.run([*git, "sparse-checkout", "set", "--no-cone", "--stdin"], + cwd=snapshot, env=env, input=patterns.encode("utf-8"), check=True) + subprocess.run([*git, "read-tree", "-mu", "HEAD"], cwd=snapshot, env=env, check=True) + for path, row in zip(paths, sources["files"], strict=True): + require(hashlib.sha256((snapshot / path).read_bytes()).hexdigest() == row["sha256"], + "historical checkout source digest changed: " + path.as_posix()) + + def entries(checker): for name, config in checker.CONFIG.items(): for entry in [config, *config.get("additional_inputs", [])]: yield name, entry -def reject(checker, entry): +def reject(root, checker, entry): try: - checker.authenticated_input(ROOT, entry) + checker.authenticated_input(root, entry) except ValueError as exc: return str(exc) raise SystemExit("historical input was admitted: " + entry["path"]) -def main(): - require(not sys.flags.optimize, "assertions must stay enabled") - checker = load_checker() +def check_snapshot(root, env): + checker = load_module(root / "scripts/replay_historical_check.py") selected = [entry for name, entry in entries(checker) if name == "tooling-ledger" and entry["path"] == SELECTED_PATH] require(len(selected) == 1, "selected-result checker overlay is not unique") @@ -94,7 +112,7 @@ def main(): require(entry["accepted_live_sha256"] == [SELECTED_ACCEPTED], "accepted selected-checker successors changed") frozen = (checker.INPUTS / entry["input"]).read_bytes() - live = (ROOT / SELECTED_PATH).read_bytes() + live = (root / SELECTED_PATH).read_bytes() require(hashlib.sha256(frozen).hexdigest() == SELECTED_PIN, "frozen selected checker bytes changed") require(hashlib.sha256(live).hexdigest() == SELECTED_LIVE, "live selected checker digest changed") require(SELECTED_LIVE not in (SELECTED_PIN, SELECTED_ACCEPTED), "live checker was already admitted") @@ -102,7 +120,7 @@ def main(): # live successor, not a broken comparison. require(SELECTED_PIN in (SELECTED_PIN, *entry["accepted_live_sha256"]), "pin membership control failed") - require(reject(checker, entry) == REJECTIONS[SELECTED_PATH][1], + require(reject(root, checker, entry) == REJECTIONS[SELECTED_PATH][1], "selected checker rejection text changed") counts = {path: 0 for path in REJECTIONS} @@ -110,7 +128,7 @@ def main(): for _name, item in entries(checker): if item["path"] not in REJECTIONS: continue - message = reject(checker, item) + message = reject(root, checker, item) counts[item["path"]] += 1 messages.setdefault(item["path"], message) for path, (count, message) in REJECTIONS.items(): @@ -118,20 +136,31 @@ def main(): require(messages[path] == message, "rejection text changed for " + path) require(sum(counts.values()) == 19, "rejection total changed") ci = [item for _name, item in entries(checker) if item["path"] == CI_PATH] - require(len(ci) == 1 and hashlib.sha256((ROOT / CI_PATH).read_bytes()).hexdigest() == CI_LIVE, + require(len(ci) == 1 and hashlib.sha256((root / CI_PATH).read_bytes()).hexdigest() == CI_LIVE, "selected CI note digest changed") diff = subprocess.check_output( - ["git", "diff", "--name-only", PARENT, INSPECTED], cwd=ROOT, text=True) + ["git", "diff", "--name-only", PARENT, INSPECTED], cwd=root, env=env, text=True) changed = sorted(name for name in diff.splitlines() if name) require(changed == CHANGED, "inspected commit diff changed") - sys.path.insert(0, str(ROOT / "scripts")) - from research_package import plan_details - details = plan_details(ROOT, set(changed)) + planner = load_module(root / "scripts/research_package.py") + details = planner.plan_details(root, set(changed)) require([row["package"] for row in details] == PLAN_PACKAGES, "helper plan selection changed") matched = {name for row in details for names in row["causes"].values() for name in names} require(sorted(set(changed) - matched) == UNMATCHED, "unmatched plan paths changed") - require(plan_details(ROOT, set()) == [], "empty change set selected a package") + require(planner.plan_details(root, set()) == [], "empty change set selected a package") + + +def main(): + require(not sys.flags.optimize, "assertions must stay enabled") + sources = json.loads(Path(__file__).with_name("SOURCES.json").read_bytes()) + require(sources["base_commit"] == INSPECTED, "historical checkout base changed") + runner = load_module(ROOT / "scripts/research_package.py") + env = runner.git_source_env() + with tempfile.TemporaryDirectory(prefix="historical-selected-replay-") as temporary: + snapshot = Path(temporary) / "snapshot" + checkout_snapshot(snapshot, sources, runner, env) + check_snapshot(snapshot, env) print("PASS_HISTORICAL_SELECTED_REPLAY_GAP") print("selected_checker_live=" + SELECTED_LIVE) print("rejections=19 distinct_paths=7 plan_packages=9")