chore(docs): R5.6 switch patch with the M1 correction (inactive)
This commit is contained in:
1 parent
bc36d3d639
commit
8e77e37633
1 file changed
+460
-122
@@ -9,6 +9,28 @@ index a9140e4..aaeef54 100644
|
|||||||
+# Written by the Rust pipeline (`pnpm r5:import-equine`, R5.6): byte-exact, never reformatted.
|
+# Written by the Rust pipeline (`pnpm r5:import-equine`, R5.6): byte-exact, never reformatted.
|
||||||
+supabase/seed/anatomical-sheets/equine/legacy-import/
|
+supabase/seed/anatomical-sheets/equine/legacy-import/
|
||||||
+supabase/seed/anatomical-sheets/equine/draft/
|
+supabase/seed/anatomical-sheets/equine/draft/
|
||||||
|
diff --git a/CLAUDE.md b/CLAUDE.md
|
||||||
|
index e664250..7773db9 100644
|
||||||
|
--- a/CLAUDE.md
|
||||||
|
+++ b/CLAUDE.md
|
||||||
|
@@ -118,7 +118,7 @@ pnpm db:types:check # CI diff
|
||||||
|
# Reference sheet in the app: the dev server bundles the curated draft; a build does not
|
||||||
|
pnpm build:preview # SHEET_BUNDLE=draft build (manual validation, preview deployments)
|
||||||
|
pnpm preview:draft # same, then serves it
|
||||||
|
-pnpm import:equine # regenerate legacy-import/ and draft/ (document, migration map, review drawings): the TypeScript writer of the seed until the R5 switch
|
||||||
|
+pnpm import:equine --check | --out <dir> # since R5.6 the official seed writer: the Rust pipeline (same as `pnpm r5:import-equine`), fingerprint `sha256-rfc8785-validated-v1`; `pnpm import:equine:legacy` = the TypeScript generator (pre-switch convention) until R5.7
|
||||||
|
pnpm r5:import-equine --check | --out <dir> # the Rust pipeline (R5.2 importer, R5.3 draft, R5.4 review files): compare the 18 generated files with the committed folders (bytes; app drawings under the declared R3 rule), or write <dir>/{legacy-import,draft} into an empty folder; never deletes (scripts/import-equine.sh, first run compiles)
|
||||||
|
pnpm assets:upload [--check] <seed folder> # R5.5: uploads the sheet drawings of a generated seed folder to the LOCAL stack's private bucket (Rust `upload-sheet-assets`, feature `upload`; SUPABASE_URL local with a port, SUPABASE_SERVICE_ROLE_KEY typed, never printed; no overwrite, confirm after verify; run by hand, scripts/upload-sheet-assets.sh); the TypeScript one is `assets:upload:legacy` until R5.7
|
||||||
|
pnpm e2e:sheet-assets # scripts/sheet-assets-e2e.sh: that tool against the local stack (upload, rerun, anon and wrong key, refused destinations); run by hand
|
||||||
|
@@ -502,7 +502,7 @@ Database (Supabase)
|
||||||
|
`publish_sheet_version`. Integrity rule codes are shared by `validateSheetDocument` (TS) and
|
||||||
|
`private.sheet_document_issues` (SQL); add a rule on both sides and in the spec table.
|
||||||
|
- Document schema change → bump `SHEET_DOCUMENT_SCHEMA_VERSION`, extend the SQL CHECK on `document_schema_version`.
|
||||||
|
-- Official equine sheet = generated seed `draft/` (`pnpm import:equine`, never edit `legacy-import/` or `draft/` by hand;
|
||||||
|
+- Official equine sheet = generated seed `draft/` (`pnpm import:equine --out` into an empty folder, then reviewed and copied; never edit `legacy-import/` or `draft/` by hand;
|
||||||
|
the golden test fails on drift). Every content change goes through `curation/changes.json` (traced in CHANGELOG.md).
|
||||||
|
It is a DRAFT until a platform admin publishes it after business review of `REVIEW-REPORT.md`.
|
||||||
|
- Sheet SVG bytes live in Storage bucket `anatomical-sheet-assets` as `<sha256>.svg`; uploads are an operator task
|
||||||
diff --git a/apps/app/tests/helpers/goldenReports.ts b/apps/app/tests/helpers/goldenReports.ts
|
diff --git a/apps/app/tests/helpers/goldenReports.ts b/apps/app/tests/helpers/goldenReports.ts
|
||||||
index ef46bce..d66fb68 100644
|
index ef46bce..d66fb68 100644
|
||||||
--- a/apps/app/tests/helpers/goldenReports.ts
|
--- a/apps/app/tests/helpers/goldenReports.ts
|
||||||
@@ -181,19 +203,22 @@ index ce5a2fd..7c15f76 100644
|
|||||||
+name = "r5_6_switch"
|
+name = "r5_6_switch"
|
||||||
+required-features = ["pdf-read", "pdf-write"]
|
+required-features = ["pdf-read", "pdf-write"]
|
||||||
diff --git a/crates/core/src/bin/report_compare.rs b/crates/core/src/bin/report_compare.rs
|
diff --git a/crates/core/src/bin/report_compare.rs b/crates/core/src/bin/report_compare.rs
|
||||||
index 59cf060..91b34ef 100644
|
index 59cf060..0748403 100644
|
||||||
--- a/crates/core/src/bin/report_compare.rs
|
--- a/crates/core/src/bin/report_compare.rs
|
||||||
+++ b/crates/core/src/bin/report_compare.rs
|
+++ b/crates/core/src/bin/report_compare.rs
|
||||||
@@ -37,6 +37,8 @@ struct SeedRef {
|
@@ -37,6 +37,11 @@ struct SeedRef {
|
||||||
document_sha256: String,
|
document_sha256: String,
|
||||||
schema_version: f64,
|
schema_version: f64,
|
||||||
species_id: String,
|
species_id: String,
|
||||||
+ #[serde(default)]
|
+ #[serde(
|
||||||
|
+ default,
|
||||||
|
+ deserialize_with = "faunosteo_core::domain::sheet::loaded::present_block"
|
||||||
|
+ )]
|
||||||
+ fingerprint: Option<faunosteo_core::domain::sheet::loaded::DeclaredFingerprint>,
|
+ fingerprint: Option<faunosteo_core::domain::sheet::loaded::DeclaredFingerprint>,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn seed_json<T: for<'de> Deserialize<'de>>(name: &str) -> Result<T, String> {
|
fn seed_json<T: for<'de> Deserialize<'de>>(name: &str) -> Result<T, String> {
|
||||||
@@ -58,6 +60,7 @@ fn load_sheet() -> Result<LoadedSheet, String> {
|
@@ -58,6 +63,7 @@ fn load_sheet() -> Result<LoadedSheet, String> {
|
||||||
document_sha256: reference.document_sha256,
|
document_sha256: reference.document_sha256,
|
||||||
schema_version,
|
schema_version,
|
||||||
species_id: reference.species_id,
|
species_id: reference.species_id,
|
||||||
@@ -287,37 +312,60 @@ index 19126aa..dcc19b6 100644
|
|||||||
files.push(("CHANGELOG.md".to_owned(), format_report(&changelog)?));
|
files.push(("CHANGELOG.md".to_owned(), format_report(&changelog)?));
|
||||||
files.push(("REVIEW-REPORT.md".to_owned(), format_report(&review)?));
|
files.push(("REVIEW-REPORT.md".to_owned(), format_report(&review)?));
|
||||||
files.push((DRAFT_SEED_SQL_FILE.to_owned(), seed));
|
files.push((DRAFT_SEED_SQL_FILE.to_owned(), seed));
|
||||||
|
diff --git a/crates/core/src/domain/archive/snapshot_rules.rs b/crates/core/src/domain/archive/snapshot_rules.rs
|
||||||
|
index 6e00fb4..ebdcb00 100644
|
||||||
|
--- a/crates/core/src/domain/archive/snapshot_rules.rs
|
||||||
|
+++ b/crates/core/src/domain/archive/snapshot_rules.rs
|
||||||
|
@@ -51,13 +51,27 @@ impl SnapshotRejection {
|
||||||
|
|
||||||
|
/// The snapshot of `sheet` that `report` needs: pure, deterministic (document order
|
||||||
|
/// everywhere). A missing asset is left out and caught by `assert_snapshot`.
|
||||||
|
+///
|
||||||
|
+/// M1 (owner 2026-10-25, R5.6): a report of this sheet stamped with the registered historical
|
||||||
|
+/// value of its verified, recomputed content gets a snapshot carrying that same stamp, so its
|
||||||
|
+/// archive holds one value and every reader (the frozen N-1 one, a rollback build) keeps it.
|
||||||
|
+/// In every other case the snapshot carries the sheet's own value, and the export's strict
|
||||||
|
+/// equality refuses a report that differs.
|
||||||
|
pub fn build_sheet_snapshot(sheet: &LoadedSheet, report: &Report) -> SheetSnapshot {
|
||||||
|
+ let stamp = &report.sheet.document_sha256;
|
||||||
|
+ let document_sha256 = if report.sheet.sheet_id == sheet.reference.sheet_id
|
||||||
|
+ && sheet.recognises_historical_stamp(&report.sheet.sheet_id, stamp)
|
||||||
|
+ {
|
||||||
|
+ stamp.clone()
|
||||||
|
+ } else {
|
||||||
|
+ sheet.reference.document_sha256.clone()
|
||||||
|
+ };
|
||||||
|
SheetSnapshot {
|
||||||
|
status: sheet.status,
|
||||||
|
reference: SheetSnapshotRef {
|
||||||
|
sheet_id: sheet.reference.sheet_id.clone(),
|
||||||
|
version_id: sheet.reference.version_id.clone(),
|
||||||
|
- document_sha256: sheet.reference.document_sha256.clone(),
|
||||||
|
+ document_sha256,
|
||||||
|
schema_version: sheet.schema_version,
|
||||||
|
species_id: sheet.species_id.clone(),
|
||||||
|
},
|
||||||
diff --git a/crates/core/src/domain/report/rebase.rs b/crates/core/src/domain/report/rebase.rs
|
diff --git a/crates/core/src/domain/report/rebase.rs b/crates/core/src/domain/report/rebase.rs
|
||||||
index 9281642..9084cae 100644
|
index 9281642..9df79ed 100644
|
||||||
--- a/crates/core/src/domain/report/rebase.rs
|
--- a/crates/core/src/domain/report/rebase.rs
|
||||||
+++ b/crates/core/src/domain/report/rebase.rs
|
+++ b/crates/core/src/domain/report/rebase.rs
|
||||||
@@ -5,6 +5,7 @@
|
@@ -37,7 +37,13 @@ pub fn rebase_report_on_sheet(
|
||||||
//! snapshot when the report carries none, and the report now references the loaded sheet.
|
|
||||||
//! Nothing happens when the report already sits on the loaded sheet.
|
|
||||||
|
|
||||||
+use crate::domain::sheet::fingerprint::equivalence;
|
|
||||||
use serde::Serialize;
|
|
||||||
#[cfg(feature = "ts")]
|
|
||||||
use ts_rs::TS;
|
|
||||||
@@ -37,7 +38,15 @@ pub fn rebase_report_on_sheet(
|
|
||||||
sheet: &LoadedSheet,
|
sheet: &LoadedSheet,
|
||||||
archived: Option<&SheetSnapshot>,
|
archived: Option<&SheetSnapshot>,
|
||||||
) -> Result<RebaseOutcome, ReadFailure> {
|
) -> Result<RebaseOutcome, ReadFailure> {
|
||||||
- if report.sheet.document_sha256 == sheet.reference.document_sha256 {
|
- if report.sheet.document_sha256 == sheet.reference.document_sha256 {
|
||||||
+ // Same document: equal fingerprints, or the registry's pair for this very sheet once its
|
+ // Same document: equal fingerprints, or the registered historical value of this very sheet,
|
||||||
+ // `v1` value was verified at load (R5.6).
|
+ // proven against its verified, recomputed `v1` value (R5.6).
|
||||||
+ let same_sheet =
|
|
||||||
+ report.sheet.sheet_id == sheet.reference.sheet_id && sheet.fingerprint_verified;
|
|
||||||
+ let stamped = &report.sheet.document_sha256;
|
+ let stamped = &report.sheet.document_sha256;
|
||||||
+ let current = &sheet.reference.document_sha256;
|
+ if *stamped == sheet.reference.document_sha256
|
||||||
+ if stamped == current
|
+ || (report.sheet.sheet_id == sheet.reference.sheet_id
|
||||||
+ || (same_sheet && equivalence(&sheet.reference.sheet_id, stamped, current).same_document())
|
+ && sheet.recognises_historical_stamp(&report.sheet.sheet_id, stamped))
|
||||||
+ {
|
+ {
|
||||||
return Ok(RebaseOutcome {
|
return Ok(RebaseOutcome {
|
||||||
report: report.clone(),
|
report: report.clone(),
|
||||||
unresolved_zones: 0,
|
unresolved_zones: 0,
|
||||||
diff --git a/crates/core/src/domain/sheet/fingerprint.rs b/crates/core/src/domain/sheet/fingerprint.rs
|
diff --git a/crates/core/src/domain/sheet/fingerprint.rs b/crates/core/src/domain/sheet/fingerprint.rs
|
||||||
index 0fca332..eda9746 100644
|
index 0fca332..81f25f6 100644
|
||||||
--- a/crates/core/src/domain/sheet/fingerprint.rs
|
--- a/crates/core/src/domain/sheet/fingerprint.rs
|
||||||
+++ b/crates/core/src/domain/sheet/fingerprint.rs
|
+++ b/crates/core/src/domain/sheet/fingerprint.rs
|
||||||
@@ -1,6 +1,5 @@
|
@@ -1,6 +1,5 @@
|
||||||
@@ -364,7 +412,92 @@ index 0fca332..eda9746 100644
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Checks what a `sheet-ref.json` declares (descriptive only): the convention must be `v1` and
|
/// Checks what a `sheet-ref.json` declares (descriptive only): the convention must be `v1` and
|
||||||
@@ -189,10 +191,8 @@ fn write_string(text: &str, out: &mut String) {
|
@@ -116,20 +118,39 @@ pub fn check_declared(
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
-/// RFC 8785 text of a JSON value. `None` for a number with no I-JSON form (never produced by
|
||||||
|
-/// the core's parser, which refuses non-finite values).
|
||||||
|
-pub fn canonical_json(value: &Value) -> Option<String> {
|
||||||
|
+/// The deepest nesting `canonical_json` writes: serde_json's own parse limit, so every value the
|
||||||
|
+/// core parsed fits; a value built in code beyond it is refused, never a stack overflow.
|
||||||
|
+pub const MAX_CANONICAL_DEPTH: usize = 128;
|
||||||
|
+
|
||||||
|
+/// Why a value has no RFC 8785 text.
|
||||||
|
+#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
+pub enum CanonicalError {
|
||||||
|
+ /// A number with no I-JSON form (never produced by the core's parser).
|
||||||
|
+ NonFinite,
|
||||||
|
+ /// Containers nested deeper than `MAX_CANONICAL_DEPTH`.
|
||||||
|
+ TooDeep,
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+/// RFC 8785 text of a JSON value.
|
||||||
|
+pub fn canonical_json(value: &Value) -> Result<String, CanonicalError> {
|
||||||
|
let mut out = String::new();
|
||||||
|
- write_value(value, &mut out)?;
|
||||||
|
- Some(out)
|
||||||
|
+ write_value(value, 0, &mut out)?;
|
||||||
|
+ Ok(out)
|
||||||
|
}
|
||||||
|
|
||||||
|
-fn write_value(value: &Value, out: &mut String) -> Option<()> {
|
||||||
|
+fn write_value(value: &Value, depth: usize, out: &mut String) -> Result<(), CanonicalError> {
|
||||||
|
+ let nested = matches!(value, Value::Array(_) | Value::Object(_));
|
||||||
|
+ if nested && depth >= MAX_CANONICAL_DEPTH {
|
||||||
|
+ return Err(CanonicalError::TooDeep);
|
||||||
|
+ }
|
||||||
|
match value {
|
||||||
|
Value::Null => out.push_str("null"),
|
||||||
|
Value::Bool(flag) => out.push_str(if *flag { "true" } else { "false" }),
|
||||||
|
Value::Number(number) => {
|
||||||
|
- let float = number.as_f64().filter(|f| f.is_finite())?;
|
||||||
|
+ let float = number
|
||||||
|
+ .as_f64()
|
||||||
|
+ .filter(|f| f.is_finite())
|
||||||
|
+ .ok_or(CanonicalError::NonFinite)?;
|
||||||
|
out.push_str(&js_number(float));
|
||||||
|
}
|
||||||
|
Value::String(text) => write_string(text, out),
|
||||||
|
@@ -139,16 +160,20 @@ fn write_value(value: &Value, out: &mut String) -> Option<()> {
|
||||||
|
if index > 0 {
|
||||||
|
out.push(',');
|
||||||
|
}
|
||||||
|
- write_value(item, out)?;
|
||||||
|
+ write_value(item, depth + 1, out)?;
|
||||||
|
}
|
||||||
|
out.push(']');
|
||||||
|
}
|
||||||
|
- Value::Object(map) => write_object(map, out)?,
|
||||||
|
+ Value::Object(map) => write_object(map, depth, out)?,
|
||||||
|
}
|
||||||
|
- Some(())
|
||||||
|
+ Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
-fn write_object(map: &serde_json::Map<String, Value>, out: &mut String) -> Option<()> {
|
||||||
|
+fn write_object(
|
||||||
|
+ map: &serde_json::Map<String, Value>,
|
||||||
|
+ depth: usize,
|
||||||
|
+ out: &mut String,
|
||||||
|
+) -> Result<(), CanonicalError> {
|
||||||
|
let mut entries: Vec<(Vec<u16>, &String, &Value)> = map
|
||||||
|
.iter()
|
||||||
|
.map(|(key, item)| (key.encode_utf16().collect(), key, item))
|
||||||
|
@@ -161,10 +186,10 @@ fn write_object(map: &serde_json::Map<String, Value>, out: &mut String) -> Optio
|
||||||
|
}
|
||||||
|
write_string(key, out);
|
||||||
|
out.push(':');
|
||||||
|
- write_value(item, out)?;
|
||||||
|
+ write_value(item, depth + 1, out)?;
|
||||||
|
}
|
||||||
|
out.push('}');
|
||||||
|
- Some(())
|
||||||
|
+ Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// `JSON.stringify` of a string: `"` `\` and the controls escaped (short forms where JSON has
|
||||||
|
@@ -189,41 +214,49 @@ fn write_string(text: &str, out: &mut String) {
|
||||||
out.push('"');
|
out.push('"');
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -376,7 +509,20 @@ index 0fca332..eda9746 100644
|
|||||||
mod hashing {
|
mod hashing {
|
||||||
use sha2::{Digest, Sha256};
|
use sha2::{Digest, Sha256};
|
||||||
|
|
||||||
@@ -211,18 +211,26 @@ mod hashing {
|
use super::canonical_json;
|
||||||
|
use crate::domain::js::parse_json;
|
||||||
|
use crate::domain::sheet::schema::AnatomicalSheetDocument;
|
||||||
|
- use crate::domain::sheet::validate::validate_sheet_document;
|
||||||
|
+ use crate::domain::sheet::validate::{is_publishable, validate_sheet_document};
|
||||||
|
|
||||||
|
/// Why a document has no fingerprint: an invalid sheet is never stamped.
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
pub enum FingerprintError {
|
||||||
|
Parse(String),
|
||||||
|
Shape(String),
|
||||||
|
- /// The integrity rules found issues (their count).
|
||||||
|
+ /// The integrity rules found errors (the count of every issue found).
|
||||||
|
Invalid(usize),
|
||||||
Canonical,
|
Canonical,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -389,6 +535,7 @@ index 0fca332..eda9746 100644
|
|||||||
let document: AnatomicalSheetDocument =
|
let document: AnatomicalSheetDocument =
|
||||||
serde_json::from_value(value).map_err(|e| FingerprintError::Shape(e.to_string()))?;
|
serde_json::from_value(value).map_err(|e| FingerprintError::Shape(e.to_string()))?;
|
||||||
- let issues = validate_sheet_document(&document);
|
- let issues = validate_sheet_document(&document);
|
||||||
|
- if !issues.is_empty() {
|
||||||
+ document_fingerprint(&document)
|
+ document_fingerprint(&document)
|
||||||
+ }
|
+ }
|
||||||
+
|
+
|
||||||
@@ -397,37 +544,51 @@ index 0fca332..eda9746 100644
|
|||||||
+ pub fn document_fingerprint(
|
+ pub fn document_fingerprint(
|
||||||
+ document: &AnatomicalSheetDocument,
|
+ document: &AnatomicalSheetDocument,
|
||||||
+ ) -> Result<String, FingerprintError> {
|
+ ) -> Result<String, FingerprintError> {
|
||||||
|
+ // Integrity errors refuse a fingerprint; warnings do not (`is_publishable`: a draft may
|
||||||
|
+ // hold an annotation with no finding zone or an unreferenced zone, R5.6 rehearsal).
|
||||||
+ let issues = validate_sheet_document(document);
|
+ let issues = validate_sheet_document(document);
|
||||||
if !issues.is_empty() {
|
+ if !is_publishable(&issues) {
|
||||||
return Err(FingerprintError::Invalid(issues.len()));
|
return Err(FingerprintError::Invalid(issues.len()));
|
||||||
}
|
}
|
||||||
let validated =
|
let validated =
|
||||||
- serde_json::to_value(&document).map_err(|e| FingerprintError::Shape(e.to_string()))?;
|
- serde_json::to_value(&document).map_err(|e| FingerprintError::Shape(e.to_string()))?;
|
||||||
|
- let canonical = canonical_json(&validated).ok_or(FingerprintError::Canonical)?;
|
||||||
+ serde_json::to_value(document).map_err(|e| FingerprintError::Shape(e.to_string()))?;
|
+ serde_json::to_value(document).map_err(|e| FingerprintError::Shape(e.to_string()))?;
|
||||||
let canonical = canonical_json(&validated).ok_or(FingerprintError::Canonical)?;
|
+ let canonical = canonical_json(&validated).map_err(|_| FingerprintError::Canonical)?;
|
||||||
Ok(Sha256::digest(canonical.as_bytes())
|
Ok(Sha256::digest(canonical.as_bytes())
|
||||||
.iter()
|
.iter()
|
||||||
|
.map(|byte| format!("{byte:02x}"))
|
||||||
diff --git a/crates/core/src/domain/sheet/loaded.rs b/crates/core/src/domain/sheet/loaded.rs
|
diff --git a/crates/core/src/domain/sheet/loaded.rs b/crates/core/src/domain/sheet/loaded.rs
|
||||||
index 4065978..3030989 100644
|
index 4065978..afc7f33 100644
|
||||||
--- a/crates/core/src/domain/sheet/loaded.rs
|
--- a/crates/core/src/domain/sheet/loaded.rs
|
||||||
+++ b/crates/core/src/domain/sheet/loaded.rs
|
+++ b/crates/core/src/domain/sheet/loaded.rs
|
||||||
@@ -6,6 +6,7 @@ use std::collections::HashMap;
|
@@ -6,6 +6,9 @@ use std::collections::HashMap;
|
||||||
|
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
+use super::fingerprint::{AliasRefusal, check_declared, document_fingerprint};
|
+use super::fingerprint::{
|
||||||
|
+ AliasRefusal, Equivalence, check_declared, document_fingerprint, equivalence,
|
||||||
|
+};
|
||||||
use super::index::{IndexedDocument, NoMainView, SheetIndex};
|
use super::index::{IndexedDocument, NoMainView, SheetIndex};
|
||||||
use super::schema::AnatomicalSheetDocument;
|
use super::schema::AnatomicalSheetDocument;
|
||||||
use crate::anatomy::svg::{Element, read_svg};
|
use crate::anatomy::svg::{Element, read_svg};
|
||||||
@@ -33,6 +34,16 @@ pub struct BundledRef {
|
@@ -33,6 +36,24 @@ pub struct BundledRef {
|
||||||
pub document_sha256: String,
|
pub document_sha256: String,
|
||||||
pub schema_version: JsInt,
|
pub schema_version: JsInt,
|
||||||
pub species_id: String,
|
pub species_id: String,
|
||||||
+ /// Descriptive (R5.6): checked against the core's registry at load, never trusted alone.
|
+ /// Descriptive (R5.6): checked against the core's registry at load, never trusted alone.
|
||||||
+ #[serde(default)]
|
+ /// Absent: a historical (v0) reference; present, it must be a valid block (`null` refused).
|
||||||
|
+ #[serde(default, deserialize_with = "present_block")]
|
||||||
+ pub fingerprint: Option<DeclaredFingerprint>,
|
+ pub fingerprint: Option<DeclaredFingerprint>,
|
||||||
+}
|
+}
|
||||||
+
|
+
|
||||||
|
+/// `fingerprint` present means a block: an explicit `null` is refused, not read as absent.
|
||||||
|
+pub fn present_block<'de, D: serde::Deserializer<'de>>(
|
||||||
|
+ deserializer: D,
|
||||||
|
+) -> Result<Option<DeclaredFingerprint>, D::Error> {
|
||||||
|
+ DeclaredFingerprint::deserialize(deserializer).map(Some)
|
||||||
|
+}
|
||||||
|
+
|
||||||
+#[derive(Debug, Clone, Deserialize)]
|
+#[derive(Debug, Clone, Deserialize)]
|
||||||
+#[serde(deny_unknown_fields)]
|
+#[serde(deny_unknown_fields)]
|
||||||
+pub struct DeclaredFingerprint {
|
+pub struct DeclaredFingerprint {
|
||||||
@@ -436,18 +597,17 @@ index 4065978..3030989 100644
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// A loaded, indexed sheet.
|
/// A loaded, indexed sheet.
|
||||||
@@ -49,6 +60,10 @@ pub struct LoadedSheet {
|
@@ -49,6 +70,9 @@ pub struct LoadedSheet {
|
||||||
/// sha256 by `svg_asset_id`; carried into an archive as provenance.
|
/// sha256 by `svg_asset_id`; carried into an archive as provenance.
|
||||||
pub asset_hashes: HashMap<String, String>,
|
pub asset_hashes: HashMap<String, String>,
|
||||||
pub migration_map: ReportMigrationMap,
|
pub migration_map: ReportMigrationMap,
|
||||||
+ /// The reference declared `v1` and its value was recomputed from the document (R5.6): only
|
+ /// The `v1` value the loader recomputed from the document and found declared (R5.6); `None`
|
||||||
+ /// then does a registered historical stamp count as this sheet's. A historical reference
|
+ /// for a historical reference (no block). Private: only `from_bundle` sets it.
|
||||||
+ /// (no block) loads as before, with no alias privilege.
|
+ verified_fingerprint: Option<String>,
|
||||||
+ pub fingerprint_verified: bool,
|
|
||||||
index: SheetIndex,
|
index: SheetIndex,
|
||||||
/// Each asset read once at load (R3): the sanitised tree, or why it cannot be drawn. A
|
/// Each asset read once at load (R3): the sanitised tree, or why it cannot be drawn. A
|
||||||
/// rejection only affects the views on that asset; `assets` keeps the raw texts (the
|
/// rejection only affects the views on that asset; `assets` keeps the raw texts (the
|
||||||
@@ -76,6 +91,8 @@ pub enum LoadError {
|
@@ -76,6 +100,8 @@ pub enum LoadError {
|
||||||
Shape(serde_json::Error),
|
Shape(serde_json::Error),
|
||||||
/// The document has no main view.
|
/// The document has no main view.
|
||||||
NoMainView,
|
NoMainView,
|
||||||
@@ -456,24 +616,50 @@ index 4065978..3030989 100644
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl From<serde_json::Error> for LoadError {
|
impl From<serde_json::Error> for LoadError {
|
||||||
@@ -102,6 +119,8 @@ impl LoadedSheet {
|
@@ -102,6 +128,9 @@ impl LoadedSheet {
|
||||||
.map(|(id, text)| (id.clone(), read_drawing(text)))
|
.map(|(id, text)| (id.clone(), read_drawing(text)))
|
||||||
.collect();
|
.collect();
|
||||||
let r = data.reference;
|
let r = data.reference;
|
||||||
+ let fingerprint_verified =
|
+ let verified_fingerprint = check_reference(&r, &document)
|
||||||
+ check_reference(&r, &document).map_err(LoadError::Fingerprint)?;
|
+ .map_err(LoadError::Fingerprint)?
|
||||||
|
+ .then(|| r.document_sha256.clone());
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
status: data.status,
|
status: data.status,
|
||||||
reference: SheetRef {
|
reference: SheetRef {
|
||||||
@@ -115,6 +134,7 @@ impl LoadedSheet {
|
@@ -115,11 +144,32 @@ impl LoadedSheet {
|
||||||
assets: data.assets,
|
assets: data.assets,
|
||||||
asset_hashes: data.asset_hashes,
|
asset_hashes: data.asset_hashes,
|
||||||
migration_map,
|
migration_map,
|
||||||
+ fingerprint_verified,
|
+ verified_fingerprint,
|
||||||
index,
|
index,
|
||||||
drawings,
|
drawings,
|
||||||
})
|
})
|
||||||
@@ -133,3 +153,28 @@ impl LoadedSheet {
|
}
|
||||||
|
|
||||||
|
+ /// Whether the loader verified a `v1` reference (no alias privilege otherwise).
|
||||||
|
+ pub fn is_fingerprint_verified(&self) -> bool {
|
||||||
|
+ self.verified_fingerprint.is_some()
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ /// Whether `stamp`, carried by a report of this sheet, is the registered historical value of
|
||||||
|
+ /// this sheet's current content (R5.6, owner M1 rules): the loader verified a `v1` reference,
|
||||||
|
+ /// the document as it stands now recomputes to that same value, and the registry binds `stamp`
|
||||||
|
+ /// to it for this sheet. No declared or stored value stands in for the recomputation, so a
|
||||||
|
+ /// mutated document or reference, a v0 sheet, another sheet or a forged stamp never qualify.
|
||||||
|
+ pub fn recognises_historical_stamp(&self, sheet_id: &str, stamp: &str) -> bool {
|
||||||
|
+ let Some(verified) = &self.verified_fingerprint else {
|
||||||
|
+ return false;
|
||||||
|
+ };
|
||||||
|
+ sheet_id == self.reference.sheet_id
|
||||||
|
+ && *verified == self.reference.document_sha256
|
||||||
|
+ && equivalence(sheet_id, stamp, verified) == Equivalence::TrustedAlias
|
||||||
|
+ && document_fingerprint(&self.document).is_ok_and(|now| now == *verified)
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
pub fn indexed(&self) -> IndexedDocument<'_> {
|
||||||
|
self.index.over(&self.document)
|
||||||
|
}
|
||||||
|
@@ -133,3 +183,28 @@ impl LoadedSheet {
|
||||||
self.drawings.get(asset_id)
|
self.drawings.get(asset_id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -515,31 +701,32 @@ index f0c6997..7f73cff 100644
|
|||||||
}
|
}
|
||||||
|
|
||||||
diff --git a/crates/core/src/pdf/compare/lines.rs b/crates/core/src/pdf/compare/lines.rs
|
diff --git a/crates/core/src/pdf/compare/lines.rs b/crates/core/src/pdf/compare/lines.rs
|
||||||
index 35e8dd2..3753529 100644
|
index 35e8dd2..7a33db6 100644
|
||||||
--- a/crates/core/src/pdf/compare/lines.rs
|
--- a/crates/core/src/pdf/compare/lines.rs
|
||||||
+++ b/crates/core/src/pdf/compare/lines.rs
|
+++ b/crates/core/src/pdf/compare/lines.rs
|
||||||
@@ -2,6 +2,7 @@
|
@@ -2,6 +2,7 @@
|
||||||
//! current label next to the archived one, `!! UNRESOLVED` with the reason where the sheet
|
//! current label next to the archived one, `!! UNRESOLVED` with the reason where the sheet
|
||||||
//! cannot place an item. Every untrusted string goes through [`esc`].
|
//! cannot place an item. Every untrusted string goes through [`esc`].
|
||||||
|
|
||||||
+use crate::domain::sheet::fingerprint::{Equivalence, equivalence};
|
+use crate::domain::sheet::fingerprint::Equivalence;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
|
|
||||||
@@ -346,13 +347,32 @@ fn archive_line(outcome: &ArchiveReadOutcome) -> Vec<String> {
|
@@ -346,13 +347,33 @@ fn archive_line(outcome: &ArchiveReadOutcome) -> Vec<String> {
|
||||||
|
|
||||||
fn sheet_line(report: &Report, sheet: &LoadedSheet) -> String {
|
fn sheet_line(report: &Report, sheet: &LoadedSheet) -> String {
|
||||||
let reference = &sheet.reference;
|
let reference = &sheet.reference;
|
||||||
- let same_sheet = report.sheet.sheet_id == reference.sheet_id
|
- let same_sheet = report.sheet.sheet_id == reference.sheet_id
|
||||||
- && report.sheet.document_sha256 == reference.document_sha256;
|
- && report.sheet.document_sha256 == reference.document_sha256;
|
||||||
+ let same = match equivalence(
|
+ let same = if report.sheet.document_sha256 == reference.document_sha256 {
|
||||||
+ &reference.sheet_id,
|
+ Equivalence::Identical
|
||||||
+ &report.sheet.document_sha256,
|
+ } else if sheet
|
||||||
+ &reference.document_sha256,
|
+ .recognises_historical_stamp(&report.sheet.sheet_id, &report.sheet.document_sha256)
|
||||||
+ ) {
|
+ {
|
||||||
+ // The alias privilege needs the loaded sheet's verified `v1` value (R5.6).
|
+ // The registered historical value of this sheet's verified, recomputed content (R5.6).
|
||||||
+ Equivalence::TrustedAlias if !sheet.fingerprint_verified => Equivalence::Different,
|
+ Equivalence::TrustedAlias
|
||||||
+ other => other,
|
+ } else {
|
||||||
|
+ Equivalence::Different
|
||||||
+ };
|
+ };
|
||||||
+ let same_sheet = report.sheet.sheet_id == reference.sheet_id && same.same_document();
|
+ let same_sheet = report.sheet.sheet_id == reference.sheet_id && same.same_document();
|
||||||
if same_sheet {
|
if same_sheet {
|
||||||
@@ -561,66 +748,6 @@ index 35e8dd2..3753529 100644
|
|||||||
return format!(
|
return format!(
|
||||||
"sheet {} ({status}, matches the bundled sheet)",
|
"sheet {} ({status}, matches the bundled sheet)",
|
||||||
esc(&reference.sheet_id)
|
esc(&reference.sheet_id)
|
||||||
diff --git a/crates/core/src/pdf/write/input.rs b/crates/core/src/pdf/write/input.rs
|
|
||||||
index 120249a..23734ac 100644
|
|
||||||
--- a/crates/core/src/pdf/write/input.rs
|
|
||||||
+++ b/crates/core/src/pdf/write/input.rs
|
|
||||||
@@ -2,6 +2,7 @@
|
|
||||||
//! branding and the labels through their schemas again, the snapshot gate with every asset
|
|
||||||
//! accepted by the SVG reader, the report's sheet and the page caps. Today's error kinds.
|
|
||||||
|
|
||||||
+use crate::domain::sheet::fingerprint::{Equivalence, equivalence};
|
|
||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
@@ -203,9 +204,12 @@ fn reason_of(rejection: SnapshotRejection) -> String {
|
|
||||||
/// Steps 2 and 3: the report belongs to this sheet and fits the page budget.
|
|
||||||
fn assert_exportable(report: &Report, snapshot: &SheetSnapshot) -> Result<(), ExportError> {
|
|
||||||
let reference = &snapshot.reference;
|
|
||||||
- if report.sheet.sheet_id != reference.sheet_id
|
|
||||||
- || report.sheet.document_sha256 != reference.document_sha256
|
|
||||||
- {
|
|
||||||
+ let same = equivalence(
|
|
||||||
+ &reference.sheet_id,
|
|
||||||
+ &report.sheet.document_sha256,
|
|
||||||
+ &reference.document_sha256,
|
|
||||||
+ );
|
|
||||||
+ if report.sheet.sheet_id != reference.sheet_id || !same.same_document() {
|
|
||||||
return Err(error(ExportErrorKind::SheetMismatch, ""));
|
|
||||||
}
|
|
||||||
if report.observations.len() > MAX_OBSERVATIONS {
|
|
||||||
@@ -225,11 +229,30 @@ fn assert_exportable(report: &Report, snapshot: &SheetSnapshot) -> Result<(), Ex
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
+/// M1 (owner 2026-10-24, option 1): an old report on the registered historical fingerprint of
|
|
||||||
+/// this very sheet, exported against the sheet's verified canonical value, archives a snapshot
|
|
||||||
+/// that carries the report's own stamp, so the envelope holds one value and every reader (the
|
|
||||||
+/// frozen N-1 one, a rollback build) keeps the snapshot. Only the registered pair of the same
|
|
||||||
+/// sheet: any other combination was refused by `assert_exportable`, and a new report already
|
|
||||||
+/// carries the canonical value.
|
|
||||||
+fn keep_the_report_stamp(report: &Report, snapshot: &mut SheetSnapshot) {
|
|
||||||
+ let reference = &snapshot.reference;
|
|
||||||
+ let same = equivalence(
|
|
||||||
+ &reference.sheet_id,
|
|
||||||
+ &report.sheet.document_sha256,
|
|
||||||
+ &reference.document_sha256,
|
|
||||||
+ );
|
|
||||||
+ if same == Equivalence::TrustedAlias && report.sheet.sheet_id == reference.sheet_id {
|
|
||||||
+ snapshot.reference.document_sha256 = report.sheet.document_sha256.clone();
|
|
||||||
+ }
|
|
||||||
+}
|
|
||||||
+
|
|
||||||
/// Every check of export.ts before a page is drawn, in its order.
|
|
||||||
pub fn check_input(input: ExportInput) -> Result<CheckedInput, ExportError> {
|
|
||||||
let (branding, labels) = typed_branding(&input)?;
|
|
||||||
- let (snapshot, assets) = checked_snapshot(&input.sheet_snapshot)?;
|
|
||||||
+ let (mut snapshot, assets) = checked_snapshot(&input.sheet_snapshot)?;
|
|
||||||
assert_exportable(&input.report, &snapshot)?;
|
|
||||||
+ keep_the_report_stamp(&input.report, &mut snapshot);
|
|
||||||
let index = SheetIndex::build(&snapshot.document)
|
|
||||||
.map_err(|NoMainView| error(ExportErrorKind::SnapshotInvalid, "no main view"))?;
|
|
||||||
Ok(CheckedInput {
|
|
||||||
diff --git a/crates/core/tests/curation_draft.rs b/crates/core/tests/curation_draft.rs
|
diff --git a/crates/core/tests/curation_draft.rs b/crates/core/tests/curation_draft.rs
|
||||||
index 31c9ffc..ba3b2c1 100644
|
index 31c9ffc..ba3b2c1 100644
|
||||||
--- a/crates/core/tests/curation_draft.rs
|
--- a/crates/core/tests/curation_draft.rs
|
||||||
@@ -1762,7 +1889,7 @@ index 0000000..5633394
|
|||||||
+ "species_id": "equine"
|
+ "species_id": "equine"
|
||||||
+}
|
+}
|
||||||
diff --git a/crates/core/tests/pdf_compare.rs b/crates/core/tests/pdf_compare.rs
|
diff --git a/crates/core/tests/pdf_compare.rs b/crates/core/tests/pdf_compare.rs
|
||||||
index c864071..c445999 100644
|
index c864071..d3fc0e1 100644
|
||||||
--- a/crates/core/tests/pdf_compare.rs
|
--- a/crates/core/tests/pdf_compare.rs
|
||||||
+++ b/crates/core/tests/pdf_compare.rs
|
+++ b/crates/core/tests/pdf_compare.rs
|
||||||
@@ -27,24 +27,58 @@ use serde_json::{Value, json};
|
@@ -27,24 +27,58 @@ use serde_json::{Value, json};
|
||||||
@@ -1896,7 +2023,7 @@ index c864071..c445999 100644
|
|||||||
+ assert_eq!(got.exit_code, row.exit_code, "exit code of `{args}`");
|
+ assert_eq!(got.exit_code, row.exit_code, "exit code of `{args}`");
|
||||||
+ }
|
+ }
|
||||||
+ assert_eq!(aliased, 77, "rows through the alias");
|
+ assert_eq!(aliased, 77, "rows through the alias");
|
||||||
+ assert!(switched_sheet().fingerprint_verified && !draft_sheet().fingerprint_verified);
|
+ assert!(switched_sheet().is_fingerprint_verified() && !draft_sheet().is_fingerprint_verified());
|
||||||
}
|
}
|
||||||
diff --git a/crates/core/tests/pdf_import.rs b/crates/core/tests/pdf_import.rs
|
diff --git a/crates/core/tests/pdf_import.rs b/crates/core/tests/pdf_import.rs
|
||||||
index 97f13ec..05fcdf3 100644
|
index 97f13ec..05fcdf3 100644
|
||||||
@@ -2003,10 +2130,10 @@ index 97f13ec..05fcdf3 100644
|
|||||||
file: &str,
|
file: &str,
|
||||||
diff --git a/crates/core/tests/r5_6_switch.rs b/crates/core/tests/r5_6_switch.rs
|
diff --git a/crates/core/tests/r5_6_switch.rs b/crates/core/tests/r5_6_switch.rs
|
||||||
new file mode 100644
|
new file mode 100644
|
||||||
index 0000000..44b07e5
|
index 0000000..07d5064
|
||||||
--- /dev/null
|
--- /dev/null
|
||||||
+++ b/crates/core/tests/r5_6_switch.rs
|
+++ b/crates/core/tests/r5_6_switch.rs
|
||||||
@@ -0,0 +1,265 @@
|
@@ -0,0 +1,427 @@
|
||||||
+//! The R5.6 switch on the switched seed (owner 2026-10-24 « corrections préalables à la
|
+//! The R5.6 switch on the switched seed (owner 2026-10-24 « corrections préalables à la
|
||||||
+//! bascule » §1, M1 option 1): an old PDF stamped with the registered historical value opens
|
+//! bascule » §1, M1 option 1): an old PDF stamped with the registered historical value opens
|
||||||
+//! with no rebase; re-exported, its snapshot keeps the report's stamp, so the current reader,
|
+//! with no rebase; re-exported, its snapshot keeps the report's stamp, so the current reader,
|
||||||
@@ -2260,20 +2387,182 @@ index 0000000..44b07e5
|
|||||||
+ json_file(&format!("{PRE_SWITCH}/sheet-ref.json")),
|
+ json_file(&format!("{PRE_SWITCH}/sheet-ref.json")),
|
||||||
+ map.clone(),
|
+ map.clone(),
|
||||||
+ );
|
+ );
|
||||||
+ assert!(!rollback.unwrap().fingerprint_verified);
|
+ assert!(!rollback.unwrap().is_fingerprint_verified());
|
||||||
+ let mut v0_with_v1_value = good.clone();
|
+ let mut v0_with_v1_value = good.clone();
|
||||||
+ v0_with_v1_value
|
+ v0_with_v1_value
|
||||||
+ .as_object_mut()
|
+ .as_object_mut()
|
||||||
+ .unwrap()
|
+ .unwrap()
|
||||||
+ .remove("fingerprint");
|
+ .remove("fingerprint");
|
||||||
+ let unverified = sheet_with_ref(v0_with_v1_value, map).unwrap();
|
+ let unverified = sheet_with_ref(v0_with_v1_value, map).unwrap();
|
||||||
+ assert!(!unverified.fingerprint_verified);
|
+ assert!(!unverified.is_fingerprint_verified());
|
||||||
+ let import = import_archive(&unverified, &old_envelope().to_string()).unwrap();
|
+ let import = import_archive(&unverified, &old_envelope().to_string()).unwrap();
|
||||||
+ assert!(import.rebase.rebased);
|
+ assert!(import.rebase.rebased);
|
||||||
+ assert!(draft_sheet().fingerprint_verified);
|
+ assert!(draft_sheet().is_fingerprint_verified());
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+// ---------------------------------------------------------------------------
|
||||||
|
+// M1 correction (owner 2026-10-25): the direct APIs, not only the application's paths.
|
||||||
|
+
|
||||||
|
+fn old_report() -> faunosteo_core::domain::report::Report {
|
||||||
|
+ from(old_envelope()["report"].clone())
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+/// The direct export: a snapshot built by the core for `sheet`, then `export_pdf`.
|
||||||
|
+fn export_on(
|
||||||
|
+ sheet: &LoadedSheet,
|
||||||
|
+ report: &faunosteo_core::domain::report::Report,
|
||||||
|
+) -> Result<Vec<u8>, String> {
|
||||||
|
+ let envelope = old_envelope();
|
||||||
|
+ let input = ExportInput {
|
||||||
|
+ sheet_snapshot: serde_json::to_value(build_sheet_snapshot(sheet, report)).unwrap(),
|
||||||
|
+ report: report.clone(),
|
||||||
|
+ branding: envelope["branding"].clone(),
|
||||||
|
+ labels: envelope["labels"].clone(),
|
||||||
|
+ locale: from(envelope["locale"].clone()),
|
||||||
|
+ exported_at: "2026-10-25T12:00:00.000Z".into(),
|
||||||
|
+ };
|
||||||
|
+ export_pdf(input, &Rasters::default())
|
||||||
|
+ .map(|r| r.pdf)
|
||||||
|
+ .map_err(|e| format!("{e:?}"))
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+#[test]
|
||||||
|
+fn the_direct_export_on_an_unverified_v0_sheet_with_the_canonical_value_is_refused() {
|
||||||
|
+ let map = json_file(&format!("{DRAFT}/report-migration-map.json"));
|
||||||
|
+ let mut v0 = json_file(&format!("{DRAFT}/sheet-ref.json"));
|
||||||
|
+ v0.as_object_mut().unwrap().remove("fingerprint");
|
||||||
|
+ let sheet = sheet_with_ref(v0, map).unwrap();
|
||||||
|
+ assert!(!sheet.is_fingerprint_verified());
|
||||||
|
+ let snapshot = build_sheet_snapshot(&sheet, &old_report());
|
||||||
|
+ assert_eq!(snapshot.reference.document_sha256, canonical());
|
||||||
|
+ let refused = export_on(&sheet, &old_report()).unwrap_err();
|
||||||
|
+ assert!(refused.contains("SheetMismatch"), "{refused}");
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+#[test]
|
||||||
|
+fn a_mutated_document_or_reference_never_keeps_the_alias() {
|
||||||
|
+ let mut document = draft_sheet();
|
||||||
|
+ document.document.name.fr = "Fiche modifiée après chargement".into();
|
||||||
|
+ assert!(!document.recognises_historical_stamp(&document.reference.sheet_id.clone(), alias()));
|
||||||
|
+ assert!(export_on(&document, &old_report()).is_err());
|
||||||
|
+ let mut reference = draft_sheet();
|
||||||
|
+ reference.reference.document_sha256 = "f".repeat(64);
|
||||||
|
+ assert!(!reference.recognises_historical_stamp(&reference.reference.sheet_id.clone(), alias()));
|
||||||
|
+ assert!(export_on(&reference, &old_report()).is_err());
|
||||||
|
+ // Untouched, the same sheet grants it, and the direct export writes one stamp.
|
||||||
|
+ let sheet = draft_sheet();
|
||||||
|
+ assert!(sheet.recognises_historical_stamp(&sheet.reference.sheet_id, alias()));
|
||||||
|
+ let written = attachment(&export_on(&sheet, &old_report()).unwrap());
|
||||||
|
+ assert_eq!(written["sheetSnapshot"]["ref"]["documentSha256"], alias());
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+#[test]
|
||||||
|
+fn the_historical_value_on_another_sheet_id_is_not_recognised() {
|
||||||
|
+ let sheet = draft_sheet();
|
||||||
|
+ assert!(!sheet.recognises_historical_stamp("00000000-0000-0000-0000-000000000000", alias()));
|
||||||
|
+ let mut report = old_report();
|
||||||
|
+ report.sheet.sheet_id = "00000000-0000-0000-0000-000000000000".into();
|
||||||
|
+ assert_eq!(
|
||||||
|
+ build_sheet_snapshot(&sheet, &report)
|
||||||
|
+ .reference
|
||||||
|
+ .document_sha256,
|
||||||
|
+ canonical()
|
||||||
|
+ );
|
||||||
|
+ assert!(export_on(&sheet, &report).is_err());
|
||||||
|
+ let import_other = {
|
||||||
|
+ let mut envelope = old_envelope();
|
||||||
|
+ envelope["report"]["sheet"]["sheetId"] = json!("00000000-0000-0000-0000-000000000000");
|
||||||
|
+ import_archive(&sheet, &envelope.to_string()).unwrap()
|
||||||
|
+ };
|
||||||
|
+ assert!(import_other.rebase.rebased);
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+#[test]
|
||||||
|
+fn a_v1_block_whose_value_contradicts_the_content_is_refused_at_load() {
|
||||||
|
+ let mut document = json_file(&format!("{DRAFT}/document.json"));
|
||||||
|
+ document["name"]["fr"] = json!("Contenu modifié, tampon conservé");
|
||||||
|
+ let base = draft_sheet();
|
||||||
|
+ let assets: serde_json::Map<String, Value> = base
|
||||||
|
+ .assets
|
||||||
|
+ .iter()
|
||||||
|
+ .map(|(k, v)| (k.clone(), json!(v)))
|
||||||
|
+ .collect();
|
||||||
|
+ let data: Result<BundledSheetData, _> = serde_json::from_value(json!({
|
||||||
|
+ "status": "draft",
|
||||||
|
+ "ref": json_file(&format!("{DRAFT}/sheet-ref.json")),
|
||||||
|
+ "document": document,
|
||||||
|
+ "migrationMap": json_file(&format!("{DRAFT}/report-migration-map.json")),
|
||||||
|
+ "assets": assets,
|
||||||
|
+ "assetHashes": {},
|
||||||
|
+ }));
|
||||||
|
+ let refused = LoadedSheet::from_bundle(data.unwrap()).unwrap_err();
|
||||||
|
+ assert!(
|
||||||
|
+ format!("{refused:?}").contains("ContentMismatch"),
|
||||||
|
+ "{refused:?}"
|
||||||
|
+ );
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+#[test]
|
||||||
|
+fn an_explicit_null_block_is_refused_and_an_absent_one_is_v0() {
|
||||||
|
+ let map = json_file(&format!("{DRAFT}/report-migration-map.json"));
|
||||||
|
+ let mut null_block = json_file(&format!("{DRAFT}/sheet-ref.json"));
|
||||||
|
+ null_block["fingerprint"] = Value::Null;
|
||||||
|
+ let refused = sheet_with_ref(null_block, map.clone()).unwrap_err();
|
||||||
|
+ assert!(refused.starts_with("shape:"), "{refused}");
|
||||||
|
+ let mut malformed = json_file(&format!("{DRAFT}/sheet-ref.json"));
|
||||||
|
+ malformed["fingerprint"] = json!("sha256-rfc8785-validated-v1");
|
||||||
|
+ assert!(sheet_with_ref(malformed, map.clone()).is_err());
|
||||||
|
+ let absent = sheet_with_ref(json_file(&format!("{PRE_SWITCH}/sheet-ref.json")), map).unwrap();
|
||||||
|
+ assert!(!absent.is_fingerprint_verified());
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+#[test]
|
||||||
|
+fn a_v1_sheet_carrying_only_draft_warnings_loads() {
|
||||||
|
+ use faunosteo_core::domain::sheet::validate::{SheetIssueSeverity, validate_sheet_document};
|
||||||
|
+ let mut document = json_file(&format!("{DRAFT}/document.json"));
|
||||||
|
+ document["annotations"][0]["finding_zone_id"] = Value::Null;
|
||||||
|
+ let typed = from(document.clone());
|
||||||
|
+ let issues = validate_sheet_document(&typed);
|
||||||
|
+ assert!(!issues.is_empty());
|
||||||
|
+ assert!(
|
||||||
|
+ issues
|
||||||
|
+ .iter()
|
||||||
|
+ .all(|i| i.severity == SheetIssueSeverity::Warning),
|
||||||
|
+ "{issues:?}"
|
||||||
|
+ );
|
||||||
|
+ let value = document_fingerprint(&typed).unwrap();
|
||||||
|
+ let mut reference = json_file(&format!("{DRAFT}/sheet-ref.json"));
|
||||||
|
+ reference["document_sha256"] = json!(value);
|
||||||
|
+ reference["fingerprint"]["aliases"] = json!([]);
|
||||||
|
+ let base = draft_sheet();
|
||||||
|
+ let assets: serde_json::Map<String, Value> = base
|
||||||
|
+ .assets
|
||||||
|
+ .iter()
|
||||||
|
+ .map(|(k, v)| (k.clone(), json!(v)))
|
||||||
|
+ .collect();
|
||||||
|
+ let hashes: serde_json::Map<String, Value> = base
|
||||||
|
+ .asset_hashes
|
||||||
|
+ .iter()
|
||||||
|
+ .map(|(k, v)| (k.clone(), json!(v)))
|
||||||
|
+ .collect();
|
||||||
|
+ let sheet = loaded(
|
||||||
|
+ reference,
|
||||||
|
+ document,
|
||||||
|
+ json_file(&format!("{DRAFT}/report-migration-map.json")),
|
||||||
|
+ Value::Object(assets),
|
||||||
|
+ Value::Object(hashes),
|
||||||
|
+ );
|
||||||
|
+ assert!(sheet.is_fingerprint_verified());
|
||||||
|
+ // Another content: an old report on it is no alias, it rebases.
|
||||||
|
+ assert!(
|
||||||
|
+ import_archive(&sheet, &old_envelope().to_string())
|
||||||
|
+ .unwrap()
|
||||||
|
+ .rebase
|
||||||
|
+ .rebased
|
||||||
|
+ );
|
||||||
+}
|
+}
|
||||||
diff --git a/crates/core/tests/sheet_fingerprint.rs b/crates/core/tests/sheet_fingerprint.rs
|
diff --git a/crates/core/tests/sheet_fingerprint.rs b/crates/core/tests/sheet_fingerprint.rs
|
||||||
index 79a9e09..f298826 100644
|
index 79a9e09..3707e95 100644
|
||||||
--- a/crates/core/tests/sheet_fingerprint.rs
|
--- a/crates/core/tests/sheet_fingerprint.rs
|
||||||
+++ b/crates/core/tests/sheet_fingerprint.rs
|
+++ b/crates/core/tests/sheet_fingerprint.rs
|
||||||
@@ -126,17 +126,16 @@ fn the_registry_holds_one_pair_bound_to_the_equine_sheet() {
|
@@ -126,17 +126,16 @@ fn the_registry_holds_one_pair_bound_to_the_equine_sheet() {
|
||||||
@@ -2316,6 +2605,34 @@ index 79a9e09..f298826 100644
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@@ -268,3 +267,27 @@ fn v1_never_carries_the_historical_value_or_a_malformed_one() {
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
+
|
||||||
|
+fn nested(depth: usize) -> Value {
|
||||||
|
+ let mut value = Value::from(1);
|
||||||
|
+ for _ in 0..depth {
|
||||||
|
+ value = Value::Array(vec![value]);
|
||||||
|
+ }
|
||||||
|
+ value
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+#[test]
|
||||||
|
+fn nesting_is_bounded_with_a_controlled_error() {
|
||||||
|
+ use faunosteo_core::domain::sheet::fingerprint::{CanonicalError, MAX_CANONICAL_DEPTH};
|
||||||
|
+ assert_eq!(MAX_CANONICAL_DEPTH, 128);
|
||||||
|
+ assert!(canonical_json(&nested(MAX_CANONICAL_DEPTH)).is_ok());
|
||||||
|
+ assert_eq!(
|
||||||
|
+ canonical_json(&nested(MAX_CANONICAL_DEPTH + 1)),
|
||||||
|
+ Err(CanonicalError::TooDeep)
|
||||||
|
+ );
|
||||||
|
+ let mut object = Value::from(1);
|
||||||
|
+ for _ in 0..=MAX_CANONICAL_DEPTH {
|
||||||
|
+ object = serde_json::json!({ "k": object });
|
||||||
|
+ }
|
||||||
|
+ assert_eq!(canonical_json(&object), Err(CanonicalError::TooDeep));
|
||||||
|
+}
|
||||||
diff --git a/package.json b/package.json
|
diff --git a/package.json b/package.json
|
||||||
index 6907a5a..02b42a7 100644
|
index 6907a5a..02b42a7 100644
|
||||||
--- a/package.json
|
--- a/package.json
|
||||||
@@ -2573,6 +2890,27 @@ index e0593ef..2fcb5e5 100644
|
|||||||
+ )
|
+ )
|
||||||
+ })
|
+ })
|
||||||
+})
|
+})
|
||||||
|
diff --git a/scripts/import-equine.sh b/scripts/import-equine.sh
|
||||||
|
index 011f78d..861b227 100755
|
||||||
|
--- a/scripts/import-equine.sh
|
||||||
|
+++ b/scripts/import-equine.sh
|
||||||
|
@@ -1,12 +1,12 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
-# `pnpm r5:import-equine --check | --out <dir>`: the anatomical pipeline on the core (R5.2 to
|
||||||
|
-# R5.4), the `import-equine` binary of crates/core behind its `curation` feature, on the native
|
||||||
|
+# `pnpm import:equine --check | --out <dir>` (alias `pnpm r5:import-equine`): the official
|
||||||
|
+# writer of the seed since R5.6, the anatomical pipeline on the core (R5.2 to R5.6), the `import-equine` binary of crates/core behind its `curation` feature, on the native
|
||||||
|
# toolchain of the development machine (scripts/rust-env.sh). The first run compiles it
|
||||||
|
# (release profile); the next ones start at once. `--check` compares the produced folders with
|
||||||
|
# the committed seed and writes nothing; `--out <dir>` writes `<dir>/legacy-import` and
|
||||||
|
# `<dir>/draft` into an absent or empty folder (a relative path is typed from the folder pnpm
|
||||||
|
-# was run in, INIT_CWD). The TypeScript `pnpm import:equine` stays the writer of the seed until
|
||||||
|
-# the R5 switch.
|
||||||
|
+# was run in, INIT_CWD). The TypeScript generator stays reachable as `pnpm import:equine:legacy`
|
||||||
|
+# (pre-switch fingerprint convention) until R5.7.
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
cd "$(dirname "$0")/.."
|
||||||
diff --git a/scripts/rust-check.sh b/scripts/rust-check.sh
|
diff --git a/scripts/rust-check.sh b/scripts/rust-check.sh
|
||||||
index d5f8207..568c1bc 100755
|
index d5f8207..568c1bc 100755
|
||||||
--- a/scripts/rust-check.sh
|
--- a/scripts/rust-check.sh
|
||||||
|
|||||||
Reference in new issue
Block a user