merge: the parity floor, machine-checked (branch t3/parity-floor-ci, faf38770)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
38faba92de
5 files changed
+261
-4
No files matched your search
@@ -21,7 +21,16 @@ jobs:
|
|||||||
CARGO_PROFILE_DEV_DEBUG: line-tables-only
|
CARGO_PROFILE_DEV_DEBUG: line-tables-only
|
||||||
CARGO_PROFILE_TEST_DEBUG: line-tables-only
|
CARGO_PROFILE_TEST_DEBUG: line-tables-only
|
||||||
steps:
|
steps:
|
||||||
|
# The parity floor compares against the commit before this one, so
|
||||||
|
# the checkout needs one more commit than the default.
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
with:
|
||||||
|
fetch-depth: 2
|
||||||
|
- name: The base branch, for the parity floor
|
||||||
|
if: github.event_name == 'pull_request'
|
||||||
|
run: |
|
||||||
|
git fetch --no-tags --depth=1 origin \
|
||||||
|
"+refs/heads/${{ github.base_ref }}:refs/remotes/origin/${{ github.base_ref }}"
|
||||||
- name: Room for the build (the image ships toolchains we never use)
|
- name: Room for the build (the image ships toolchains we never use)
|
||||||
run: |
|
run: |
|
||||||
sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc \
|
sudo rm -rf /usr/share/dotnet /usr/local/lib/android /opt/ghc \
|
||||||
@@ -30,6 +39,16 @@ jobs:
|
|||||||
- uses: jdx/mise-action@v2
|
- uses: jdx/mise-action@v2
|
||||||
- name: GUI build dependencies
|
- name: GUI build dependencies
|
||||||
run: sudo apt-get update && sudo apt-get install -y libxkbcommon-dev libgtk-3-dev
|
run: sudo apt-get update && sudo apt-get install -y libxkbcommon-dev libgtk-3-dev
|
||||||
|
# docs/parity.md's floor never decreases (AGENTS.md, "Parity
|
||||||
|
# tracking"); a test checks it inside `just check`, this checks the
|
||||||
|
# commit's floor against its base.
|
||||||
|
- name: The parity floor holds
|
||||||
|
run: |
|
||||||
|
if [ "${{ github.event_name }}" = "pull_request" ]; then
|
||||||
|
scripts/parity-floor.sh "origin/${{ github.base_ref }}"
|
||||||
|
else
|
||||||
|
scripts/parity-floor.sh HEAD^1
|
||||||
|
fi
|
||||||
- run: just check
|
- run: just check
|
||||||
- name: What the build used
|
- name: What the build used
|
||||||
if: always()
|
if: always()
|
||||||
|
|||||||
@@ -145,8 +145,11 @@ clone, with status. Rules:
|
|||||||
|
|
||||||
- Every feature change updates `docs/parity.md` in the same commit.
|
- Every feature change updates `docs/parity.md` in the same commit.
|
||||||
- The **floor never decreases**: the count of `done` items is monotonic.
|
- The **floor never decreases**: the count of `done` items is monotonic.
|
||||||
CI will enforce this once the catalog is machine-readable (roadmap phase 3);
|
`crates/ledger-cli/tests/parity_floor.rs` runs in `cargo test` (so in
|
||||||
until then, it is enforced by review — yours.
|
`just check`) and fails unless every status is one of the three and the
|
||||||
|
`done` count equals the floor line exactly; the CI step
|
||||||
|
`scripts/parity-floor.sh` fails when the floor falls below the base
|
||||||
|
commit's.
|
||||||
- Statuses are `done` (implemented + tested + golden-covered), `partial`,
|
- Statuses are `done` (implemented + tested + golden-covered), `partial`,
|
||||||
`todo`. No other statuses. `done` requires all three.
|
`todo`. No other statuses. `done` requires all three.
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,193 @@
|
|||||||
|
//! The parity catalog's floor, machine-checked (docs/parity.md;
|
||||||
|
//! AGENTS.md, "Parity tracking").
|
||||||
|
//!
|
||||||
|
//! Every table with a `Status` column must hold only `done`, `partial` or
|
||||||
|
//! `todo`, and the number of `done` rows must equal the catalog's
|
||||||
|
//! `**Floor: N done**` line exactly. Equal, not at least: adding a done row
|
||||||
|
//! raises the floor in the same commit, so a later drop is always caught.
|
||||||
|
//! The history half (the floor never falls between commits) is
|
||||||
|
//! `scripts/parity-floor.sh`, run by CI before `just check`.
|
||||||
|
|
||||||
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
|
fn root() -> PathBuf {
|
||||||
|
Path::new(env!("CARGO_MANIFEST_DIR"))
|
||||||
|
.join("../..")
|
||||||
|
.canonicalize()
|
||||||
|
.unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn catalog() -> String {
|
||||||
|
let path = root().join("docs/parity.md");
|
||||||
|
std::fs::read_to_string(&path).unwrap_or_else(|e| panic!("{}: {e}", path.display()))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The only statuses the catalog allows (docs/parity.md:
|
||||||
|
/// `done` = implemented + invariant-tested + golden-covered,
|
||||||
|
/// `partial` = implemented but missing tests or goldens, `todo` = not
|
||||||
|
/// started).
|
||||||
|
const STATUSES: [&str; 3] = ["done", "partial", "todo"];
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
struct Row {
|
||||||
|
area: String,
|
||||||
|
status: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A markdown table row's cells, trimmed, without the outer pipes.
|
||||||
|
fn cells(line: &str) -> Vec<&str> {
|
||||||
|
line.trim()
|
||||||
|
.trim_matches('|')
|
||||||
|
.split('|')
|
||||||
|
.map(str::trim)
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The `**Floor: N done**` line, or `None` when the file has none.
|
||||||
|
fn parse_floor(text: &str) -> Option<u32> {
|
||||||
|
for line in text.lines() {
|
||||||
|
let Some(rest) = line.trim().strip_prefix("**Floor: ") else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
let mut words = rest.split_whitespace();
|
||||||
|
let (Some(number), Some(marker)) = (words.next(), words.next()) else {
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
if marker != "done**" {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
return number.parse().ok();
|
||||||
|
}
|
||||||
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Every data row of every table whose header has a `Status` column.
|
||||||
|
/// Errors name the row's first cell and the bad status.
|
||||||
|
fn parse_tables(text: &str) -> Result<Vec<Row>, Vec<String>> {
|
||||||
|
let mut rows = Vec::new();
|
||||||
|
let mut errors = Vec::new();
|
||||||
|
let mut status_col: Option<usize> = None;
|
||||||
|
|
||||||
|
for (index, line) in text.lines().enumerate() {
|
||||||
|
let line_no = index + 1;
|
||||||
|
if !line.trim_start().starts_with('|') {
|
||||||
|
// A table ends at the first non-table line.
|
||||||
|
status_col = None;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let parts = cells(line);
|
||||||
|
let separator = parts
|
||||||
|
.iter()
|
||||||
|
.all(|cell| !cell.is_empty() && cell.chars().all(|c| c == '-' || c == ':'));
|
||||||
|
if separator {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let Some(col) = status_col else {
|
||||||
|
if let Some(col) = parts.iter().position(|cell| *cell == "Status") {
|
||||||
|
status_col = Some(col);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
};
|
||||||
|
let area = parts.first().copied().unwrap_or_default().to_string();
|
||||||
|
match parts.get(col).copied() {
|
||||||
|
None => errors.push(format!(
|
||||||
|
"docs/parity.md:{line_no}: row `{area}` has no status cell"
|
||||||
|
)),
|
||||||
|
Some("") => errors.push(format!(
|
||||||
|
"docs/parity.md:{line_no}: row `{area}` has an empty status"
|
||||||
|
)),
|
||||||
|
Some(status) if !STATUSES.contains(&status) => errors.push(format!(
|
||||||
|
"docs/parity.md:{line_no}: row `{area}` has status `{status}`, \
|
||||||
|
not one of done, partial, todo"
|
||||||
|
)),
|
||||||
|
Some(status) => rows.push(Row {
|
||||||
|
area,
|
||||||
|
status: status.to_string(),
|
||||||
|
}),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if errors.is_empty() {
|
||||||
|
Ok(rows)
|
||||||
|
} else {
|
||||||
|
Err(errors)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn every_row_has_a_known_status() {
|
||||||
|
let text = catalog();
|
||||||
|
if let Err(errors) = parse_tables(&text) {
|
||||||
|
panic!(
|
||||||
|
"docs/parity.md's statuses must be exactly done, partial or todo:\n{}",
|
||||||
|
errors.join("\n")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn the_done_count_is_the_floor() {
|
||||||
|
let text = catalog();
|
||||||
|
let rows = parse_tables(&text).unwrap_or_else(|errors| {
|
||||||
|
panic!(
|
||||||
|
"docs/parity.md's statuses must be exactly done, partial or todo:\n{}",
|
||||||
|
errors.join("\n")
|
||||||
|
)
|
||||||
|
});
|
||||||
|
let done: Vec<&str> = rows
|
||||||
|
.iter()
|
||||||
|
.filter(|row| row.status == "done")
|
||||||
|
.map(|row| row.area.as_str())
|
||||||
|
.collect();
|
||||||
|
let floor = parse_floor(&text).unwrap_or_else(|| {
|
||||||
|
panic!(
|
||||||
|
"docs/parity.md has no `**Floor: N done**` line; restore it \
|
||||||
|
(docs/parity.md's intro and AGENTS.md, \"Parity tracking\")"
|
||||||
|
)
|
||||||
|
});
|
||||||
|
if done.len() > floor as usize {
|
||||||
|
panic!(
|
||||||
|
"docs/parity.md has {} `done` rows but its floor line says {floor}. \
|
||||||
|
Raise the line to `**Floor: {} done**` in this commit: adding a \
|
||||||
|
done row raises the floor in the same commit, so a later drop is \
|
||||||
|
always caught.\nDone rows:\n {}",
|
||||||
|
done.len(),
|
||||||
|
done.len(),
|
||||||
|
done.join("\n ")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if done.len() < floor as usize {
|
||||||
|
panic!(
|
||||||
|
"docs/parity.md has {} `done` rows but its floor line says {floor}. \
|
||||||
|
Restore the missing row: the floor never decreases, and lowering \
|
||||||
|
it needs the owner's decision.\nDone rows:\n {}",
|
||||||
|
done.len(),
|
||||||
|
done.join("\n ")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_bad_status_names_its_row() {
|
||||||
|
let text = "| Area | Status | Notes |\n|---|---|---|\n| Ledger | finished | — |\n";
|
||||||
|
let errors = parse_tables(text).unwrap_err();
|
||||||
|
assert_eq!(errors.len(), 1, "{errors:?}");
|
||||||
|
assert!(errors[0].contains("Ledger"), "{errors:?}");
|
||||||
|
assert!(errors[0].contains("finished"), "{errors:?}");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_missing_status_cell_is_an_error() {
|
||||||
|
let text = "| Area | Status | Notes |\n|---|---|---|\n| Ledger | | — |\n";
|
||||||
|
let errors = parse_tables(text).unwrap_err();
|
||||||
|
assert_eq!(errors.len(), 1, "{errors:?}");
|
||||||
|
assert!(errors[0].contains("Ledger"), "{errors:?}");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_missing_floor_line_is_none() {
|
||||||
|
assert_eq!(parse_floor("# Parity catalog\n\nNo floor here.\n"), None);
|
||||||
|
assert_eq!(
|
||||||
|
parse_floor("**Floor: 7 done** (2026-01-01; the sections below record each rise)"),
|
||||||
|
Some(7)
|
||||||
|
);
|
||||||
|
}
|
||||||
+4
-2
@@ -6,9 +6,11 @@ same commit as the feature. **The floor never decreases**: the count of
|
|||||||
|
|
||||||
Statuses: `done` = implemented + invariant-tested + golden-covered.
|
Statuses: `done` = implemented + invariant-tested + golden-covered.
|
||||||
`partial` = implemented but missing tests or goldens. `todo` = not started.
|
`partial` = implemented but missing tests or goldens. `todo` = not started.
|
||||||
No other statuses.
|
No other statuses. `crates/ledger-cli/tests/parity_floor.rs` enforces the
|
||||||
|
statuses and the floor in `cargo test`; `scripts/parity-floor.sh` enforces
|
||||||
|
in CI that the floor never falls between commits.
|
||||||
|
|
||||||
**Floor: 21 done** (2026-10-28; it was 10 on 2026-10-10, when the fixed-asset register was added, and the sections below record each rise).
|
**Floor: 25 done** (2026-10-28; it was 10 on 2026-10-10, when the fixed-asset register was added, and the sections below record each rise; 2026-11-06: P4b S5 added one `done` row and S6 three, to 25, which the line had missed — the four rows' implementations and tests are named below).
|
||||||
|
|
||||||
| Area | GnuCash counterpart (a cross-check, not the spec) | Status | Notes |
|
| Area | GnuCash counterpart (a cross-check, not the spec) | Status | Notes |
|
||||||
|---|---|---|---|
|
|---|---|---|---|
|
||||||
|
|||||||
Executable
+40
@@ -0,0 +1,40 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# The parity catalog's floor never decreases (docs/parity.md; AGENTS.md,
|
||||||
|
# "Parity tracking"). `crates/ledger-cli/tests/parity_floor.rs` checks the
|
||||||
|
# floor against the rows in one commit; this checks it against the base
|
||||||
|
# commit, which a test cannot do.
|
||||||
|
#
|
||||||
|
# Usage: scripts/parity-floor.sh <base-ref>
|
||||||
|
# prints both floors; exits 1 when the working tree's floor is lower.
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
base_ref="${1:?usage: scripts/parity-floor.sh <base-ref>}"
|
||||||
|
cd "$(git rev-parse --show-toplevel)"
|
||||||
|
|
||||||
|
floor_of() {
|
||||||
|
# The first `**Floor: N done**` line, or nothing.
|
||||||
|
sed -n 's/^\*\*Floor: \([0-9][0-9]*\) done\*\*.*/\1/p' | head -n 1
|
||||||
|
}
|
||||||
|
|
||||||
|
if ! base_doc=$(git show "${base_ref}:docs/parity.md" 2>/dev/null); then
|
||||||
|
echo "parity floor: cannot read docs/parity.md at ${base_ref}" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
base_floor=$(printf '%s\n' "$base_doc" | floor_of)
|
||||||
|
|
||||||
|
if [ -z "$base_floor" ]; then
|
||||||
|
echo "parity floor: ${base_ref} has no floor line; nothing to compare"
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
work_floor=$(floor_of < docs/parity.md)
|
||||||
|
if [ -z "$work_floor" ]; then
|
||||||
|
echo "parity floor: docs/parity.md in the working tree has no floor line" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "parity floor: ${base_ref} says ${base_floor} done; the working tree says ${work_floor} done"
|
||||||
|
if [ "$work_floor" -lt "$base_floor" ]; then
|
||||||
|
echo "parity floor: the floor never decreases (docs/parity.md; AGENTS.md, \"Parity tracking\")" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
Reference in new issue
Block a user