From 99d3cc3399e4f19b49ee28af204ba917492e75fd Mon Sep 17 00:00:00 2001 From: Oleh Martsokha Date: Wed, 2 Dec 2026 13:13:38 +0100 Subject: [PATCH] Update elide and elide-runtime Depend on elide-runtime alone (4c0f1d8e, elide 985ec3cd) and move to its reorganized API: anonymize takes an AnonymizeRequest, formats come from the provider, RegisteredComponent replaces RegisteredRecognizer. A redaction's review audit is now the AppliedReport anonymize returns, staged and read back on its own. Reviewers come from Parts::reviewers, and analyses, review audits and intermediates load through one Stored reader. Add an end-to-end test of the review audit crediting every reviewer. Co-Authored-By: Claude Opus 5.5 --- .github/dependabot.yml | 2 +- Cargo.lock | 452 ++++++------------ Cargo.toml | 3 +- crates/nvisy-server/Cargo.toml | 5 +- .../src/domain/detection_decisions.rs | 128 +---- .../src/domain/input/workspace_detections.rs | 2 +- .../src/domain/input/workspace_policies.rs | 8 +- crates/nvisy-server/src/domain/json.rs | 2 +- .../src/domain/output/workspace_redactions.rs | 8 +- .../src/domain/workspace_detections.rs | 19 +- .../src/domain/workspace_redactions.rs | 51 +- .../nvisy-server/src/handler/capabilities.rs | 7 +- .../src/handler/detection_audits.rs | 9 +- .../handler/request/workspace_detections.rs | 5 +- .../handler/request/workspace_documents.rs | 2 +- .../src/handler/request/workspace_policies.rs | 6 +- .../src/handler/response/capabilities.rs | 6 +- .../handler/response/workspace_detections.rs | 2 +- .../handler/response/workspace_policies.rs | 2 +- .../handler/response/workspace_redactions.rs | 14 +- .../src/handler/utility/redaction_key.rs | 2 +- .../src/handler/workspace_redactions.rs | 12 +- .../src/response/error/engine_error.rs | 10 +- .../nvisy-server/src/service/blob/reader.rs | 125 +++-- .../nvisy-server/src/service/blob/writer.rs | 48 +- .../nvisy-server/src/service/engine/config.rs | 2 +- crates/nvisy-server/src/service/engine/mod.rs | 2 +- .../src/service/engine/modality.rs | 2 +- .../src/service/engine/service.rs | 16 +- crates/nvisy-server/src/test_util.rs | 24 + .../nvisy-server/src/worker/detection/job.rs | 2 +- .../src/worker/detection/support.rs | 2 +- .../src/worker/detection/worker.rs | 8 +- .../tests/workspace_redactions.rs | 172 +++++++ 34 files changed, 587 insertions(+), 573 deletions(-) create mode 100644 crates/nvisy-server/tests/workspace_redactions.rs diff --git a/.github/dependabot.yml b/.github/dependabot.yml index ada2cdbf..e41e4c4c 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -18,7 +18,7 @@ updates: rebase-strategy: "auto" versioning-strategy: "auto" # Elide is bumped by hand: a new revision usually needs code changes, and - # elide-pipeline must move with the elide revision it was built against. + # elide-runtime must move with the elide revision it was built against. ignore: - dependency-name: "elide" - dependency-name: "elide-*" diff --git a/Cargo.lock b/Cargo.lock index f4cf414c..86b14df8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1458,7 +1458,7 @@ version = "4.6.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4c174f11f949b9ca8c60580925e282b9cbd5454750e506f08648b2038080cd7" dependencies = [ - "heck 0.5.0", + "heck", "proc-macro2", "quote", "syn 3.0.10", @@ -3014,7 +3014,7 @@ checksum = "cc51ea5a4c1cfac05a51e51cdbb6a5471bbb88091fcb045a27ff13b38e9a3204" dependencies = [ "darling 0.24.1", "either", - "heck 0.5.0", + "heck", "proc-macro2", "quote", "syn 3.0.10", @@ -3124,9 +3124,8 @@ checksum = "0e9c71c2167ca323c882b99918929403426e2373ea17242ff5653e0d5e1058be" [[package]] name = "elide" version = "0.1.0" -source = "git+https://github.com/nvisycom/elide?branch=main#850253e69ddb3b5119caee1c5f5ee098c467b7ca" +source = "git+https://github.com/nvisycom/elide?branch=main#985ec3cdeeaa23bcac31d45c3fde6fb1f0198cd1" dependencies = [ - "async-trait", "elide-audio", "elide-backend", "elide-codec", @@ -3149,9 +3148,8 @@ dependencies = [ [[package]] name = "elide-audio" version = "0.1.0" -source = "git+https://github.com/nvisycom/elide?branch=main#850253e69ddb3b5119caee1c5f5ee098c467b7ca" +source = "git+https://github.com/nvisycom/elide?branch=main#985ec3cdeeaa23bcac31d45c3fde6fb1f0198cd1" dependencies = [ - "async-trait", "bytes", "elide-codec", "elide-core", @@ -3166,9 +3164,8 @@ dependencies = [ [[package]] name = "elide-backend" version = "0.1.0" -source = "git+https://github.com/nvisycom/elide?branch=main#850253e69ddb3b5119caee1c5f5ee098c467b7ca" +source = "git+https://github.com/nvisycom/elide?branch=main#985ec3cdeeaa23bcac31d45c3fde6fb1f0198cd1" dependencies = [ - "async-trait", "elide-core", "gloo-timers", "send_wrapper", @@ -3179,9 +3176,8 @@ dependencies = [ [[package]] name = "elide-bentoml" version = "0.1.0" -source = "git+https://github.com/nvisycom/elide-runtime?rev=296f2db896f750393da47bb849156bfc83bcf4f4#296f2db896f750393da47bb849156bfc83bcf4f4" +source = "git+https://github.com/nvisycom/elide-runtime?rev=4c0f1d8e078157ec7a2ed4ae9a2f86a9670f4190#4c0f1d8e078157ec7a2ed4ae9a2f86a9670f4190" dependencies = [ - "async-trait", "base64 0.23.1", "bentoml", "elide-audio", @@ -3197,20 +3193,19 @@ dependencies = [ [[package]] name = "elide-codec" version = "0.1.0" -source = "git+https://github.com/nvisycom/elide?branch=main#850253e69ddb3b5119caee1c5f5ee098c467b7ca" +source = "git+https://github.com/nvisycom/elide?branch=main#985ec3cdeeaa23bcac31d45c3fde6fb1f0198cd1" dependencies = [ - "async-trait", "bytes", "elide-core", + "futures", "hipstr", ] [[package]] name = "elide-core" version = "0.1.0" -source = "git+https://github.com/nvisycom/elide?branch=main#850253e69ddb3b5119caee1c5f5ee098c467b7ca" +source = "git+https://github.com/nvisycom/elide?branch=main#985ec3cdeeaa23bcac31d45c3fde6fb1f0198cd1" dependencies = [ - "async-trait", "blake3", "celes", "elide-macros", @@ -3224,24 +3219,11 @@ dependencies = [ "uuid", ] -[[package]] -name = "elide-deployment" -version = "0.1.0" -source = "git+https://github.com/nvisycom/elide-runtime?rev=296f2db896f750393da47bb849156bfc83bcf4f4#296f2db896f750393da47bb849156bfc83bcf4f4" -dependencies = [ - "elide", - "hipstr", - "schemars 1.2.3", - "serde", - "toml", -] - [[package]] name = "elide-detection" version = "0.1.0" -source = "git+https://github.com/nvisycom/elide?branch=main#850253e69ddb3b5119caee1c5f5ee098c467b7ca" +source = "git+https://github.com/nvisycom/elide?branch=main#985ec3cdeeaa23bcac31d45c3fde6fb1f0198cd1" dependencies = [ - "async-trait", "elide-core", "futures", "schemars 1.2.3", @@ -3253,7 +3235,7 @@ dependencies = [ [[package]] name = "elide-engine" version = "0.1.0" -source = "git+https://github.com/nvisycom/elide?branch=main#850253e69ddb3b5119caee1c5f5ee098c467b7ca" +source = "git+https://github.com/nvisycom/elide?branch=main#985ec3cdeeaa23bcac31d45c3fde6fb1f0198cd1" dependencies = [ "bytes", "elide-audio", @@ -3264,6 +3246,7 @@ dependencies = [ "elide-image", "elide-redaction", "erased-serde", + "jiff 1.0.3", "schemars 1.2.3", "serde", "serde-value", @@ -3272,24 +3255,11 @@ dependencies = [ "uuid", ] -[[package]] -name = "elide-export" -version = "0.1.0" -source = "git+https://github.com/nvisycom/elide-runtime?rev=296f2db896f750393da47bb849156bfc83bcf4f4#296f2db896f750393da47bb849156bfc83bcf4f4" -dependencies = [ - "csv", - "elide", - "serde", - "serde_json", - "zip", -] - [[package]] name = "elide-fake" version = "0.1.0" -source = "git+https://github.com/nvisycom/elide?branch=main#850253e69ddb3b5119caee1c5f5ee098c467b7ca" +source = "git+https://github.com/nvisycom/elide?branch=main#985ec3cdeeaa23bcac31d45c3fde6fb1f0198cd1" dependencies = [ - "async-trait", "elide-core", "fake", "getrandom 0.4.3", @@ -3299,7 +3269,7 @@ dependencies = [ [[package]] name = "elide-format" version = "0.1.0" -source = "git+https://github.com/nvisycom/elide?branch=main#850253e69ddb3b5119caee1c5f5ee098c467b7ca" +source = "git+https://github.com/nvisycom/elide?branch=main#985ec3cdeeaa23bcac31d45c3fde6fb1f0198cd1" dependencies = [ "elide-audio", "elide-codec", @@ -3314,9 +3284,8 @@ dependencies = [ [[package]] name = "elide-image" version = "0.1.0" -source = "git+https://github.com/nvisycom/elide?branch=main#850253e69ddb3b5119caee1c5f5ee098c467b7ca" +source = "git+https://github.com/nvisycom/elide?branch=main#985ec3cdeeaa23bcac31d45c3fde6fb1f0198cd1" dependencies = [ - "async-trait", "bytes", "elide-codec", "elide-core", @@ -3332,9 +3301,8 @@ dependencies = [ [[package]] name = "elide-lingua" version = "0.1.0" -source = "git+https://github.com/nvisycom/elide?branch=main#850253e69ddb3b5119caee1c5f5ee098c467b7ca" +source = "git+https://github.com/nvisycom/elide?branch=main#985ec3cdeeaa23bcac31d45c3fde6fb1f0198cd1" dependencies = [ - "async-trait", "elide-core", "lingua", "tracing", @@ -3343,9 +3311,8 @@ dependencies = [ [[package]] name = "elide-llm" version = "0.1.0" -source = "git+https://github.com/nvisycom/elide?branch=main#850253e69ddb3b5119caee1c5f5ee098c467b7ca" +source = "git+https://github.com/nvisycom/elide?branch=main#985ec3cdeeaa23bcac31d45c3fde6fb1f0198cd1" dependencies = [ - "async-trait", "base64 0.23.1", "elide-core", "elide-image", @@ -3353,8 +3320,8 @@ dependencies = [ "reqwest-middleware", "reqwest-retry", "reqwest-tracing", - "rig 0.46.0", - "rig-reqwest 0.46.0", + "rig", + "rig-reqwest", "schemars 1.2.3", "serde", "serde_json", @@ -3367,7 +3334,7 @@ dependencies = [ [[package]] name = "elide-macros" version = "0.1.0" -source = "git+https://github.com/nvisycom/elide?branch=main#850253e69ddb3b5119caee1c5f5ee098c467b7ca" +source = "git+https://github.com/nvisycom/elide?branch=main#985ec3cdeeaa23bcac31d45c3fde6fb1f0198cd1" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -3378,9 +3345,8 @@ dependencies = [ [[package]] name = "elide-markup" version = "0.1.0" -source = "git+https://github.com/nvisycom/elide?branch=main#850253e69ddb3b5119caee1c5f5ee098c467b7ca" +source = "git+https://github.com/nvisycom/elide?branch=main#985ec3cdeeaa23bcac31d45c3fde6fb1f0198cd1" dependencies = [ - "async-trait", "elide-codec", "elide-core", "quick-xml 0.42.0", @@ -3389,9 +3355,8 @@ dependencies = [ [[package]] name = "elide-ner" version = "0.1.0" -source = "git+https://github.com/nvisycom/elide?branch=main#850253e69ddb3b5119caee1c5f5ee098c467b7ca" +source = "git+https://github.com/nvisycom/elide?branch=main#985ec3cdeeaa23bcac31d45c3fde6fb1f0198cd1" dependencies = [ - "async-trait", "elide-core", "hipstr", "tracing", @@ -3401,9 +3366,8 @@ dependencies = [ [[package]] name = "elide-office" version = "0.1.0" -source = "git+https://github.com/nvisycom/elide?branch=main#850253e69ddb3b5119caee1c5f5ee098c467b7ca" +source = "git+https://github.com/nvisycom/elide?branch=main#985ec3cdeeaa23bcac31d45c3fde6fb1f0198cd1" dependencies = [ - "async-trait", "bytes", "elide-codec", "elide-core", @@ -3416,10 +3380,9 @@ dependencies = [ [[package]] name = "elide-pattern" version = "0.1.0" -source = "git+https://github.com/nvisycom/elide?branch=main#850253e69ddb3b5119caee1c5f5ee098c467b7ca" +source = "git+https://github.com/nvisycom/elide?branch=main#985ec3cdeeaa23bcac31d45c3fde6fb1f0198cd1" dependencies = [ "aho-corasick", - "async-trait", "bs58", "csv", "derive_builder", @@ -3437,9 +3400,8 @@ dependencies = [ [[package]] name = "elide-pdf" version = "0.1.0" -source = "git+https://github.com/nvisycom/elide?branch=main#850253e69ddb3b5119caee1c5f5ee098c467b7ca" +source = "git+https://github.com/nvisycom/elide?branch=main#985ec3cdeeaa23bcac31d45c3fde6fb1f0198cd1" dependencies = [ - "async-trait", "bytes", "elide-codec", "elide-core", @@ -3453,64 +3415,24 @@ dependencies = [ "unicode-normalization", ] -[[package]] -name = "elide-pipeline" -version = "0.1.0" -source = "git+https://github.com/nvisycom/elide-runtime?rev=296f2db896f750393da47bb849156bfc83bcf4f4#296f2db896f750393da47bb849156bfc83bcf4f4" -dependencies = [ - "bytes", - "elide", - "elide-export", - "elide-provider", - "elide-review", - "elide-schema", - "elide-template", - "hipstr", - "jiff 1.0.3", - "schemars 1.2.3", - "serde", - "serde-value", - "serde_json", - "uuid", -] - [[package]] name = "elide-plain" version = "0.1.0" -source = "git+https://github.com/nvisycom/elide?branch=main#850253e69ddb3b5119caee1c5f5ee098c467b7ca" +source = "git+https://github.com/nvisycom/elide?branch=main#985ec3cdeeaa23bcac31d45c3fde6fb1f0198cd1" dependencies = [ "anstream", - "async-trait", "bytes", "csv", "elide-codec", "elide-core", ] -[[package]] -name = "elide-provider" -version = "0.1.0" -source = "git+https://github.com/nvisycom/elide-runtime?rev=296f2db896f750393da47bb849156bfc83bcf4f4#296f2db896f750393da47bb849156bfc83bcf4f4" -dependencies = [ - "elide", - "elide-bentoml", - "elide-deployment", - "elide-llm", - "elide-pdf", - "elide-review", - "elide-schema", - "schemars 1.2.3", - "serde", - "uuid", -] - [[package]] name = "elide-redaction" version = "0.1.0" -source = "git+https://github.com/nvisycom/elide?branch=main#850253e69ddb3b5119caee1c5f5ee098c467b7ca" +source = "git+https://github.com/nvisycom/elide?branch=main#985ec3cdeeaa23bcac31d45c3fde6fb1f0198cd1" dependencies = [ "aes-gcm", - "async-trait", "base64 0.23.1", "bytes", "elide-audio", @@ -3531,23 +3453,75 @@ dependencies = [ ] [[package]] -name = "elide-review" +name = "elide-runtime" version = "0.1.0" -source = "git+https://github.com/nvisycom/elide-runtime?rev=296f2db896f750393da47bb849156bfc83bcf4f4#296f2db896f750393da47bb849156bfc83bcf4f4" +source = "git+https://github.com/nvisycom/elide-runtime?rev=4c0f1d8e078157ec7a2ed4ae9a2f86a9670f4190#4c0f1d8e078157ec7a2ed4ae9a2f86a9670f4190" dependencies = [ + "bytes", + "csv", "elide", - "elide-schema", + "elide-runtime-certificate", + "elide-runtime-core", + "elide-runtime-governance", + "elide-runtime-provider", + "elide-runtime-review", + "elide-runtime-template", + "hipstr", + "jiff 1.0.3", "schemars 1.2.3", "serde", + "serde_json", "uuid", + "zip", +] + +[[package]] +name = "elide-runtime-certificate" +version = "0.1.0" +source = "git+https://github.com/nvisycom/elide-runtime?rev=4c0f1d8e078157ec7a2ed4ae9a2f86a9670f4190#4c0f1d8e078157ec7a2ed4ae9a2f86a9670f4190" +dependencies = [ + "elide", + "elide-runtime-core", + "elide-runtime-governance", + "hipstr", + "jiff 1.0.3", + "schemars 1.2.3", + "serde", + "serde_json", + "uuid", +] + +[[package]] +name = "elide-runtime-core" +version = "0.1.0" +source = "git+https://github.com/nvisycom/elide-runtime?rev=4c0f1d8e078157ec7a2ed4ae9a2f86a9670f4190#4c0f1d8e078157ec7a2ed4ae9a2f86a9670f4190" +dependencies = [ + "elide", + "schemars 1.2.3", + "serde", + "sha2 0.11.3", ] [[package]] -name = "elide-schema" +name = "elide-runtime-deployment" version = "0.1.0" -source = "git+https://github.com/nvisycom/elide-runtime?rev=296f2db896f750393da47bb849156bfc83bcf4f4#296f2db896f750393da47bb849156bfc83bcf4f4" +source = "git+https://github.com/nvisycom/elide-runtime?rev=4c0f1d8e078157ec7a2ed4ae9a2f86a9670f4190#4c0f1d8e078157ec7a2ed4ae9a2f86a9670f4190" dependencies = [ "elide", + "elide-runtime-core", + "hipstr", + "schemars 1.2.3", + "serde", + "toml", +] + +[[package]] +name = "elide-runtime-governance" +version = "0.1.0" +source = "git+https://github.com/nvisycom/elide-runtime?rev=4c0f1d8e078157ec7a2ed4ae9a2f86a9670f4190#4c0f1d8e078157ec7a2ed4ae9a2f86a9670f4190" +dependencies = [ + "elide", + "elide-runtime-core", "hipstr", "schemars 1.2.3", "semver", @@ -3556,12 +3530,44 @@ dependencies = [ ] [[package]] -name = "elide-template" +name = "elide-runtime-provider" version = "0.1.0" -source = "git+https://github.com/nvisycom/elide-runtime?rev=296f2db896f750393da47bb849156bfc83bcf4f4#296f2db896f750393da47bb849156bfc83bcf4f4" +source = "git+https://github.com/nvisycom/elide-runtime?rev=4c0f1d8e078157ec7a2ed4ae9a2f86a9670f4190#4c0f1d8e078157ec7a2ed4ae9a2f86a9670f4190" dependencies = [ "elide", - "elide-schema", + "elide-bentoml", + "elide-llm", + "elide-pdf", + "elide-runtime-core", + "elide-runtime-deployment", + "elide-runtime-governance", + "hipstr", + "schemars 1.2.3", + "serde", + "uuid", +] + +[[package]] +name = "elide-runtime-review" +version = "0.1.0" +source = "git+https://github.com/nvisycom/elide-runtime?rev=4c0f1d8e078157ec7a2ed4ae9a2f86a9670f4190#4c0f1d8e078157ec7a2ed4ae9a2f86a9670f4190" +dependencies = [ + "elide", + "elide-runtime-core", + "elide-runtime-governance", + "schemars 1.2.3", + "serde", + "uuid", +] + +[[package]] +name = "elide-runtime-template" +version = "0.1.0" +source = "git+https://github.com/nvisycom/elide-runtime?rev=4c0f1d8e078157ec7a2ed4ae9a2f86a9670f4190#4c0f1d8e078157ec7a2ed4ae9a2f86a9670f4190" +dependencies = [ + "elide", + "elide-runtime-core", + "elide-runtime-governance", "hipstr", "jiff 1.0.3", "schemars 1.2.3", @@ -4418,12 +4424,6 @@ dependencies = [ "stable_deref_trait", ] -[[package]] -name = "heck" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" - [[package]] name = "heck" version = "0.5.0" @@ -6735,7 +6735,7 @@ name = "nvisy-assistant" version = "0.1.0" dependencies = [ "nvisy-core", - "rig 0.47.1", + "rig", "schemars 1.2.3", "serde", "serde_json", @@ -6919,8 +6919,7 @@ dependencies = [ "csv", "derive_more", "dotenvy", - "elide", - "elide-pipeline", + "elide-runtime", "futures", "garde", "hex", @@ -7825,7 +7824,7 @@ version = "0.14.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b6e4d69d0fa3e7f6f9cf6b53a0e83e4fc99ba3586f65ce166cff30bd13bb4ad2" dependencies = [ - "heck 0.4.1", + "heck", "itertools 0.15.0", "log", "multimap", @@ -8534,60 +8533,26 @@ version = "0.8.53" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "47b34b781b31e5d73e9fbc8689c70551fd1ade9a19e3e28cfec8580a79290cc4" -[[package]] -name = "rig" -version = "0.46.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc9eff465db44a1c3fa8e1950e54d18e9f1b6721a59cddd44aaeb150a5838e63" -dependencies = [ - "rig-agent 0.46.0", - "rig-cassette 0.46.0", - "rig-core 0.46.0", - "rig-derive 0.46.0", - "rig-harness-protocol", -] - [[package]] name = "rig" version = "0.47.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8400c238ea633780bdd0f960eece8863f67e8d45fc01fa9048519447740cc18e" dependencies = [ - "rig-agent 0.47.1", - "rig-cassette 0.47.1", - "rig-core 0.47.1", - "rig-derive 0.47.1", + "rig-agent", + "rig-cassette", + "rig-core", + "rig-derive", "rig-fastembed", "rig-helixdb", "rig-lancedb", "rig-milvus", - "rig-reqwest 0.47.1", + "rig-reqwest", "rig-tungstenite", "rig-typesafeai", "rig-vectorize", ] -[[package]] -name = "rig-agent" -version = "0.46.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0175c1087b491593f47de7639fb349665b4a6caceb4f65e549e9dc42dc02b7ae" -dependencies = [ - "async-stream", - "futures", - "http", - "indexmap 2.14.2", - "rig-core 0.46.0", - "rig-derive 0.46.0", - "rig-memory 0.46.0", - "schemars 1.2.3", - "serde", - "serde_json", - "thiserror 2.0.21", - "tracing", - "tracing-futures", -] - [[package]] name = "rig-agent" version = "0.47.1" @@ -8598,9 +8563,9 @@ dependencies = [ "futures", "http", "indexmap 2.14.2", - "rig-core 0.47.1", - "rig-derive 0.47.1", - "rig-memory 0.47.1", + "rig-core", + "rig-derive", + "rig-memory", "schemars 1.2.3", "serde", "serde_json", @@ -8609,20 +8574,6 @@ dependencies = [ "tracing-futures", ] -[[package]] -name = "rig-cassette" -version = "0.46.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ca25973567a393cc57f8627e50b8bc4dee4421affbd15609ca6675eb660c8f2" -dependencies = [ - "base64 0.22.1", - "futures", - "rig-agent 0.46.0", - "rig-core 0.46.0", - "serde", - "serde_json", -] - [[package]] name = "rig-cassette" version = "0.47.1" @@ -8631,44 +8582,12 @@ checksum = "f599e922761871fba733234fa3e7d6ce2494e0330cdc19b1ba80d67f92d163c6" dependencies = [ "base64 0.23.1", "futures", - "rig-agent 0.47.1", - "rig-core 0.47.1", + "rig-agent", + "rig-core", "serde", "serde_json", ] -[[package]] -name = "rig-core" -version = "0.46.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c46316e31b3e80a050ad35790f1b612b4dfdb46982293cc78641caf4271f1b05" -dependencies = [ - "async-stream", - "base64 0.22.1", - "bytes", - "fastrand", - "futures", - "glob", - "http", - "httpdate", - "indexmap 2.14.2", - "mime", - "mime_guess", - "ordered-float 5.5.1", - "rig-derive 0.46.0", - "rig-http 0.46.0", - "schemars 1.2.3", - "serde", - "serde_json", - "serde_path_to_error", - "sha2 0.10.9", - "thiserror 2.0.21", - "tracing", - "url", - "uuid", - "web-time", -] - [[package]] name = "rig-core" version = "0.47.1" @@ -8687,9 +8606,9 @@ dependencies = [ "mime", "mime_guess", "ordered-float 5.5.1", - "rig-derive 0.47.1", - "rig-http 0.47.1", - "rig-reqwest 0.47.1", + "rig-derive", + "rig-http", + "rig-reqwest", "rig-tungstenite", "schemars 1.2.3", "serde", @@ -8703,19 +8622,6 @@ dependencies = [ "web-time", ] -[[package]] -name = "rig-derive" -version = "0.46.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be8c7db5ee8f8ece69fa04b253d096d9b40fa28bd0d7e5cb8a77602b5edf93de" -dependencies = [ - "convert_case 0.11.0", - "proc-macro-crate", - "proc-macro2", - "quote", - "syn 2.0.119", -] - [[package]] name = "rig-derive" version = "0.47.1" @@ -8737,15 +8643,9 @@ checksum = "d5843da4eedc8234fca4aac9c2341ab0121c0318cdcc0303061488378ebc18c2" dependencies = [ "fastembed", "futures", - "rig-core 0.47.1", + "rig-core", ] -[[package]] -name = "rig-harness-protocol" -version = "0.46.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "983eb19c87bf95dc134163e0c003be8f38b393cdfb18917fafe3baa63d82301c" - [[package]] name = "rig-helixdb" version = "0.47.1" @@ -8753,28 +8653,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "691a8970917f7754280f39b8e24a99a8ae84b526d1683cdda365e944cc6c34bf" dependencies = [ "reqwest 0.13.5", - "rig-core 0.47.1", + "rig-core", "serde", "serde_json", "thiserror 2.0.21", ] -[[package]] -name = "rig-http" -version = "0.46.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac927db714f03f383330e16ef360d4ab288fdf42eecab6156982fab90786d5bd" -dependencies = [ - "bytes", - "futures", - "futures-timer", - "http", - "mime", - "thiserror 2.0.21", - "tokio", - "url", -] - [[package]] name = "rig-http" version = "0.47.1" @@ -8801,26 +8685,11 @@ dependencies = [ "arrow-json", "futures", "lancedb", - "rig-core 0.47.1", + "rig-core", "serde", "serde_json", ] -[[package]] -name = "rig-memory" -version = "0.46.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d4423dfa0337714345615cdfefee141605f166be1c174211139bdcbbe25403c" -dependencies = [ - "base64 0.22.1", - "memchr", - "rig-core 0.46.0", - "serde", - "serde_json", - "sha2 0.10.9", - "thiserror 2.0.21", -] - [[package]] name = "rig-memory" version = "0.47.1" @@ -8829,7 +8698,7 @@ checksum = "0a29509f0a89f4f865ecaee6296c8ff48fc39ff23ad0769515f95ea65ca0bb7e" dependencies = [ "base64 0.23.1", "memchr", - "rig-core 0.47.1", + "rig-core", "serde", "serde_json", "thiserror 2.0.21", @@ -8842,30 +8711,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ac843b4f1421bbaf06c45c8f90a75b3c61850ab653df01d008cc0fb187574f5" dependencies = [ "reqwest 0.13.5", - "rig-core 0.47.1", - "rig-reqwest 0.47.1", + "rig-core", + "rig-reqwest", "serde", "serde_json", ] -[[package]] -name = "rig-reqwest" -version = "0.46.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a203e5c50e5460024594cc4ccf6cfc99c7ff22aee57cbacef0fb52ea0c7abd10" -dependencies = [ - "bytes", - "futures", - "http", - "reqwest 0.13.5", - "reqwest-middleware", - "rig-http 0.46.0", - "thiserror 2.0.21", - "tracing", - "url", - "webpki-root-certs", -] - [[package]] name = "rig-reqwest" version = "0.47.1" @@ -8876,7 +8727,8 @@ dependencies = [ "futures", "http", "reqwest 0.13.5", - "rig-http 0.47.1", + "reqwest-middleware", + "rig-http", "thiserror 2.0.21", "tracing", "url", @@ -8890,7 +8742,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a75c531f43d4f8783c20158337508004853267288a44bd252dfcbdd362187bd7" dependencies = [ "futures", - "rig-http 0.47.1", + "rig-http", "thiserror 2.0.21", "tokio", "tokio-tungstenite", @@ -8903,8 +8755,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c1a1117e7d9f3f3ba9fe79f8f502851b27aa3262dcbd452fb077cacbafe0cd37" dependencies = [ "http", - "rig-core 0.47.1", - "rig-reqwest 0.47.1", + "rig-core", + "rig-reqwest", "serde", "serde_json", ] @@ -8916,7 +8768,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b8d49b0d842fe698b3ecc12aa07be09f3340eb0f6dc4f4e1cd103fa4f8a7d02d" dependencies = [ "reqwest 0.13.5", - "rig-core 0.47.1", + "rig-core", "serde", "serde_json", "thiserror 2.0.21", @@ -9702,7 +9554,7 @@ version = "0.8.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c1c97747dbf44bb1ca44a561ece23508e99cb592e862f22222dcf42f51d1e451" dependencies = [ - "heck 0.4.1", + "heck", "proc-macro2", "quote", "syn 2.0.119", @@ -9714,7 +9566,7 @@ version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "287f59010008f0d7cf5e3b03196d666c1acc46c8d3e9cf34c28a1a7157601e72" dependencies = [ - "heck 0.4.1", + "heck", "proc-macro2", "quote", "syn 2.0.119", @@ -9912,7 +9764,7 @@ version = "0.26.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c6bee85a5a24955dc440386795aa378cd9cf82acd5f764469152d2270e581be" dependencies = [ - "heck 0.5.0", + "heck", "proc-macro2", "quote", "rustversion", @@ -9925,7 +9777,7 @@ version = "0.27.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7695ce3845ea4b33927c055a39dc438a45b059f7c1b3d91d38d10355fb8cbca7" dependencies = [ - "heck 0.5.0", + "heck", "proc-macro2", "quote", "syn 2.0.119", @@ -9937,7 +9789,7 @@ version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ab85eea0270ee17587ed4156089e10b9e6880ee688791d45a905f5b1ca36f664" dependencies = [ - "heck 0.5.0", + "heck", "proc-macro2", "quote", "syn 2.0.119", diff --git a/Cargo.toml b/Cargo.toml index 218febe0..be0af97f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,8 +47,7 @@ debug = true # See for more details: https://github.com/rust-lang/cargo/issues/11329 # Elide crates -elide-pipeline = { git = "https://github.com/nvisycom/elide-runtime", rev = "296f2db896f750393da47bb849156bfc83bcf4f4", default-features = false, features = [] } -elide = { git = "https://github.com/nvisycom/elide", branch = "main", default-features = false, features = [] } +elide-runtime = { git = "https://github.com/nvisycom/elide-runtime", rev = "4c0f1d8e078157ec7a2ed4ae9a2f86a9670f4190", default-features = false, features = [] } # Internal crates nvisy-core = { path = "./crates/nvisy-core", version = "0.1.0" } diff --git a/crates/nvisy-server/Cargo.toml b/crates/nvisy-server/Cargo.toml index e827e320..139ff1a7 100644 --- a/crates/nvisy-server/Cargo.toml +++ b/crates/nvisy-server/Cargo.toml @@ -50,7 +50,7 @@ test_util = [ [dependencies] # Elide crates -elide-pipeline = { workspace = true, features = [ +elide-runtime = { workspace = true, features = [ "all-modalities", "audit-json", "audit-csv", @@ -153,9 +153,6 @@ ipnet = { workspace = true, features = [] } url = { workspace = true, features = [] } [dev-dependencies] -# Elide crates -elide = { workspace = true, features = ["engine"] } - # Internal crates nvisy-nats = { workspace = true, features = [] } nvisy-postgres = { workspace = true, features = ["schema", "test_util"] } diff --git a/crates/nvisy-server/src/domain/detection_decisions.rs b/crates/nvisy-server/src/domain/detection_decisions.rs index 3c569eb0..5f1969ab 100644 --- a/crates/nvisy-server/src/domain/detection_decisions.rs +++ b/crates/nvisy-server/src/domain/detection_decisions.rs @@ -12,11 +12,13 @@ //! applied, so it is keyed by its content: identical adds redact the same span, //! so they are one decision. -use elide_pipeline::Report; -use elide_pipeline::entity::{ - AuditKind, Edit, EditBucket, EditSet, HiddenChoices, HiddenContentEdits, Retag, -}; -use elide_pipeline::modality::{Audio, Image, Modality, Tabular, Text}; +use elide_runtime::elide::modality::Modality; +use elide_runtime::elide::modality::audio::Audio; +use elide_runtime::elide::modality::image::Image; +use elide_runtime::elide::modality::tabular::Tabular; +use elide_runtime::elide::modality::text::Text; +use elide_runtime::elide::report::{Parts, Report}; +use elide_runtime::review::{Edit, EditBucket, EditSet, HiddenChoices, HiddenContentEdits, Retag}; use nvisy_postgres::model::WorkspaceDetectionEdit; use serde::Serialize; use sha2::{Digest, Sha256}; @@ -122,36 +124,17 @@ pub(crate) fn apply(report: &mut Report, decisions: &[(Uuid, EditSet)]) -> Resul Ok(()) } -/// The accounts a report's reviewer events name, in first-seen order. +/// The accounts the reviewer events in a report's parts name, sorted by id. /// /// Every decision this server lands names its author by account id, so each /// reviewer an audit names is an account. A name that is not an account id is /// skipped. -pub(crate) fn reviewers(report: &Report) -> Vec { - let mut accounts = Vec::new(); - for (part_id, modality) in report.part_ids() { - elide_pipeline::governance::each_modality!(|M| { - if ::NAME == modality - && let Ok(part) = report.part::(part_id) - { - for entity in part.entities() { - for event in entity.audit().events() { - let by = match &event.kind { - AuditKind::Manual(manual) => manual.by.as_str(), - AuditKind::Included(included) => included.by.as_str(), - _ => continue, - }; - if let Ok(account) = by.parse::() - && !accounts.contains(&account) - { - accounts.push(account); - } - } - } - } - }); - } - accounts +pub(crate) fn reviewers(parts: Parts<'_>) -> Vec { + parts + .reviewers() + .into_iter() + .filter_map(|by| by.parse().ok()) + .collect() } /// Decodes stored decisions into `(author, decision)` pairs, in stored order. @@ -300,37 +283,12 @@ where #[cfg(test)] mod tests { - use elide::PartId; - use elide::entity::audit::{Pattern, PatternRule}; - use elide::entity::{Birth, Entity}; - use elide::modality::text::TextLocation; - use elide::primitive::{ComponentId, Confidence}; - use elide_pipeline::entity::{Add, HiddenChoice, LabelRef, RemoveAll, Suppress}; + use elide_runtime::elide::entity::LabelRef; + use elide_runtime::elide::modality::text::TextLocation; + use elide_runtime::review::{Add, HiddenChoice, RemoveAll, Suppress}; use super::*; - fn document() -> PartId { - PartId::leaf("report.docx") - } - - /// A report holding one detected email address, and its entity id. - fn report() -> (Report, Uuid) { - let entity = Entity::new(Birth::new( - Confidence::MAX, - Pattern::new( - ComponentId::new("probe", "1"), - LabelRef::new("email_address"), - TextLocation::inline(0..5), - PatternRule::default(), - ), - )); - let id = entity.id(); - ( - Report::new().insert_part::(document(), vec![entity]), - id, - ) - } - fn retag(id: Uuid, label: Option<&str>, location: Option) -> Edit { Edit::Retag(Retag { id, @@ -452,56 +410,4 @@ mod tests { let err = merge([&all, &choice]).expect_err("the two answer one question differently"); assert_eq!(err.kind(), ErrorKind::BadRequest); } - - #[test] - fn each_decision_lands_under_its_author() -> Result<()> { - let (mut report, id) = report(); - let (alice, bob, carol) = (Uuid::now_v7(), Uuid::now_v7(), Uuid::now_v7()); - let decisions = split(&set([ - retag(id, Some("person_name"), Some(TextLocation::inline(0..4))), - Edit::Suppress(Suppress { id, reason: None }), - ]))?; - let authors = [alice, bob, carol]; - let attributed: Vec<(Uuid, EditSet)> = decisions - .into_iter() - .zip(authors) - .map(|(decision, author)| (author, decision.edits)) - .collect(); - - apply(&mut report, &attributed)?; - - let part = report.part::(&document()).expect("the text part"); - let entity = part.entity(id).expect("the entity"); - assert_eq!(entity.label().as_str(), "person_name"); - assert_eq!(entity.location(), &TextLocation::inline(0..4)); - assert!(entity.is_suppressed()); - let named: Vec = entity - .audit() - .events() - .iter() - .filter_map(|event| match &event.kind { - AuditKind::Manual(manual) => Some(manual.by.to_string()), - _ => None, - }) - .collect(); - assert_eq!(named, authors.map(|author| author.to_string())); - assert_eq!(reviewers(&report), authors); - Ok(()) - } - - #[test] - fn contradicting_authors_are_rejected_before_anything_lands() { - let (mut report, id) = report(); - let before = report.digest(); - let attributed = vec![ - (Uuid::now_v7(), set([retag(id, Some("person_name"), None)])), - ( - Uuid::now_v7(), - set([retag(id, Some("email_address"), None)]), - ), - ]; - let err = apply(&mut report, &attributed).expect_err("two labels for one entity"); - assert_eq!(err.kind(), ErrorKind::BadRequest); - assert_eq!(report.digest(), before, "nothing landed"); - } } diff --git a/crates/nvisy-server/src/domain/input/workspace_detections.rs b/crates/nvisy-server/src/domain/input/workspace_detections.rs index 760194bf..7f9ecefb 100644 --- a/crates/nvisy-server/src/domain/input/workspace_detections.rs +++ b/crates/nvisy-server/src/domain/input/workspace_detections.rs @@ -1,6 +1,6 @@ //! Detection service inputs. -use elide_pipeline::provider::DocumentContext; +use elide_runtime::provider::DocumentContext; use nvisy_postgres::types::RetentionOverride; use uuid::Uuid; diff --git a/crates/nvisy-server/src/domain/input/workspace_policies.rs b/crates/nvisy-server/src/domain/input/workspace_policies.rs index 39655ed7..869689a9 100644 --- a/crates/nvisy-server/src/domain/input/workspace_policies.rs +++ b/crates/nvisy-server/src/domain/input/workspace_policies.rs @@ -1,9 +1,9 @@ //! Policy service inputs. -use elide_pipeline::entity::LabelRef; -use elide_pipeline::governance::policy::{LabelScope, Policy, PolicyRule, TemplateOrigin}; -use elide_pipeline::governance::redaction::{ModalityRedactions, TextRedaction}; -use elide_pipeline::template::PolicyTemplate; +use elide_runtime::elide::entity::LabelRef; +use elide_runtime::governance::policy::{LabelScope, Policy, PolicyRule, TemplateOrigin}; +use elide_runtime::governance::redaction::{ModalityRedactions, TextRedaction}; +use elide_runtime::template::PolicyTemplate; use sha2::{Digest, Sha256}; use uuid::Uuid; diff --git a/crates/nvisy-server/src/domain/json.rs b/crates/nvisy-server/src/domain/json.rs index 69d2f4c3..a11c66f8 100644 --- a/crates/nvisy-server/src/domain/json.rs +++ b/crates/nvisy-server/src/domain/json.rs @@ -1,7 +1,7 @@ //! JSON encoding shared by the domain services: values stored as plaintext //! `JSONB` (policy definitions, edit sets, outbox jobs). -use elide_pipeline::governance::policy::Policy; +use elide_runtime::governance::policy::Policy; use serde::Serialize; use uuid::Uuid; diff --git a/crates/nvisy-server/src/domain/output/workspace_redactions.rs b/crates/nvisy-server/src/domain/output/workspace_redactions.rs index 3565f989..008b9874 100644 --- a/crates/nvisy-server/src/domain/output/workspace_redactions.rs +++ b/crates/nvisy-server/src/domain/output/workspace_redactions.rs @@ -1,12 +1,12 @@ //! Redaction service outputs. -use elide_pipeline::Audit; +use elide_runtime::elide::report::AppliedReport; use nvisy_postgres::types::AccountRefRow; /// A redaction's review audit, with the accounts its reviewer events name. pub struct ReviewAudit { - /// The review audit. - pub audit: Audit, - /// The accounts the audit's reviewer events name, in first-seen order. + /// The applied report of what the redaction redacted. + pub report: AppliedReport, + /// The accounts the audit's reviewer events name, sorted by id. pub accounts: Vec, } diff --git a/crates/nvisy-server/src/domain/workspace_detections.rs b/crates/nvisy-server/src/domain/workspace_detections.rs index 7d812727..fe47760d 100644 --- a/crates/nvisy-server/src/domain/workspace_detections.rs +++ b/crates/nvisy-server/src/domain/workspace_detections.rs @@ -14,10 +14,11 @@ use std::collections::HashMap; -use elide_pipeline::entity::EditSet; -use elide_pipeline::governance::policy::Policy; -use elide_pipeline::provider::DocumentContext; -use elide_pipeline::{ArtifactSet, Audit}; +use elide_runtime::Audit; +use elide_runtime::elide::report::Artifacts; +use elide_runtime::governance::policy::Policy; +use elide_runtime::provider::DocumentContext; +use elide_runtime::review::EditSet; use nvisy_postgres::model::{ NewDetectionDecision, NewWorkspaceDetection, NewWorkspaceDetectionJob, WorkspaceDetection as WorkspaceDetectionModel, @@ -322,11 +323,7 @@ impl WorkspaceDetectionService { /// - `NotFound` if the detection does not exist in the workspace, or its /// analysis ran no enricher. /// - A database, storage, or decoding error if loading them fails. - pub async fn intermediates( - &self, - workspace_id: Uuid, - detection_id: Uuid, - ) -> Result { + pub async fn intermediates(&self, workspace_id: Uuid, detection_id: Uuid) -> Result { let detection = self.find(workspace_id, detection_id).await?; let blob = { let mut conn = self.postgres.get_connection().await?; @@ -454,7 +451,7 @@ impl WorkspaceDetectionService { /// connection, then restores it from storage (no connection held across the /// object-store round-trip). /// - /// [`Audit`]: elide_pipeline::Audit + /// [`Audit`]: elide_runtime::Audit /// /// # Errors /// @@ -466,7 +463,7 @@ impl WorkspaceDetectionService { &self, workspace_id: Uuid, detection: &WorkspaceDetectionModel, - ) -> Result { + ) -> Result { let audit_blob = { let mut conn = self.postgres.get_connection().await?; self.reader.resolve_audit_blob(&mut conn, detection).await? diff --git a/crates/nvisy-server/src/domain/workspace_redactions.rs b/crates/nvisy-server/src/domain/workspace_redactions.rs index 892c5b71..fca38cae 100644 --- a/crates/nvisy-server/src/domain/workspace_redactions.rs +++ b/crates/nvisy-server/src/domain/workspace_redactions.rs @@ -1,8 +1,9 @@ //! Redaction domain service: redacting a detection, and reading redactions back. -use elide_pipeline::entity::EditSet; -use elide_pipeline::governance::policy::Policy; -use elide_pipeline::provider::KeyConfig; +use elide_runtime::AnonymizeRequest; +use elide_runtime::governance::policy::Policy; +use elide_runtime::provider::KeyConfig; +use elide_runtime::review::EditSet; use nvisy_postgres::model::{ Blob, NewWorkspaceDocument, NewWorkspaceRedaction, Workspace, WorkspaceDetection as WorkspaceDetectionModel, WorkspaceDocument, WorkspaceRedaction, @@ -109,7 +110,9 @@ impl WorkspaceRedactionService { key: Option, ) -> Result { let inputs = self.preflight(workspace.id, detection_id).await?; - let staged = self.produce(workspace, &inputs, key).await?; + let staged = self + .produce(workspace, &inputs, origin.account_id, key) + .await?; self.commit(origin, workspace, &inputs, staged).await } @@ -182,12 +185,12 @@ impl WorkspaceRedactionService { &self, workspace: &Workspace, inputs: &RedactInputs, + redacted_by: Uuid, key: Option, ) -> Result { // The stored detection analysis is loaded into a working audit and never - // mutated on disk: reviewer edits and the redaction outcome land on this - // clone, which is persisted as the redaction's own review audit, leaving the - // detection analysis immutable and re-redactable. + // mutated on disk: reviewer edits land on this copy, which the redaction + // consumes, leaving the detection analysis immutable and re-redactable. let mut reviewed = self .reader .load_audit(workspace.id, &inputs.audit_blob) @@ -217,11 +220,17 @@ impl WorkspaceRedactionService { // The keyed operators (HMAC, encrypt) run with the caller's key; a policy // using one without a key fails here as a 400. The codec params and document - // context are read back from the audit, recorded at detect time. - let redacted = self - .engine - .anonymize(document, &inputs.policies, &mut reviewed, key.as_ref()) - .await?; + // context are read back from the audit, recorded at detect time, and the + // redacting account is named as who ran it. The applied report it returns, + // the record of what was redacted, is persisted as the redaction's review + // audit. + let redacted_by = redacted_by.to_string(); + let request = AnonymizeRequest { + policies: &inputs.policies, + key: key.as_ref(), + by: &redacted_by, + }; + let anonymized = self.engine.anonymize(document, reviewed, &request).await?; // Stage both produced objects (redacted document + review audit) outside the // transaction — object writes are not transactional — then commit their blobs, @@ -243,18 +252,18 @@ impl WorkspaceRedactionService { &inputs.document, retention_override.as_ref(), &retention, - redacted.bytes, + anonymized.document.bytes, ) .await?; // Staging the review audit after the output means a failure here would strand // the already-written output object (no blob to reclaim it); discard it first. let staged_review = match self .writer - .stage_audit( + .stage_review( inputs.detection.workspace_id, retention_override.as_ref(), &retention, - &reviewed, + &anonymized.report, ) .await { @@ -423,9 +432,9 @@ impl WorkspaceRedactionService { .await?) } - /// Loads a redaction's review audit: the detection analysis with the - /// reviewer decisions applied and the per-entity redaction outcome recorded, - /// with the accounts its reviewer events name. The connection is released + /// Loads a redaction's review audit: the applied report of what it redacted, + /// each entity's trail running from detection through the reviewer decisions + /// to its redaction, with the accounts its reviewer events name. The connection is released /// before the object-store load. /// /// # Errors @@ -446,13 +455,13 @@ impl WorkspaceRedactionService { .resolve_review_blob(&mut conn, &redaction) .await? }; - let audit = self.reader.load_audit(workspace_id, &review_blob).await?; - let reviewers = detection_decisions::reviewers(&audit.report); + let report = self.reader.load_review(workspace_id, &review_blob).await?; + let reviewers = detection_decisions::reviewers(report.parts()); let accounts = { let mut conn = self.postgres.get_connection().await?; conn.find_account_refs(&reviewers).await? }; - Ok(ReviewAudit { audit, accounts }) + Ok(ReviewAudit { report, accounts }) } } diff --git a/crates/nvisy-server/src/handler/capabilities.rs b/crates/nvisy-server/src/handler/capabilities.rs index e0510462..fdaf1123 100644 --- a/crates/nvisy-server/src/handler/capabilities.rs +++ b/crates/nvisy-server/src/handler/capabilities.rs @@ -9,12 +9,12 @@ //! the configured [`Engine`], connector availability from the host's //! configuration, and sign-in methods from the configured auth providers. //! -//! [`Engine`]: elide_pipeline::Engine +//! [`Engine`]: elide_runtime::Engine use aide::axum::ApiRouter; use aide::transform::TransformOperation; use axum::extract::State; -use elide_pipeline::entity::LabelCatalog; +use elide_runtime::elide::entity::LabelCatalog; use nvisy_core::net::EndpointPolicy; use nvisy_file_service::FileService; use nvisy_postgres::types::IdentityProvider; @@ -101,6 +101,7 @@ async fn list_formats( fn format_capabilities(engine: &EngineService) -> FormatCapabilities { let formats = engine .engine() + .provider() .formats() .iter() .filter_map(|format| { @@ -197,7 +198,7 @@ pub fn public_routes() -> ApiRouter { #[cfg(test)] mod tests { - use elide_pipeline::entity::LabelCatalog; + use elide_runtime::elide::entity::LabelCatalog; use nvisy_core::Secret; use nvisy_file_service::OAuthApps; use nvisy_file_service::oauth::OAuthApp; diff --git a/crates/nvisy-server/src/handler/detection_audits.rs b/crates/nvisy-server/src/handler/detection_audits.rs index 2a3b9912..3b314beb 100644 --- a/crates/nvisy-server/src/handler/detection_audits.rs +++ b/crates/nvisy-server/src/handler/detection_audits.rs @@ -15,8 +15,9 @@ use aide::transform::TransformOperation; use axum::body::Body; use axum::extract::State; use axum::http::{HeaderMap, HeaderValue}; -use elide_pipeline::export::{ExportCsv, ExportJson}; -use elide_pipeline::{ArtifactSet, Audit}; +use elide_runtime::Audit; +use elide_runtime::elide::report::Artifacts; +use elide_runtime::export::{ExportCsv, ExportJson}; use crate::domain; use crate::extract::{Authorized, Json, Path, Query, markers}; @@ -83,7 +84,7 @@ async fn get_detection_intermediates( State(detections): State, authz: Authorized, Path(path_params): Path, -) -> Result> { +) -> Result> { tracing::debug!(target: TRACING_TARGET, "Getting detection intermediates"); let intermediates = detections @@ -104,7 +105,7 @@ fn get_detection_intermediates_docs(op: TransformOperation) -> TransformOperatio search the content and add entities the analysis missed. A detection whose analysis \ ran no enricher has no intermediates (404).", ) - .response::<200, Json>() + .response::<200, Json>() .response::<401, Json>() .response::<403, Json>() .response::<404, Json>() diff --git a/crates/nvisy-server/src/handler/request/workspace_detections.rs b/crates/nvisy-server/src/handler/request/workspace_detections.rs index 43d57d37..328bbc0b 100644 --- a/crates/nvisy-server/src/handler/request/workspace_detections.rs +++ b/crates/nvisy-server/src/handler/request/workspace_detections.rs @@ -1,7 +1,8 @@ //! Detection request types (detect and redact). -use elide_pipeline::entity::{EditSet, LabelCatalog, LabelRef}; -use elide_pipeline::provider::DocumentContext; +use elide_runtime::elide::entity::{LabelCatalog, LabelRef}; +use elide_runtime::provider::DocumentContext; +use elide_runtime::review::EditSet; use garde::Validate; use nvisy_postgres::types::{DetectionFilter, DetectionStatus, RetentionOverride}; use schemars::JsonSchema; diff --git a/crates/nvisy-server/src/handler/request/workspace_documents.rs b/crates/nvisy-server/src/handler/request/workspace_documents.rs index 51101055..b9a096fa 100644 --- a/crates/nvisy-server/src/handler/request/workspace_documents.rs +++ b/crates/nvisy-server/src/handler/request/workspace_documents.rs @@ -4,7 +4,7 @@ use std::borrow::Cow; use std::collections::BTreeSet; use derive_more::{AsRef, Into}; -use elide_pipeline::FormatRegistry; +use elide_runtime::elide::codec::FormatRegistry; use garde::Validate; use nvisy_postgres::model; use nvisy_postgres::types::DocumentKind; diff --git a/crates/nvisy-server/src/handler/request/workspace_policies.rs b/crates/nvisy-server/src/handler/request/workspace_policies.rs index 8c1ae07a..afd3bacc 100644 --- a/crates/nvisy-server/src/handler/request/workspace_policies.rs +++ b/crates/nvisy-server/src/handler/request/workspace_policies.rs @@ -1,8 +1,8 @@ //! Policy request types. -use elide_pipeline::governance::policy::{LabelScope, PolicyRule}; -use elide_pipeline::governance::redaction::ModalityRedactions; -use elide_pipeline::template::PolicyTemplate; +use elide_runtime::governance::policy::{LabelScope, PolicyRule}; +use elide_runtime::governance::redaction::ModalityRedactions; +use elide_runtime::template::PolicyTemplate; use garde::Validate; use nvisy_postgres::types::PolicyKind; use schemars::JsonSchema; diff --git a/crates/nvisy-server/src/handler/response/capabilities.rs b/crates/nvisy-server/src/handler/response/capabilities.rs index 1ca8b44f..683f7210 100644 --- a/crates/nvisy-server/src/handler/response/capabilities.rs +++ b/crates/nvisy-server/src/handler/response/capabilities.rs @@ -1,6 +1,6 @@ //! Deployment capabilities response types. -use elide_pipeline::RegisteredRecognizer; +use elide_runtime::RegisteredComponent; use nvisy_core::net::EndpointPolicy; use nvisy_file_service::FileService; use nvisy_file_service::provider::FileServiceProvider; @@ -15,9 +15,9 @@ use crate::service::DocumentModality; #[serde(rename_all = "camelCase")] pub struct RecognizerCatalog { /// NER (named-entity recognition) recognizers. - pub ner: Vec, + pub ner: Vec, /// LLM recognizers. - pub llm: Vec, + pub llm: Vec, } /// Per-provider availability for the OAuth file services. Each field is `true` diff --git a/crates/nvisy-server/src/handler/response/workspace_detections.rs b/crates/nvisy-server/src/handler/response/workspace_detections.rs index da510358..2e1b0b29 100644 --- a/crates/nvisy-server/src/handler/response/workspace_detections.rs +++ b/crates/nvisy-server/src/handler/response/workspace_detections.rs @@ -1,6 +1,6 @@ //! `WorkspaceDetection` response types. -use elide_pipeline::entity::EditSet; +use elide_runtime::review::EditSet; use jiff::Timestamp; use nvisy_postgres::model::{ WorkspaceDetection as DetectionModel, WorkspaceDetectionEdit as EditModel, diff --git a/crates/nvisy-server/src/handler/response/workspace_policies.rs b/crates/nvisy-server/src/handler/response/workspace_policies.rs index 831a7059..c0923e11 100644 --- a/crates/nvisy-server/src/handler/response/workspace_policies.rs +++ b/crates/nvisy-server/src/handler/response/workspace_policies.rs @@ -1,6 +1,6 @@ //! Policy response types. -use elide_pipeline::governance::policy::Policy; +use elide_runtime::governance::policy::Policy; use jiff::Timestamp; use nvisy_postgres::model::{WorkspacePolicy as WorkspacePolicyModel, WorkspacePolicyVersion}; use nvisy_postgres::types::PolicyKind; diff --git a/crates/nvisy-server/src/handler/response/workspace_redactions.rs b/crates/nvisy-server/src/handler/response/workspace_redactions.rs index e62f292c..31022dff 100644 --- a/crates/nvisy-server/src/handler/response/workspace_redactions.rs +++ b/crates/nvisy-server/src/handler/response/workspace_redactions.rs @@ -1,6 +1,6 @@ //! Redaction response types. -use elide_pipeline::Audit; +use elide_runtime::elide::report::AppliedReport; use jiff::Timestamp; use nvisy_postgres::model::WorkspaceRedaction as RedactionModel; use nvisy_postgres::types::{DetectionId, RedactionId}; @@ -68,11 +68,11 @@ impl WorkspaceRedactionResult { #[derive(Serialize, JsonSchema)] #[serde(rename_all = "camelCase")] pub struct WorkspaceRedactionReview { - /// The review audit: the detection's base analysis with the reviewer - /// decisions applied and the per-entity redaction outcome recorded. Each - /// reviewer event's `by` is the account id of the reviewer who made that - /// decision. - pub audit: Audit, + /// The applied report: every entity's trail, from detection through the + /// reviewer decisions in force at redact time to the redaction that ran on + /// it. Each reviewer event's `by` is the account id of the reviewer who made + /// that decision. + pub report: AppliedReport, /// The accounts the audit's reviewer events name, resolved so a client can /// show who decided each one without a lookup. A reviewer who has since left /// the workspace still resolves. @@ -84,7 +84,7 @@ impl WorkspaceRedactionReview { #[must_use] pub fn from_output(review: ReviewAudit) -> Self { Self { - audit: review.audit, + report: review.report, accounts: review.accounts.into_iter().map(AccountRef::from).collect(), } } diff --git a/crates/nvisy-server/src/handler/utility/redaction_key.rs b/crates/nvisy-server/src/handler/utility/redaction_key.rs index e40cbe39..58d875d4 100644 --- a/crates/nvisy-server/src/handler/utility/redaction_key.rs +++ b/crates/nvisy-server/src/handler/utility/redaction_key.rs @@ -4,7 +4,7 @@ use std::borrow::Cow; use base64::Engine; use base64::engine::general_purpose::STANDARD; -use elide_pipeline::provider::KeyConfig; +use elide_runtime::provider::KeyConfig; use nvisy_core::Secret; use schemars::{JsonSchema, Schema, SchemaGenerator}; use serde::Deserialize; diff --git a/crates/nvisy-server/src/handler/workspace_redactions.rs b/crates/nvisy-server/src/handler/workspace_redactions.rs index d01c41d0..dd861362 100644 --- a/crates/nvisy-server/src/handler/workspace_redactions.rs +++ b/crates/nvisy-server/src/handler/workspace_redactions.rs @@ -96,8 +96,8 @@ fn list_workspace_redactions_docs(op: TransformOperation) -> TransformOperation .response::<200, Json>() } -/// Returns a redaction's review audit: the analysis with the reviewer decisions -/// applied and the per-entity redaction outcome recorded, with the accounts its +/// Returns a redaction's review audit: the applied report of what it redacted, +/// each entity's trail from detection to redaction, with the accounts its /// reviewer events name. #[tracing::instrument( skip_all, @@ -121,10 +121,10 @@ async fn get_redaction_review( fn get_redaction_review_docs(op: TransformOperation) -> TransformOperation { op.summary("Get redaction review") .description( - "Returns the redaction's review audit: the detection's base analysis with the \ - reviewer decisions in force at redact time applied, and the per-entity redaction \ - outcome recorded. Unlike the detection's findings, it is fixed once the redaction \ - is made. Each reviewer event's `by` is the account id of the reviewer who made that \ + "Returns the redaction's review audit: the applied report of what it redacted, \ + each entity's trail running from detection through the reviewer decisions in force \ + at redact time to the redaction that ran on it. Unlike the detection's findings, it \ + is fixed once the redaction is made. Each reviewer event's `by` is the account id of the reviewer who made that \ decision, and `accounts` resolves every one of them.", ) .response::<200, Json>() diff --git a/crates/nvisy-server/src/response/error/engine_error.rs b/crates/nvisy-server/src/response/error/engine_error.rs index 2e2481df..13bd4c20 100644 --- a/crates/nvisy-server/src/response/error/engine_error.rs +++ b/crates/nvisy-server/src/response/error/engine_error.rs @@ -1,6 +1,6 @@ //! Redaction-engine error to HTTP error conversion. //! -//! Maps `elide_pipeline::Error` onto an HTTP error by its kind. Two kinds are +//! Maps `elide_runtime::elide::Error` onto an HTTP error by its kind. Two kinds are //! caller errors: `MalformedInput` is a bad document the caller supplied, and //! `Configuration` is an incoherent request or policy set (e.g. policies that can //! detect but never redact, or a reviewer override naming an off-pipeline @@ -8,13 +8,13 @@ //! renderer the build does not ship) — is a server-side processing fault. The //! engine's own message travels along as context. -use elide_pipeline::ErrorKind as EngineErrorKind; -use elide_pipeline::entity::EditError; +use elide_runtime::elide::ErrorKind as EngineErrorKind; +use elide_runtime::review::EditError; use super::http_error::{Error as HttpError, ErrorKind}; -impl From for HttpError { - fn from(error: elide_pipeline::Error) -> Self { +impl From for HttpError { + fn from(error: elide_runtime::elide::Error) -> Self { match error.kind() { EngineErrorKind::MalformedInput => ErrorKind::BadRequest .with_message("Document could not be processed") diff --git a/crates/nvisy-server/src/service/blob/reader.rs b/crates/nvisy-server/src/service/blob/reader.rs index c4031b0f..7185a4dd 100644 --- a/crates/nvisy-server/src/service/blob/reader.rs +++ b/crates/nvisy-server/src/service/blob/reader.rs @@ -1,8 +1,10 @@ //! Read side of the pipeline-run blob store: loading a run's staged outputs. -use elide_pipeline::entity::AuditHash; -use elide_pipeline::file::Document; -use elide_pipeline::{ArtifactSet, Audit, Restorer}; +use elide_runtime::Audit; +use elide_runtime::elide::audit::AuditHash; +use elide_runtime::elide::report::{AppliedReport, Artifacts}; +use elide_runtime::elide::schema::{Schema, Stored}; +use elide_runtime::file::Document; use nvisy_postgres::PgConn; use nvisy_postgres::model::{Blob, WorkspaceDetection, WorkspaceDocument, WorkspaceRedaction}; use nvisy_postgres::query::WorkspaceBlobRepository; @@ -13,8 +15,8 @@ use crate::response::{ErrorKind, Result}; use crate::service::{CryptoService, Infra}; /// Loads a pipeline run's staged outputs from the first-party blob store: reads -/// and decrypts audits and enrichment intermediates, restores them, and checks -/// them against their recorded digests. Its write counterpart is +/// and decrypts analyses, review audits and enrichment intermediates, decodes +/// them, and checks them against their recorded digests. Its write counterpart is /// [`ArtifactWriter`]. /// /// Cloneable and cheap to pass around: it holds the shared [`Infra`] clients @@ -73,7 +75,7 @@ impl ArtifactReader { /// no database connection: only object-store I/O and decryption, so a caller /// can run it after releasing its connection. /// - /// The audit is restored through [`Audit::restore`], which maps each entity + /// The audit is read through the built-in [`Schema`], which maps each entity /// group's modality name back to its built-in type and checks the decoded /// audit against the digest recorded on the blob when it was written. /// @@ -85,22 +87,8 @@ impl ArtifactReader { /// the audit cannot be decoded or does not match its digest. /// - A storage error if the object store rejects the read. pub async fn load_audit(&self, workspace_id: Uuid, audit_blob: &Blob) -> Result { - let expected = recorded_digest(audit_blob)?; - let plaintext = self - .read_decrypted::(workspace_id, &audit_blob.storage_path, "audit") - .await? - .ok_or_else(|| { - ErrorKind::InternalServerError.with_message("Audit is missing from storage") - })?; - Audit::restore( - &expected, - &mut serde_json::Deserializer::from_slice(&plaintext), - ) - .map_err(|err| { - ErrorKind::InternalServerError - .with_message("Failed to decode audit") - .with_context(err.to_string()) - }) + self.load_stored::(workspace_id, audit_blob, "audit") + .await } /// Resolves the blob holding a detection's enrichment intermediates. @@ -134,9 +122,9 @@ impl ArtifactReader { /// already-resolved blob. Holds no database connection: only object-store I/O /// and decryption. /// - /// The [`ArtifactSet`] is restored through the built-in [`Restorer`], which - /// maps each group's modality name back to its concrete artifact type and - /// checks the decoded set against the digest recorded on the blob. + /// The [`Artifacts`] are read through the built-in [`Schema`], which maps + /// each group's modality name back to its concrete artifact type and checks + /// the decoded set against the digest recorded on the blob. /// /// # Errors /// @@ -150,39 +138,43 @@ impl ArtifactReader { &self, workspace_id: Uuid, intermediates_blob: &Blob, - ) -> Result { - let expected = recorded_digest(intermediates_blob)?; - let plaintext = self - .read_decrypted::( - workspace_id, - &intermediates_blob.storage_path, - "intermediates", - ) - .await? - .ok_or_else(|| { - ErrorKind::InternalServerError - .with_message("Intermediates are missing from storage") - })?; - Restorer::builtin() - .restore( - &expected, - &mut serde_json::Deserializer::from_slice(&plaintext), - ) - .map_err(|err| { - ErrorKind::InternalServerError - .with_message("Failed to decode intermediates") - .with_context(err.to_string()) - }) + ) -> Result { + self.load_stored::(workspace_id, intermediates_blob, "intermediates") + .await + } + + /// Loads and decodes a redaction's review audit from its already-resolved + /// blob: the [`AppliedReport`], the record of what the redaction redacted. + /// Holds no database connection: only object-store I/O and decryption. + /// + /// The report is read through the built-in [`Schema`], which checks it + /// against the digest recorded on the blob. An applied report's digest never + /// matches a report's, so a detection analysis is never read back as one. + /// + /// # Errors + /// + /// - `InternalServerError` if the blob's storage path is not a valid audit + /// key, if the blob has no valid recorded digest, if the object is missing + /// from storage, if reading its bytes fails, if decrypting them fails, or if + /// the report cannot be decoded or does not match its digest. + /// - A storage error if the object store rejects the read. + pub async fn load_review( + &self, + workspace_id: Uuid, + review_blob: &Blob, + ) -> Result { + self.load_stored::(workspace_id, review_blob, "review audit") + .await } /// Resolves the blob holding a redaction's review audit. /// /// The connection-bound step of loading a review audit; pair with - /// [`load_audit`] to release the connection before the object-store + /// [`load_review`] to release the connection before the object-store /// round-trip. A redaction always produces a review audit, so a NULL pointer /// means its blob has since been reclaimed (404). /// - /// [`load_audit`]: Self::load_audit + /// [`load_review`]: Self::load_review /// /// # Errors /// @@ -238,6 +230,35 @@ impl ArtifactReader { .with_correlation_id(correlation_id)) } + /// Reads, decrypts and decodes the [`Stored`] value in `blob`, from `K`'s + /// store, through the built-in [`Schema`], checking it against the digest + /// recorded on the blob. `what` names the content in error messages. + async fn load_stored( + &self, + workspace_id: Uuid, + blob: &Blob, + what: &str, + ) -> Result { + let expected = recorded_digest(blob)?; + let plaintext = self + .read_decrypted::(workspace_id, &blob.storage_path, what) + .await? + .ok_or_else(|| { + ErrorKind::InternalServerError + .with_message(format!("The {what} is missing from storage")) + })?; + Schema::builtin() + .read( + &expected, + &mut serde_json::Deserializer::from_slice(&plaintext), + ) + .map_err(|err| { + ErrorKind::InternalServerError + .with_message(format!("Failed to decode {what}")) + .with_context(err.to_string()) + }) + } + /// Reads and decrypts the object at `storage_path` in `K`'s store, or `None` /// if it is missing. `what` names the content in error messages. async fn read_decrypted( @@ -283,8 +304,8 @@ impl ArtifactReader { } } -/// The engine digest recorded on an audit or intermediates blob when it was -/// written, which the decoded content must match. +/// The engine digest recorded on an audit, review or intermediates blob when it +/// was written, which the decoded content must match. /// /// # Errors /// diff --git a/crates/nvisy-server/src/service/blob/writer.rs b/crates/nvisy-server/src/service/blob/writer.rs index ec7d1b6b..5e059fc3 100644 --- a/crates/nvisy-server/src/service/blob/writer.rs +++ b/crates/nvisy-server/src/service/blob/writer.rs @@ -3,7 +3,8 @@ use std::io::Cursor; use bytes::Bytes; -use elide_pipeline::{ArtifactSet, Audit}; +use elide_runtime::Audit; +use elide_runtime::elide::report::{AppliedReport, Artifacts}; use nvisy_postgres::model::{NewBlob, WorkspaceDocument}; use nvisy_postgres::types::{Retention, RetentionOverride, RetentionScope, RetentionSettings}; use nvisy_s3::{AuditKey, DocumentKey, IntermediateKey, ObjectKey}; @@ -61,14 +62,13 @@ impl ArtifactWriter { Self { infra, crypto } } - /// Encrypts an audit — a detection's analysis or a redaction's review audit — - /// writes it to the audit bucket, and builds the [`StagedBlob`] that will - /// hold it, under the audit-logs retention scope. + /// Encrypts a detection's analysis, writes it to the audit bucket, and builds + /// the [`StagedBlob`] that will hold it, under the audit-logs retention + /// scope. /// /// The audit is the map of detected PII, so it is encrypted with the - /// workspace key before it leaves the process. A detection points at its - /// analysis (`audit_blob_id`) and a redaction at its review audit - /// (`review_audit_blob_id`); both share this scope. + /// workspace key before it leaves the process. A detection points at it + /// through `audit_blob_id`. /// /// # Errors /// @@ -93,6 +93,38 @@ impl ArtifactWriter { .await } + /// Encrypts a redaction's review audit, the [`AppliedReport`] of what it + /// redacted, writes it to the audit bucket, and builds the [`StagedBlob`] + /// that will hold it, under the audit-logs retention scope it shares with + /// the detection's analysis. + /// + /// The report locates every redacted entity, so it is encrypted with the + /// workspace key before it leaves the process. A redaction points at it + /// through `review_audit_blob_id`. + /// + /// # Errors + /// + /// - `InternalServerError` if serializing or encrypting the report fails. + /// - A storage error if the object write fails. + pub async fn stage_review( + &self, + workspace_id: Uuid, + retention_override: Option<&RetentionOverride>, + workspace_settings: &RetentionSettings, + report: &AppliedReport, + ) -> Result { + let plaintext = to_json(report)?; + let retention = workspace_settings.resolve(RetentionScope::AuditLogs, retention_override); + self.stage_encrypted( + AuditKey::generate(workspace_id), + workspace_id, + &plaintext, + retention, + Some(report.digest().as_bytes().to_vec()), + ) + .await + } + /// Encrypts a detection's enrichment intermediates (OCR layout, transcript), /// writes them to the intermediates store, and builds the [`StagedBlob`] that /// will hold them, under their own retention scope. @@ -106,7 +138,7 @@ impl ArtifactWriter { workspace_id: Uuid, retention_override: Option<&RetentionOverride>, workspace_settings: &RetentionSettings, - artifacts: &ArtifactSet, + artifacts: &Artifacts, ) -> Result { let plaintext = to_json(artifacts)?; let retention = diff --git a/crates/nvisy-server/src/service/engine/config.rs b/crates/nvisy-server/src/service/engine/config.rs index e4f74f64..9338b097 100644 --- a/crates/nvisy-server/src/service/engine/config.rs +++ b/crates/nvisy-server/src/service/engine/config.rs @@ -12,7 +12,7 @@ use std::path::{Path, PathBuf}; -use elide_pipeline::provider::Deployment; +use elide_runtime::provider::Deployment; use crate::{Error, Result}; diff --git a/crates/nvisy-server/src/service/engine/mod.rs b/crates/nvisy-server/src/service/engine/mod.rs index e87bd0e3..b5fba506 100644 --- a/crates/nvisy-server/src/service/engine/mod.rs +++ b/crates/nvisy-server/src/service/engine/mod.rs @@ -6,7 +6,7 @@ //! each request then drives analyze / anonymize against it. Deduplication and //! calibration are engine-owned solid defaults, not configured here. //! -//! [`Engine`]: elide_pipeline::Engine +//! [`Engine`]: elide_runtime::Engine mod config; mod error; diff --git a/crates/nvisy-server/src/service/engine/modality.rs b/crates/nvisy-server/src/service/engine/modality.rs index 90baa9e3..64298842 100644 --- a/crates/nvisy-server/src/service/engine/modality.rs +++ b/crates/nvisy-server/src/service/engine/modality.rs @@ -53,7 +53,7 @@ impl DocumentModality { /// "text documents" filter means to a user. Metadata-only formats (`office` /// docprops) and test fixtures are excluded. /// -/// [`FormatId`]: elide_pipeline::FormatRegistry +/// [`FormatId`]: elide_runtime::elide::codec::FormatRegistry #[must_use] pub fn format_modality(format_id: &str) -> Option { // `elide..`: the segment is the stable grouping key. diff --git a/crates/nvisy-server/src/service/engine/service.rs b/crates/nvisy-server/src/service/engine/service.rs index de7ee7c0..a8af5015 100644 --- a/crates/nvisy-server/src/service/engine/service.rs +++ b/crates/nvisy-server/src/service/engine/service.rs @@ -3,12 +3,13 @@ use std::collections::HashSet; use derive_more::Deref; -use elide_pipeline::file::Document; -use elide_pipeline::governance::policy::Policy; -use elide_pipeline::provider::{Deployment, Provider, RequestContext}; -use elide_pipeline::{ - Analyzed, Engine, Error as EngineError, ErrorKind as EngineErrorKind, Result as EngineResult, +use elide_runtime::elide::{ + Error as EngineError, ErrorKind as EngineErrorKind, Result as EngineResult, }; +use elide_runtime::file::Document; +use elide_runtime::governance::policy::Policy; +use elide_runtime::provider::{Deployment, Provider, RequestContext}; +use elide_runtime::{Analyzed, Engine}; use super::config::{self, EngineConfig}; use super::error::UnknownFormatToken; @@ -113,7 +114,7 @@ impl EngineService { I: IntoIterator, S: AsRef, { - let registry = self.engine.formats(); + let registry = self.engine.provider().formats(); let mut out = Vec::new(); let mut seen = HashSet::new(); @@ -150,7 +151,7 @@ impl EngineService { I: IntoIterator, S: AsRef, { - let registry = self.engine.formats(); + let registry = self.engine.provider().formats(); let mut out = Vec::new(); let mut seen = HashSet::new(); @@ -187,6 +188,7 @@ impl EngineService { #[must_use] pub fn supports_extension(&self, extension: &str) -> bool { self.engine + .provider() .formats() .by_extension(&extension.trim().to_ascii_lowercase()) .is_some() diff --git a/crates/nvisy-server/src/test_util.rs b/crates/nvisy-server/src/test_util.rs index cf97f2e1..bf14c150 100644 --- a/crates/nvisy-server/src/test_util.rs +++ b/crates/nvisy-server/src/test_util.rs @@ -36,6 +36,7 @@ use crate::service::{ AuthKeys, AuthKeysConfig, CryptoConfig, CryptoService, EngineConfig, FileConnectorsConfig, HealthConfig, IntegrationConfig, OidcConfig, ServiceState, SignupConfig, }; +use crate::worker::WorkerSet; use crate::worker::purge::PurgeConfig; /// A matching Ed25519 keypair (PKCS#8 PEM), used to sign and verify session @@ -231,6 +232,29 @@ impl TestApp { (actor, workspace.id) } + /// Seeds an [`Actor`] and their membership at `role` in an existing + /// `workspace_id`, for a test that needs several members of one workspace. + /// + /// # Panics + /// + /// Panics if any seed fails. + pub async fn member_of(&self, workspace_id: Uuid, role: WorkspaceRole) -> Actor { + let actor = self.actor().await; + self.infra + .db + .seed_workspace_member(workspace_id, actor.account_id, role) + .await; + actor + } + + /// Starts the background workers the server runs beside the router, for a + /// test that drives work they perform, such as a detection's analysis. Hold + /// the returned set for the whole test: the workers stop when the + /// application shuts down. + pub fn spawn_workers(&self) -> WorkerSet { + self.state.spawn_workers() + } + /// A pooled connection to the shared test database. async fn connection(&self) -> PgConn { self.state diff --git a/crates/nvisy-server/src/worker/detection/job.rs b/crates/nvisy-server/src/worker/detection/job.rs index 09241d02..aa212b57 100644 --- a/crates/nvisy-server/src/worker/detection/job.rs +++ b/crates/nvisy-server/src/worker/detection/job.rs @@ -8,7 +8,7 @@ use std::fmt::Display; -use elide_pipeline::provider::DocumentContext; +use elide_runtime::provider::DocumentContext; use nvisy_nats::stream::{BroadcastStream, BroadcastTopic}; use nvisy_postgres::types::{DetectionId, DetectionStatus}; use schemars::JsonSchema; diff --git a/crates/nvisy-server/src/worker/detection/support.rs b/crates/nvisy-server/src/worker/detection/support.rs index d97d2d00..3c3ca676 100644 --- a/crates/nvisy-server/src/worker/detection/support.rs +++ b/crates/nvisy-server/src/worker/detection/support.rs @@ -1,7 +1,7 @@ //! Detection worker helpers: policy resolution for a run and the shared failure //! path. -use elide_pipeline::governance::policy::Policy; +use elide_runtime::governance::policy::Policy; use nvisy_postgres::model::UpdateWorkspaceDetection; use nvisy_postgres::query::{WorkspaceDetectionRepository, WorkspacePolicyRepository}; use nvisy_postgres::types::{DetectionMetadata, DetectionStatus, Json}; diff --git a/crates/nvisy-server/src/worker/detection/worker.rs b/crates/nvisy-server/src/worker/detection/worker.rs index a8aee04f..37ae8750 100644 --- a/crates/nvisy-server/src/worker/detection/worker.rs +++ b/crates/nvisy-server/src/worker/detection/worker.rs @@ -11,9 +11,9 @@ use std::iter; use std::num::NonZero; use std::time::Duration; -use elide_pipeline::ArtifactSet; -use elide_pipeline::primitive::RasterMode; -use elide_pipeline::provider::{CodecParams, DocumentContext, RequestContext}; +use elide_runtime::elide::codec::pdf::RasterMode; +use elide_runtime::elide::report::Artifacts; +use elide_runtime::provider::{CodecParams, DocumentContext, RequestContext}; use nvisy_nats::stream::Settle; use nvisy_postgres::model::{UpdateWorkspaceDetection, WorkspaceDetection}; use nvisy_postgres::query::{ @@ -241,7 +241,7 @@ impl DetectionWorker { workspace_id: Uuid, retention_override: Option<&RetentionOverride>, settings: &WorkspaceSettings, - artifacts: &ArtifactSet, + artifacts: &Artifacts, ) -> Result> { if artifacts.is_empty() { return Ok(None); diff --git a/crates/nvisy-server/tests/workspace_redactions.rs b/crates/nvisy-server/tests/workspace_redactions.rs new file mode 100644 index 00000000..3247f612 --- /dev/null +++ b/crates/nvisy-server/tests/workspace_redactions.rs @@ -0,0 +1,172 @@ +//! A redaction's review audit, end to end: detect, decide, redact, review. +#![cfg(feature = "test_util")] + +use std::collections::HashSet; +use std::time::Duration; + +use axum_test::multipart::{MultipartForm, Part}; +use elide_runtime::elide::entity::LabelRef; +use elide_runtime::elide::modality::text::Text; +use elide_runtime::review::{Edit, EditSet, Retag, Suppress}; +use nvisy_postgres::types::WorkspaceRole; +use nvisy_server::test_util::{Actor, TestApp}; +use serde_json::{Value, json}; +use uuid::Uuid; + +/// Uploads a text document holding one email address and returns its id. +async fn upload(app: &TestApp, workspace: Uuid, actor: &Actor) -> String { + let form = MultipartForm::new().add_part( + "file", + Part::bytes(b"Contact jane@example.com today.".to_vec()) + .file_name("contact.txt") + .mime_type("text/plain"), + ); + let response = app + .server() + .post(&format!("/workspaces/{workspace}/documents")) + .authorization_bearer(&actor.jwt) + .multipart(form) + .await; + response.assert_status_success(); + let uploaded: Value = response.json(); + uploaded[0]["id"] + .as_str() + .expect("the document id") + .to_owned() +} + +/// Detects email addresses in `document` and waits for the analysis, returning +/// the detection's path. +async fn detect(app: &TestApp, workspace: Uuid, actor: &Actor, document: &str) -> String { + let response = app + .server() + .post(&format!("/workspaces/{workspace}/detections")) + .authorization_bearer(&actor.jwt) + .json(&json!({ + "documentId": document, + "source": "labels", + "labels": ["email_address"], + })) + .await; + response.assert_status_success(); + let detection: Value = response.json(); + let id = detection["id"].as_str().expect("the detection id"); + let path = format!("/workspaces/{workspace}/detections/{id}"); + for _ in 0..120 { + let detection: Value = app + .server() + .get(&path) + .authorization_bearer(&actor.jwt) + .await + .json(); + match detection["status"].as_str() { + Some("complete") => return path, + Some("failed") => panic!("the detection failed: {}", detection["error"]), + _ => tokio::time::sleep(Duration::from_millis(250)).await, + } + } + panic!("the detection did not complete"); +} + +/// Replaces the detection's edits with `edits`, as `actor`. +async fn set_edits(app: &TestApp, path: &str, actor: &Actor, rev: i32, edits: &[Edit]) { + let mut set = EditSet::default(); + for edit in edits { + set.edit(edit.clone()); + } + app.server() + .patch(path) + .authorization_bearer(&actor.jwt) + .json(&json!({ "editSetRev": rev, "edits": set })) + .await + .assert_status_ok(); +} + +#[tokio::test] +async fn the_review_audit_credits_every_reviewer_decision() { + let app = TestApp::spawn().await; + let _workers = app.spawn_workers(); + let (owner, workspace) = app.workspace_owner().await; + let editor = app.member_of(workspace, WorkspaceRole::Editor).await; + + let document = upload(&app, workspace, &owner).await; + let path = detect(&app, workspace, &owner, &document).await; + let analysis: Value = app + .server() + .get(&format!("{path}/analysis")) + .authorization_bearer(&owner.jwt) + .await + .json(); + let report_id = &analysis["report"]["id"]; + let entity: Uuid = analysis["report"]["parts"][0]["entities"][0]["id"] + .as_str() + .and_then(|id| id.parse().ok()) + .expect("the detected email address"); + + // The owner relabels the entity; the editor keeps that and suppresses it, so + // each decision has its own author. + let relabel = Edit::Retag(Retag { + id: entity, + label: Some(LabelRef::new("person_name")), + location: None, + reason: None, + }); + let suppress = Edit::Suppress(Suppress { + id: entity, + reason: None, + }); + set_edits(&app, &path, &owner, 0, std::slice::from_ref(&relabel)).await; + set_edits(&app, &path, &editor, 1, &[relabel, suppress]).await; + + let response = app + .server() + .post(&format!("{path}/redactions")) + .authorization_bearer(&owner.jwt) + .await; + response.assert_status(axum::http::StatusCode::CREATED); + let redaction: Value = response.json(); + let redaction = redaction["id"].as_str().expect("the redaction id"); + + let review_path = format!("/workspaces/{workspace}/redactions/{redaction}/review"); + let review: Value = app + .server() + .get(&review_path) + .authorization_bearer(&editor.jwt) + .await + .json(); + + // The review is the report the detection's analysis was applied from. + assert_eq!(&review["report"]["id"], report_id); + + // Each reviewer's decision is on the entity's trail under their account id, + // and every account the trail names is resolved. + let both: HashSet = [owner.account_id, editor.account_id] + .iter() + .map(Uuid::to_string) + .collect(); + let trail = review["report"]["parts"][0]["entities"][0]["audit"] + .as_array() + .expect("the entity's trail"); + let named: HashSet = trail + .iter() + .filter(|event| event["kind"]["kind"] == "manual") + .filter_map(|event| event["kind"]["detail"]["by"].as_str()) + .map(ToOwned::to_owned) + .collect(); + assert_eq!(named, both, "{trail:#?}"); + let accounts: HashSet = review["accounts"] + .as_array() + .expect("the resolved accounts") + .iter() + .filter_map(|account| account["id"].as_str()) + .map(ToOwned::to_owned) + .collect(); + assert_eq!(accounts, both); + + let outsider = app.actor().await; + app.server() + .get(&review_path) + .authorization_bearer(&outsider.jwt) + .await + .assert_status_forbidden(); +}