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 e9294dd397384e95336985bef5b7b3b2779cec9b
parent 06986109b31e1e5886bae150d7324b5657e84825
Author: triesap <tyson@radroots.org>
Date:   Sat, 10 Oct 2026 02:00:24 +0000

fix: Bound scoped query contexts and redact diagnostics (C188a)

- Admit complete mutable and decoded contexts before hashing or storage work.
- Enforce inherited author and relay bounds while preserving typed errors and cursors.
- Redact core, FFI and Swift diagnostics and refresh the exact native artifacts.
- Verify context regressions, installed bindings and affected fixtures before acceptance.

Diffstat:
MPackage.swift | 1+
ATera/Runtime/TeraRuntimeContext.swift | 5+++++
MTeraFFI/provenance.json | 54+++++++++++++++++++++++++++---------------------------
MTeraFFI/source.lock | 4++--
MTeraFFI/source/aarch64-apple-darwin.json | 70+++++++++++++++++++++++++++++++++++++++++-----------------------------
MTeraFFI/source/aarch64-apple-ios-sim.json | 70+++++++++++++++++++++++++++++++++++++++++-----------------------------
MTeraFFI/source/aarch64-apple-ios.json | 70+++++++++++++++++++++++++++++++++++++++++-----------------------------
MTeraTests/TeraSearchFFICompatibilityTests.swift | 57+++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mcore/crates/tera_core/src/runtime/product_surface/context.rs | 148++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------
Acore/crates/tera_core/src/runtime/product_surface/context_admission_tests.rs | 112+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mcore/crates/tera_core/src/runtime/product_surface/today.rs | 6++++++
Mcore/crates/tera_core/src/runtime/product_surface/today_paging.rs | 2+-
Mcore/crates/tera_core/src/runtime/product_surface/today_paging_scope.rs | 3+++
Mcore/crates/tera_core/src/runtime/product_surface/today_performance_tests.rs | 145+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mcore/crates/tera_core/src/runtime/product_surface/today_reconciliation.rs | 2+-
Mcore/crates/tera_core/src/runtime/product_surface/today_refresh.rs | 3+--
Mcore/crates/tera_ffi/src/dto.rs | 3++-
Acore/crates/tera_ffi/src/dto/local_network_debug.rs | 13+++++++++++++
Mcore/crates/tera_ffi/tests/runtime_delegation.rs | 53+++++++++++++++++++++++++++++++++++++++++++++++++++++
Mrelease/provenance.json | 18++++++++++++------
Mscripts/kotlin_smoke/src/test/kotlin/tera/smoke/SearchAdmissionTests.kt | 15+++++++++++++++
21 files changed, 684 insertions(+), 170 deletions(-)

