diff --git a/docs/governance/workstreams.md b/docs/governance/workstreams.md index 6bbf86f..70c2f88 100644 --- a/docs/governance/workstreams.md +++ b/docs/governance/workstreams.md @@ -311,6 +311,7 @@ state to its index: [`docs/adr/`](../adr/README.md), [`docs/pdr/`](../pdr/README | D292 | **Who contributes is a sentence nothing enforces, and an outsider has no path** (the maintainer's request, 2026-11-25: collaboration within one organisation and on an open project alike). Measured the same day on a public test project with a small AI agent on an account with no access: the fork's CI waited for a person and ran without secrets, and pr-check refused its gamed sheet; but the contributing guide spoke to members only, K3 sent it to `nstack claim`, and approving one run released that run only (#542, #543) | Proposed: PDR-0025, one answer `contributors: members \| open`, kept with the project's answers, shown in the contributing guide and displayed on the forge (GitHub's pull requests restricted to collaborators, readable as `pull_request_creation_policy`); an absent answer asserts nothing, so an update changes no project; accepted only after two measurements — the setting written through the API, and an agent's App still opening pull requests under `members`; no claim bot, no AI detection, no contributor agreement chosen for the project. Two independent reviews: the findings against the code and the pull request, then the record itself (its default hid a breaking change, now absent-asserts-nothing) | | D293 | **An outside contributor has a path** (#542, found by a rehearsal from a fork on a public test project at v0.34.11): the guide, K3 and the verifier's playbook said nothing to someone with no access | Done: `CONTRIBUTING.md` gains "From outside the organisation" before "Joining the project" and the pull request template points to it; K3 on a fork's pull request says a member can hold the deliverable for its author (`nstack claim D --person @`) and that unheld is acceptable, read from `PR_FROM_FORK` set by the pull-request workflow (absent = not a fork); the verification playbook has the verifier confirm the change delivers the deliverable it names, carries its oracle, and claims only what was run; INSTALL says to approve a fork's workflows from the pull request page. Tests: K3's Action on a fork versus a member's, the workflow's env, the rendered section The section is GitHub's words on GitHub, says off GitHub that a member runs and records the checks, and is absent with no forge (the fresh verifier's finding) | | D294 | **The template's text left in a description is named** (#543): a pull request kept sections at the template's own text ("What it changes", the Summary's ``) and pr-check said nothing; the row copied as an example came from the handbook's table, while the template's own row was already a placeholder T2 refuses | Done: pr-check warns `[template]`, once, naming each paragraph of the description outside the test sheet that is wholly one `<...>` placeholder (HTML tags, comments and attributes are not one); the warning is not a failure and only runs when the description is carried. The handbook's example table now says it is an example from a sign-in module and that a sheet's scenarios come from its own deliverable's acceptance criteria. Tests: a kept placeholder and title heading are named, a filled description is silent, HTML lines stay silent, a placeholder inside the sheet is T2's and not named | +| D295 | **T4 lets an automated row stand at a commit nobody attested** (#548): with `checks: attested`, a pull request verified at X merged the default branch where only another module changed, and T4 refused the automated rows because the relief asked a passing record of X, which projects rarely make (they attest after verifying) — stricter than a row at the head, which needs none | Done: `attest.inputs` takes the commit to read (default `HEAD`); where X has no record at all (a voided one, or one whose `Module checks` failed, is refused as before), `same_inputs` computes the digest from git at X and at the head (same placeholder identity, same base, the scope read from the working tree's manifests — on the forge the test merge, which can only widen it) and the row stands when they are equal, X is in the head's history, and its run, dated by X's commit, is as fresh as a record's; the head's digest is computed once per run, before the head's record is required. When they differ the message is the record path's, with what changed. The git-only digest drops the engine and the runner, which nothing records for an unrecorded commit — as for a row at the head. A record of X is still read first, with its freshness; `checks: forge` unchanged. The handbook's sentence says so. ADR-0006 states no record requirement for the row's commit beyond decision 3's digest, so it is untouched. Tests: no record across a merge of another module stands; a merge that changed `contracts/` or the lockfile is refused naming it; a voided X, a failed X, a stale X, a side-branch X and an X missing a module folder are refused; the head's digest is read once; the keep by record is unchanged | | v0.6.0 | **What is announced refuses, and the documents say what is true**: D51 to D54, and the documentary lot of the internal audit | **Done (2026-09-20)**: five workstreams merged (#83, #84, #85, #86, #87), **v0.6.0 published**, tag on `8ae544c`, verified on published artefacts — including an update of `tool-library` from v0.5.0, 9 files and no conflict, still compliant. Found doing it: D55. Next: the pilot, and M11 beside it | | Pilot | **`NapkinStack/flet`, the first real project**, run by a session that knew nothing of this repository, with the maintainer as decider and this repository's agent as observer — public on the Free plan, where the whole checklist is available, rather than private on Team where G5 is paid and G6 does not exist | **Set aside by the maintainer, 2026-10-15**, at its cycle boundary; the real product followed since is `summit`. **Ran from 2026-09-20**: discovery decided *go* after three rounds and two independent challenges, charter accepted; cycle 01 closed `stopped/reframed`, **cycle 02 closed** with two deliverables accepted and one deferred (its #27), **cycle 03 framed and approved** (#28, #30), which starts its first `critical` module; the framework taken to v0.6.1 by itself at the boundary (#29), v0.6.2 proposed (#31). It has produced D56 to D63, D68, D70 to D77, replicated D26 and D55, and measured D49 — the first figures on what an independent verifier finds (PDR-0003) | | M11 | **Ceremony follows consequence** (PDR-0011): the framework charges what a failure costs, per module and per project, and states each price before it is paid; with PDR-0004's routing, and PDR-0007, PDR-0008 and PDR-0010 — through to v0.7.0 | **Published as v0.7.0 (2026-10-12).** Planned 2026-09-23 (#98). Merged: **M11f** (#101), **M11a** (#102), **M11b** (#103), **M11d** (#104), **M11e** (#105), **M11c** (#106), **M11h** (#107), **M11g** (#108) closed by its probe — not clean, returned to M13; **M11m** (D68, D74, D75); **M11l** (PDR-0010, D59, D60); **M11n** (D79); **M11o** (PDR-0010 extended: every document has its moment); **M11p** (PDR-0002's three levels given a place: `docs/project/rules/`); **M11j** (PDR-0007: the unframed stage); **M11q** (no folder created empty; PDR-0012 proposed: a project's tree is the project's). **M11k** (PDR-0008's print mode: `nstack settings`; D77, D78). **M11s** (PDR-0012 accepted; the framework's files under `.nstack/`; an update carries what a project adapted); **M11u** (an update rewrites the old addresses a project wrote in its own files, D85). **M11t** (`nstack new-contract`: the contracts module is created by the first contract; PDR-0012 built in full); **M11v** (what the third project found: D81, D82, D83, D86, D87). **M11i**: v0.7.0 published 2026-10-12 (#125, D88). To do: **M11r** PDR-0008's apply mode and D57, after a probe on the real forge; the two earlier projects take v0.7.0 themselves, observed | diff --git a/platform/tests/test_attest.py b/platform/tests/test_attest.py index 2ae4319..f7b1fcf 100644 --- a/platform/tests/test_attest.py +++ b/platform/tests/test_attest.py @@ -828,8 +828,8 @@ def test_pr_check_lets_an_automated_row_stand_across_a_merge_in_that_kept_the_mo same = pull_request.same_inputs(root, head, base) main = git(root, "rev-parse", "main") assert same(first[:7]) is None - assert same(main[:7]) == (f"{main[:7]} has no passing record of its module checks: nstack attest with {main[:7]} checked out, " - "and the row stands while what its modules read is unchanged since"), "#491: why, and the cheap path" + assert same(main[:7]) == (f"what its modules read changed between {main[:7]} and the head {head[:7]}: modules/a (1 file)"), \ + "D295: no record at all, read from git — what differs is said, and the cheap path" monkeypatch.setattr(attest, "FRESH_DAYS", -1) assert "is older than -1 days" in pull_request.same_inputs(root, head, base)(first[:7]), "past the bound, re-run" @@ -872,6 +872,138 @@ def test_t4_says_when_the_head_has_no_record_yet(counting): +def test_t4_lets_a_row_stand_at_a_commit_with_no_record_when_git_tells_the_head_s_inputs(counting): + """D295 (#548): a row at a commit nobody attested stands as a row at the head does, when what the + modules read, told from git at both, is the same — here the merge changed only module c. The head + holds no record either: a row at the head asks none.""" + from napkinstack import pull_request + + root = counting + base = modular(root) + first = git(root, "rev-parse", "HEAD") + main_moves(root, "modules/c/code.py") + head = git(root, "rev-parse", "HEAD") + assert attest.latest(root, first) is None and attest.latest(root, head) is None + assert pull_request.same_inputs(root, head, base)(first[:7]) is None + + +@pytest.mark.parametrize("path, said", [("contracts/doc.md", "contracts/doc.md"), ("uv.lock", "uv.lock")]) +def test_t4_names_what_changed_for_a_row_at_a_commit_with_no_record(counting, path, said): + """D295: the merge also changed a shared file — a row without a record is not kept, and T4 says what.""" + from napkinstack import pull_request + + root = counting + base = modular(root) + first = git(root, "rev-parse", "HEAD") + main_moves(root, path) + head = git(root, "rev-parse", "HEAD") + assert pull_request.same_inputs(root, head, base)(first) == \ + f"what its modules read changed between {first} and the head {head[:7]}: {said}" + + +def _unrecorded_refusal(first): + return (f"{first} has no passing record of its module checks: nstack attest with {first} checked out, and the row " + "stands while what its modules read is unchanged since") + + +def test_t4_keeps_refusing_a_voided_commit(counting): + """D295's verifier: only a commit with no record at all is read from git. A voided one is refused as + before, though git tells the head's inputs.""" + from napkinstack import pull_request + + root = counting + base = modular(root) + first = git(root, "rev-parse", "HEAD") + attest.run(root, base, None, "") + attest.void(root, first, "unsound run", base) + main_moves(root, "modules/c/code.py") + head = git(root, "rev-parse", "HEAD") + assert pull_request.same_inputs(root, head, base)(first) == _unrecorded_refusal(first) + + +def test_t4_keeps_refusing_a_commit_whose_module_checks_failed(counting, monkeypatch): + """D295's verifier: a record whose Module checks failed is refused as before, though git tells the + head's inputs.""" + from napkinstack import pull_request + + root = counting + base = modular(root) + first = git(root, "rev-parse", "HEAD") + monkeypatch.setattr(attest, "CHECKS", (attest.Check("Passes", (attest.Step("e", "e", "true"),)), + attest.Check("Module checks", (attest.Step("f", "f", "false"),), kept=True))) + attest.run(root, base, None, "") + assert attest.latest(root, first) is not None + main_moves(root, "modules/c/code.py") + head = git(root, "rev-parse", "HEAD") + assert pull_request.same_inputs(root, head, base)(first) == _unrecorded_refusal(first) + + +def test_t4_asks_a_row_read_from_git_to_be_as_fresh_as_a_record(counting, monkeypatch): + """D295's verifier: past the bound, a row with no record is refused as a recorded one is.""" + from napkinstack import pull_request + + root = counting + base = modular(root) + first = git(root, "rev-parse", "HEAD") + main_moves(root, "modules/c/code.py") + head = git(root, "rev-parse", "HEAD") + assert pull_request.same_inputs(root, head, base)(first) is None + monkeypatch.setattr(attest, "FRESH_DAYS", -1) + assert pull_request.same_inputs(root, head, base)(first) == ( + f"its run at {first} is older than -1 days, or than {attest.FRESH_COMMITS} commits of the default branch") + + +def test_t4_asks_a_row_read_from_git_to_be_in_the_head_s_history(counting): + """D295's verifier: a commit on a side branch with equal inputs is not the head's past.""" + from napkinstack import pull_request + + root = counting + base = modular(root) + first = git(root, "rev-parse", "HEAD") + git(root, "switch", "-q", "-c", "side", first) + git(root, "commit", "-q", "--allow-empty", "-m", "side\n\nAgent-Session: a-session") + side = git(root, "rev-parse", "HEAD") + git(root, "switch", "-q", "work") + main_moves(root, "modules/c/code.py") + head = git(root, "rev-parse", "HEAD") + assert pull_request.same_inputs(root, head, base)(first) is None + assert pull_request.same_inputs(root, head, base)(side) == _unrecorded_refusal(side) + + +def test_t4_refuses_with_the_old_message_when_a_module_folder_is_absent_at_the_commit(counting): + """D295: a digest that cannot be told at the commit — a module folder the head reads is not there — is + not compared.""" + from napkinstack import pull_request + + root = counting + base = modular(root) + git(root, "switch", "-q", "main") + git(root, "rm", "-rq", "modules/b") + git(root, "commit", "-q", "-m", "no b\n\nAgent-Session: a-session") + nob = git(root, "rev-parse", "HEAD") + git(root, "switch", "-q", "work") + git(root, "merge", "-q", "--no-edit", "-s", "ours", "main") # the head keeps b, main's commit does not + head = git(root, "rev-parse", "HEAD") + assert pull_request.same_inputs(root, head, base)(nob) == _unrecorded_refusal(nob) + + +def test_t4_reads_the_head_s_digest_from_git_once(counting, monkeypatch): + """D295's verifier: one computation of the head's digest per run, not per row.""" + from napkinstack import pull_request + + root = counting + base = modular(root) + first = git(root, "rev-parse", "HEAD") + main_moves(root, "modules/c/code.py") + head = git(root, "rev-parse", "HEAD") + seen: list[str] = [] + monkeypatch.setattr(attest, "inputs", lambda root, base, identity="", commit="HEAD", real=attest.inputs: + seen.append(commit) or real(root, base, identity, commit)) + same = pull_request.same_inputs(root, head, base) + assert same(first) is None and same(first[:7]) is None + assert seen.count(head) == 1 + + def test_the_forge_s_run_leaves_a_row_waiting_for_the_head_s_record_to_the_required_status(counting, monkeypatch): """#495: the forge's run starts at the push, before nstack attest writes the head's record. Where the ruleset requires attest's status, T4 does not fail for want of that record, as A1 does not: the row @@ -894,8 +1026,8 @@ def test_the_forge_s_run_leaves_a_row_waiting_for_the_head_s_record_to_the_requi assert len(said) == 1 and said[0].startswith(f"[T4] automated rows run at {first[:7]} wait for the record of the " f"head {head[:7]}: the required status '{attest.CONTEXT}' judges them"), said assert f"Action: nstack attest on the head {head[:7]}" in said[0] - assert same(main[:7]).startswith(f"{main[:7]} has no passing record of its module checks"), \ - "the row's commit has no record: attest at the head would not keep it" + assert same(main[:7]).startswith(f"what its modules read changed between {main[:7]} and the head {head[:7]}"), \ + "the row's commit has no record and git tells another digest: attest at the head would not keep it" monkeypatch.setattr(pull_request, "status_required", lambda root: False) assert pull_request.same_inputs(root, head, base)(first[:7]).startswith(f"the head {head[:7]} has no passing record"), \ "the status not required: the run judges, as before" diff --git a/skeleton/.nstack/handbook/05-workflow.md b/skeleton/.nstack/handbook/05-workflow.md index 9cadc5c..de779a2 100644 --- a/skeleton/.nstack/handbook/05-workflow.md +++ b/skeleton/.nstack/handbook/05-workflow.md @@ -364,8 +364,11 @@ acceptance criteria of its deliverable. person — and the run is at most 7 days old, the default branch moved by 20 commits at most. A module that reads something it does not declare is the risk: declare it in `consumes` — a record cannot be declared: a check never reads one —, and the default branch's own `Module - checks` run catches what was missed once it runs that module. A commit with no passing record - of its own is the case to know: `pr-check`'s T4 says so — `nstack attest` with that commit checked out, and + checks` run catches what was missed once it runs that module. A commit with no record at all stands + when git gives the same inputs digest at that commit and at the head, the commit is in the head's + history, and it is as fresh as a record would have to be (the bounds above); otherwise T4 says what + changed. A commit whose record exists and passed nothing, or that cannot be read from git, is the case + to know: `pr-check`'s T4 says so — `nstack attest` with that commit checked out, and its rows stand without running them again —, as it says a digest that differs, with what changed — a module consumed, a shared file; or, when no file did, the modules run or the engine —, or a run past its bound. The forge's run, made at the push, comes before the head's record: where the diff --git a/src/napkinstack/attest.py b/src/napkinstack/attest.py index a989c53..e688ba6 100644 --- a/src/napkinstack/attest.py +++ b/src/napkinstack/attest.py @@ -414,24 +414,27 @@ def keep_log(root: Path, commit: str, check: str, steps: list[tuple[str, str]]) RECORDS = ("docs/project/", "docs/adr/", "docs/pdr/") -def inputs(root: Path, base: str, identity: str = "") -> str | None: - """The digest of what `Module checks` reads at HEAD (ADR-0006 decision 2, D223): the folders of +def inputs(root: Path, base: str, identity: str = "", commit: str = "HEAD") -> str | None: + """The digest of what `Module checks` reads at `commit`, HEAD by default (ADR-0006 decision 2, D223): the folders of the modules it runs, of those they consume from or assemble, every tracked path outside the module folders — `contracts/` and `platform/` included, which every module reads — but the project's records, `docs/project/`, `docs/adr/` and `docs/pdr/` (D242), and who runs it with which engine; git's ids, never hashed by hand. None when it cannot be told: no key.""" + # The scope is the working tree's: the head locally and under nstack attest; on the forge the checkout + # is the test merge, which can only widen it — conservative (D295). Read at `commit`, a manifest that + # moved in between is a folder read whole, and so a difference. scope = input_scope(root, base) if scope is None: return None names, folders, inside = scope lines = [f"ran {' '.join(names)}", f"identity {identity}"] for folder in sorted(folders): - tree = _git(root, "rev-parse", "--verify", "--quiet", f"HEAD:{folder}", check=False).stdout.strip() + tree = _git(root, "rev-parse", "--verify", "--quiet", f"{commit}:{folder}", check=False).stdout.strip() if not tree: return None lines.append(f"{folder} {tree}") # -z: a path git would quote — a record whose name is not ASCII, `résumé.md` — is read as it is. - listed = _git(root, "ls-tree", "-r", "-z", "--full-tree", "HEAD", check=False) + listed = _git(root, "ls-tree", "-r", "-z", "--full-tree", commit, check=False) if listed.returncode: return None lines += [line for line in listed.stdout.split("\0") diff --git a/src/napkinstack/pull_request.py b/src/napkinstack/pull_request.py index a8a5cf9..461277c 100644 --- a/src/napkinstack/pull_request.py +++ b/src/napkinstack/pull_request.py @@ -931,8 +931,9 @@ def same_inputs(root: Path, head: str, base: str, warn: Callable[[str], None] = lambda message: None) -> Callable[[str], str | None]: """T4's relief for an automated row (D223): the record of the row's commit and the head's hold the same inputs digest, and the row's run is fresh. While nstack attest makes the head's record, - the digest it computed stands in for it. The callable returns None when the row stands, else why - it does not — the cheap path first (#491). The forge's run starts at the push, before that record: + the digest it computed stands in for it; a commit with no record at all stands as the head does, + when git tells the same digest at both, it is in the head's history and fresh (D295). The + callable returns None when the row stands, else why it does not — the cheap path first (#491). The forge's run starts at the push, before that record: where the ruleset requires attest's status, a row waiting for it is left to that status, as A1 is, and said (#495).""" from napkinstack import attest @@ -964,10 +965,31 @@ def head_digest() -> str | None: def same(commit: str) -> str | None: digest = head_digest() # first: it fetches the remote's records, the row's commit's among them full = _git(root, "rev-parse", "--verify", "--quiet", f"{commit}^{{commit}}").stdout.strip() - found = _module_inputs(attest.latest(root, full), root, full) if full else None + record = attest.latest(root, full) if full else None + found = _module_inputs(record, root, full) if full else None if not found: - return (f"{commit} has no passing record of its module checks: nstack attest with {commit} checked out, and " - "the row stands while what its modules read is unchanged since") + unrecorded = (f"{commit} has no passing record of its module checks: nstack attest with {commit} checked out, and " + "the row stands while what its modules read is unchanged since") + # No record at all (D295): what its modules read, told from git at the commit and at the head, as + # for a row at the head, which asks none. A record that exists and passes nothing is refused. + if not full or record is not None \ + or _git(root, "merge-base", "--is-ancestor", full, head).returncode != 0: + return unrecorded + if "git" not in cache: # once per run, not per row + cache["git"] = attest.inputs(root, base, "-", head) + then = attest.inputs(root, base, "-", full) + if not then or not cache["git"]: + return unrecorded + if then != cache["git"]: + return f"what its modules read changed between {commit} and the head {head[:7]}" + \ + _what_changed(root, base, full, head) + base_commit = _git(root, "rev-parse", "--verify", "--quiet", f"{base}^{{commit}}").stdout.strip() or None + made = _git(root, "log", "-1", "--format=%cI", full).stdout.strip() + run_base = _git(root, "merge-base", full, base_commit).stdout.strip() if base_commit else None + if not attest._fresh(root, made, run_base or None, base_commit): + return (f"its run at {commit} is older than {attest.FRESH_DAYS} days, or than " + f"{attest.FRESH_COMMITS} commits of the default branch") + return None if not digest: if cache.get("waits"): if commit not in waiting: