napkinstack 0.31.0__tar.gz → 0.32.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {napkinstack-0.31.0 → napkinstack-0.32.0}/PKG-INFO +4 -4
- {napkinstack-0.31.0 → napkinstack-0.32.0}/README.md +3 -3
- {napkinstack-0.31.0 → napkinstack-0.32.0}/pyproject.toml +2 -1
- {napkinstack-0.31.0 → napkinstack-0.32.0}/pyproject.toml.orig +2 -1
- {napkinstack-0.31.0 → napkinstack-0.32.0}/src/napkinstack/attest.py +159 -33
- {napkinstack-0.31.0 → napkinstack-0.32.0}/src/napkinstack/cli.py +12 -2
- {napkinstack-0.31.0 → napkinstack-0.32.0}/src/napkinstack/doctor.py +18 -6
- {napkinstack-0.31.0 → napkinstack-0.32.0}/src/napkinstack/hold.py +42 -15
- {napkinstack-0.31.0 → napkinstack-0.32.0}/src/napkinstack/pull_request.py +23 -6
- {napkinstack-0.31.0 → napkinstack-0.32.0}/src/napkinstack/settings.py +8 -5
- {napkinstack-0.31.0 → napkinstack-0.32.0}/LICENSE +0 -0
- {napkinstack-0.31.0 → napkinstack-0.32.0}/src/napkinstack/__init__.py +0 -0
- {napkinstack-0.31.0 → napkinstack-0.32.0}/src/napkinstack/__main__.py +0 -0
- {napkinstack-0.31.0 → napkinstack-0.32.0}/src/napkinstack/agent.py +0 -0
- {napkinstack-0.31.0 → napkinstack-0.32.0}/src/napkinstack/assurance.py +0 -0
- {napkinstack-0.31.0 → napkinstack-0.32.0}/src/napkinstack/board.py +0 -0
- {napkinstack-0.31.0 → napkinstack-0.32.0}/src/napkinstack/compat.py +0 -0
- {napkinstack-0.31.0 → napkinstack-0.32.0}/src/napkinstack/discovery.py +0 -0
- {napkinstack-0.31.0 → napkinstack-0.32.0}/src/napkinstack/evidence.py +0 -0
- {napkinstack-0.31.0 → napkinstack-0.32.0}/src/napkinstack/fitness/__init__.py +0 -0
- {napkinstack-0.31.0 → napkinstack-0.32.0}/src/napkinstack/fitness/boundaries.py +0 -0
- {napkinstack-0.31.0 → napkinstack-0.32.0}/src/napkinstack/fitness/hygiene.py +0 -0
- {napkinstack-0.31.0 → napkinstack-0.32.0}/src/napkinstack/fitness/manifests.py +0 -0
- {napkinstack-0.31.0 → napkinstack-0.32.0}/src/napkinstack/fitness/plan.py +0 -0
- {napkinstack-0.31.0 → napkinstack-0.32.0}/src/napkinstack/fitness/pr_scope.py +0 -0
- {napkinstack-0.31.0 → napkinstack-0.32.0}/src/napkinstack/landed.py +0 -0
- {napkinstack-0.31.0 → napkinstack-0.32.0}/src/napkinstack/modules.py +0 -0
- {napkinstack-0.31.0 → napkinstack-0.32.0}/src/napkinstack/owners.py +0 -0
- {napkinstack-0.31.0 → napkinstack-0.32.0}/src/napkinstack/project.py +0 -0
- {napkinstack-0.31.0 → napkinstack-0.32.0}/src/napkinstack/provenance.py +0 -0
- {napkinstack-0.31.0 → napkinstack-0.32.0}/src/napkinstack/skills.py +0 -0
- {napkinstack-0.31.0 → napkinstack-0.32.0}/src/napkinstack/templates/contracts/AGENTS.md +0 -0
- {napkinstack-0.31.0 → napkinstack-0.32.0}/src/napkinstack/templates/contracts/MANIFEST.yaml +0 -0
- {napkinstack-0.31.0 → napkinstack-0.32.0}/src/napkinstack/templates/contracts/README.md +0 -0
- {napkinstack-0.31.0 → napkinstack-0.32.0}/src/napkinstack/templates/contracts/docs/runbook.md +0 -0
- {napkinstack-0.31.0 → napkinstack-0.32.0}/src/napkinstack/templates/contracts/tests/.gitkeep +0 -0
- {napkinstack-0.31.0 → napkinstack-0.32.0}/src/napkinstack/templates/module/AGENTS.md +0 -0
- {napkinstack-0.31.0 → napkinstack-0.32.0}/src/napkinstack/templates/module/MANIFEST.yaml +0 -0
- {napkinstack-0.31.0 → napkinstack-0.32.0}/src/napkinstack/templates/module/README.md +0 -0
- {napkinstack-0.31.0 → napkinstack-0.32.0}/src/napkinstack/templates/module/src/.gitkeep +0 -0
- {napkinstack-0.31.0 → napkinstack-0.32.0}/src/napkinstack/templates/module/tests/.gitkeep +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: napkinstack
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.32.0
|
|
4
4
|
Summary: Engineering framework for several teams and their agents working in one repository: modules, contracts, guardrails in CI.
|
|
5
5
|
License-Expression: MIT
|
|
6
6
|
License-File: LICENSE
|
|
@@ -22,7 +22,7 @@ modules, contracts, guardrails in CI. On the Django or Rails model, one command
|
|
|
22
22
|
the project, which then receives new versions on demand; no application stack is imposed.
|
|
23
23
|
Positioning and vocabulary: [`PRODUCT.md`](PRODUCT.md) §1.
|
|
24
24
|
|
|
25
|
-
> **Status: v0.
|
|
25
|
+
> **Status: v0.32.0, published** on [PyPI](https://pypi.org/project/napkinstack/).
|
|
26
26
|
> What each version changes, engine and project apart: [`CHANGELOG.md`](CHANGELOG.md).
|
|
27
27
|
> What is open: [`docs/governance/workstreams.md`](docs/governance/workstreams.md).
|
|
28
28
|
|
|
@@ -86,8 +86,8 @@ To try it without installing anything, or to install it from this repository ins
|
|
|
86
86
|
registry — always pinned to a release tag:
|
|
87
87
|
|
|
88
88
|
```bash
|
|
89
|
-
uvx --from "git+https://github.com/NapkinStack/engineering-os@v0.
|
|
90
|
-
uv tool install "napkinstack @ git+https://github.com/NapkinStack/engineering-os@v0.
|
|
89
|
+
uvx --from "git+https://github.com/NapkinStack/engineering-os@v0.32.0" nstack init my-project
|
|
90
|
+
uv tool install "napkinstack @ git+https://github.com/NapkinStack/engineering-os@v0.32.0"
|
|
91
91
|
```
|
|
92
92
|
|
|
93
93
|
**Two channels, one published artefact.** The registry publishes: the PyPI artefact of a
|
|
@@ -5,7 +5,7 @@ modules, contracts, guardrails in CI. On the Django or Rails model, one command
|
|
|
5
5
|
the project, which then receives new versions on demand; no application stack is imposed.
|
|
6
6
|
Positioning and vocabulary: [`PRODUCT.md`](PRODUCT.md) §1.
|
|
7
7
|
|
|
8
|
-
> **Status: v0.
|
|
8
|
+
> **Status: v0.32.0, published** on [PyPI](https://pypi.org/project/napkinstack/).
|
|
9
9
|
> What each version changes, engine and project apart: [`CHANGELOG.md`](CHANGELOG.md).
|
|
10
10
|
> What is open: [`docs/governance/workstreams.md`](docs/governance/workstreams.md).
|
|
11
11
|
|
|
@@ -69,8 +69,8 @@ To try it without installing anything, or to install it from this repository ins
|
|
|
69
69
|
registry — always pinned to a release tag:
|
|
70
70
|
|
|
71
71
|
```bash
|
|
72
|
-
uvx --from "git+https://github.com/NapkinStack/engineering-os@v0.
|
|
73
|
-
uv tool install "napkinstack @ git+https://github.com/NapkinStack/engineering-os@v0.
|
|
72
|
+
uvx --from "git+https://github.com/NapkinStack/engineering-os@v0.32.0" nstack init my-project
|
|
73
|
+
uv tool install "napkinstack @ git+https://github.com/NapkinStack/engineering-os@v0.32.0"
|
|
74
74
|
```
|
|
75
75
|
|
|
76
76
|
**Two channels, one published artefact.** The registry publishes: the PyPI artefact of a
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "napkinstack"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.32.0"
|
|
4
4
|
description = "Engineering framework for several teams and their agents working in one repository: modules, contracts, guardrails in CI."
|
|
5
5
|
requires-python = ">=3.12"
|
|
6
6
|
license = "MIT"
|
|
@@ -24,6 +24,7 @@ nstack = "napkinstack.cli:main"
|
|
|
24
24
|
|
|
25
25
|
[dependency-groups]
|
|
26
26
|
dev = ["pytest==9.1.1"]
|
|
27
|
+
audit = ["pip-audit==2.10.1"]
|
|
27
28
|
|
|
28
29
|
[tool.uv]
|
|
29
30
|
required-version = ">=0.12.14,<0.13"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "napkinstack"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.32.0"
|
|
4
4
|
description = "Engineering framework for several teams and their agents working in one repository: modules, contracts, guardrails in CI."
|
|
5
5
|
requires-python = ">=3.12"
|
|
6
6
|
license = "MIT"
|
|
@@ -18,6 +18,7 @@ nstack = "napkinstack.cli:main"
|
|
|
18
18
|
|
|
19
19
|
[dependency-groups]
|
|
20
20
|
dev = ["pytest==9.1.1"]
|
|
21
|
+
audit = ["pip-audit==2.10.1"] # CI's audit of the lock (D234), never installed by uv sync
|
|
21
22
|
|
|
22
23
|
[tool.uv]
|
|
23
24
|
required-version = ">=0.12.14,<0.13"
|
|
@@ -132,20 +132,92 @@ def unplaced(value, root: Path):
|
|
|
132
132
|
return value
|
|
133
133
|
|
|
134
134
|
|
|
135
|
-
def
|
|
136
|
-
"""The
|
|
135
|
+
def _lines(root: Path, commit: str) -> list[dict]:
|
|
136
|
+
"""The runs and voids a commit's note holds, in no order: notes merge line by line, sorted."""
|
|
137
137
|
shown = _git(root, "notes", f"--ref={NOTES}", "show", commit, check=False)
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
runs = []
|
|
141
|
-
for line in shown.stdout.splitlines():
|
|
138
|
+
found = []
|
|
139
|
+
for line in shown.stdout.splitlines() if shown.returncode == 0 else []:
|
|
142
140
|
try:
|
|
143
141
|
run = json.loads(line)
|
|
144
142
|
except json.JSONDecodeError:
|
|
145
143
|
continue
|
|
146
144
|
if isinstance(run, dict) and run.get("record") == RECORD and run.get("commit") == commit:
|
|
147
|
-
|
|
148
|
-
return
|
|
145
|
+
found.append(run)
|
|
146
|
+
return found
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def voided_runs(root: Path, commit: str) -> set[str]:
|
|
150
|
+
"""The runs of a commit a void named, by their time (#429): each void lists the runs the note
|
|
151
|
+
held when it was made, so a clock ahead or a merge of notes never brings one back."""
|
|
152
|
+
return {str(at) for line in _lines(root, commit) if line.get("void") and isinstance(line.get("voids"), list)
|
|
153
|
+
for at in line["voids"]}
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
def latest(root: Path, commit: str) -> dict | None:
|
|
157
|
+
"""The record of a commit: the latest run its note holds that no void named; else its latest
|
|
158
|
+
void, when every run was voided; else None."""
|
|
159
|
+
lines = _lines(root, commit)
|
|
160
|
+
gone = voided_runs(root, commit)
|
|
161
|
+
runs = [line for line in lines if not line.get("void") and str(line.get("at", "")) not in gone]
|
|
162
|
+
voids = [line for line in lines if line.get("void")]
|
|
163
|
+
return max(runs or voids, key=lambda run: str(run.get("at", "")), default=None)
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def kept_from_voided(root: Path, check: dict, commit: str) -> bool:
|
|
167
|
+
"""Whether a check a record kept comes from a run since voided (#429): its first run, on the
|
|
168
|
+
commit it was kept from, or on this one."""
|
|
169
|
+
first = check.get("kept_from") if isinstance(check, dict) else None
|
|
170
|
+
return bool(first) and str(first) in voided_runs(root, str(check.get("kept_commit") or commit))
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
def void(root: Path, ref: str, reason: str, base: str = "origin/main", accept_identity: bool = False) -> int:
|
|
174
|
+
"""Marks a commit's record as known unsound — a run that shared what it must not, a tool that
|
|
175
|
+
lied (#429): a line of its own in the note naming every run the note holds. None of them is a
|
|
176
|
+
record afterwards, nor kept from, on its commit or through another commit's record (D223), and
|
|
177
|
+
pr-check reads the head unattested until it is attested again. The runs stay in the note:
|
|
178
|
+
evidence is never rewritten."""
|
|
179
|
+
reason = " ".join(reason.split())
|
|
180
|
+
if not reason:
|
|
181
|
+
print("FAIL [attest] a void says why: the next reader of the record is owed the reason.\n"
|
|
182
|
+
' Action: nstack attest --void <commit> --reason "<what made it unsound>".')
|
|
183
|
+
return 1
|
|
184
|
+
who, refused = _publishable(root, base, accept_identity)
|
|
185
|
+
if refused:
|
|
186
|
+
print(refused.replace("the record would", "the void would"))
|
|
187
|
+
return 1
|
|
188
|
+
commit = _git(root, "rev-parse", "--verify", "--quiet", f"{ref}^{{commit}}", check=False).stdout.strip()
|
|
189
|
+
remote, unread = read_remote(root)
|
|
190
|
+
if remote is not None and unread:
|
|
191
|
+
print(f"FAIL [attest] the notes of {remote} are not read ({unread}): a void names every run they hold, "
|
|
192
|
+
"and one unread would stay a record.\n Action: fix the access, then again.")
|
|
193
|
+
return 1
|
|
194
|
+
runs = [line for line in _lines(root, commit) if not line.get("void")] if commit else []
|
|
195
|
+
if not runs:
|
|
196
|
+
print(f"FAIL [attest] no record of {ref} to void: nothing is kept from a run that was never recorded.\n"
|
|
197
|
+
" Action: name the commit whose record is unsound (git notes --ref=nstack/checks list).")
|
|
198
|
+
return 1
|
|
199
|
+
line = {"record": RECORD, "commit": commit,
|
|
200
|
+
"at": datetime.datetime.now(datetime.timezone.utc).isoformat(timespec="microseconds"),
|
|
201
|
+
"by": who, "void": unplaced(reason, root), "voids": sorted(str(run.get("at", "")) for run in runs),
|
|
202
|
+
"checks": []}
|
|
203
|
+
before = _git(root, "notes", f"--ref={NOTES}", "show", commit, check=False).stdout.rstrip("\n")
|
|
204
|
+
subprocess.run(["git", "notes", f"--ref={NOTES}", "add", "--force", "--file=-", commit], cwd=root,
|
|
205
|
+
input=before + "\n" + json.dumps(line, separators=(",", ":"), ensure_ascii=False) + "\n",
|
|
206
|
+
text=True, capture_output=True, check=True)
|
|
207
|
+
if not (latest(root, commit) or {}).get("void"):
|
|
208
|
+
print(f"FAIL [attest] the void of {commit[:12]} is written, yet a run stays its record.\n"
|
|
209
|
+
" Action: report it: git notes --ref=nstack/checks show " + commit[:12])
|
|
210
|
+
return 1
|
|
211
|
+
where, pushed = "local only: no remote", True
|
|
212
|
+
if remote is not None:
|
|
213
|
+
sent = _git(root, "push", "--quiet", remote, f"refs/notes/{NOTES}", check=False)
|
|
214
|
+
pushed = sent.returncode == 0
|
|
215
|
+
where = f"pushed to {remote}" if pushed else f"NOT pushed to {remote}: {sent.stderr.strip()}"
|
|
216
|
+
print(f"Record of {commit[:12]}: voided by {who} — {line['void']}; {where}; {_show(root, commit, 0, 0, line['void'])}.\n"
|
|
217
|
+
+ (" Nothing is kept from it any more; the commit is attested again by nstack attest on it."
|
|
218
|
+
if pushed else " Action: push again (git push " + str(remote) + " refs/notes/" + NOTES
|
|
219
|
+
+ "): until then only this clone knows."))
|
|
220
|
+
return 0 if pushed else 1
|
|
149
221
|
|
|
150
222
|
|
|
151
223
|
def _remote(root: Path) -> str | None:
|
|
@@ -215,7 +287,7 @@ def _session(root: Path, commit: str) -> str | None:
|
|
|
215
287
|
return trailers.strip().splitlines()[0] if trailers.strip() else None
|
|
216
288
|
|
|
217
289
|
|
|
218
|
-
def _show(root: Path, commit: str, passed: int, total: int) -> str:
|
|
290
|
+
def _show(root: Path, commit: str, passed: int, total: int, voided: str | None = None) -> str:
|
|
219
291
|
"""The forge's display, when there is one and a token: never a judgement, a view of the record."""
|
|
220
292
|
from napkinstack import hold # the one reading of the project's GitHub
|
|
221
293
|
|
|
@@ -223,8 +295,9 @@ def _show(root: Path, commit: str, passed: int, total: int) -> str:
|
|
|
223
295
|
if forge is None:
|
|
224
296
|
return hold.unshown(root)
|
|
225
297
|
api, repo, token = forge
|
|
226
|
-
body = json.dumps({"state": "success" if passed == total else "failure", "context": CONTEXT,
|
|
227
|
-
"description": f"
|
|
298
|
+
body = json.dumps({"state": "success" if passed == total and voided is None else "failure", "context": CONTEXT,
|
|
299
|
+
"description": f"voided: {voided}"[:140] if voided is not None
|
|
300
|
+
else f"attested: {passed} of {total}"}).encode()
|
|
228
301
|
request = urllib.request.Request(f"{api}/repos/{repo}/statuses/{commit}", data=body, method="POST",
|
|
229
302
|
headers={"Accept": "application/vnd.github+json",
|
|
230
303
|
"Authorization": f"Bearer {token}"})
|
|
@@ -276,22 +349,53 @@ def _shown(root: Path, base: str) -> set[str]:
|
|
|
276
349
|
REASON = 8 # lines of a failed step shown when it says no FAIL line of its own
|
|
277
350
|
|
|
278
351
|
|
|
352
|
+
EXITED = re.compile(r"FAIL \[\w+\] module '[^']+': `.*` exited with \d+\.")
|
|
353
|
+
|
|
354
|
+
|
|
279
355
|
def why(output: str) -> list[str]:
|
|
280
356
|
"""A failed step's reason: its FAIL lines and the indented lines under each (the action), or,
|
|
281
|
-
when it says none, its last lines — a check that failed says why without its whole output (#244).
|
|
357
|
+
when it says none, its last lines — a check that failed says why without its whole output (#244).
|
|
358
|
+
A module command that exited non-zero says no more than its code: the last lines its own tool
|
|
359
|
+
wrote before it come first — a test runner's summary names the test that failed (#428)."""
|
|
282
360
|
lines = output.splitlines()
|
|
283
|
-
said, under = [], False
|
|
361
|
+
said, under, tool, audit = [], False, [], False
|
|
284
362
|
for line in lines:
|
|
285
363
|
if line.startswith("FAIL"):
|
|
364
|
+
if EXITED.match(line):
|
|
365
|
+
said.extend(tool[-REASON:])
|
|
366
|
+
tool = []
|
|
286
367
|
said.append(line)
|
|
287
368
|
under = True
|
|
288
369
|
elif under and line.startswith(" "):
|
|
289
370
|
said.append(line)
|
|
290
371
|
else:
|
|
291
372
|
under = False
|
|
373
|
+
if line.startswith(("::group::", "-> ")):
|
|
374
|
+
tool, audit = [], False # a module's own command writes after the engine says it runs it
|
|
375
|
+
elif line.startswith("Evidence of "):
|
|
376
|
+
audit = True # and before the engine audits its evidence: those lines are the engine's
|
|
377
|
+
elif line.strip() and not audit and not line.startswith(("FAIL", "::")):
|
|
378
|
+
tool.append(line)
|
|
292
379
|
return said or [line for line in lines if line.strip()][-REASON:]
|
|
293
380
|
|
|
294
381
|
|
|
382
|
+
LOG_KEPT = 8 * 1024 * 1024 # bytes of a failed step's output kept in its log, the last ones
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
def keep_log(root: Path, commit: str, check: str, steps: list[tuple[str, str]]) -> Path:
|
|
386
|
+
"""A failed check's whole output, in the clone's git folder — never in the tree, where it would
|
|
387
|
+
leave changes the next attest refuses: the record keeps 64 KiB of it and a FAIL line a few
|
|
388
|
+
lines; a test that fails once and passes again is named here, or nowhere (#428). Its last
|
|
389
|
+
8 MiB when longer; the next failure of the same commit and check replaces it."""
|
|
390
|
+
folder = (root / _git(root, "rev-parse", "--git-path", "nstack/attest").stdout.strip()).resolve()
|
|
391
|
+
folder.mkdir(parents=True, exist_ok=True)
|
|
392
|
+
path = folder / f"{commit[:12]}-{re.sub(r'[^a-z0-9]+', '-', check.lower()).strip('-')}.log"
|
|
393
|
+
text = steps[0][1] if len(steps) == 1 else "".join(f"== {label}\n{output.rstrip(chr(10))}\n" for label, output in steps)
|
|
394
|
+
data = text.encode("utf-8", "replace")
|
|
395
|
+
path.write_bytes(data if len(data) <= LOG_KEPT else data[-LOG_KEPT:])
|
|
396
|
+
return path
|
|
397
|
+
|
|
398
|
+
|
|
295
399
|
# An engine whose code a string names: published, a forge's commit, or a checkout's own commit.
|
|
296
400
|
NAMED = re.compile(r".* \(commit [0-9a-f]{7,}\)|.*@[0-9a-f]{7,}|a local checkout at (?!an unknown commit)\S+(?<!-dirty)")
|
|
297
401
|
|
|
@@ -367,7 +471,7 @@ def _by_inputs(root: Path, base: str, digest: str | None, check: Check, engine:
|
|
|
367
471
|
if digest is None or not check.kept or base_commit is None or not (origin is None or NAMED.fullmatch(origin)):
|
|
368
472
|
return None
|
|
369
473
|
for commit in _git(root, "rev-list", f"{base_commit}..HEAD", check=False).stdout.split():
|
|
370
|
-
record = latest(root, commit)
|
|
474
|
+
record = latest(root, commit) # a voided commit's latest line is its void: no check is kept from it
|
|
371
475
|
if record is None or (record.get("engine"), record.get("origin"), record.get("published"),
|
|
372
476
|
record.get("by")) != (engine, said, origin is None, who):
|
|
373
477
|
continue
|
|
@@ -375,6 +479,8 @@ def _by_inputs(root: Path, base: str, digest: str | None, check: Check, engine:
|
|
|
375
479
|
found = next((c for c in checks if isinstance(c, dict) and c.get("name") == check.name), None)
|
|
376
480
|
if not found or found.get("passed") is not True or found.get("inputs") != digest:
|
|
377
481
|
continue
|
|
482
|
+
if kept_from_voided(root, found, commit):
|
|
483
|
+
continue # kept, through this record, from a run since voided (#429)
|
|
378
484
|
first = str(found.get("kept_from") or record.get("at", ""))
|
|
379
485
|
run_base = found.get("kept_base") or record.get("base_commit")
|
|
380
486
|
if not _fresh(root, first, run_base, base_commit):
|
|
@@ -384,7 +490,7 @@ def _by_inputs(root: Path, base: str, digest: str | None, check: Check, engine:
|
|
|
384
490
|
|
|
385
491
|
|
|
386
492
|
def _kept(previous: dict | None, check: Check, engine: str, origin: str | None, base_commit: str | None,
|
|
387
|
-
who: str, said: str | None = None) -> dict | None:
|
|
493
|
+
who: str, said: str | None = None, root: Path | None = None) -> dict | None:
|
|
388
494
|
"""The check as the commit's record last passed it, when what it reads is the same: the commit,
|
|
389
495
|
the base commit, the engine — published, or one whose commit names its code — and the person who
|
|
390
496
|
ran it. A sheet filled in between changes the description, which this check never reads (#275).
|
|
@@ -399,6 +505,8 @@ def _kept(previous: dict | None, check: Check, engine: str, origin: str | None,
|
|
|
399
505
|
found = next((c for c in checks if isinstance(c, dict) and c.get("name") == check.name), None)
|
|
400
506
|
if not found or found.get("passed") is not True or found.get("kept_commit"):
|
|
401
507
|
return None # kept by its inputs from another commit: its freshness is _by_inputs' to judge (D223)
|
|
508
|
+
if root is not None and kept_from_voided(root, found, str(previous.get("commit", ""))):
|
|
509
|
+
return None # kept, on this commit, from a run since voided: a clone that had not seen the void (#429)
|
|
402
510
|
return {**found, "kept_from": found.get("kept_from") or previous.get("at")}
|
|
403
511
|
|
|
404
512
|
|
|
@@ -416,26 +524,34 @@ def sheet_of(body: str) -> dict | None:
|
|
|
416
524
|
return found or None
|
|
417
525
|
|
|
418
526
|
|
|
419
|
-
def
|
|
420
|
-
|
|
421
|
-
|
|
527
|
+
def _publishable(root: Path, base: str, accept_identity: bool) -> tuple[str, str | None]:
|
|
528
|
+
"""Who a line of the notes will name, and why it may not travel: the notes go to the remote, and
|
|
529
|
+
never publish an address the project does not already show (#235) — a run's record, or a void."""
|
|
422
530
|
who, address = _identity(root)
|
|
423
531
|
remote = _remote(root)
|
|
424
532
|
if remote is not None and not accept_identity and not NOREPLY.fullmatch(address):
|
|
425
533
|
if _git(root, "rev-parse", "--verify", "--quiet", f"{base}^{{commit}}", check=False).returncode != 0:
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
return 1
|
|
534
|
+
return who, (f"FAIL [attest] base '{base}' not found: the identities the project already shows cannot "
|
|
535
|
+
f"be read, and the record would travel to {remote}.\n"
|
|
536
|
+
" Action: fetch the base (git fetch), or pass --base with a commit of the shared history.")
|
|
430
537
|
# No remote: nothing travels — the record stays in this repository, whoever ran it.
|
|
431
538
|
if remote is not None and not accept_identity and not NOREPLY.fullmatch(address) and address not in _shown(root, base):
|
|
432
539
|
# A record travels with the notes to the remote: it never publishes an address the project
|
|
433
540
|
# does not already show — a fresh clone falls back on a workstation's personal identity (#235).
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
541
|
+
return who, (f"FAIL [attest] the record would name {who or 'no one'}, an identity this project's history "
|
|
542
|
+
f"does not show — it travels with the notes to {remote}.\n"
|
|
543
|
+
" Action: set this checkout's identity to the one the project works under "
|
|
544
|
+
"(git config user.name / user.email), or, for a first record of your own, "
|
|
545
|
+
"nstack attest --accept-identity.")
|
|
546
|
+
return who, None
|
|
547
|
+
|
|
548
|
+
|
|
549
|
+
def run(root: Path, base: str, body_file: Path | None, labels: str | None, accept_identity: bool = False,
|
|
550
|
+
again: bool = False) -> int:
|
|
551
|
+
print(provenance.judged_by(root), flush=True)
|
|
552
|
+
who, refused = _publishable(root, base, accept_identity)
|
|
553
|
+
if refused:
|
|
554
|
+
print(refused)
|
|
439
555
|
return 1
|
|
440
556
|
if _git(root, "status", "--porcelain", "--untracked-files=normal").stdout.strip():
|
|
441
557
|
print("FAIL [attest] the tree holds changes: a record names one commit, and this tree is none.\n"
|
|
@@ -445,6 +561,7 @@ def run(root: Path, base: str, body_file: Path | None, labels: str | None, accep
|
|
|
445
561
|
engine, origin = provenance.engine()
|
|
446
562
|
base_commit = _git(root, "rev-parse", "--verify", "--quiet", f"{base}^{{commit}}", check=False).stdout.strip() or None
|
|
447
563
|
previous = None if again else latest(root, commit)
|
|
564
|
+
previous = None if previous and previous.get("void") else previous # a void keeps nothing, evidence included
|
|
448
565
|
# The option, else PR_LABELS as the caller set it: one way for attest and pr-check (D147) — and the
|
|
449
566
|
# pull request's own when the forge answers, a label it does not carry refused (#368).
|
|
450
567
|
from napkinstack.pull_request import labels_for
|
|
@@ -470,7 +587,7 @@ def run(root: Path, base: str, body_file: Path | None, labels: str | None, accep
|
|
|
470
587
|
digest = inputs(root, base, json.dumps([engine, unplaced(origin, root), origin is None, who]))
|
|
471
588
|
env["NSTACK_INPUTS"] = digest or "" # the head's, for pr-check's T4 while this record is made (D223)
|
|
472
589
|
for check in CHECKS:
|
|
473
|
-
kept = _kept(previous, check, engine, origin, base_commit, who, unplaced(origin, root))
|
|
590
|
+
kept = _kept(previous, check, engine, origin, base_commit, who, unplaced(origin, root), root)
|
|
474
591
|
if kept is not None:
|
|
475
592
|
results.append(kept)
|
|
476
593
|
print(f"ok [attest] {check.name}: kept from the record of {kept['kept_from']} — same commit, base "
|
|
@@ -484,21 +601,30 @@ def run(root: Path, base: str, body_file: Path | None, labels: str | None, accep
|
|
|
484
601
|
f"same inputs ({digest[:12]}), within {FRESH_DAYS} days and {FRESH_COMMITS} commits of the "
|
|
485
602
|
"default branch (nstack attest --again runs it)", flush=True)
|
|
486
603
|
continue
|
|
487
|
-
steps = []
|
|
604
|
+
steps, outputs = [], []
|
|
488
605
|
for step in check.steps:
|
|
489
|
-
done = subprocess.run(["bash", "-c", step.command], cwd=root, env=env,
|
|
490
|
-
|
|
606
|
+
done = subprocess.run(["bash", "-c", step.command], cwd=root, env=env, stdout=subprocess.PIPE,
|
|
607
|
+
stderr=subprocess.STDOUT, text=True, errors="replace")
|
|
491
608
|
steps.append({"label": step.label, "command": step.command, "exit": done.returncode,
|
|
492
609
|
"output": capped(done.stdout),
|
|
493
610
|
"sha256": hashlib.sha256(done.stdout.encode("utf-8", "replace")).hexdigest()})
|
|
611
|
+
outputs.append(done.stdout)
|
|
494
612
|
passed = all(step["exit"] == 0 for step in steps)
|
|
495
613
|
results.append({"name": check.name, "passed": passed, "steps": steps,
|
|
496
614
|
**({"inputs": digest} if check.kept and digest else {})})
|
|
497
615
|
failed = "; ".join(f"{s['label']} exited {s['exit']}" for s in steps if s["exit"])
|
|
498
616
|
print(f"FAIL [attest] {check.name}: {failed}" if failed else f"ok [attest] {check.name}", flush=True)
|
|
499
|
-
for step in steps:
|
|
617
|
+
for step, whole in zip(steps, outputs):
|
|
500
618
|
if step["exit"]:
|
|
501
|
-
print("\n".join(f" {line}" for line in why(
|
|
619
|
+
print("\n".join(f" {line}" for line in why(whole)), flush=True)
|
|
620
|
+
if failed:
|
|
621
|
+
try:
|
|
622
|
+
log = keep_log(root, commit, check.name, [(s["label"], o) for s, o in zip(steps, outputs)])
|
|
623
|
+
except OSError as error: # a full or read-only disk never costs the record
|
|
624
|
+
print(f" whole output: not kept ({error.strerror})", flush=True)
|
|
625
|
+
else:
|
|
626
|
+
shown = log.relative_to(root) if log.is_relative_to(root) else log
|
|
627
|
+
print(f" whole output: {shown}", flush=True)
|
|
502
628
|
record = {"record": RECORD, "commit": commit,
|
|
503
629
|
"at": datetime.datetime.now(datetime.timezone.utc).isoformat(timespec="microseconds"),
|
|
504
630
|
"engine": engine, "origin": origin, "published": origin is None, "by": who, "session": _session(root, commit),
|
|
@@ -176,7 +176,8 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
176
176
|
ld.add_argument("--span", default="HEAD~1..HEAD",
|
|
177
177
|
help="the commits to read, BEFORE..AFTER (default: the last commit)")
|
|
178
178
|
at = _add(sub, "attest", "runs the CI's checks here and records the run on the commit, in git",
|
|
179
|
-
lambda a: attest.
|
|
179
|
+
lambda a: attest.void(a.root, a.void, a.reason or "", a.base, a.accept_identity) if a.void
|
|
180
|
+
else attest.run(a.root, a.base, a.body_file, a.labels, a.accept_identity, a.again))
|
|
180
181
|
at.add_argument("--base", default="origin/main")
|
|
181
182
|
at.add_argument("--body-file", type=Path, help="the pull request's description, for its checks")
|
|
182
183
|
at.add_argument("--labels", help="the pull request's labels, comma-separated (default: PR_LABELS); with a "
|
|
@@ -185,6 +186,10 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
185
186
|
help="record under an identity the project's history does not show yet — a first record of yours")
|
|
186
187
|
at.add_argument("--again", action="store_true",
|
|
187
188
|
help="runs every check, even the module checks this commit's record passed with the same base and engine")
|
|
189
|
+
at.add_argument("--void", metavar="COMMIT",
|
|
190
|
+
help="marks COMMIT's record as known unsound, with --reason: no check is kept from it any more, "
|
|
191
|
+
"and pr-check reads it unattested until attested again; nothing runs")
|
|
192
|
+
at.add_argument("--reason", help="why the record is unsound, with --void")
|
|
188
193
|
cl = _add(sub, "claim", "takes a ready deliverable for a session, before its first change; "
|
|
189
194
|
"the shared remote refuses a second taker",
|
|
190
195
|
lambda a: hold.claim(a.root, a.deliverable, a.session, a.person, a.take_over))
|
|
@@ -314,7 +319,12 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
314
319
|
os.environ.pop(name, None)
|
|
315
320
|
if late := provenance.behind(_named_root(argv)):
|
|
316
321
|
print(late, file=sys.stderr, flush=True)
|
|
317
|
-
|
|
322
|
+
parser = build_parser()
|
|
323
|
+
args = parser.parse_args(argv)
|
|
324
|
+
if args.command == "attest" and (bool(args.void) != bool(args.reason) or (args.void and (args.again or args.body_file
|
|
325
|
+
or args.labels))):
|
|
326
|
+
parser.error("attest: --void and --reason go together, and with no run: never with --again, "
|
|
327
|
+
"--body-file or --labels")
|
|
318
328
|
if args.command in JUDGES:
|
|
319
329
|
print(provenance.judged_by(args.root), flush=True)
|
|
320
330
|
if said := plan.stage_line(args.root):
|
|
@@ -46,9 +46,9 @@ Rules:
|
|
|
46
46
|
N2 information, never a gap (D219): a workflow whose last runs on the default branch all
|
|
47
47
|
failed — RED_STREAK or more in a row — named with its first failing run. A workflow outside
|
|
48
48
|
the required checks can stay red for weeks while every pull request merges green
|
|
49
|
-
G1-
|
|
49
|
+
G1-G22 the GitHub settings of CHECKLIST; G6 is not applicable outside a public
|
|
50
50
|
repository, G21 outside `approval: agent`, and on a private one G1-G5, G12, G13, G17,
|
|
51
|
-
G18
|
|
51
|
+
G18 and G20-G22 name the GitHub plan or option required
|
|
52
52
|
|
|
53
53
|
Off GitHub (the project's `forge` answer, ADR-0010) no G rule is read: the forge-neutral
|
|
54
54
|
PROTECTIONS are said as information — the same list as INSTALL.md's, bound by a test — and the
|
|
@@ -88,7 +88,7 @@ OUT_OF_REACH = "OUT OF REACH" # the plan forbids it: a state, not a fault (
|
|
|
88
88
|
NOT_READ = "NOT READ" # an optional read that did not answer: said, never counted (L10)
|
|
89
89
|
# The settings that make the forge refuse a merge. A repository is guarded when they are
|
|
90
90
|
# all in force; the others matter and none of them stops a merge.
|
|
91
|
-
BLOCKING = ("G1", "G2", "G3", "G4", "G12", "G13", "G21")
|
|
91
|
+
BLOCKING = ("G1", "G2", "G3", "G4", "G12", "G13", "G21", "G22")
|
|
92
92
|
API_VERSION = "2026-03-10"
|
|
93
93
|
JOBS = ("Fitness functions", "PR scope and review budget", "Hooks and secrets", "Test sheet and cycle",
|
|
94
94
|
"Module checks")
|
|
@@ -169,6 +169,10 @@ CHECKLIST = [ # (rule, setting, action)
|
|
|
169
169
|
# approves what they pushed — the author's own fix included.
|
|
170
170
|
("G21", "The most recent push approved by someone other than its pusher (approval: agent)",
|
|
171
171
|
f"{RULESET}: require approval of the most recent reviewable push"),
|
|
172
|
+
# G22: two pull requests each green on its own base can turn main red together (#430): the
|
|
173
|
+
# checks pass on what will land only when a branch is up to date with main before it merges.
|
|
174
|
+
("G22", "Branches up to date before merging: the checks judged what will land, main included",
|
|
175
|
+
f"{RULESET}: require status checks — require branches to be up to date before merging"),
|
|
172
176
|
]
|
|
173
177
|
|
|
174
178
|
# Asked of a project only on one of its answers: elsewhere not applicable, and said why.
|
|
@@ -187,7 +191,7 @@ def unasked(rule: str, answers: dict) -> str | None:
|
|
|
187
191
|
# (GitHub documentation, 2026-09-15).
|
|
188
192
|
PUBLIC_ONLY = {"G6": "private vulnerability reporting only exists for a public repository; "
|
|
189
193
|
"state an internal channel in SECURITY.md"}
|
|
190
|
-
PRIVATE_PLAN = dict.fromkeys(("G1", "G2", "G3", "G4", "G12", "G13", "G17", "G18", "G20", "G21"),
|
|
194
|
+
PRIVATE_PLAN = dict.fromkeys(("G1", "G2", "G3", "G4", "G12", "G13", "G17", "G18", "G20", "G21", "G22"),
|
|
191
195
|
"Private repository: rulesets require the GitHub Team plan (organisation) "
|
|
192
196
|
"or Pro (personal account); without it, nothing blocks the merge.")
|
|
193
197
|
PRIVATE_PLAN["G5"] = ("Private repository: Secret Protection is a paid option; without it, only the "
|
|
@@ -250,6 +254,12 @@ def _rule(client: GitHub, kind: str) -> dict | None:
|
|
|
250
254
|
return next((rule for rule in _rules(client) if rule.get("type") == kind), None)
|
|
251
255
|
|
|
252
256
|
|
|
257
|
+
def _status_rules(client: GitHub) -> list[dict]:
|
|
258
|
+
"""Every required-checks rule that applies, from every ruleset: GitHub layers them and the
|
|
259
|
+
strictest holds, so one rule read alone can say less than the branch gets (D239)."""
|
|
260
|
+
return [rule.get("parameters") or {} for rule in _rules(client) if rule.get("type") == "required_status_checks"]
|
|
261
|
+
|
|
262
|
+
|
|
253
263
|
# A name at a hold's depth, nstack/hold/<cycle>/<id>: GitHub answers for a branch that need not
|
|
254
264
|
# exist, and a ruleset's `**` stops at a slash (fnmatch, FNM_PATHNAME) — a probe one level up
|
|
255
265
|
# would read a pattern that covers no hold.
|
|
@@ -347,8 +357,8 @@ CHECKS: dict[str, Callable[[GitHub], bool]] = {
|
|
|
347
357
|
"G1": lambda c: _rule(c, "pull_request") is not None,
|
|
348
358
|
"G2": lambda c: _parameters(c, "pull_request").get("required_approving_review_count", 0) >= 1,
|
|
349
359
|
"G3": lambda c: _parameters(c, "pull_request").get("require_code_owner_review") is True,
|
|
350
|
-
"G4": lambda c: set(JOBS) <= {check.get("context") for
|
|
351
|
-
|
|
360
|
+
"G4": lambda c: set(JOBS) <= {check.get("context") for rule in _status_rules(c)
|
|
361
|
+
for check in rule.get("required_status_checks", [])},
|
|
352
362
|
"G5": _security,
|
|
353
363
|
"G6": lambda c: c.get("/private-vulnerability-reporting").get("enabled") is True,
|
|
354
364
|
"G7": _allowed_actions,
|
|
@@ -367,6 +377,8 @@ CHECKS: dict[str, Callable[[GitHub], bool]] = {
|
|
|
367
377
|
"G19": lambda c: _merges(c, "default_branch").get("default_branch") == "main",
|
|
368
378
|
"G20": _holds_kept,
|
|
369
379
|
"G21": lambda c: _parameters(c, "pull_request").get("require_last_push_approval") is True,
|
|
380
|
+
"G22": lambda c: (any(rule.get("strict_required_status_checks_policy") is True for rule in _status_rules(c))
|
|
381
|
+
or _rule(c, "merge_queue") is not None), # a queue checks what will land, too
|
|
370
382
|
}
|
|
371
383
|
|
|
372
384
|
|
|
@@ -259,12 +259,38 @@ def _record(root: Path, name: str | None, cycle: str, ident: str, sha: str) -> t
|
|
|
259
259
|
_git(root, "update-ref", f"refs/heads/{branch}", sha, check=True)
|
|
260
260
|
return True, "local only: no remote, nobody else sees it"
|
|
261
261
|
pushed = _git(root, "push", "--quiet", name, f"{sha}:refs/heads/{branch}")
|
|
262
|
-
if pushed.returncode != 0:
|
|
263
|
-
return False, pushed.stderr.strip()
|
|
262
|
+
if pushed.returncode != 0: # a hook may give its reason on either stream (#427)
|
|
263
|
+
return False, "\n ".join(line for line in (pushed.stdout + pushed.stderr).strip().splitlines() if line.strip())
|
|
264
264
|
_git(root, "update-ref", f"{MIRROR}/hold/{cycle}/{ident}", sha, check=True)
|
|
265
265
|
return True, f"pushed to {name}"
|
|
266
266
|
|
|
267
267
|
|
|
268
|
+
def _after_refusal(root: Path, cycle: str, ident: str, before: str | None, sha: str) -> str:
|
|
269
|
+
"""After a refused push, what the remote holds now (#427): "recorded" when it has this event
|
|
270
|
+
after all (git failed after the remote took it), "moved" when another event came first, "same"
|
|
271
|
+
when nothing moved — the push itself was refused —, "unknown" when it cannot be read again."""
|
|
272
|
+
try:
|
|
273
|
+
fetch(root, again=True)
|
|
274
|
+
except Unreachable:
|
|
275
|
+
return "unknown"
|
|
276
|
+
tip = read(root, cycle, ident).tip
|
|
277
|
+
return "recorded" if tip == sha else "same" if tip == before else "moved"
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
def _refusal(command: str, ident: str, where: str, state: str) -> str | None:
|
|
281
|
+
"""What a refused push is said as; None when the event is on the remote after all."""
|
|
282
|
+
if state == "recorded":
|
|
283
|
+
return None
|
|
284
|
+
if state == "moved":
|
|
285
|
+
return f"FAIL [{command}] {ident}'s hold moved meanwhile: {where}\n Action: run nstack plan, then again."
|
|
286
|
+
said = ("and the hold did not move: nothing was recorded" if state == "same"
|
|
287
|
+
else "and the remote cannot be read again: whether the hold moved is not known")
|
|
288
|
+
# A hook, a protection or a credential said no: running `nstack plan` again changes none of it.
|
|
289
|
+
return (f"FAIL [{command}] {ident}: the push was refused, {said}.\n {where}\n"
|
|
290
|
+
" Action: fix what the refusal above names (the clone's own pre-push hook, a protection "
|
|
291
|
+
"of the remote, its credentials), then again.")
|
|
292
|
+
|
|
293
|
+
|
|
268
294
|
def slug(title: str) -> str:
|
|
269
295
|
"""A branch name from a title: its first words, never a word cut."""
|
|
270
296
|
plain = unicodedata.normalize("NFKD", title).encode("ascii", "ignore").decode()
|
|
@@ -507,18 +533,17 @@ def claim(root: Path, ident: str, session: str | None = None, person: str | None
|
|
|
507
533
|
sha = _event(root, current.tip, ident, event, person, session, previous)
|
|
508
534
|
ok, where = _record(root, name, cycle, ident, sha)
|
|
509
535
|
if not ok:
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
pass
|
|
514
|
-
winner = read(root, cycle, ident)
|
|
515
|
-
if winner.tip != current.tip:
|
|
536
|
+
state = _after_refusal(root, cycle, ident, current.tip, sha)
|
|
537
|
+
if state == "moved":
|
|
538
|
+
winner = read(root, cycle, ident)
|
|
516
539
|
print(f"FAIL [hold] {ident} was taken first: "
|
|
517
540
|
f"{said(winner) if winner.held else 'given back meanwhile'}.\n"
|
|
518
541
|
" Action: take another ready deliverable — nstack plan lists them; or run again.")
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
542
|
+
return 1
|
|
543
|
+
if refused := _refusal("hold", ident, where, state):
|
|
544
|
+
print(refused)
|
|
545
|
+
return 1
|
|
546
|
+
where = f"pushed to {name}" # git failed after the remote took it: the event is on record
|
|
522
547
|
left = f"{previous.person}, session {', '.join(previous.sessions)}" if previous and previous.sessions \
|
|
523
548
|
else (previous.person if previous else "")
|
|
524
549
|
done = {"claim": "taken", "renew": "renewed", "take-over": f"taken over from {left}"}
|
|
@@ -613,9 +638,10 @@ def release(root: Path, ident: str, session: str | None = None, person: str | No
|
|
|
613
638
|
return 1
|
|
614
639
|
sha = _event(root, current.tip, ident, "release", person, session)
|
|
615
640
|
ok, where = _record(root, name, stem, ident, sha)
|
|
616
|
-
if not ok:
|
|
617
|
-
print(
|
|
641
|
+
if not ok and (refused := _refusal("hold", ident, where, _after_refusal(root, stem, ident, current.tip, sha))):
|
|
642
|
+
print(refused)
|
|
618
643
|
return 1
|
|
644
|
+
where = where if ok else f"pushed to {name}"
|
|
619
645
|
print(f"{ident} released by {person}; {where}. Its branches are kept.")
|
|
620
646
|
return 0
|
|
621
647
|
|
|
@@ -1025,9 +1051,10 @@ def deliver(root: Path, ident: str, given: list[str], session: str | None = None
|
|
|
1025
1051
|
sha = _event(root, current.tip, ident, "deliver", person, session,
|
|
1026
1052
|
criteria=[f"{number} {' '.join(answers[number])}" for number in sorted(answers)])
|
|
1027
1053
|
ok, where = _record(root, name, cycle, ident, sha)
|
|
1028
|
-
if not ok:
|
|
1029
|
-
print(
|
|
1054
|
+
if not ok and (refused := _refusal("deliver", ident, where, _after_refusal(root, cycle, ident, current.tip, sha))):
|
|
1055
|
+
print(refused)
|
|
1030
1056
|
return 1
|
|
1057
|
+
where = where if ok else f"pushed to {name}"
|
|
1031
1058
|
print(f"{ident} delivered, on record; {where}. No pull request: nstack plan says it, and the closure writes the state.")
|
|
1032
1059
|
return 0
|
|
1033
1060
|
|
|
@@ -777,12 +777,17 @@ def status_required(root: Path) -> bool:
|
|
|
777
777
|
for rule in rules if isinstance(rules, list))
|
|
778
778
|
|
|
779
779
|
|
|
780
|
-
def _module_inputs(record: dict | None) -> tuple[str, str, str | None] | None:
|
|
781
|
-
"""A record's `Module checks` digest, its first run's time and base (ADR-0006, D223)
|
|
780
|
+
def _module_inputs(record: dict | None, root: Path | None = None, commit: str = "") -> tuple[str, str, str | None] | None:
|
|
781
|
+
"""A record's `Module checks` digest, its first run's time and base (ADR-0006, D223); none when
|
|
782
|
+
it was kept from a run since voided (#429)."""
|
|
783
|
+
from napkinstack import attest
|
|
784
|
+
|
|
782
785
|
checks = record.get("checks") if isinstance(record, dict) and isinstance(record.get("checks"), list) else []
|
|
783
786
|
found = next((c for c in checks if isinstance(c, dict) and c.get("name") == "Module checks"), None)
|
|
784
787
|
if not found or found.get("passed") is not True or not found.get("inputs"):
|
|
785
788
|
return None
|
|
789
|
+
if root is not None and attest.kept_from_voided(root, found, commit):
|
|
790
|
+
return None
|
|
786
791
|
return str(found["inputs"]), str(found.get("kept_from") or record.get("at", "")), \
|
|
787
792
|
found.get("kept_base") or record.get("base_commit")
|
|
788
793
|
|
|
@@ -807,14 +812,14 @@ def same_inputs(root: Path, head: str, base: str) -> Callable[[str], bool]:
|
|
|
807
812
|
cache["head"] = os.environ.get("NSTACK_INPUTS") or None
|
|
808
813
|
else:
|
|
809
814
|
attest.read_remote(root)
|
|
810
|
-
found = _module_inputs(attest.latest(root, head))
|
|
815
|
+
found = _module_inputs(attest.latest(root, head), root, head)
|
|
811
816
|
cache["head"] = found[0] if found else None
|
|
812
817
|
return cache["head"]
|
|
813
818
|
|
|
814
819
|
def same(commit: str) -> bool:
|
|
815
820
|
full = _git(root, "rev-parse", "--verify", "--quiet", f"{commit}^{{commit}}").stdout.strip()
|
|
816
821
|
digest = head_digest()
|
|
817
|
-
found = _module_inputs(attest.latest(root, full)) if full and digest else None
|
|
822
|
+
found = _module_inputs(attest.latest(root, full), root, full) if full and digest else None
|
|
818
823
|
base_commit = _git(root, "rev-parse", "--verify", "--quiet", f"{base}^{{commit}}").stdout.strip() or None
|
|
819
824
|
return bool(found and found[0] == digest and attest._fresh(root, found[1], found[2], base_commit))
|
|
820
825
|
|
|
@@ -838,12 +843,14 @@ def check_attested(root: Path, head: str, fail, warn=lambda message: None) -> st
|
|
|
838
843
|
shown = ""
|
|
839
844
|
if record:
|
|
840
845
|
passed = sum(1 for check in record["checks"] if check["passed"])
|
|
841
|
-
shown = f"; a record of the head:
|
|
846
|
+
shown = (f"; a record of the head: voided — {record['void']} (information)" if record.get("void")
|
|
847
|
+
else f"; a record of the head: attested {passed} of {len(record['checks'])} (information)")
|
|
842
848
|
return "the forge's CI" + shown
|
|
843
849
|
if os.environ.get("NSTACK_ATTESTING") == head:
|
|
844
850
|
return "attested — this run is the record being made"
|
|
845
851
|
if status_required(root):
|
|
846
|
-
if record is not None and not all(check["passed"] for check in record["checks"])
|
|
852
|
+
if record is not None and (record.get("void") or not all(check["passed"] for check in record["checks"])
|
|
853
|
+
or any(attest.kept_from_voided(root, check, head) for check in record["checks"])):
|
|
847
854
|
# The status is the last attest that could post one; a later run without a token is in the
|
|
848
855
|
# notes only — said, since the forge's green may be an earlier record's.
|
|
849
856
|
warn(f"[A2] the latest record of the head {head[:7]} does not pass, and the status "
|
|
@@ -865,6 +872,16 @@ def check_attested(root: Path, head: str, fail, warn=lambda message: None) -> st
|
|
|
865
872
|
f"'{attest.CONTEXT}' in the branch's ruleset: nstack attest posts it with the record, and this "
|
|
866
873
|
"run leaves the record to it (07-governance.md §7).")
|
|
867
874
|
return "attested — no record of the head"
|
|
875
|
+
if record.get("void"):
|
|
876
|
+
fail("A2", f"the record of the head {head[:7]} was voided by {record.get('by')} at {record.get('at')}: "
|
|
877
|
+
f"{record['void']}.\n Action: run nstack attest on the head again — nothing is kept from a "
|
|
878
|
+
"voided record.")
|
|
879
|
+
return "attested — the record of the head was voided"
|
|
880
|
+
unsound = [check["name"] for check in record["checks"] if attest.kept_from_voided(root, check, head)]
|
|
881
|
+
if unsound:
|
|
882
|
+
fail("A2", f"the record of the head {head[:7]} keeps {', '.join(unsound)} from a run since voided.\n"
|
|
883
|
+
" Action: run nstack attest on the head again — nothing is kept from a voided run.")
|
|
884
|
+
return "attested — the record of the head keeps a voided run"
|
|
868
885
|
names = [check["name"] for check in record["checks"]]
|
|
869
886
|
missing = [check.name for check in attest.CHECKS if check.name not in names]
|
|
870
887
|
failed = [check["name"] for check in record["checks"] if not check["passed"]]
|
|
@@ -46,7 +46,7 @@ from napkinstack.project import ANSWERS
|
|
|
46
46
|
|
|
47
47
|
RULESET_NAME = "nstack-checklist"
|
|
48
48
|
HOLDS_RULESET = "nstack-holds" # the holds of deliverables: never forced, never deleted (G20)
|
|
49
|
-
IN_RULESET = ("G1", "G2", "G3", "G4", "G13", "G17", "G18", "G21")
|
|
49
|
+
IN_RULESET = ("G1", "G2", "G3", "G4", "G13", "G17", "G18", "G21", "G22")
|
|
50
50
|
PULL_REQUEST = ("G1", "G2", "G3", "G13", "G21")
|
|
51
51
|
LABEL_COLOURS = {"cross-module": "d93f0b", "over-budget": "fbca04", "out-of-cycle": "5319e7",
|
|
52
52
|
"request": "0e8a16", "bug": "d73a4a", "architecture": "1d76db", "debt": "c5def5",
|
|
@@ -76,10 +76,11 @@ def ruleset(missing: set[str]) -> dict:
|
|
|
76
76
|
"required_approving_review_count": 1, "require_code_owner_review": True,
|
|
77
77
|
"dismiss_stale_reviews_on_push": True, "require_last_push_approval": "G21" in missing,
|
|
78
78
|
"required_review_thread_resolution": False}})
|
|
79
|
-
if "G4"
|
|
79
|
+
if missing & {"G4", "G22"}:
|
|
80
|
+
# Up to date before merging (G22, #430): what the checks judged is what lands, main included.
|
|
80
81
|
rules.append({"type": "required_status_checks", "parameters": {
|
|
81
82
|
"required_status_checks": [{"context": job} for job in doctor.JOBS],
|
|
82
|
-
"strict_required_status_checks_policy":
|
|
83
|
+
"strict_required_status_checks_policy": True}})
|
|
83
84
|
return {"name": RULESET_NAME, "target": "branch", "enforcement": "active",
|
|
84
85
|
"conditions": {"ref_name": {"include": ["~DEFAULT_BRANCH"], "exclude": []}},
|
|
85
86
|
"bypass_actors": [], "rules": rules}
|
|
@@ -281,8 +282,10 @@ def _apply(client: Forge, root: Path, calls: list[Call], notes: list[str]) -> in
|
|
|
281
282
|
if rest:
|
|
282
283
|
again, answer_again = client.send(method, path, {**body, "rules": rest})
|
|
283
284
|
if again:
|
|
284
|
-
|
|
285
|
-
|
|
285
|
+
kept = ", ".join(rule for rule in closed.split(", ") if rule not in ("G4", "G22"))
|
|
286
|
+
refused = " and ".join(rule for rule in closed.split(", ") if rule in ("G4", "G22"))
|
|
287
|
+
print(f" applied {kept}: {method} {path or '/'} "
|
|
288
|
+
f"({answer_again}); {refused} refused ({answer}): open a first pull request, let the checks "
|
|
286
289
|
"run, then run nstack settings --apply again")
|
|
287
290
|
failed += 1
|
|
288
291
|
continue
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{napkinstack-0.31.0 → napkinstack-0.32.0}/src/napkinstack/templates/contracts/docs/runbook.md
RENAMED
|
File without changes
|
{napkinstack-0.31.0 → napkinstack-0.32.0}/src/napkinstack/templates/contracts/tests/.gitkeep
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|