Spaces:
Running
Running
Sync GitHub source 592c8cbe7e8b6d8907cc52fae8436438d95b8127
Browse filesCanonical source: https://github.com/noqt/Lumi-Eggcracker/commit/592c8cbe7e8b6d8907cc52fae8436438d95b8127
- HUGGINGFACE_MANIFEST.json +22 -6
- HUGGINGFACE_SYNC.json +4 -4
- README.md +1 -1
- TRY_IT.md +75 -20
- examples/observe-first/lumi-eggcracker-observe-first.pyz +0 -0
- examples/observe-first/lumi-eggcracker-observe-first.pyz.sha256 +1 -0
- index.html +2 -2
- scripts/build_observe_first_zipapp.py +287 -0
- tests/test_observe_first_zipapp.py +183 -0
HUGGINGFACE_MANIFEST.json
CHANGED
|
@@ -37,7 +37,7 @@
|
|
| 37 |
"size": 10537
|
| 38 |
},
|
| 39 |
"README.md": {
|
| 40 |
-
"sha256": "
|
| 41 |
"size": 48062
|
| 42 |
},
|
| 43 |
"RELEASE_NOTES.md": {
|
|
@@ -57,8 +57,8 @@
|
|
| 57 |
"size": 1970
|
| 58 |
},
|
| 59 |
"TRY_IT.md": {
|
| 60 |
-
"sha256": "
|
| 61 |
-
"size":
|
| 62 |
},
|
| 63 |
"actions/validate-hosted-proof-receipt/action.yml": {
|
| 64 |
"sha256": "4f66f6bfe972a945cdb686a570f51aeb7a474c48986608c9de862dfb6cf27ab3",
|
|
@@ -116,6 +116,14 @@
|
|
| 116 |
"sha256": "a4293e0147a43483d17eb6983ffb8d46ee5f767a978f018ce5080cb37cf9fee7",
|
| 117 |
"size": 304
|
| 118 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
"examples/observe-first/partial-match.json": {
|
| 120 |
"sha256": "2c4ec5b4c8074225aaee5e9c41aa2535cd0d4e85a7ec243dcb71f996d08a0ee2",
|
| 121 |
"size": 315
|
|
@@ -201,7 +209,7 @@
|
|
| 201 |
"size": 4101
|
| 202 |
},
|
| 203 |
"index.html": {
|
| 204 |
-
"sha256": "
|
| 205 |
"size": 22790
|
| 206 |
},
|
| 207 |
"integrations/prometheus/eggcracker.rules.yml": {
|
|
@@ -252,6 +260,10 @@
|
|
| 252 |
"sha256": "2b21689c110c4c01a998cd10b014b22ad11957758dacb793e9fda5ccc9a782e8",
|
| 253 |
"size": 17005
|
| 254 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
| 255 |
"scripts/build_release.py": {
|
| 256 |
"sha256": "c3792b513b4f2811d31da7783331e7b918de243d46bd949467ff4fa11bb55746",
|
| 257 |
"size": 7625
|
|
@@ -728,6 +740,10 @@
|
|
| 728 |
"sha256": "146a10077b6e90a75971677e48b7030955f89f114aef85e7bb757bd0643c3550",
|
| 729 |
"size": 6990
|
| 730 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
| 731 |
"tests/test_offline_boundary.py": {
|
| 732 |
"sha256": "2138cae662b8d1a0f1b4cf7ae63ce0aef7ca887aa2d3cf684a6ef82ef46737d5",
|
| 733 |
"size": 9742
|
|
@@ -863,6 +879,6 @@
|
|
| 863 |
},
|
| 864 |
"schema": "noqt.huggingface_manifest.v1",
|
| 865 |
"source_repository": "https://github.com/noqt/Lumi-Eggcracker",
|
| 866 |
-
"source_revision": "
|
| 867 |
-
"source_url": "https://github.com/noqt/Lumi-Eggcracker/commit/
|
| 868 |
}
|
|
|
|
| 37 |
"size": 10537
|
| 38 |
},
|
| 39 |
"README.md": {
|
| 40 |
+
"sha256": "edef2906f69c4c818aae37d9447b06da8bf536417b2451523e9799a76a4b00c0",
|
| 41 |
"size": 48062
|
| 42 |
},
|
| 43 |
"RELEASE_NOTES.md": {
|
|
|
|
| 57 |
"size": 1970
|
| 58 |
},
|
| 59 |
"TRY_IT.md": {
|
| 60 |
+
"sha256": "8f055baf9d4ffd208db06a80d57d6775b89654317fc14c3cf732ec1aa21b2076",
|
| 61 |
+
"size": 14917
|
| 62 |
},
|
| 63 |
"actions/validate-hosted-proof-receipt/action.yml": {
|
| 64 |
"sha256": "4f66f6bfe972a945cdb686a570f51aeb7a474c48986608c9de862dfb6cf27ab3",
|
|
|
|
| 116 |
"sha256": "a4293e0147a43483d17eb6983ffb8d46ee5f767a978f018ce5080cb37cf9fee7",
|
| 117 |
"size": 304
|
| 118 |
},
|
| 119 |
+
"examples/observe-first/lumi-eggcracker-observe-first.pyz": {
|
| 120 |
+
"sha256": "2cc33f9b61eb22e0b456ad37c7938dd51ff9a74b7950d57e9747231eac818fa7",
|
| 121 |
+
"size": 38881
|
| 122 |
+
},
|
| 123 |
+
"examples/observe-first/lumi-eggcracker-observe-first.pyz.sha256": {
|
| 124 |
+
"sha256": "4411f50b29e58f52a40c54f7a7d7a16729273deca89be9c8e1a00fa6c2d49b1a",
|
| 125 |
+
"size": 100
|
| 126 |
+
},
|
| 127 |
"examples/observe-first/partial-match.json": {
|
| 128 |
"sha256": "2c4ec5b4c8074225aaee5e9c41aa2535cd0d4e85a7ec243dcb71f996d08a0ee2",
|
| 129 |
"size": 315
|
|
|
|
| 209 |
"size": 4101
|
| 210 |
},
|
| 211 |
"index.html": {
|
| 212 |
+
"sha256": "0fed8adb502782875768dbb8d6a82afdd95ff3d762002977d4b2eff0189d5af5",
|
| 213 |
"size": 22790
|
| 214 |
},
|
| 215 |
"integrations/prometheus/eggcracker.rules.yml": {
|
|
|
|
| 260 |
"sha256": "2b21689c110c4c01a998cd10b014b22ad11957758dacb793e9fda5ccc9a782e8",
|
| 261 |
"size": 17005
|
| 262 |
},
|
| 263 |
+
"scripts/build_observe_first_zipapp.py": {
|
| 264 |
+
"sha256": "b57cbffdd1e6ec0d38742923849b55b36878d76eb9f91c1e35aaacc52ae770fb",
|
| 265 |
+
"size": 10122
|
| 266 |
+
},
|
| 267 |
"scripts/build_release.py": {
|
| 268 |
"sha256": "c3792b513b4f2811d31da7783331e7b918de243d46bd949467ff4fa11bb55746",
|
| 269 |
"size": 7625
|
|
|
|
| 740 |
"sha256": "146a10077b6e90a75971677e48b7030955f89f114aef85e7bb757bd0643c3550",
|
| 741 |
"size": 6990
|
| 742 |
},
|
| 743 |
+
"tests/test_observe_first_zipapp.py": {
|
| 744 |
+
"sha256": "5659f6c2392ed3274b035332e3579971ccc9be2397be939aea9e5bb6000d757c",
|
| 745 |
+
"size": 7486
|
| 746 |
+
},
|
| 747 |
"tests/test_offline_boundary.py": {
|
| 748 |
"sha256": "2138cae662b8d1a0f1b4cf7ae63ce0aef7ca887aa2d3cf684a6ef82ef46737d5",
|
| 749 |
"size": 9742
|
|
|
|
| 879 |
},
|
| 880 |
"schema": "noqt.huggingface_manifest.v1",
|
| 881 |
"source_repository": "https://github.com/noqt/Lumi-Eggcracker",
|
| 882 |
+
"source_revision": "592c8cbe7e8b6d8907cc52fae8436438d95b8127",
|
| 883 |
+
"source_url": "https://github.com/noqt/Lumi-Eggcracker/commit/592c8cbe7e8b6d8907cc52fae8436438d95b8127"
|
| 884 |
}
|
HUGGINGFACE_SYNC.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
{
|
| 2 |
"manifest": "HUGGINGFACE_MANIFEST.json",
|
| 3 |
-
"manifest_sha256": "
|
| 4 |
-
"mirrored_files":
|
| 5 |
"mode": "DERIVED_READ_ONLY_MIRROR",
|
| 6 |
"release_reference": {
|
| 7 |
"assets": [
|
|
@@ -65,7 +65,7 @@
|
|
| 65 |
},
|
| 66 |
"schema": "noqt.huggingface_sync.v1",
|
| 67 |
"source_repository": "https://github.com/noqt/Lumi-Eggcracker",
|
| 68 |
-
"source_revision": "
|
| 69 |
-
"source_url": "https://github.com/noqt/Lumi-Eggcracker/commit/
|
| 70 |
"target": "https://huggingface.co/spaces/noqt/eggcracker"
|
| 71 |
}
|
|
|
|
| 1 |
{
|
| 2 |
"manifest": "HUGGINGFACE_MANIFEST.json",
|
| 3 |
+
"manifest_sha256": "fe9cab4b55f8292aef0ecf3af75e078dfa157a76edcf3ee5112352d65ac2c848",
|
| 4 |
+
"mirrored_files": 204,
|
| 5 |
"mode": "DERIVED_READ_ONLY_MIRROR",
|
| 6 |
"release_reference": {
|
| 7 |
"assets": [
|
|
|
|
| 65 |
},
|
| 66 |
"schema": "noqt.huggingface_sync.v1",
|
| 67 |
"source_repository": "https://github.com/noqt/Lumi-Eggcracker",
|
| 68 |
+
"source_revision": "592c8cbe7e8b6d8907cc52fae8436438d95b8127",
|
| 69 |
+
"source_url": "https://github.com/noqt/Lumi-Eggcracker/commit/592c8cbe7e8b6d8907cc52fae8436438d95b8127",
|
| 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 |
-
> [`
|
| 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.
|
|
|
|
| 11 |
---
|
| 12 |
|
| 13 |
> Official noqt Hugging Face distribution, generated from GitHub commit
|
| 14 |
+
> [`592c8cbe7e8b`](https://github.com/noqt/Lumi-Eggcracker/commit/592c8cbe7e8b6d8907cc52fae8436438d95b8127). 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.
|
TRY_IT.md
CHANGED
|
@@ -5,20 +5,80 @@ don't need Linux, a GPU, a model download or a local installation.
|
|
| 5 |
|
| 6 |

|
| 7 |
|
| 8 |
-
##
|
| 9 |
|
| 10 |
-
|
| 11 |
-
It
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
```sh
|
| 18 |
PYTHONPATH=src python3 -m lumi_eggcracker.observe_first examples/observe-first/benign.json
|
| 19 |
PYTHONPATH=src python3 -m lumi_eggcracker.observe_first examples/observe-first/complete-match.json
|
| 20 |
PYTHONPATH=src python3 -m lumi_eggcracker.observe_first examples/observe-first/partial-match.json
|
| 21 |
-
# Add --explain-selection only when you want the inert profile-selection explanation.
|
| 22 |
PYTHONPATH=src python3 -m lumi_eggcracker.observe_first --explain-selection examples/observe-first/complete-match.json
|
| 23 |
```
|
| 24 |
|
|
@@ -29,21 +89,16 @@ $env:PYTHONPATH = "src"
|
|
| 29 |
python -m lumi_eggcracker.observe_first examples/observe-first/benign.json
|
| 30 |
python -m lumi_eggcracker.observe_first examples/observe-first/complete-match.json
|
| 31 |
python -m lumi_eggcracker.observe_first examples/observe-first/partial-match.json
|
| 32 |
-
# Add --explain-selection only when you want the inert profile-selection explanation.
|
| 33 |
python -m lumi_eggcracker.observe_first --explain-selection examples/observe-first/complete-match.json
|
| 34 |
```
|
| 35 |
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
or framework identity, topology, provenance, safety, native qualification or
|
| 44 |
-
authorization. Nothing in this source-preview usage claims publication.
|
| 45 |
-
The hosted proof below remains the supported disposable Linux demonstration of
|
| 46 |
-
the native containment mechanism.
|
| 47 |
|
| 48 |
## Start it with GitHub CLI
|
| 49 |
|
|
|
|
| 5 |
|
| 6 |

|
| 7 |
|
| 8 |
+
## Checkout-free source-only observe-first preview (unreleased)
|
| 9 |
|
| 10 |
+
This separate preview runs on Python 3.11 or newer from a downloaded zipapp.
|
| 11 |
+
It needs no Git checkout, package installation, or `PYTHONPATH`. Download the
|
| 12 |
+
zipapp, its adjacent checksum file, and the synthetic fixture files into one
|
| 13 |
+
directory. These links follow the current public `main` branch:
|
| 14 |
+
|
| 15 |
+
- [Zipapp](https://raw.githubusercontent.com/noqt/Lumi-Eggcracker/main/examples/observe-first/lumi-eggcracker-observe-first.pyz)
|
| 16 |
+
- [Zipapp SHA-256 file](https://raw.githubusercontent.com/noqt/Lumi-Eggcracker/main/examples/observe-first/lumi-eggcracker-observe-first.pyz.sha256)
|
| 17 |
+
- [Benign fixture](https://raw.githubusercontent.com/noqt/Lumi-Eggcracker/main/examples/observe-first/benign.json)
|
| 18 |
+
- [Complete-match fixture](https://raw.githubusercontent.com/noqt/Lumi-Eggcracker/main/examples/observe-first/complete-match.json)
|
| 19 |
+
- [Partial-match fixture](https://raw.githubusercontent.com/noqt/Lumi-Eggcracker/main/examples/observe-first/partial-match.json)
|
| 20 |
+
|
| 21 |
+
On macOS or Linux, download the files and verify the adjacent checksum with
|
| 22 |
+
`sha256sum`:
|
| 23 |
+
|
| 24 |
+
```sh
|
| 25 |
+
mkdir -p observe-first-preview && cd observe-first-preview
|
| 26 |
+
curl -fSLO https://raw.githubusercontent.com/noqt/Lumi-Eggcracker/main/examples/observe-first/lumi-eggcracker-observe-first.pyz
|
| 27 |
+
curl -fSLO https://raw.githubusercontent.com/noqt/Lumi-Eggcracker/main/examples/observe-first/lumi-eggcracker-observe-first.pyz.sha256
|
| 28 |
+
curl -fSLO https://raw.githubusercontent.com/noqt/Lumi-Eggcracker/main/examples/observe-first/benign.json
|
| 29 |
+
curl -fSLO https://raw.githubusercontent.com/noqt/Lumi-Eggcracker/main/examples/observe-first/complete-match.json
|
| 30 |
+
curl -fSLO https://raw.githubusercontent.com/noqt/Lumi-Eggcracker/main/examples/observe-first/partial-match.json
|
| 31 |
+
sha256sum -c lumi-eggcracker-observe-first.pyz.sha256
|
| 32 |
+
python3 --version
|
| 33 |
+
python3 lumi-eggcracker-observe-first.pyz benign.json
|
| 34 |
+
python3 lumi-eggcracker-observe-first.pyz complete-match.json
|
| 35 |
+
python3 lumi-eggcracker-observe-first.pyz partial-match.json
|
| 36 |
+
python3 lumi-eggcracker-observe-first.pyz --explain-selection complete-match.json
|
| 37 |
+
```
|
| 38 |
+
|
| 39 |
+
On Windows PowerShell, run the equivalent commands:
|
| 40 |
+
|
| 41 |
+
```powershell
|
| 42 |
+
$previewDir = Join-Path (Get-Location) "observe-first-preview"
|
| 43 |
+
New-Item -ItemType Directory -Path $previewDir -Force | Out-Null
|
| 44 |
+
Set-Location $previewDir
|
| 45 |
+
$baseUrl = "https://raw.githubusercontent.com/noqt/Lumi-Eggcracker/main/examples/observe-first"
|
| 46 |
+
Invoke-WebRequest "$baseUrl/lumi-eggcracker-observe-first.pyz" -OutFile "lumi-eggcracker-observe-first.pyz"
|
| 47 |
+
Invoke-WebRequest "$baseUrl/lumi-eggcracker-observe-first.pyz.sha256" -OutFile "lumi-eggcracker-observe-first.pyz.sha256"
|
| 48 |
+
Invoke-WebRequest "$baseUrl/benign.json" -OutFile "benign.json"
|
| 49 |
+
Invoke-WebRequest "$baseUrl/complete-match.json" -OutFile "complete-match.json"
|
| 50 |
+
Invoke-WebRequest "$baseUrl/partial-match.json" -OutFile "partial-match.json"
|
| 51 |
+
$checksumLine = (Get-Content "lumi-eggcracker-observe-first.pyz.sha256" -Raw).Trim()
|
| 52 |
+
$checksumMatch = [regex]::Match($checksumLine, '^([0-9a-f]{64}) lumi-eggcracker-observe-first\.pyz$')
|
| 53 |
+
if (-not $checksumMatch.Success) { throw "Checksum file format is invalid" }
|
| 54 |
+
$expectedHash = $checksumMatch.Groups[1].Value
|
| 55 |
+
$actualHash = (Get-FileHash "lumi-eggcracker-observe-first.pyz" -Algorithm SHA256).Hash.ToLowerInvariant()
|
| 56 |
+
if ($actualHash -cne $expectedHash) { throw "Zipapp checksum mismatch" }
|
| 57 |
+
python --version
|
| 58 |
+
python .\lumi-eggcracker-observe-first.pyz .\benign.json
|
| 59 |
+
python .\lumi-eggcracker-observe-first.pyz .\complete-match.json
|
| 60 |
+
python .\lumi-eggcracker-observe-first.pyz .\partial-match.json
|
| 61 |
+
python .\lumi-eggcracker-observe-first.pyz --explain-selection .\complete-match.json
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
The archive's `SOURCE-MANIFEST.json` records base source commit
|
| 65 |
+
`47b822ca5d1dcc753535a7c2fcb74aece7f9b73d` and SHA-256 values for every
|
| 66 |
+
included source member. The adjacent checksum detects a changed or incomplete
|
| 67 |
+
download; it is not a signature or independent authentication. The preview is
|
| 68 |
+
synthetic, quiescent and offline. It reads one bounded JSON fixture, prints a
|
| 69 |
+
deterministic `WOULD_ACT` or `NO_COMPLETE_MATCH` result, and performs no live
|
| 70 |
+
observation, approval, output-file write, or actuation. The optional
|
| 71 |
+
`--explain-selection` flag prints the inert catalogue-selection explanation.
|
| 72 |
+
This source preview is unreleased, outside signed v1.0.10, and not
|
| 73 |
+
native-qualified. A non-match is not a safety result.
|
| 74 |
+
|
| 75 |
+
If you already have a source checkout, the same preview can also be run from
|
| 76 |
+
its `src` directory without creating the zipapp:
|
| 77 |
|
| 78 |
```sh
|
| 79 |
PYTHONPATH=src python3 -m lumi_eggcracker.observe_first examples/observe-first/benign.json
|
| 80 |
PYTHONPATH=src python3 -m lumi_eggcracker.observe_first examples/observe-first/complete-match.json
|
| 81 |
PYTHONPATH=src python3 -m lumi_eggcracker.observe_first examples/observe-first/partial-match.json
|
|
|
|
| 82 |
PYTHONPATH=src python3 -m lumi_eggcracker.observe_first --explain-selection examples/observe-first/complete-match.json
|
| 83 |
```
|
| 84 |
|
|
|
|
| 89 |
python -m lumi_eggcracker.observe_first examples/observe-first/benign.json
|
| 90 |
python -m lumi_eggcracker.observe_first examples/observe-first/complete-match.json
|
| 91 |
python -m lumi_eggcracker.observe_first examples/observe-first/partial-match.json
|
|
|
|
| 92 |
python -m lumi_eggcracker.observe_first --explain-selection examples/observe-first/complete-match.json
|
| 93 |
```
|
| 94 |
|
| 95 |
+
For either entry point, the partial fixture reports catalogue requirements
|
| 96 |
+
with supplied and missing evidence. Unknown or wrong-group identifiers are
|
| 97 |
+
rejected before normal output. The selection explanation names complete
|
| 98 |
+
catalogue profiles and the maintained first-complete selection rule only; it
|
| 99 |
+
does not establish true workload or framework identity, topology, provenance,
|
| 100 |
+
safety, native qualification or authorization. Nothing in this source-preview
|
| 101 |
+
usage claims publication.
|
|
|
|
|
|
|
|
|
|
|
|
|
| 102 |
|
| 103 |
## Start it with GitHub CLI
|
| 104 |
|
examples/observe-first/lumi-eggcracker-observe-first.pyz
ADDED
|
Binary file (38.9 kB). View file
|
|
|
examples/observe-first/lumi-eggcracker-observe-first.pyz.sha256
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
2cc33f9b61eb22e0b456ad37c7938dd51ff9a74b7950d57e9747231eac818fa7 lumi-eggcracker-observe-first.pyz
|
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="
|
| 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 ·
|
| 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="592c8cbe7e8b6d8907cc52fae8436438d95b8127">
|
| 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 · 592c8cbe7e8b</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/build_observe_first_zipapp.py
ADDED
|
@@ -0,0 +1,287 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Build a deterministic source-only observe-first zipapp."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import argparse
|
| 6 |
+
import hashlib
|
| 7 |
+
import io
|
| 8 |
+
import json
|
| 9 |
+
import os
|
| 10 |
+
import stat
|
| 11 |
+
import sys
|
| 12 |
+
import zipfile
|
| 13 |
+
from pathlib import Path
|
| 14 |
+
|
| 15 |
+
ROOT = Path(__file__).resolve().parents[1]
|
| 16 |
+
SOURCE_COMMIT = "47b822ca5d1dcc753535a7c2fcb74aece7f9b73d"
|
| 17 |
+
MAIN_MODULE = (
|
| 18 |
+
b"from lumi_eggcracker.observe_first import main\n"
|
| 19 |
+
b"raise SystemExit(main())\n"
|
| 20 |
+
)
|
| 21 |
+
ZIP_TIMESTAMP = (1980, 1, 1, 0, 0, 0)
|
| 22 |
+
ZIP_MODE = stat.S_IFREG | 0o644
|
| 23 |
+
MAX_SOURCE_BYTES = 8 * 1024 * 1024
|
| 24 |
+
|
| 25 |
+
SOURCE_INPUTS = (
|
| 26 |
+
("LICENSE", "LICENSE", "50e6751797c50dedd75ef1b8a0d9e42f5f8472e9fbce91f34718e9f97b0c780a"),
|
| 27 |
+
(
|
| 28 |
+
"src/lumi_eggcracker/__init__.py",
|
| 29 |
+
"lumi_eggcracker/__init__.py",
|
| 30 |
+
"8ca0bc0b310bfdfad676471477e28fe30d6311fef2c1360dc67a2c530e2acf34",
|
| 31 |
+
),
|
| 32 |
+
(
|
| 33 |
+
"src/lumi_eggcracker/observe_first.py",
|
| 34 |
+
"lumi_eggcracker/observe_first.py",
|
| 35 |
+
"428997c394c5fc853e0fe5cce82b1c3eae2d09b2b72c27f35bea3e1ff9be2152",
|
| 36 |
+
),
|
| 37 |
+
(
|
| 38 |
+
"src/lumi_eggcracker/detectors.py",
|
| 39 |
+
"lumi_eggcracker/detectors.py",
|
| 40 |
+
"d2f0485dbac785dce2bb5bcef451ddcb49fb5200f03e13b19acdcada3581bab7",
|
| 41 |
+
),
|
| 42 |
+
(
|
| 43 |
+
"src/lumi_eggcracker/jsonio.py",
|
| 44 |
+
"lumi_eggcracker/jsonio.py",
|
| 45 |
+
"8d4955af0399dd478add5e50c2c2edc9f100ebeec49223d50c13280aef85dc15",
|
| 46 |
+
),
|
| 47 |
+
(
|
| 48 |
+
"src/lumi_eggcracker/detector_catalogue.json",
|
| 49 |
+
"lumi_eggcracker/detector_catalogue.json",
|
| 50 |
+
"e0556219f7012b0657366af84804a1f3b5874d9f281a1341b4fa8ae819962c6d",
|
| 51 |
+
),
|
| 52 |
+
)
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
class BuildError(Exception):
|
| 56 |
+
"""The requested source or output path is not safe for this build."""
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def _is_reparse(metadata: os.stat_result) -> bool:
|
| 60 |
+
reparse_flag = getattr(stat, "FILE_ATTRIBUTE_REPARSE_POINT", 0x400)
|
| 61 |
+
return bool(getattr(metadata, "st_file_attributes", 0) & reparse_flag)
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def _is_safe_regular(metadata: os.stat_result) -> bool:
|
| 65 |
+
return (
|
| 66 |
+
stat.S_ISREG(metadata.st_mode)
|
| 67 |
+
and not stat.S_ISLNK(metadata.st_mode)
|
| 68 |
+
and not _is_reparse(metadata)
|
| 69 |
+
)
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
def _identity(metadata: os.stat_result) -> tuple[int, ...]:
|
| 73 |
+
return (
|
| 74 |
+
stat.S_IFMT(metadata.st_mode),
|
| 75 |
+
metadata.st_dev,
|
| 76 |
+
metadata.st_ino,
|
| 77 |
+
metadata.st_size,
|
| 78 |
+
metadata.st_mtime_ns,
|
| 79 |
+
)
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
def _safe_directory_chain(directory: Path) -> Path:
|
| 83 |
+
absolute = Path(os.path.abspath(os.fspath(directory)))
|
| 84 |
+
chain = list(reversed((absolute, *absolute.parents)))
|
| 85 |
+
for component in chain:
|
| 86 |
+
try:
|
| 87 |
+
metadata = component.lstat()
|
| 88 |
+
except OSError as error:
|
| 89 |
+
raise BuildError("an input or output parent cannot be inspected") from error
|
| 90 |
+
if (
|
| 91 |
+
stat.S_ISLNK(metadata.st_mode)
|
| 92 |
+
or _is_reparse(metadata)
|
| 93 |
+
or not stat.S_ISDIR(metadata.st_mode)
|
| 94 |
+
):
|
| 95 |
+
raise BuildError("input and output parents must be real directories")
|
| 96 |
+
return absolute
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
def _read_regular_file(path: Path) -> bytes:
|
| 100 |
+
_safe_directory_chain(path.parent)
|
| 101 |
+
try:
|
| 102 |
+
before = path.lstat()
|
| 103 |
+
except OSError as error:
|
| 104 |
+
raise BuildError("a required source file cannot be inspected") from error
|
| 105 |
+
if not _is_safe_regular(before) or not 1 <= before.st_size <= MAX_SOURCE_BYTES:
|
| 106 |
+
raise BuildError("a required source file is not a bounded regular file")
|
| 107 |
+
|
| 108 |
+
flags = os.O_RDONLY | getattr(os, "O_BINARY", 0) | getattr(os, "O_NOFOLLOW", 0)
|
| 109 |
+
try:
|
| 110 |
+
descriptor = os.open(path, flags)
|
| 111 |
+
except OSError as error:
|
| 112 |
+
raise BuildError("a required source file cannot be opened safely") from error
|
| 113 |
+
|
| 114 |
+
try:
|
| 115 |
+
opened = os.fstat(descriptor)
|
| 116 |
+
if not _is_safe_regular(opened) or _identity(opened) != _identity(before):
|
| 117 |
+
raise BuildError("a source file changed while being opened")
|
| 118 |
+
chunks: list[bytes] = []
|
| 119 |
+
total = 0
|
| 120 |
+
while True:
|
| 121 |
+
chunk = os.read(descriptor, min(64 * 1024, MAX_SOURCE_BYTES + 1 - total))
|
| 122 |
+
if not chunk:
|
| 123 |
+
break
|
| 124 |
+
chunks.append(chunk)
|
| 125 |
+
total += len(chunk)
|
| 126 |
+
if total > MAX_SOURCE_BYTES:
|
| 127 |
+
raise BuildError("a required source file exceeds the size bound")
|
| 128 |
+
after_open = os.fstat(descriptor)
|
| 129 |
+
after_path = path.lstat()
|
| 130 |
+
if (
|
| 131 |
+
not _is_safe_regular(after_open)
|
| 132 |
+
or not _is_safe_regular(after_path)
|
| 133 |
+
or _identity(opened) != _identity(after_open)
|
| 134 |
+
or _identity(before) != _identity(after_path)
|
| 135 |
+
or total != after_path.st_size
|
| 136 |
+
):
|
| 137 |
+
raise BuildError("a source file changed while being read")
|
| 138 |
+
return b"".join(chunks)
|
| 139 |
+
except OSError as error:
|
| 140 |
+
raise BuildError("a required source file cannot be read safely") from error
|
| 141 |
+
finally:
|
| 142 |
+
os.close(descriptor)
|
| 143 |
+
|
| 144 |
+
|
| 145 |
+
def _canonical_json(value: object) -> bytes:
|
| 146 |
+
encoded = json.dumps(value, sort_keys=True, separators=(",", ":"), ensure_ascii=True)
|
| 147 |
+
return f"{encoded}\n".encode()
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
def _source_members() -> dict[str, bytes]:
|
| 151 |
+
members = {"__main__.py": MAIN_MODULE}
|
| 152 |
+
for source_name, archive_name, expected_digest in SOURCE_INPUTS:
|
| 153 |
+
data = _read_regular_file(ROOT / source_name)
|
| 154 |
+
actual_digest = hashlib.sha256(data).hexdigest()
|
| 155 |
+
if actual_digest != expected_digest:
|
| 156 |
+
raise BuildError(f"source identity mismatch for {source_name}")
|
| 157 |
+
members[archive_name] = data
|
| 158 |
+
|
| 159 |
+
manifest = {
|
| 160 |
+
"base_commit": SOURCE_COMMIT,
|
| 161 |
+
"members": [
|
| 162 |
+
{"path": name, "sha256": hashlib.sha256(data).hexdigest()}
|
| 163 |
+
for name, data in sorted(members.items())
|
| 164 |
+
],
|
| 165 |
+
"schema_version": "lumi-eggcracker.observe-first-source-manifest.v1",
|
| 166 |
+
}
|
| 167 |
+
members["SOURCE-MANIFEST.json"] = _canonical_json(manifest)
|
| 168 |
+
return members
|
| 169 |
+
|
| 170 |
+
|
| 171 |
+
def _archive_bytes(members: dict[str, bytes]) -> bytes:
|
| 172 |
+
output = io.BytesIO()
|
| 173 |
+
with zipfile.ZipFile(output, "w", compression=zipfile.ZIP_STORED) as archive:
|
| 174 |
+
archive.comment = b""
|
| 175 |
+
for name in sorted(members):
|
| 176 |
+
info = zipfile.ZipInfo(name, date_time=ZIP_TIMESTAMP)
|
| 177 |
+
info.compress_type = zipfile.ZIP_STORED
|
| 178 |
+
info.create_system = 3
|
| 179 |
+
info.external_attr = ZIP_MODE << 16
|
| 180 |
+
info.internal_attr = 0
|
| 181 |
+
info.flag_bits = 0
|
| 182 |
+
info.extra = b""
|
| 183 |
+
info.comment = b""
|
| 184 |
+
archive.writestr(info, members[name])
|
| 185 |
+
return output.getvalue()
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
def _absolute_output(path: Path, *, label: str, suffix: str) -> Path:
|
| 189 |
+
absolute = Path(os.path.abspath(os.fspath(path)))
|
| 190 |
+
if not absolute.name or absolute.suffix.lower() != suffix:
|
| 191 |
+
raise BuildError(f"{label} must have a {suffix} filename")
|
| 192 |
+
_safe_directory_chain(absolute.parent)
|
| 193 |
+
try:
|
| 194 |
+
absolute.lstat()
|
| 195 |
+
except FileNotFoundError:
|
| 196 |
+
return absolute
|
| 197 |
+
except OSError as error:
|
| 198 |
+
raise BuildError(f"{label} cannot be inspected") from error
|
| 199 |
+
raise BuildError(f"{label} must not already exist")
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
def _remove_if_owned(path: Path, identity: tuple[int, int]) -> None:
|
| 203 |
+
try:
|
| 204 |
+
metadata = path.lstat()
|
| 205 |
+
if (metadata.st_dev, metadata.st_ino) == identity:
|
| 206 |
+
path.unlink()
|
| 207 |
+
except OSError:
|
| 208 |
+
pass
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
def _write_new_file(path: Path, data: bytes) -> tuple[int, int]:
|
| 212 |
+
_safe_directory_chain(path.parent)
|
| 213 |
+
flags = os.O_WRONLY | os.O_CREAT | os.O_EXCL | getattr(os, "O_BINARY", 0)
|
| 214 |
+
try:
|
| 215 |
+
descriptor = os.open(path, flags, 0o644)
|
| 216 |
+
except OSError as error:
|
| 217 |
+
raise BuildError("an output could not be created without overwriting") from error
|
| 218 |
+
|
| 219 |
+
opened = os.fstat(descriptor)
|
| 220 |
+
identity = (opened.st_dev, opened.st_ino)
|
| 221 |
+
try:
|
| 222 |
+
view = memoryview(data)
|
| 223 |
+
while view:
|
| 224 |
+
written = os.write(descriptor, view)
|
| 225 |
+
if written <= 0:
|
| 226 |
+
raise OSError("short output write")
|
| 227 |
+
view = view[written:]
|
| 228 |
+
os.fsync(descriptor)
|
| 229 |
+
return identity
|
| 230 |
+
except OSError as error:
|
| 231 |
+
_remove_if_owned(path, identity)
|
| 232 |
+
raise BuildError("an output could not be written completely") from error
|
| 233 |
+
finally:
|
| 234 |
+
os.close(descriptor)
|
| 235 |
+
|
| 236 |
+
|
| 237 |
+
def _build(output: Path, checksum: Path) -> None:
|
| 238 |
+
output = _absolute_output(output, label="zipapp output", suffix=".pyz")
|
| 239 |
+
checksum = _absolute_output(checksum, label="checksum output", suffix=".sha256")
|
| 240 |
+
if os.path.normcase(os.fspath(output)) == os.path.normcase(os.fspath(checksum)):
|
| 241 |
+
raise BuildError("zipapp and checksum outputs must be different files")
|
| 242 |
+
|
| 243 |
+
for source_name, _, _ in SOURCE_INPUTS:
|
| 244 |
+
source = Path(os.path.abspath(os.fspath(ROOT / source_name)))
|
| 245 |
+
if os.path.normcase(os.fspath(source)) in {
|
| 246 |
+
os.path.normcase(os.fspath(output)),
|
| 247 |
+
os.path.normcase(os.fspath(checksum)),
|
| 248 |
+
}:
|
| 249 |
+
raise BuildError("an output path overlaps a source input")
|
| 250 |
+
|
| 251 |
+
archive_data = _archive_bytes(_source_members())
|
| 252 |
+
archive_digest = hashlib.sha256(archive_data).hexdigest()
|
| 253 |
+
checksum_data = f"{archive_digest} {output.name}\n".encode("ascii")
|
| 254 |
+
created: list[tuple[Path, tuple[int, int]]] = []
|
| 255 |
+
try:
|
| 256 |
+
created.append((output, _write_new_file(output, archive_data)))
|
| 257 |
+
created.append((checksum, _write_new_file(checksum, checksum_data)))
|
| 258 |
+
except BuildError:
|
| 259 |
+
for path, identity in reversed(created):
|
| 260 |
+
_remove_if_owned(path, identity)
|
| 261 |
+
raise
|
| 262 |
+
|
| 263 |
+
|
| 264 |
+
def main() -> int:
|
| 265 |
+
parser = argparse.ArgumentParser(description=__doc__)
|
| 266 |
+
parser.add_argument("--output", required=True, type=Path, help="new .pyz output path")
|
| 267 |
+
parser.add_argument(
|
| 268 |
+
"--checksum",
|
| 269 |
+
type=Path,
|
| 270 |
+
help="new checksum path (default: adjacent <output>.sha256)",
|
| 271 |
+
)
|
| 272 |
+
args = parser.parse_args()
|
| 273 |
+
output = args.output
|
| 274 |
+
checksum = args.checksum or Path(f"{output}.sha256")
|
| 275 |
+
try:
|
| 276 |
+
_build(output, checksum)
|
| 277 |
+
except BuildError as error:
|
| 278 |
+
print(f"observe-first zipapp build refused: {error}", file=sys.stderr)
|
| 279 |
+
return 2
|
| 280 |
+
except OSError:
|
| 281 |
+
print("observe-first zipapp build refused: a file operation failed", file=sys.stderr)
|
| 282 |
+
return 2
|
| 283 |
+
return 0
|
| 284 |
+
|
| 285 |
+
|
| 286 |
+
if __name__ == "__main__":
|
| 287 |
+
raise SystemExit(main())
|
tests/test_observe_first_zipapp.py
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import hashlib
|
| 4 |
+
import json
|
| 5 |
+
import os
|
| 6 |
+
import stat
|
| 7 |
+
import subprocess
|
| 8 |
+
import sys
|
| 9 |
+
import tempfile
|
| 10 |
+
import zipfile
|
| 11 |
+
from pathlib import Path
|
| 12 |
+
|
| 13 |
+
ROOT = Path(__file__).resolve().parents[1]
|
| 14 |
+
BUILDER = ROOT / "scripts" / "build_observe_first_zipapp.py"
|
| 15 |
+
SOURCE_COMMIT = "47b822ca5d1dcc753535a7c2fcb74aece7f9b73d"
|
| 16 |
+
MAIN_MODULE = (
|
| 17 |
+
b"from lumi_eggcracker.observe_first import main\n"
|
| 18 |
+
b"raise SystemExit(main())\n"
|
| 19 |
+
)
|
| 20 |
+
PINNED_HASHES = {
|
| 21 |
+
"LICENSE": "50e6751797c50dedd75ef1b8a0d9e42f5f8472e9fbce91f34718e9f97b0c780a",
|
| 22 |
+
"lumi_eggcracker/__init__.py": (
|
| 23 |
+
"8ca0bc0b310bfdfad676471477e28fe30d6311fef2c1360dc67a2c530e2acf34"
|
| 24 |
+
),
|
| 25 |
+
"lumi_eggcracker/observe_first.py": (
|
| 26 |
+
"428997c394c5fc853e0fe5cce82b1c3eae2d09b2b72c27f35bea3e1ff9be2152"
|
| 27 |
+
),
|
| 28 |
+
"lumi_eggcracker/detectors.py": (
|
| 29 |
+
"d2f0485dbac785dce2bb5bcef451ddcb49fb5200f03e13b19acdcada3581bab7"
|
| 30 |
+
),
|
| 31 |
+
"lumi_eggcracker/jsonio.py": (
|
| 32 |
+
"8d4955af0399dd478add5e50c2c2edc9f100ebeec49223d50c13280aef85dc15"
|
| 33 |
+
),
|
| 34 |
+
"lumi_eggcracker/detector_catalogue.json": (
|
| 35 |
+
"e0556219f7012b0657366af84804a1f3b5874d9f281a1341b4fa8ae819962c6d"
|
| 36 |
+
),
|
| 37 |
+
}
|
| 38 |
+
MANIFEST_NAME = "SOURCE-MANIFEST.json"
|
| 39 |
+
MANIFEST_SCHEMA = "lumi-eggcracker.observe-first-source-manifest.v1"
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
def _run_builder(
|
| 43 |
+
output: Path, *, checksum: Path | None = None
|
| 44 |
+
) -> subprocess.CompletedProcess[bytes]:
|
| 45 |
+
command = [sys.executable, str(BUILDER), "--output", str(output)]
|
| 46 |
+
if checksum is not None:
|
| 47 |
+
command.extend(["--checksum", str(checksum)])
|
| 48 |
+
environment = os.environ.copy()
|
| 49 |
+
environment.pop("PYTHONPATH", None)
|
| 50 |
+
environment["PYTHONDONTWRITEBYTECODE"] = "1"
|
| 51 |
+
return subprocess.run(command, capture_output=True, cwd=ROOT, env=environment, check=False)
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def _reference_environment() -> dict[str, str]:
|
| 55 |
+
environment = os.environ.copy()
|
| 56 |
+
environment.pop("PYTHONPATH", None)
|
| 57 |
+
environment["PYTHONPATH"] = str(ROOT / "src")
|
| 58 |
+
environment["PYTHONDONTWRITEBYTECODE"] = "1"
|
| 59 |
+
return environment
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
def _expected_members() -> dict[str, str]:
|
| 63 |
+
return {**PINNED_HASHES, "__main__.py": hashlib.sha256(MAIN_MODULE).hexdigest()}
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def test_build_is_deterministic_and_binds_exact_source_members() -> None:
|
| 67 |
+
with tempfile.TemporaryDirectory(prefix="observe-first-zipapp-build-") as raw:
|
| 68 |
+
directory = Path(raw)
|
| 69 |
+
first = directory / "first.pyz"
|
| 70 |
+
second = directory / "second.pyz"
|
| 71 |
+
second_checksum = directory / "second-checksum.sha256"
|
| 72 |
+
first_result = _run_builder(first)
|
| 73 |
+
second_result = _run_builder(second, checksum=second_checksum)
|
| 74 |
+
|
| 75 |
+
assert first_result.returncode == 0, first_result.stderr.decode("utf-8", errors="replace")
|
| 76 |
+
assert second_result.returncode == 0, second_result.stderr.decode("utf-8", errors="replace")
|
| 77 |
+
assert first.read_bytes() == second.read_bytes()
|
| 78 |
+
|
| 79 |
+
first_checksum = Path(f"{first}.sha256")
|
| 80 |
+
first_digest = hashlib.sha256(first.read_bytes()).hexdigest()
|
| 81 |
+
second_digest = hashlib.sha256(second.read_bytes()).hexdigest()
|
| 82 |
+
assert first_checksum.read_text(encoding="ascii") == f"{first_digest} {first.name}\n"
|
| 83 |
+
assert second_checksum.read_text(encoding="ascii") == f"{second_digest} {second.name}\n"
|
| 84 |
+
|
| 85 |
+
expected_members = _expected_members()
|
| 86 |
+
with zipfile.ZipFile(first) as archive:
|
| 87 |
+
infos = archive.infolist()
|
| 88 |
+
names = [item.filename for item in infos]
|
| 89 |
+
assert names == sorted(names)
|
| 90 |
+
assert set(names) == {*expected_members, MANIFEST_NAME}
|
| 91 |
+
for info in infos:
|
| 92 |
+
assert info.date_time == (1980, 1, 1, 0, 0, 0)
|
| 93 |
+
assert info.create_system == 3
|
| 94 |
+
assert info.compress_type == zipfile.ZIP_STORED
|
| 95 |
+
assert stat.S_IFMT(info.external_attr >> 16) == stat.S_IFREG
|
| 96 |
+
assert stat.S_IMODE(info.external_attr >> 16) == 0o644
|
| 97 |
+
|
| 98 |
+
for name, expected_digest in expected_members.items():
|
| 99 |
+
member = archive.read(name)
|
| 100 |
+
assert hashlib.sha256(member).hexdigest() == expected_digest
|
| 101 |
+
assert archive.read("__main__.py") == MAIN_MODULE
|
| 102 |
+
|
| 103 |
+
expected_manifest = {
|
| 104 |
+
"base_commit": SOURCE_COMMIT,
|
| 105 |
+
"members": [
|
| 106 |
+
{"path": name, "sha256": expected_members[name]}
|
| 107 |
+
for name in sorted(expected_members)
|
| 108 |
+
],
|
| 109 |
+
"schema_version": MANIFEST_SCHEMA,
|
| 110 |
+
}
|
| 111 |
+
manifest_bytes = archive.read(MANIFEST_NAME)
|
| 112 |
+
assert manifest_bytes == (
|
| 113 |
+
json.dumps(expected_manifest, sort_keys=True, separators=(",", ":")) + "\n"
|
| 114 |
+
).encode("utf-8")
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
def test_zipapp_matches_pinned_source_module_and_rejects_malformed_input() -> None:
|
| 118 |
+
with tempfile.TemporaryDirectory(prefix="observe-first-zipapp-run-") as raw:
|
| 119 |
+
directory = Path(raw)
|
| 120 |
+
archive_path = directory / "observe-first.pyz"
|
| 121 |
+
result = _run_builder(archive_path)
|
| 122 |
+
assert result.returncode == 0, result.stderr.decode("utf-8", errors="replace")
|
| 123 |
+
|
| 124 |
+
run_directory = directory / "clean-cwd"
|
| 125 |
+
run_directory.mkdir()
|
| 126 |
+
archive_environment = os.environ.copy()
|
| 127 |
+
archive_environment.pop("PYTHONPATH", None)
|
| 128 |
+
archive_environment["PYTHONDONTWRITEBYTECODE"] = "1"
|
| 129 |
+
reference_environment = _reference_environment()
|
| 130 |
+
|
| 131 |
+
cases = (
|
| 132 |
+
("benign.json", ()),
|
| 133 |
+
("complete-match.json", ()),
|
| 134 |
+
("partial-match.json", ()),
|
| 135 |
+
("complete-match.json", ("--explain-selection",)),
|
| 136 |
+
)
|
| 137 |
+
for fixture_name, flags in cases:
|
| 138 |
+
fixture = ROOT / "examples" / "observe-first" / fixture_name
|
| 139 |
+
archive_command = [sys.executable, str(archive_path), *flags, str(fixture)]
|
| 140 |
+
archive_result = subprocess.run(
|
| 141 |
+
archive_command,
|
| 142 |
+
capture_output=True,
|
| 143 |
+
cwd=run_directory,
|
| 144 |
+
env=archive_environment,
|
| 145 |
+
check=False,
|
| 146 |
+
)
|
| 147 |
+
source_command = [
|
| 148 |
+
sys.executable,
|
| 149 |
+
"-m",
|
| 150 |
+
"lumi_eggcracker.observe_first",
|
| 151 |
+
*flags,
|
| 152 |
+
str(fixture),
|
| 153 |
+
]
|
| 154 |
+
source_result = subprocess.run(
|
| 155 |
+
source_command,
|
| 156 |
+
capture_output=True,
|
| 157 |
+
cwd=run_directory,
|
| 158 |
+
env=reference_environment,
|
| 159 |
+
check=False,
|
| 160 |
+
)
|
| 161 |
+
assert archive_result.returncode == source_result.returncode
|
| 162 |
+
assert archive_result.returncode == 0, archive_result.stderr.decode(
|
| 163 |
+
"utf-8", errors="replace"
|
| 164 |
+
)
|
| 165 |
+
assert source_result.returncode == 0, source_result.stderr.decode(
|
| 166 |
+
"utf-8", errors="replace"
|
| 167 |
+
)
|
| 168 |
+
assert archive_result.stderr == source_result.stderr
|
| 169 |
+
assert json.loads(archive_result.stdout) == json.loads(source_result.stdout)
|
| 170 |
+
assert archive_result.stdout == source_result.stdout
|
| 171 |
+
|
| 172 |
+
malformed = run_directory / "malformed.json"
|
| 173 |
+
malformed.write_bytes(b'{"schema_version":')
|
| 174 |
+
malformed_result = subprocess.run(
|
| 175 |
+
[sys.executable, str(archive_path), str(malformed)],
|
| 176 |
+
capture_output=True,
|
| 177 |
+
cwd=run_directory,
|
| 178 |
+
env=archive_environment,
|
| 179 |
+
check=False,
|
| 180 |
+
)
|
| 181 |
+
assert malformed_result.returncode == 2
|
| 182 |
+
assert malformed_result.stdout == b""
|
| 183 |
+
assert b"Traceback" not in malformed_result.stderr
|