diff --git a/Package.swift b/Package.swift @@ -154,6 +154,7 @@ let package = Package( "Runtime/TeraRuntimeClientDraftInventory.swift", "Runtime/TeraRuntimeTodayClient.swift", "Runtime/TeraRuntimeModels.swift", + "Runtime/TeraRuntimeContext.swift", "Runtime/TeraTodaySyncModels.swift", "Runtime/TeraTodayPageModels.swift", "Runtime/TeraRuntimeInvalidation.swift", diff --git a/Tera/Runtime/TeraRuntimeContext.swift b/Tera/Runtime/TeraRuntimeContext.swift @@ -0,0 +1,5 @@ +extension TeraLocalNetwork: CustomDebugStringConvertible { + var debugDescription: String { + "TeraLocalNetwork(schemaVersion: \(schemaVersion), relayCount: \(relayURLs.count), followedAuthorCount: \(followedAuthors.count), generation: \(generation))" + } +} diff --git a/TeraFFI/provenance.json b/TeraFFI/provenance.json @@ -22,9 +22,9 @@ "sha256": "3ed9b7ece2f86e5b5d1ddc6ecbb97deb49c46ca2ea91a930eaec1b580232345c" }, { - "bytes": 79600992, + "bytes": 79563224, "path": "TeraFFI.xcframework/ios-arm64-simulator/libtera_ffi.a", - "sha256": "5b378426d97c3401849a362f96e2ec3190f553244f77b8a56d850864e8f1e227" + "sha256": "94a28b2f2f320256778f74efd1f7f65c6415f7bd4ffe4791302809c2a2b431ce" }, { "bytes": 105627, @@ -37,9 +37,9 @@ "sha256": "3ed9b7ece2f86e5b5d1ddc6ecbb97deb49c46ca2ea91a930eaec1b580232345c" }, { - "bytes": 79664376, + "bytes": 79625088, "path": "TeraFFI.xcframework/ios-arm64/libtera_ffi.a", - "sha256": "a7c3431b2fa7489e27058d8a745652d275b329a7e8bdd60cd23401e18cbf56ad" + "sha256": "b6577b694c39985fab42485d9bc4b967d7d4737dc2ccc78bd130c67775bd5d33" }, { "bytes": 64990, @@ -77,34 +77,34 @@ "sha256": "3ed9b7ece2f86e5b5d1ddc6ecbb97deb49c46ca2ea91a930eaec1b580232345c" }, { - "bytes": 23646320, + "bytes": 23619712, "path": "native/aarch64-apple-darwin/libtera_ffi.dylib", - "sha256": "0befe59a06f3f9925e8f691257fb442699d98039ae49a7fd15ade8fbae41f43f" + "sha256": "db0e7ad03f4dec837e64a50fb680ba5e0b62880f55e93846d07f3d2ffe5921c4" }, { - "bytes": 79600992, + "bytes": 79563224, "path": "native/aarch64-apple-ios-sim/libtera_ffi.a", - "sha256": "5b378426d97c3401849a362f96e2ec3190f553244f77b8a56d850864e8f1e227" + "sha256": "94a28b2f2f320256778f74efd1f7f65c6415f7bd4ffe4791302809c2a2b431ce" }, { - "bytes": 79664376, + "bytes": 79625088, "path": "native/aarch64-apple-ios/libtera_ffi.a", - "sha256": "a7c3431b2fa7489e27058d8a745652d275b329a7e8bdd60cd23401e18cbf56ad" + "sha256": "b6577b694c39985fab42485d9bc4b967d7d4737dc2ccc78bd130c67775bd5d33" }, { - "bytes": 160615, + "bytes": 161180, "path": "source/aarch64-apple-darwin.json", - "sha256": "c04d27244cd651fed3ecf65de2853c296f670cb05675f0bda3028bf6af1a7f89" + "sha256": "e2442d4447dfb565bcd950e0f297b704b0de27ecad6cdb9135cf1d852c0c82c7" }, { - "bytes": 160540, + "bytes": 161105, "path": "source/aarch64-apple-ios-sim.json", - "sha256": "bcd90656720746f4e57779d4607dda6bde068a7583cf58593dc589a6edc6165b" + "sha256": "a17da420d9e40cdd4e35021c5701b013794cb50f667a8defcb5478504def2348" }, { - "bytes": 160510, + "bytes": 161075, "path": "source/aarch64-apple-ios.json", - "sha256": "cf9b15dd892e06d0c68ec9424ae157cc3951020e967299f0268a1ef67234c4ca" + "sha256": "dfdcd3b63c8a45ff60f33073fe56fbbd9d914d364406677343631f727afa379e" } ], "language": "swift", @@ -112,7 +112,7 @@ "schema": "radroots.artifact-manifest.v2", "source": { "repository": "https://github.com/radrootslabs/tera", - "tree": "18b97c7c5e6b18469ec6b19ae25498d304efe4ce" + "tree": "f8d9a6694ee906eb602b34418651f747611e00a5" }, "source_records": { "aarch64-apple-darwin": "source/aarch64-apple-darwin.json", @@ -139,9 +139,9 @@ "sha256": "3ed9b7ece2f86e5b5d1ddc6ecbb97deb49c46ca2ea91a930eaec1b580232345c" }, { - "bytes": 79600992, + "bytes": 79563224, "path": "Tera/Frameworks/TeraFFI.xcframework/ios-arm64-simulator/libtera_ffi.a", - "sha256": "5b378426d97c3401849a362f96e2ec3190f553244f77b8a56d850864e8f1e227" + "sha256": "94a28b2f2f320256778f74efd1f7f65c6415f7bd4ffe4791302809c2a2b431ce" }, { "bytes": 105627, @@ -154,9 +154,9 @@ "sha256": "3ed9b7ece2f86e5b5d1ddc6ecbb97deb49c46ca2ea91a930eaec1b580232345c" }, { - "bytes": 79664376, + "bytes": 79625088, "path": "Tera/Frameworks/TeraFFI.xcframework/ios-arm64/libtera_ffi.a", - "sha256": "a7c3431b2fa7489e27058d8a745652d275b329a7e8bdd60cd23401e18cbf56ad" + "sha256": "b6577b694c39985fab42485d9bc4b967d7d4737dc2ccc78bd130c67775bd5d33" }, { "bytes": 807948, @@ -174,19 +174,19 @@ "sha256": "5d74060f97e52dad69ab7567c16d6b6b34acfab846f468450d89e2394a8a69d5" }, { - "bytes": 160615, + "bytes": 161180, "path": "TeraFFI/source/aarch64-apple-darwin.json", - "sha256": "c04d27244cd651fed3ecf65de2853c296f670cb05675f0bda3028bf6af1a7f89" + "sha256": "e2442d4447dfb565bcd950e0f297b704b0de27ecad6cdb9135cf1d852c0c82c7" }, { - "bytes": 160540, + "bytes": 161105, "path": "TeraFFI/source/aarch64-apple-ios-sim.json", - "sha256": "bcd90656720746f4e57779d4607dda6bde068a7583cf58593dc589a6edc6165b" + "sha256": "a17da420d9e40cdd4e35021c5701b013794cb50f667a8defcb5478504def2348" }, { - "bytes": 160510, + "bytes": 161075, "path": "TeraFFI/source/aarch64-apple-ios.json", - "sha256": "cf9b15dd892e06d0c68ec9424ae157cc3951020e967299f0268a1ef67234c4ca" + "sha256": "dfdcd3b63c8a45ff60f33073fe56fbbd9d914d364406677343631f727afa379e" } ], "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 = "18b97c7c5e6b18469ec6b19ae25498d304efe4ce" -manifest_sha256 = "975eded4554823578e637925c5ec4ae214c2b14ddfc41837a07b3b615fd12192" +source_tree = "f8d9a6694ee906eb602b34418651f747611e00a5" +manifest_sha256 = "4daef4ddc3a79768e65128c0c2464ec311fa707aceb817485d15b4efb422e1dd" source_date_epoch = 1787871027 [foundation] diff --git a/TeraFFI/source/aarch64-apple-darwin.json b/TeraFFI/source/aarch64-apple-darwin.json @@ -1046,10 +1046,16 @@ "sha256": "77a596cc8ae3814a072904a2c25251454b6149c595c19646514e3561f2049bb5" }, "core/crates/tera_core/src/runtime/product_surface/context.rs": { - "bytes": 14211, - "git_blob": "92498807101c638cec675e0b49fde1f4ceed17a2", + "bytes": 16376, + "git_blob": "f3a861b1ce510cce1a51149b879ca954fbf9f618", "mode": "100644", - "sha256": "e20fc6c5ec40fd904fb8a84a406be1ac01a706c59c7a67eb895127a76ad9496e" + "sha256": "9806e6f6772ad223af4469149c3aea589c134012f5ec47a1f00ccc3f52b6205d" + }, + "core/crates/tera_core/src/runtime/product_surface/context_admission_tests.rs": { + "bytes": 3450, + "git_blob": "7d60258bba53d8ef20baacffb65cd58e0252d63f", + "mode": "100644", + "sha256": "766a8e956874d7d60a78753d21de142aecd51d5d9074140cf62ebf002bf2e8a9" }, "core/crates/tera_core/src/runtime/product_surface/coordinate.rs": { "bytes": 4939, @@ -1874,10 +1880,10 @@ "sha256": "1d105fa23b9914c466009402f60bf3de83be3cf302be39b818392d5ae11faa6c" }, "core/crates/tera_core/src/runtime/product_surface/today.rs": { - "bytes": 130103, - "git_blob": "4dfeba25d2cfafbf67d6f6ec345c8f67b5ce6dc3", + "bytes": 130321, + "git_blob": "1d059ed32a190b662f94aeac8c1396f8c1f9f478", "mode": "100644", - "sha256": "ccd5b84abd0bd897438ea01fd014bf67a2d78d02f4a4be2481f177b0914db5c6" + "sha256": "cdf65cf74fcd873dcea900ecf1832caeec7ce44fe2cfff15367f626a26f5c0f3" }, "core/crates/tera_core/src/runtime/product_surface/today_admission_tests.rs": { "bytes": 13548, @@ -1983,21 +1989,21 @@ }, "core/crates/tera_core/src/runtime/product_surface/today_paging.rs": { "bytes": 6577, - "git_blob": "8e291338e77dfcdb7d9e1529520a6214586663c3", + "git_blob": "db0141d33fd9fedac37b8405edd1e2dca4cef179", "mode": "100644", - "sha256": "584e4b6acd2aea58f4c4d18eea6272919744b165849d70d164e478da0c462a0f" + "sha256": "f8e3da8786b1700e466020ad674da925c60854b0fc5670789029467891d7e713" }, "core/crates/tera_core/src/runtime/product_surface/today_paging_scope.rs": { - "bytes": 1703, - "git_blob": "cc1fb36406b9ad236a5653bbd59d8256dd91bd19", + "bytes": 1800, + "git_blob": "a6f1635637f14bc14f070a3ed6b5ef2e2818117d", "mode": "100644", - "sha256": "e9ea1a0ee6c52031895184cd0a2b3c526318fd521ab2bd6b1b08ef53f3c9ff66" + "sha256": "a818a499cd947e6424351131c61fec6a1bc2ef833129fecda356c35f61541699" }, "core/crates/tera_core/src/runtime/product_surface/today_performance_tests.rs": { - "bytes": 9725, - "git_blob": "3e46dc627b8a0826fd26bfd2dd16e35590d75bfb", + "bytes": 14490, + "git_blob": "816b82c2e38b921ffb9a8a4e25054688ef61b1ca", "mode": "100644", - "sha256": "0182c407fe4ff61c0a50d16a9c2d61a93a7ad79b177ac85ab0822c039fed341a" + "sha256": "785e0c163b7660648b07bf128183cfa722acf661660b922da75ddb212e93ff80" }, "core/crates/tera_core/src/runtime/product_surface/today_permissive_evidence_tests.rs": { "bytes": 1242, @@ -2013,9 +2019,9 @@ }, "core/crates/tera_core/src/runtime/product_surface/today_reconciliation.rs": { "bytes": 2370, - "git_blob": "1282df42a3e8caf92ed663eb1392a41fa0f0f8f1", + "git_blob": "1cbd2c87dfb8803aa0da3a95205572d77d1cd0f8", "mode": "100644", - "sha256": "e5b8a42bbd3edda57490ee8ec4504dab1f7fb18859d9bb37509e5ecd05115d72" + "sha256": "25478bff1ff14f4ee81c9995d5882388e3f21de7e8a51187ee19d6ccee56c187" }, "core/crates/tera_core/src/runtime/product_surface/today_reconciliation_tests.rs": { "bytes": 3678, @@ -2024,10 +2030,10 @@ "sha256": "25fdb0267fba678ab8952d94e5d4a278f6ee062c32b2fc65b9ad5c6ec6e4300e" }, "core/crates/tera_core/src/runtime/product_surface/today_refresh.rs": { - "bytes": 6407, - "git_blob": "c31e7ea71bbb95acb0411549f23495a86f8f781d", + "bytes": 6406, + "git_blob": "f7391f8f735f97a72e8c106c8f21d7e6029e1707", "mode": "100644", - "sha256": "9fc9289143661968c5327975b0b80da0d5cac2f790a5f77212b0b6d5f7621fb5" + "sha256": "eccef47b40e5744c53df3835ccb668e07ef1e5b4014ef8f74d0ff9ae1cbb7f27" }, "core/crates/tera_core/src/runtime/product_surface/today_scope_tests.rs": { "bytes": 14361, @@ -2324,10 +2330,10 @@ "sha256": "e05c1d8778f8482039ed4ffac1b213d08d3d8bba6e33580d354e435346a07819" }, "core/crates/tera_ffi/src/dto.rs": { - "bytes": 107414, - "git_blob": "52ed2d94bd53aad208f76b1226acc1f429aa2746", + "bytes": 107432, + "git_blob": "d16ea3d2b40277ec6c65908968bd61466f874280", "mode": "100644", - "sha256": "a47ccb2d2a42f36ef63a7d9489c47e2f99d06b1a5af2e3b7fbe6dba0f47ed79f" + "sha256": "c44be95cc728333ed4e88c029804031aa3141c62e742042ae885a1332de57b84" }, "core/crates/tera_ffi/src/dto/calendar.rs": { "bytes": 2040, @@ -2341,6 +2347,12 @@ "mode": "100644", "sha256": "54b6200c83b7b3681bf0167ee9098511f285aa3b70562f7ceb8275833748e6d4" }, + "core/crates/tera_ffi/src/dto/local_network_debug.rs": { + "bytes": 521, + "git_blob": "060c8206748f2cefc4690c350e778377e15c0fab", + "mode": "100644", + "sha256": "32a763eda1e03db233091613fde98ea639578abd91ba7e2146e65883d5b7062c" + }, "core/crates/tera_ffi/src/dto/today_sync.rs": { "bytes": 4837, "git_blob": "b80972c1517fcda4be3593bc92015316c582b4e4", @@ -2654,10 +2666,10 @@ "sha256": "db41f36cd1d8f0dc9d1f6b065b0d4dbaaab7d11b01a185a05c5b478a5c7a5816" }, "core/crates/tera_ffi/tests/runtime_delegation.rs": { - "bytes": 34760, - "git_blob": "5488322926e8abe4aaf395cccf58e0fe034754ce", + "bytes": 36873, + "git_blob": "6d66be47bfca37633ae4dc72f9d33f04d042c35f", "mode": "100644", - "sha256": "56878042315d512ff14efc49a9c84affba55325ec3574308175b7283cfa3e451" + "sha256": "d2a7666d3e3d83f7acd313ed99fbf109148aa031e747288e04e3e681c46bf888" }, "core/crates/tera_ffi/tests/runtime_lifecycle.rs": { "bytes": 4293, @@ -3092,10 +3104,10 @@ "sha256": "01164253edfc8186d3ffb1aec19aef2f689b0ca448f9eac299aa1082f70c299e" }, "scripts/kotlin_smoke/src/test/kotlin/tera/smoke/SearchAdmissionTests.kt": { - "bytes": 2134, - "git_blob": "3b39b5077bc6f702b9dccfd42490ede996c927e6", + "bytes": 3118, + "git_blob": "5e6957d33d137adb975158198580e4febe0f75f5", "mode": "100644", - "sha256": "aca646aba37ff726958ced8b6f9cf25547b382774a18b7de0ea11f93cc189327" + "sha256": "c8d02b000fa65563df0bdf066dc3528161b7174259ed2397890d786d2314360d" }, "scripts/kotlin_smoke/src/test/kotlin/tera/smoke/SmokeFixture.kt": { "bytes": 4450, @@ -3417,6 +3429,6 @@ } }, "policy": "staged_inputs", - "tree": "18b97c7c5e6b18469ec6b19ae25498d304efe4ce" + "tree": "f8d9a6694ee906eb602b34418651f747611e00a5" } } diff --git a/TeraFFI/source/aarch64-apple-ios-sim.json b/TeraFFI/source/aarch64-apple-ios-sim.json @@ -1044,10 +1044,16 @@ "sha256": "77a596cc8ae3814a072904a2c25251454b6149c595c19646514e3561f2049bb5" }, "core/crates/tera_core/src/runtime/product_surface/context.rs": { - "bytes": 14211, - "git_blob": "92498807101c638cec675e0b49fde1f4ceed17a2", + "bytes": 16376, + "git_blob": "f3a861b1ce510cce1a51149b879ca954fbf9f618", "mode": "100644", - "sha256": "e20fc6c5ec40fd904fb8a84a406be1ac01a706c59c7a67eb895127a76ad9496e" + "sha256": "9806e6f6772ad223af4469149c3aea589c134012f5ec47a1f00ccc3f52b6205d" + }, + "core/crates/tera_core/src/runtime/product_surface/context_admission_tests.rs": { + "bytes": 3450, + "git_blob": "7d60258bba53d8ef20baacffb65cd58e0252d63f", + "mode": "100644", + "sha256": "766a8e956874d7d60a78753d21de142aecd51d5d9074140cf62ebf002bf2e8a9" }, "core/crates/tera_core/src/runtime/product_surface/coordinate.rs": { "bytes": 4939, @@ -1872,10 +1878,10 @@ "sha256": "1d105fa23b9914c466009402f60bf3de83be3cf302be39b818392d5ae11faa6c" }, "core/crates/tera_core/src/runtime/product_surface/today.rs": { - "bytes": 130103, - "git_blob": "4dfeba25d2cfafbf67d6f6ec345c8f67b5ce6dc3", + "bytes": 130321, + "git_blob": "1d059ed32a190b662f94aeac8c1396f8c1f9f478", "mode": "100644", - "sha256": "ccd5b84abd0bd897438ea01fd014bf67a2d78d02f4a4be2481f177b0914db5c6" + "sha256": "cdf65cf74fcd873dcea900ecf1832caeec7ce44fe2cfff15367f626a26f5c0f3" }, "core/crates/tera_core/src/runtime/product_surface/today_admission_tests.rs": { "bytes": 13548, @@ -1981,21 +1987,21 @@ }, "core/crates/tera_core/src/runtime/product_surface/today_paging.rs": { "bytes": 6577, - "git_blob": "8e291338e77dfcdb7d9e1529520a6214586663c3", + "git_blob": "db0141d33fd9fedac37b8405edd1e2dca4cef179", "mode": "100644", - "sha256": "584e4b6acd2aea58f4c4d18eea6272919744b165849d70d164e478da0c462a0f" + "sha256": "f8e3da8786b1700e466020ad674da925c60854b0fc5670789029467891d7e713" }, "core/crates/tera_core/src/runtime/product_surface/today_paging_scope.rs": { - "bytes": 1703, - "git_blob": "cc1fb36406b9ad236a5653bbd59d8256dd91bd19", + "bytes": 1800, + "git_blob": "a6f1635637f14bc14f070a3ed6b5ef2e2818117d", "mode": "100644", - "sha256": "e9ea1a0ee6c52031895184cd0a2b3c526318fd521ab2bd6b1b08ef53f3c9ff66" + "sha256": "a818a499cd947e6424351131c61fec6a1bc2ef833129fecda356c35f61541699" }, "core/crates/tera_core/src/runtime/product_surface/today_performance_tests.rs": { - "bytes": 9725, - "git_blob": "3e46dc627b8a0826fd26bfd2dd16e35590d75bfb", + "bytes": 14490, + "git_blob": "816b82c2e38b921ffb9a8a4e25054688ef61b1ca", "mode": "100644", - "sha256": "0182c407fe4ff61c0a50d16a9c2d61a93a7ad79b177ac85ab0822c039fed341a" + "sha256": "785e0c163b7660648b07bf128183cfa722acf661660b922da75ddb212e93ff80" }, "core/crates/tera_core/src/runtime/product_surface/today_permissive_evidence_tests.rs": { "bytes": 1242, @@ -2011,9 +2017,9 @@ }, "core/crates/tera_core/src/runtime/product_surface/today_reconciliation.rs": { "bytes": 2370, - "git_blob": "1282df42a3e8caf92ed663eb1392a41fa0f0f8f1", + "git_blob": "1cbd2c87dfb8803aa0da3a95205572d77d1cd0f8", "mode": "100644", - "sha256": "e5b8a42bbd3edda57490ee8ec4504dab1f7fb18859d9bb37509e5ecd05115d72" + "sha256": "25478bff1ff14f4ee81c9995d5882388e3f21de7e8a51187ee19d6ccee56c187" }, "core/crates/tera_core/src/runtime/product_surface/today_reconciliation_tests.rs": { "bytes": 3678, @@ -2022,10 +2028,10 @@ "sha256": "25fdb0267fba678ab8952d94e5d4a278f6ee062c32b2fc65b9ad5c6ec6e4300e" }, "core/crates/tera_core/src/runtime/product_surface/today_refresh.rs": { - "bytes": 6407, - "git_blob": "c31e7ea71bbb95acb0411549f23495a86f8f781d", + "bytes": 6406, + "git_blob": "f7391f8f735f97a72e8c106c8f21d7e6029e1707", "mode": "100644", - "sha256": "9fc9289143661968c5327975b0b80da0d5cac2f790a5f77212b0b6d5f7621fb5" + "sha256": "eccef47b40e5744c53df3835ccb668e07ef1e5b4014ef8f74d0ff9ae1cbb7f27" }, "core/crates/tera_core/src/runtime/product_surface/today_scope_tests.rs": { "bytes": 14361, @@ -2322,10 +2328,10 @@ "sha256": "e05c1d8778f8482039ed4ffac1b213d08d3d8bba6e33580d354e435346a07819" }, "core/crates/tera_ffi/src/dto.rs": { - "bytes": 107414, - "git_blob": "52ed2d94bd53aad208f76b1226acc1f429aa2746", + "bytes": 107432, + "git_blob": "d16ea3d2b40277ec6c65908968bd61466f874280", "mode": "100644", - "sha256": "a47ccb2d2a42f36ef63a7d9489c47e2f99d06b1a5af2e3b7fbe6dba0f47ed79f" + "sha256": "c44be95cc728333ed4e88c029804031aa3141c62e742042ae885a1332de57b84" }, "core/crates/tera_ffi/src/dto/calendar.rs": { "bytes": 2040, @@ -2339,6 +2345,12 @@ "mode": "100644", "sha256": "54b6200c83b7b3681bf0167ee9098511f285aa3b70562f7ceb8275833748e6d4" }, + "core/crates/tera_ffi/src/dto/local_network_debug.rs": { + "bytes": 521, + "git_blob": "060c8206748f2cefc4690c350e778377e15c0fab", + "mode": "100644", + "sha256": "32a763eda1e03db233091613fde98ea639578abd91ba7e2146e65883d5b7062c" + }, "core/crates/tera_ffi/src/dto/today_sync.rs": { "bytes": 4837, "git_blob": "b80972c1517fcda4be3593bc92015316c582b4e4", @@ -2652,10 +2664,10 @@ "sha256": "db41f36cd1d8f0dc9d1f6b065b0d4dbaaab7d11b01a185a05c5b478a5c7a5816" }, "core/crates/tera_ffi/tests/runtime_delegation.rs": { - "bytes": 34760, - "git_blob": "5488322926e8abe4aaf395cccf58e0fe034754ce", + "bytes": 36873, + "git_blob": "6d66be47bfca37633ae4dc72f9d33f04d042c35f", "mode": "100644", - "sha256": "56878042315d512ff14efc49a9c84affba55325ec3574308175b7283cfa3e451" + "sha256": "d2a7666d3e3d83f7acd313ed99fbf109148aa031e747288e04e3e681c46bf888" }, "core/crates/tera_ffi/tests/runtime_lifecycle.rs": { "bytes": 4293, @@ -3090,10 +3102,10 @@ "sha256": "01164253edfc8186d3ffb1aec19aef2f689b0ca448f9eac299aa1082f70c299e" }, "scripts/kotlin_smoke/src/test/kotlin/tera/smoke/SearchAdmissionTests.kt": { - "bytes": 2134, - "git_blob": "3b39b5077bc6f702b9dccfd42490ede996c927e6", + "bytes": 3118, + "git_blob": "5e6957d33d137adb975158198580e4febe0f75f5", "mode": "100644", - "sha256": "aca646aba37ff726958ced8b6f9cf25547b382774a18b7de0ea11f93cc189327" + "sha256": "c8d02b000fa65563df0bdf066dc3528161b7174259ed2397890d786d2314360d" }, "scripts/kotlin_smoke/src/test/kotlin/tera/smoke/SmokeFixture.kt": { "bytes": 4450, @@ -3415,6 +3427,6 @@ } }, "policy": "staged_inputs", - "tree": "18b97c7c5e6b18469ec6b19ae25498d304efe4ce" + "tree": "f8d9a6694ee906eb602b34418651f747611e00a5" } } diff --git a/TeraFFI/source/aarch64-apple-ios.json b/TeraFFI/source/aarch64-apple-ios.json @@ -1044,10 +1044,16 @@ "sha256": "77a596cc8ae3814a072904a2c25251454b6149c595c19646514e3561f2049bb5" }, "core/crates/tera_core/src/runtime/product_surface/context.rs": { - "bytes": 14211, - "git_blob": "92498807101c638cec675e0b49fde1f4ceed17a2", + "bytes": 16376, + "git_blob": "f3a861b1ce510cce1a51149b879ca954fbf9f618", "mode": "100644", - "sha256": "e20fc6c5ec40fd904fb8a84a406be1ac01a706c59c7a67eb895127a76ad9496e" + "sha256": "9806e6f6772ad223af4469149c3aea589c134012f5ec47a1f00ccc3f52b6205d" + }, + "core/crates/tera_core/src/runtime/product_surface/context_admission_tests.rs": { + "bytes": 3450, + "git_blob": "7d60258bba53d8ef20baacffb65cd58e0252d63f", + "mode": "100644", + "sha256": "766a8e956874d7d60a78753d21de142aecd51d5d9074140cf62ebf002bf2e8a9" }, "core/crates/tera_core/src/runtime/product_surface/coordinate.rs": { "bytes": 4939, @@ -1872,10 +1878,10 @@ "sha256": "1d105fa23b9914c466009402f60bf3de83be3cf302be39b818392d5ae11faa6c" }, "core/crates/tera_core/src/runtime/product_surface/today.rs": { - "bytes": 130103, - "git_blob": "4dfeba25d2cfafbf67d6f6ec345c8f67b5ce6dc3", + "bytes": 130321, + "git_blob": "1d059ed32a190b662f94aeac8c1396f8c1f9f478", "mode": "100644", - "sha256": "ccd5b84abd0bd897438ea01fd014bf67a2d78d02f4a4be2481f177b0914db5c6" + "sha256": "cdf65cf74fcd873dcea900ecf1832caeec7ce44fe2cfff15367f626a26f5c0f3" }, "core/crates/tera_core/src/runtime/product_surface/today_admission_tests.rs": { "bytes": 13548, @@ -1981,21 +1987,21 @@ }, "core/crates/tera_core/src/runtime/product_surface/today_paging.rs": { "bytes": 6577, - "git_blob": "8e291338e77dfcdb7d9e1529520a6214586663c3", + "git_blob": "db0141d33fd9fedac37b8405edd1e2dca4cef179", "mode": "100644", - "sha256": "584e4b6acd2aea58f4c4d18eea6272919744b165849d70d164e478da0c462a0f" + "sha256": "f8e3da8786b1700e466020ad674da925c60854b0fc5670789029467891d7e713" }, "core/crates/tera_core/src/runtime/product_surface/today_paging_scope.rs": { - "bytes": 1703, - "git_blob": "cc1fb36406b9ad236a5653bbd59d8256dd91bd19", + "bytes": 1800, + "git_blob": "a6f1635637f14bc14f070a3ed6b5ef2e2818117d", "mode": "100644", - "sha256": "e9ea1a0ee6c52031895184cd0a2b3c526318fd521ab2bd6b1b08ef53f3c9ff66" + "sha256": "a818a499cd947e6424351131c61fec6a1bc2ef833129fecda356c35f61541699" }, "core/crates/tera_core/src/runtime/product_surface/today_performance_tests.rs": { - "bytes": 9725, - "git_blob": "3e46dc627b8a0826fd26bfd2dd16e35590d75bfb", + "bytes": 14490, + "git_blob": "816b82c2e38b921ffb9a8a4e25054688ef61b1ca", "mode": "100644", - "sha256": "0182c407fe4ff61c0a50d16a9c2d61a93a7ad79b177ac85ab0822c039fed341a" + "sha256": "785e0c163b7660648b07bf128183cfa722acf661660b922da75ddb212e93ff80" }, "core/crates/tera_core/src/runtime/product_surface/today_permissive_evidence_tests.rs": { "bytes": 1242, @@ -2011,9 +2017,9 @@ }, "core/crates/tera_core/src/runtime/product_surface/today_reconciliation.rs": { "bytes": 2370, - "git_blob": "1282df42a3e8caf92ed663eb1392a41fa0f0f8f1", + "git_blob": "1cbd2c87dfb8803aa0da3a95205572d77d1cd0f8", "mode": "100644", - "sha256": "e5b8a42bbd3edda57490ee8ec4504dab1f7fb18859d9bb37509e5ecd05115d72" + "sha256": "25478bff1ff14f4ee81c9995d5882388e3f21de7e8a51187ee19d6ccee56c187" }, "core/crates/tera_core/src/runtime/product_surface/today_reconciliation_tests.rs": { "bytes": 3678, @@ -2022,10 +2028,10 @@ "sha256": "25fdb0267fba678ab8952d94e5d4a278f6ee062c32b2fc65b9ad5c6ec6e4300e" }, "core/crates/tera_core/src/runtime/product_surface/today_refresh.rs": { - "bytes": 6407, - "git_blob": "c31e7ea71bbb95acb0411549f23495a86f8f781d", + "bytes": 6406, + "git_blob": "f7391f8f735f97a72e8c106c8f21d7e6029e1707", "mode": "100644", - "sha256": "9fc9289143661968c5327975b0b80da0d5cac2f790a5f77212b0b6d5f7621fb5" + "sha256": "eccef47b40e5744c53df3835ccb668e07ef1e5b4014ef8f74d0ff9ae1cbb7f27" }, "core/crates/tera_core/src/runtime/product_surface/today_scope_tests.rs": { "bytes": 14361, @@ -2322,10 +2328,10 @@ "sha256": "e05c1d8778f8482039ed4ffac1b213d08d3d8bba6e33580d354e435346a07819" }, "core/crates/tera_ffi/src/dto.rs": { - "bytes": 107414, - "git_blob": "52ed2d94bd53aad208f76b1226acc1f429aa2746", + "bytes": 107432, + "git_blob": "d16ea3d2b40277ec6c65908968bd61466f874280", "mode": "100644", - "sha256": "a47ccb2d2a42f36ef63a7d9489c47e2f99d06b1a5af2e3b7fbe6dba0f47ed79f" + "sha256": "c44be95cc728333ed4e88c029804031aa3141c62e742042ae885a1332de57b84" }, "core/crates/tera_ffi/src/dto/calendar.rs": { "bytes": 2040, @@ -2339,6 +2345,12 @@ "mode": "100644", "sha256": "54b6200c83b7b3681bf0167ee9098511f285aa3b70562f7ceb8275833748e6d4" }, + "core/crates/tera_ffi/src/dto/local_network_debug.rs": { + "bytes": 521, + "git_blob": "060c8206748f2cefc4690c350e778377e15c0fab", + "mode": "100644", + "sha256": "32a763eda1e03db233091613fde98ea639578abd91ba7e2146e65883d5b7062c" + }, "core/crates/tera_ffi/src/dto/today_sync.rs": { "bytes": 4837, "git_blob": "b80972c1517fcda4be3593bc92015316c582b4e4", @@ -2652,10 +2664,10 @@ "sha256": "db41f36cd1d8f0dc9d1f6b065b0d4dbaaab7d11b01a185a05c5b478a5c7a5816" }, "core/crates/tera_ffi/tests/runtime_delegation.rs": { - "bytes": 34760, - "git_blob": "5488322926e8abe4aaf395cccf58e0fe034754ce", + "bytes": 36873, + "git_blob": "6d66be47bfca37633ae4dc72f9d33f04d042c35f", "mode": "100644", - "sha256": "56878042315d512ff14efc49a9c84affba55325ec3574308175b7283cfa3e451" + "sha256": "d2a7666d3e3d83f7acd313ed99fbf109148aa031e747288e04e3e681c46bf888" }, "core/crates/tera_ffi/tests/runtime_lifecycle.rs": { "bytes": 4293, @@ -3090,10 +3102,10 @@ "sha256": "01164253edfc8186d3ffb1aec19aef2f689b0ca448f9eac299aa1082f70c299e" }, "scripts/kotlin_smoke/src/test/kotlin/tera/smoke/SearchAdmissionTests.kt": { - "bytes": 2134, - "git_blob": "3b39b5077bc6f702b9dccfd42490ede996c927e6", + "bytes": 3118, + "git_blob": "5e6957d33d137adb975158198580e4febe0f75f5", "mode": "100644", - "sha256": "aca646aba37ff726958ced8b6f9cf25547b382774a18b7de0ea11f93cc189327" + "sha256": "c8d02b000fa65563df0bdf066dc3528161b7174259ed2397890d786d2314360d" }, "scripts/kotlin_smoke/src/test/kotlin/tera/smoke/SmokeFixture.kt": { "bytes": 4450, @@ -3415,6 +3427,6 @@ } }, "policy": "staged_inputs", - "tree": "18b97c7c5e6b18469ec6b19ae25498d304efe4ce" + "tree": "f8d9a6694ee906eb602b34418651f747611e00a5" } } diff --git a/TeraTests/TeraSearchFFICompatibilityTests.swift b/TeraTests/TeraSearchFFICompatibilityTests.swift @@ -1,7 +1,64 @@ +@testable import TeraApp import TeraKitBindings import XCTest final class TeraSearchFFICompatibilityTests: XCTestCase { + func testInstalledContextEnforcesAggregateAdmission() async throws { + let fixture = try MediaOwnershipFixture() + defer { fixture.remove() } + let runtime = try await fixture.runtime() + let authors = (0 ..< 4096).map { index in + let suffix = String(index, radix: 16) + return String(repeating: "0", count: 64 - suffix.count) + suffix + } + let context = network(authors: authors) + XCTAssertEqual(try runtime.phase1LocalNetwork(context: context).followedAuthors, authors) + for invalid in [ + authors + [String(repeating: "0", count: 60) + "1000"], + [String(repeating: "a", count: 64), String(repeating: "a", count: 64)], + [String(repeating: "A", count: 64)], [String(repeating: "x", count: 262_145)], + ] { + do { + _ = try await runtime.phase1Search(context: network(authors: invalid), query: "carrot", limit: 20, asOfUnixS: 1_800_000_000, viewerTimeZone: "UTC") + XCTFail("Invalid public context must fail before query execution") + } catch let TeraAppError.Failure(report) { + XCTAssertEqual(report.code, "invalid_local_network") + XCTAssertFalse(report.retryable) + XCTAssertEqual(report.recoveryActions, ["correct_input"]) + } + } + _ = try await runtime.shutdown() + do { + _ = try await runtime.phase1Search(context: context, query: "carrot", limit: 20, asOfUnixS: 1_800_000_000, viewerTimeZone: "UTC") + XCTFail("Valid-context closed runtime retains lifecycle precedence") + } catch let TeraAppError.Failure(report) { + XCTAssertEqual(report.code, "client_closed") + } + } + + func testHostContextDebugRedactsRawFields() { + let context = TeraLocalNetwork( + schemaVersion: 1, id: "private-id-sentinel", label: "private-label-sentinel", + relayURLs: ["wss://private-relay-sentinel.example"], locality: "private-location-sentinel", + followedAuthors: [String(repeating: "a", count: 64)], generation: 7 + ) + let debug = String(reflecting: context) + for sentinel in [context.id, context.label, context.relayURLs[0], context.locality ?? "", context.followedAuthors[0]] { + XCTAssertFalse(debug.contains(sentinel)) + } + XCTAssertTrue(debug.contains("relayCount: 1")) + XCTAssertTrue(debug.contains("followedAuthorCount: 1")) + XCTAssertTrue(debug.contains("generation: 7")) + XCTAssertEqual(context.label, "private-label-sentinel") + } + + private func network(authors: [String]) -> FfiLocalNetworkRecord { + FfiLocalNetworkRecord( + schemaVersion: 1, id: "nearby", label: "Nearby", relayUrls: ["wss://relay.example"], + locality: nil, followedAuthors: authors, generation: 1 + ) + } + func testInstalledSearchEnforcesRawAndNormalizedByteAdmission() async throws { let fixture = try MediaOwnershipFixture() defer { fixture.remove() } diff --git a/core/crates/tera_core/src/runtime/product_surface/context.rs b/core/crates/tera_core/src/runtime/product_surface/context.rs @@ -8,9 +8,15 @@ use super::LocalNetworkId; const CONTEXT_TEXT_MAX_BYTES: usize = 256; const RELAY_URL_MAX_BYTES: usize = 2_048; +const FOLLOWED_AUTHORS_MAX_ITEMS: usize = 4_096; +const FOLLOWED_AUTHORS_MAX_BYTES: usize = 262_144; + +#[cfg(test)] +#[path = "context_admission_tests.rs"] +mod admission_tests; /// A validated local query/composer context. It has no Nostr event identity. -#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)] +#[derive(Clone, Deserialize, Eq, PartialEq, Serialize)] #[serde(rename_all = "camelCase")] pub struct LocalNetwork { pub id: LocalNetworkId, @@ -21,6 +27,17 @@ pub struct LocalNetwork { pub generation: u64, } +impl std::fmt::Debug for LocalNetwork { + fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + formatter + .debug_struct("LocalNetwork") + .field("relay_count", &self.relay_urls.len()) + .field("followed_author_count", &self.followed_authors.len()) + .field("generation", &self.generation) + .finish_non_exhaustive() + } +} + #[derive(Clone, Debug, Error, Eq, PartialEq)] pub enum LocalNetworkError { #[error("local network {field} is invalid")] @@ -77,58 +94,64 @@ impl LocalNetwork { generation: u64, relay_policy: LocalNetworkRelayPolicy, ) -> Result<Self, LocalNetworkError> { - let id = LocalNetworkId::new(id)?; - validate_text(&label, "label")?; - if let Some(locality) = locality.as_deref() { - validate_text(locality, "locality")?; + let mut network = Self { + id: LocalNetworkId::new(id)?, + label, + relay_urls, + locality, + followed_authors, + generation, + }; + network.relay_urls = network.validate(Some(relay_policy))?; + Ok(network) + } + + /// Revalidates public mutable/decoded query data without granting transport access. + pub(crate) fn validate_query_context(&self) -> Result<(), LocalNetworkError> { + self.validate(None).map(|_| ()) + } + + fn validate( + &self, + relay_policy: Option<LocalNetworkRelayPolicy>, + ) -> Result<Vec<String>, LocalNetworkError> { + // Check every aggregate/raw bound before parsing, deduplication or hashing. + if self.followed_authors.len() > FOLLOWED_AUTHORS_MAX_ITEMS + || self + .followed_authors + .iter() + .try_fold(0usize, |total, value| total.checked_add(value.len())) + .is_none_or(|total| total > FOLLOWED_AUTHORS_MAX_BYTES) + { + return Err(LocalNetworkError::InvalidAuthor); } - if relay_urls.is_empty() { + if self.relay_urls.is_empty() { return Err(LocalNetworkError::MissingRelay); } - if relay_urls.len() > radroots_transport::target::TARGET_SET_MAX_ITEMS { + if self.relay_urls.len() > radroots_transport::target::TARGET_SET_MAX_ITEMS + || self + .relay_urls + .iter() + .any(|relay| relay.is_empty() || relay.len() > RELAY_URL_MAX_BYTES) + { return Err(LocalNetworkError::InvalidRelay); } + validate_text(self.id.as_str(), "id")?; + validate_text(&self.label, "label")?; + if let Some(locality) = self.locality.as_deref() { + validate_text(locality, "locality")?; + } + validate_authors(&self.followed_authors)?; let mut relays = BTreeSet::new(); - let mut canonical_relay_urls = Vec::with_capacity(relay_urls.len()); - for relay in relay_urls { - if relay.is_empty() || relay.len() > RELAY_URL_MAX_BYTES { - return Err(LocalNetworkError::InvalidRelay); - } - let relay = RelayUrl::parse( - relay, - match relay_policy { - LocalNetworkRelayPolicy::Public => RelayUrlPolicy::Public, - LocalNetworkRelayPolicy::Simulator => RelayUrlPolicy::Local, - LocalNetworkRelayPolicy::Device => RelayUrlPolicy::PrivateNetwork, - }, - ) - .map_err(|_| LocalNetworkError::InvalidRelay)?; + let mut canonical_relay_urls = Vec::with_capacity(self.relay_urls.len()); + for relay in &self.relay_urls { + let relay = parse_relay(relay, relay_policy)?; if !relays.insert(relay.clone()) { return Err(LocalNetworkError::DuplicateRelay); } canonical_relay_urls.push(relay.to_string()); } - let mut authors = BTreeSet::new(); - for author in &followed_authors { - if author.len() != 64 - || !author - .bytes() - .all(|byte| byte.is_ascii_digit() || (b'a'..=b'f').contains(&byte)) - { - return Err(LocalNetworkError::InvalidAuthor); - } - if !authors.insert(author) { - return Err(LocalNetworkError::DuplicateAuthor); - } - } - Ok(Self { - id, - label, - relay_urls: canonical_relay_urls, - locality, - followed_authors, - generation, - }) + Ok(canonical_relay_urls) } /// Applies the locked locality policy to the selected local context. @@ -151,8 +174,8 @@ impl LocalNetwork { fn validate_text(value: &str, field: &'static str) -> Result<(), LocalNetworkError> { if value.is_empty() - || value.trim() != value || value.len() > CONTEXT_TEXT_MAX_BYTES + || value.trim() != value || value.chars().any(char::is_control) { return Err(LocalNetworkError::InvalidText { field }); @@ -160,6 +183,45 @@ fn validate_text(value: &str, field: &'static str) -> Result<(), LocalNetworkErr Ok(()) } +fn validate_authors(authors: &[String]) -> Result<(), LocalNetworkError> { + let mut unique = BTreeSet::new(); + for author in authors { + if author.len() != 64 + || !author + .bytes() + .all(|byte| byte.is_ascii_digit() || (b'a'..=b'f').contains(&byte)) + { + return Err(LocalNetworkError::InvalidAuthor); + } + if !unique.insert(author) { + return Err(LocalNetworkError::DuplicateAuthor); + } + } + Ok(()) +} + +fn parse_relay( + relay: &str, + policy: Option<LocalNetworkRelayPolicy>, +) -> Result<RelayUrl, LocalNetworkError> { + let policies: &[RelayUrlPolicy] = match policy { + Some(LocalNetworkRelayPolicy::Public) => &[RelayUrlPolicy::Public], + Some(LocalNetworkRelayPolicy::Simulator) => &[RelayUrlPolicy::Local], + Some(LocalNetworkRelayPolicy::Device) => &[RelayUrlPolicy::PrivateNetwork], + // Query contexts do not initiate connections. Retain all existing forms; + // exact constructor/FFI and transport destination policy remains separate. + None => &[ + RelayUrlPolicy::Public, + RelayUrlPolicy::Local, + RelayUrlPolicy::PrivateNetwork, + ], + }; + policies + .iter() + .find_map(|policy| RelayUrl::parse(relay, *policy).ok()) + .ok_or(LocalNetworkError::InvalidRelay) +} + #[derive(Clone, Copy, Debug, Deserialize, Eq, PartialEq, Serialize)] #[serde(rename_all = "PascalCase")] pub enum LocalityEvidence { diff --git a/core/crates/tera_core/src/runtime/product_surface/context_admission_tests.rs b/core/crates/tera_core/src/runtime/product_surface/context_admission_tests.rs @@ -0,0 +1,112 @@ +use super::*; + +fn selected(authors: Vec<String>) -> Result<LocalNetwork, LocalNetworkError> { + LocalNetwork::new( + "nearby".into(), + "Nearby".into(), + vec!["wss://relay.example".into()], + None, + authors, + 7, + ) +} + +#[test] +fn followed_author_aggregate_is_admitted_at_exact_boundary() { + let authors = (0..4096) + .map(|index| format!("{index:064x}")) + .collect::<Vec<_>>(); + let context = selected(authors.clone()).unwrap(); + assert_eq!(context.followed_authors, authors); + assert_eq!( + context + .followed_authors + .iter() + .map(String::len) + .sum::<usize>(), + 262_144 + ); + let mut over = authors; + over.push(format!("{:064x}", 4096)); + assert_eq!(selected(over), Err(LocalNetworkError::InvalidAuthor)); + assert!(selected(Vec::new()).unwrap().followed_authors.is_empty()); +} + +#[test] +fn context_author_shape_and_duplicates_retain_typed_failures() { + for authors in [ + vec!["a".repeat(63)], + vec!["A".repeat(64)], + vec!["x".repeat(262_145)], + ] { + assert_eq!(selected(authors), Err(LocalNetworkError::InvalidAuthor)); + } + assert_eq!( + selected(vec!["a".repeat(64), "a".repeat(64)]), + Err(LocalNetworkError::DuplicateAuthor) + ); +} + +#[test] +fn context_revalidation_preserves_supported_relay_forms_and_wire_values() { + for (relay, policy) in [ + ("wss://relay.example", LocalNetworkRelayPolicy::Public), + ("ws://127.0.0.1:7447", LocalNetworkRelayPolicy::Simulator), + ("ws://10.0.0.1:7447", LocalNetworkRelayPolicy::Device), + ] { + let context = LocalNetwork::new_for_relay_policy( + "nearby".into(), + "Nearby".into(), + vec![relay.into()], + None, + vec![], + 7, + policy, + ) + .unwrap(); + context.validate_query_context().unwrap(); + let wire = serde_json::to_value(&context).unwrap(); + assert_eq!(wire["id"], "nearby"); + assert_eq!(wire["relayUrls"][0], relay); + assert_eq!(wire["followedAuthors"], serde_json::json!([])); + let decoded: LocalNetwork = serde_json::from_value(wire).unwrap(); + assert_eq!(decoded, context); + decoded.validate_query_context().unwrap(); + } + let public = LocalNetwork::new( + "nearby".into(), + "Nearby".into(), + vec!["ws://10.0.0.1:7447".into()], + None, + vec![], + 7, + ); + assert_eq!(public, Err(LocalNetworkError::InvalidRelay)); +} + +#[test] +fn context_debug_redacts_raw_fields_and_keeps_safe_diagnostics() { + let mut context = selected(vec!["a".repeat(64)]).unwrap(); + context.label = "private-label-sentinel".into(); + context.locality = Some("private-location-sentinel".into()); + let debug = format!("{context:?}"); + for sentinel in [ + "nearby", + "private-label-sentinel", + "private-location-sentinel", + "wss://relay.example", + &"a".repeat(64), + ] { + assert!( + !debug.contains(sentinel), + "Sensitive context field must be redacted" + ); + } + assert!(debug.contains("relay_count: 1")); + assert!(debug.contains("followed_author_count: 1")); + assert!(debug.contains("generation: 7")); + assert_eq!( + serde_json::to_value(&context).unwrap()["label"], + "private-label-sentinel" + ); +} diff --git a/core/crates/tera_core/src/runtime/product_surface/today.rs b/core/crates/tera_core/src/runtime/product_surface/today.rs @@ -327,6 +327,9 @@ impl TeraRuntime { viewer_time_zone: &str, ) -> Result<Vec<SearchResult>, TodayError> { let _command = self.lifecycle.enter()?; + context + .validate_query_context() + .map_err(|_| TodayError::InvalidRequest)?; if limit == 0 || limit > TODAY_SEARCH_LIMIT_MAX || as_of == 0 @@ -410,6 +413,9 @@ impl TeraRuntime { viewer_time_zone: &str, ) -> Result<MeSnapshot, TodayError> { let _command = self.lifecycle.enter()?; + context + .validate_query_context() + .map_err(|_| TodayError::InvalidRequest)?; let calendar = super::ViewerCalendarContext::new(as_of, viewer_time_zone)?; if !valid_public_key(public_key) || as_of == 0 { return Err(TodayError::InvalidRequest); diff --git a/core/crates/tera_core/src/runtime/product_surface/today_paging.rs b/core/crates/tera_core/src/runtime/product_surface/today_paging.rs @@ -46,6 +46,7 @@ impl TeraRuntime { } else if request.as_of.is_none() || request.viewer_time_zone.is_none() { return Err(TodayError::InvalidRequest); } + let query_scope = paging_scope::query_scope(context, self.store_public_key)?; let first_calendar = request .as_of .map(|as_of| { @@ -64,7 +65,6 @@ impl TeraRuntime { .as_deref() .map(TodayCursor::scope) .transpose()?; - let query_scope = paging_scope::query_scope(context, self.store_public_key)?; if let Some(scope) = &decoded_scope { if scope.context_id != context.id || scope.context_generation != context.generation diff --git a/core/crates/tera_core/src/runtime/product_surface/today_paging_scope.rs b/core/crates/tera_core/src/runtime/product_surface/today_paging_scope.rs @@ -14,6 +14,9 @@ pub(super) fn query_scope( context: &LocalNetwork, owner: Option<PublicKey>, ) -> Result<[u8; 32], TodayError> { + context + .validate_query_context() + .map_err(|_| TodayError::InvalidRequest)?; let mut digest = Sha256::new(); digest.update(b"tera.today-query-scope.v1\0"); // Serialize an unambiguous tuple of the full context and runtime identity. diff --git a/core/crates/tera_core/src/runtime/product_surface/today_performance_tests.rs b/core/crates/tera_core/src/runtime/product_surface/today_performance_tests.rs @@ -12,6 +12,151 @@ const EVENT_COUNT: u64 = 10_000; const NOW: u64 = 2_000_000_000; #[tokio::test] +async fn context_rejection_precedes_all_scoped_storage_work() { + let (_root, runtime, counts) = counted_sqlite().await; + let original = context(None, 1); + let mut invalid = Vec::new(); + let mut value = original.clone(); + value.followed_authors = (0..4097).map(|index| format!("{index:064x}")).collect(); + invalid.push(value); + for authors in [ + vec!["a".repeat(64), "a".repeat(64)], + vec!["A".repeat(64)], + vec!["x".repeat(262_145)], + ] { + let mut value = original.clone(); + value.followed_authors = authors; + invalid.push(value); + } + for relays in [ + vec![], + vec![ + "wss://relay.example".into(), + "WSS://RELAY.EXAMPLE:443/".into(), + ], + vec!["invalid".into()], + vec!["x".repeat(2049)], + (0..65) + .map(|index| format!("wss://relay{index}.example")) + .collect(), + ] { + let mut value = original.clone(); + value.relay_urls = relays; + invalid.push(value); + } + let mut value = original.clone(); + value.label = "x".repeat(1_048_576); + invalid.push(value); + let mut value = original.clone(); + value.locality = Some("invalid\0location".into()); + invalid.push(value); + let mut wire = serde_json::to_value(&original).unwrap(); + wire["followedAuthors"] = serde_json::json!(["a".repeat(63)]); + invalid.push(serde_json::from_value(wire).unwrap()); + for selected in &invalid { + for operation in 0..5 { + counts.take(); + let result = match operation { + 0 => runtime + .phase1_search(selected, "carrot", 20, NOW, "UTC") + .await + .map(|_| ()), + 1 => runtime + .phase1_me(selected, &keys().public_key().to_string(), NOW, "UTC") + .await + .map(|_| ()), + 2 => runtime + .phase1_today_page(selected, TodayPageRequest::first(20, NOW, "UTC")) + .await + .map(|_| ()), + 3 => runtime + .phase1_today_reconcile(selected, NOW, &[], None, "UTC") + .await + .map(|_| ()), + _ => runtime + .phase1_refresh_today(selected, NOW, TodayProjectionUpdate::Rebuild) + .await + .map(|_| ()), + }; + assert!( + matches!(result, Err(TodayError::InvalidRequest)), + "invalid context in operation{operation}" + ); + assert!( + counts.take().is_empty(), + "rejected context must not touch storage" + ); + } + } + runtime.shutdown().await.unwrap(); + counts.take(); + assert!(matches!( + runtime + .phase1_search(&invalid[0], "carrot", 20, NOW, "UTC") + .await, + Err(TodayError::Lifecycle(_)) + )); + assert!(counts.take().is_empty()); +} + +#[tokio::test] +async fn context_maximum_preserves_complete_scope_and_query_behavior() { + let (_root, runtime, counts) = counted_sqlite().await; + let mut selected = context(None, 1); + selected.followed_authors = (0..4096).map(|index| format!("{index:064x}")).collect(); + let mut expected = Sha256::new(); + expected.update(b"tera.today-query-scope.v1\0"); + expected + .update(encode(&(&selected, runtime.store_public_key.map(|key| key.to_hex()))).unwrap()); + let expected: [u8; 32] = expected.finalize().into(); + assert_eq!( + paging_scope::query_scope(&selected, runtime.store_public_key).unwrap(), + expected + ); + runtime + .phase1_refresh_today(&selected, NOW, TodayProjectionUpdate::Rebuild) + .await + .unwrap(); + counts.take(); + assert!( + runtime + .phase1_search(&selected, "carrot", 20, NOW, "UTC") + .await + .unwrap() + .is_empty() + ); + assert!( + runtime + .phase1_me(&selected, &keys().public_key().to_string(), NOW, "UTC") + .await + .unwrap() + .cards + .is_empty() + ); + assert!( + runtime + .phase1_today_page(&selected, TodayPageRequest::first(20, NOW, "UTC")) + .await + .unwrap() + .items + .is_empty() + ); + assert!( + runtime + .phase1_today_reconcile(&selected, NOW, &[], None, "UTC") + .await + .unwrap() + .items + .is_empty() + ); + assert!( + !counts.take().is_empty(), + "accepted context must reach real storage" + ); + runtime.shutdown().await.unwrap(); +} + +#[tokio::test] async fn search_rejects_raw_and_normalized_boundaries_before_storage() { let (_root, runtime, counts) = counted_sqlite().await; let selected = context(None, 1); diff --git a/core/crates/tera_core/src/runtime/product_surface/today_reconciliation.rs b/core/crates/tera_core/src/runtime/product_surface/today_reconciliation.rs @@ -25,6 +25,7 @@ impl TeraRuntime { if as_of == 0 || card_ids.len() > usize::from(TODAY_PAGE_LIMIT_MAX) { return Err(TodayError::InvalidRequest); } + let query_scope = paging_scope::query_scope(context, self.store_public_key)?; let calendar = super::super::ViewerCalendarContext::new(as_of, viewer_time_zone)?; let selected = card_ids .iter() @@ -33,7 +34,6 @@ impl TeraRuntime { if selected.len() != card_ids.len() { return Err(TodayError::InvalidRequest); } - let query_scope = paging_scope::query_scope(context, self.store_public_key)?; let storage = self .client .storage() diff --git a/core/crates/tera_core/src/runtime/product_surface/today_refresh.rs b/core/crates/tera_core/src/runtime/product_surface/today_refresh.rs @@ -12,6 +12,7 @@ impl TeraRuntime { if now_unix_seconds == 0 { return Err(TodayError::InvalidRequest); } + let query_scope = paging_scope::query_scope(context, self.store_public_key)?; let requested_updated_at_unix_ms = now_unix_seconds .checked_mul(1_000) .ok_or(TodayError::InvalidRequest)?; @@ -37,8 +38,6 @@ impl TeraRuntime { Some(state) => Some(state), None => calendar_migration::legacy_state(storage, context).await?, }; - let query_scope = paging_scope::query_scope(context, self.store_public_key)?; - if update == TodayProjectionUpdate::Incremental && prior.as_ref().is_some_and(|state| { state.source_events == event_status.raw_events() diff --git a/core/crates/tera_ffi/src/dto.rs b/core/crates/tera_ffi/src/dto.rs @@ -41,6 +41,7 @@ pub use viewer_calendar::{FfiViewerCalendarContext, TODAY_PAGE_FFI_SCHEMA_VERSIO mod calendar; pub use calendar::{FfiCalendarTiming, FfiCivilDate, TODAY_CARD_FFI_SCHEMA_VERSION}; +mod local_network_debug; mod today_sync; pub use today_sync::{ FfiTodayDiscoveryRecord, FfiTodayRelaySyncState, FfiTodaySyncRecord, FfiTodaySyncTermination, @@ -464,7 +465,7 @@ pub struct FfiCardAddParityRecord { pub command_type: FfiAddCommandType, } -#[derive(Clone, Debug, Eq, PartialEq, uniffi::Record)] +#[derive(Clone, Eq, PartialEq, uniffi::Record)] pub struct FfiLocalNetworkRecord { pub schema_version: u16, pub id: String, diff --git a/core/crates/tera_ffi/src/dto/local_network_debug.rs b/core/crates/tera_ffi/src/dto/local_network_debug.rs @@ -0,0 +1,13 @@ +use super::FfiLocalNetworkRecord; + +impl std::fmt::Debug for FfiLocalNetworkRecord { + fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + formatter + .debug_struct("FfiLocalNetworkRecord") + .field("schema_version", &self.schema_version) + .field("relay_count", &self.relay_urls.len()) + .field("followed_author_count", &self.followed_authors.len()) + .field("generation", &self.generation) + .finish_non_exhaustive() + } +} diff --git a/core/crates/tera_ffi/tests/runtime_delegation.rs b/core/crates/tera_ffi/tests/runtime_delegation.rs @@ -20,6 +20,59 @@ mod retraction; mod support; #[tokio::test] +async fn context_aggregate_admission_and_debug_remain_typed_at_native_boundary() { + let (_root, runtime) = support::runtime().await; + let context = FfiLocalNetworkRecord { + schema_version: MOBILE_FFI_SCHEMA_VERSION, + id: "nearby".into(), + label: "private-label-sentinel".into(), + relay_urls: vec!["wss://relay.example".into()], + locality: Some("private-location-sentinel".into()), + followed_authors: (0..4096).map(|index| format!("{index:064x}")).collect(), + generation: 7, + }; + assert_eq!( + runtime.phase1_local_network(context.clone()).unwrap(), + context + ); + let debug = format!("{context:?}"); + for sentinel in [ + &context.id, + &context.label, + &context.relay_urls[0], + context.locality.as_ref().unwrap(), + &context.followed_authors[0], + ] { + assert!(!debug.contains(sentinel)); + } + assert!(debug.contains("followed_author_count: 4096")); + assert!(debug.contains("generation: 7")); + let mut over = context.clone(); + over.followed_authors.push(format!("{:064x}", 4096)); + let mut duplicate = context.clone(); + duplicate.followed_authors = vec!["a".repeat(64), "a".repeat(64)]; + let mut malformed = context.clone(); + malformed.followed_authors = vec!["A".repeat(64)]; + let mut aggregate = context.clone(); + aggregate.followed_authors = vec!["x".repeat(262_145)]; + for invalid in [over, duplicate, malformed, aggregate] { + let TeraAppError::Failure { report } = runtime + .phase1_search(invalid, "carrot".into(), 20, 1_800_000_000, "UTC".into()) + .await + .unwrap_err(); + assert_eq!(report.code, "invalid_local_network"); + assert!(!report.retryable); + assert_eq!(report.recovery_actions, ["correct_input"]); + } + runtime.shutdown().await.unwrap(); + let TeraAppError::Failure { report } = runtime + .phase1_search(context, "carrot".into(), 20, 1_800_000_000, "UTC".into()) + .await + .unwrap_err(); + assert_eq!(report.code, "client_closed"); +} + +#[tokio::test] async fn search_byte_admission_preserves_typed_native_failure() { let (_root, runtime) = support::runtime().await; let context = FfiLocalNetworkRecord { 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": "975eded4554823578e637925c5ec4ae214c2b14ddfc41837a07b3b615fd12192", + "ffi_provenance_sha256": "4daef4ddc3a79768e65128c0c2464ec311fa707aceb817485d15b4efb422e1dd", "info_plist_sha256": "b55010dd73b34bf5ad910a888be0ea1ae45f2a5c14329fa6a57059a317bdbd42", "privacy_manifest_sha256": "0f2103257ba596fbcaeb1d6a4dffe3ae021e84c010178852c6bf500a8cfb0f19", "sbom_sha256": "3b7fc006547d0551e0ac65d6e4dba414803ee1ebceab58d1f385dda98b2df7ef", @@ -20,10 +20,10 @@ "authored_app": { "files": { "Package.swift": { - "bytes": 10117, - "git_blob": "40e3d82029f982ddb0f9f88c87bd111bcb6c68af", + "bytes": 10161, + "git_blob": "5eb3f406f0d9e1bf65263e530f02110d51fe63c9", "mode": "100644", - "sha256": "e2251394e447c670bb7eab9433f1950185240ba832682ea13b30599d89bab70d" + "sha256": "4043cba85b9052246ab0ba3f6712fc62343d6ea82939374730bee924e5f0a02d" }, "Tera/App/App.swift": { "bytes": 233, @@ -667,6 +667,12 @@ "mode": "100644", "sha256": "d51f2d1bcedac63ac0920ba26148a94d7e1afafd5510435d7d853b91c69fc942" }, + "Tera/Runtime/TeraRuntimeContext.swift": { + "bytes": 260, + "git_blob": "c4a23471604f03b66bdf2a3dd55e5a8780e79a22", + "mode": "100644", + "sha256": "5852001328fcbe7cda128f55791c112964af25bed4541bf77c709e02ee81705c" + }, "Tera/Runtime/TeraRuntimeFailureMapping.swift": { "bytes": 1779, "git_blob": "f658ea62c0c02f23062d39ed9691734d1dec5dfe", @@ -1251,14 +1257,14 @@ } }, "policy": "staged_inputs", - "tree": "186052f4a0ca0731791d6f7c2ad647822286bb87" + "tree": "9e3bde8e5b90f38792f8524bd89f05ce7e413d7d" }, "cargo_lock_sha256": "67bcbc7cf880e3ffb6e01c193d4e63dc007ed74335f066077dbac87a40514817", "consumer_source_lock_sha256": "eadc233fb6b20d32960ae1b2b444a58c1ee146045c29c037a168b603dcd99555", "lib_revision": "babe4622ec60f85167845bba8d58d3da58b03227", "source_date_epoch": 1787871027, "swift_package_lock_sha256": "8aec408132602a249111a65903c985cca5898ec316a45916d88ba756f08ea40d", - "tera_ffi_source_tree": "18b97c7c5e6b18469ec6b19ae25498d304efe4ce", + "tera_ffi_source_tree": "f8d9a6694ee906eb602b34418651f747611e00a5", "xcode_package_lock_sha256": "3656728f8251f3ea644aa150d154819766470ca7bd4f85b7c51fdf301d361d16" }, "version": "0.1.0-alpha" diff --git a/scripts/kotlin_smoke/src/test/kotlin/tera/smoke/SearchAdmissionTests.kt b/scripts/kotlin_smoke/src/test/kotlin/tera/smoke/SearchAdmissionTests.kt @@ -17,6 +17,21 @@ class SearchAdmissionTests { val runtime = fixture.runtime() val context = FfiLocalNetworkRecord(1u, "nearby", "Nearby", listOf("wss://relay.example"), null, emptyList(), 1uL) try { + val authors = (0 until 4096).map { it.toString(16).padStart(64, '0') } + val maximum = context.copy(followedAuthors = authors) + assertEquals(authors, runtime.phase1LocalNetwork(maximum).followedAuthors) + for (invalidAuthors in listOf( + authors + 4096.toString(16).padStart(64, '0'), + listOf("a".repeat(64), "a".repeat(64)), + listOf("A".repeat(64)), listOf("x".repeat(262_145)), + )) { + val failure = assertFailsWith<TeraAppException.Failure> { + runtime.phase1Search(context.copy(followedAuthors = invalidAuthors), "carrot", 20u, UNIX_S, "UTC") + } + assertEquals("invalid_local_network", failure.report.code) + assertFalse(failure.report.retryable) + assertEquals(listOf("correct_input"), failure.report.recoveryActions) + } runtime.phase1RefreshToday(context, UNIX_S, FfiTodayProjectionUpdate.REBUILD) for (query in listOf( "x".repeat(257), "é".repeat(128) + "a",