field_ios

In-the-field app for Radroots on iOS
git clone https://radroots.dev/git/field_ios.git
Log | Files | Refs | README | LICENSE

commit 83ae86b76d2cfa3eae43913e47f2670357d8eeba
parent 8dba1a4ce547d533481d022335c19edfccfe516e
Author: triesap <tyson@radroots.org>
Date:   Tue,  6 Oct 2026 12:10:44 +0000

tera: Bind native builds to captured compiler and SDK inputs

- Reject unsupported inherited native overrides before capture or execution.
- Fence captured tools and SDKs and key caches by all producer records.
- Bind Kotlin consumption to installed source records and native bytes.
- Produce bounded genuine test callbacks with verified regression coverage.

Diffstat:
MMakefile | 8++++++--
MTeraFFI/producer.toml | 7+++++++
MTeraFFI/provenance.json | 50+++++++++++++++++++++++++-------------------------
MTeraFFI/source.lock | 4++--
MTeraFFI/source/aarch64-apple-darwin.json | 318++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------
MTeraFFI/source/aarch64-apple-ios-sim.json | 320++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------
MTeraFFI/source/aarch64-apple-ios.json | 320++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---------
Mrelease/provenance.json | 4++--
Mscripts/ffi_build.py | 115+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------
Ascripts/ffi_native.py | 506+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mscripts/ffi_provenance.py | 41+++++++++++++++++++++++++++++++++++------
Mscripts/ffi_source.py | 39++++++++++++++++++++++++++++++++++++---
Mscripts/kotlin_smoke.py | 21+++++++++++++++++++--
Mscripts/swift-quality.sh | 5+++++
Mscripts/test_ffi_artifacts.py | 60++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ascripts/test_ffi_native.py | 773+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ascripts/test_ffi_native_cache.py | 289++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mscripts/test_ffi_provenance.py | 12++++++++++++
Mscripts/test_kotlin_smoke.py | 215+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ascripts/test_unittest_report.py | 726+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Ascripts/unittest_report.py | 612+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mscripts/verify-package-contract.sh | 2++
22 files changed, 4274 insertions(+), 173 deletions(-)

