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
5 changes: 5 additions & 0 deletions .github/workflows/scripts-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ jobs:
run: |
test -f scripts/fleet/flow-report/test_flow_report.py
python3 -I -m unittest discover -s scripts/fleet/flow-report -p 'test_flow_report.py' -v
- name: Run graph encoding bake-off report check (#10219)
run: |
test -f doc/2026-11-13T03-40-00Z_design_id-atlas-summit/part-a-graph/test_validate_real_encoding_bakeoff.py
python3 -I -m unittest discover -s doc/2026-11-13T03-40-00Z_design_id-atlas-summit/part-a-graph -p 'test_validate_real_encoding_bakeoff.py' -v
python3 -I doc/2026-11-13T03-40-00Z_design_id-atlas-summit/part-a-graph/validate_real_encoding_bakeoff.py --check-committed
- name: Run queue transport alert contract tests (#6369)
run: |
test -f scripts/fleet/queue-transport-alert/test_check_transport.py
Expand Down
25 changes: 18 additions & 7 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,10 @@ discipline (target broker, narrowest Rust verification).

## Testing doctrine

Three tools, used where they fit:

- **PBT (property-based testing):** state invariants that must always hold, then let a generator hammer the code with thousands of random inputs to find counterexamples. Where code has meaningful invariants — parsers, serializers, state machines, replication, ID/crypto formats — state the invariants and cover them with property tests. In Rust here that is `proptest` (already a dev-dependency of `pkgs/id`).
- **MBT (model-based testing):** where a system's behavior has a spec or design model, build the model and generate tests — and their expected results — from it, instead of hand-writing cases only.
- **Oracles:** the decision procedure that tells you whether actual output matches expected — the hard part of automated testing. Every automated test names its oracle: a reference implementation, the model, an invariant check, or a golden corpus. A test with no decidable oracle is a smell to fix, not ship.

Example-based tests remain fine for smoke and acceptance coverage; they do not replace PBT/MBT where those fit.
Full text: [`doc/agents/testing-doctrine.md`](doc/agents/testing-doctrine.md).
In short: property tests (PBT, `proptest`) where code has invariants;
model-based tests (MBT) where a spec or model exists; every automated
test names its oracle. Example tests stay fine for smoke and acceptance.

## Operator script argument contract (#3352)

Expand Down Expand Up @@ -93,6 +90,20 @@ for ownership; check notes before posting a park/pickup note. Always post
progress notes. Land or checkpoint a reviewable slice before parking for size.
There is no ownership handoff: never park awaiting one.

## Nothing waits on the owner

Full text: [FDR-0013](doc/decisions/FDR-0013-no-owner-decision-gates.md); how: `.agents/skills/decide-and-proceed`.
Never park, block or label work as waiting on the owner for a choice,
review or approval: decide, record it on the issue, continue. Only a
hands item (one action only a person's hands can do) may wait.

## Finishing work

A PR that completes an issue says `Closes #N`. After a merge, run the
issue's done check and close it, or note what is left and clear
`status:in-review`: open issues with merged work block their waiters.
Out of work: `fleet agent next` ([onboarding](doc/agents/onboarding-an-agent.md)).

## Research, design and delivery workflow

Use it when a request, from one sentence to pages of voice-transcribed notes, should become researched documents, designs, plans or parallel PRs. Contracts: [`planning/workflow/`](planning/workflow/README.md). Where documents go: [`planning/DOCUMENTATION_ARCHITECTURE.md`](planning/DOCUMENTATION_ARCHITECTURE.md). Tool: `python3 -I scripts/research_workflow.py` (`check`, `status`, `ready`).
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
#!/usr/bin/env python3
"""Tests for the layout-independent report comparison (stdlib only).

Oracle: a Markdown table says the same thing however its cells are
padded, and something different as soon as one cell's text changes. The
repository formatter re-pads tables on main, so the report check must
pass on a re-padded table and still fail on a changed number.
"""

from __future__ import annotations

import importlib.util
import random
import unittest
from pathlib import Path

HERE = Path(__file__).resolve().parent
SPEC = importlib.util.spec_from_file_location(
"bakeoff", HERE / "validate_real_encoding_bakeoff.py"
)
bakeoff = importlib.util.module_from_spec(SPEC)
SPEC.loader.exec_module(bakeoff)

TIGHT = "| engine | load µs | bytes |\n|---|---:|---:|\n| `a` | 7982 | 312475 |\n| `b` | 199808 | 1118208 |"
PADDED = (
"\n"
"| engine | load µs | bytes |\n"
"| ------ | ------: | ------: |\n"
"| `a` | 7982 | 312475 |\n"
"| `b` | 199808 | 1118208 |\n"
)


class TableCells(unittest.TestCase):
def test_padding_rule_width_and_blank_lines_do_not_change_the_cells(self) -> None:
self.assertEqual(bakeoff.table_cells(TIGHT), bakeoff.table_cells(PADDED))
Comment on lines +35 to +36

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Cover table-normalization invariants with property-based tests

The new parser explicitly promises invariance under cell padding, separator width, and blank lines, but this test checks only two hand-written layouts. The testing doctrine in AGENTS.md requires property-based coverage for code with invariants; its linked full text specifically includes parsers and says example tests do not replace PBT. Add generated layout variations that must preserve the expected cells, retaining these examples as smoke coverage.

AGENTS.md reference: AGENTS.md:L37-L39

Useful? React with 👍 / 👎.

self.assertEqual(
bakeoff.table_cells(PADDED),
[
["engine", "load µs", "bytes"],
["`a`", "7982", "312475"],
["`b`", "199808", "1118208"],
],
)

def test_a_changed_number_a_missing_row_or_stray_text_is_a_difference(self) -> None:
base = bakeoff.table_cells(TIGHT)
self.assertNotEqual(
bakeoff.table_cells(PADDED.replace("312475", "312476")), base
)
self.assertNotEqual(
bakeoff.table_cells("\n".join(PADDED.splitlines()[:-1])), base
)
self.assertNotEqual(bakeoff.table_cells(PADDED + "edited by hand\n"), base)
# A reordered pair of rows is a different table too.
lines = TIGHT.splitlines()
self.assertNotEqual(
bakeoff.table_cells("\n".join(lines[:2] + [lines[3], lines[2]])), base
)

def test_list_items_ignore_blank_lines_and_indentation_only(self) -> None:
self.assertEqual(
bakeoff.list_items("\n- load µs: `a`\n\n - bytes: `a`\n"),
["- load µs: `a`", "- bytes: `a`"],
)
self.assertNotEqual(
bakeoff.list_items("- load µs: `b`"), bakeoff.list_items("- load µs: `a`")
)


CELL_ALPHABET = "abcxyzABC0123456789µ`_. /"
SEED = 10219
CASES = 2000


def random_matrix(rng: random.Random) -> list[list[str]]:
"""A header row and zero to five body rows, one to six cells each."""
columns = rng.randint(1, 6)

def cell() -> str:
return "".join(
rng.choice(CELL_ALPHABET) for _ in range(rng.randint(0, 9))
).strip()

return [[cell() for _ in range(columns)] for _ in range(rng.randint(1, 6))]


def random_layout(rng: random.Random, matrix: list[list[str]]) -> str:
"""The matrix as a Markdown table under a random layout.

Everything the formatter may vary is drawn at random: the padding on
each side of every cell, the width and alignment colons of the rule
row, and blank lines and indentation around the table.
"""

def row(cells: list[str]) -> str:
return (
"|"
+ "|".join(
" " * rng.randint(0, 4) + c + " " * rng.randint(0, 4) for c in cells
)
+ "|"
)

def rule_cell() -> str:
return rng.choice(["", ":"]) + "-" * rng.randint(1, 12) + rng.choice(["", ":"])

lines = [row(matrix[0]), row([rule_cell() for _ in matrix[0]])] + [
row(r) for r in matrix[1:]
]
lines = [" " * rng.randint(0, 3) + line for line in lines]
return "\n" * rng.randint(0, 3) + "\n".join(lines) + "\n" * rng.randint(0, 3)


class LayoutProperty(unittest.TestCase):
"""Property tests with a seeded generator (stdlib only).

Oracle: the generating model. A table is rendered from a cell matrix,
so the matrix is the expected answer for every layout of it.
"""

def test_any_layout_of_a_table_parses_back_to_its_cells(self) -> None:
rng = random.Random(SEED)
for case in range(CASES):
matrix = random_matrix(rng)
rendered = random_layout(rng, matrix)
self.assertEqual(
bakeoff.table_cells(rendered),
matrix,
f"seed {SEED} case {case}: {rendered!r}",
)

def test_two_layouts_of_one_table_always_compare_equal(self) -> None:
rng = random.Random(SEED + 1)
for case in range(CASES):
matrix = random_matrix(rng)
first, second = random_layout(rng, matrix), random_layout(rng, matrix)
self.assertEqual(
bakeoff.table_cells(first),
bakeoff.table_cells(second),
f"seed {SEED + 1} case {case}",
)

def test_changing_any_one_cell_is_always_a_difference(self) -> None:
rng = random.Random(SEED + 2)
for case in range(CASES):
matrix = random_matrix(rng)
changed = [list(r) for r in matrix]
r = rng.randrange(len(changed))
c = rng.randrange(len(changed[r]))
changed[r][c] = changed[r][c] + "7"
self.assertNotEqual(
bakeoff.table_cells(random_layout(rng, changed)),
bakeoff.table_cells(random_layout(rng, matrix)),
f"seed {SEED + 2} case {case}",
)


class CommittedReport(unittest.TestCase):
def test_the_committed_report_matches_the_committed_results(self) -> None:
results = bakeoff.load_json(bakeoff.RESULTS)
bakeoff.check_report(results)

def test_a_report_with_one_changed_cell_is_refused(self) -> None:
results = bakeoff.load_json(bakeoff.RESULTS)
engine = bakeoff.ENGINES[0]
rows = bakeoff.table_values(results)
original = bakeoff.REPORT
text = original.read_text(encoding="utf-8")
needle = f" {rows[engine][0]} "
self.assertIn(needle, text)
changed = HERE / "real-encoding-bakeoff.changed-for-test.md"
changed.write_text(
text.replace(needle, f" {rows[engine][0] + 1} ", 1), encoding="utf-8"
)
try:
bakeoff.REPORT = changed
with self.assertRaisesRegex(bakeoff.Invalid, "table differs"):
bakeoff.check_report(results)
finally:
bakeoff.REPORT = original
changed.unlink()

def test_a_report_with_one_changed_leader_is_refused(self) -> None:
results = bakeoff.load_json(bakeoff.RESULTS)
original = bakeoff.REPORT
text = original.read_text(encoding="utf-8")
leaders = bakeoff.block(text, "leaders")
first = bakeoff.list_items(leaders)[0]
name = first.split("`")[1]
other = next(e for e in bakeoff.ENGINES if e != name)
changed = HERE / "real-encoding-bakeoff.changed-for-test.md"
changed.write_text(
text.replace(first, first.replace(name, other), 1), encoding="utf-8"
)
try:
bakeoff.REPORT = changed
with self.assertRaisesRegex(bakeoff.Invalid, "leaders differ"):
bakeoff.check_report(results)
finally:
bakeoff.REPORT = original
changed.unlink()


if __name__ == "__main__":
unittest.main()
33 changes: 31 additions & 2 deletions ...026-11-13T03-40-00Z_design_id-atlas-summit/part-a-graph/validate_real_encoding_bakeoff.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -612,14 +612,43 @@ def block(text: str, name: str) -> str:
return match.group(1)


def table_cells(markdown: str) -> list[list[str]]:
"""The cells of a Markdown table, row by row, without its layout.

The repository's formatter pads cells, widens the rule row and adds
blank lines around a block. None of that changes what the table says,
so the comparison is on cell text: the rule row is dropped and each
cell is stripped. A row that is not a table row is kept as one cell,
so stray text in the block still makes the comparison fail.
"""
rows: list[list[str]] = []
for line in markdown.splitlines():
line = line.strip()
if not line:
continue
if not (line.startswith("|") and line.endswith("|") and len(line) > 1):
rows.append([line])
continue
cells = [cell.strip() for cell in line[1:-1].split("|")]
if all(re.fullmatch(r":?-+:?", cell) for cell in cells):
continue
rows.append(cells)
return rows


def list_items(markdown: str) -> list[str]:
"""The non-blank lines of a block, each stripped."""
return [line.strip() for line in markdown.splitlines() if line.strip()]


def check_report(results: dict) -> None:
text = REPORT.read_text(encoding="utf-8")
need(
block(text, "table") == render_table(results),
table_cells(block(text, "table")) == table_cells(render_table(results)),
"report: table differs from the committed results",
)
need(
block(text, "leaders") == render_leaders(results),
list_items(block(text, "leaders")) == list_items(render_leaders(results)),
"report: leaders differ from the committed results",
)
need(results["fixture"]["sha256"] in text, "report: must name the fixture SHA-256")
Expand Down
11 changes: 11 additions & 0 deletions doc/agents/testing-doctrine.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Testing doctrine

Indexed from [`AGENTS.md`](../../AGENTS.md).

Three tools, used where they fit:

- **PBT (property-based testing):** state invariants that must always hold, then let a generator hammer the code with thousands of random inputs to find counterexamples. Where code has meaningful invariants — parsers, serializers, state machines, replication, ID/crypto formats — state the invariants and cover them with property tests. In Rust here that is `proptest` (already a dev-dependency of `pkgs/id`).
- **MBT (model-based testing):** where a system's behavior has a spec or design model, build the model and generate tests — and their expected results — from it, instead of hand-writing cases only.
- **Oracles:** the decision procedure that tells you whether actual output matches expected — the hard part of automated testing. Every automated test names its oracle: a reference implementation, the model, an invariant check, or a golden corpus. A test with no decidable oracle is a smell to fix, not ship.

Example-based tests remain fine for smoke and acceptance coverage; they do not replace PBT/MBT where those fit.