Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 1 addition & 48 deletions tests/compass/test_artifact_invalidation.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
"""

import json
import pathlib
import re

import pytest

Expand All @@ -39,7 +37,6 @@
ArtifactRefusal,
ArtifactStore,
Axis,
Cell,
Conditions,
Fingerprint,
Gate,
Expand All @@ -63,14 +60,6 @@
verify,
)

REPO = pathlib.Path(__file__).resolve().parents[2]
#: The design document the invalidation matrix is read back out of.
MATRIX_DOC = REPO / "atom" / "compass" / "design" / "07_calibration_toolchain.md"
#: The heading of the section that holds the table, whatever it is numbered.
MATRIX_HEADING = re.compile(r"^## .*\bInvalidation$", re.MULTILINE)
#: One cell of the document's table: the mark, and the parenthesis beside it.
CELL = re.compile(r"^([X-])(?:\s*\*?\((.+)\)\*?)?$")

ATOM_ROOT = SourceRoot(
"atom",
"/workspace/ATOM/atom",
Expand Down Expand Up @@ -168,37 +157,7 @@ def publish(
)


# --- the matrix is a table, and it is the document's ----------------------


def test_the_matrix_is_the_documents_table():
"""The code's table and the document's are one fact, cell by cell.

The document's table is what a reader checks the code against by eye, so
this checks the same thing mechanically: the column headers, the row labels, every mark,
and every parenthesis. A note dropped here is a claim about *why* a cell
is what it is, silently lost -- `- (shape-parametric)` is the sentence
that makes one pricing campaign serve many shapes.
"""
text = MATRIX_DOC.read_text(encoding="utf-8")
table = MATRIX_HEADING.split(text, 1)[1].split("### The gate", 1)[0]
lines = [line for line in table.splitlines() if line.strip().startswith("|")]
header, _divider, *body = lines
columns = [part.strip() for part in header.strip().strip("|").split("|")][1:]
assert columns == [axis.value for axis in Axis]

stated = {}
for line in body:
label, *marks = [part.strip() for part in line.strip().strip("|").split("|")]
row = Row(label.replace("`", ""))
cells = {}
for axis, mark in zip(Axis, marks):
matched = CELL.match(mark.replace("**", "").strip())
assert matched is not None, f"{row} x {axis}: cannot read {mark!r}"
cells[axis] = Cell(matched.group(1) == "X", matched.group(2) or "")
stated[row] = cells
assert stated == dict(MATRIX)
assert set(stated) == set(Row)
# --- the matrix is a table ------------------------------------------------


def test_the_matrix_is_not_uniform():
Expand Down Expand Up @@ -245,12 +204,6 @@ def test_every_cell_of_the_matrix_decides_by_itself(row, axis):
and not about any row: a rule that refused on every axis would pass every
cross and fail every zero, and a rule that refused on none would do the
reverse.

It reads `MATRIX` rather than restating the document by hand, so on its
own it
would pass against a wrong table that the code agreed with. The anchor is
`test_the_matrix_is_the_documents_table`, which ties `MATRIX` to the document; the
chain is document -> table -> behaviour, and each link is a test.
"""
recorded = {row: fingerprint(row, BASE)}
changed = moved(BASE, axis)
Expand Down
46 changes: 1 addition & 45 deletions tests/compass/test_artifact_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import json
import pathlib
import re
import sys

import pytest
Expand All @@ -49,12 +48,6 @@
roots_for,
)

REPO = pathlib.Path(__file__).resolve().parents[2]
#: The design document the artifact key table is read back out of.
KEY_TABLE_DOC = REPO / "atom" / "compass" / "design" / "07_calibration_toolchain.md"
#: One row of the six-artifacts table: the name, and the `Keyed by` cell.
ROW = re.compile(r"^\| `([a-z_]+)` \| [^|]*\| ([^|]*)\|", re.MULTILINE)

