CB-WP-0046: the rule the placement encodes, and a log that names its rules
Some checks failed
ci / check (push) Failing after 4s
Some checks failed
ci / check (push) Failing after 4s
CB-WP-0045 left "nothing explains what a scope does" open and gave a FALSE reason: that scoping is our Variant so no printed sentence exists. The H2 package ships Rules_Text.csv -- twenty-two passages of player-facing rules -- and nothing in clay-borg had ever read the file. A wrong reason for an open item is worse than an open item; it retires the question. Filed as F26 against ground-game: a package that adds a FILE is invisible where one that adds a column is not. The scope rule now renders under the table in the edition's own words, only when a non-global scope is in play, matched by heading rather than row number, and absent (never paraphrased) if the edition drops it. The trial log stamps its variant on the begin marker -- a session property, not an eighth column -- read off state.variant rather than the --variant flag, because a bare `state.variant = v` leaves H2 inert and a flag-stamped log would put false provenance on real player words. An unstamped log reports `unrecorded`, never `ground-darvo-r0`. Six mutations, six red. The sixth is the finding: every trials.py fixture built its marker out of BEGIN, so nine checks followed BEGIN away from what hotseat.rs writes and stayed green while real logs broke. A fixture built from the constant under test cannot test the constant -- the control is now a literal, asserted from both sides. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
parent
df65e2dee1
commit
de25c4cae0
10 changed files with 986 additions and 12 deletions
|
|
@ -100,7 +100,11 @@ pub fn game_path(base: &std::path::Path, n: usize) -> std::path::PathBuf {
|
|||
/// **Reusing `FindingRegister.md`'s idiom deliberately** (ADR-0014 D2) —
|
||||
/// a table between HTML-comment markers, so a human reads the file and a
|
||||
/// tool reads the block, and neither needs the other's cooperation.
|
||||
pub fn write_trial_log(path: &std::path::Path, notes: &[TrialNote]) -> Result<(), String> {
|
||||
pub fn write_trial_log(
|
||||
path: &std::path::Path,
|
||||
notes: &[TrialNote],
|
||||
variant: &str,
|
||||
) -> Result<(), String> {
|
||||
let mut s = String::new();
|
||||
s.push_str("# Trial log\n\n");
|
||||
s.push_str(
|
||||
|
|
@ -111,7 +115,19 @@ pub fn write_trial_log(path: &std::path::Path, notes: &[TrialNote]) -> Result<()
|
|||
`ground-game` (ADR-0014 D4) — a note reaches them only by being promoted to a\n\
|
||||
register finding, by a human, with the wording chosen then.\n\n",
|
||||
);
|
||||
s.push_str("<!-- trial-log:begin -->\n\n");
|
||||
// CB-WP-0046: WHICH RULES THIS SESSION PLAYED.
|
||||
//
|
||||
// Without it a baseline note and an H2 note are indistinguishable,
|
||||
// which stopped being survivable the moment both were being played
|
||||
// in the same week. It rides the marker rather than becoming an
|
||||
// eighth column because the variant is a property of the SESSION,
|
||||
// and a per-note column would repeat one fact on every line.
|
||||
//
|
||||
// Read off the STATE, not off the command line: `--variant h2` with
|
||||
// a bare `state.variant = v` assignment leaves H2 inert, and a log
|
||||
// stamped from the flag would have recorded H2 for a session that
|
||||
// played the baseline. This records what actually ran.
|
||||
let _ = write!(s, "<!-- trial-log:begin variant={variant} -->\n\n");
|
||||
// ADR-0019 D3/D4: `game` and `after` are the binding a reader can act
|
||||
// on -- replay `after` commands of game `game` and you are standing
|
||||
// where the player stood. `state_hash` stays as an integrity check at
|
||||
|
|
@ -209,7 +225,7 @@ impl Server {
|
|||
state_hash: hash[..12].to_string(),
|
||||
text: note.text.clone(),
|
||||
});
|
||||
write_trial_log(path, &log)
|
||||
write_trial_log(path, &log, state.variant.id())
|
||||
}
|
||||
|
||||
/// Begin the next game (ADR-0019 D1).
|
||||
|
|
@ -968,6 +984,63 @@ mod tests {
|
|||
/// this loop breaks it; a player writing what they thought must be
|
||||
/// able to write a second one and then still press `play again`,
|
||||
/// which is what the trailing command here proves.
|
||||
/// **The log says which rules the session played** (CB-WP-0046).
|
||||
///
|
||||
/// Without it a baseline note and an H2 note are indistinguishable,
|
||||
/// which is how *"i did not notice any difference"* stays unreadable
|
||||
/// after the fact — you cannot tell whether it is a finding about H2
|
||||
/// or a note about a session that never ran it.
|
||||
#[test]
|
||||
fn the_trial_log_records_which_rules_were_played() {
|
||||
let dir = std::env::temp_dir().join(format!("cb-trial-var-{}", std::process::id()));
|
||||
std::fs::create_dir_all(&dir).unwrap();
|
||||
let path = dir.join("trial.md");
|
||||
let note = TrialNote {
|
||||
n: 1,
|
||||
game: 1,
|
||||
after: 4,
|
||||
round: 3,
|
||||
step: "Select".into(),
|
||||
state_hash: "abc123def456".into(),
|
||||
text: "it felt harder".into(),
|
||||
};
|
||||
write_trial_log(&path, &[note], "h2-scoped-problem-stress").unwrap();
|
||||
let written = std::fs::read_to_string(&path).unwrap();
|
||||
assert!(
|
||||
written.contains("<!-- trial-log:begin variant=h2-scoped-problem-stress -->"),
|
||||
"the log does not say which rules were played:\n{written}"
|
||||
);
|
||||
// **Not an eighth column.** The variant is a property of the
|
||||
// session; repeating it per row would widen a table whose parser
|
||||
// treats an unexpected width as an error.
|
||||
let row = written
|
||||
.lines()
|
||||
.find(|l| l.starts_with("| 1 |"))
|
||||
.expect("the note row");
|
||||
assert_eq!(
|
||||
row.matches('|').count() - 1,
|
||||
7,
|
||||
"the table gained a column: {row}"
|
||||
);
|
||||
let _ = std::fs::remove_dir_all(&dir);
|
||||
}
|
||||
|
||||
/// The stamp is read off the STATE, never off the command line.
|
||||
///
|
||||
/// Three call sites once set `state.variant = v` directly instead of
|
||||
/// `with_variant()`, which renders H2 inert. A log stamped from the
|
||||
/// `--variant` flag would have recorded `h2` for a session that
|
||||
/// played the baseline — a false provenance on real player words,
|
||||
/// which is worse than no provenance.
|
||||
#[test]
|
||||
fn the_stamp_names_the_rules_that_actually_ran() {
|
||||
let src = include_str!("hotseat.rs");
|
||||
assert!(
|
||||
src.contains("write_trial_log(path, &log, state.variant.id())"),
|
||||
"the trial log is stamped from something other than the state"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_note_can_be_written_after_the_game_has_ended() {
|
||||
let dir = std::env::temp_dir().join(format!("cb-note-end-{}", std::process::id()));
|
||||
|
|
|
|||
123
tools/trials.py
123
tools/trials.py
|
|
@ -15,14 +15,27 @@ reuses `FindingRegister.md`'s idiom: a table between HTML-comment markers
|
|||
inside a readable Markdown file.
|
||||
"""
|
||||
|
||||
import os, re, sys, glob, datetime
|
||||
import os
|
||||
import re, sys, glob, datetime
|
||||
|
||||
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
TRIALS = os.path.join(ROOT, "trials")
|
||||
|
||||
BEGIN = "<!-- trial-log:begin -->"
|
||||
# The begin marker carries attributes since CB-WP-0046, so it is matched
|
||||
# by PREFIX. A bare `<!-- trial-log:begin -->` is still a valid marker —
|
||||
# every log written before this one has it.
|
||||
BEGIN = "<!-- trial-log:begin"
|
||||
END = "<!-- trial-log:end -->"
|
||||
|
||||
# Which rules the session was played under (CB-WP-0046).
|
||||
#
|
||||
# **A session property, not a note property**, so it rides the marker
|
||||
# rather than becoming an eighth column. The variant is fixed at startup
|
||||
# and cannot change between games, so a per-row column would repeat one
|
||||
# fact on every line and force a third accepted row width on a parser
|
||||
# whose docstring is about exactly that hazard.
|
||||
VARIANT_ATTR = re.compile(r"variant=([A-Za-z0-9._-]+)")
|
||||
|
||||
# GameDesign §3.1's figure, shared rather than reinvented: a note that
|
||||
# cannot expire ages into an apparent finding.
|
||||
NOTE_EXPIRY_DAYS = 30
|
||||
|
|
@ -45,7 +58,12 @@ def parse(text):
|
|||
is precisely the failure this tool exists to prevent."""
|
||||
if BEGIN not in text or END not in text:
|
||||
raise ValueError("no trial-log block")
|
||||
block = text.split(BEGIN)[1].split(END)[0]
|
||||
# Split off the marker's own line so an attribute cannot be read as
|
||||
# a table row, and so `variant=` is available to every row below it.
|
||||
tail = text.split(BEGIN, 1)[1].split(END)[0]
|
||||
marker, _, block = tail.partition("\n")
|
||||
hit = VARIANT_ATTR.search(marker)
|
||||
variant = hit.group(1) if hit else None
|
||||
rows = []
|
||||
for line in block.splitlines():
|
||||
line = line.strip()
|
||||
|
|
@ -63,16 +81,21 @@ def parse(text):
|
|||
# considered, and did not do) would have emptied every existing
|
||||
# log without a word.
|
||||
if len(cells) == len(COLUMNS):
|
||||
rows.append(dict(zip(COLUMNS, cells)))
|
||||
row = dict(zip(COLUMNS, cells))
|
||||
elif len(cells) == len(LEGACY_COLUMNS):
|
||||
row = dict(zip(LEGACY_COLUMNS, cells))
|
||||
row["legacy"] = True
|
||||
rows.append(row)
|
||||
else:
|
||||
raise ValueError(
|
||||
f"trial-log row has {len(cells)} columns, expected "
|
||||
f"{len(COLUMNS)} or {len(LEGACY_COLUMNS)}: {line!r}"
|
||||
)
|
||||
# **`None`, not a default of "baseline"** — a log written before
|
||||
# the marker carried the attribute does not say which rules were
|
||||
# played, and answering an unrecorded question with the common
|
||||
# case is how a baseline note gets read as an H2 result.
|
||||
row["variant"] = variant
|
||||
rows.append(row)
|
||||
return rows
|
||||
|
||||
|
||||
|
|
@ -174,12 +197,20 @@ def report(root=TRIALS, today=None):
|
|||
found = logs(root)
|
||||
print("trials — what the players said, and where\n")
|
||||
total, orphans, pending, expired, legacy = 0, 0, 0, 0, 0
|
||||
by_variant = {}
|
||||
for path, rows, _ in found:
|
||||
name = os.path.basename(path)
|
||||
age = age_days(path, today)
|
||||
print(f" {name} ({len(rows)} note(s), {age}d)")
|
||||
# CB-WP-0046: which rules were played. `unrecorded` is said out
|
||||
# loud rather than filled in with the common case — a note read
|
||||
# under the wrong rules is worse than a note whose rules are
|
||||
# openly unknown.
|
||||
rules = (rows[0].get("variant") if rows else None) or "unrecorded"
|
||||
print(f" {name} ({len(rows)} note(s), {age}d, rules {rules})")
|
||||
for r in rows:
|
||||
total += 1
|
||||
key = r.get("variant") or "unrecorded"
|
||||
by_variant[key] = by_variant.get(key, 0) + 1
|
||||
# ADR-0019 D2: each note names its own game, and each game has
|
||||
# its own recording. One recording per FILE was the assumption
|
||||
# that made `play again` overwrite the evidence.
|
||||
|
|
@ -207,6 +238,15 @@ def report(root=TRIALS, today=None):
|
|||
print(f" legacy binding {legacy}"
|
||||
" (written before ADR-0019; position not checkable, NOT orphaned)")
|
||||
print(f" notes past {NOTE_EXPIRY_DAYS} days {expired} target 0")
|
||||
# A tally by rules, because the question a reader now has is "was this
|
||||
# said about H2 or about the baseline" and counting the logs by hand
|
||||
# is how that gets answered wrong.
|
||||
if by_variant:
|
||||
print(" notes by rules "
|
||||
+ ", ".join(f"{v} {n}" for v, n in sorted(by_variant.items())))
|
||||
if "unrecorded" in by_variant:
|
||||
print(" (unrecorded = written before"
|
||||
" CB-WP-0046 stamped the marker)")
|
||||
if total and not orphans and not legacy:
|
||||
print("\n Every note points at a position a reader can reach.")
|
||||
print("\n Raw notes stay in this repo (ADR-0014 D4). A note reaches"
|
||||
|
|
@ -231,13 +271,19 @@ def self_test():
|
|||
ok = ok and bool(cond)
|
||||
print(f" [{'ok ' if cond else 'FAIL'}] {name}" + (f" — {detail}" if detail else ""))
|
||||
|
||||
def log_of(*rows):
|
||||
# `BEGIN` is a PREFIX since CB-WP-0046, so a fixture has to close the
|
||||
# marker itself — which is the point: the closing text is what the
|
||||
# attribute sits inside.
|
||||
OPEN = BEGIN + " -->"
|
||||
|
||||
def log_of(*rows, marker=None):
|
||||
head = ("| n | game | after | round | step | state_hash | comment |\n"
|
||||
"|---|---|---|---|---|---|---|\n")
|
||||
return f"# Trial log\n\n{BEGIN}\n\n{head}" + "".join(rows) + f"\n{END}\n"
|
||||
return (f"# Trial log\n\n{marker or OPEN}\n\n{head}"
|
||||
+ "".join(rows) + f"\n{END}\n")
|
||||
|
||||
good = log_of("| 1 | 1 | 4 | 3 | Select | abc123def456 | why is SOLVE doing nothing |\n")
|
||||
legacy = (f"# Trial log\n\n{BEGIN}\n\n"
|
||||
legacy = (f"# Trial log\n\n{OPEN}\n\n"
|
||||
"| n | round | step | state_hash | comment |\n|---|---|---|---|---|\n"
|
||||
"| 1 | 3 | Select | abc123def456 | why is SOLVE doing nothing |\n"
|
||||
f"\n{END}\n")
|
||||
|
|
@ -256,6 +302,65 @@ def self_test():
|
|||
check("a legacy row is MARKED legacy", parse(legacy)[0].get("legacy") is True)
|
||||
check("the header row is not a note", all(r["n"] != "n" for r in parse(good)))
|
||||
|
||||
# CB-WP-0046 — WHICH RULES THE SESSION PLAYED.
|
||||
row = "| 1 | 1 | 4 | 3 | Select | abc123def456 | it felt harder |\n"
|
||||
stamped = log_of(row, marker=BEGIN + " variant=h2-scoped-problem-stress -->")
|
||||
check("a stamped log reports its variant",
|
||||
parse(stamped)[0]["variant"] == "h2-scoped-problem-stress")
|
||||
check("an unstamped log says NOTHING, not 'baseline'",
|
||||
parse(log_of(row))[0]["variant"] is None,
|
||||
"answering an unrecorded question with the common case is how a "
|
||||
"baseline note gets read as an H2 result")
|
||||
# The attribute must not be mistaken for a table row, and adding it
|
||||
# must not change how many notes the log has.
|
||||
check("the marker is not counted as a note", len(parse(stamped)) == 1)
|
||||
check("stamping does not disturb the row", parse(stamped)[0]["after"] == "4")
|
||||
# The marker is not a THIRD row width: the table shape is untouched,
|
||||
# which is why the parser needed no new accepted width.
|
||||
check("the stamped table has the same columns as the unstamped one",
|
||||
set(parse(stamped)[0]) - {"variant"} == set(parse(good)[0]) - {"variant"})
|
||||
# **A LITERAL marker, not one built from `BEGIN`.**
|
||||
#
|
||||
# Every fixture above composes its marker out of `BEGIN`, so all of
|
||||
# them follow `BEGIN` wherever it goes — including away from what
|
||||
# `hotseat.rs` actually writes. Reverting `BEGIN` to an exact match
|
||||
# broke real stamped logs and every one of those checks stayed green.
|
||||
# The format is shared across two languages and this is the only
|
||||
# check that holds this side to the bytes the other side emits.
|
||||
literal = ("# Trial log\n\n"
|
||||
"<!-- trial-log:begin variant=h2-scoped-problem-stress -->\n\n"
|
||||
"| n | game | after | round | step | state_hash | comment |\n"
|
||||
"|---|---|---|---|---|---|---|\n"
|
||||
"| 1 | 1 | 4 | 3 | Select | abc123def456 | it felt harder |\n"
|
||||
"\n<!-- trial-log:end -->\n")
|
||||
# Caught, because the failure mode is `parse` REFUSING the writer's
|
||||
# output — and an uncaught traceback names a line number where a
|
||||
# named check names the defect.
|
||||
try:
|
||||
literal_rows = parse(literal)
|
||||
except ValueError:
|
||||
literal_rows = []
|
||||
check("the bytes hotseat.rs writes are the bytes this parses",
|
||||
len(literal_rows) == 1
|
||||
and literal_rows[0]["variant"] == "h2-scoped-problem-stress",
|
||||
"hotseat.rs's the_trial_log_records_which_rules_were_played "
|
||||
"asserts this same string from the writing side")
|
||||
# And the marker as it was written before CB-WP-0046, also literal.
|
||||
try:
|
||||
older = parse(literal.replace(
|
||||
"<!-- trial-log:begin variant=h2-scoped-problem-stress -->",
|
||||
"<!-- trial-log:begin -->"))
|
||||
except ValueError:
|
||||
older = []
|
||||
check("a pre-CB-WP-0046 marker still opens a log", len(older) == 1,
|
||||
"ADR-0019 D4's discipline: old logs stay readable")
|
||||
|
||||
check("a legacy log can still be stamped",
|
||||
parse(f"# Trial log\n\n{BEGIN} variant=ground-darvo-r0 -->\n\n"
|
||||
"| n | round | step | state_hash | comment |\n|---|---|---|---|---|\n"
|
||||
"| 1 | 3 | Select | abc123def456 | x |\n"
|
||||
f"\n{END}\n")[0]["variant"] == "ground-darvo-r0")
|
||||
|
||||
# CB-WP-0032. A row of the wrong shape must be LOUD. This used to
|
||||
# `continue`, so a format change would have reported zero notes for
|
||||
# every log at once -- the failure the parser's own docstring names.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue