artifact-receipts 0.1.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.
Files changed (34) hide show
  1. artifact_receipts-0.1.0/CONTRIBUTING.md +8 -0
  2. artifact_receipts-0.1.0/LICENSE +21 -0
  3. artifact_receipts-0.1.0/MANIFEST.in +4 -0
  4. artifact_receipts-0.1.0/PKG-INFO +263 -0
  5. artifact_receipts-0.1.0/README.md +252 -0
  6. artifact_receipts-0.1.0/VALIDATION.md +91 -0
  7. artifact_receipts-0.1.0/artifact_receipts/__init__.py +13 -0
  8. artifact_receipts-0.1.0/artifact_receipts/__main__.py +4 -0
  9. artifact_receipts-0.1.0/artifact_receipts/child_runner.py +63 -0
  10. artifact_receipts-0.1.0/artifact_receipts/children.py +211 -0
  11. artifact_receipts-0.1.0/artifact_receipts/cli.py +130 -0
  12. artifact_receipts-0.1.0/artifact_receipts/observe.py +402 -0
  13. artifact_receipts-0.1.0/artifact_receipts/plugin.py +49 -0
  14. artifact_receipts-0.1.0/artifact_receipts/report.py +265 -0
  15. artifact_receipts-0.1.0/artifact_receipts/wheel.py +224 -0
  16. artifact_receipts-0.1.0/artifact_receipts.egg-info/PKG-INFO +263 -0
  17. artifact_receipts-0.1.0/artifact_receipts.egg-info/SOURCES.txt +32 -0
  18. artifact_receipts-0.1.0/artifact_receipts.egg-info/dependency_links.txt +1 -0
  19. artifact_receipts-0.1.0/artifact_receipts.egg-info/entry_points.txt +2 -0
  20. artifact_receipts-0.1.0/artifact_receipts.egg-info/requires.txt +1 -0
  21. artifact_receipts-0.1.0/artifact_receipts.egg-info/top_level.txt +1 -0
  22. artifact_receipts-0.1.0/ci/qualify_installed.py +55 -0
  23. artifact_receipts-0.1.0/demo/run_demo.sh +66 -0
  24. artifact_receipts-0.1.0/pyproject.toml +20 -0
  25. artifact_receipts-0.1.0/setup.cfg +4 -0
  26. artifact_receipts-0.1.0/tests/conftest.py +4 -0
  27. artifact_receipts-0.1.0/tests/harness.py +150 -0
  28. artifact_receipts-0.1.0/tests/test_children.py +269 -0
  29. artifact_receipts-0.1.0/tests/test_controls.py +551 -0
  30. artifact_receipts-0.1.0/tests/test_demo_gate.py +28 -0
  31. artifact_receipts-0.1.0/tests/test_module_layout.py +77 -0
  32. artifact_receipts-0.1.0/tests/test_native_files.py +186 -0
  33. artifact_receipts-0.1.0/tests/test_report_delivery.py +135 -0
  34. artifact_receipts-0.1.0/tests/test_review_controls.py +124 -0