ATOM_ROOT = SourceRoot(
"atom",
"/workspace/ATOM/atom",
Expand Down Expand Up @@ -115,48 +108,11 @@ def members_for(topology: Topology, stem: str, extension: str) -> dict[str, byte
}


def words(text: str) -> str:
"""Text with the punctuation that separates words flattened to spaces."""
return re.sub(
r"[-_*`]", lambda hit: "" if hit.group() in "*`" else " ", text.lower()
)


# --- a key is a tuple, never a path -----------------------------------------


def test_the_six_artifacts_are_the_ones_the_key_table_declares():
"""The kinds *and their key fields* are one fact with the document's table.

The `Keyed by` column is compared per row, not just the set of names: an
earlier version of this test compared only the names and one tuple, and
stayed green with five of `memory_readings`' seven key fields deleted --
which is the row whose length is the whole point of separating "part of
the key" from "merely recorded".
"""
text = KEY_TABLE_DOC.read_text(encoding="utf-8")
table = text.split("### The six artifacts", 1)[1].split("### Four rules", 1)[0]
rows = dict(ROW.findall(table))
assert set(rows) == {kind.value for kind in Kind}
def test_every_kind_declares_its_key_fields():
assert set(KEY_FIELDS) == set(Kind)
for kind in Kind:
cell = rows[kind.value]
stated = re.search(r"\(([^)]*)\)", cell)
fields = KEY_FIELDS[kind]
if stated is None:
assert (
len(fields) == 1
), f"the key table keys {kind} by one thing, code has {fields}"
else:
named = [part for part in stated.group(1).split(",") if part.strip()]
assert len(fields) == len(named), (
f"the key table keys {kind} by {len(named)} fields and "
f"KEY_FIELDS has {len(fields)}: {fields}"
)
for field in fields:
assert words(field) in words(
cell
), f"the key table's {kind} row omits `{field}`"


def test_a_price_list_asked_for_by_path_is_refused_by_name(tmp_path):
Expand Down
34 changes: 0 additions & 34 deletions tests/compass/test_cpu_gate_exclude.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,13 @@
`regen_cpu_gate_exclude.sh`'s job, not a unit test's.
"""

import re
from pathlib import Path

import pytest

REPO = Path(__file__).resolve().parents[2]
EXCLUDE = REPO / "scripts" / "compass" / "cpu_gate_exclude.txt"
TRIGGERS = REPO / "scripts" / "compass" / "gpu_gate_triggers.txt"
README = REPO / "scripts" / "compass" / "README.md"

GEN_BEGIN, GEN_END = "# BEGIN GENERATED", "# END GENERATED"
MAN_BEGIN, MAN_END = "# BEGIN MANUAL", "# END MANUAL"
Expand Down Expand Up @@ -189,38 +187,6 @@ def test_the_manual_guard_finds_nothing_when_the_section_empties(monkeypatch, tm
assert not _manual_entries()


@pytest.mark.parametrize(
"listed, stated, derive",
[
(EXCLUDE, r"\*\*(\d+)\*\* excluded test files", _entries),
(
EXCLUDE,
r"\*\*(\d+) GENERATED\*\*",
lambda: _paths(_section(GEN_BEGIN, GEN_END)),
),
(EXCLUDE, r"\*\*(\d+) MANUAL\*\*", _manual_entries),
(TRIGGERS, r"\*\*(\d+)\*\* source paths", _trigger_entries),
],
ids=["total", "generated", "manual", "triggers"],
)
def test_the_readme_states_the_counts_the_list_holds(listed, stated, derive):
# README.md restates these lists' counts. The pin above holds the MANUAL one
# in its own file only, and regen_gpu_gate_triggers.sh rewrites the trigger
# list wholesale without touching the README. Without this join, either
# change leaves the README wrong in silence. Same shape as gate_gpu.sh's
# BASE_FAILED against gpu_gate_known_failures.txt: the stated number stays,
# the list is counted, and a disagreement names both rather than picking one.
row = [ln for ln in _lines(README) if ln.startswith(f"| `{listed.name}` |")]
assert len(row) == 1, f"{README.name} has {len(row)} rows for {listed.name}"
found = re.search(stated, row[0])
assert found, f"{README.name}'s {listed.name} row no longer states /{stated}/"
entries = derive()
assert int(found[1]) == len(entries), (
f"{README.name} states {found[0]} but {listed.name} holds {len(entries)}: "
f"{entries}. Update the README row to match the list."
)


@pytest.mark.parametrize("entry", _manual_entries())
def test_every_manual_entry_states_why(entry):
# A manual entry is an assertion no script can check, so the reason is the
Expand Down
Loading