noqt commited on
Commit
02a2a78
·
verified ·
1 Parent(s): 86dcff0

Sync GitHub source a5d1879c781062f43a2a2102dd773128fc9662f2

Browse files

Canonical source: https://github.com/noqt/Lumi-Eggcracker/commit/a5d1879c781062f43a2a2102dd773128fc9662f2

HUGGINGFACE_MANIFEST.json CHANGED
@@ -37,8 +37,8 @@
37
  "size": 10537
38
  },
39
  "README.md": {
40
- "sha256": "829342729f67f8fb086f5645f1946125970a26710551d398ac9e10ad4db5a713",
41
- "size": 39135
42
  },
43
  "RELEASE_NOTES.md": {
44
  "sha256": "64d330d0f297b15720fc65e6347ececc1b99a917a597d405ebfac04baf3222ea",
@@ -189,7 +189,7 @@
189
  "size": 4101
190
  },
191
  "index.html": {
192
- "sha256": "51dd6177b9bdbb164f87aeeb7ed22318064c82aa7b40c9e95714610f5708e510",
193
  "size": 22790
194
  },
195
  "integrations/prometheus/eggcracker.rules.yml": {
@@ -257,8 +257,8 @@
257
  "size": 4746
258
  },
259
  "scripts/collect_supported_path_receipt.py": {
260
- "sha256": "528b3dc1ab4cb7999225f1d94165ece7f48282f83ef87183c633307103c368e0",
261
- "size": 10593
262
  },
263
  "scripts/containment_probe.py": {
264
  "sha256": "104009c1c3f758633012826f3192d3c1f6433977f96b4c80b4f8f8ddfacc26e4",
@@ -601,8 +601,8 @@
601
  "size": 6820
602
  },
603
  "tests/test_collect_supported_path_receipt.py": {
604
- "sha256": "79ae57bf3d78cac5fbe1b9d7db60462328f70cb17214bc75a5b5e7eff3ea0eef",
605
- "size": 15595
606
  },
607
  "tests/test_containment.py": {
608
  "sha256": "168e840c8928ed5521a1f11080b4bb5679c145f66635c8b3785a2fca60f19f06",
@@ -839,6 +839,6 @@
839
  },
840
  "schema": "noqt.huggingface_manifest.v1",
841
  "source_repository": "https://github.com/noqt/Lumi-Eggcracker",
842
- "source_revision": "4f3515c2e4cc473e7a2a3c10cbda496a3c889324",
843
- "source_url": "https://github.com/noqt/Lumi-Eggcracker/commit/4f3515c2e4cc473e7a2a3c10cbda496a3c889324"
844
  }
 
37
  "size": 10537
38
  },
39
  "README.md": {
40
+ "sha256": "9769457cb12f80f20b11f3f3d55ba43a0860c3d36d4cd721b74a2762c8be1464",
41
+ "size": 40484
42
  },
43
  "RELEASE_NOTES.md": {
44
  "sha256": "64d330d0f297b15720fc65e6347ececc1b99a917a597d405ebfac04baf3222ea",
 
189
  "size": 4101
190
  },
191
  "index.html": {
192
+ "sha256": "bf6a2388a76492e642b8a716dc2a05da4a9ed1171bca85b7690978c34453660c",
193
  "size": 22790
194
  },
195
  "integrations/prometheus/eggcracker.rules.yml": {
 
257
  "size": 4746
258
  },
259
  "scripts/collect_supported_path_receipt.py": {
260
+ "sha256": "88bd859e24e42ea8585bc484c6e46726865fc5cc9c1c37597b8d50ae397b2bfa",
261
+ "size": 18878
262
  },
263
  "scripts/containment_probe.py": {
264
  "sha256": "104009c1c3f758633012826f3192d3c1f6433977f96b4c80b4f8f8ddfacc26e4",
 
601
  "size": 6820
602
  },
603
  "tests/test_collect_supported_path_receipt.py": {
604
+ "sha256": "a320bd635bec70932121b5f633fc451fd1d7c117e0477f4d42b7fae2edc49769",
605
+ "size": 27694
606
  },
607
  "tests/test_containment.py": {
608
  "sha256": "168e840c8928ed5521a1f11080b4bb5679c145f66635c8b3785a2fca60f19f06",
 
839
  },
840
  "schema": "noqt.huggingface_manifest.v1",
841
  "source_repository": "https://github.com/noqt/Lumi-Eggcracker",
842
+ "source_revision": "a5d1879c781062f43a2a2102dd773128fc9662f2",
843
+ "source_url": "https://github.com/noqt/Lumi-Eggcracker/commit/a5d1879c781062f43a2a2102dd773128fc9662f2"
844
  }
HUGGINGFACE_SYNC.json CHANGED
@@ -1,6 +1,6 @@
1
  {
2
  "manifest": "HUGGINGFACE_MANIFEST.json",
3
- "manifest_sha256": "c4f375e954b02597f9cdfa0e4f512aa938f48aeb736afaa996dc41cf6bc3c20e",
4
  "mirrored_files": 194,
5
  "mode": "DERIVED_READ_ONLY_MIRROR",
6
  "release_reference": {
@@ -65,7 +65,7 @@
65
  },
66
  "schema": "noqt.huggingface_sync.v1",
67
  "source_repository": "https://github.com/noqt/Lumi-Eggcracker",
68
- "source_revision": "4f3515c2e4cc473e7a2a3c10cbda496a3c889324",
69
- "source_url": "https://github.com/noqt/Lumi-Eggcracker/commit/4f3515c2e4cc473e7a2a3c10cbda496a3c889324",
70
  "target": "https://huggingface.co/spaces/noqt/eggcracker"
71
  }
 