@@ -0,0 +1,8 @@
1
+ # Contributing
2
+
3
+ Preserve the narrow file-binding contract. Changes must include positive controls,
4
+ negative controls, and fail-closed behavior for missing or contradictory evidence.
5
+ Do not describe on-disk bytes as executed code or cooperative receipts as a security
6
+ boundary. Keep sensitive paths, module names and arguments out of shared examples.
7
+ AI-assisted contributions are allowed under the same testing and review standards.
8
+ New observation modes or broader support claims need explicit design discussion.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Anish Pentyala
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,4 @@
1
+ include LICENSE README.md VALIDATION.md CONTRIBUTING.md
2
+ recursive-include tests *.py
3
+ recursive-include demo *.sh
4
+ recursive-include ci *.py
@@ -0,0 +1,263 @@
1
+ Metadata-Version: 2.4
2
+ Name: artifact-receipts
3
+ Version: 0.1.0
4
+ Summary: Bind pytest-observed import origins to the bytes of a specific local wheel
5
+ License-Expression: MIT
6
+ Requires-Python: >=3.10
7
+ Description-Content-Type: text/markdown
8
+ License-File: LICENSE
9
+ Requires-Dist: pytest>=8
10
+ Dynamic: license-file
11
+
12
+ # artifact-receipts (v0.1.0)
13
+
14
+ Source-installable local tool. No package-registry release or third-party adoption is claimed.
15
+
16
+ Binds the on-disk source files of packages imported during a pytest run to
17
+ the bytes of a specific local wheel. It answers one question: *when my
18
+ tests ran, were the resolved source files of this package byte-identical to
19
+ the files in this exact wheel artifact?* It binds bytes on disk to the
20
+ artifact; it does not claim which bytes were executed at import time (see
21
+ the honesty boundaries below).
22
+
23
+ This is accident detection, not attestation. Typical accident: a source
24
+ checkout on `sys.path` silently shadows the installed wheel during tests (the
25
+ shape reported in pypa/cibuildwheel#1534), or an installed file was modified
26
+ after install. Name/version checks pass in both cases; this tool does not.
27
+
28
+ This is a narrow packaging/test-isolation diagnostic, not a new provenance
29
+ algorithm or a replacement for clean test environments, artifact verification,
30
+ coverage measurement or supply-chain attestation.
31
+
32
+ ## Install from source
33
+
34
+ ```sh
35
+ python -m pip install .
36
+ ```
37
+
38
+ Use Python 3.10 or later with pytest installed. The locally checked support
39
+ matrix is stated in VALIDATION.md; an open-ended Python/pytest dependency floor
40
+ is not proof of compatibility with every version or platform.
41
+
42
+ ## Usage
43
+
44
+ ```
45
+ python -m artifact_receipts run \
46
+ --wheel dist/mypkg-1.0-py3-none-any.whl \
47
+ --package mypkg [--package mypkg.plugins] \
48
+ [--json-report receipts.json] [--human-report receipts.txt] \
49
+ -- [pytest args]
50
+ ```
51
+
52
+ Run it with the interpreter/environment you would run pytest with. It calls
53
+ `pytest.main` in-process: nothing is installed, `sys.path` is not modified,
54
+ and your pytest args pass through after `--`.
55
+
56
+ ## What "verified" means (and does not)
57
+
58
+ `verified` means: every selected package was resolved by the import system
59
+ during the run (recorded by wrappers around the `sys.meta_path` finders),
60
+ every observed module's on-disk source file is byte-identical (SHA-256) to
61
+ the member at that module's own archive-relative path in the given wheel
62
+ (whose own SHA-256 is reported; package `__init__.py` and plain-module `.py`
63
+ layouts are distinct, even if their bytes match. Matching only some other member, e.g. a
64
+ dist-info file with identical bytes, is a mismatch, not a match), the
65
+ resolution records and the terminal `sys.modules` scan agree (a module
66
+ resolved from more than one distinct origin during the run is an observation
67
+ gap, resident or not; a module imported then removed mid-run is still bound
68
+ from its recorded origin; a replaced module whose resident origin disagrees
69
+ with the recorded origin is an observation gap), no module was preloaded
70
+ before the run, no unsupported module kind was involved, and no cached
71
+ bytecode contradicts its source file.
72
+
73
+ The wheel's identity must be unambiguous before any mapping is trusted:
74
+ filename, the single `.dist-info` directory, and METADATA `Name`/`Version`
75
+ must agree with each other. RECORD must parse; supplied digests must use
76
+ SHA-256 and match the archive member bytes. A supplied digest for a nonexistent
77
+ archive member, or an identity/digest conflict, makes the wheel invalid
78
+ (`incomplete`). Members omitted from RECORD produce a warning, not a failure;
79
+ entries without a digest do not authenticate their member. Byte binding uses
80
+ the actual ZIP member bytes, not the completeness of RECORD.
81
+
82
+ It does **not** mean:
83
+
84
+ - that those source bytes were the bytes executed at import time. With the
85
+ default timestamp+size pyc validity, an attacker or accident that preserves
86
+ size and mtime can make the interpreter execute stale bytecode while the
87
+ source file matches; PEP 552 hash-based pycs with `check_source` unset are
88
+ trusted without any source check. Post-hoc file hashing cannot see either.
89
+ The report carries bytecode-cache evidence and flags trusted-without-
90
+ checking pycs, and the scope string says this explicitly. `verified` is a
91
+ statement about byte binding, never about executed bytes.
92
+ - that every import in the process was observed. Code run without the import
93
+ system (exec, runpy of a path) leaves no resolution record.
94
+ - anything about build provenance, semantic equivalence, coverage, or
95
+ whether the code behaved honestly.
96
+ - anything about nonstandard custom-loader source filenames, extension/native modules, namespace packages, sourceless
97
+ imports, `pytest-xdist` workers, or modules the wheel relocates through
98
+ `.data/purelib`: these are detected and refused (overall `incomplete`,
99
+ never `verified`; a relocated member is never a provenance failure when
100
+ the install is otherwise correct).
101
+ - anything outside the pytest process itself. Imports of selected packages
102
+ in forked, spawned, or subprocess children are NOT observed and NOT
103
+ detected: the tool cannot see them, and every report carries a standing
104
+ warning saying so. This is a stated scope limit, not a detection claim.
105
+
106
+ ## Results and exit codes
107
+
108
+ - `verified` (0): binding established and tests passed.
109
+ - `failed` (13): at least one observed module's bytes are not in the wheel
110
+ at its own archive-relative path.
111
+ - `incomplete` (14): evidence insufficient (nothing resolved during the run,
112
+ preloaded module, unsupported kind/mode, observation gap between resolution
113
+ records and the terminal module table, bytecode cache contradicting its
114
+ source file, invalid wheel, report-write failure). An invalid wheel
115
+ (duplicate members, path traversal, malformed or digest-mismatched RECORD,
116
+ unsafe paths, filename/dist-info/METADATA identity conflict) yields
117
+ `incomplete` without trusting any mapping from it; members are never
118
+ extracted.
119
+ - A failing pytest run keeps pytest's own exit code no matter what
120
+ provenance says; a report-write failure cannot erase a test failure and
121
+ cannot leave a run `verified`.
122
+
123
+ Exit codes 13 and 14 sit outside pytest's own 0-5 range, so a consumer
124
+ mapping exit codes can never confuse a provenance result with a pytest
125
+ internal error (3) or usage error (4).
126
+
127
+ ## Controls
128
+
129
+ `tests/test_controls.py` and `tests/test_review_controls.py` run negative controls in clean subprocesses: correct install, checkout shadowing,
130
+ same-path changed bytes, submodule-only shadowing, nothing imported,
131
+ namespace package, failing pytest with matching and mismatching provenance,
132
+ duplicate zip members, path traversal, malformed RECORD, report-write
133
+ failure, preloaded module (import-system 5.3.1 sys.modules hit), module
134
+ imported then removed from sys.modules mid-run (still bound from the recorded
135
+ origin), module imported then replaced mid-run (observation gap), module
136
+ resolved from two distinct origins while resident (observation gap), module
137
+ bytes matching only a non-module wheel member (mismatch: binding requires
138
+ the module-relative path), dist-info/filename and METADATA/filename identity
139
+ conflicts (invalid wheel), `.data/purelib` relocation on a correct install
140
+ (unsupported, not failed), size/mtime-preserving tamper, stale pyc executed
141
+ while the file matches (documented boundary), and unchecked hash-based pyc.
142
+
143
+ ## Demo
144
+
145
+ `demo/run_demo.sh` (offline) shows ordinary pytest passing against a
146
+ shadowing source checkout while artifact-receipts fails the run.
147
+
148
+ ## Validation
149
+
150
+ `ci/qualify_installed.py SOURCE_ROOT EXACT_WHEEL` checks the currently installed
151
+ tool's location and runtime-file bytes against the source and exact wheel, then
152
+ runs a tests/demo-only copy outside the checkout. It does not install anything.
153
+ Use a clean environment and install the wheel first. The tests create tiny
154
+ synthetic wheel fixtures; native tests compile small C extensions and need `cc`
155
+ and Python development headers on Linux. There is no network access in these
156
+ controls. Current results and limits are in VALIDATION.md.
157
+
158
+ ## Experimental: explicitly required Python children
159
+
160
+ The default command still covers the pytest process only. It does not discover
161
+ arbitrary subprocess, fork, spawn or xdist imports.
162
+
163
+ For tests that deliberately run a Python worker, declare each required job:
164
+
165
+ ```sh
166
+ python -m artifact_receipts run --wheel dist/example-1.0-py3-none-any.whl \
167
+ --package example --require-child worker --json-report receipt.json -- tests
168
+ ```
169
+
170
+ Use the helper in the test that launches that script:
171
+
172
+ ```python
173
+ import example
174
+ from artifact_receipts.children import run_observed_python
175
+
176
+
177
+ def test_worker():
178
+ assert example is not None
179
+ result = run_observed_python("worker", "tests/worker.py", ["--mode", "check"])
180
+ assert result.returncode == 0, result.stderr
181
+ ```
182
+
183
+ The worker is an ordinary Python script that imports the selected package. The
184
+ helper runs a fresh interpreter with import observation installed before the
185
+ script, and returns a `subprocess.CompletedProcess` with captured text stdout and
186
+ stderr. Optional keyword arguments are `python`, `cwd`, `env` and `timeout`
187
+ (default 60 seconds, finite and positive). Script arguments are passed without
188
+ a shell. `env`, when given, replaces the environment, rather than adding keys.
189
+ The interpreter must already have this tool and the selected package installed;
190
+ nothing is installed and the parent import path is not changed. The child's
191
+ script-directory lookup matches ordinary `python path/to/script.py` behavior,
192
+ including a script-local package shadowing its installed copy.
193
+
194
+ Each required label must run exactly once. Missing, repeated, unfinished,
195
+ malformed or wrong-run receipts are **incomplete**. An ignored child return code
196
+ does not hide its mismatch or missing evidence: parent aggregation still fails
197
+ closed. Each declared child must import every selected package, independently
198
+ of the parent's imports. Parent tests must still import those packages too.
199
+ Pytest failures keep their own exit code. Otherwise a mismatch in either parent
200
+ or required child returns 13; insufficient child evidence returns 14.
201
+
202
+ Receipts cross-check run, label, launched PID, wheel hash, selected packages,
203
+ process exit and module verdicts. The parent verifies matching module paths and
204
+ digests against its wheel again. Reports put each child's evidence under
205
+ `children`, separately from parent `modules`, and include a `child_scope`.
206
+
207
+ This is cooperative build evidence, **not a security boundary**. Tested code
208
+ runs as the same user and can forge receipt files. A nonce prevents accidental
209
+ reuse, not malicious forgery. Observation still binds source bytes on disk after
210
+ execution, not the exact bytes executed. Unregistered children and grandchildren
211
+ are neither observed nor detected. Children cannot recursively register jobs
212
+ in the parent session. A timeout kills only the named process, not its whole
213
+ process tree; descendants may survive and are the caller's responsibility.
214
+ Captured output has no memory cap, so this helper is not for unbounded output.
215
+ Receipt JSON is capped at 8 MiB of characters per file. Reports include script
216
+ paths and arguments; inspect them before sharing.
217
+
218
+ ## Consuming reports safely
219
+
220
+ Require exit code 0 from the current invocation **and** its matching complete
221
+ report with `result: verified`. A report alone is never a completion marker.
222
+ Missing reports, nonzero exits, malformed or stale reports must not count as
223
+ verified, even if another file contains an older `verified` result. Use a fresh
224
+ output directory per run and retain the process exit status with the artifacts.
225
+
226
+ Detected report-write failures change a previously verified in-memory result to
227
+ incomplete. Output files are replaced individually after complete writes; after
228
+ a detected failure the tool attempts to rewrite requested files with that result,
229
+ or remove files it cannot repair. Recovery is best-effort. Filesystem errors can
230
+ block both rewriting and removal, and abrupt exit, signal or power loss can
231
+ interrupt recovery or prevent reports entirely. Multiple report files are not
232
+ an atomic transaction. The command's exit status is required even when a report
233
+ file exists. Byte mismatches and pytest failures keep their own failure status.
234
+
235
+
236
+ ## Opt-in native file binding
237
+
238
+ `--observe-native` adds file binding for the current interpreter's standard
239
+ `importlib.machinery.ExtensionFileLoader` only. A native module's exact
240
+ filename must use a suffix in that interpreter's `EXTENSION_SUFFIXES` and
241
+ match its own wheel-relative module or package `__init__` path. Bytes matching
242
+ a different member or the other module/package layout do not pass. The report
243
+ sets `native_file_binding` and gives the narrower native scope explicitly.
244
+
245
+ This is an optional file-binding mode, not a loaded-code attestation.
246
+ Without the flag, extension modules still make the result incomplete. The flag
247
+ cannot be combined with `--require-child`; native child capture is not supported.
248
+ Custom native loaders, iOS framework relocation and `.data` relocation remain
249
+ unsupported. Preloaded modules, contradictory origins and unobserved imports
250
+ still cannot earn a verified result.
251
+
252
+ A native match binds the extension **file on disk** to the exact wheel member.
253
+ It does not bind the image loaded in memory, capture system or bundled shared
254
+ library dependencies, validate wheel tags or ABI/platform compatibility, attest
255
+ build provenance, or establish code safety. A file replaced after loading can
256
+ have different bytes from the image still mapped in memory. A test importing
257
+ an extension with a passing functional result is not evidence that all of its
258
+ native dependencies came from the wheel.
259
+
260
+ Native compilation controls establish only the tested Linux interpreter and
261
+ standard loader cases. Windows/macOS, shared-library dependency binding and
262
+ hostile-process behavior are not qualified here. No external-wheel rehearsal,
263
+ third-party adoption or upstream validation is claimed.
@@ -0,0 +1,252 @@
1
+ # artifact-receipts (v0.1.0)
2
+
3
+ Source-installable local tool. No package-registry release or third-party adoption is claimed.
4
+
5
+ Binds the on-disk source files of packages imported during a pytest run to
6
+ the bytes of a specific local wheel. It answers one question: *when my
7
+ tests ran, were the resolved source files of this package byte-identical to
8
+ the files in this exact wheel artifact?* It binds bytes on disk to the
9
+ artifact; it does not claim which bytes were executed at import time (see
10
+ the honesty boundaries below).
11
+
12
+ This is accident detection, not attestation. Typical accident: a source
13
+ checkout on `sys.path` silently shadows the installed wheel during tests (the
14
+ shape reported in pypa/cibuildwheel#1534), or an installed file was modified
15
+ after install. Name/version checks pass in both cases; this tool does not.
16
+
17
+ This is a narrow packaging/test-isolation diagnostic, not a new provenance
18
+ algorithm or a replacement for clean test environments, artifact verification,
19
+ coverage measurement or supply-chain attestation.
20
+
21
+ ## Install from source
22
+
23
+ ```sh
24
+ python -m pip install .
25
+ ```
26
+
27
+ Use Python 3.10 or later with pytest installed. The locally checked support
28
+ matrix is stated in VALIDATION.md; an open-ended Python/pytest dependency floor
29
+ is not proof of compatibility with every version or platform.
30
+
31
+ ## Usage
32
+
33
+ ```
34
+ python -m artifact_receipts run \
35
+ --wheel dist/mypkg-1.0-py3-none-any.whl \
36
+ --package mypkg [--package mypkg.plugins] \
37
+ [--json-report receipts.json] [--human-report receipts.txt] \
38
+ -- [pytest args]
39
+ ```
40
+
41
+ Run it with the interpreter/environment you would run pytest with. It calls
42
+ `pytest.main` in-process: nothing is installed, `sys.path` is not modified,
43
+ and your pytest args pass through after `--`.
44
+
45
+ ## What "verified" means (and does not)
46
+
47
+ `verified` means: every selected package was resolved by the import system
48
+ during the run (recorded by wrappers around the `sys.meta_path` finders),
49
+ every observed module's on-disk source file is byte-identical (SHA-256) to
50
+ the member at that module's own archive-relative path in the given wheel
51
+ (whose own SHA-256 is reported; package `__init__.py` and plain-module `.py`
52
+ layouts are distinct, even if their bytes match. Matching only some other member, e.g. a
53
+ dist-info file with identical bytes, is a mismatch, not a match), the
54
+ resolution records and the terminal `sys.modules` scan agree (a module
55
+ resolved from more than one distinct origin during the run is an observation
56
+ gap, resident or not; a module imported then removed mid-run is still bound
57
+ from its recorded origin; a replaced module whose resident origin disagrees
58
+ with the recorded origin is an observation gap), no module was preloaded
59
+ before the run, no unsupported module kind was involved, and no cached
60
+ bytecode contradicts its source file.
61
+
62
+ The wheel's identity must be unambiguous before any mapping is trusted:
63
+ filename, the single `.dist-info` directory, and METADATA `Name`/`Version`
64
+ must agree with each other. RECORD must parse; supplied digests must use
65
+ SHA-256 and match the archive member bytes. A supplied digest for a nonexistent
66
+ archive member, or an identity/digest conflict, makes the wheel invalid
67
+ (`incomplete`). Members omitted from RECORD produce a warning, not a failure;
68
+ entries without a digest do not authenticate their member. Byte binding uses
69
+ the actual ZIP member bytes, not the completeness of RECORD.
70
+
71
+ It does **not** mean:
72
+
73
+ - that those source bytes were the bytes executed at import time. With the
74
+ default timestamp+size pyc validity, an attacker or accident that preserves
75
+ size and mtime can make the interpreter execute stale bytecode while the
76
+ source file matches; PEP 552 hash-based pycs with `check_source` unset are
77
+ trusted without any source check. Post-hoc file hashing cannot see either.
78
+ The report carries bytecode-cache evidence and flags trusted-without-
79
+ checking pycs, and the scope string says this explicitly. `verified` is a
80
+ statement about byte binding, never about executed bytes.
81
+ - that every import in the process was observed. Code run without the import
82
+ system (exec, runpy of a path) leaves no resolution record.
83
+ - anything about build provenance, semantic equivalence, coverage, or
84
+ whether the code behaved honestly.
85
+ - anything about nonstandard custom-loader source filenames, extension/native modules, namespace packages, sourceless
86
+ imports, `pytest-xdist` workers, or modules the wheel relocates through
87
+ `.data/purelib`: these are detected and refused (overall `incomplete`,
88
+ never `verified`; a relocated member is never a provenance failure when
89
+ the install is otherwise correct).
90
+ - anything outside the pytest process itself. Imports of selected packages
91
+ in forked, spawned, or subprocess children are NOT observed and NOT
92
+ detected: the tool cannot see them, and every report carries a standing
93
+ warning saying so. This is a stated scope limit, not a detection claim.
94
+
95
+ ## Results and exit codes
96
+
97
+ - `verified` (0): binding established and tests passed.
98
+ - `failed` (13): at least one observed module's bytes are not in the wheel
99
+ at its own archive-relative path.
100
+ - `incomplete` (14): evidence insufficient (nothing resolved during the run,
101
+ preloaded module, unsupported kind/mode, observation gap between resolution
102
+ records and the terminal module table, bytecode cache contradicting its
103
+ source file, invalid wheel, report-write failure). An invalid wheel
104
+ (duplicate members, path traversal, malformed or digest-mismatched RECORD,
105
+ unsafe paths, filename/dist-info/METADATA identity conflict) yields
106
+ `incomplete` without trusting any mapping from it; members are never
107
+ extracted.
108
+ - A failing pytest run keeps pytest's own exit code no matter what
109
+ provenance says; a report-write failure cannot erase a test failure and
110
+ cannot leave a run `verified`.
111
+
112
+ Exit codes 13 and 14 sit outside pytest's own 0-5 range, so a consumer
113
+ mapping exit codes can never confuse a provenance result with a pytest
114
+ internal error (3) or usage error (4).
115
+
116
+ ## Controls
117
+
118
+ `tests/test_controls.py` and `tests/test_review_controls.py` run negative controls in clean subprocesses: correct install, checkout shadowing,
119
+ same-path changed bytes, submodule-only shadowing, nothing imported,
120
+ namespace package, failing pytest with matching and mismatching provenance,
121
+ duplicate zip members, path traversal, malformed RECORD, report-write
122
+ failure, preloaded module (import-system 5.3.1 sys.modules hit), module
123
+ imported then removed from sys.modules mid-run (still bound from the recorded
124
+ origin), module imported then replaced mid-run (observation gap), module
125
+ resolved from two distinct origins while resident (observation gap), module
126
+ bytes matching only a non-module wheel member (mismatch: binding requires
127
+ the module-relative path), dist-info/filename and METADATA/filename identity
128
+ conflicts (invalid wheel), `.data/purelib` relocation on a correct install
129
+ (unsupported, not failed), size/mtime-preserving tamper, stale pyc executed
130
+ while the file matches (documented boundary), and unchecked hash-based pyc.
131
+
132
+ ## Demo
133
+
134
+ `demo/run_demo.sh` (offline) shows ordinary pytest passing against a
135
+ shadowing source checkout while artifact-receipts fails the run.
136
+
137
+ ## Validation
138
+
139
+ `ci/qualify_installed.py SOURCE_ROOT EXACT_WHEEL` checks the currently installed
140
+ tool's location and runtime-file bytes against the source and exact wheel, then
141
+ runs a tests/demo-only copy outside the checkout. It does not install anything.
142
+ Use a clean environment and install the wheel first. The tests create tiny
143
+ synthetic wheel fixtures; native tests compile small C extensions and need `cc`
144
+ and Python development headers on Linux. There is no network access in these
145
+ controls. Current results and limits are in VALIDATION.md.
146
+
147
+ ## Experimental: explicitly required Python children
148
+
149
+ The default command still covers the pytest process only. It does not discover
150
+ arbitrary subprocess, fork, spawn or xdist imports.
151
+
152
+ For tests that deliberately run a Python worker, declare each required job:
153
+
154
+ ```sh
155
+ python -m artifact_receipts run --wheel dist/example-1.0-py3-none-any.whl \
156
+ --package example --require-child worker --json-report receipt.json -- tests
157
+ ```
158
+
159
+ Use the helper in the test that launches that script:
160
+
161
+ ```python
162
+ import example
163
+ from artifact_receipts.children import run_observed_python
164
+
165
+
166
+ def test_worker():
167
+ assert example is not None
168
+ result = run_observed_python("worker", "tests/worker.py", ["--mode", "check"])
169
+ assert result.returncode == 0, result.stderr
170
+ ```
171
+
172
+ The worker is an ordinary Python script that imports the selected package. The
173
+ helper runs a fresh interpreter with import observation installed before the
174
+ script, and returns a `subprocess.CompletedProcess` with captured text stdout and
175
+ stderr. Optional keyword arguments are `python`, `cwd`, `env` and `timeout`
176
+ (default 60 seconds, finite and positive). Script arguments are passed without
177
+ a shell. `env`, when given, replaces the environment, rather than adding keys.
178
+ The interpreter must already have this tool and the selected package installed;
179
+ nothing is installed and the parent import path is not changed. The child's
180
+ script-directory lookup matches ordinary `python path/to/script.py` behavior,
181
+ including a script-local package shadowing its installed copy.
182
+
183
+ Each required label must run exactly once. Missing, repeated, unfinished,
184
+ malformed or wrong-run receipts are **incomplete**. An ignored child return code
185
+ does not hide its mismatch or missing evidence: parent aggregation still fails
186
+ closed. Each declared child must import every selected package, independently
187
+ of the parent's imports. Parent tests must still import those packages too.
188
+ Pytest failures keep their own exit code. Otherwise a mismatch in either parent
189
+ or required child returns 13; insufficient child evidence returns 14.
190
+
191
+ Receipts cross-check run, label, launched PID, wheel hash, selected packages,
192
+ process exit and module verdicts. The parent verifies matching module paths and
193
+ digests against its wheel again. Reports put each child's evidence under
194
+ `children`, separately from parent `modules`, and include a `child_scope`.
195
+
196
+ This is cooperative build evidence, **not a security boundary**. Tested code
197
+ runs as the same user and can forge receipt files. A nonce prevents accidental
198
+ reuse, not malicious forgery. Observation still binds source bytes on disk after
199
+ execution, not the exact bytes executed. Unregistered children and grandchildren
200
+ are neither observed nor detected. Children cannot recursively register jobs
201
+ in the parent session. A timeout kills only the named process, not its whole
202
+ process tree; descendants may survive and are the caller's responsibility.
203
+ Captured output has no memory cap, so this helper is not for unbounded output.
204
+ Receipt JSON is capped at 8 MiB of characters per file. Reports include script
205
+ paths and arguments; inspect them before sharing.
206
+
207
+ ## Consuming reports safely
208
+
209
+ Require exit code 0 from the current invocation **and** its matching complete
210
+ report with `result: verified`. A report alone is never a completion marker.
211
+ Missing reports, nonzero exits, malformed or stale reports must not count as
212
+ verified, even if another file contains an older `verified` result. Use a fresh
213
+ output directory per run and retain the process exit status with the artifacts.
214
+
215
+ Detected report-write failures change a previously verified in-memory result to
216
+ incomplete. Output files are replaced individually after complete writes; after
217
+ a detected failure the tool attempts to rewrite requested files with that result,
218
+ or remove files it cannot repair. Recovery is best-effort. Filesystem errors can
219
+ block both rewriting and removal, and abrupt exit, signal or power loss can
220
+ interrupt recovery or prevent reports entirely. Multiple report files are not
221
+ an atomic transaction. The command's exit status is required even when a report
222
+ file exists. Byte mismatches and pytest failures keep their own failure status.
223
+
224
+
225
+ ## Opt-in native file binding
226
+
227
+ `--observe-native` adds file binding for the current interpreter's standard
228
+ `importlib.machinery.ExtensionFileLoader` only. A native module's exact
229
+ filename must use a suffix in that interpreter's `EXTENSION_SUFFIXES` and
230
+ match its own wheel-relative module or package `__init__` path. Bytes matching
231
+ a different member or the other module/package layout do not pass. The report
232
+ sets `native_file_binding` and gives the narrower native scope explicitly.
233
+
234
+ This is an optional file-binding mode, not a loaded-code attestation.
235
+ Without the flag, extension modules still make the result incomplete. The flag
236
+ cannot be combined with `--require-child`; native child capture is not supported.
237
+ Custom native loaders, iOS framework relocation and `.data` relocation remain
238
+ unsupported. Preloaded modules, contradictory origins and unobserved imports
239
+ still cannot earn a verified result.
240
+
241
+ A native match binds the extension **file on disk** to the exact wheel member.
242
+ It does not bind the image loaded in memory, capture system or bundled shared
243
+ library dependencies, validate wheel tags or ABI/platform compatibility, attest
244
+ build provenance, or establish code safety. A file replaced after loading can
245
+ have different bytes from the image still mapped in memory. A test importing
246
+ an extension with a passing functional result is not evidence that all of its
247
+ native dependencies came from the wheel.
248
+
249
+ Native compilation controls establish only the tested Linux interpreter and
250
+ standard loader cases. Windows/macOS, shared-library dependency binding and
251
+ hostile-process behavior are not qualified here. No external-wheel rehearsal,
252
+ third-party adoption or upstream validation is claimed.
@@ -0,0 +1,91 @@
1
+ # Validation and support boundaries
2
+
3
+ Candidate preparation, November 14, 2026. This is one original tool with optional
4
+ required-child and native-file binding modes, not several independent projects.
5
+ No public repository, hosted CI, registry publication or third-party adoption is
6
+ claimed by these local results.
7
+
8
+ ## Checked environment
9
+
10
+ - Actual CPython 3.10.12, Linux x86-64, pytest 8.3.5 and 9.2.0, each in an
11
+ installed-wheel environment outside the source checkout.
12
+ - Each run passes all 140 tests with no skips and one expected warning
13
+ from the deliberate duplicate-ZIP-member fixture. Native tests compile actual
14
+ small C modules and packages with `cc`; they are not mocked import successes.
15
+ - Each offline demo returns verified exit 0 for matching source files and exit
16
+ 13 for a shadowing checkout while its functional pytest test still passes.
17
+ Existing shell controls independently reject unexpected mismatch exits 0 and
18
+ 14 and accept 13.
19
+ - Seven runtime Python files retain the recovered implementation bytes. The
20
+ two reviewed-correction candidates, observe.py and wheel.py, preserve
21
+ originless import evidence and fix conservative ZIP/name rejection. A prior
22
+ 114-test public candidate was not merged after new review found these cases.
23
+ - The qualification script verifies the exact runtime file list and every
24
+ source/wheel/installed Python file's bytes, records interpreter/pytest versions,
25
+ origin and wheel SHA-256, then runs a tests/demo-only copy in a fresh directory.
26
+ It rejects an import from the source tree and a wheel with differing runtime
27
+ bytes before running tests. A passing test run without that byte check is not
28
+ the installed-artifact claim.
29
+ - Wheel and source distribution build successfully. The included GitHub Actions
30
+ workflow repeats the two checked pytest versions on Python 3.10. Its presence
31
+ is not evidence that hosted CI has run or passed.
32
+
33
+ The declared `Python >=3.10` and `pytest >=8` metadata are dependency floors,
34
+ not a guarantee for every later version. Other interpreters, versions, operating
35
+ systems, free-threading, arbitrary import hooks, hostile code, distributed workers
36
+ and external-package rehearsals are not qualified by this matrix. Native tests
37
+ require a compiler and development headers; no Windows or macOS native claim.
38
+
39
+ ## What the controls establish
40
+
41
+ Positive and negative cases cover correct files, checkout shadowing, changed
42
+ installed files, exact module/package paths, wheel identity/RECORD conflicts,
43
+ preloaded or unobserved modules, removed/replaced/multi-origin modules, bytecode
44
+ contradictions, explicitly required child receipts, report-write failures and
45
+ opt-in standard-loader native files. Full details are in README.md and tests.
46
+
47
+ The result binds **on-disk files** to wheel member bytes. It does not establish
48
+ executed Python bytecode, loaded native memory, shared-library dependencies,
49
+ semantic correctness, coverage, provenance attestations or a security boundary.
50
+ An unchecked/stale bytecode cache or a file replaced after native loading can
51
+ decouple execution from the matching file on disk. Cooperative child receipts
52
+ can be forged by tested code with the same user permissions. Unregistered
53
+ children/grandchildren are neither observed nor detected. Captured child output
54
+ is not memory-capped, and timeout does not kill an entire descendant process tree.
55
+
56
+ Reports may reveal module names, local paths, interpreter location, script paths
57
+ and arguments. Review reports before sharing them. Require current exit 0 plus
58
+ the current complete `verified` report; a stale report alone is not success.
59
+
60
+ ## Pre-merge review corrections
61
+
62
+ A namespace imported and then removed from `sys.modules` used to disappear from
63
+ reconciliation. A matching root package could then incorrectly produce
64
+ `verified`. Originless resolutions now remain `unsupported` even after removal;
65
+ mixed originless/file or other-origin resolutions are an `observation_gap`.
66
+ Empty origins are treated as originless as well as None. Resident and removed
67
+ cases, both transition orders, and non-file origins have direct controls.
68
+
69
+ Explicit safe ZIP directory entries are accepted without treating them as files
70
+ to hash. Absolute, backslash, empty internal, dot and traversal components remain
71
+ rejected. Distribution names are compared after lowercasing and collapsing runs
72
+ of `-`, `_` and `.` in filename/dist-info/METADATA, while exact version and
73
+ single-dist-info requirements remain. This does not make the tool a full wheel
74
+ specification validator; notably its digest support is still SHA-256 only.
75
+
76
+ The 26 new control cases fail on the previous exact candidate in 17 places:
77
+ 11 origin-evidence assertions, one directory-entry CLI assertion and five
78
+ name-compatibility loads raising WheelError. Nine rejection controls already
79
+ pass there. Four isolated production reversions weaken origin evidence, reject
80
+ safe directories, admit ambiguous relative directory paths, or restore old
81
+ metadata-name comparison; the corresponding controls fail. A traversal control
82
+ was strengthened to omit directory RECORD rows, so its mutation demonstrates
83
+ acceptance of the unsafe path rather than an unrelated digest failure.
84
+
85
+ Specification references, fetched November 14, 2026:
86
+ - https://packaging.python.org/en/latest/specifications/name-normalization/
87
+ says names "should be lowercased with all runs of the characters `.`, `-`, or
88
+ `_` replaced with a single `-` character".
89
+ - https://packaging.python.org/en/latest/specifications/binary-distribution-format/
90
+ says a wheel "is a ZIP-format archive" and consumers "must be prepared to
91
+ accept `.` (FULL STOP) and uppercase letters" in distribution names.
@@ -0,0 +1,13 @@
1
+ """artifact_receipts: bind pytest-observed imports to a local wheel's bytes.
2
+
3
+ Verifies that the on-disk source files of selected packages, as resolved by
4
+ the import system during the pytest run, are byte-identical to members of a
5
+ specific local wheel.
6
+
7
+ Scope: accidental-environment error detection (e.g. a source checkout
8
+ shadowing an installed wheel). Not a security attestation, not a
9
+ hostile-code sandbox, and not proof of which bytes were executed at import
10
+ time (see README's honesty boundaries).
11
+ """
12
+
13
+ __version__ = "0.1.0"
@@ -0,0 +1,4 @@
1
+ from .cli import main
2
+
3
+ if __name__ == "__main__":
4
+ raise SystemExit(main())