diff --git a/Makefile b/Makefile @@ -12,7 +12,7 @@ UI_TEST_SELECTOR ?= .PHONY: all doctor bootstrap persona-verifier-bootstrap ffi-bootstrap artifact-check package-contract-check \ ffi-source-write ffi-source-check \ ffi-candidate-build ffi-candidate-check \ - swift-quality maintainability-check \ + swift-quality native-cache-check maintainability-check \ linux-shared-rust kotlin-smoke kotlin-smoke-bootstrap \ package-resolve package-build package-test project xcodegen xcode-resolve \ xcode-build-debug xcode-build-release unit-test ui-test api-snapshot-write \ @@ -50,6 +50,10 @@ package-contract-check: doctor swift-quality: doctor cargo extbuild run -- scripts/swift-quality.sh +native-cache-check: doctor + cargo extbuild run -- uv run --project scripts/persona-verifier --offline --frozen \ + python -m unittest -v scripts.test_ffi_native_cache + maintainability-check: doctor cargo extbuild run -- uv run --offline --project scripts/persona-verifier \ python scripts/maintainability_ratchet.py verify @@ -104,7 +108,7 @@ release-evidence-write: doctor release-preflight: artifact-check package-contract-check cargo extbuild run -- scripts/release-preflight.sh -verify: swift-quality linux-shared-rust kotlin-smoke artifact-check package-contract-check package-build package-test \ +verify: swift-quality native-cache-check linux-shared-rust kotlin-smoke artifact-check package-contract-check package-build package-test \ xcode-build-debug xcode-build-release unit-test ui-test api-snapshot-check clean: doctor diff --git a/TeraFFI/producer.toml b/TeraFFI/producer.toml @@ -22,6 +22,7 @@ features = [] [build] rust_version = "1.97.1" profile = "release" +native_input_policy = "closed_apple_c_v1" ios_deployment_target = "18.0" rust_flags = [ "--remap-path-prefix={producer_root}=/tera", @@ -34,3 +35,9 @@ host_dylib_install_name = "@rpath/libtera_ffi.dylib" host_linker_reproducible = true host_oso_prefix = "{extbuild_root}" targets = ["aarch64-apple-ios", "aarch64-apple-ios-sim", "aarch64-apple-darwin"] + +[native] +maximum_sdk_nodes = 100000 +maximum_sdk_aggregate_bytes = 2000000000 +maximum_inspection_seconds = 120 +stream_chunk_bytes = 65536 diff --git a/TeraFFI/provenance.json b/TeraFFI/provenance.json @@ -22,9 +22,9 @@ "sha256": "3ed9b7ece2f86e5b5d1ddc6ecbb97deb49c46ca2ea91a930eaec1b580232345c" }, { - "bytes": 79611288, + "bytes": 79611168, "path": "TeraFFI.xcframework/ios-arm64-simulator/libtera_ffi.a", - "sha256": "ef8b9167db554e775cbff57362441381339018fceae0c35173ffb0485265bf0b" + "sha256": "6c639ff57ef4a6fc03d45d50948f7387cd1b4eaaff95a4d4d99c711080df7574" }, { "bytes": 105627, @@ -37,9 +37,9 @@ "sha256": "3ed9b7ece2f86e5b5d1ddc6ecbb97deb49c46ca2ea91a930eaec1b580232345c" }, { - "bytes": 79645856, + "bytes": 79645728, "path": "TeraFFI.xcframework/ios-arm64/libtera_ffi.a", - "sha256": "e1c4926a9eef1db20cf5e0b7c17c6afae45773d88f7743502ccb5dcb4eab26ae" + "sha256": "e714580021c9aac76a0b84f2bb4719aece857eda99bf98050e1e1f0039055226" }, { "bytes": 64990, @@ -82,29 +82,29 @@ "sha256": "806c8175fa25676a1ad0b1b7f8da64309da2c5e686db4cd45dbbee21e543f115" }, { - "bytes": 79611288, + "bytes": 79611168, "path": "native/aarch64-apple-ios-sim/libtera_ffi.a", - "sha256": "ef8b9167db554e775cbff57362441381339018fceae0c35173ffb0485265bf0b" + "sha256": "6c639ff57ef4a6fc03d45d50948f7387cd1b4eaaff95a4d4d99c711080df7574" }, { - "bytes": 79645856, + "bytes": 79645728, "path": "native/aarch64-apple-ios/libtera_ffi.a", - "sha256": "e1c4926a9eef1db20cf5e0b7c17c6afae45773d88f7743502ccb5dcb4eab26ae" + "sha256": "e714580021c9aac76a0b84f2bb4719aece857eda99bf98050e1e1f0039055226" }, { - "bytes": 143532, + "bytes": 155993, "path": "source/aarch64-apple-darwin.json", - "sha256": "fe9af0ce2b11ed77d5f8f00379e26c2fa376871aaf3d3f683bdb2d8fe051008e" + "sha256": "db1575324f9dec716de0621208795074a839f45f0d6a39339d6c6348b124f3ff" }, { - "bytes": 143376, + "bytes": 155918, "path": "source/aarch64-apple-ios-sim.json", - "sha256": "d0f662ebb4f0dfb4bd4b42f32083dda85ca81b1a9635f7eb303e7542da3df0ab" + "sha256": "5e82aeb2cbf97c16f338987e41b87460d500b7acb28e1fe882ec0828520b0714" }, { - "bytes": 143372, + "bytes": 155888, "path": "source/aarch64-apple-ios.json", - "sha256": "62b104e618b8b08241cef5f9292588fb4e04988793029a5158929bfb65a66152" + "sha256": "2eb3787ccdff664543ad3a95a8e110503ce08e18e5faceb68ac3c0fa1bfb52dd" } ], "language": "swift", @@ -112,7 +112,7 @@ "schema": "radroots.artifact-manifest.v2", "source": { "repository": "https://github.com/radrootslabs/tera", - "tree": "16436eff2c5f2f69b6d2d767b1d0264bb9051992" + "tree": "a7f7ef68f86606405e16d5b51ecd57a8bdf02fd4" }, "source_records": { "aarch64-apple-darwin": "source/aarch64-apple-darwin.json", @@ -139,9 +139,9 @@ "sha256": "3ed9b7ece2f86e5b5d1ddc6ecbb97deb49c46ca2ea91a930eaec1b580232345c" }, { - "bytes": 79611288, + "bytes": 79611168, "path": "Tera/Frameworks/TeraFFI.xcframework/ios-arm64-simulator/libtera_ffi.a", - "sha256": "ef8b9167db554e775cbff57362441381339018fceae0c35173ffb0485265bf0b" + "sha256": "6c639ff57ef4a6fc03d45d50948f7387cd1b4eaaff95a4d4d99c711080df7574" }, { "bytes": 105627, @@ -154,9 +154,9 @@ "sha256": "3ed9b7ece2f86e5b5d1ddc6ecbb97deb49c46ca2ea91a930eaec1b580232345c" }, { - "bytes": 79645856, + "bytes": 79645728, "path": "Tera/Frameworks/TeraFFI.xcframework/ios-arm64/libtera_ffi.a", - "sha256": "e1c4926a9eef1db20cf5e0b7c17c6afae45773d88f7743502ccb5dcb4eab26ae" + "sha256": "e714580021c9aac76a0b84f2bb4719aece857eda99bf98050e1e1f0039055226" }, { "bytes": 807948, @@ -174,19 +174,19 @@ "sha256": "5d74060f97e52dad69ab7567c16d6b6b34acfab846f468450d89e2394a8a69d5" }, { - "bytes": 143532, + "bytes": 155993, "path": "TeraFFI/source/aarch64-apple-darwin.json", - "sha256": "fe9af0ce2b11ed77d5f8f00379e26c2fa376871aaf3d3f683bdb2d8fe051008e" + "sha256": "db1575324f9dec716de0621208795074a839f45f0d6a39339d6c6348b124f3ff" }, { - "bytes": 143376, + "bytes": 155918, "path": "TeraFFI/source/aarch64-apple-ios-sim.json", - "sha256": "d0f662ebb4f0dfb4bd4b42f32083dda85ca81b1a9635f7eb303e7542da3df0ab" + "sha256": "5e82aeb2cbf97c16f338987e41b87460d500b7acb28e1fe882ec0828520b0714" }, { - "bytes": 143372, + "bytes": 155888, "path": "TeraFFI/source/aarch64-apple-ios.json", - "sha256": "62b104e618b8b08241cef5f9292588fb4e04988793029a5158929bfb65a66152" + "sha256": "2eb3787ccdff664543ad3a95a8e110503ce08e18e5faceb68ac3c0fa1bfb52dd" } ], "schema": "tera.installed-native-artifacts.v1" diff --git a/TeraFFI/source.lock b/TeraFFI/source.lock @@ -1,7 +1,7 @@ schema = "tera.installed-source.v1" repository = "https://github.com/radrootslabs/tera" -source_tree = "16436eff2c5f2f69b6d2d767b1d0264bb9051992" -manifest_sha256 = "a24d7847393da41d7ae575e729e92a418d99401b937346df5e6c2afebebe2cb0" +source_tree = "a7f7ef68f86606405e16d5b51ecd57a8bdf02fd4" +manifest_sha256 = "78f1d4676995abec157170f19694169ac686b4c038da4640a5502d12ca638616" source_date_epoch = 1787871027 [foundation] diff --git a/TeraFFI/source/aarch64-apple-darwin.json b/TeraFFI/source/aarch64-apple-darwin.json @@ -369,6 +369,114 @@ ], "features": [], "ios_deployment_target": "18.0", + "native": { + "compiler_arguments": [ + "--no-default-config" + ], + "compiler_resources": { + "bytes": 83967222, + "nodes": 377, + "path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/21", + "sha256": "dd5989662272c61af2fb63d0eaf970f66d9c5a1f10ef3a8d481a2592f80578cf" + }, + "deployment": {}, + "developer_dir": "/Applications/Xcode.app/Contents/Developer", + "inherited": { + "generator_profile_overrides": { + "CARGO_PROFILE_DEV_DEBUG": "line-tables-only" + }, + "path_sha256": "e4bfec31ceb26bfa330c30b81c526b8429ba650cf8a92c77e5c3971924187a16" + }, + "inspection_limits": { + "maximum_inspection_seconds": 120, + "maximum_sdk_aggregate_bytes": 2000000000, + "maximum_sdk_nodes": 100000, + "stream_chunk_bytes": 65536 + }, + "linker_driver_arguments": [ + "--no-default-config", + "-fuse-ld=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" + ], + "policy": "closed_apple_c_v1", + "sdk": { + "bytes": 765532437, + "nodes": 49700, + "path": "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk", + "sha256": "20c43e843e92669de61c29972eb0b1cf18f67e5fa534822dd6d897bec1dc20f8" + }, + "sdk_build": "25F70", + "sdk_name": "macosx", + "sdk_version": "26.5", + "target": "aarch64-apple-darwin", + "tools": { + "archiver": { + "bytes": 73520, + "path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ar", + "resolved_path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ar", + "sha256": "e49ffad64ad1cee722540fc5ecb00a230fd8071680682c60d9c851029d20e814" + }, + "compiler": { + "bytes": 141373024, + "path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang", + "resolved_path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang", + "sha256": "7def90dd8829726686213a747fc5bff1583df933dae5edc55d755479e0bfe00a" + }, + "linker": { + "bytes": 2331792, + "path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld", + "resolved_path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld", + "sha256": "5897b275efd93b201b6df5832dd541262b3f20f290859ba78f2200a6a66ef38b" + }, + "ranlib": { + "bytes": 210800, + "path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib", + "resolved_path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool", + "sha256": "229eb9d8027953d2aee0590f983eed587d52bdd1ebc21114a62ce693f77b03f1" + }, + "swift": { + "bytes": 171036592, + "path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift", + "resolved_path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend", + "sha256": "2ed38571e92c0283091838c1649e27650ad9c99950288e883c7b2dc6c4ce89fb" + }, + "swift_format": { + "bytes": 8035472, + "path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-format", + "resolved_path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-format", + "sha256": "48317544bec55d5dee83e15738a342c0c31bf9c60273599f85601a8faea0016c" + }, + "swift_symbolgraph_extract": { + "bytes": 171036592, + "path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-symbolgraph-extract", + "resolved_path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend", + "sha256": "2ed38571e92c0283091838c1649e27650ad9c99950288e883c7b2dc6c4ce89fb" + }, + "swiftc": { + "bytes": 171036592, + "path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc", + "resolved_path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend", + "sha256": "2ed38571e92c0283091838c1649e27650ad9c99950288e883c7b2dc6c4ce89fb" + }, + "swiftformat": { + "bytes": 4700024, + "path": "/opt/homebrew/bin/swiftformat", + "resolved_path": "/opt/homebrew/Cellar/swiftformat/0.63.1/bin/swiftformat", + "sha256": "5495efaea582c21d93d344dfbfe3f05893b8bf3c99f7fd2962972c4a80caa685" + }, + "xcodebuild": { + "bytes": 100528, + "path": "/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild", + "resolved_path": "/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild", + "sha256": "d508f0e1901151843804e4af512d4587ad0e422039e43e14abf22792360ad3d4" + }, + "xcrun": { + "bytes": 117392, + "path": "/usr/bin/xcrun", + "resolved_path": "/usr/bin/xcrun", + "sha256": "a439970aea2b4e435eac6518ff62c97fd1c57d8c731974027ad211b515c7a7b8" + } + } + }, "package": "tera_ffi", "package_rust_flags": [ "-Clink-arg=-Wl,-install_name,@rpath/libtera_ffi.dylib", @@ -384,6 +492,10 @@ "rustc": "rustc 1.97.1 (8bab26f4f 2026-07-14)\nbinary: rustc\ncommit-hash: 8bab26f4f68e0e26f0bb7960be334d5b520ea452\ncommit-date: 2026-07-14\nhost: aarch64-apple-darwin\nrelease: 1.97.1\nLLVM version: 22.1.6", "source_date_epoch": 1787871027, "symbol_reader": "llvm-nm, compatible with GNU nm\nLLVM (http://llvm.org/):\n LLVM version 22.1.6-rust-1.97.1-stable\n Optimized build.", + "symbol_reader_identity": { + "bytes": 45024888, + "sha256": "35ce10ff99cd452e3767c4dfa7ed998a3265a960a3b393c307117f85dcb1f4e5" + }, "target": "aarch64-apple-darwin" }, "cargo_lock_sha256": "31aced473ddc097b2a3508b9247a336f8598b31dabdca320f10f9b720195424f", @@ -490,6 +602,114 @@ "zmij v1.0.23|" ], "features": [], + "native": { + "compiler_arguments": [ + "--no-default-config" + ], + "compiler_resources": { + "bytes": 83967222, + "nodes": 377, + "path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/21", + "sha256": "dd5989662272c61af2fb63d0eaf970f66d9c5a1f10ef3a8d481a2592f80578cf" + }, + "deployment": {}, + "developer_dir": "/Applications/Xcode.app/Contents/Developer", + "inherited": { + "generator_profile_overrides": { + "CARGO_PROFILE_DEV_DEBUG": "line-tables-only" + }, + "path_sha256": "e4bfec31ceb26bfa330c30b81c526b8429ba650cf8a92c77e5c3971924187a16" + }, + "inspection_limits": { + "maximum_inspection_seconds": 120, + "maximum_sdk_aggregate_bytes": 2000000000, + "maximum_sdk_nodes": 100000, + "stream_chunk_bytes": 65536 + }, + "linker_driver_arguments": [ + "--no-default-config", + "-fuse-ld=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" + ], + "policy": "closed_apple_c_v1", + "sdk": { + "bytes": 765532437, + "nodes": 49700, + "path": "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk", + "sha256": "20c43e843e92669de61c29972eb0b1cf18f67e5fa534822dd6d897bec1dc20f8" + }, + "sdk_build": "25F70", + "sdk_name": "macosx", + "sdk_version": "26.5", + "target": "aarch64-apple-darwin", + "tools": { + "archiver": { + "bytes": 73520, + "path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ar", + "resolved_path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ar", + "sha256": "e49ffad64ad1cee722540fc5ecb00a230fd8071680682c60d9c851029d20e814" + }, + "compiler": { + "bytes": 141373024, + "path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang", + "resolved_path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang", + "sha256": "7def90dd8829726686213a747fc5bff1583df933dae5edc55d755479e0bfe00a" + }, + "linker": { + "bytes": 2331792, + "path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld", + "resolved_path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld", + "sha256": "5897b275efd93b201b6df5832dd541262b3f20f290859ba78f2200a6a66ef38b" + }, + "ranlib": { + "bytes": 210800, + "path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib", + "resolved_path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool", + "sha256": "229eb9d8027953d2aee0590f983eed587d52bdd1ebc21114a62ce693f77b03f1" + }, + "swift": { + "bytes": 171036592, + "path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift", + "resolved_path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend", + "sha256": "2ed38571e92c0283091838c1649e27650ad9c99950288e883c7b2dc6c4ce89fb" + }, + "swift_format": { + "bytes": 8035472, + "path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-format", + "resolved_path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-format", + "sha256": "48317544bec55d5dee83e15738a342c0c31bf9c60273599f85601a8faea0016c" + }, + "swift_symbolgraph_extract": { + "bytes": 171036592, + "path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-symbolgraph-extract", + "resolved_path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend", + "sha256": "2ed38571e92c0283091838c1649e27650ad9c99950288e883c7b2dc6c4ce89fb" + }, + "swiftc": { + "bytes": 171036592, + "path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc", + "resolved_path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend", + "sha256": "2ed38571e92c0283091838c1649e27650ad9c99950288e883c7b2dc6c4ce89fb" + }, + "swiftformat": { + "bytes": 4700024, + "path": "/opt/homebrew/bin/swiftformat", + "resolved_path": "/opt/homebrew/Cellar/swiftformat/0.63.1/bin/swiftformat", + "sha256": "5495efaea582c21d93d344dfbfe3f05893b8bf3c99f7fd2962972c4a80caa685" + }, + "xcodebuild": { + "bytes": 100528, + "path": "/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild", + "resolved_path": "/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild", + "sha256": "d508f0e1901151843804e4af512d4587ad0e422039e43e14abf22792360ad3d4" + }, + "xcrun": { + "bytes": 117392, + "path": "/usr/bin/xcrun", + "resolved_path": "/usr/bin/xcrun", + "sha256": "a439970aea2b4e435eac6518ff62c97fd1c57d8c731974027ad211b515c7a7b8" + } + } + }, "package": "tera_bindgen", "profile": "dev", "profile_overrides": { @@ -514,10 +734,10 @@ "sha256": "5382cbc1cb6314cd0bd45be4cb4b6475d2d74d422d296ea3b51b16b7f45dc84f" }, "Makefile": { - "bytes": 3976, - "git_blob": "91897a30656e65215cc73620b4d9eb8ede682ef5", + "bytes": 4182, + "git_blob": "2cbf6cc9fec52ab0a50308ae5e180f807712035d", "mode": "100644", - "sha256": "0c7c343f51fe8503c29047ad3b93ff45582b5e5bff2768baa7883d9826c4be69" + "sha256": "4d585db8759d621215884b7727ff0aea74902abb3daa6f3c8974f5e94a286180" }, "TeraFFI/Makefile": { "bytes": 374, @@ -526,10 +746,10 @@ "sha256": "7e9bc238cc27041e3f6b63d40d28712f3276bf0b3f3deb7609f4fb962db4f4c1" }, "TeraFFI/producer.toml": { - "bytes": 1084, - "git_blob": "23e07f3d818f7f3d57a77fca3bca6b32b9218e74", + "bytes": 1264, + "git_blob": "4ac636cfd39722fb027db8935fa2536dfd1add0a", "mode": "100644", - "sha256": "eebaf5b181e9b27c3854201c6f6ac1662b7a7045168f960a5c1dac8c5de29013" + "sha256": "67b1a8182cd20a445df7e9e94ab4d6ffdcd210f5362819fbf5f6d5b8182bcdad" }, "TeraFFI/scripts/verify-installed-artifacts.sh": { "bytes": 255, @@ -2704,10 +2924,10 @@ "sha256": "568ee230a99a907cc9063c203fbecc80e6ba4aca3db6c1e3af93abdbc904b7d5" }, "scripts/ffi_build.py": { - "bytes": 13121, - "git_blob": "0e4f11cd56003b562bccb90eeb30ca706a272863", + "bytes": 14912, + "git_blob": "3c56911a3d761ae12be76c8511903e4196b3755e", "mode": "100644", - "sha256": "eafe2189e97a436522fdf18909aa494392ab0347da28b338cc999b30044fc90d" + "sha256": "76ec2f8c38883c63709bfb2cce79dc5851533e981f41e7bd065c29ea69f7f4cf" }, "scripts/ffi_installed.py": { "bytes": 8207, @@ -2715,17 +2935,23 @@ "mode": "100644", "sha256": "2f14e83fe08d70b4c92361d9bccd08dd6c480eebd767a692a8b5f03fdb0e5380" }, + "scripts/ffi_native.py": { + "bytes": 17880, + "git_blob": "ee6f4024858b0fca71f6f6bb3f851b64ba52eb81", + "mode": "100644", + "sha256": "4b4ba6fd87c53b3d263404b4e1d62474fab27456f23574ce89af5f1f56871e37" + }, "scripts/ffi_provenance.py": { - "bytes": 6808, - "git_blob": "de2c086a110501f8bd11f1e5b26b2473c468ce28", + "bytes": 7683, + "git_blob": "d011914a27d88e08ff2d38f6841a8e948cb40a40", "mode": "100644", - "sha256": "2a1a89db83bfd1b1a2e80c1fbd31288dcf2f75a1439ba3446633c755dec0255f" + "sha256": "e88886ba1485e49585c6e595d6f2ce9a9211efc703b1087fe66668c2534ee985" }, "scripts/ffi_source.py": { - "bytes": 13564, - "git_blob": "42a767ceb4ee1e5f00be6d0f31101450a78c16e5", + "bytes": 14339, + "git_blob": "20cc49423ced887c47df7c9b29e4c6d8a3bd50fb", "mode": "100644", - "sha256": "49f7995b46c22c2c64c808e2bf3ff2d7d1041040697b1c3f61a4f07d021a7712" + "sha256": "62b2a12982e11f62f70e60b1f16cc1f164c2fdfd3ab915c92b9ea1dbf7ed6eca" }, "scripts/generate-project.sh": { "bytes": 2964, @@ -2740,10 +2966,10 @@ "sha256": "26046966bece8c811a5b3edef191e2ea5b5c4be3187cf65a29f7edbe93cbb487" }, "scripts/kotlin_smoke.py": { - "bytes": 10695, - "git_blob": "7e68d51111202626ff46d146b37cdebbf9121370", + "bytes": 11310, + "git_blob": "fd294e2b6e291624a52fc9276676ed471776f198", "mode": "100644", - "sha256": "48277943e29720c3713326990e74fd50c6e2c805cd7c6fd5b62b0016cfdac1ad" + "sha256": "c28be2b7d25dd5a19d8ca014f8e2f2e829fdf62f164a6436c0995427534e3e58" }, "scripts/kotlin_smoke/build.gradle.kts": { "bytes": 1479, @@ -2950,10 +3176,10 @@ "sha256": "1803572abdb2e22bedd275724edae5f09c523b132bc59086aacca0f5183905d0" }, "scripts/swift-quality.sh": { - "bytes": 2308, - "git_blob": "f07b465c125de12548d523a293a96a3837c1193d", + "bytes": 2459, + "git_blob": "13a1843e6ae14d91b2bffb8085bb2130dd74e5fc", "mode": "100755", - "sha256": "07cd900d465744eab373c07d90b954758732a0564cab42f7bd4df88dd42bdeee" + "sha256": "1e4f4e2f36e9ae476c88da975ba97fe7868ba11529d02ed76fa27ef4bc4fb99e" }, "scripts/test_app_dependency_graph.py": { "bytes": 4007, @@ -2962,10 +3188,10 @@ "sha256": "d336abd6368ad3b0d0171b32aaa4a44d9c1a8551899d39a1445eca05b67d8b30" }, "scripts/test_ffi_artifacts.py": { - "bytes": 7460, - "git_blob": "e933763e0f8329e5b97f9a5115b7fadf6504eb15", + "bytes": 10184, + "git_blob": "a1dd396b883ebe3c9933d19d9c2194103ed907b6", "mode": "100644", - "sha256": "b45a467dd04903f12550f7ad83ca438dee08e2113ba7146b7f4f1184e273d1f9" + "sha256": "5aa2802564104a5d32bcf322e52148ae2eb7d38379e3b10cf82dc657fd0a911c" }, "scripts/test_ffi_installed.py": { "bytes": 5140, @@ -2973,17 +3199,29 @@ "mode": "100644", "sha256": "1a60456d7780dfb26dbc71c3c3a07190f6d78c44521f264e0d8aa3ee41c7ff59" }, + "scripts/test_ffi_native.py": { + "bytes": 33161, + "git_blob": "bb0b05666d892062b496eadc36dfc35db16988d3", + "mode": "100644", + "sha256": "782dd020ef450d207e12896a9bb781edbecd25bc4b795df2664be102b05ae4b0" + }, + "scripts/test_ffi_native_cache.py": { + "bytes": 12040, + "git_blob": "528174a7c73739d30bf0defb5f774da7f088c5b2", + "mode": "100644", + "sha256": "4d930c13d3f6446073a87419d7a7ac91d01aadc31b19964789a261ba8699a5f6" + }, "scripts/test_ffi_provenance.py": { - "bytes": 11247, - "git_blob": "cc1140c5a4153ea2a9526a69a231ed65037209f7", + "bytes": 11856, + "git_blob": "0fe4fe8c93d72fcc1055e9c2bc6b8b2a54f06081", "mode": "100644", - "sha256": "cda3773df7ec0ed0c6bc508167f65f9f0a9a2f81ca461078c0313dbd57785584" + "sha256": "9cf479a3126635500c0d1b487b298769bc93f4894f08204b05e1b41308d532af" }, "scripts/test_kotlin_smoke.py": { - "bytes": 3609, - "git_blob": "0e3fb31aaba13316c533c166ea5bee4a5903fae8", + "bytes": 13269, + "git_blob": "eeb4ed3c56d16a0cea55c43645834a12c64c933e", "mode": "100644", - "sha256": "f97d7e8cea2fb18b5a4dc9b3f2ea20938343c363934471a5647fa5795204a34d" + "sha256": "2906c6a93678def240cc43042845dcecfdc2c2e5efc4bdad7600c693c9bc72ba" }, "scripts/test_legacy_identifiers.py": { "bytes": 6406, @@ -3033,17 +3271,29 @@ "mode": "100644", "sha256": "56797c8dd8b1e1efc3c1f469f86c542baecaf12db60bcc799585f475438379f5" }, + "scripts/test_unittest_report.py": { + "bytes": 33055, + "git_blob": "1e2b8a07baa061d13b70221fa725a8872d9be924", + "mode": "100644", + "sha256": "a1b1ef1ac7533bad0af80bf66790a8954aa990b279d8f417bd15e040f3bfb521" + }, "scripts/test_xcode_selection.py": { "bytes": 4745, "git_blob": "b633afbccd765a106e2ad591881926a9add542ac", "mode": "100644", "sha256": "a917dfbc1d8ecac7d1539670651e4b468059bc77dfe31aeefbc6c6eb21bebbfb" }, + "scripts/unittest_report.py": { + "bytes": 20276, + "git_blob": "319eb74779ee70a119e997979ac2d6a65d6b243b", + "mode": "100644", + "sha256": "c1bbdc3c0ad9df4679eb110f9e145b5e399e7e5f74298a56028f46ff1269ff98" + }, "scripts/verify-package-contract.sh": { - "bytes": 1663, - "git_blob": "76674ddf0dbdb54e39dd788bf8ad5515af47f1c8", + "bytes": 1730, + "git_blob": "a9e22505700f690dfaf8714eadad3c5128b9ecd4", "mode": "100755", - "sha256": "8798d003a8a0ac9e5aff6fc89093fd7af9f6de95a32be1c5e0391727a2461eb2" + "sha256": "836e0ab1fbf3535c8f26f4a3540fe6f51ccae7f78ebada79ca703dd4420d83f6" }, "scripts/xcode.sh": { "bytes": 22437, @@ -3059,6 +3309,6 @@ } }, "policy": "staged_inputs", - "tree": "16436eff2c5f2f69b6d2d767b1d0264bb9051992" + "tree": "a7f7ef68f86606405e16d5b51ecd57a8bdf02fd4" } } diff --git a/TeraFFI/source/aarch64-apple-ios-sim.json b/TeraFFI/source/aarch64-apple-ios-sim.json @@ -369,6 +369,116 @@ ], "features": [], "ios_deployment_target": "18.0", + "native": { + "compiler_arguments": [ + "--no-default-config" + ], + "compiler_resources": { + "bytes": 83967222, + "nodes": 377, + "path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/21", + "sha256": "dd5989662272c61af2fb63d0eaf970f66d9c5a1f10ef3a8d481a2592f80578cf" + }, + "deployment": { + "IPHONEOS_DEPLOYMENT_TARGET": "18.0" + }, + "developer_dir": "/Applications/Xcode.app/Contents/Developer", + "inherited": { + "generator_profile_overrides": { + "CARGO_PROFILE_DEV_DEBUG": "line-tables-only" + }, + "path_sha256": "e4bfec31ceb26bfa330c30b81c526b8429ba650cf8a92c77e5c3971924187a16" + }, + "inspection_limits": { + "maximum_inspection_seconds": 120, + "maximum_sdk_aggregate_bytes": 2000000000, + "maximum_sdk_nodes": 100000, + "stream_chunk_bytes": 65536 + }, + "linker_driver_arguments": [ + "--no-default-config", + "-fuse-ld=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" + ], + "policy": "closed_apple_c_v1", + "sdk": { + "bytes": 219022288, + "nodes": 10008, + "path": "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator.sdk", + "sha256": "8ef53260e42aa5ca73f62ae1888d37b766288d1105f0de20c74520c22a1b9f6d" + }, + "sdk_build": "23F81a", + "sdk_name": "iphonesimulator", + "sdk_version": "26.5", + "target": "aarch64-apple-ios-sim", + "tools": { + "archiver": { + "bytes": 73520, + "path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ar", + "resolved_path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ar", + "sha256": "e49ffad64ad1cee722540fc5ecb00a230fd8071680682c60d9c851029d20e814" + }, + "compiler": { + "bytes": 141373024, + "path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang", + "resolved_path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang", + "sha256": "7def90dd8829726686213a747fc5bff1583df933dae5edc55d755479e0bfe00a" + }, + "linker": { + "bytes": 2331792, + "path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld", + "resolved_path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld", + "sha256": "5897b275efd93b201b6df5832dd541262b3f20f290859ba78f2200a6a66ef38b" + }, + "ranlib": { + "bytes": 210800, + "path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib", + "resolved_path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool", + "sha256": "229eb9d8027953d2aee0590f983eed587d52bdd1ebc21114a62ce693f77b03f1" + }, + "swift": { + "bytes": 171036592, + "path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift", + "resolved_path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend", + "sha256": "2ed38571e92c0283091838c1649e27650ad9c99950288e883c7b2dc6c4ce89fb" + }, + "swift_format": { + "bytes": 8035472, + "path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-format", + "resolved_path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-format", + "sha256": "48317544bec55d5dee83e15738a342c0c31bf9c60273599f85601a8faea0016c" + }, + "swift_symbolgraph_extract": { + "bytes": 171036592, + "path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-symbolgraph-extract", + "resolved_path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend", + "sha256": "2ed38571e92c0283091838c1649e27650ad9c99950288e883c7b2dc6c4ce89fb" + }, + "swiftc": { + "bytes": 171036592, + "path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc", + "resolved_path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend", + "sha256": "2ed38571e92c0283091838c1649e27650ad9c99950288e883c7b2dc6c4ce89fb" + }, + "swiftformat": { + "bytes": 4700024, + "path": "/opt/homebrew/bin/swiftformat", + "resolved_path": "/opt/homebrew/Cellar/swiftformat/0.63.1/bin/swiftformat", + "sha256": "5495efaea582c21d93d344dfbfe3f05893b8bf3c99f7fd2962972c4a80caa685" + }, + "xcodebuild": { + "bytes": 100528, + "path": "/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild", + "resolved_path": "/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild", + "sha256": "d508f0e1901151843804e4af512d4587ad0e422039e43e14abf22792360ad3d4" + }, + "xcrun": { + "bytes": 117392, + "path": "/usr/bin/xcrun", + "resolved_path": "/usr/bin/xcrun", + "sha256": "a439970aea2b4e435eac6518ff62c97fd1c57d8c731974027ad211b515c7a7b8" + } + } + }, "package": "tera_ffi", "package_rust_flags": [], "profile": "release", @@ -380,6 +490,10 @@ "rustc": "rustc 1.97.1 (8bab26f4f 2026-07-14)\nbinary: rustc\ncommit-hash: 8bab26f4f68e0e26f0bb7960be334d5b520ea452\ncommit-date: 2026-07-14\nhost: aarch64-apple-darwin\nrelease: 1.97.1\nLLVM version: 22.1.6", "source_date_epoch": 1787871027, "symbol_reader": "llvm-nm, compatible with GNU nm\nLLVM (http://llvm.org/):\n LLVM version 22.1.6-rust-1.97.1-stable\n Optimized build.", + "symbol_reader_identity": { + "bytes": 45024888, + "sha256": "35ce10ff99cd452e3767c4dfa7ed998a3265a960a3b393c307117f85dcb1f4e5" + }, "target": "aarch64-apple-ios-sim" }, "cargo_lock_sha256": "31aced473ddc097b2a3508b9247a336f8598b31dabdca320f10f9b720195424f", @@ -486,6 +600,114 @@ "zmij v1.0.23|" ], "features": [], + "native": { + "compiler_arguments": [ + "--no-default-config" + ], + "compiler_resources": { + "bytes": 83967222, + "nodes": 377, + "path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/21", + "sha256": "dd5989662272c61af2fb63d0eaf970f66d9c5a1f10ef3a8d481a2592f80578cf" + }, + "deployment": {}, + "developer_dir": "/Applications/Xcode.app/Contents/Developer", + "inherited": { + "generator_profile_overrides": { + "CARGO_PROFILE_DEV_DEBUG": "line-tables-only" + }, + "path_sha256": "e4bfec31ceb26bfa330c30b81c526b8429ba650cf8a92c77e5c3971924187a16" + }, + "inspection_limits": { + "maximum_inspection_seconds": 120, + "maximum_sdk_aggregate_bytes": 2000000000, + "maximum_sdk_nodes": 100000, + "stream_chunk_bytes": 65536 + }, + "linker_driver_arguments": [ + "--no-default-config", + "-fuse-ld=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" + ], + "policy": "closed_apple_c_v1", + "sdk": { + "bytes": 765532437, + "nodes": 49700, + "path": "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk", + "sha256": "20c43e843e92669de61c29972eb0b1cf18f67e5fa534822dd6d897bec1dc20f8" + }, + "sdk_build": "25F70", + "sdk_name": "macosx", + "sdk_version": "26.5", + "target": "aarch64-apple-darwin", + "tools": { + "archiver": { + "bytes": 73520, + "path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ar", + "resolved_path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ar", + "sha256": "e49ffad64ad1cee722540fc5ecb00a230fd8071680682c60d9c851029d20e814" + }, + "compiler": { + "bytes": 141373024, + "path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang", + "resolved_path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang", + "sha256": "7def90dd8829726686213a747fc5bff1583df933dae5edc55d755479e0bfe00a" + }, + "linker": { + "bytes": 2331792, + "path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld", + "resolved_path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld", + "sha256": "5897b275efd93b201b6df5832dd541262b3f20f290859ba78f2200a6a66ef38b" + }, + "ranlib": { + "bytes": 210800, + "path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib", + "resolved_path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool", + "sha256": "229eb9d8027953d2aee0590f983eed587d52bdd1ebc21114a62ce693f77b03f1" + }, + "swift": { + "bytes": 171036592, + "path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift", + "resolved_path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend", + "sha256": "2ed38571e92c0283091838c1649e27650ad9c99950288e883c7b2dc6c4ce89fb" + }, + "swift_format": { + "bytes": 8035472, + "path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-format", + "resolved_path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-format", + "sha256": "48317544bec55d5dee83e15738a342c0c31bf9c60273599f85601a8faea0016c" + }, + "swift_symbolgraph_extract": { + "bytes": 171036592, + "path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-symbolgraph-extract", + "resolved_path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend", + "sha256": "2ed38571e92c0283091838c1649e27650ad9c99950288e883c7b2dc6c4ce89fb" + }, + "swiftc": { + "bytes": 171036592, + "path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc", + "resolved_path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend", + "sha256": "2ed38571e92c0283091838c1649e27650ad9c99950288e883c7b2dc6c4ce89fb" + }, + "swiftformat": { + "bytes": 4700024, + "path": "/opt/homebrew/bin/swiftformat", + "resolved_path": "/opt/homebrew/Cellar/swiftformat/0.63.1/bin/swiftformat", + "sha256": "5495efaea582c21d93d344dfbfe3f05893b8bf3c99f7fd2962972c4a80caa685" + }, + "xcodebuild": { + "bytes": 100528, + "path": "/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild", + "resolved_path": "/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild", + "sha256": "d508f0e1901151843804e4af512d4587ad0e422039e43e14abf22792360ad3d4" + }, + "xcrun": { + "bytes": 117392, + "path": "/usr/bin/xcrun", + "resolved_path": "/usr/bin/xcrun", + "sha256": "a439970aea2b4e435eac6518ff62c97fd1c57d8c731974027ad211b515c7a7b8" + } + } + }, "package": "tera_bindgen", "profile": "dev", "profile_overrides": { @@ -510,10 +732,10 @@ "sha256": "5382cbc1cb6314cd0bd45be4cb4b6475d2d74d422d296ea3b51b16b7f45dc84f" }, "Makefile": { - "bytes": 3976, - "git_blob": "91897a30656e65215cc73620b4d9eb8ede682ef5", + "bytes": 4182, + "git_blob": "2cbf6cc9fec52ab0a50308ae5e180f807712035d", "mode": "100644", - "sha256": "0c7c343f51fe8503c29047ad3b93ff45582b5e5bff2768baa7883d9826c4be69" + "sha256": "4d585db8759d621215884b7727ff0aea74902abb3daa6f3c8974f5e94a286180" }, "TeraFFI/Makefile": { "bytes": 374, @@ -522,10 +744,10 @@ "sha256": "7e9bc238cc27041e3f6b63d40d28712f3276bf0b3f3deb7609f4fb962db4f4c1" }, "TeraFFI/producer.toml": { - "bytes": 1084, - "git_blob": "23e07f3d818f7f3d57a77fca3bca6b32b9218e74", + "bytes": 1264, + "git_blob": "4ac636cfd39722fb027db8935fa2536dfd1add0a", "mode": "100644", - "sha256": "eebaf5b181e9b27c3854201c6f6ac1662b7a7045168f960a5c1dac8c5de29013" + "sha256": "67b1a8182cd20a445df7e9e94ab4d6ffdcd210f5362819fbf5f6d5b8182bcdad" }, "TeraFFI/scripts/verify-installed-artifacts.sh": { "bytes": 255, @@ -2700,10 +2922,10 @@ "sha256": "568ee230a99a907cc9063c203fbecc80e6ba4aca3db6c1e3af93abdbc904b7d5" }, "scripts/ffi_build.py": { - "bytes": 13121, - "git_blob": "0e4f11cd56003b562bccb90eeb30ca706a272863", + "bytes": 14912, + "git_blob": "3c56911a3d761ae12be76c8511903e4196b3755e", "mode": "100644", - "sha256": "eafe2189e97a436522fdf18909aa494392ab0347da28b338cc999b30044fc90d" + "sha256": "76ec2f8c38883c63709bfb2cce79dc5851533e981f41e7bd065c29ea69f7f4cf" }, "scripts/ffi_installed.py": { "bytes": 8207, @@ -2711,17 +2933,23 @@ "mode": "100644", "sha256": "2f14e83fe08d70b4c92361d9bccd08dd6c480eebd767a692a8b5f03fdb0e5380" }, + "scripts/ffi_native.py": { + "bytes": 17880, + "git_blob": "ee6f4024858b0fca71f6f6bb3f851b64ba52eb81", + "mode": "100644", + "sha256": "4b4ba6fd87c53b3d263404b4e1d62474fab27456f23574ce89af5f1f56871e37" + }, "scripts/ffi_provenance.py": { - "bytes": 6808, - "git_blob": "de2c086a110501f8bd11f1e5b26b2473c468ce28", + "bytes": 7683, + "git_blob": "d011914a27d88e08ff2d38f6841a8e948cb40a40", "mode": "100644", - "sha256": "2a1a89db83bfd1b1a2e80c1fbd31288dcf2f75a1439ba3446633c755dec0255f" + "sha256": "e88886ba1485e49585c6e595d6f2ce9a9211efc703b1087fe66668c2534ee985" }, "scripts/ffi_source.py": { - "bytes": 13564, - "git_blob": "42a767ceb4ee1e5f00be6d0f31101450a78c16e5", + "bytes": 14339, + "git_blob": "20cc49423ced887c47df7c9b29e4c6d8a3bd50fb", "mode": "100644", - "sha256": "49f7995b46c22c2c64c808e2bf3ff2d7d1041040697b1c3f61a4f07d021a7712" + "sha256": "62b2a12982e11f62f70e60b1f16cc1f164c2fdfd3ab915c92b9ea1dbf7ed6eca" }, "scripts/generate-project.sh": { "bytes": 2964, @@ -2736,10 +2964,10 @@ "sha256": "26046966bece8c811a5b3edef191e2ea5b5c4be3187cf65a29f7edbe93cbb487" }, "scripts/kotlin_smoke.py": { - "bytes": 10695, - "git_blob": "7e68d51111202626ff46d146b37cdebbf9121370", + "bytes": 11310, + "git_blob": "fd294e2b6e291624a52fc9276676ed471776f198", "mode": "100644", - "sha256": "48277943e29720c3713326990e74fd50c6e2c805cd7c6fd5b62b0016cfdac1ad" + "sha256": "c28be2b7d25dd5a19d8ca014f8e2f2e829fdf62f164a6436c0995427534e3e58" }, "scripts/kotlin_smoke/build.gradle.kts": { "bytes": 1479, @@ -2946,10 +3174,10 @@ "sha256": "1803572abdb2e22bedd275724edae5f09c523b132bc59086aacca0f5183905d0" }, "scripts/swift-quality.sh": { - "bytes": 2308, - "git_blob": "f07b465c125de12548d523a293a96a3837c1193d", + "bytes": 2459, + "git_blob": "13a1843e6ae14d91b2bffb8085bb2130dd74e5fc", "mode": "100755", - "sha256": "07cd900d465744eab373c07d90b954758732a0564cab42f7bd4df88dd42bdeee" + "sha256": "1e4f4e2f36e9ae476c88da975ba97fe7868ba11529d02ed76fa27ef4bc4fb99e" }, "scripts/test_app_dependency_graph.py": { "bytes": 4007, @@ -2958,10 +3186,10 @@ "sha256": "d336abd6368ad3b0d0171b32aaa4a44d9c1a8551899d39a1445eca05b67d8b30" }, "scripts/test_ffi_artifacts.py": { - "bytes": 7460, - "git_blob": "e933763e0f8329e5b97f9a5115b7fadf6504eb15", + "bytes": 10184, + "git_blob": "a1dd396b883ebe3c9933d19d9c2194103ed907b6", "mode": "100644", - "sha256": "b45a467dd04903f12550f7ad83ca438dee08e2113ba7146b7f4f1184e273d1f9" + "sha256": "5aa2802564104a5d32bcf322e52148ae2eb7d38379e3b10cf82dc657fd0a911c" }, "scripts/test_ffi_installed.py": { "bytes": 5140, @@ -2969,17 +3197,29 @@ "mode": "100644", "sha256": "1a60456d7780dfb26dbc71c3c3a07190f6d78c44521f264e0d8aa3ee41c7ff59" }, + "scripts/test_ffi_native.py": { + "bytes": 33161, + "git_blob": "bb0b05666d892062b496eadc36dfc35db16988d3", + "mode": "100644", + "sha256": "782dd020ef450d207e12896a9bb781edbecd25bc4b795df2664be102b05ae4b0" + }, + "scripts/test_ffi_native_cache.py": { + "bytes": 12040, + "git_blob": "528174a7c73739d30bf0defb5f774da7f088c5b2", + "mode": "100644", + "sha256": "4d930c13d3f6446073a87419d7a7ac91d01aadc31b19964789a261ba8699a5f6" + }, "scripts/test_ffi_provenance.py": { - "bytes": 11247, - "git_blob": "cc1140c5a4153ea2a9526a69a231ed65037209f7", + "bytes": 11856, + "git_blob": "0fe4fe8c93d72fcc1055e9c2bc6b8b2a54f06081", "mode": "100644", - "sha256": "cda3773df7ec0ed0c6bc508167f65f9f0a9a2f81ca461078c0313dbd57785584" + "sha256": "9cf479a3126635500c0d1b487b298769bc93f4894f08204b05e1b41308d532af" }, "scripts/test_kotlin_smoke.py": { - "bytes": 3609, - "git_blob": "0e3fb31aaba13316c533c166ea5bee4a5903fae8", + "bytes": 13269, + "git_blob": "eeb4ed3c56d16a0cea55c43645834a12c64c933e", "mode": "100644", - "sha256": "f97d7e8cea2fb18b5a4dc9b3f2ea20938343c363934471a5647fa5795204a34d" + "sha256": "2906c6a93678def240cc43042845dcecfdc2c2e5efc4bdad7600c693c9bc72ba" }, "scripts/test_legacy_identifiers.py": { "bytes": 6406, @@ -3029,17 +3269,29 @@ "mode": "100644", "sha256": "56797c8dd8b1e1efc3c1f469f86c542baecaf12db60bcc799585f475438379f5" }, + "scripts/test_unittest_report.py": { + "bytes": 33055, + "git_blob": "1e2b8a07baa061d13b70221fa725a8872d9be924", + "mode": "100644", + "sha256": "a1b1ef1ac7533bad0af80bf66790a8954aa990b279d8f417bd15e040f3bfb521" + }, "scripts/test_xcode_selection.py": { "bytes": 4745, "git_blob": "b633afbccd765a106e2ad591881926a9add542ac", "mode": "100644", "sha256": "a917dfbc1d8ecac7d1539670651e4b468059bc77dfe31aeefbc6c6eb21bebbfb" }, + "scripts/unittest_report.py": { + "bytes": 20276, + "git_blob": "319eb74779ee70a119e997979ac2d6a65d6b243b", + "mode": "100644", + "sha256": "c1bbdc3c0ad9df4679eb110f9e145b5e399e7e5f74298a56028f46ff1269ff98" + }, "scripts/verify-package-contract.sh": { - "bytes": 1663, - "git_blob": "76674ddf0dbdb54e39dd788bf8ad5515af47f1c8", + "bytes": 1730, + "git_blob": "a9e22505700f690dfaf8714eadad3c5128b9ecd4", "mode": "100755", - "sha256": "8798d003a8a0ac9e5aff6fc89093fd7af9f6de95a32be1c5e0391727a2461eb2" + "sha256": "836e0ab1fbf3535c8f26f4a3540fe6f51ccae7f78ebada79ca703dd4420d83f6" }, "scripts/xcode.sh": { "bytes": 22437, @@ -3055,6 +3307,6 @@ } }, "policy": "staged_inputs", - "tree": "16436eff2c5f2f69b6d2d767b1d0264bb9051992" + "tree": "a7f7ef68f86606405e16d5b51ecd57a8bdf02fd4" } } diff --git a/TeraFFI/source/aarch64-apple-ios.json b/TeraFFI/source/aarch64-apple-ios.json @@ -369,6 +369,116 @@ ], "features": [], "ios_deployment_target": "18.0", + "native": { + "compiler_arguments": [ + "--no-default-config" + ], + "compiler_resources": { + "bytes": 83967222, + "nodes": 377, + "path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/21", + "sha256": "dd5989662272c61af2fb63d0eaf970f66d9c5a1f10ef3a8d481a2592f80578cf" + }, + "deployment": { + "IPHONEOS_DEPLOYMENT_TARGET": "18.0" + }, + "developer_dir": "/Applications/Xcode.app/Contents/Developer", + "inherited": { + "generator_profile_overrides": { + "CARGO_PROFILE_DEV_DEBUG": "line-tables-only" + }, + "path_sha256": "e4bfec31ceb26bfa330c30b81c526b8429ba650cf8a92c77e5c3971924187a16" + }, + "inspection_limits": { + "maximum_inspection_seconds": 120, + "maximum_sdk_aggregate_bytes": 2000000000, + "maximum_sdk_nodes": 100000, + "stream_chunk_bytes": 65536 + }, + "linker_driver_arguments": [ + "--no-default-config", + "-fuse-ld=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" + ], + "policy": "closed_apple_c_v1", + "sdk": { + "bytes": 179460531, + "nodes": 9862, + "path": "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk", + "sha256": "3c024cd45fbe1fa2e0c389b565449215f787ef1f013d52eac260ae0a5e54a6f2" + }, + "sdk_build": "23F81a", + "sdk_name": "iphoneos", + "sdk_version": "26.5", + "target": "aarch64-apple-ios", + "tools": { + "archiver": { + "bytes": 73520, + "path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ar", + "resolved_path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ar", + "sha256": "e49ffad64ad1cee722540fc5ecb00a230fd8071680682c60d9c851029d20e814" + }, + "compiler": { + "bytes": 141373024, + "path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang", + "resolved_path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang", + "sha256": "7def90dd8829726686213a747fc5bff1583df933dae5edc55d755479e0bfe00a" + }, + "linker": { + "bytes": 2331792, + "path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld", + "resolved_path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld", + "sha256": "5897b275efd93b201b6df5832dd541262b3f20f290859ba78f2200a6a66ef38b" + }, + "ranlib": { + "bytes": 210800, + "path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib", + "resolved_path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool", + "sha256": "229eb9d8027953d2aee0590f983eed587d52bdd1ebc21114a62ce693f77b03f1" + }, + "swift": { + "bytes": 171036592, + "path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift", + "resolved_path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend", + "sha256": "2ed38571e92c0283091838c1649e27650ad9c99950288e883c7b2dc6c4ce89fb" + }, + "swift_format": { + "bytes": 8035472, + "path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-format", + "resolved_path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-format", + "sha256": "48317544bec55d5dee83e15738a342c0c31bf9c60273599f85601a8faea0016c" + }, + "swift_symbolgraph_extract": { + "bytes": 171036592, + "path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-symbolgraph-extract", + "resolved_path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend", + "sha256": "2ed38571e92c0283091838c1649e27650ad9c99950288e883c7b2dc6c4ce89fb" + }, + "swiftc": { + "bytes": 171036592, + "path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc", + "resolved_path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend", + "sha256": "2ed38571e92c0283091838c1649e27650ad9c99950288e883c7b2dc6c4ce89fb" + }, + "swiftformat": { + "bytes": 4700024, + "path": "/opt/homebrew/bin/swiftformat", + "resolved_path": "/opt/homebrew/Cellar/swiftformat/0.63.1/bin/swiftformat", + "sha256": "5495efaea582c21d93d344dfbfe3f05893b8bf3c99f7fd2962972c4a80caa685" + }, + "xcodebuild": { + "bytes": 100528, + "path": "/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild", + "resolved_path": "/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild", + "sha256": "d508f0e1901151843804e4af512d4587ad0e422039e43e14abf22792360ad3d4" + }, + "xcrun": { + "bytes": 117392, + "path": "/usr/bin/xcrun", + "resolved_path": "/usr/bin/xcrun", + "sha256": "a439970aea2b4e435eac6518ff62c97fd1c57d8c731974027ad211b515c7a7b8" + } + } + }, "package": "tera_ffi", "package_rust_flags": [], "profile": "release", @@ -380,6 +490,10 @@ "rustc": "rustc 1.97.1 (8bab26f4f 2026-07-14)\nbinary: rustc\ncommit-hash: 8bab26f4f68e0e26f0bb7960be334d5b520ea452\ncommit-date: 2026-07-14\nhost: aarch64-apple-darwin\nrelease: 1.97.1\nLLVM version: 22.1.6", "source_date_epoch": 1787871027, "symbol_reader": "llvm-nm, compatible with GNU nm\nLLVM (http://llvm.org/):\n LLVM version 22.1.6-rust-1.97.1-stable\n Optimized build.", + "symbol_reader_identity": { + "bytes": 45024888, + "sha256": "35ce10ff99cd452e3767c4dfa7ed998a3265a960a3b393c307117f85dcb1f4e5" + }, "target": "aarch64-apple-ios" }, "cargo_lock_sha256": "31aced473ddc097b2a3508b9247a336f8598b31dabdca320f10f9b720195424f", @@ -486,6 +600,114 @@ "zmij v1.0.23|" ], "features": [], + "native": { + "compiler_arguments": [ + "--no-default-config" + ], + "compiler_resources": { + "bytes": 83967222, + "nodes": 377, + "path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/21", + "sha256": "dd5989662272c61af2fb63d0eaf970f66d9c5a1f10ef3a8d481a2592f80578cf" + }, + "deployment": {}, + "developer_dir": "/Applications/Xcode.app/Contents/Developer", + "inherited": { + "generator_profile_overrides": { + "CARGO_PROFILE_DEV_DEBUG": "line-tables-only" + }, + "path_sha256": "e4bfec31ceb26bfa330c30b81c526b8429ba650cf8a92c77e5c3971924187a16" + }, + "inspection_limits": { + "maximum_inspection_seconds": 120, + "maximum_sdk_aggregate_bytes": 2000000000, + "maximum_sdk_nodes": 100000, + "stream_chunk_bytes": 65536 + }, + "linker_driver_arguments": [ + "--no-default-config", + "-fuse-ld=/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" + ], + "policy": "closed_apple_c_v1", + "sdk": { + "bytes": 765532437, + "nodes": 49700, + "path": "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk", + "sha256": "20c43e843e92669de61c29972eb0b1cf18f67e5fa534822dd6d897bec1dc20f8" + }, + "sdk_build": "25F70", + "sdk_name": "macosx", + "sdk_version": "26.5", + "target": "aarch64-apple-darwin", + "tools": { + "archiver": { + "bytes": 73520, + "path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ar", + "resolved_path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ar", + "sha256": "e49ffad64ad1cee722540fc5ecb00a230fd8071680682c60d9c851029d20e814" + }, + "compiler": { + "bytes": 141373024, + "path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang", + "resolved_path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang", + "sha256": "7def90dd8829726686213a747fc5bff1583df933dae5edc55d755479e0bfe00a" + }, + "linker": { + "bytes": 2331792, + "path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld", + "resolved_path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld", + "sha256": "5897b275efd93b201b6df5832dd541262b3f20f290859ba78f2200a6a66ef38b" + }, + "ranlib": { + "bytes": 210800, + "path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ranlib", + "resolved_path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/libtool", + "sha256": "229eb9d8027953d2aee0590f983eed587d52bdd1ebc21114a62ce693f77b03f1" + }, + "swift": { + "bytes": 171036592, + "path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift", + "resolved_path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend", + "sha256": "2ed38571e92c0283091838c1649e27650ad9c99950288e883c7b2dc6c4ce89fb" + }, + "swift_format": { + "bytes": 8035472, + "path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-format", + "resolved_path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-format", + "sha256": "48317544bec55d5dee83e15738a342c0c31bf9c60273599f85601a8faea0016c" + }, + "swift_symbolgraph_extract": { + "bytes": 171036592, + "path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-symbolgraph-extract", + "resolved_path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend", + "sha256": "2ed38571e92c0283091838c1649e27650ad9c99950288e883c7b2dc6c4ce89fb" + }, + "swiftc": { + "bytes": 171036592, + "path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc", + "resolved_path": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend", + "sha256": "2ed38571e92c0283091838c1649e27650ad9c99950288e883c7b2dc6c4ce89fb" + }, + "swiftformat": { + "bytes": 4700024, + "path": "/opt/homebrew/bin/swiftformat", + "resolved_path": "/opt/homebrew/Cellar/swiftformat/0.63.1/bin/swiftformat", + "sha256": "5495efaea582c21d93d344dfbfe3f05893b8bf3c99f7fd2962972c4a80caa685" + }, + "xcodebuild": { + "bytes": 100528, + "path": "/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild", + "resolved_path": "/Applications/Xcode.app/Contents/Developer/usr/bin/xcodebuild", + "sha256": "d508f0e1901151843804e4af512d4587ad0e422039e43e14abf22792360ad3d4" + }, + "xcrun": { + "bytes": 117392, + "path": "/usr/bin/xcrun", + "resolved_path": "/usr/bin/xcrun", + "sha256": "a439970aea2b4e435eac6518ff62c97fd1c57d8c731974027ad211b515c7a7b8" + } + } + }, "package": "tera_bindgen", "profile": "dev", "profile_overrides": { @@ -510,10 +732,10 @@ "sha256": "5382cbc1cb6314cd0bd45be4cb4b6475d2d74d422d296ea3b51b16b7f45dc84f" }, "Makefile": { - "bytes": 3976, - "git_blob": "91897a30656e65215cc73620b4d9eb8ede682ef5", + "bytes": 4182, + "git_blob": "2cbf6cc9fec52ab0a50308ae5e180f807712035d", "mode": "100644", - "sha256": "0c7c343f51fe8503c29047ad3b93ff45582b5e5bff2768baa7883d9826c4be69" + "sha256": "4d585db8759d621215884b7727ff0aea74902abb3daa6f3c8974f5e94a286180" }, "TeraFFI/Makefile": { "bytes": 374, @@ -522,10 +744,10 @@ "sha256": "7e9bc238cc27041e3f6b63d40d28712f3276bf0b3f3deb7609f4fb962db4f4c1" }, "TeraFFI/producer.toml": { - "bytes": 1084, - "git_blob": "23e07f3d818f7f3d57a77fca3bca6b32b9218e74", + "bytes": 1264, + "git_blob": "4ac636cfd39722fb027db8935fa2536dfd1add0a", "mode": "100644", - "sha256": "eebaf5b181e9b27c3854201c6f6ac1662b7a7045168f960a5c1dac8c5de29013" + "sha256": "67b1a8182cd20a445df7e9e94ab4d6ffdcd210f5362819fbf5f6d5b8182bcdad" }, "TeraFFI/scripts/verify-installed-artifacts.sh": { "bytes": 255, @@ -2700,10 +2922,10 @@ "sha256": "568ee230a99a907cc9063c203fbecc80e6ba4aca3db6c1e3af93abdbc904b7d5" }, "scripts/ffi_build.py": { - "bytes": 13121, - "git_blob": "0e4f11cd56003b562bccb90eeb30ca706a272863", + "bytes": 14912, + "git_blob": "3c56911a3d761ae12be76c8511903e4196b3755e", "mode": "100644", - "sha256": "eafe2189e97a436522fdf18909aa494392ab0347da28b338cc999b30044fc90d" + "sha256": "76ec2f8c38883c63709bfb2cce79dc5851533e981f41e7bd065c29ea69f7f4cf" }, "scripts/ffi_installed.py": { "bytes": 8207, @@ -2711,17 +2933,23 @@ "mode": "100644", "sha256": "2f14e83fe08d70b4c92361d9bccd08dd6c480eebd767a692a8b5f03fdb0e5380" }, + "scripts/ffi_native.py": { + "bytes": 17880, + "git_blob": "ee6f4024858b0fca71f6f6bb3f851b64ba52eb81", + "mode": "100644", + "sha256": "4b4ba6fd87c53b3d263404b4e1d62474fab27456f23574ce89af5f1f56871e37" + }, "scripts/ffi_provenance.py": { - "bytes": 6808, - "git_blob": "de2c086a110501f8bd11f1e5b26b2473c468ce28", + "bytes": 7683, + "git_blob": "d011914a27d88e08ff2d38f6841a8e948cb40a40", "mode": "100644", - "sha256": "2a1a89db83bfd1b1a2e80c1fbd31288dcf2f75a1439ba3446633c755dec0255f" + "sha256": "e88886ba1485e49585c6e595d6f2ce9a9211efc703b1087fe66668c2534ee985" }, "scripts/ffi_source.py": { - "bytes": 13564, - "git_blob": "42a767ceb4ee1e5f00be6d0f31101450a78c16e5", + "bytes": 14339, + "git_blob": "20cc49423ced887c47df7c9b29e4c6d8a3bd50fb", "mode": "100644", - "sha256": "49f7995b46c22c2c64c808e2bf3ff2d7d1041040697b1c3f61a4f07d021a7712" + "sha256": "62b2a12982e11f62f70e60b1f16cc1f164c2fdfd3ab915c92b9ea1dbf7ed6eca" }, "scripts/generate-project.sh": { "bytes": 2964, @@ -2736,10 +2964,10 @@ "sha256": "26046966bece8c811a5b3edef191e2ea5b5c4be3187cf65a29f7edbe93cbb487" }, "scripts/kotlin_smoke.py": { - "bytes": 10695, - "git_blob": "7e68d51111202626ff46d146b37cdebbf9121370", + "bytes": 11310, + "git_blob": "fd294e2b6e291624a52fc9276676ed471776f198", "mode": "100644", - "sha256": "48277943e29720c3713326990e74fd50c6e2c805cd7c6fd5b62b0016cfdac1ad" + "sha256": "c28be2b7d25dd5a19d8ca014f8e2f2e829fdf62f164a6436c0995427534e3e58" }, "scripts/kotlin_smoke/build.gradle.kts": { "bytes": 1479, @@ -2946,10 +3174,10 @@ "sha256": "1803572abdb2e22bedd275724edae5f09c523b132bc59086aacca0f5183905d0" }, "scripts/swift-quality.sh": { - "bytes": 2308, - "git_blob": "f07b465c125de12548d523a293a96a3837c1193d", + "bytes": 2459, + "git_blob": "13a1843e6ae14d91b2bffb8085bb2130dd74e5fc", "mode": "100755", - "sha256": "07cd900d465744eab373c07d90b954758732a0564cab42f7bd4df88dd42bdeee" + "sha256": "1e4f4e2f36e9ae476c88da975ba97fe7868ba11529d02ed76fa27ef4bc4fb99e" }, "scripts/test_app_dependency_graph.py": { "bytes": 4007, @@ -2958,10 +3186,10 @@ "sha256": "d336abd6368ad3b0d0171b32aaa4a44d9c1a8551899d39a1445eca05b67d8b30" }, "scripts/test_ffi_artifacts.py": { - "bytes": 7460, - "git_blob": "e933763e0f8329e5b97f9a5115b7fadf6504eb15", + "bytes": 10184, + "git_blob": "a1dd396b883ebe3c9933d19d9c2194103ed907b6", "mode": "100644", - "sha256": "b45a467dd04903f12550f7ad83ca438dee08e2113ba7146b7f4f1184e273d1f9" + "sha256": "5aa2802564104a5d32bcf322e52148ae2eb7d38379e3b10cf82dc657fd0a911c" }, "scripts/test_ffi_installed.py": { "bytes": 5140, @@ -2969,17 +3197,29 @@ "mode": "100644", "sha256": "1a60456d7780dfb26dbc71c3c3a07190f6d78c44521f264e0d8aa3ee41c7ff59" }, + "scripts/test_ffi_native.py": { + "bytes": 33161, + "git_blob": "bb0b05666d892062b496eadc36dfc35db16988d3", + "mode": "100644", + "sha256": "782dd020ef450d207e12896a9bb781edbecd25bc4b795df2664be102b05ae4b0" + }, + "scripts/test_ffi_native_cache.py": { + "bytes": 12040, + "git_blob": "528174a7c73739d30bf0defb5f774da7f088c5b2", + "mode": "100644", + "sha256": "4d930c13d3f6446073a87419d7a7ac91d01aadc31b19964789a261ba8699a5f6" + }, "scripts/test_ffi_provenance.py": { - "bytes": 11247, - "git_blob": "cc1140c5a4153ea2a9526a69a231ed65037209f7", + "bytes": 11856, + "git_blob": "0fe4fe8c93d72fcc1055e9c2bc6b8b2a54f06081", "mode": "100644", - "sha256": "cda3773df7ec0ed0c6bc508167f65f9f0a9a2f81ca461078c0313dbd57785584" + "sha256": "9cf479a3126635500c0d1b487b298769bc93f4894f08204b05e1b41308d532af" }, "scripts/test_kotlin_smoke.py": { - "bytes": 3609, - "git_blob": "0e3fb31aaba13316c533c166ea5bee4a5903fae8", + "bytes": 13269, + "git_blob": "eeb4ed3c56d16a0cea55c43645834a12c64c933e", "mode": "100644", - "sha256": "f97d7e8cea2fb18b5a4dc9b3f2ea20938343c363934471a5647fa5795204a34d" + "sha256": "2906c6a93678def240cc43042845dcecfdc2c2e5efc4bdad7600c693c9bc72ba" }, "scripts/test_legacy_identifiers.py": { "bytes": 6406, @@ -3029,17 +3269,29 @@ "mode": "100644", "sha256": "56797c8dd8b1e1efc3c1f469f86c542baecaf12db60bcc799585f475438379f5" }, + "scripts/test_unittest_report.py": { + "bytes": 33055, + "git_blob": "1e2b8a07baa061d13b70221fa725a8872d9be924", + "mode": "100644", + "sha256": "a1b1ef1ac7533bad0af80bf66790a8954aa990b279d8f417bd15e040f3bfb521" + }, "scripts/test_xcode_selection.py": { "bytes": 4745, "git_blob": "b633afbccd765a106e2ad591881926a9add542ac", "mode": "100644", "sha256": "a917dfbc1d8ecac7d1539670651e4b468059bc77dfe31aeefbc6c6eb21bebbfb" }, + "scripts/unittest_report.py": { + "bytes": 20276, + "git_blob": "319eb74779ee70a119e997979ac2d6a65d6b243b", + "mode": "100644", + "sha256": "c1bbdc3c0ad9df4679eb110f9e145b5e399e7e5f74298a56028f46ff1269ff98" + }, "scripts/verify-package-contract.sh": { - "bytes": 1663, - "git_blob": "76674ddf0dbdb54e39dd788bf8ad5515af47f1c8", + "bytes": 1730, + "git_blob": "a9e22505700f690dfaf8714eadad3c5128b9ecd4", "mode": "100755", - "sha256": "8798d003a8a0ac9e5aff6fc89093fd7af9f6de95a32be1c5e0391727a2461eb2" + "sha256": "836e0ab1fbf3535c8f26f4a3540fe6f51ccae7f78ebada79ca703dd4420d83f6" }, "scripts/xcode.sh": { "bytes": 22437, @@ -3055,6 +3307,6 @@ } }, "policy": "staged_inputs", - "tree": "16436eff2c5f2f69b6d2d767b1d0264bb9051992" + "tree": "a7f7ef68f86606405e16d5b51ecd57a8bdf02fd4" } } diff --git a/release/provenance.json b/release/provenance.json @@ -2,7 +2,7 @@ "artifacts": { "app_api_sha256": "020924097c0d7efc33128cb8fd3d3b2026d95f57c44da71880e585aff80f070b", "ffi_api_sha256": "5d74060f97e52dad69ab7567c16d6b6b34acfab846f468450d89e2394a8a69d5", - "ffi_provenance_sha256": "a24d7847393da41d7ae575e729e92a418d99401b937346df5e6c2afebebe2cb0", + "ffi_provenance_sha256": "78f1d4676995abec157170f19694169ac686b4c038da4640a5502d12ca638616", "info_plist_sha256": "b55010dd73b34bf5ad910a888be0ea1ae45f2a5c14329fa6a57059a317bdbd42", "privacy_manifest_sha256": "0f2103257ba596fbcaeb1d6a4dffe3ae021e84c010178852c6bf500a8cfb0f19", "sbom_sha256": "f0a15c2c9ad7799539fbc52fd1fdbcf17f4046b6f86cfe0a9b8980adc0079e10", @@ -22,7 +22,7 @@ "lib_revision": "189c49b74b4bafc142b00b76b296477931139e72", "source_date_epoch": 1787871027, "swift_package_lock_sha256": "8aec408132602a249111a65903c985cca5898ec316a45916d88ba756f08ea40d", - "tera_ffi_source_tree": "16436eff2c5f2f69b6d2d767b1d0264bb9051992", + "tera_ffi_source_tree": "a7f7ef68f86606405e16d5b51ecd57a8bdf02fd4", "xcode_package_lock_sha256": "3656728f8251f3ea644aa150d154819766470ca7bd4f85b7c51fdf301d361d16" }, "version": "0.1.0-alpha" diff --git a/scripts/ffi_build.py b/scripts/ffi_build.py @@ -3,6 +3,7 @@ from __future__ import annotations import argparse +import hashlib import json import os import plistlib @@ -16,6 +17,7 @@ from typing import Any import ffi_artifacts as artifacts import ffi_installed as installed +import ffi_native as native import ffi_provenance as provenance import ffi_source as source import package_contract as contract @@ -42,6 +44,7 @@ def build_environment( } environment = dict(os.environ) environment.pop("TERA_CONSUMER_REVISION", None) + environment.pop("DYLD_FALLBACK_LIBRARY_PATH", None) environment.update( { "CARGO_ENCODED_RUSTFLAGS": "\x1f".join( @@ -107,15 +110,22 @@ def library_command(root: Path, target: str, project: Path) -> list[str]: def build_libraries( - root: Path, bundle: Path, target_root: Path, logs: Path, env: dict[str, str] + root: Path, + bundle: Path, + target_root: Path, + logs: Path, + env: dict[str, str], + records: dict[str, dict[str, Any]], ) -> None: for target in artifacts.TARGETS: - run( + run_native( root, logs, "build-" + target, library_command(root, target, Path(env["EXT_BUILD_PROJECT_DIR"])), env, + records[target]["build"]["native"], + records[target]["generator"]["native"], ) extension = "dylib" if target == artifacts.TARGETS[-1] else "a" destination = bundle / "native" / target @@ -127,11 +137,15 @@ def build_libraries( def generate_bindings( - root: Path, bundle: Path, logs: Path, env: dict[str, str] + root: Path, + bundle: Path, + logs: Path, + env: dict[str, str], + host: dict[str, Any], ) -> None: generated = bundle / "generated" generated.mkdir() - run( + run_native( root, logs, "generate-swift", @@ -156,6 +170,8 @@ def generate_bindings( str(root / "core/crates/tera_ffi/uniffi.toml"), ], env, + host, + host, ) headers = bundle / "headers" headers.mkdir() @@ -164,9 +180,14 @@ def generate_bindings( def package_framework( - root: Path, bundle: Path, logs: Path, env: dict[str, str] + root: Path, + bundle: Path, + logs: Path, + env: dict[str, str], + context: dict[str, Any], + host: dict[str, Any], ) -> None: - argv = ["xcodebuild", "-create-xcframework"] + argv = [context["tools"]["xcodebuild"]["path"], "-create-xcframework"] for target in artifacts.TARGETS[:2]: argv += [ "-library", @@ -175,7 +196,7 @@ def package_framework( str(bundle / "headers"), ] argv += ["-output", str(bundle / artifacts.FRAMEWORK)] - run(root, logs, "package-xcframework", argv, env) + run_native(root, logs, "package-xcframework", argv, env, context, host) canonicalize_framework_info(bundle / artifacts.FRAMEWORK / "Info.plist") @@ -192,12 +213,10 @@ def generate_api( logs: Path, env: dict[str, str], deployment: str, + context: dict[str, Any], + host: dict[str, Any], ) -> None: - sdk = ( - source.command(root, ["xcrun", "--sdk", "iphonesimulator", "--show-sdk-path"]) - .decode() - .strip() - ) + sdk = context["sdk"]["path"] module = work / "module" symbols = work / "symbols" module.mkdir() @@ -214,15 +233,12 @@ def generate_api( "-module-cache-path", str(work / "module-cache"), ] - run( + run_native( root, logs, "compile-swift-module", [ - "xcrun", - "--sdk", - "iphonesimulator", - "swiftc", + context["tools"]["swiftc"]["path"], "-emit-module", "-parse-as-library", *common, @@ -231,16 +247,15 @@ def generate_api( str(bundle / "generated/TeraKitBindings.swift"), ], env, + context, + host, ) - run( + run_native( root, logs, "extract-swift-api", [ - "xcrun", - "--sdk", - "iphonesimulator", - "swift-symbolgraph-extract", + context["tools"]["swift_symbolgraph_extract"]["path"], *common, "-I", str(module), @@ -252,6 +267,8 @@ def generate_api( str(symbols), ], env, + context, + host, ) graph = json.loads((symbols / f"{artifacts.MODULE}.symbols.json").read_text()) output = normalize_api(graph) @@ -288,14 +305,23 @@ def normalize_api(graph: dict[str, Any]) -> dict[str, Any]: } -def record_abi(root: Path, bundle: Path, logs: Path, env: dict[str, str]) -> None: +def record_abi( + root: Path, + bundle: Path, + logs: Path, + env: dict[str, str], + records: dict[str, dict[str, Any]], +) -> None: symbols = {} reader = provenance.symbol_reader( root, source.producer_contract(root)["build"]["host"] ) for target in artifacts.TARGETS: + expected_reader = records[target]["build"]["symbol_reader_identity"] + if native.file_identity(reader) != expected_reader: + raise source.ProvenanceError("native symbol reader drift before use") extension = "dylib" if target == artifacts.TARGETS[-1] else "a" - log = run( + log = run_native( root, logs, "symbols-" + target, @@ -307,7 +333,11 @@ def record_abi(root: Path, bundle: Path, logs: Path, env: dict[str, str]) -> Non str(bundle / "native" / target / f"libtera_ffi.{extension}"), ], env, + records[target]["build"]["native"], + records[target]["generator"]["native"], ) + if native.file_identity(reader) != expected_reader: + raise source.ProvenanceError("native symbol reader drift after use") symbols[target] = sorted( set( re.findall( @@ -324,6 +354,29 @@ def capture_sources(root: Path) -> dict[str, dict[str, Any]]: return {target: provenance.capture(root, target) for target in artifacts.TARGETS} +def candidate_path(project: Path, records: dict[str, dict[str, Any]]) -> Path: + tree = records[artifacts.TARGETS[0]]["source"]["tree"] + identity = hashlib.sha256(provenance.encoded(records)).hexdigest() + return project / "target/tera_ffi/candidates" / (tree + "-" + identity) + + +def run_native( + root: Path, + logs: Path, + name: str, + argv: list[str], + environment: dict[str, str], + context: dict[str, Any], + host: dict[str, Any], +) -> Path: + bound = native.execution_environment(root, environment, context, host) + try: + return run(root, logs, name, argv, bound) + finally: + native.verify(root, context) + native.verify(root, host) + + def build( root: Path, project: Path, @@ -333,6 +386,8 @@ def build( ) -> dict[str, Any]: config = source.producer_contract(root) environment = build_environment(root, project, config) + host = records[native.HOST]["generator"]["native"] + simulator = records["aarch64-apple-ios-sim"]["build"]["native"] destination.parent.mkdir(parents=True, exist_ok=True) logs = Path(tempfile.mkdtemp(prefix="build-", dir=destination.parent)) # Logs survive failure. Only this invocation's temporary workspace is cleaned. @@ -342,9 +397,9 @@ def build( work = Path(temporary) bundle = work / "bundle" bundle.mkdir() - build_libraries(root, bundle, target_root, logs, environment) - generate_bindings(root, bundle, logs, environment) - package_framework(root, bundle, logs, environment) + build_libraries(root, bundle, target_root, logs, environment, records) + generate_bindings(root, bundle, logs, environment, host) + package_framework(root, bundle, logs, environment, simulator, host) generate_api( root, bundle, @@ -352,8 +407,10 @@ def build( logs, environment, config["build"]["ios_deployment_target"], + simulator, + host, ) - record_abi(root, bundle, logs, environment) + record_abi(root, bundle, logs, environment, records) if capture_sources(root) != records: raise source.ProvenanceError( "producer changed during native artifact build" @@ -389,7 +446,7 @@ def main() -> int: return 0 records = capture_sources(root) tree = records[artifacts.TARGETS[0]]["source"]["tree"] - destination = project / "target/tera_ffi/candidates" / tree + destination = candidate_path(project, records) if args.mode in ("build", "install") and not destination.exists(): build(root, project, target_root, records, destination) artifacts.check(destination, records) diff --git a/scripts/ffi_native.py b/scripts/ffi_native.py @@ -0,0 +1,506 @@ +"""Closed Apple C input policy and execution bindings for cc 1.4.0/SQLite 0.37.0. + +Inherited overrides are rejected by presence, including empty values. We never +flatten cc's priority-ordered tool selection or additive flags into one input. +CXX and CPPFLAGS are inactive in the current C graph. PATH is recorded by digest; +only public tool/SDK locations are exported, never arbitrary environment values. +""" + +from __future__ import annotations + +import hashlib +import json +import os +import shutil +import stat +import time +from pathlib import Path +from typing import Any + +import ffi_source as source + +TARGET_SDKS = { + "aarch64-apple-ios": "iphoneos", + "aarch64-apple-ios-sim": "iphonesimulator", + "aarch64-apple-darwin": "macosx", +} +HOST = "aarch64-apple-darwin" +TOOL_INPUTS = ("CC", "CFLAGS", "AR", "ARFLAGS", "RANLIB", "RANLIBFLAGS") +# cc 1.4.0 reads these global cargo_env_var_os controls with trim inheritance on. +TRIM_INPUTS = ("CARGO_TRIM_PATHS_SCOPE", "CARGO_TRIM_PATHS_REMAP") +PKG_INPUTS = ( + "PKG_CONFIG", + "PKG_CONFIG_PATH", + "PKG_CONFIG_LIBDIR", + "PKG_CONFIG_SYSROOT_DIR", + "PKG_CONFIG_ALLOW_CROSS", +) +DIRECT_INPUTS = ( + *TRIM_INPUTS, + "CC_KNOWN_WRAPPER_CUSTOM", + "CC_SHELL_ESCAPED_FLAGS", + "CRATE_CC_NO_DEFAULTS", + "CC_FORCE_DISABLE", + "CC_ENABLE_DEBUG_OUTPUT", + "CROSS_COMPILE", + "LIBSQLITE3_FLAGS", + "RING_PREGENERATE_ASM", + "SQLITE_MAX_VARIABLE_NUMBER", + "SQLITE_MAX_EXPR_DEPTH", + "SQLITE_MAX_COLUMN", + "LIBSQLITE3_SYS_USE_PKG_CONFIG", + "SQLITE3_LIB_DIR", + "SQLITE3_INCLUDE_DIR", + "SQLITE3_STATIC", + "SQLITE3_NO_PKG_CONFIG", + "SQLITE3_DYNAMIC", + "PKG_CONFIG_ALL_STATIC", + "PKG_CONFIG_ALL_DYNAMIC", + "PKG_CONFIG_ALLOW_SYSTEM_CFLAGS", + "PKG_CONFIG_ALLOW_SYSTEM_LIBS", + "SDKROOT", + "DEVELOPER_DIR", + "TOOLCHAINS", + "SDK_DIR", + "IPHONEOS_DEPLOYMENT_TARGET", + "MACOSX_DEPLOYMENT_TARGET", + "CPATH", + "C_INCLUDE_PATH", + "OBJC_INCLUDE_PATH", + "CPLUS_INCLUDE_PATH", + "OBJCPLUS_INCLUDE_PATH", + "LIBRARY_PATH", + "COMPILER_PATH", + "GCC_EXEC_PREFIX", + "CCC_OVERRIDE_OPTIONS", + "RC_DEBUG_OPTIONS", + "RC_CFLAGS", + "ZERO_AR_DATE", + "CLANG_CONFIG_FILE_SYSTEM_DIR", + "CLANG_CONFIG_FILE_USER_DIR", +) +PUBLIC_ROOTS = ( + Path("/Applications"), + Path("/Library/Developer"), + Path("/usr"), + Path("/opt/homebrew"), +) +# Streaming identity caps, independent of the unchanged 2 MiB source-file cap. +MAX_NATIVE_NODES = 100_000 +MAX_NATIVE_BYTES = 2_000_000_000 +MAX_INSPECTION_SECONDS = 120 +INSPECTION_LIMITS = { + "maximum_sdk_nodes": MAX_NATIVE_NODES, + "maximum_sdk_aggregate_bytes": MAX_NATIVE_BYTES, + "maximum_inspection_seconds": MAX_INSPECTION_SECONDS, + "stream_chunk_bytes": 65536, +} + + +def inherited_names() -> set[str]: + names = set(DIRECT_INPUTS) + for base in (*TOOL_INPUTS, *PKG_INPUTS): + names.update((base, "HOST_" + base, "TARGET_" + base)) + for target in TARGET_SDKS: + names.update((base + "_" + target, base + "_" + target.replace("-", "_"))) + return names + + +def reject_inherited(environment: dict[str, str]) -> None: + if inherited_names().intersection(environment): + raise source.ProvenanceError("ungoverned inherited native build input") + if any( + name.startswith("DYLD_") and name != "DYLD_FALLBACK_LIBRARY_PATH" + for name in environment + ): + raise source.ProvenanceError("ungoverned inherited Apple loader input") + + +def inherited_identity(environment: dict[str, str]) -> dict[str, Any]: + reject_inherited(environment) + path = environment.get("PATH", "") + if not path or len(path.encode()) > source.MAX_BYTES: + raise source.ProvenanceError("native search path is missing or exceeds bound") + result = { + "path_sha256": hashlib.sha256(path.encode()).hexdigest(), + "generator_profile_overrides": source.allowed_profile_overrides(), + } + fallback = environment.get("DYLD_FALLBACK_LIBRARY_PATH") + if fallback is not None: + result["removed_dyld_fallback_sha256"] = hashlib.sha256( + fallback.encode() + ).hexdigest() + return result + + +def inspection_environment() -> dict[str, str]: + environment = dict(os.environ) + reject_inherited(environment) + environment.pop("DYLD_FALLBACK_LIBRARY_PATH", None) + return environment + + +def public_path(value: str) -> Path: + path = Path(value) + if not path.is_absolute(): + raise source.ProvenanceError("native tool or SDK path is not absolute") + if ".." in path.parts or not any( + path.is_relative_to(root) for root in PUBLIC_ROOTS + ): + raise source.ProvenanceError("native tool or SDK path is not public") + try: + resolved = path.resolve(strict=True) + except (OSError, RuntimeError, ValueError): + raise source.ProvenanceError( + "native tool or SDK path cannot be resolved" + ) from None + if not any(resolved.is_relative_to(root) for root in PUBLIC_ROOTS): + raise source.ProvenanceError("native tool or SDK path is not public") + return resolved + + +def public_tool(value: str) -> Path: + public_path(value) + # Preserve the executable alias: Swift/ranlib dispatch by argv[0]. + return Path(value) + + +def check_deadline(deadline: float) -> None: + if time.monotonic() > deadline: + raise source.ProvenanceError("native identity exceeds inspection bound") + + +def file_stamp(path: Path) -> tuple[int, ...]: + return stat_stamp(path.stat(follow_symlinks=False)) + + +def stat_stamp(value: os.stat_result) -> tuple[int, ...]: + return ( + value.st_dev, + value.st_ino, + value.st_mode, + value.st_size, + value.st_mtime_ns, + value.st_ctime_ns, + ) + + +def file_identity(path: Path, deadline: float | None = None) -> dict[str, Any]: + if deadline is None: + deadline = time.monotonic() + MAX_INSPECTION_SECONDS + check_deadline(deadline) + descriptor = os.open(path, os.O_RDONLY | os.O_NOFOLLOW | os.O_NONBLOCK) + with os.fdopen(descriptor, "rb") as handle: + before = os.fstat(handle.fileno()) + if not stat.S_ISREG(before.st_mode) or before.st_size > MAX_NATIVE_BYTES: + raise source.ProvenanceError( + "native identity input is not bounded regular data" + ) + digest = hashlib.sha256() + count = 0 + while chunk := handle.read(65536): + check_deadline(deadline) + count += len(chunk) + if count > MAX_NATIVE_BYTES: + raise source.ProvenanceError("native identity input exceeds bound") + digest.update(chunk) + after = os.fstat(handle.fileno()) + if (after.st_ino, after.st_size, after.st_mtime_ns, after.st_ctime_ns) != ( + before.st_ino, + before.st_size, + before.st_mtime_ns, + before.st_ctime_ns, + ) or file_stamp(path)[:4] != ( + before.st_dev, + before.st_ino, + before.st_mode, + before.st_size, + ): + raise source.ProvenanceError("native identity input changed while reading") + check_deadline(deadline) + return {"sha256": digest.hexdigest(), "bytes": count} + + +def sdk_directory( + root: Path, directory: Path, inventory: dict[Path, tuple[int, ...]], deadline: float +) -> int: + check_deadline(deadline) + flags = os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW + descriptor = os.open(root, flags) + current = root + try: + if stat_stamp(os.fstat(descriptor)) != inventory[current]: + raise source.ProvenanceError("native SDK directory changed during capture") + for name in directory.relative_to(root).parts: + check_deadline(deadline) + child = os.open(name, flags, dir_fd=descriptor) + os.close(descriptor) + descriptor = child + current = current / name + if stat_stamp(os.fstat(descriptor)) != inventory[current]: + raise source.ProvenanceError( + "native SDK directory changed during capture" + ) + return descriptor + except BaseException: + os.close(descriptor) + raise + + +def sdk_entries( + root: Path, directory: Path, inventory: dict[Path, tuple[int, ...]], deadline: float +): + descriptor = sdk_directory(root, directory, inventory, deadline) + try: + with os.scandir(descriptor) as entries: + while True: + check_deadline(deadline) + try: + entry = next(entries) + except StopIteration: + return + check_deadline(deadline) + yield directory / entry.name + finally: + os.close(descriptor) + + +def sdk_inventory(path: Path, deadline: float) -> dict[Path, tuple[int, ...]]: + check_deadline(deadline) + if not stat.S_ISDIR(path.lstat().st_mode): + raise source.ProvenanceError("native SDK root is not a directory") + inventory = {path: file_stamp(path)} + pending = [path] + try: + while pending: + directory = pending.pop() + for entry in sdk_entries(path, directory, inventory, deadline): + if len(inventory) > MAX_NATIVE_NODES: + raise source.ProvenanceError( + "native SDK identity exceeds inspection bound" + ) + stamp = file_stamp(entry) + inventory[entry] = stamp + if stat.S_ISDIR(stamp[2]): + pending.append(entry) + except OSError: + raise source.ProvenanceError("native SDK enumeration failed") from None + return inventory + + +def sdk_identity(path: Path, deadline: float | None = None) -> dict[str, Any]: + digest = hashlib.sha256() + size = 0 + if deadline is None: + deadline = time.monotonic() + MAX_INSPECTION_SECONDS + inventory = sdk_inventory(path, deadline) + for entry in sorted(inventory): + check_deadline(deadline) + identity, count = sdk_entry(path, entry, deadline) + size += count + if size > MAX_NATIVE_BYTES: + raise source.ProvenanceError("native SDK identity exceeds byte bound") + digest.update(entry.relative_to(path).as_posix().encode() + b"\0" + identity) + if sdk_inventory(path, deadline) != inventory: + raise source.ProvenanceError("native SDK inventory changed during capture") + return { + "path": str(path), + "sha256": digest.hexdigest(), + "nodes": len(inventory) - 1, + "bytes": size, + } + + +def sdk_entry(root: Path, path: Path, deadline: float) -> tuple[bytes, int]: + mode = path.lstat().st_mode + if stat.S_ISLNK(mode): + if not path.resolve().is_relative_to(root): + raise source.ProvenanceError("native SDK link escapes its root") + return b"link\0" + os.readlink(path).encode(), 0 + if stat.S_ISDIR(mode): + return ("directory\0" + str(stat.S_IMODE(mode))).encode(), 0 + identity = file_identity(path, deadline) + return str(identity).encode(), identity["bytes"] + + +def tool_identity(path: Path, deadline: float | None = None) -> dict[str, Any]: + resolved = public_path(str(path)) + if not os.access(path, os.X_OK): + raise source.ProvenanceError("native tool is not executable") + return { + "path": str(path), + "resolved_path": str(resolved), + **file_identity(resolved, deadline), + } + + +def query( + root: Path, argv: list[str], environment: dict[str, str], deadline: float +) -> str: + check_deadline(deadline) + timeout = min(MAX_INSPECTION_SECONDS, deadline - time.monotonic()) + return ( + source.command(root, argv, environment=environment, timeout=timeout) + .decode() + .strip() + ) + + +def capture(root: Path, target: str) -> dict[str, Any]: + try: + return capture_apple(root, target) + except (OSError, UnicodeError, RuntimeError, ValueError): + raise source.ProvenanceError("native Apple input inspection failed") from None + + +def capture_apple(root: Path, target: str) -> dict[str, Any]: + deadline = time.monotonic() + MAX_INSPECTION_SECONDS + environment = dict(os.environ) + inherited = inherited_identity(environment) + environment.pop("DYLD_FALLBACK_LIBRARY_PATH", None) + if target not in TARGET_SDKS: + raise source.ProvenanceError("native target is not governed") + xcrun = public_tool(shutil.which("xcrun", path=environment["PATH"]) or "") + developer = public_path( + query(root, ["/usr/bin/xcode-select", "-p"], environment, deadline) + ) + environment["DEVELOPER_DIR"] = str(developer) + sdk = TARGET_SDKS[target] + tools = {"xcrun": tool_identity(xcrun, deadline)} + for key, name in ( + ("compiler", "clang"), + ("linker", "ld"), + ("archiver", "ar"), + ("ranlib", "ranlib"), + ("swiftc", "swiftc"), + ("swift_symbolgraph_extract", "swift-symbolgraph-extract"), + ("xcodebuild", "xcodebuild"), + ("swift_format", "swift-format"), + ("swift", "swift"), + ): + selected = query( + root, [str(xcrun), "--sdk", sdk, "--find", name], environment, deadline + ) + tools[key] = tool_identity(public_tool(selected), deadline) + formatter = public_tool(shutil.which("swiftformat", path=environment["PATH"]) or "") + tools["swiftformat"] = tool_identity(formatter, deadline) + sdk_path = public_path( + query( + root, [str(xcrun), "--sdk", sdk, "--show-sdk-path"], environment, deadline + ) + ) + resources = public_path( + query( + root, + [tools["compiler"]["path"], "-print-resource-dir"], + environment, + deadline, + ) + ) + result = { + "policy": "closed_apple_c_v1", + "target": target, + "sdk_name": sdk, + "inspection_limits": INSPECTION_LIMITS, + "inherited": inherited, + "developer_dir": str(developer), + "tools": tools, + "sdk": sdk_identity(sdk_path, deadline), + "compiler_resources": sdk_identity(resources, deadline), + "compiler_arguments": ["--no-default-config"], + "linker_driver_arguments": [ + "--no-default-config", + "-fuse-ld=" + tools["linker"]["path"], + ], + "sdk_version": query( + root, + [str(xcrun), "--sdk", sdk, "--show-sdk-version"], + environment, + deadline, + ), + "sdk_build": query( + root, + [str(xcrun), "--sdk", sdk, "--show-sdk-build-version"], + environment, + deadline, + ), + "deployment": {"IPHONEOS_DEPLOYMENT_TARGET": "18.0"} if target != HOST else {}, + } + if inherited_identity(dict(os.environ)) != inherited: + raise source.ProvenanceError("native environment changed during capture") + check_deadline(deadline) + return result + + +def verify(root: Path, context: dict[str, Any]) -> None: + if capture(root, context["target"]) != context: + raise source.ProvenanceError("native environment, tool or SDK drift") + + +def cache_identity(context: dict[str, Any], host: dict[str, Any]) -> str: + encoded = json.dumps( + {"target": context, "host": host}, sort_keys=True, separators=(",", ":") + ).encode() + return hashlib.sha256(encoded).hexdigest() + + +def execution_environment( + root: Path, + environment: dict[str, str], + context: dict[str, Any], + host: dict[str, Any], +) -> dict[str, str]: + # The caller already supplies governed Rust flags/deployment; reject only + # the ungoverned trim controls here, including keys absent from os.environ. + if set(TRIM_INPUTS).intersection(environment): + raise source.ProvenanceError("ungoverned inherited native build input") + verify(root, context) + verify(root, host) + result = dict(environment) + result.pop("DYLD_FALLBACK_LIBRARY_PATH", None) + # PATH is copied before execution, and its inherited identity must match capture. + if ( + hashlib.sha256(result["PATH"].encode()).hexdigest() + != context["inherited"]["path_sha256"] + ): + raise source.ProvenanceError( + "native execution search path differs from capture" + ) + result.update( + {"DEVELOPER_DIR": context["developer_dir"], "SDKROOT": context["sdk"]["path"]} + ) + result.pop("IPHONEOS_DEPLOYMENT_TARGET", None) + result.update(context["deployment"]) + if context["tools"]["linker"] != host["tools"]["linker"]: + raise source.ProvenanceError("native split host/target linker is not governed") + identity = cache_identity(context, host) + # The captured clang driver must dispatch to the captured ld, not a PATH fallback. + result["CARGO_ENCODED_RUSTFLAGS"] = "\x1f".join( + filter( + None, + ( + result.get("CARGO_ENCODED_RUSTFLAGS", ""), + '--cfg=tera_native_context="' + identity + '"', + "\x1f".join( + "-Clink-arg=" + argument + for argument in context["linker_driver_arguments"] + ), + ), + ) + ) + for selected in (host, context): + target = selected["target"] + # cc tracks CFLAGS via rerun-if-env-changed. Rust flags also bind Cargo + # units, including builders such as ring that suppress cc metadata. + result["CFLAGS_" + target] = " ".join( + [ + *selected["compiler_arguments"], + "-DTERA_NATIVE_CONTEXT_" + identity + "=1", + ] + ) + for name, key in (("CC", "compiler"), ("AR", "archiver"), ("RANLIB", "ranlib")): + result[name + "_" + target] = selected["tools"][key]["path"] + result["CARGO_TARGET_" + target.upper().replace("-", "_") + "_LINKER"] = ( + selected["tools"]["compiler"]["path"] + ) + return result diff --git a/scripts/ffi_provenance.py b/scripts/ffi_provenance.py @@ -12,6 +12,7 @@ from pathlib import Path from typing import Any import ffi_source as source +import ffi_native as native import package_contract as contract @@ -23,7 +24,12 @@ def capture(root: Path, target: str) -> dict[str, Any]: if target not in build["targets"]: raise source.ProvenanceError("producer target is not governed") snapshot = source.source_snapshot(root, config["source_inputs"]) - rustc = source.command(root, ["rustc", "-Vv"]).decode().strip() + native_target = native.capture(root, target) + native_host = native.capture(root, build["host"]) + environment = native.inspection_environment() + rustc = ( + source.command(root, ["rustc", "-Vv"], environment=environment).decode().strip() + ) if f"release: {build['rust_version']}\n" not in rustc + "\n": raise source.ProvenanceError( "active Rust compiler differs from producer contract" @@ -47,14 +53,23 @@ def capture(root: Path, target: str) -> dict[str, Any]: "package_rust_flags": source.library_rust_flags(build, target), "source_date_epoch": build["source_date_epoch"], "rustc": rustc, + "symbol_reader_identity": native.file_identity( + symbol_reader(root, build["host"]) + ), "symbol_reader": source.command( - root, [str(symbol_reader(root, build["host"])), "--version"] + root, + [str(symbol_reader(root, build["host"])), "--version"], + environment=environment, ) .decode() .strip(), "apple_toolchain": apple_toolchain(root), + "native": native_target, "feature_graph": source.feature_graph( - root, config["ffi"]["package"], target + root, + config["ffi"]["package"], + target, + environment=environment, ), }, "generator": { @@ -62,20 +77,32 @@ def capture(root: Path, target: str) -> dict[str, Any]: "target": build["host"], "profile": "dev", "profile_overrides": source.allowed_profile_overrides(), + "native": native_host, "feature_graph": source.feature_graph( - root, config["generator"]["package"], build["host"] + root, + config["generator"]["package"], + build["host"], + environment=environment, ), }, "disposition": "local_staged_source_only", } if source.source_snapshot(root, config["source_inputs"]) != snapshot: raise source.ProvenanceError("producer source changed during capture") + native.verify(root, native_target) + native.verify(root, native_host) return result def symbol_reader(root: Path, host: str) -> Path: sysroot = Path( - source.command(root, ["rustc", "--print", "sysroot"]).decode().strip() + source.command( + root, + ["rustc", "--print", "sysroot"], + environment=native.inspection_environment(), + ) + .decode() + .strip() ) reader = sysroot / "lib/rustlib" / host / "bin/llvm-nm" if not reader.is_file() or not os.access(reader, os.X_OK): @@ -97,7 +124,9 @@ def apple_toolchain(root: Path) -> dict[str, str]: ], } return { - name: source.command(root, argv).decode().strip() + name: source.command(root, argv, environment=native.inspection_environment()) + .decode() + .strip() for name, argv in commands.items() } diff --git a/scripts/ffi_source.py b/scripts/ffi_source.py @@ -34,12 +34,27 @@ class ProvenanceError(Exception): """A source-free, fail-closed provenance rejection.""" -def command(root: Path, argv: list[str], data: bytes | None = None) -> bytes: +def command( + root: Path, + argv: list[str], + data: bytes | None = None, + *, + environment: dict[str, str] | None = None, + timeout: float = 120, +) -> bytes: + if not 0 < timeout <= 120: + raise ProvenanceError("producer inspection deadline is expired or invalid") if argv[0] == "git": argv = ["git", "--no-replace-objects", *argv[1:]] try: result = subprocess.run( - argv, cwd=root, input=data, capture_output=True, check=False, timeout=120 + argv, + cwd=root, + input=data, + env=environment, + capture_output=True, + check=False, + timeout=timeout, ) except (OSError, subprocess.TimeoutExpired) as error: raise ProvenanceError("producer inspection command unavailable") from error @@ -70,6 +85,7 @@ def producer_contract(root: Path) -> dict[str, Any]: "ffi", "generator", "build", + "native", } contract._exact(set(value), expected, "producer contract fields") contract._exact(value["schema"], "tera.native-producer.v1", "producer schema") @@ -104,6 +120,11 @@ def producer_contract(root: Path) -> dict[str, Any]: "generator selection", ) validate_build(value["build"]) + import ffi_native + + contract._exact( + value["native"], ffi_native.INSPECTION_LIMITS, "native inspection limits" + ) cargo = contract._read_toml(root / "Cargo.toml") lock = contract._read_toml(root / value["foundation_lock"]) validate_foundation(cargo, lock) @@ -142,12 +163,18 @@ def validate_build(value: Any) -> None: "host_linker_reproducible", "host_oso_prefix", "targets", + "native_input_policy", }, "producer build fields", ) contract._exact(value["rust_version"], "1.97.1", "producer Rust version") contract._exact(value["profile"], "release", "producer build profile") contract._exact( + value["native_input_policy"], + "closed_apple_c_v1", + "producer native input policy", + ) + contract._exact( value["ios_deployment_target"], "18.0", "producer deployment target" ) contract._exact(value["host"], "aarch64-apple-darwin", "producer host") @@ -346,6 +373,9 @@ def tree_identity(tree: dict[str, Any]) -> str: def reject_build_overrides() -> None: + import ffi_native + + ffi_native.reject_inherited(os.environ) forbidden = ( "RUSTFLAGS", "RUSTC", @@ -383,7 +413,9 @@ def allowed_profile_overrides() -> dict[str, str]: return {} -def feature_graph(root: Path, package: str, target: str) -> list[str]: +def feature_graph( + root: Path, package: str, target: str, *, environment: dict[str, str] | None = None +) -> list[str]: raw = command( root, [ @@ -402,5 +434,6 @@ def feature_graph(root: Path, package: str, target: str) -> list[str]: "--format", "{p}|{f}", ], + environment=environment, ).decode() return sorted(set(raw.replace(str(root), "<producer-root>").splitlines())) diff --git a/scripts/kotlin_smoke.py b/scripts/kotlin_smoke.py @@ -15,9 +15,11 @@ from pathlib import Path from typing import Any import ffi_artifacts as artifacts +import ffi_build as builder import ffi_installed as installed import ffi_provenance as provenance import ffi_source as source +import package_contract as contract HARNESS = "scripts/kotlin_smoke" HOST = "aarch64-apple-darwin" @@ -114,8 +116,22 @@ def native_input( ) -> tuple[dict[str, Any], Path, dict[str, Any]]: manifest = installed.check(root) candidate = manifest["candidate"] - tree = candidate["source"]["tree"] - base = output.parent / "tera_ffi/candidates" / tree + records = { + target: contract._read_json(root / "TeraFFI/source" / f"{target}.json") + for target in artifacts.TARGETS + } + for target, record in records.items(): + data = provenance.encoded(record) + require( + { + "path": f"source/{target}.json", + "bytes": len(data), + "sha256": hashlib.sha256(data).hexdigest(), + } + in candidate["files"], + "Kotlin smoke source record does not match the installed producer", + ) + base = builder.candidate_path(output.parent.parent, records) require(base.resolve() == base, "Kotlin native candidate contains a symlink") record = artifacts.file_record(base, LIBRARY) require( @@ -271,6 +287,7 @@ def main() -> int: ET.ParseError, subprocess.SubprocessError, source.ProvenanceError, + contract.PackageContractError, ) as error: print(f"Kotlin binding smoke failed: {error}", file=sys.stderr) return 1 diff --git a/scripts/swift-quality.sh b/scripts/swift-quality.sh @@ -22,6 +22,11 @@ readonly -a MAINTAINABILITY_RULES=( ) readonly -a PYTHON_QUALITY_PATHS=( scripts/ffi_source.py + scripts/ffi_native.py + scripts/test_ffi_native.py + scripts/test_ffi_native_cache.py + scripts/unittest_report.py + scripts/test_unittest_report.py scripts/ffi_artifacts.py scripts/ffi_build.py scripts/ffi_installed.py diff --git a/scripts/test_ffi_artifacts.py b/scripts/test_ffi_artifacts.py @@ -129,6 +129,28 @@ class NativeArtifactTests(unittest.TestCase): with self.assertRaisesRegex(source.ProvenanceError, "tuples disagree"): artifacts.check(self.root, records) + def test_complete_tuple_candidates_coexist_without_cache_cleaning(self) -> None: + original = builder.candidate_path(self.root, self.records) + self.assertEqual(original, builder.candidate_path(self.root, self.records)) + original.mkdir(parents=True) + (original / "preserved").write_text("old native tuple") + for section in ("build", "generator"): + changed = copy.deepcopy(self.records) + changed[artifacts.TARGETS[0]].setdefault(section, {})["native"] = { + "sdk": "changed native tuple" + } + with self.subTest(section=section): + candidate = builder.candidate_path(self.root, changed) + self.assertNotEqual(candidate, original) + self.assertEqual( + changed[artifacts.TARGETS[0]]["source"]["tree"], + self.records[artifacts.TARGETS[0]]["source"]["tree"], + ) + candidate.mkdir() + self.assertEqual( + (original / "preserved").read_text(), "old native tuple" + ) + def test_cross_target_abi_mismatch_is_rejected(self) -> None: symbols = contract._read_json(self.root / "abi_symbols.json") symbols[artifacts.TARGETS[0]] = ["ffi_tera_ffi_other"] @@ -166,6 +188,44 @@ class NativeArtifactTests(unittest.TestCase): environment["SOURCE_DATE_EPOCH"], str(config["build"]["source_date_epoch"]) ) + def test_abi_symbol_reader_digest_drift_rejects_before_and_after_use(self) -> None: + import ffi_native as native + + reader = self.root / "reader" + original = b"synthetic symbol reader" + reader.write_bytes(original) + records = copy.deepcopy(self.records) + for record in records.values(): + record["build"].update( + {"symbol_reader_identity": native.file_identity(reader), "native": {}} + ) + record["generator"] = {"native": {}} + + def changed_after_run(*args): + reader.write_bytes(b"changed reader") + log = self.root / "symbols.txt" + log.write_text("_ffi_tera_ffi_fixture\n") + return log + + with patch.object(provenance, "symbol_reader", return_value=reader): + reader.write_bytes(b"changed reader") + with patch.object(builder, "run_native") as run: + with self.assertRaisesRegex( + source.ProvenanceError, "reader drift before" + ): + builder.record_abi( + SCRIPTS.parent, self.root, self.root, {}, records + ) + run.assert_not_called() + reader.write_bytes(original) + with patch.object(builder, "run_native", side_effect=changed_after_run): + with self.assertRaisesRegex( + source.ProvenanceError, "reader drift after" + ): + builder.record_abi( + SCRIPTS.parent, self.root, self.root, {}, records + ) + if __name__ == "__main__": unittest.main() diff --git a/scripts/test_ffi_native.py b/scripts/test_ffi_native.py @@ -0,0 +1,773 @@ +"""Native input guards and real filesystem/subprocess controls; no artifact claims.""" + +from __future__ import annotations + +import copy +import json +import itertools +import os +import subprocess +import sys +import tempfile +import unittest +from pathlib import Path +from unittest.mock import patch + +SCRIPTS = Path(__file__).resolve().parent +if str(SCRIPTS) not in sys.path: + sys.path.insert(0, str(SCRIPTS)) + +import ffi_build as builder # noqa: E402 +import ffi_native as native # noqa: E402 +import ffi_source as source # noqa: E402 + + +# Literal cc 1.4.0 cargo_env_var_os inputs, independent of the production list. +CARGO_TRIM_OVERRIDES = ( + {"CARGO_TRIM_PATHS_SCOPE": ""}, + {"CARGO_TRIM_PATHS_SCOPE": "macro"}, + {"CARGO_TRIM_PATHS_REMAP": ""}, + {"CARGO_TRIM_PATHS_REMAP": "native.c=C137_REMAPPED"}, + {"CARGO_TRIM_PATHS_SCOPE": "", "CARGO_TRIM_PATHS_REMAP": ""}, + {"CARGO_TRIM_PATHS_SCOPE": "", "CARGO_TRIM_PATHS_REMAP": "native.c=C137_REMAPPED"}, + {"CARGO_TRIM_PATHS_SCOPE": "all", "CARGO_TRIM_PATHS_REMAP": ""}, + { + "CARGO_TRIM_PATHS_SCOPE": "all", + "CARGO_TRIM_PATHS_REMAP": "native.c=C137_REMAPPED", + }, +) + + +class NativePublicPathTests(unittest.TestCase): + """Actual private aliases with the unchanged production public roots.""" + + def setUp(self) -> None: + temporary = tempfile.TemporaryDirectory(prefix="C137_PRIVATE_PATH_SENTINEL-") + self.addCleanup(temporary.cleanup) + self.alias = Path(temporary.name).resolve() / "clang" + self.alias.symlink_to("/usr/bin/clang") + self.assertFalse(any(self.alias.is_relative_to(p) for p in native.PUBLIC_ROOTS)) + self.assertTrue( + any(self.alias.resolve().is_relative_to(p) for p in native.PUBLIC_ROOTS) + ) + + def assert_private_rejection(self, path: Path) -> None: + for helper in (native.public_path, native.public_tool, native.tool_identity): + with self.subTest(helper=helper.__name__): + with self.assertRaises(source.ProvenanceError) as failure: + helper(path if helper is native.tool_identity else str(path)) + self.assertNotIn(str(path), str(failure.exception)) + self.assertNotIn("C137_PRIVATE_PATH_SENTINEL", str(failure.exception)) + + def test_real_private_alias_to_public_tool_rejects_without_private_diagnostic( + self, + ) -> None: + self.assert_private_rejection(self.alias) + + def test_public_prefix_traversal_to_private_alias_rejects_without_diagnostic( + self, + ) -> None: + path = Path("/usr/..") / self.alias.relative_to("/") + self.assertTrue(path.is_relative_to(Path("/usr"))) + normalized = Path(os.path.normpath(path)) + self.assertFalse(any(normalized.is_relative_to(p) for p in native.PUBLIC_ROOTS)) + self.assert_private_rejection(path) + + def test_traversal_rejects_even_when_resolved_tool_is_public(self) -> None: + self.assert_private_rejection(Path("/usr/bin/../bin/clang")) + + def test_real_public_tools_keep_selected_path_and_public_resolved_identity( + self, + ) -> None: + for name in ("clang", "ranlib"): + with self.subTest(tool=name): + path = Path("/usr/bin") / name + self.assertEqual(native.public_tool(str(path)), path) + identity = native.tool_identity(path) + self.assertEqual(identity["path"], str(path)) + self.assertEqual(identity["resolved_path"], str(path.resolve())) + self.assertTrue( + any( + Path(identity["resolved_path"]).is_relative_to(p) + for p in native.PUBLIC_ROOTS + ) + ) + + +class NativeInputTests(unittest.TestCase): + def test_literal_cargo_trim_inputs_reject_source_policy(self) -> None: + for overrides in CARGO_TRIM_OVERRIDES: + with ( + self.subTest(overrides=overrides), + patch.dict(os.environ, overrides, clear=True), + ): + with self.assertRaisesRegex( + source.ProvenanceError, "^ungoverned inherited native build input$" + ): + source.reject_build_overrides() + + def test_literal_cargo_trim_inputs_reject_inspection_environment(self) -> None: + for overrides in CARGO_TRIM_OVERRIDES: + with ( + self.subTest(overrides=overrides), + patch.dict(os.environ, overrides, clear=True), + ): + with self.assertRaisesRegex( + source.ProvenanceError, "^ungoverned inherited native build input$" + ): + native.inspection_environment() + + def test_literal_cargo_trim_inputs_reject_build_before_config_read(self) -> None: + config = source.producer_contract(SCRIPTS.parent) + for overrides in CARGO_TRIM_OVERRIDES: + with ( + self.subTest(overrides=overrides), + patch.dict(os.environ, overrides, clear=True), + patch.object( + builder.contract, "_read_toml", return_value={"revision": "a" * 40} + ) as read, + ): + with self.assertRaisesRegex( + source.ProvenanceError, "^ungoverned inherited native build input$" + ): + builder.build_environment(SCRIPTS.parent, Path("/external"), config) + read.assert_not_called() + + def test_cc_cargo_trim_names_do_not_invent_host_or_target_variants(self) -> None: + for name in ("CARGO_TRIM_PATHS_SCOPE", "CARGO_TRIM_PATHS_REMAP"): + for variant in ( + "HOST_" + name, + "TARGET_" + name, + name + "_aarch64-apple-ios", + name + "_aarch64_apple_ios", + ): + with self.subTest(variant=variant): + native.reject_inherited({variant: "inactive cc input"}) + + def test_every_supported_input_variant_rejects_empty_and_nonempty(self) -> None: + for name in sorted(native.inherited_names()): + for value in ("", "unrecorded"): + with self.subTest(name=name, empty=not value): + with patch.dict(os.environ, {name: value}, clear=True): + with self.assertRaisesRegex( + source.ProvenanceError, "ungoverned" + ): + source.reject_build_overrides() + + def test_tool_precedence_and_additive_flag_inputs_are_never_flattened(self) -> None: + for target in native.TARGET_SDKS: + for base in native.TOOL_INPUTS: + names = ( + base, + "HOST_" + base, + "TARGET_" + base, + base + "_" + target.replace("-", "_"), + base + "_" + target, + ) + for winner in names: + environment = {name: "lower" for name in names} + environment[winner] = "" + with self.subTest(target=target, base=base, winner=winner): + with self.assertRaises(source.ProvenanceError): + native.reject_inherited(environment) + + def test_inactive_cpp_and_other_target_controls_do_not_invent_inputs(self) -> None: + environment = { + "CXX": "inactive", + "CPPFLAGS": "inactive", + "CC_wasm32_unknown_unknown": "inactive", + } + native.reject_inherited(environment) + + def test_ring_pregeneration_is_rejected_for_every_presence_sensitive_value( + self, + ) -> None: + for value in ("", "0", "1", "malformed"): + with self.subTest(value=value), self.assertRaises(source.ProvenanceError): + native.reject_inherited({"RING_PREGENERATE_ASM": value}) + + def test_uv_fallback_is_bound_by_digest_and_other_loader_controls_reject( + self, + ) -> None: + base = {"PATH": "/public/tools"} + first = native.inherited_identity(base) + second = native.inherited_identity( + {**base, "DYLD_FALLBACK_LIBRARY_PATH": "sentinel"} + ) + self.assertNotEqual(first, second) + self.assertNotIn("sentinel", json.dumps(second)) + for key in ( + "DYLD_LIBRARY_PATH", + "DYLD_INSERT_LIBRARIES", + "DYLD_FRAMEWORK_PATH", + ): + with self.subTest(key=key), self.assertRaises(source.ProvenanceError): + native.inherited_identity({**base, key: ""}) + + def test_missing_or_unbounded_path_is_rejected(self) -> None: + for value in ("", "x" * (source.MAX_BYTES + 1)): + with ( + self.subTest(empty=not value), + self.assertRaises(source.ProvenanceError), + ): + native.inherited_identity({"PATH": value}) + + def test_extbuild_allowed_generator_debug_policy_is_preserved(self) -> None: + with patch.dict( + os.environ, + { + "EXT_BUILD_RUN_ACTIVE": "1", + "CARGO_PROFILE_DEV_DEBUG": "line-tables-only", + }, + clear=True, + ): + source.reject_build_overrides() + self.assertEqual( + source.allowed_profile_overrides(), + {"CARGO_PROFILE_DEV_DEBUG": "line-tables-only"}, + ) + + +class NativeBindingTests(unittest.TestCase): + def setUp(self) -> None: + temporary = tempfile.TemporaryDirectory() + self.addCleanup(temporary.cleanup) + self.root = Path(temporary.name).resolve() + self.tools = self.root / "bin" + self.tools.mkdir() + for name in ( + "xcrun", + "clang", + "ld", + "ar", + "libtool", + "swift-frontend", + "xcodebuild", + "swiftformat", + "swift-format", + "swift", + ): + tool = self.tools / name + tool.write_text("synthetic tool identity: " + name) + tool.chmod(0o755) + for alias, target in ( + ("ranlib", "libtool"), + ("swiftc", "swift-frontend"), + ("swift-symbolgraph-extract", "swift-frontend"), + ): + (self.tools / alias).symlink_to(target) + self.sdks = {} + self.resources = self.root / "resources" + self.resources.mkdir() + (self.resources / "stddef.h").write_text("/* clang resources */") + for name in native.TARGET_SDKS.values(): + sdk = self.root / name + sdk.mkdir() + (sdk / "SDKSettings.json").write_text('{"Version":"26.5"}') + (sdk / "header.h").write_text("/* governed SDK */") + self.sdks[name] = sdk + self.environment = { + "PATH": str(self.tools), + "EXT_BUILD_RUN_ACTIVE": "1", + "CARGO_PROFILE_DEV_DEBUG": "line-tables-only", + "DYLD_FALLBACK_LIBRARY_PATH": "private-sentinel", + } + self.addCleanup(patch.stopall) + patch.dict(os.environ, self.environment, clear=True).start() + patch.object(native, "PUBLIC_ROOTS", (self.root,)).start() + patch.object(source, "command", side_effect=self.query).start() + + def query(self, root: Path, argv: list[str], **kwargs) -> bytes: + self.assertEqual(root, self.root) + self.assertNotIn("DYLD_FALLBACK_LIBRARY_PATH", kwargs["environment"]) + if argv[0] == "/usr/bin/xcode-select": + return str(self.root).encode() + if "-print-resource-dir" in argv: + return str(self.resources).encode() + sdk = argv[argv.index("--sdk") + 1] + if "--find" in argv: + return str(self.tools / argv[-1]).encode() + if "--show-sdk-path" in argv: + return str(self.sdks[sdk]).encode() + if "--show-sdk-version" in argv: + return b"26.5" + if "--show-sdk-build-version" in argv: + return b"test-sdk-build" + self.fail("unexpected synthetic query") + + def capture(self, target: str) -> dict: + return native.capture(self.root, target) + + def test_public_fixture_aliases_retain_actual_argv0_dispatch(self) -> None: + # These existing synthetic tools use explicitly substituted fixture roots. + dispatch = ( + f"#!{sys.executable}\nimport os,sys\nprint(os.path.basename(sys.argv[0]))\n" + ) + for name in ("libtool", "swift-frontend"): + (self.tools / name).write_text(dispatch) + for name in ("ranlib", "swiftc", "swift-symbolgraph-extract"): + with self.subTest(tool=name): + alias = self.tools / name + selected = native.public_tool(str(alias)) + self.assertEqual(selected, alias) + self.assertNotEqual(selected, alias.resolve()) + identity = native.tool_identity(selected) + self.assertEqual(identity["path"], str(alias)) + self.assertEqual(identity["resolved_path"], str(alias.resolve())) + result = subprocess.run( + [str(selected)], + check=True, + capture_output=True, + text=True, + timeout=30, + env=native.inspection_environment(), + ) + self.assertEqual(result.stdout.strip(), name) + + def test_literal_cargo_trim_capture_rejects_before_tool_queries(self) -> None: + for overrides in CARGO_TRIM_OVERRIDES: + with self.subTest(overrides=overrides), patch.dict(os.environ, overrides): + source.command.reset_mock() + with self.assertRaisesRegex( + source.ProvenanceError, "^ungoverned inherited native build input$" + ): + self.capture(native.HOST) + source.command.assert_not_called() + + def test_literal_cargo_trim_introduction_rejects_after_initial_capture( + self, + ) -> None: + context = self.capture(native.HOST) + for overrides in CARGO_TRIM_OVERRIDES: + with self.subTest(overrides=overrides), patch.dict(os.environ, overrides): + source.command.reset_mock() + with self.assertRaisesRegex( + source.ProvenanceError, "^ungoverned inherited native build input$" + ): + native.verify(self.root, context) + source.command.assert_not_called() + + def test_literal_cargo_trim_in_execution_dictionary_rejects_with_clean_ambient( + self, + ) -> None: + context = self.capture("aarch64-apple-ios") + host = self.capture(native.HOST) + for overrides in CARGO_TRIM_OVERRIDES: + with self.subTest(overrides=overrides): + self.assertNotIn("CARGO_TRIM_PATHS_SCOPE", os.environ) + self.assertNotIn("CARGO_TRIM_PATHS_REMAP", os.environ) + environment = { + **self.environment, + **overrides, + "CARGO_ENCODED_RUSTFLAGS": "--remap-path-prefix=/fixture=/tera", + "IPHONEOS_DEPLOYMENT_TARGET": "18.0", + } + source.command.reset_mock() + with self.assertRaisesRegex( + source.ProvenanceError, "^ungoverned inherited native build input$" + ): + native.execution_environment(self.root, environment, context, host) + source.command.assert_not_called() + + def test_clean_owned_build_environment_retains_governed_flags_and_deployment( + self, + ) -> None: + config = source.producer_contract(SCRIPTS.parent) + environment = builder.build_environment(SCRIPTS.parent, self.root, config) + host = self.capture(native.HOST) + for target in native.TARGET_SDKS: + with self.subTest(target=target): + context = self.capture(target) + bound = native.execution_environment( + self.root, environment, context, host + ) + self.assertTrue( + bound["CARGO_ENCODED_RUSTFLAGS"].startswith( + environment["CARGO_ENCODED_RUSTFLAGS"] + "\x1f" + ) + ) + self.assertEqual( + bound["SOURCE_DATE_EPOCH"], environment["SOURCE_DATE_EPOCH"] + ) + self.assertEqual(bound["CARGO_PROFILE_DEV_DEBUG"], "line-tables-only") + self.assertNotIn("DYLD_FALLBACK_LIBRARY_PATH", bound) + self.assertNotIn("MACOSX_DEPLOYMENT_TARGET", bound) + if target == native.HOST: + self.assertNotIn("IPHONEOS_DEPLOYMENT_TARGET", bound) + else: + self.assertEqual(bound["IPHONEOS_DEPLOYMENT_TARGET"], "18.0") + + def test_all_targets_and_independent_generator_bind_real_alias_and_sdk_bytes( + self, + ) -> None: + host = self.capture(native.HOST) + for target, sdk in native.TARGET_SDKS.items(): + with self.subTest(target=target): + context = self.capture(target) + self.assertEqual(context, self.capture(target)) + self.assertEqual(context["sdk"]["path"], str(self.sdks[sdk])) + self.assertEqual( + context["tools"]["ranlib"]["path"], str(self.tools / "ranlib") + ) + self.assertEqual( + context["tools"]["ranlib"]["resolved_path"], + str(self.tools / "libtool"), + ) + self.assertEqual( + context["tools"]["swiftc"]["path"], str(self.tools / "swiftc") + ) + bound = native.execution_environment( + self.root, self.environment, context, host + ) + self.assertEqual(bound["SDKROOT"], str(self.sdks[sdk])) + self.assertEqual(bound["PATH"], self.environment["PATH"]) + self.assertEqual(bound["CARGO_PROFILE_DEV_DEBUG"], "line-tables-only") + self.assertNotIn("DYLD_FALLBACK_LIBRARY_PATH", bound) + self.assertNotIn("MACOSX_DEPLOYMENT_TARGET", bound) + for selected in (target, native.HOST): + self.assertEqual(bound["CC_" + selected], str(self.tools / "clang")) + self.assertEqual(bound["AR_" + selected], str(self.tools / "ar")) + self.assertEqual( + bound["RANLIB_" + selected], str(self.tools / "ranlib") + ) + if target == native.HOST: + self.assertNotIn("IPHONEOS_DEPLOYMENT_TARGET", bound) + else: + self.assertEqual(bound["IPHONEOS_DEPLOYMENT_TARGET"], "18.0") + + def test_changed_tools_sdk_and_selection_are_fenced_before_execution(self) -> None: + context = self.capture("aarch64-apple-ios") + for path in ( + self.tools / "clang", + self.tools / "ld", + self.tools / "ar", + self.tools / "libtool", + self.tools / "swift-frontend", + self.tools / "xcodebuild", + self.tools / "swiftformat", + self.sdks["iphoneos"] / "header.h", + self.resources / "stddef.h", + ): + original = path.read_bytes() + path.write_bytes(original + b"changed") + with ( + self.subTest(tool=path.name), + self.assertRaisesRegex(source.ProvenanceError, "drift"), + ): + native.verify(self.root, context) + path.write_bytes(original) + changed = copy.deepcopy(context) + changed["sdk"]["path"] = str(self.sdks["macosx"]) + with self.assertRaisesRegex(source.ProvenanceError, "drift"): + native.verify(self.root, changed) + + def test_environment_presence_and_path_changes_are_fenced(self) -> None: + context = self.capture(native.HOST) + for overrides in ( + {"PATH": str(self.tools) + ":/different"}, + {"DYLD_FALLBACK_LIBRARY_PATH": "changed"}, + {"LIBSQLITE3_SYS_USE_PKG_CONFIG": ""}, + {"DEVELOPER_DIR": ""}, + {"CARGO_PROFILE_DEV_DEBUG": "different"}, + ): + with ( + self.subTest(keys=sorted(overrides)), + patch.dict(os.environ, overrides), + ): + with self.assertRaises(source.ProvenanceError): + native.verify(self.root, context) + + def test_native_stage_executes_captured_environment_in_a_real_child(self) -> None: + host = self.capture(native.HOST) + for target in (*native.TARGET_SDKS, native.HOST): + context = self.capture(target) + log = builder.run_native( + self.root, + self.root, + "child-" + target, + [ + sys.executable, + "-c", + "import json,os; print(json.dumps(dict(os.environ)))", + ], + self.environment, + context, + host, + ) + observed = json.loads(log.read_text()) + self.assertEqual(observed["SDKROOT"], context["sdk"]["path"]) + self.assertEqual( + observed["CC_" + target], context["tools"]["compiler"]["path"] + ) + self.assertEqual( + observed[ + "CARGO_TARGET_" + target.upper().replace("-", "_") + "_LINKER" + ], + context["tools"]["compiler"]["path"], + ) + self.assertIn( + context["tools"]["linker"]["path"], observed["CARGO_ENCODED_RUSTFLAGS"] + ) + + def test_target_and_host_sdk_changes_bind_both_c_and_rust_cache_inputs( + self, + ) -> None: + target = self.capture("aarch64-apple-ios") + host = self.capture(native.HOST) + original = native.execution_environment( + self.root, self.environment, target, host + ) + repeated = native.execution_environment( + self.root, self.environment, target, host + ) + self.assertEqual(original, repeated) + for sdk, selected in (("iphoneos", "target"), ("macosx", "host")): + with self.subTest(selected=selected): + (self.sdks[sdk] / "header.h").write_text("changed SDK context " + sdk) + target = self.capture("aarch64-apple-ios") + host = self.capture(native.HOST) + changed = native.execution_environment( + self.root, self.environment, target, host + ) + for key in ( + "CFLAGS_aarch64-apple-ios", + "CFLAGS_aarch64-apple-darwin", + "CARGO_ENCODED_RUSTFLAGS", + ): + self.assertNotEqual(changed[key], original[key]) + self.assertIn( + "--no-default-config", changed["CFLAGS_aarch64-apple-ios"] + ) + self.assertEqual(changed["PATH"], original["PATH"]) + original = changed + + def test_postbuild_sdk_drift_rejects_real_child_result(self) -> None: + context = self.capture(native.HOST) + path = self.sdks["macosx"] / "header.h" + code = ( + "from pathlib import Path; Path(" + + repr(str(path)) + + ").write_text('changed')" + ) + with self.assertRaisesRegex(source.ProvenanceError, "drift"): + builder.run_native( + self.root, + self.root, + "postbuild-drift", + [sys.executable, "-c", code], + self.environment, + context, + context, + ) + self.assertTrue((self.root / "postbuild-drift.txt").is_file()) + + def test_bad_tool_path_or_permissions_reject_without_echoing_path(self) -> None: + with self.assertRaisesRegex(source.ProvenanceError, "not absolute"): + native.public_path("private-sentinel") + with self.assertRaisesRegex(source.ProvenanceError, "not public"): + native.public_path("/bin/sh") + path = self.tools / "ar" + path.chmod(0o644) + with self.assertRaisesRegex(source.ProvenanceError, "not executable"): + native.tool_identity(path) + + def test_sdk_symlink_escape_and_nonregular_file_reject(self) -> None: + sdk = self.sdks["iphoneos"] + (sdk / "link").symlink_to(self.tools / "clang") + with self.assertRaisesRegex(source.ProvenanceError, "escapes"): + native.sdk_identity(sdk) + (sdk / "link").unlink() + os.mkfifo(sdk / "fifo") + with self.assertRaisesRegex(source.ProvenanceError, "regular"): + native.sdk_identity(sdk) + + def test_sdk_node_and_aggregate_byte_limits_exact_and_one_over(self) -> None: + sdk = self.sdks["iphoneos"] + size = sum(path.stat().st_size for path in sdk.iterdir()) + with ( + patch.object(native, "MAX_NATIVE_NODES", 2), + patch.object(native, "MAX_NATIVE_BYTES", size), + ): + self.assertEqual(native.sdk_identity(sdk)["nodes"], 2) + self.assertEqual(native.sdk_identity(sdk)["bytes"], size) + with patch.object(native, "MAX_NATIVE_NODES", 1): + with self.assertRaisesRegex(source.ProvenanceError, "inspection bound"): + native.sdk_identity(sdk) + with patch.object(native, "MAX_NATIVE_BYTES", size - 1): + with self.assertRaisesRegex(source.ProvenanceError, "byte bound"): + native.sdk_identity(sdk) + + def test_sdk_inspection_deadline_is_bounded(self) -> None: + with patch.object( + native.time, + "monotonic", + side_effect=itertools.chain([0], itertools.repeat(120)), + ): + native.sdk_identity(self.sdks["iphoneos"]) + with patch.object(native.time, "monotonic", side_effect=[0, 121]): + with self.assertRaisesRegex(source.ProvenanceError, "inspection bound"): + native.sdk_identity(self.sdks["iphoneos"]) + + def test_long_stream_is_fenced_within_chunks(self) -> None: + path = self.sdks["iphoneos"] / "header.h" + with patch.object(native.time, "monotonic", side_effect=[0, 0, 121]): + with self.assertRaisesRegex(source.ProvenanceError, "inspection bound"): + native.file_identity(path) + + def test_stream_detects_content_mutation_at_descriptor_settlement(self) -> None: + path = self.sdks["iphoneos"] / "header.h" + stamp = native.file_stamp + + def changed_stamp(selected): + selected.write_bytes(b"changed while reading") + return stamp(selected) + + with patch.object(native, "file_stamp", side_effect=changed_stamp): + with self.assertRaisesRegex( + source.ProvenanceError, "changed while reading" + ): + native.file_identity(path) + + def test_failed_sdk_walk_rejects_incomplete_inventory(self) -> None: + with patch.object( + native.os, "scandir", side_effect=PermissionError("private-sentinel") + ): + with self.assertRaisesRegex(source.ProvenanceError, "enumeration failed"): + native.sdk_identity(self.sdks["iphoneos"]) + + def observed_sdk_directory(self) -> tuple[Path, dict, object]: + directory = self.root / "wide-sdk" + directory.mkdir() + for index in range(32): + (directory / f"member{index}").write_bytes(b"synthetic SDK byte") + observed = {"entries": 0} + scanner = native.os.scandir + + class CountingScandir: + def __init__(self, selected): + self.iterator = scanner(selected) + + def __iter__(self): + return self + + def __next__(self): + entry = next(self.iterator) + observed["entries"] += 1 + return entry + + def __enter__(self): + return self + + def __exit__(self, *args): + self.iterator.close() + + return directory, observed, CountingScandir + + def test_sdk_wide_directory_rejects_before_buffering_beyond_node_cap(self) -> None: + directory, observed, scanner = self.observed_sdk_directory() + with ( + patch.object(native, "MAX_NATIVE_NODES", 2), + patch.object(native.os, "scandir", scanner), + ): + with self.assertRaisesRegex(source.ProvenanceError, "inspection bound"): + native.sdk_inventory(directory, float("inf")) + self.assertLessEqual(observed["entries"], 3) + + def test_sdk_deadline_is_checked_during_real_directory_enumeration(self) -> None: + directory, observed, scanner = self.observed_sdk_directory() + with ( + patch.object(native.os, "scandir", scanner), + patch.object( + native.time, "monotonic", side_effect=lambda: observed["entries"] + ), + ): + with self.assertRaisesRegex(source.ProvenanceError, "inspection bound"): + native.sdk_inventory(directory, 2) + self.assertLessEqual(observed["entries"], 3) + + def test_inventoried_directory_replaced_by_foreign_symlink_is_not_traversed( + self, + ) -> None: + sdk = self.sdks["iphoneos"] + directory = sdk / "child" + directory.mkdir() + (directory / "member").write_text("SDK member") + foreign = self.root / "foreign" + foreign.mkdir() + (foreign / "sentinel").write_text("must not be enumerated") + stamp = native.file_stamp + + def replace_directory(path): + value = stamp(path) + if path == directory and not path.is_symlink(): + path.rename(self.root / "preserved-child") + path.symlink_to(foreign, target_is_directory=True) + return value + + with patch.object(native, "file_stamp", side_effect=replace_directory): + with self.assertRaises(source.ProvenanceError): + native.sdk_inventory(sdk, float("inf")) + + def test_tool_query_receives_only_remaining_aggregate_deadline(self) -> None: + with patch.object(native.time, "monotonic", return_value=100): + native.query(self.root, ["/usr/bin/xcode-select", "-p"], {}, 101) + self.assertEqual(source.command.call_args.kwargs["timeout"], 1) + with patch.object(native.time, "monotonic", return_value=102): + with self.assertRaisesRegex(source.ProvenanceError, "inspection bound"): + native.query(self.root, ["/usr/bin/xcode-select", "-p"], {}, 101) + + def test_legitimate_internal_sdk_links_and_capture_inventory_drift(self) -> None: + sdk = self.sdks["iphoneos"] + (sdk / "alias.h").symlink_to("header.h") + self.assertEqual(native.sdk_identity(sdk)["nodes"], 3) + actual_entry = native.sdk_entry + + def changing_entry(root, path, deadline): + value = actual_entry(root, path, deadline) + if path.name == "header.h": + (root / "new.h").write_text("inventory drift") + return value + + with patch.object(native, "sdk_entry", side_effect=changing_entry): + with self.assertRaisesRegex(source.ProvenanceError, "inventory changed"): + native.sdk_identity(sdk) + + def test_sdk_root_and_member_replacement_during_capture_reject(self) -> None: + sdk = self.sdks["iphoneos"] + actual_entry = native.sdk_entry + + def replacing_entry(root, path, deadline): + value = actual_entry(root, path, deadline) + if path.name == "header.h": + path.unlink() + path.write_text("/* governed SDK */") + return value + + with patch.object(native, "sdk_entry", side_effect=replacing_entry): + with self.assertRaisesRegex(source.ProvenanceError, "inventory changed"): + native.sdk_identity(sdk) + + def test_sdk_root_replacement_during_capture_rejects_equal_bytes(self) -> None: + sdk = self.sdks["iphoneos"] + actual_entry = native.sdk_entry + + def replace_root(root, path, deadline): + value = actual_entry(root, path, deadline) + if path.name == "header.h": + root.rename(root.with_name("preserved-sdk")) + root.mkdir() + for original in root.with_name("preserved-sdk").iterdir(): + (root / original.name).write_bytes(original.read_bytes()) + return value + + with patch.object(native, "sdk_entry", side_effect=replace_root): + with self.assertRaisesRegex(source.ProvenanceError, "inventory changed"): + native.sdk_identity(sdk) + + def test_tool_nofollow_identity_rejects_symlink_input(self) -> None: + with self.assertRaises(OSError): + native.file_identity(self.tools / "ranlib") + + +if __name__ == "__main__": + unittest.main() diff --git a/scripts/test_ffi_native_cache.py b/scripts/test_ffi_native_cache.py @@ -0,0 +1,289 @@ +"""Real pinned Cargo/cc rebuild controls; disposable contexts are not admission.""" + +from __future__ import annotations + +import copy +import hashlib +import importlib +import json +import os +import shlex +import subprocess +import sys +import tempfile +import time +import unittest +from pathlib import Path +from unittest.mock import patch + +SCRIPTS = Path(__file__).resolve().parent +if str(SCRIPTS) not in sys.path: + sys.path.insert(0, str(SCRIPTS)) + +builder = importlib.import_module("ffi_build") +native = importlib.import_module("ffi_native") + + +class NativeCargoCacheTests(unittest.TestCase): + @classmethod + def setUpClass(cls) -> None: + if not os.environ.get("EXT_BUILD_RUN_ACTIVE"): + raise RuntimeError("real native cache tests require extbuild") + cls.capsule = SCRIPTS.parent + cls.platform = native.capture(cls.capsule, native.HOST) + + def setUp(self) -> None: + project, self.target_root = builder.build_roots(self.capsule) + directory = project / "target/tera_ffi/native_cache_tests" + directory.mkdir(parents=True, exist_ok=True) + self.root = Path(tempfile.mkdtemp(prefix="fixture-", dir=directory)).resolve() + self.environment = native.inspection_environment() + self.target_before = self.environment["CARGO_TARGET_DIR"] + self.package = "tera_native_cache_" + self.root.name.replace("-", "_") + (self.root / "src").mkdir() + (self.root / "Cargo.toml").write_text( + f'[package]\nname="{self.package}"\nversion="0.0.0"\nedition="2024"\n' + '[build-dependencies]\ncc="=1.4.0"\nfind-msvc-tools="=0.1.9"\nshlex="=2.0.1"\n' + ) + (self.root / "build.rs").write_text( + 'fn main() { println!("cargo:rerun-if-changed=native.c"); ' + 'cc::Build::new().file("native.c").compile("native_cache_control"); }\n' + ) + (self.root / "native.c").write_text( + "int native_value(void) { return C137_COMPILER_VALUE + C137_SDK_VALUE; }\n" + ) + (self.root / "src/main.rs").write_text( + 'unsafe extern "C" { fn native_value() -> i32; } ' + 'fn main() { println!("{}", unsafe { native_value() }); }\n' + ) + self.wrapper = self.root / "clang" + self.invocations = self.root / "compiler_invocations.txt" + self.sdk = self.root / "MacOSX.sdk" + self.sdk.mkdir() + self.header = self.sdk / "native_value.h" + self.header.write_text("#define C137_SDK_VALUE 0\n") + self.write_compiler(1) + self.observations = [] + argv = [ + "cargo", + "generate-lockfile", + "--offline", + "--manifest-path", + str(self.root / "Cargo.toml"), + ] + with (self.root / "lock.txt").open("wb") as log: + subprocess.run( + argv, + cwd=self.root, + env=self.environment, + stdout=log, + stderr=subprocess.STDOUT, + check=True, + timeout=120, + ) + self.addCleanup(self.save_observations) + + def write_compiler(self, value: int) -> None: + self.wrapper.write_text( + '#!/bin/sh\ncase " $* " in *native.c*) printf "compiled\\n" >> ' + + shlex.quote(str(self.invocations)) + + ";; esac\nexec " + + shlex.quote(self.platform["tools"]["compiler"]["path"]) + + f' -DC137_COMPILER_VALUE={value} "$@" -isysroot ' + + shlex.quote(self.platform["sdk"]["path"]) + + "\n" + ) + self.wrapper.chmod(0o755) + + def context(self, target: str = native.HOST) -> dict: + context = copy.deepcopy(self.platform) + context["target"] = target + context["inherited"]["path_sha256"] = hashlib.sha256( + self.environment["PATH"].encode() + ).hexdigest() + context["tools"]["compiler"] = { + "path": str(self.wrapper), + "resolved_path": str(self.wrapper), + **native.file_identity(self.wrapper), + } + context["platform_sdk"] = context["sdk"] + context["sdk"] = native.sdk_identity(self.sdk) + context["compiler_arguments"] += [ + "-isysroot", + context["platform_sdk"]["path"], + "-include", + str(self.header), + ] + context["linker_driver_arguments"] += [ + "-isysroot", + context["platform_sdk"]["path"], + ] + return context + + def fence(self, root: Path, context: dict) -> None: + self.assertEqual(root, self.root) + self.assertEqual( + hashlib.sha256(self.environment["PATH"].encode()).hexdigest(), + context["inherited"]["path_sha256"], + ) + compiler = context["tools"]["compiler"] + self.assertEqual( + native.file_identity(Path(compiler["resolved_path"])), + {key: compiler[key] for key in ("sha256", "bytes")}, + ) + self.assertEqual( + native.sdk_identity(Path(context["sdk"]["path"])), context["sdk"] + ) + self.assertEqual( + native.sdk_identity(Path(context["platform_sdk"]["path"])), + context["platform_sdk"], + ) + self.assertEqual( + native.sdk_identity(Path(context["compiler_resources"]["path"])), + context["compiler_resources"], + ) + for key in ("linker", "archiver", "ranlib"): + tool = context["tools"][key] + self.assertEqual( + native.file_identity(Path(tool["resolved_path"])), + {name: tool[name] for name in ("sha256", "bytes")}, + ) + + def execute( + self, name: str, context: dict, host: dict, *, generator: bool = False + ) -> dict: + argv = [ + "cargo", + "run", + "--manifest-path", + str(self.root / "Cargo.toml"), + "--offline", + "--locked", + "--release", + "-vv", + ] + if not generator: + argv += ["--target", native.HOST] + with patch.object(native, "verify", side_effect=self.fence): + started = time.monotonic() + log = builder.run_native( + self.root, self.root, name, argv, self.environment, context, host + ) + elapsed = time.monotonic() - started + raw = log.read_text() + relative = "release" if generator else native.HOST + "/release" + binary = self.target_root / relative / self.package + observed = { + "name": name, + "argv": argv, + "exit_code": 0, + "value": int(raw.splitlines()[-1]), + "log": str(log), + "compiler_calls": len(self.invocations.read_text().splitlines()), + "binary_mtime_ns": binary.stat().st_mtime_ns, + "binary_sha256": hashlib.sha256(binary.read_bytes()).hexdigest(), + "context": context, + "host": host, + "cargo_target_dir": self.environment["CARGO_TARGET_DIR"], + "elapsed_seconds": elapsed, + } + self.assertEqual(observed["cargo_target_dir"], self.target_before) + self.observations.append(observed) + return observed + + def save_observations(self) -> None: + (self.root / "observations.json").write_text( + json.dumps( + { + "fixture": "Real clang/ld/ar/ranlib and platform SDK, pinned cc1.4.0 C archive and executed Rust binary. Disposable compiler wrapper and SDK include-header context replace public selection; real input bytes are fenced before/after each invocation. No production capture/public admission assertion or Tera artifact qualification.", + "root": str(self.root), + "observations": self.observations, + }, + sort_keys=True, + indent=2, + ) + + "\n" + ) + print("native cache observations: " + str(self.root / "observations.json")) + + def assert_reused(self, first: dict, second: dict) -> None: + self.assertEqual(second["compiler_calls"], first["compiler_calls"]) + self.assertEqual(second["binary_mtime_ns"], first["binary_mtime_ns"]) + self.assertEqual(second["binary_sha256"], first["binary_sha256"]) + + def test_same_path_compiler_bytes_rebuild_real_cargo_cc_and_reuse( + self, + ) -> None: + original = self.context() + first = self.execute("first", original, original) + self.assertEqual(first["value"], 1) + self.assert_reused(first, self.execute("stable-first", original, original)) + self.write_compiler(2) + compiler = self.context() + second = self.execute("changed-compiler", compiler, compiler) + self.assertEqual(second["value"], 2) + self.assertGreater(second["compiler_calls"], first["compiler_calls"]) + self.assert_reused(second, self.execute("stable-compiler", compiler, compiler)) + + def test_same_path_sdk_header_bytes_rebuild_real_cargo_cc_and_reuse(self) -> None: + original = self.context() + first = self.execute("sdk-first", original, original) + self.assertEqual(first["value"], 1) + self.assert_reused(first, self.execute("sdk-stable-first", original, original)) + self.header.write_text("#define C137_SDK_VALUE 3\n") + sdk = self.context() + third = self.execute("changed-sdk", sdk, sdk) + self.assertEqual(third["value"], 4) + self.assertGreater(third["compiler_calls"], first["compiler_calls"]) + self.assert_reused(third, self.execute("stable-sdk", sdk, sdk)) + + def test_metadata_suppressed_cc_builder_rebuilds_via_cargo_fingerprint( + self, + ) -> None: + (self.root / "build.rs").write_text( + 'fn main() { println!("cargo:rerun-if-changed=native.c"); ' + 'cc::Build::new().cargo_metadata(false).file("native.c").compile("native_cache_control"); ' + 'println!("cargo:rustc-link-search=native={}", std::env::var("OUT_DIR").unwrap()); ' + 'println!("cargo:rustc-link-lib=static=native_cache_control"); }\n' + ) + original = self.context() + first = self.execute("metadata-first", original, original) + self.assertEqual(first["value"], 1) + self.assert_reused(first, self.execute("metadata-stable", original, original)) + self.write_compiler(2) + changed = self.context() + second = self.execute("metadata-compiler-changed", changed, changed) + self.assertEqual(second["value"], 2) + self.assertGreater(second["compiler_calls"], first["compiler_calls"]) + self.assert_reused( + second, self.execute("metadata-rebuilt-stable", changed, changed) + ) + + def test_independent_host_context_invalidates_real_generator_cache(self) -> None: + target = self.context("aarch64-apple-ios") + # Keep this independently selected target context unchanged while only + # the host compiler fixture changes. The executed fixture is Darwin. + target["tools"]["compiler"] = copy.deepcopy(self.platform["tools"]["compiler"]) + target["sdk"] = target["platform_sdk"] + target["compiler_arguments"] = self.platform["compiler_arguments"] + host = self.context() + first = self.execute("generator-first", target, host, generator=True) + self.assertEqual(first["value"], 1) + self.assert_reused( + first, self.execute("generator-stable", target, host, generator=True) + ) + self.write_compiler(2) + changed_host = self.context() + current = self.execute( + "generator-host-changed", target, changed_host, generator=True + ) + self.assertEqual(current["value"], 2) + self.assertGreater(current["compiler_calls"], first["compiler_calls"]) + self.assert_reused( + current, + self.execute("generator-host-stable", target, changed_host, generator=True), + ) + + +if __name__ == "__main__": + unittest.main() diff --git a/scripts/test_ffi_provenance.py b/scripts/test_ffi_provenance.py @@ -157,6 +157,18 @@ class ProducerSourceTests(unittest.TestCase): with self.assertRaisesRegex(source.ProvenanceError, "ungoverned"): source.reject_build_overrides() + def test_inherited_native_inputs_are_rejected_before_capture(self) -> None: + for key, value in ( + ("LIBSQLITE3_FLAGS", "-USQLITE_ENABLE_API_ARMOR"), + ("LIBSQLITE3_SYS_USE_PKG_CONFIG", ""), + ("CC_aarch64-apple-ios", "unrecorded-clang"), + ("HOST_CFLAGS", "-DUNRECORDED_NATIVE_INPUT=1"), + ("SDKROOT", "/unrecorded-sdk"), + ): + with self.subTest(key=key), patch.dict(os.environ, {key: value}): + with self.assertRaisesRegex(source.ProvenanceError, "ungoverned"): + source.reject_build_overrides() + def test_local_cargo_build_configuration_cannot_escape_source_identity( self, ) -> None: diff --git a/scripts/test_kotlin_smoke.py b/scripts/test_kotlin_smoke.py @@ -1,5 +1,8 @@ from __future__ import annotations +import contextlib +import copy +import io import os import sys import tempfile @@ -12,8 +15,12 @@ SCRIPTS = Path(__file__).resolve().parent if str(SCRIPTS) not in sys.path: sys.path.insert(0, str(SCRIPTS)) +import ffi_artifacts as artifacts # noqa: E402 +import ffi_build as builder # noqa: E402 +import ffi_provenance as provenance # noqa: E402 import ffi_source as source # noqa: E402 import kotlin_smoke as smoke # noqa: E402 +import package_contract as contract # noqa: E402 class KotlinSmokeTests(unittest.TestCase): @@ -93,5 +100,213 @@ class KotlinSmokeTests(unittest.TestCase): smoke.output_root(self.root) +class KotlinNativeInputTests(unittest.TestCase): + """Real cache/record bytes with only installed admission substituted.""" + + def setUp(self) -> None: + temporary = tempfile.TemporaryDirectory() + self.addCleanup(temporary.cleanup) + self.directory = Path(temporary.name).resolve() + self.root = self.directory / "capsule" + self.project = self.directory / "external" + self.output = self.project / "target/kotlin_smoke" + self.records = { + target: { + "repository": "https://example.invalid/tera", + "source": {"tree": "a" * 40, "files": []}, + "foundation": {"fixture": "synthetic admitted source tuple"}, + "build": {"target": target, "native": {"sdk_sha256": "b" * 64}}, + "generator": {"native": {"sdk_sha256": "c" * 64}}, + } + for target in artifacts.TARGETS + } + self.write_records(self.records) + self.base, self.manifest = self.write_candidate( + self.records, b"current synthetic library; not executable\n" + ) + + def write_records(self, records: dict) -> None: + directory = self.root / "TeraFFI/source" + directory.mkdir(parents=True, exist_ok=True) + for target, record in records.items(): + (directory / f"{target}.json").write_bytes(provenance.encoded(record)) + + def write_candidate(self, records: dict, contents: bytes) -> tuple[Path, dict]: + base = builder.candidate_path(self.project, records) + library = base / smoke.LIBRARY + library.parent.mkdir(parents=True, exist_ok=True) + library.write_bytes(contents) + files = [artifacts.file_record(base, smoke.LIBRARY)] + for target, record in records.items(): + relative = f"source/{target}.json" + path = base / relative + path.parent.mkdir(exist_ok=True) + path.write_bytes(provenance.encoded(record)) + files.append(artifacts.file_record(base, relative)) + return base, { + "candidate": { + "source": { + "repository": records[smoke.HOST]["repository"], + "tree": records[smoke.HOST]["source"]["tree"], + }, + "files": files, + } + } + + def native_input( + self, manifest: dict | None = None, *, after_admission: dict | None = None + ) -> tuple[dict, Path, dict]: + def admit(root: Path) -> dict: + self.assertEqual(root, self.root) + if after_admission is not None: + self.write_records(after_admission) + return manifest or self.manifest + + with ( + patch.object(smoke.installed, "check", side_effect=admit) as admission, + patch.object( + provenance, "capture", side_effect=AssertionError("ambient recapture") + ), + patch.object( + builder, + "capture_sources", + side_effect=AssertionError("ambient recapture"), + ), + ): + result = smoke.native_input(self.root, self.output) + admission.assert_called_once_with(self.root) + return result + + def test_current_tuple_wins_over_preserved_legacy_and_old_tuple(self) -> None: + legacy = self.project / "target/tera_ffi/candidates" / ("a" * 40) + library = legacy / smoke.LIBRARY + library.parent.mkdir(parents=True) + library.write_bytes(b"preserved legacy library") + previous = copy.deepcopy(self.records) + previous[smoke.HOST]["build"]["native"]["sdk_sha256"] = "d" * 64 + old_base, _ = self.write_candidate(previous, b"preserved old tuple library") + candidate, native, record = self.native_input() + self.assertEqual(candidate, self.manifest["candidate"]) + self.assertEqual(native, self.base / smoke.LIBRARY) + self.assertIn(record, candidate["files"]) + self.assertEqual(library.read_bytes(), b"preserved legacy library") + self.assertEqual( + (old_base / smoke.LIBRARY).read_bytes(), b"preserved old tuple library" + ) + + def test_every_target_build_and_generator_tuple_changes_cache_identity( + self, + ) -> None: + original = (self.base / smoke.LIBRARY).read_bytes() + for target in artifacts.TARGETS: + for section in ("build", "generator"): + with self.subTest(target=target, section=section): + changed = copy.deepcopy(self.records) + changed[target][section]["native"]["sdk_sha256"] = "e" * 64 + self.write_records(changed) + base, manifest = self.write_candidate( + changed, f"synthetic {target} {section} tuple".encode() + ) + self.assertNotEqual(base, self.base) + self.assertEqual( + changed[target]["source"], self.records[target]["source"] + ) + _, native, _ = self.native_input(manifest) + self.assertEqual(native, base / smoke.LIBRARY) + self.assertEqual((self.base / smoke.LIBRARY).read_bytes(), original) + + def test_record_change_after_installed_check_cannot_select_another_native_tuple( + self, + ) -> None: + contents = (self.base / smoke.LIBRARY).read_bytes() + for target in artifacts.TARGETS: + for section in ("build", "generator"): + with self.subTest(target=target, section=section): + changed = copy.deepcopy(self.records) + changed[target][section]["native"]["sdk_sha256"] = "f" * 64 + alternate, manifest = self.write_candidate(changed, contents) + self.assertNotEqual(alternate, self.base) + self.assertEqual( + manifest["candidate"]["source"], + self.manifest["candidate"]["source"], + ) + self.assertEqual( + artifacts.file_record(alternate, smoke.LIBRARY), + artifacts.file_record(self.base, smoke.LIBRARY), + ) + with self.assertRaisesRegex( + source.ProvenanceError, "source record does not match" + ): + self.native_input(after_admission=changed) + + def test_each_missing_malformed_or_symlink_record_rejects_without_fallback( + self, + ) -> None: + legacy = self.project / "target/tera_ffi/candidates" / ("a" * 40) + library = legacy / smoke.LIBRARY + library.parent.mkdir(parents=True) + library.write_bytes((self.base / smoke.LIBRARY).read_bytes()) + for target in artifacts.TARGETS: + path = self.root / "TeraFFI/source" / f"{target}.json" + original = path.read_bytes() + for kind in ("missing", "malformed", "symlink"): + with self.subTest(target=target, kind=kind): + path.unlink() + if kind == "malformed": + path.write_bytes(b"{malformed synthetic record") + elif kind == "symlink": + actual = self.directory / "synthetic-record.json" + actual.write_bytes(original) + path.symlink_to(actual) + try: + with self.assertRaises(contract.PackageContractError): + self.native_input() + finally: + if path.exists() or path.is_symlink(): + path.unlink() + path.write_bytes(original) + + def test_wrong_native_bytes_are_rejected(self) -> None: + (self.base / smoke.LIBRARY).write_bytes(b"different native tuple bytes") + with self.assertRaisesRegex(source.ProvenanceError, "does not match"): + self.native_input() + + def test_candidate_symlink_is_rejected(self) -> None: + destination = self.base.with_name("preserved-synthetic-candidate") + self.base.rename(destination) + self.base.symlink_to(destination, target_is_directory=True) + with self.assertRaisesRegex( + source.ProvenanceError, "candidate contains a symlink" + ): + self.native_input() + + def test_library_symlink_is_rejected(self) -> None: + library = self.base / smoke.LIBRARY + actual = self.directory / "synthetic-library" + library.rename(actual) + library.symlink_to(actual) + with self.assertRaisesRegex(source.ProvenanceError, "path contains a symlink"): + self.native_input() + + def test_contract_rejection_returns_safe_cli_failure(self) -> None: + output = io.StringIO() + with ( + patch.object(sys, "argv", ["kotlin_smoke.py", "verify"]), + patch.object( + smoke, + "run", + side_effect=contract.PackageContractError( + "required JSON contract is malformed" + ), + ), + contextlib.redirect_stderr(output), + ): + self.assertEqual(smoke.main(), 1) + self.assertEqual( + output.getvalue(), + "Kotlin binding smoke failed: required JSON contract is malformed\n", + ) + + if __name__ == "__main__": unittest.main() diff --git a/scripts/test_unittest_report.py b/scripts/test_unittest_report.py @@ -0,0 +1,726 @@ +"""Exercise the standalone producer with actual stdlib tests and disposable roots.""" + +from __future__ import annotations + +import importlib +import io +import json +import os +import shutil +import subprocess +import sys +import tempfile +import unittest +from pathlib import Path +from unittest.mock import patch + +SECRET = "private exception, skip reason, and subtest parameter" +SCRIPTS = Path(__file__).resolve().parent + + +class StandaloneReportTests(unittest.TestCase): + def setUp(self): + temporary = tempfile.TemporaryDirectory(prefix="tera-unittest-report-") + self.addCleanup(temporary.cleanup) + self.root = Path(temporary.name).resolve() + (self.root / "scripts").mkdir() + subprocess.run( + ["git", "init", "--quiet", str(self.root)], check=True, timeout=10 + ) + shutil.copyfile( + SCRIPTS / "unittest_report.py", self.root / "scripts/unittest_report.py" + ) + self.output = self.root / "report.json" + + def module(self, source, name="test_observed"): + path = self.root / "scripts" / (name + ".py") + path.write_text("import unittest\nSECRET = " + repr(SECRET) + "\n" + source) + return "scripts." + name + + def run_process(self, modules, output=None): + arguments = [ + sys.executable, + "-m", + "scripts.unittest_report", + "--report", + str(output or self.output), + *modules, + ] + record = self.probe_record(arguments, modules) + result = subprocess.run( + arguments, + cwd=self.root, + capture_output=True, + text=True, + timeout=30, + env={**os.environ, "PYTHONDONTWRITEBYTECODE": "1"}, + ) + if record is not None: + (record / "exit.txt").write_text(str(result.returncode)) + (record / "stdout.txt").write_text(result.stdout) + (record / "stderr.txt").write_text(result.stderr) + raw = ( + self.output.read_bytes() + if self.output.is_file() and not self.output.is_symlink() + else b"" + ) + (record / "report.json").write_bytes(raw) + return result + + def probe_record(self, arguments, modules): + evidence = os.environ.get("TERA_REPORT_TEST_EVIDENCE") + if not evidence: + return None + record = Path(tempfile.mkdtemp(prefix="probe-", dir=evidence)) + (record / "argv.json").write_text(json.dumps(arguments)) + (record / "cwd.txt").write_text(str(self.root)) + (record / "producer.py").write_bytes( + (self.root / "scripts/unittest_report.py").read_bytes() + ) + for index, module in enumerate(modules[:4096]): + if len(module) <= 255 and module.startswith("scripts.test_"): + path = self.root / "scripts" / (module[8:] + ".py") + if path.is_file() and not path.is_symlink(): + (record / ("module-" + str(index) + ".py")).write_bytes( + path.read_bytes() + ) + return record + + def run_report(self, modules, output=None): + result = self.run_process(modules, output) + raw = self.output.read_bytes() if self.output.is_file() else b"" + document = json.loads(raw) if raw else None + if document is not None: + self.assertNotIn(SECRET, json.dumps(document)) + self.assertEqual( + set(document), {"schema", "test_ids", "tests_run", "callbacks"} + ) + return result, document + + def test_genuine_pass_and_successful_subtests_have_one_identity(self): + module = self.module(""" +class ObservedTests(unittest.TestCase): + def test_one(self): + for index in range(3): + with self.subTest(private=SECRET, index=index): + self.assertTrue(True) +""") + result, document = self.run_report([module]) + self.assertEqual(result.returncode, 0, result.stderr) + identity = module + ".ObservedTests.test_one" + self.assertEqual(document["test_ids"], [identity]) + self.assertEqual(document["tests_run"], 1) + self.assertEqual( + [row["callback"] for row in document["callbacks"]], + [ + "startTestRun", + "startTest", + "addSubTest", + "addSubTest", + "addSubTest", + "addSuccess", + "stopTest", + "stopTestRun", + ], + ) + self.assertEqual( + [ + row["ordinal"] + for row in document["callbacks"] + if row["callback"] == "addSubTest" + ], + [1, 2, 3], + ) + + def test_actual_nonpassing_test_outcomes_are_observed(self): + modes = { + "failure": ("self.fail(SECRET)", "addFailure"), + "error": ("raise RuntimeError(SECRET)", "addError"), + "skip": ("self.skipTest(SECRET)", "addSkip"), + "cleanup": ("self.addCleanup(lambda: self.fail(SECRET))", "addFailure"), + "cleanup_error": ("self.addCleanup(lambda: int(SECRET))", "addError"), + "expected": ("self.fail(SECRET)", "addExpectedFailure"), + "unexpected": ("pass", "addUnexpectedSuccess"), + } + for mode, (body, callback) in modes.items(): + with self.subTest(mode=mode): + decorator = ( + " @unittest.expectedFailure\n" + if mode in {"expected", "unexpected"} + else "" + ) + module = self.module( + "class ObservedTests(unittest.TestCase):\n" + + decorator + + " def test_one(self):\n " + + body + + "\n" + ) + self.output.unlink(missing_ok=True) + result, document = self.run_report([module]) + self.assertNotEqual(result.returncode, 0) + self.assertIn( + callback, [row["callback"] for row in document["callbacks"]] + ) + self.assertEqual(document["callbacks"][-1], {"callback": "stopTestRun"}) + + def test_actual_subtest_failure_error_and_skip_redact_parameters(self): + for body, callback in [ + ("self.fail(SECRET)", "addSubTest"), + ("raise RuntimeError(SECRET)", "addSubTest"), + ("self.skipTest(SECRET)", "addSkip"), + ]: + with self.subTest(callback=callback, body=body): + module = self.module( + "class ObservedTests(unittest.TestCase):\n def test_one(self):\n with self.subTest(private=SECRET):\n " + + body + + "\n" + ) + self.output.unlink(missing_ok=True) + result, document = self.run_report([module]) + self.assertNotEqual(result.returncode, 0) + event = next( + row for row in document["callbacks"] if row["callback"] == callback + ) + self.assertEqual(event["test_id"], module + ".ObservedTests.test_one") + if callback == "addSubTest": + self.assertFalse(event["successful"]) + + def fixture_source(self, scope, phase, skip=False): + action = ( + "raise unittest.SkipTest(SECRET)" if skip else "raise RuntimeError(SECRET)" + ) + if scope == "module": + fixture = "def " + phase + "():\n " + action + "\n" + return ( + fixture + + "class ObservedTests(unittest.TestCase):\n def test_one(self): pass\n" + ) + return ( + "class ObservedTests(unittest.TestCase):\n @classmethod\n def " + + phase + + "(cls):\n " + + action + + "\n def test_one(self): pass\n" + ) + + def test_actual_module_and_class_fixture_errors_and_skips(self): + for scope, phases in [ + ("module", ["setUpModule", "tearDownModule"]), + ("class", ["setUpClass", "tearDownClass"]), + ]: + for phase in phases: + for skip in [False, True]: + with self.subTest(scope=scope, phase=phase, skip=skip): + module = self.module(self.fixture_source(scope, phase, skip)) + self.output.unlink(missing_ok=True) + result, document = self.run_report([module]) + self.assertNotEqual(result.returncode, 0) + self.assertIn( + "addSkip" if skip else "addError", + [row["callback"] for row in document["callbacks"]], + ) + event = next( + row + for row in document["callbacks"] + if row["callback"] == ("addSkip" if skip else "addError") + ) + owner = module + (".ObservedTests" if scope == "class" else "") + self.assertEqual(event["test_id"], phase + " (" + owner + ")") + self.assertEqual( + document["callbacks"][-1], {"callback": "stopTestRun"} + ) + + def test_actual_class_and_module_cleanup_errors(self): + for source in [ + "def setUpModule():\n unittest.addModuleCleanup(lambda: int(SECRET))\nclass ObservedTests(unittest.TestCase):\n def test_one(self): pass\n", + "class ObservedTests(unittest.TestCase):\n @classmethod\n def setUpClass(cls): cls.addClassCleanup(lambda: int(SECRET))\n def test_one(self): pass\n", + ]: + with self.subTest(source=source): + module = self.module(source) + self.output.unlink(missing_ok=True) + result, document = self.run_report([module]) + self.assertNotEqual(result.returncode, 0) + self.assertIn( + "addError", [row["callback"] for row in document["callbacks"]] + ) + + def test_actual_early_stop_and_interruption_preserve_partial_inventory(self): + for body in ["self._outcome.result.stop()", "raise KeyboardInterrupt(SECRET)"]: + with self.subTest(body=body): + module = self.module( + "class ObservedTests(unittest.TestCase):\n def test_one(self):\n " + + body + + "\n def test_two(self): pass\n" + ) + self.output.unlink(missing_ok=True) + result, document = self.run_report([module]) + self.assertNotEqual(result.returncode, 0) + self.assertIsNotNone(document, result.stderr) + self.assertEqual(len(document["test_ids"]), 2) + self.assertEqual(document["tests_run"], 1) + self.assertEqual(document["callbacks"][-1], {"callback": "stopTestRun"}) + + def test_multiple_modules_have_real_completed_tests(self): + source = ( + "class ObservedTests(unittest.TestCase):\n def test_one(self): pass\n" + ) + modules = [self.module(source), self.module(source, "test_secondary")] + result, document = self.run_report(modules) + self.assertEqual(result.returncode, 0, result.stderr) + self.assertEqual(document["tests_run"], 2) + self.assertEqual(len(document["test_ids"]), 2) + + def test_empty_module_and_duplicate_test_inventory_are_rejected(self): + sources = [ + "pass\n", + "class ObservedTests(unittest.TestCase):\n def test_one(self): pass\ndef load_tests(loader, tests, pattern):\n return unittest.TestSuite([ObservedTests('test_one'), ObservedTests('test_one')])\n", + ] + for source in sources: + with self.subTest(source=source): + result, _ = self.run_report([self.module(source)]) + self.assertNotEqual(result.returncode, 0) + + def test_selectors_are_bounded_canonical_unique_modules(self): + module = self.module( + "class ObservedTests(unittest.TestCase):\n def test_one(self): pass\n" + ) + for selectors in [ + [module, module], + [], + ["scripts/test_observed.py"], + ["scripts.test_"], + ["foreign.test_observed"], + ["scripts.test_" + "x" * 300], + [module] * 4097, + ]: + with self.subTest(selectors=selectors[:2]): + result, _ = self.run_report(selectors) + self.assertNotEqual(result.returncode, 0) + + def test_selected_origins_cannot_be_symlinks_directories_or_foreign_ids(self): + module = self.module( + "class ObservedTests(unittest.TestCase):\n def test_one(self): pass\n" + ) + path = self.root / "scripts/test_observed.py" + foreign = self.root / "foreign.py" + path.rename(foreign) + path.symlink_to(foreign) + result, _ = self.run_report([module]) + self.assertNotEqual(result.returncode, 0) + path.unlink() + path.mkdir() + result, _ = self.run_report([module]) + self.assertNotEqual(result.returncode, 0) + path.rmdir() + self.module( + "class ObservedTests(unittest.TestCase):\n def test_one(self): pass\nObservedTests.__module__ = 'foreign.test_observed'\n" + ) + result, _ = self.run_report([module]) + self.assertNotEqual(result.returncode, 0) + + def test_producer_origin_cannot_be_symlinked(self): + path = self.root / "scripts/unittest_report.py" + foreign = self.root / "foreign.py" + path.rename(foreign) + path.symlink_to(foreign) + result, _ = self.run_report([self.module("pass\n")]) + self.assertNotEqual(result.returncode, 0) + + def test_safe_output_is_exclusive_and_rejects_symlink_parents(self): + module = self.module( + "class ObservedTests(unittest.TestCase):\n def test_one(self): pass\n" + ) + self.output.write_bytes(b"preserved") + result = self.run_process([module]) + self.assertNotEqual(result.returncode, 0) + self.assertEqual(self.output.read_bytes(), b"preserved") + self.output.unlink() + self.output.symlink_to(self.root / "foreign.json") + result, _ = self.run_report([module]) + self.assertNotEqual(result.returncode, 0) + self.output.unlink() + (self.root / "alias").symlink_to( + self.root / "scripts", target_is_directory=True + ) + result, _ = self.run_report([module], self.root / "alias/report.json") + self.assertNotEqual(result.returncode, 0) + self.assertFalse((self.root / "scripts/report.json").exists()) + + def test_source_and_output_replacement_during_execution_fail_closed(self): + sources = [ + "from pathlib import Path\nclass ObservedTests(unittest.TestCase):\n def test_one(self):\n Path(__file__).write_text('pass\\n')\n", + "from pathlib import Path\nclass ObservedTests(unittest.TestCase):\n def test_one(self):\n Path('report.json').unlink()\n Path('report.json').write_text('replacement')\n", + ] + for source in sources: + with self.subTest(source=source): + self.output.unlink(missing_ok=True) + result = self.run_process([self.module(source)]) + self.assertNotEqual(result.returncode, 0) + + def test_real_same_inode_output_tampering_is_rejected(self): + for action in [ + "path.write_bytes(b'PRIVATE_OUTPUT_SENTINEL')", + "path.write_bytes(b'PRIVATE_OUTPUT_SENTINEL' * 120000)", + "path.write_bytes(b'PRIVATE_OUTPUT_SENTINEL'); path.write_bytes(b'')", + ]: + with self.subTest(action=action): + self.output.unlink(missing_ok=True) + module = self.module( + "from pathlib import Path\nclass ObservedTests(unittest.TestCase):\n" + " def test_one(self):\n path = Path('report.json')\n" + " before = path.stat().st_ino\n " + action + "\n" + " self.assertEqual(path.stat().st_ino, before)\n" + " Path('testcase-passed').write_text('passed')\n" + ) + result = self.run_process([module]) + self.assertEqual((self.root / "testcase-passed").read_text(), "passed") + self.assertNotEqual(result.returncode, 0) + self.assertNotIn("PRIVATE_OUTPUT_SENTINEL", result.stderr) + + def test_output_settlement_rechecks_content_and_position(self): + # Inject a mutation after the real writer returns, before actual close. + for action in [ + "os.write(output.descriptor, b'PRIVATE_OUTPUT_SENTINEL')", + "os.ftruncate(output.descriptor, 0)", + "os.pwrite(output.descriptor, b'X', 0)", + "os.lseek(output.descriptor, 0, os.SEEK_SET)", + ]: + with self.subTest(action=action): + self.output.unlink(missing_ok=True) + module = self.module( + "import os, sys\nclass ObservedTests(unittest.TestCase):\n" + " def test_one(self):\n" + " owner = sys.modules['__main__']\n" + " original = owner.ReportOutput.write\n" + " def changed(output, document):\n" + " original(output, document)\n " + + action + + "\n owner.ReportOutput.write = changed\n" + " from pathlib import Path\n" + " Path('testcase-passed').write_text('passed')\n" + ) + result = self.run_process([module]) + self.assertEqual((self.root / "testcase-passed").read_text(), "passed") + self.assertNotEqual(result.returncode, 0) + self.assertNotIn("PRIVATE_OUTPUT_SENTINEL", result.stderr) + + def test_real_callback_limit_is_exact_and_does_not_append_over_bound(self): + for extra in [0, 1]: + with self.subTest(extra=extra): + module = self.module( + "class ObservedTests(unittest.TestCase):\n def test_one(self):\n for _ in range(" + + str(4091 + extra) + + "):\n with self.subTest(private=SECRET): pass\n" + ) + self.output.unlink(missing_ok=True) + result, document = self.run_report([module]) + self.assertEqual(result.returncode == 0, extra == 0, result.stderr) + self.assertLessEqual(len(document["callbacks"]), 4096) + if extra == 0: + self.assertEqual(len(document["callbacks"]), 4096) + + def test_real_inventory_limit_is_separate_from_callback_limit(self): + for count in [4096, 4097]: + with self.subTest(count=count): + module = self.module( + "class ObservedTests(unittest.TestCase):\n def test_one(self): pass\ndef load_tests(loader, tests, pattern):\n case = type('ManyTests', (unittest.TestCase,), {'__module__': __name__, **{f'test_{index}': lambda self: None for index in range(" + + str(count) + + ")}})\n return loader.loadTestsFromTestCase(case)\n" + ) + self.output.unlink(missing_ok=True) + result, document = self.run_report([module]) + self.assertNotEqual(result.returncode, 0) + if count == 4096: + self.assertEqual(len(document["test_ids"]), 4096) + self.assertLessEqual(len(document["callbacks"]), 4096) + + def report_shape(self, identity, subtests): + callbacks = [ + {"callback": "startTestRun"}, + {"callback": "startTest", "test_id": identity}, + ] + callbacks.extend( + { + "callback": "addSubTest", + "test_id": identity, + "ordinal": index + 1, + "successful": True, + } + for index in range(subtests) + ) + callbacks.extend( + [ + {"callback": "addSuccess", "test_id": identity}, + {"callback": "stopTest", "test_id": identity}, + {"callback": "stopTestRun"}, + ] + ) + return { + "schema": "tera.unittest-callback-report.v1", + "test_ids": [identity], + "tests_run": 1, + "callbacks": callbacks, + } + + def test_actual_report_accepts_two_million_bytes_and_rejects_overflow(self): + prefix = "scripts.test_observed.ManyTests.test_" + for others in range(4): + document = self.report_shape(prefix, 0) + for index in range(others): + other = self.report_shape(prefix + "a_" + str(index), 0) + document["test_ids"].insert(index, other["test_ids"][0]) + document["callbacks"][1:1] = other["callbacks"][1:-1] + document["tests_run"] += 1 + baseline = len(json.dumps(document, sort_keys=True, separators=(",", ":"))) + padding, remainder = divmod(2_000_000 - baseline, 4) + if remainder == 0: + break + self.assertEqual(remainder, 0) + for extra in [0, 1]: + with self.subTest(extra=extra): + source = ( + "class ManyTests(unittest.TestCase): pass\nfor index in range(" + + str(others) + + "):\n setattr(ManyTests, 'test_a_' + str(index), lambda self: None)\nsetattr(ManyTests, 'test_' + 'x' * " + + str(padding + extra) + + ", lambda self: None)\n" + ) + module = self.module(source) + self.output.unlink(missing_ok=True) + result, document = self.run_report([module]) + self.assertEqual(result.returncode == 0, extra == 0, result.stderr) + self.assertLessEqual(len(self.output.read_bytes()), 2_000_000) + if extra == 0: + self.assertEqual(len(self.output.read_bytes()), 2_000_000) + self.assertEqual(document["tests_run"], others + 1) + + def test_partial_testcase_without_success_is_not_accepted(self): + module = self.module( + "class ObservedTests(unittest.TestCase):\n def test_one(self): pass\n def run(self, result):\n result.startTest(self)\n result.stopTest(self)\n" + ) + result, document = self.run_report([module]) + self.assertNotEqual(result.returncode, 0) + self.assertEqual(document["tests_run"], 1) + self.assertNotIn( + "addSuccess", [row["callback"] for row in document["callbacks"]] + ) + + def test_selected_code_cannot_exit_successfully_during_import(self): + result, _ = self.run_report([self.module("raise SystemExit(0)\n")]) + self.assertNotEqual(result.returncode, 0) + + def test_selected_module_does_not_execute_forged_cached_bytecode(self): + module = self.module( + "class ObservedTests(unittest.TestCase):\n def test_one(self): pass\n" + ) + source = self.root / "scripts/test_observed.py" + code = compile("raise SystemExit(0)", str(source), "exec") + import importlib._bootstrap_external + + cached = Path(importlib.util.cache_from_source(str(source))) + cached.parent.mkdir() + cached.write_bytes( + importlib._bootstrap_external._code_to_timestamp_pyc( + code, int(source.stat().st_mtime), source.stat().st_size + ) + ) + result, document = self.run_report([module]) + self.assertEqual(result.returncode, 0, result.stderr) + self.assertEqual(document["tests_run"], 1) + + def test_foreign_resolution_is_rejected_before_module_execution(self): + (self.root / "foreign").mkdir() + (self.root / "foreign/test_secondary.py").write_text( + "from pathlib import Path\nPath('foreign-executed').write_text('executed')\n" + ) + first = self.module( + "import scripts\nfrom pathlib import Path\nscripts.__path__ = [str(Path.cwd() / 'foreign')]\nclass ObservedTests(unittest.TestCase):\n def test_one(self): pass\n" + ) + second = self.module( + "class ObservedTests(unittest.TestCase):\n def test_one(self): pass\n", + "test_secondary", + ) + result, _ = self.run_report([first, second]) + self.assertNotEqual(result.returncode, 0) + self.assertFalse((self.root / "foreign-executed").exists()) + + def test_output_directory_rename_cannot_redirect_descriptor_writes(self): + module = self.module( + "from pathlib import Path\nclass ObservedTests(unittest.TestCase):\n def test_one(self):\n Path('output').rename('moved')\n Path('output').mkdir()\n Path('output/report.json').write_text('replacement')\n" + ) + (self.root / "output").mkdir() + result = self.run_process([module], self.root / "output/report.json") + self.assertNotEqual(result.returncode, 0) + self.assertEqual((self.root / "output/report.json").read_text(), "replacement") + self.assertEqual((self.root / "moved/report.json").read_bytes(), b"") + + def test_duplicate_run_boundary_and_invalid_test_id_are_nonpassing(self): + for source in [ + "class ObservedTests(unittest.TestCase):\n def test_one(self): self._outcome.result.startTestRun()\n", + "class ObservedTests(unittest.TestCase):\n def test_one(self): pass\n def id(self): return SECRET\n", + ]: + with self.subTest(source=source): + self.output.unlink(missing_ok=True) + result, _ = self.run_report([self.module(source)]) + self.assertNotEqual(result.returncode, 0) + + +class OutputIntegrityTests(unittest.TestCase): + """Injected timing controls around actual writes of genuine observations.""" + + def setUp(self): + self.producer = importlib.import_module("scripts.unittest_report") + temporary = tempfile.TemporaryDirectory(prefix="tera-output-integrity-") + self.addCleanup(temporary.cleanup) + self.root = Path(temporary.name) + case = type( + "ObservedTests", + (unittest.TestCase,), + {"__module__": "scripts.test_observed", "test_one": lambda self: None}, + )("test_one") + suite, budget = unittest.TestSuite([case]), self.producer.ReportBudget() + inventory = self.producer.inventory(suite, ["scripts.test_observed"], budget) + result, passing = self.producer.observe(suite, inventory, budget, io.StringIO()) + self.assertTrue(passing) + self.document = { + "schema": self.producer.SCHEMA, + "test_ids": inventory, + "tests_run": result.testsRun, + "callbacks": result.callbacks, + } + + def output(self, name): + path = self.root / (name + ".json") + output = self.producer.ReportOutput(str(path)) + self.addCleanup(os.close, output.directory) + self.addCleanup(os.close, output.descriptor) + evidence = os.environ.get("TERA_REPORT_TEST_EVIDENCE") + if evidence: + record = Path( + tempfile.mkdtemp(prefix="injected-" + name + "-", dir=evidence) + ) + self.addCleanup(shutil.copyfile, path, record / "report.json") + return output + + def mutate(self, output, mode): + if mode == "append": + os.pwrite( + output.descriptor, SECRET.encode(), os.fstat(output.descriptor).st_size + ) + elif mode == "truncate": + os.ftruncate(output.descriptor, 0) + elif mode == "same_size": + os.pwrite(output.descriptor, b"X", 0) + else: + os.lseek(output.descriptor, 0, os.SEEK_SET) + + def test_actual_write_races_reject_append_truncate_content_and_offset(self): + original = os.write + for mode in ["append", "truncate", "same_size", "offset"]: + with self.subTest(mode=mode): + output, calls = self.output("write-" + mode), [] + + def changed(descriptor, raw): + count = original(descriptor, raw) + if not calls: + calls.append(count) + self.mutate(output, mode) + return count + + with patch.object(self.producer.os, "write", changed): + with self.assertRaises(self.producer.ReportError) as failure: + output.write(self.document) + self.assertNotIn(SECRET, str(failure.exception)) + self.assertTrue(calls) + + def test_prewrite_descriptor_offset_is_rejected(self): + output = self.output("prewrite-offset") + os.lseek(output.descriptor, 3, os.SEEK_SET) + with self.assertRaises(self.producer.ReportError): + output.write(self.document) + self.assertEqual(os.fstat(output.descriptor).st_size, 0) + + def test_actual_short_writes_preserve_exact_emitted_bytes(self): + output, original = self.output("short-write"), os.write + + def partial(descriptor, raw): + return original(descriptor, raw[:7]) + + with patch.object(self.producer.os, "write", partial): + output.write(self.document) + output.verify() + raw = (self.root / "short-write.json").read_bytes() + self.assertEqual( + raw, self.producer.ENCODER.encode(self.document).encode("ascii") + ) + self.assertEqual(os.lseek(output.descriptor, 0, os.SEEK_CUR), len(raw)) + + def test_descriptor_read_races_are_bounded_and_fenced(self): + original = os.pread + for mode in ["same_size", "offset"]: + with self.subTest(mode=mode): + output, reads = self.output("read-" + mode), [] + + def changed(descriptor, count, offset): + raw = original(descriptor, count, offset) + reads.append((count, offset)) + if len(reads) == 1: + self.mutate(output, mode) + return raw + + with patch.object(self.producer.os, "pread", changed): + with self.assertRaises(self.producer.ReportError): + output.write(self.document) + self.assertTrue(reads) + self.assertTrue(all(0 < count <= 65536 for count, _ in reads)) + + +class ObserverBoundTests(unittest.TestCase): + def test_byte_budget_accepts_exact_limit_and_rejects_next_byte(self): + producer = importlib.import_module("scripts.unittest_report") + budget = producer.ReportBudget() + budget.size = producer.MAX_BYTES - 1 + budget.add(1) + self.assertEqual(budget.size, producer.MAX_BYTES) + with self.assertRaises(producer.ReportError): + budget.add(1) + self.assertEqual(budget.size, producer.MAX_BYTES) + + def test_observer_never_retains_exception_skip_or_subtest_values(self): + producer = importlib.import_module("scripts.unittest_report") + module = "scripts.test_observed" + + def method(case): + with case.subTest(private=SECRET): + case.skipTest(SECRET) + + case_type = type( + "ObservedTests", + (unittest.TestCase,), + {"__module__": module, "test_one": method}, + ) + case = case_type("test_one") + budget = producer.ReportBudget() + inventory = producer.inventory(unittest.TestSuite([case]), [module], budget) + result, passing = producer.observe( + unittest.TestSuite([case]), inventory, budget, io.StringIO() + ) + self.assertFalse(passing) + self.assertEqual(result.skipped, []) + self.assertNotIn(SECRET, repr(result.__dict__)) + + def test_imported_module_origin_is_checked_after_loading(self): + producer = importlib.import_module("scripts.unittest_report") + with tempfile.TemporaryDirectory() as temporary: + root = Path(temporary).resolve() + (root / "scripts").mkdir() + (root / "scripts/test_observed.py").write_text("pass\n") + with patch.object(producer.importlib.util, "find_spec") as find: + find.return_value.origin = str(root / "foreign.py") + with self.assertRaises(producer.ReportError): + producer.load_modules(root, ["scripts.test_observed"]) + + +if __name__ == "__main__": + unittest.main() diff --git a/scripts/unittest_report.py b/scripts/unittest_report.py @@ -0,0 +1,612 @@ +"""Standalone, bounded observations of genuine stdlib unittest callbacks. + +Run from the capsule root with the frozen persona-verifier Python interpreter. +The machine report contains identities and callback facts only. Diagnostics use +stderr and never become report fields. No parent contract or pytest is loaded. +""" + +from __future__ import annotations + +import hashlib +import importlib +import importlib.machinery +import importlib.util +import json +import os +import re +import stat +import sys +import unittest +from pathlib import Path + +SCHEMA = "tera.unittest-callback-report.v1" +MAX_BYTES = 2_000_000 +MAX_ITEMS = 4096 +MODULE = re.compile(r"scripts\.test_[A-Za-z0-9_]+") +TEST_ID = re.compile( + r"scripts\.test_[A-Za-z0-9_]+\.[A-Za-z_][A-Za-z0-9_]*\.[A-Za-z_][A-Za-z0-9_]*(?:\.[A-Za-z_][A-Za-z0-9_]*)*" +) +FIXTURE_ID = re.compile( + r"(?:setUpClass|tearDownClass|setUpModule|tearDownModule) " + r"\((scripts\.test_[A-Za-z0-9_]+(?:\.[A-Za-z_][A-Za-z0-9_]*)*)\)" +) +ENCODER = json.JSONEncoder(sort_keys=True, separators=(",", ":"), ensure_ascii=True) + + +class ReportError(Exception): + """A stable, secret-free report rejection.""" + + +def require(condition, message): + if not condition: + raise ReportError(message) + + +def encoded_size(value): + return sum(len(chunk) for chunk in ENCODER.iterencode(value)) + + +class ReportBudget: + def __init__(self): + self.size = encoded_size( + {"schema": SCHEMA, "test_ids": [], "tests_run": 0, "callbacks": []} + ) + + def add(self, size): + require(self.size + size <= MAX_BYTES, "report byte bound exceeded") + self.size += size + + def append(self, destination, value): + require(len(destination) < MAX_ITEMS, "report item bound exceeded") + self.add(encoded_size(value) + int(bool(destination))) + destination.append(value) + + +def selectors(values): + require(0 < len(values) <= MAX_ITEMS, "selected module count is invalid") + seen = set() + for value in values: + require( + isinstance(value, str) and len(value) <= 255, "selected module is invalid" + ) + require(MODULE.fullmatch(value) is not None, "selected module is not canonical") + require(value not in seen, "selected module is duplicated") + seen.add(value) + return values + + +def open_directory(path): + """Walk every component with nofollow; retain the actual directory descriptor.""" + require( + isinstance(path, str) and 0 < len(path) <= 4096 and "\x00" not in path, + "output path is invalid", + ) + absolute = path.startswith("/") + descriptor = os.open("/" if absolute else ".", os.O_RDONLY | os.O_DIRECTORY) + try: + for component in path.split("/"): + if not component or component == ".": + continue + child = os.open( + component, + os.O_RDONLY | os.O_DIRECTORY | os.O_NOFOLLOW, + dir_fd=descriptor, + ) + os.close(descriptor) + descriptor = child + return descriptor + except BaseException: + os.close(descriptor) + raise + + +def identity(information): + return (information.st_dev, information.st_ino) + + +def source_metadata(information): + return ( + identity(information), + information.st_mode, + information.st_nlink, + information.st_size, + information.st_mtime_ns, + information.st_ctime_ns, + ) + + +class ReportOutput: + """Exclusive output with bounded byte, position and identity fencing.""" + + def __init__(self, path): + require( + isinstance(path, str) and 0 < len(path) <= 4096 and "\x00" not in path, + "output path is invalid", + ) + self.parent, self.name = os.path.split(path) + require(self.name not in {"", ".", ".."}, "output basename is invalid") + self.directory = open_directory(self.parent or ".") + try: + self.descriptor = os.open( + self.name, + os.O_RDWR | os.O_CREAT | os.O_EXCL | os.O_NOFOLLOW, + 0o600, + dir_fd=self.directory, + ) + except BaseException: + os.close(self.directory) + raise + try: + self.information = os.fstat(self.descriptor) + self.size = 0 + self.digest = hashlib.sha256() + require( + stat.S_ISREG(self.information.st_mode) + and self.information.st_nlink == 1 + and self.information.st_size == 0, + "output is not an exclusive regular file", + ) + except BaseException: + self.close() + raise + + def verify_position(self, information): + require( + information.st_size == self.size + and self.size <= MAX_BYTES + and os.lseek(self.descriptor, 0, os.SEEK_CUR) == self.size, + "output size or write position changed", + ) + + def verify_metadata(self): + information = os.fstat(self.descriptor) + require( + source_metadata(information) == source_metadata(self.information), + "output metadata changed", + ) + self.verify_position(information) + current = os.stat(self.name, dir_fd=self.directory, follow_symlinks=False) + require( + source_metadata(current) == source_metadata(information), + "output identity changed", + ) + return information + + def verify_directory(self): + directory = open_directory(self.parent or ".") + try: + require( + identity(os.fstat(directory)) == identity(os.fstat(self.directory)), + "output directory changed", + ) + finally: + os.close(directory) + + def verify(self): + self.verify_directory() + before = self.verify_metadata() + digest, offset = hashlib.sha256(), 0 + while offset < self.size: + raw = os.pread(self.descriptor, min(65536, self.size - offset), offset) + require(bool(raw), "output changed while reading") + digest.update(raw) + offset += len(raw) + require(digest.digest() == self.digest.digest(), "output bytes changed") + require( + source_metadata(before) == source_metadata(self.verify_metadata()), + "output changed while reading", + ) + self.verify_directory() + + def write_piece(self, raw): + while raw: + self.verify_metadata() + count = os.write(self.descriptor, raw) + require(0 < count <= len(raw), "output write did not advance") + self.size += count + self.digest.update(raw[:count]) + information = os.fstat(self.descriptor) + self.verify_position(information) + require( + source_metadata(information)[:3] + == source_metadata(self.information)[:3], + "output identity changed", + ) + self.information = information + raw = raw[count:] + + def write(self, document): + require(encoded_size(document) <= MAX_BYTES, "report byte bound exceeded") + self.verify() + require(self.size == 0, "output was already written") + total = 0 + for chunk in ENCODER.iterencode(document): + raw = chunk.encode("ascii") + total += len(raw) + require(total <= MAX_BYTES, "report byte bound exceeded") + self.write_piece(raw) + os.fsync(self.descriptor) + self.verify() + + def close(self): + try: + self.verify() + finally: + try: + os.close(self.descriptor) + finally: + os.close(self.directory) + + +def source_snapshot(root, relative): + directory = open_directory(str(root / relative.parent)) + try: + descriptor = os.open( + relative.name, os.O_RDONLY | os.O_NOFOLLOW | os.O_NONBLOCK, dir_fd=directory + ) + try: + before = os.fstat(descriptor) + require( + stat.S_ISREG(before.st_mode) and 0 < before.st_size <= MAX_BYTES, + "source origin is not a bounded regular file", + ) + digest = hashlib.sha256() + chunks = [] + remaining = before.st_size + while remaining: + chunk = os.read(descriptor, min(65536, remaining)) + require(bool(chunk), "source origin changed while reading") + digest.update(chunk) + chunks.append(chunk) + remaining -= len(chunk) + after = os.fstat(descriptor) + require( + source_metadata(before) == source_metadata(after), + "source origin changed while reading", + ) + current = os.stat(relative.name, dir_fd=directory, follow_symlinks=False) + require( + source_metadata(current) == source_metadata(before), + "source origin identity changed", + ) + return (source_metadata(before), digest.hexdigest()), b"".join(chunks) + finally: + os.close(descriptor) + finally: + os.close(directory) + + +def source_identity(root, relative): + return source_snapshot(root, relative)[0] + + +def owned_origin(module, expected): + require( + getattr(module, "__file__", None) == str(expected), + "loaded module file origin differs", + ) + require( + getattr(getattr(module, "__spec__", None), "origin", None) == str(expected), + "loaded module specification origin differs", + ) + + +def load_modules(root, names): + modules, sources = [], {} + for name in names: + relative = Path("scripts") / (name.split(".")[1] + ".py") + before, raw = source_snapshot(root, relative) + spec = importlib.util.find_spec(name) + require( + spec is not None and spec.origin == str(root / relative), + "selected module resolution origin differs", + ) + require( + type(spec.loader) is importlib.machinery.SourceFileLoader, + "selected module loader differs", + ) + module = importlib.util.module_from_spec(spec) + require( + source_identity(root, relative) == before, + "selected module changed before import", + ) + sys.modules[name] = module + exec(compile(raw, str(root / relative), "exec"), module.__dict__) + owned_origin(module, root / relative) + require( + source_identity(root, relative) == before, + "selected module changed during import", + ) + sources[relative] = before + modules.append(module) + return modules, sources + + +def iter_tests(suite): + pending = [iter(suite)] + visited = set() + while pending: + current = next(pending[-1], None) + if current is None: + pending.pop() + elif isinstance(current, unittest.TestSuite): + require( + id(current) not in visited and len(visited) < MAX_ITEMS, + "suite inventory is cyclic or oversized", + ) + visited.add(id(current)) + pending.append(iter(current)) + else: + require( + isinstance(current, unittest.TestCase), + "inventory contains a non-testcase", + ) + yield current + + +def canonical_id(test): + value = test.id() + require( + isinstance(value, str) and len(value) <= MAX_BYTES, + "testcase identity is invalid", + ) + require(TEST_ID.fullmatch(value) is not None, "testcase identity is not canonical") + require( + value == unittest.TestCase.id(test), + "testcase identity differs from its actual class and method", + ) + return value + + +def inventory(suite, names, budget): + values, seen, represented = [], set(), set() + for test in iter_tests(suite): + value = canonical_id(test) + module = type(test).__module__ + require( + module in names and value.startswith(module + "."), + "testcase belongs to an unselected module", + ) + require(value not in seen, "testcase inventory is duplicated") + budget.append(values, value) + seen.add(value) + represented.add(module) + require( + bool(values) and represented == set(names), + "selected module inventory is empty or incomplete", + ) + return values + + +class CallbackResult(unittest.TestResult): + """Store bounded redacted callback facts, never formatted errors or reprs.""" + + def __init__(self, test_ids, budget, stream): + super().__init__() + self.callbacks = [] + self.inventory = set(test_ids) + self.budget = budget + self.stream = stream + self.active = None + self.started, self.completed, self.succeeded = set(), set(), set() + self.ordinal = 0 + self.success = False + self.nonpassing = False + self.rejected = False + self.run_started = False + self.run_stopped = False + + def event(self, callback, test_id=None, **fields): + value = {"callback": callback, **fields} + if test_id is not None: + value["test_id"] = test_id + try: + self.budget.append(self.callbacks, value) + except ReportError: + self.rejected = True + self.stop() + raise + + def startTestRun(self): + require(not self.run_started, "test run started twice") + self.run_started = True + self.event("startTestRun") + super().startTestRun() + + def stopTestRun(self): + require( + self.run_started and not self.run_stopped, "test run stop order differs" + ) + self.run_stopped = True + self.event("stopTestRun") + super().stopTestRun() + + def startTest(self, test): + require( + self.run_started and not self.run_stopped, + "testcase is outside run boundaries", + ) + value = canonical_id(test) + require( + value in self.inventory + and value not in self.started + and self.active is None, + "testcase start differs from inventory", + ) + self.budget.add(len(str(self.testsRun + 1)) - len(str(self.testsRun))) + self.event("startTest", value) + super().startTest(test) + self.active, self.ordinal, self.success = value, 0, False + self.started.add(value) + + def stopTest(self, test): + value = canonical_id(test) + require(value == self.active, "testcase stop order differs") + self.event("stopTest", value) + self.completed.add(value) + self.active = None + super().stopTest(test) + + def addSuccess(self, test): + value = canonical_id(test) + require( + value == self.active and not self.success, "testcase success order differs" + ) + self.event("addSuccess", value) + self.success = True + self.succeeded.add(value) + super().addSuccess(test) + + def addSubTest(self, test, subtest, err): + del subtest + value = canonical_id(test) + require(value == self.active and not self.success, "subtest order differs") + self.ordinal += 1 + self.event("addSubTest", value, ordinal=self.ordinal, successful=err is None) + if err is not None: + self.nonpassing = True + + def nonpass(self, callback, test): + self.nonpassing = True + # _SubTest.id() includes raw parameter repr; its parent is the identity. + parent = getattr(test, "test_case", test) + if isinstance(parent, unittest.TestCase): + value = canonical_id(parent) + elif type(parent) is unittest.suite._ErrorHolder: + value = self.fixture_id(parent) + else: + value = "unittest.redacted_noncase" + self.event(callback, value) + print("unittest-report: " + callback, file=self.stream) + + def fixture_id(self, test): + value = test.id() + require( + isinstance(value, str) and len(value) <= MAX_BYTES, + "fixture identity is invalid", + ) + match = FIXTURE_ID.fullmatch(value) + require(match is not None, "fixture identity is not canonical") + require( + any(item.startswith(match[1] + ".") for item in self.inventory), + "fixture identity is outside inventory", + ) + return value + + def addFailure(self, test, err): + del err + self.nonpass("addFailure", test) + + def addError(self, test, err): + del err + self.nonpass("addError", test) + + def addSkip(self, test, reason): + del reason + self.nonpass("addSkip", test) + + def addExpectedFailure(self, test, err): + del err + self.nonpass("addExpectedFailure", test) + + def addUnexpectedSuccess(self, test): + self.nonpass("addUnexpectedSuccess", test) + + def wasSuccessful(self): + return not self.nonpassing and not self.rejected + + def passing(self): + boundaries = self.callbacks[:1] == [ + {"callback": "startTestRun"} + ] and self.callbacks[-1:] == [{"callback": "stopTestRun"}] + return ( + boundaries + and self.testsRun > 0 + and self.wasSuccessful() + and not self.shouldStop + and self.active is None + and self.started == self.completed == self.succeeded == self.inventory + and self.testsRun == len(self.inventory) + ) + + +def observe(suite, test_ids, budget, stream): + result = CallbackResult(test_ids, budget, stream) + result.startTestRun() + try: + suite(result) + except BaseException: + result.rejected = True + result.stop() + print("unittest-report: test run interrupted or rejected", file=stream) + finally: + try: + result.stopTestRun() + except ReportError: + result.rejected = True + return result, result.passing() + + +def execute(root, names, output, stream): + producer = Path("scripts/unittest_report.py") + initial = source_identity(root, producer) + owned_origin(sys.modules[__name__], root / producer) + modules, sources = load_modules(root, names) + sources[producer] = initial + loader = unittest.TestLoader() + suite = unittest.TestSuite(loader.loadTestsFromModule(module) for module in modules) + require(not loader.errors, "testcase discovery failed") + budget = ReportBudget() + test_ids = inventory(suite, names, budget) + result, passing = observe(suite, test_ids, budget, stream) + for relative, before in sources.items(): + require( + source_identity(root, relative) == before, + "source origin changed during execution", + ) + output.write( + { + "schema": SCHEMA, + "test_ids": test_ids, + "tests_run": result.testsRun, + "callbacks": result.callbacks, + } + ) + return 0 if passing else 1 + + +def main(arguments=None): + arguments = sys.argv[1:] if arguments is None else arguments + output = None + status = 1 + try: + require(sys.version_info[:3] == (3, 14, 7), "frozen Python version differs") + require( + len(arguments) >= 3 and arguments[0] == "--report", + "expected one explicit report output and selected modules", + ) + names = selectors(arguments[2:]) + root = Path(os.path.abspath(__file__)).parent.parent + require( + identity(root.stat()) == identity(Path.cwd().stat()), + "runner must use the capsule root", + ) + output = ReportOutput(arguments[1]) + status = execute(root, names, output, sys.stderr) + except BaseException: + print( + "unittest-report: input, origin, output, or lifecycle rejected", + file=sys.stderr, + ) + finally: + if output is not None: + try: + output.close() + except BaseException: + print("unittest-report: output settlement rejected", file=sys.stderr) + status = 1 + return status + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/scripts/verify-package-contract.sh b/scripts/verify-package-contract.sh @@ -18,6 +18,8 @@ sh "$repo_root/scripts/ffi-provenance.sh" contract-check scripts/test_legacy_identifiers.py \ scripts/test_app_dependency_graph.py \ scripts/test_ffi_provenance.py \ + scripts/test_ffi_native.py \ + scripts/test_unittest_report.py \ scripts/test_ffi_artifacts.py \ scripts/test_ffi_installed.py \ scripts/test_kotlin_smoke.py \