1
  {
2
  "manifest": "HUGGINGFACE_MANIFEST.json",
3
+ "manifest_sha256": "9ec261a44fd95098441b39d501ad0e602fafddfde6c99eba950d1b731484824d",
4
  "mirrored_files": 194,
5
  "mode": "DERIVED_READ_ONLY_MIRROR",
6
  "release_reference": {
 
65
  },
66
  "schema": "noqt.huggingface_sync.v1",
67
  "source_repository": "https://github.com/noqt/Lumi-Eggcracker",
68
+ "source_revision": "a5d1879c781062f43a2a2102dd773128fc9662f2",
69
+ "source_url": "https://github.com/noqt/Lumi-Eggcracker/commit/a5d1879c781062f43a2a2102dd773128fc9662f2",
70
  "target": "https://huggingface.co/spaces/noqt/eggcracker"
71
  }
README.md CHANGED
@@ -11,7 +11,7 @@ short_description: Native Linux kill switch for supported local-AI workloads
11
  ---
12
 
13
  > Official noqt Hugging Face distribution, generated from GitHub commit
14
- > [`4f3515c2e4cc`](https://github.com/noqt/Lumi-Eggcracker/commit/4f3515c2e4cc473e7a2a3c10cbda496a3c889324). This Space distributes the source for
15
  > discovery and cloning; Eggcracker itself runs on a supported native Linux
16
  > host, not on Hugging Face. A snapshot is called current only after the
17
  > release-linked sync job verifies its returned Hub commit and full manifest.
@@ -365,6 +365,38 @@ writes nothing without the explicit opt-in flag.
365
  Review the local JSON before deciding whether to share it; `permission_to_quote`
366
  records permission, but does not send or publish anything.
367
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
368
  ### Qualify the offline boundary
369
 
370
  On the disposable native Ubuntu host, qualify the offline network primitive
 
11
  ---
12
 
13
  > Official noqt Hugging Face distribution, generated from GitHub commit
14
+ > [`a5d1879c7810`](https://github.com/noqt/Lumi-Eggcracker/commit/a5d1879c781062f43a2a2102dd773128fc9662f2). This Space distributes the source for
15
  > discovery and cloning; Eggcracker itself runs on a supported native Linux
16
  > host, not on Hugging Face. A snapshot is called current only after the
17
  > release-linked sync job verifies its returned Hub commit and full manifest.
 
365
  Review the local JSON before deciding whether to share it; `permission_to_quote`
366
  records permission, but does not send or publish anything.
367
 
368
+ #### Verify a final receipt offline
369
+
370
+ After a receipt has been written, verify that one final local file still has
371
+ the closed v1 shape and the expected source identities without writing, using
372
+ root, or making a network request:
373
+
374
+ ```sh
375
+ python3 scripts/collect_supported_path_receipt.py \
376
+ --verify-receipt ./supported-path-receipt.json \
377
+ --expect-source-commit <exact-40-lowercase-hex-source-commit> \
378
+ --expect-source-tree-sha256 <exact-64-lowercase-hex-source-tree-sha256>
379
+ ```
380
+
381
+ Verification reads at most the receipt size bound from one local regular file,
382
+ rejects links, duplicate members, invalid UTF-8, and closed-schema,
383
+ timestamp, privacy or outcome drift, and compares the observed source IDs with
384
+ the two expected IDs. On success it emits only a bounded `outcome` and the
385
+ `receipt_sha256` of the exact bounded bytes that were validated:
386
+
387
+ ```json
388
+ {"outcome":"supported-success","receipt_sha256":"<64-lowercase-hex-digest>"}
389
+ ```
390
+
391
+ Any verification failure emits a fixed, non-echoing diagnostic and exits with
392
+ status 2.
393
+
394
+ This establishes schema and source-ID consistency and identifies the validated
395
+ bytes. It is not receipt authenticity or tamper resistance without a trusted
396
+ reference, does not prove the run or containment, and does not grant
397
+ permission to quote; the receipt's `permission_to_quote` field still requires
398
+ separate review.
399
+
400
  ### Qualify the offline boundary
401
 
402
  On the disposable native Ubuntu host, qualify the offline network primitive
index.html CHANGED
@@ -4,7 +4,7 @@
4
  <meta charset="utf-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1">
6
  <meta name="description" content="Lumi Eggcracker is noqt's native Linux kill switch for unapproved supported local-AI workloads. Clone the complete source from Hugging Face.">
7
- <meta name="noqt-source-revision" content="4f3515c2e4cc473e7a2a3c10cbda496a3c889324">
8
  <meta name="theme-color" content="#090a0c">
9
  <title>Lumi Eggcracker — Native Linux AI kill switch</title>
10
  <style>
@@ -649,7 +649,7 @@ sudo /usr/bin/python3 -I -S scripts/first_kill.py \
649
  <section>
650
  <div class="shell source-bar">
651
  <div>
652
- <div class="source-id">SOURCE COMMIT · 4f3515c2e4cc</div>
653
  <h2>Inspect every line.</h2>
654
  <p>Complete source, tests, qualification documents and reproducible proof tooling are distributed in this repository.</p>
655
  </div>
 
4
  <meta charset="utf-8">
5
  <meta name="viewport" content="width=device-width, initial-scale=1">
6
  <meta name="description" content="Lumi Eggcracker is noqt's native Linux kill switch for unapproved supported local-AI workloads. Clone the complete source from Hugging Face.">
7
+ <meta name="noqt-source-revision" content="a5d1879c781062f43a2a2102dd773128fc9662f2">
8
  <meta name="theme-color" content="#090a0c">
9
  <title>Lumi Eggcracker — Native Linux AI kill switch</title>
10
  <style>
 
649
  <section>
650
  <div class="shell source-bar">
651
  <div>
652
+ <div class="source-id">SOURCE COMMIT · a5d1879c7810</div>
653
  <h2>Inspect every line.</h2>
654
  <p>Complete source, tests, qualification documents and reproducible proof tooling are distributed in this repository.</p>
655
  </div>
scripts/collect_supported_path_receipt.py CHANGED
@@ -1,9 +1,10 @@
1
  #!/usr/bin/env python3
2
- """Create one explicitly opted-in, redacted local supported-path receipt."""
3
 
4
  from __future__ import annotations
5
 
6
  import argparse
 
7
  import json
8
  import os
9
  import re
@@ -17,6 +18,20 @@ from pathlib import Path
17
  MAX_INPUT_BYTES = 4_096
18
  MAX_RECEIPT_BYTES = 8_192
19
  SCHEMA_VERSION = "lumi-eggcracker-supported-path-receipt-v1"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  SUPPORTED_ENVIRONMENT = "disposable-native-ubuntu-24.04-cgroup-v2"
21
  SUPPORTED_PATH = "containment-primitive-probe"
22
  EXACT_COMMAND = (
@@ -73,6 +88,10 @@ class SafeArgumentParser(argparse.ArgumentParser):
73
  raise ReceiptInputError("invalid command-line arguments")
74
 
75
 
 
 
 
 
76
  def _unique_object(pairs: list[tuple[str, object]]) -> dict[str, object]:
77
  value: dict[str, object] = {}
78
  for name, item in pairs:
@@ -117,26 +136,7 @@ def _validate_source_identity(observed: Mapping[str, object]) -> None:
117
  raise ReceiptInputError("source_tree_sha256 is not an exact lowercase tree identity")
118
 
119
 
120
- def _validate_input(value: object) -> dict[str, object]:
121
- if not isinstance(value, dict):
122
- raise ReceiptInputError("input root must be an object")
123
- _require_exact_fields(value, INPUT_FIELDS, "input")
124
-
125
- fixed_strings = {
126
- "supported_environment": SUPPORTED_ENVIRONMENT,
127
- "supported_path": SUPPORTED_PATH,
128
- "exact_command": EXACT_COMMAND,
129
- "expected_result": EXPECTED_RESULT,
130
- }
131
- for field, expected in fixed_strings.items():
132
- if not isinstance(value[field], str) or value[field] != expected:
133
- raise ReceiptInputError(f"input field {field} is not the supported fixed value")
134
-
135
- permission = value["permission_to_quote"]
136
- if not isinstance(permission, bool):
137
- raise ReceiptInputError("permission_to_quote must be an explicit boolean")
138
-
139
- observed = value["observed_result"]
140
  if not isinstance(observed, dict):
141
  raise ReceiptInputError("observed_result must be an object")
142
  outcome = observed.get("outcome")
@@ -189,9 +189,153 @@ def _validate_input(value: object) -> dict[str, object]:
189
  else:
190
  raise ReceiptInputError("observed_result outcome is not supported")
191
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
192
  return dict(value)
193
 
194
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
195
  def _safe_output_parent(destination: Path) -> Path:
196
  parent = Path(os.path.abspath(destination.parent))
197
  try:
@@ -260,23 +404,81 @@ def _build_receipt(value: Mapping[str, object]) -> dict[str, object]:
260
 
261
  def main(argv: Sequence[str] | None = None) -> int:
262
  parser = SafeArgumentParser(
263
- description="write one explicitly opted-in local supported-path receipt"
264
  )
265
- parser.add_argument(
 
 
266
  "--i-opt-in-to-write-local-receipt",
267
  action="store_true",
268
  help="explicitly allow this command to write the local redacted receipt",
269
  )
270
- parser.add_argument("--input", type=Path, required=True, help="bounded local JSON input")
271
- parser.add_argument("--output", type=Path, required=True, help="new local JSON receipt")
 
 
 
 
 
 
 
 
 
 
 
 
 
272
  try:
273
  arguments = parser.parse_args(argv)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
274
  if not arguments.i_opt_in_to_write_local_receipt:
275
  raise ReceiptInputError("explicit opt-in is required; no receipt was written")
 
 
276
  value = _validate_input(_read_input(arguments.input))
277
  _write_new_receipt(arguments.output, _build_receipt(value))
278
  except ReceiptInputError as error:
279
- print(f"NOT WRITTEN: {error}", file=sys.stderr)
 
280
  return 2
281
  print("WROTE local redacted supported-path receipt")
282
  return 0
 
1
  #!/usr/bin/env python3
2
+ """Create or verify one bounded, redacted local supported-path receipt."""
3
 
4
  from __future__ import annotations
5
 
6
  import argparse
7
+ import hashlib
8
  import json
9
  import os
10
  import re
 
18
  MAX_INPUT_BYTES = 4_096
19
  MAX_RECEIPT_BYTES = 8_192
20
  SCHEMA_VERSION = "lumi-eggcracker-supported-path-receipt-v1"
21
+ RECEIPT_FIELDS = {
22
+ "schema_version",
23
+ "recorded_at_utc",
24
+ "supported_environment",
25
+ "supported_path",
26
+ "exact_command",
27
+ "expected_result",
28
+ "observed_result",
29
+ "permission_to_quote",
30
+ "privacy",
31
+ }
32
+ TIMESTAMP_PATTERN = re.compile(
33
+ r"[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z"
34
+ )
35
  SUPPORTED_ENVIRONMENT = "disposable-native-ubuntu-24.04-cgroup-v2"
36
  SUPPORTED_PATH = "containment-primitive-probe"
37
  EXACT_COMMAND = (
 
88
  raise ReceiptInputError("invalid command-line arguments")
89
 
90
 
91
+ def _reject_nonstandard_number(_value: str) -> object:
92
+ raise ReceiptInputError("receipt contains a non-standard number")
93
+
94
+
95
  def _unique_object(pairs: list[tuple[str, object]]) -> dict[str, object]:
96
  value: dict[str, object] = {}
97
  for name, item in pairs:
 
136
  raise ReceiptInputError("source_tree_sha256 is not an exact lowercase tree identity")
137
 
138
 
139
+ def _validate_observed_result(observed: object) -> dict[str, object]:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
140
  if not isinstance(observed, dict):
141
  raise ReceiptInputError("observed_result must be an object")
142
  outcome = observed.get("outcome")
 
189
  else:
190
  raise ReceiptInputError("observed_result outcome is not supported")
191
 
192
+ return dict(observed)
193
+
194
+
195
+ def _validate_input(value: object) -> dict[str, object]:
196
+ if not isinstance(value, dict):
197
+ raise ReceiptInputError("input root must be an object")
198
+ _require_exact_fields(value, INPUT_FIELDS, "input")
199
+
200
+ fixed_strings = {
201
+ "supported_environment": SUPPORTED_ENVIRONMENT,
202
+ "supported_path": SUPPORTED_PATH,
203
+ "exact_command": EXACT_COMMAND,
204
+ "expected_result": EXPECTED_RESULT,
205
+ }
206
+ for field, expected in fixed_strings.items():
207
+ if not isinstance(value[field], str) or value[field] != expected:
208
+ raise ReceiptInputError(f"input field {field} is not the supported fixed value")
209
+
210
+ permission = value["permission_to_quote"]
211
+ if not isinstance(permission, bool):
212
+ raise ReceiptInputError("permission_to_quote must be an explicit boolean")
213
+
214
+ _validate_observed_result(value["observed_result"])
215
  return dict(value)
216
 
217
 
218
+ def _safe_receipt_parent(path: Path) -> Path:
219
+ parent = Path(os.path.abspath(path.parent))
220
+ try:
221
+ for candidate in (parent, *parent.parents):
222
+ metadata = candidate.lstat()
223
+ if stat.S_ISLNK(metadata.st_mode) or not stat.S_ISDIR(metadata.st_mode):
224
+ raise ReceiptInputError("receipt parent must contain no links or non-directories")
225
+ except ReceiptInputError:
226
+ raise
227
+ except (OSError, ValueError) as error:
228
+ raise ReceiptInputError("receipt parent is not an existing regular directory") from error
229
+ return parent
230
+
231
+
232
+ def _read_final_receipt(path: Path) -> tuple[object, str]:
233
+ _safe_receipt_parent(path)
234
+ descriptor = -1
235
+ try:
236
+ metadata = path.lstat()
237
+ if stat.S_ISLNK(metadata.st_mode) or not stat.S_ISREG(metadata.st_mode):
238
+ raise ReceiptInputError("receipt must be a regular file, not a link")
239
+ flags = os.O_RDONLY | getattr(os, "O_NOFOLLOW", 0) | getattr(os, "O_BINARY", 0)
240
+ descriptor = os.open(path, flags)
241
+ with os.fdopen(descriptor, "rb") as handle:
242
+ descriptor = -1
243
+ current = os.fstat(handle.fileno())
244
+ if stat.S_ISLNK(current.st_mode) or not stat.S_ISREG(current.st_mode):
245
+ raise ReceiptInputError("receipt must be a regular file, not a link")
246
+ encoded = handle.read(MAX_RECEIPT_BYTES + 1)
247
+ except ReceiptInputError:
248
+ raise
249
+ except (OSError, ValueError) as error:
250
+ raise ReceiptInputError("receipt could not be read") from error
251
+ finally:
252
+ if descriptor >= 0:
253
+ try:
254
+ os.close(descriptor)
255
+ except OSError:
256
+ pass
257
+ if len(encoded) > MAX_RECEIPT_BYTES:
258
+ raise ReceiptInputError("receipt exceeds its safe size bound")
259
+ receipt_sha256 = hashlib.sha256(encoded).hexdigest()
260
+ try:
261
+ value = json.loads(
262
+ encoded.decode("utf-8"),
263
+ object_pairs_hook=_unique_object,
264
+ parse_constant=_reject_nonstandard_number,
265
+ )
266
+ except ReceiptInputError:
267
+ raise
268
+ except (UnicodeError, json.JSONDecodeError, RecursionError, ValueError) as error:
269
+ raise ReceiptInputError("receipt is not bounded UTF-8 JSON") from error
270
+ return value, receipt_sha256
271
+
272
+
273
+ def _validate_expected_source_identity(value: object, pattern: re.Pattern[str], label: str) -> str:
274
+ if not isinstance(value, str) or pattern.fullmatch(value) is None:
275
+ raise ReceiptInputError(f"{label} is not an exact lowercase source identity")
276
+ return value
277
+
278
+
279
+ def _validate_final_receipt(
280
+ value: object,
281
+ *,
282
+ expected_source_commit: str,
283
+ expected_source_tree_sha256: str,
284
+ ) -> str:
285
+ if not isinstance(value, dict):
286
+ raise ReceiptInputError("receipt root must be an object")
287
+ _require_exact_fields(value, RECEIPT_FIELDS, "receipt")
288
+
289
+ fixed_strings = {
290
+ "schema_version": SCHEMA_VERSION,
291
+ "supported_environment": SUPPORTED_ENVIRONMENT,
292
+ "supported_path": SUPPORTED_PATH,
293
+ "exact_command": EXACT_COMMAND,
294
+ "expected_result": EXPECTED_RESULT,
295
+ }
296
+ for field, expected in fixed_strings.items():
297
+ if not isinstance(value[field], str) or value[field] != expected:
298
+ raise ReceiptInputError(f"receipt field {field} is not the supported fixed value")
299
+
300
+ recorded_at = value["recorded_at_utc"]
301
+ if not isinstance(recorded_at, str) or TIMESTAMP_PATTERN.fullmatch(recorded_at) is None:
302
+ raise ReceiptInputError("recorded_at_utc is not an exact UTC timestamp")
303
+ try:
304
+ datetime.strptime(recorded_at, "%Y-%m-%dT%H:%M:%SZ").replace(tzinfo=UTC)
305
+ except ValueError as error:
306
+ raise ReceiptInputError("recorded_at_utc is not an exact UTC timestamp") from error
307
+
308
+ permission = value["permission_to_quote"]
309
+ if not isinstance(permission, bool):
310
+ raise ReceiptInputError("permission_to_quote must be an explicit boolean")
311
+
312
+ privacy = value["privacy"]
313
+ if not isinstance(privacy, dict):
314
+ raise ReceiptInputError("privacy does not match the closed schema")
315
+ _require_exact_fields(privacy, set(PRIVACY), "privacy")
316
+ for field, expected in PRIVACY.items():
317
+ actual = privacy[field]
318
+ if type(actual) is not type(expected) or actual != expected:
319
+ raise ReceiptInputError("privacy does not match the required redacted values")
320
+
321
+ observed = _validate_observed_result(value["observed_result"])
322
+ _validate_expected_source_identity(
323
+ expected_source_commit, SOURCE_COMMIT_PATTERN, "expected source_commit"
324
+ )
325
+ _validate_expected_source_identity(
326
+ expected_source_tree_sha256, SOURCE_TREE_PATTERN, "expected source_tree_sha256"
327
+ )
328
+ if (
329
+ observed["source_commit"] != expected_source_commit
330
+ or observed["source_tree_sha256"] != expected_source_tree_sha256
331
+ ):
332
+ raise ReceiptInputError("receipt source identity does not match the expected identities")
333
+ outcome = observed["outcome"]
334
+ if not isinstance(outcome, str):
335
+ raise ReceiptInputError("observed_result outcome is not supported")
336
+ return outcome
337
+
338
+
339
  def _safe_output_parent(destination: Path) -> Path:
340
  parent = Path(os.path.abspath(destination.parent))
341
  try:
 
404
 
405
  def main(argv: Sequence[str] | None = None) -> int:
406
  parser = SafeArgumentParser(
407
+ description="write or verify one bounded local supported-path receipt"
408
  )
409
+ verification_requested = "--verify-receipt" in (sys.argv[1:] if argv is None else argv)
410
+ modes = parser.add_mutually_exclusive_group()
411
+ modes.add_argument(
412
  "--i-opt-in-to-write-local-receipt",
413
  action="store_true",
414
  help="explicitly allow this command to write the local redacted receipt",
415
  )
416
+ modes.add_argument(
417
+ "--verify-receipt",
418
+ type=Path,
419
+ help="read and verify one final local JSON receipt without writing",
420
+ )
421
+ parser.add_argument(
422
+ "--expect-source-commit",
423
+ help="expected exact lowercase source commit identity for verification",
424
+ )
425
+ parser.add_argument(
426
+ "--expect-source-tree-sha256",
427
+ help="expected exact lowercase source tree identity for verification",
428
+ )
429
+ parser.add_argument("--input", type=Path, help="bounded local JSON input")
430
+ parser.add_argument("--output", type=Path, help="new local JSON receipt")
431
  try:
432
  arguments = parser.parse_args(argv)
433
+ verification_requested = arguments.verify_receipt is not None
434
+ if arguments.verify_receipt is not None:
435
+ if (
436
+ arguments.i_opt_in_to_write_local_receipt
437
+ or arguments.input is not None
438
+ or arguments.output is not None
439
+ ):
440
+ raise ReceiptInputError("verification mode cannot be combined with write mode")
441
+ if (
442
+ arguments.expect_source_commit is None
443
+ or arguments.expect_source_tree_sha256 is None
444
+ ):
445
+ raise ReceiptInputError("verification requires both expected source identities")
446
+ _validate_expected_source_identity(
447
+ arguments.expect_source_commit, SOURCE_COMMIT_PATTERN, "expected source_commit"
448
+ )
449
+ _validate_expected_source_identity(
450
+ arguments.expect_source_tree_sha256,
451
+ SOURCE_TREE_PATTERN,
452
+ "expected source_tree_sha256",
453
+ )
454
+ receipt, receipt_sha256 = _read_final_receipt(arguments.verify_receipt)
455
+ outcome = _validate_final_receipt(
456
+ receipt,
457
+ expected_source_commit=arguments.expect_source_commit,
458
+ expected_source_tree_sha256=arguments.expect_source_tree_sha256,
459
+ )
460
+ print(
461
+ json.dumps(
462
+ {"outcome": outcome, "receipt_sha256": receipt_sha256},
463
+ sort_keys=True,
464
+ separators=(",", ":"),
465
+ )
466
+ )
467
+ return 0
468
+ if (
469
+ arguments.expect_source_commit is not None
470
+ or arguments.expect_source_tree_sha256 is not None
471
+ ):
472
+ raise ReceiptInputError("expected source identities require --verify-receipt")
473
  if not arguments.i_opt_in_to_write_local_receipt:
474
  raise ReceiptInputError("explicit opt-in is required; no receipt was written")
475
+ if arguments.input is None or arguments.output is None:
476
+ raise ReceiptInputError("write mode requires --input and --output")
477
  value = _validate_input(_read_input(arguments.input))
478
  _write_new_receipt(arguments.output, _build_receipt(value))
479
  except ReceiptInputError as error:
480
+ prefix = "NOT VERIFIED" if verification_requested else "NOT WRITTEN"
481
+ print(f"{prefix}: {error}", file=sys.stderr)
482
  return 2
483
  print("WROTE local redacted supported-path receipt")
484
  return 0
tests/test_collect_supported_path_receipt.py CHANGED
@@ -1,6 +1,7 @@
1
  from __future__ import annotations
2
 
3
  import ast
 
4
  import importlib.util
5
  import json
6
  import os
@@ -122,6 +123,7 @@ class SupportedPathReceiptTests(unittest.TestCase):
122
  "collections",
123
  "datetime",
124
  "json",
 
125
  "os",
126
  "pathlib",
127
  "re",
@@ -360,6 +362,257 @@ class SupportedPathReceiptTests(unittest.TestCase):
360
  self.assertNotIn(str(invalid_value), stderr.getvalue())
361
  self.assertFalse(output.exists())
362
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
363
 
364
  if __name__ == "__main__":
365
  unittest.main()
 
1
  from __future__ import annotations
2
 
3
  import ast
4
+ import hashlib
5
  import importlib.util
6
  import json
7
  import os
 
123
  "collections",
124
  "datetime",
125
  "json",
126
+ "hashlib",
127
  "os",
128
  "pathlib",
129
  "re",
 
362
  self.assertNotIn(str(invalid_value), stderr.getvalue())
363
  self.assertFalse(output.exists())
364
 
365
+ def write_final_receipt(
366
+ self,
367
+ directory: str,
368
+ *,
369
+ observed: dict[str, object] | None = None,
370
+ quote: bool = False,
371
+ suffix: bytes = b"\n",
372
+ ) -> tuple[Path, bytes]:
373
+ receipt = collector._build_receipt(
374
+ submission(quote=quote, observed=observed or success_observed())
375
+ )
376
+ encoded = (
377
+ json.dumps(receipt, indent=2, sort_keys=True).encode("utf-8") + suffix
378
+ )
379
+ path = Path(directory) / "final-receipt.json"
380
+ path.write_bytes(encoded)
381
+ return path, encoded
382
+
383
+ def run_verifier(
384
+ self,
385
+ receipt: Path,
386
+ *,
387
+ source_commit: str = SOURCE_COMMIT,
388
+ source_tree_sha256: str = SOURCE_TREE_SHA256,
389
+ extra: list[str] | None = None,
390
+ ) -> tuple[int, StringIO, StringIO]:
391
+ arguments = [
392
+ "--verify-receipt",
393
+ str(receipt),
394
+ "--expect-source-commit",
395
+ source_commit,
396
+ "--expect-source-tree-sha256",
397
+ source_tree_sha256,
398
+ ]
399
+ if extra:
400
+ arguments.extend(extra)
401
+ stdout = StringIO()
402
+ stderr = StringIO()
403
+ with redirect_stdout(stdout), redirect_stderr(stderr):
404
+ status = collector.main(arguments)
405
+ return status, stdout, stderr
406
+
407
+ def test_verify_receipt_emits_only_outcome_and_digest_of_exact_bytes(self) -> None:
408
+ with TemporaryDirectory() as directory:
409
+ receipt, encoded = self.write_final_receipt(directory, suffix=b" \n")
410
+ status, stdout, stderr = self.run_verifier(receipt)
411
+ self.assertEqual(0, status)
412
+ self.assertEqual(
413
+ {
414
+ "outcome": "supported-success",
415
+ "receipt_sha256": hashlib.sha256(encoded).hexdigest(),
416
+ },
417
+ json.loads(stdout.getvalue()),
418
+ )
419
+ self.assertEqual("", stderr.getvalue())
420
+
421
+ def test_verify_receipt_accepts_reproducible_blocker_outcome(self) -> None:
422
+ with TemporaryDirectory() as directory:
423
+ receipt, _encoded = self.write_final_receipt(
424
+ directory, observed=blocker_observed(), quote=True
425
+ )
426
+ status, stdout, stderr = self.run_verifier(receipt)
427
+ self.assertEqual(0, status)
428
+ self.assertEqual("reproducible-blocker", json.loads(stdout.getvalue())["outcome"])
429
+ self.assertEqual("", stderr.getvalue())
430
+
431
+ def test_verify_receipt_rejects_schema_timestamp_privacy_and_outcome_drift(self) -> None:
432
+ cases = (
433
+ ("schema_version", "other-schema"),
434
+ ("recorded_at_utc", "2026-13-14T00:00:00Z"),
435
+ ("permission_to_quote", "yes"),
436
+ ("privacy", {**collector.PRIVACY, "raw_output_collected": True}),
437
+ ("observed_result", success_observed(outcome="unsupported")),
438
+ )
439
+ for field, invalid_value in cases:
440
+ with self.subTest(field=field), TemporaryDirectory() as directory:
441
+ receipt_value = collector._build_receipt(
442
+ submission(quote=False, observed=success_observed())
443
+ )
444
+ receipt_value[field] = invalid_value
445
+ encoded = (json.dumps(receipt_value, sort_keys=True) + "\n").encode("utf-8")
446
+ receipt = Path(directory) / "receipt.json"
447
+ receipt.write_bytes(encoded)
448
+ status, stdout, stderr = self.run_verifier(receipt)
449
+ self.assertEqual(2, status)
450
+ self.assertEqual("", stdout.getvalue())
451
+ self.assertTrue(stderr.getvalue().startswith("NOT VERIFIED:"))
452
+ self.assertNotIn(str(invalid_value), stderr.getvalue())
453
+
454
+ def test_verify_receipt_rejects_duplicate_members_invalid_utf8_and_oversize(self) -> None:
455
+ cases = (
456
+ b'{"schema_version":"one","schema_version":"two"}',
457
+ b"\xffprivate-marker",
458
+ b" " * (collector.MAX_RECEIPT_BYTES + 1),
459
+ )
460
+ for encoded in cases:
461
+ with self.subTest(encoded=encoded[:10]), TemporaryDirectory() as directory:
462
+ receipt = Path(directory) / "receipt.json"
463
+ receipt.write_bytes(encoded)
464
+ status, stdout, stderr = self.run_verifier(receipt)
465
+ self.assertEqual(2, status)
466
+ self.assertEqual("", stdout.getvalue())
467
+ self.assertTrue(stderr.getvalue().startswith("NOT VERIFIED:"))
468
+ self.assertNotIn("private-marker", stderr.getvalue())
469
+
470
+ def test_verify_receipt_rejects_integer_digit_limit_without_file_changes(self) -> None:
471
+ private_marker = "private-integer-limit-marker"
472
+ digits = "9" * 4_301
473
+ encoded = b'{"integer": ' + digits.encode("ascii") + b"}\n"
474
+ self.assertLess(len(encoded), collector.MAX_RECEIPT_BYTES)
475
+ with TemporaryDirectory() as directory:
476
+ receipt = Path(directory) / f"{private_marker}.json"
477
+ sibling = Path(directory) / "sibling.json"
478
+ sibling_bytes = b"stable sibling\n"
479
+ receipt.write_bytes(encoded)
480
+ sibling.write_bytes(sibling_bytes)
481
+ before_entries = sorted(path.name for path in Path(directory).iterdir())
482
+ before_receipt_mtime = receipt.stat().st_mtime_ns
483
+ before_sibling_mtime = sibling.stat().st_mtime_ns
484
+
485
+ status, stdout, stderr = self.run_verifier(receipt)
486
+
487
+ after_entries = sorted(path.name for path in Path(directory).iterdir())
488
+ after_receipt_mtime = receipt.stat().st_mtime_ns
489
+ after_sibling_mtime = sibling.stat().st_mtime_ns
490
+ after_receipt_bytes = receipt.read_bytes()
491
+ after_sibling_bytes = sibling.read_bytes()
492
+ self.assertEqual(2, status)
493
+ self.assertEqual("", stdout.getvalue())
494
+ self.assertEqual("NOT VERIFIED: receipt is not bounded UTF-8 JSON\n", stderr.getvalue())
495
+ self.assertNotIn("Traceback", stderr.getvalue())
496
+ self.assertNotIn(private_marker, stderr.getvalue())
497
+ self.assertNotIn(digits, stderr.getvalue())
498
+ self.assertEqual(before_entries, after_entries)
499
+ self.assertEqual(encoded, after_receipt_bytes)
500
+ self.assertEqual(before_receipt_mtime, after_receipt_mtime)
501
+ self.assertEqual(sibling_bytes, after_sibling_bytes)
502
+ self.assertEqual(before_sibling_mtime, after_sibling_mtime)
503
+
504
+ @unittest.skipUnless(hasattr(os, "symlink"), "symlinks are unavailable")
505
+ def test_verify_receipt_rejects_symlink_without_reading_target(self) -> None:
506
+ with TemporaryDirectory() as directory:
507
+ target, _encoded = self.write_final_receipt(directory)
508
+ receipt = Path(directory) / "receipt-link.json"
509
+ try:
510
+ receipt.symlink_to(target)
511
+ except OSError:
512
+ self.skipTest("symlink creation is not permitted")
513
+ status, stdout, stderr = self.run_verifier(receipt)
514
+ self.assertEqual(2, status)
515
+ self.assertEqual("", stdout.getvalue())
516
+ self.assertIn("regular file", stderr.getvalue())
517
+
518
+ def test_verify_receipt_requires_matching_source_ids_and_read_only_mode(self) -> None:
519
+ private_marker = "private-source-marker"
520
+ with TemporaryDirectory() as directory:
521
+ receipt, _encoded = self.write_final_receipt(directory)
522
+ status, stdout, stderr = self.run_verifier(
523
+ receipt, source_commit=private_marker
524
+ )
525
+ self.assertEqual(2, status)
526
+ self.assertEqual("", stdout.getvalue())
527
+ self.assertIn("exact lowercase source identity", stderr.getvalue())
528
+ self.assertNotIn(private_marker, stderr.getvalue())
529
+
530
+ status, stdout, stderr = self.run_verifier(
531
+ receipt,
532
+ extra=["--i-opt-in-to-write-local-receipt"],
533
+ )
534
+ self.assertEqual(2, status)
535
+ self.assertEqual("", stdout.getvalue())
536
+ self.assertEqual("NOT VERIFIED: invalid command-line arguments\n", stderr.getvalue())
537
+
538
+ def test_verify_receipt_rejects_independent_valid_but_mismatched_source_ids(self) -> None:
539
+ cases = (
540
+ ("commit", "c" * 40, SOURCE_TREE_SHA256),
541
+ ("tree", SOURCE_COMMIT, "d" * 64),
542
+ )
543
+ for label, expected_commit, expected_tree in cases:
544
+ with self.subTest(identity=label), TemporaryDirectory() as directory:
545
+ receipt, _encoded = self.write_final_receipt(directory)
546
+ status, stdout, stderr = self.run_verifier(
547
+ receipt,
548
+ source_commit=expected_commit,
549
+ source_tree_sha256=expected_tree,
550
+ )
551
+ self.assertEqual(2, status)
552
+ self.assertEqual("", stdout.getvalue())
553
+ self.assertTrue(stderr.getvalue().startswith("NOT VERIFIED:"))
554
+ self.assertIn("does not match", stderr.getvalue())
555
+ self.assertNotIn(expected_commit, stderr.getvalue())
556
+ self.assertNotIn(expected_tree, stderr.getvalue())
557
+
558
+ def test_verify_receipt_rejects_missing_and_additional_top_level_members(self) -> None:
559
+ private_marker = "private-top-level-marker"
560
+ cases = ("missing", "additional")
561
+ for case in cases:
562
+ with self.subTest(case=case), TemporaryDirectory() as directory:
563
+ receipt_value = collector._build_receipt(
564
+ submission(quote=False, observed=success_observed())
565
+ )
566
+ if case == "missing":
567
+ receipt_value.pop("privacy")
568
+ else:
569
+ receipt_value[private_marker] = "private-top-level-value"
570
+ receipt = Path(directory) / "receipt.json"
571
+ receipt.write_text(json.dumps(receipt_value), encoding="utf-8")
572
+ status, stdout, stderr = self.run_verifier(receipt)
573
+ self.assertEqual(2, status)
574
+ self.assertEqual("", stdout.getvalue())
575
+ self.assertIn("closed schema", stderr.getvalue())
576
+ self.assertNotIn(private_marker, stderr.getvalue())
577
+ self.assertNotIn("private-top-level-value", stderr.getvalue())
578
+
579
+ def test_verify_receipt_rejects_non_regular_directory_path_without_echoing_it(self) -> None:
580
+ private_marker = "private-receipt-directory"
581
+ with TemporaryDirectory() as directory:
582
+ receipt = Path(directory) / private_marker
583
+ receipt.mkdir()
584
+ status, stdout, stderr = self.run_verifier(receipt)
585
+ self.assertEqual(2, status)
586
+ self.assertEqual("", stdout.getvalue())
587
+ self.assertIn("regular file", stderr.getvalue())
588
+ self.assertNotIn(private_marker, stderr.getvalue())
589
+
590
+ def test_verify_receipt_does_not_create_or_modify_sibling_or_receipt_files(self) -> None:
591
+ with TemporaryDirectory() as directory:
592
+ receipt, encoded = self.write_final_receipt(directory)
593
+ sibling = Path(directory) / "sibling.json"
594
+ sibling_bytes = b"stable sibling\n"
595
+ sibling.write_bytes(sibling_bytes)
596
+ before_entries = sorted(path.name for path in Path(directory).iterdir())
597
+ before_receipt_mtime = receipt.stat().st_mtime_ns
598
+ before_sibling_mtime = sibling.stat().st_mtime_ns
599
+
600
+ status, stdout, stderr = self.run_verifier(receipt)
601
+
602
+ after_entries = sorted(path.name for path in Path(directory).iterdir())
603
+ after_receipt_mtime = receipt.stat().st_mtime_ns
604
+ after_sibling_mtime = sibling.stat().st_mtime_ns
605
+ after_receipt_bytes = receipt.read_bytes()
606
+ after_sibling_bytes = sibling.read_bytes()
607
+ self.assertEqual(0, status)
608
+ self.assertNotEqual("", stdout.getvalue())
609
+ self.assertEqual("", stderr.getvalue())
610
+ self.assertEqual(before_entries, after_entries)
611
+ self.assertEqual(encoded, after_receipt_bytes)
612
+ self.assertEqual(before_receipt_mtime, after_receipt_mtime)
613
+ self.assertEqual(sibling_bytes, after_sibling_bytes)
614
+ self.assertEqual(before_sibling_mtime, after_sibling_mtime)
615
+
616
 
617
  if __name__ == "__main__":
618
  unittest.main()