diff --git a/pkgs/id/benchmarks/Cargo.toml b/pkgs/id/benchmarks/Cargo.toml new file mode 100644 index 0000000000..ad627b85fa --- /dev/null +++ b/pkgs/id/benchmarks/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "id-benchmarks" +version = "0.1.0" +edition = "2021" +description = "Benchmark schema, synthetic workload fixture and reference oracle for the #9133 benchmark contract (C9133-01)" +license = "MIT OR Apache-2.0" + +# Standalone crate: deliberately not a member of the pkgs/id workspace +# (the slice owns only this crate; the workspace root is a shared file +# this slice does not edit). Run via: +# cargo test --manifest-path pkgs/id/benchmarks/Cargo.toml --test workload_oracle +[workspace] + +[dependencies] +serde = { version = "1.0", features = ["derive"] } +serde_json = "1.0" +sha2 = "0.11" +hex = "0.4" diff --git a/pkgs/id/benchmarks/fixtures/synthetic-workload.json b/pkgs/id/benchmarks/fixtures/synthetic-workload.json new file mode 100644 index 0000000000..3ea2c7af23 --- /dev/null +++ b/pkgs/id/benchmarks/fixtures/synthetic-workload.json @@ -0,0 +1,187 @@ +{ + "format": "id-atlas-synthetic-workload/v3", + "measurement_status": "synthetic correctness fixture; no timings measured", + "identity_profile": "fixture-only SHA256 over exact profile bytes; not a production ContentId algorithm claim", + "physical_key_profile": "fixture-only immutable generation-qualified keys; key non-reuse modeled, not provider-enforced", + "tenant": "tenant-a", + "expected_content_id": "sha256:ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad", + "operations": [ + { + "id": "blob_put_if_absent", + "input": { "bytes_hex": "616263", "metadata": { "owner": "fixture" } }, + "expected": { + "accepted": true, + "created": true, + "generation": 1, + "physical_key": "fixture/sha256-ba7816bf/gen-1", + "lifecycle": "Live", + "row_revision": 1 + }, + "engine_support": { "d1": "supported", "r2": "supported", "redb": "supported", "turso": "supported" } + }, + { + "id": "blob_put_if_absent", + "input": { "bytes_hex": "616263", "metadata": { "owner": "fixture" } }, + "expected": { + "accepted": true, + "created": false, + "generation": 1, + "lifecycle": "Live", + "reference_count": 0, + "row_revision": 1 + }, + "engine_support": { "d1": "supported", "r2": "supported", "redb": "supported", "turso": "supported" } + }, + { + "id": "blob_get", + "input": {}, + "expected": { "bytes_hex": "616263", "generation": 1, "lifecycle": "Live" }, + "engine_support": { "d1": "supported", "r2": "supported", "redb": "supported", "turso": "supported" } + }, + { + "id": "metadata_lookup", + "input": {}, + "expected": { "metadata": { "owner": "fixture" }, "generation": 1 }, + "engine_support": { "d1": "supported", "r2": "supported", "redb": "supported", "turso": "supported" } + }, + { + "id": "metadata_scan", + "input": { "tenant": "tenant-a", "prefix": "sha256:" }, + "expected": { "content_ids": ["sha256:ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"] }, + "engine_support": { "d1": "supported", "r2": "unsupported", "redb": "supported", "turso": "supported" } + }, + { + "id": "ref_commit_if_live", + "input": { "generation": 1, "reference": "loc-1" }, + "expected": { "accepted": true, "generation": 1, "reference_count": 1 }, + "engine_support": { + "d1": "supported", + "r2": "external-authority-required", + "redb": "supported", + "turso": "supported" + } + }, + { + "id": "blob_put_if_absent", + "input": { "bytes_hex": "616263", "metadata": { "owner": "fixture" } }, + "expected": { + "accepted": true, + "created": false, + "generation": 1, + "lifecycle": "Live", + "reference_count": 1, + "row_revision": 1 + }, + "engine_support": { "d1": "supported", "r2": "supported", "redb": "supported", "turso": "supported" } + }, + { + "id": "object_tombstone_delete", + "input": { "generation": 1 }, + "expected": { "tombstoned": false, "reason": "references-present", "lifecycle": "Live" }, + "engine_support": { + "d1": "authority-fence-only", + "r2": "external-authority-fence-required", + "redb": "authority-fence-only", + "turso": "authority-fence-only" + } + }, + { + "id": "ref_remove", + "input": { "generation": 1, "reference": "loc-1" }, + "expected": { "removed": true, "reference_count": 0 }, + "engine_support": { + "d1": "supported", + "r2": "external-authority-required", + "redb": "supported", + "turso": "supported" + } + }, + { + "id": "object_tombstone_delete", + "input": { "generation": 1 }, + "expected": { + "tombstoned": true, + "generation": 1, + "physical_key": "fixture/sha256-ba7816bf/gen-1", + "lifecycle": "Tombstoned" + }, + "engine_support": { + "d1": "authority-fence-only", + "r2": "external-authority-fence-required", + "redb": "authority-fence-only", + "turso": "authority-fence-only" + } + }, + { + "id": "ref_commit_if_live", + "input": { "generation": 1, "reference": "late-ref" }, + "expected": { "accepted": false, "reason": "generation-fenced" }, + "engine_support": { + "d1": "supported", + "r2": "external-authority-required", + "redb": "supported", + "turso": "supported" + } + }, + { + "id": "blob_put_if_absent", + "input": { "bytes_hex": "616263", "metadata": { "owner": "fixture" } }, + "expected": { + "accepted": false, + "created": false, + "generation": 1, + "lifecycle": "Tombstoned", + "reason": "explicit-resurrection-required" + }, + "engine_support": { "d1": "supported", "r2": "supported", "redb": "supported", "turso": "supported" } + }, + { + "id": "blob_put_if_absent", + "input": { "bytes_hex": "616263", "metadata": { "owner": "fixture" }, "resurrection": true }, + "expected": { + "accepted": true, + "created": true, + "generation": 2, + "physical_key": "fixture/sha256-ba7816bf/gen-2", + "lifecycle": "Live", + "row_revision": 1, + "content_id": "sha256:ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad" + }, + "engine_support": { "d1": "supported", "r2": "supported", "redb": "supported", "turso": "supported" } + }, + { + "id": "ref_commit_if_live", + "input": { "generation": 2, "reference": "loc-2" }, + "expected": { "accepted": true, "generation": 2, "reference_count": 1 }, + "engine_support": { + "d1": "supported", + "r2": "external-authority-required", + "redb": "supported", + "turso": "supported" + } + }, + { + "id": "object_delete_captured_key", + "input": { "generation": 1 }, + "expected": { + "deleted_key": "fixture/sha256-ba7816bf/gen-1", + "deleted": true, + "generation_2_key_present": true, + "generation_2_reference_count": 1, + "content_id_unchanged": true + }, + "engine_support": { + "d1": "delete-captured-key-after-fence", + "r2": "plain-delete-captured-never-reused-key-after-fence", + "redb": "authority-then-plain-delete-captured-key", + "turso": "authority-then-plain-delete-captured-key" + } + }, + { + "id": "blob_get", + "input": {}, + "expected": { "bytes_hex": "616263", "generation": 2, "lifecycle": "Live" }, + "engine_support": { "d1": "supported", "r2": "supported", "redb": "supported", "turso": "supported" } + } + ] +} diff --git a/pkgs/id/benchmarks/result-v1.schema.json b/pkgs/id/benchmarks/result-v1.schema.json new file mode 100644 index 0000000000..4a3c944a40 --- /dev/null +++ b/pkgs/id/benchmarks/result-v1.schema.json @@ -0,0 +1,77 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "pkgs/id/benchmarks/result-v1.schema.json", + "title": "id-benchmarks result v1", + "description": "One engine's benchmark result document for the #9133 benchmark contract (S2.1-S2.3, S2.16). Local (redb/Turso laptop) and cloud (D1/R2) evidence follow-ups in benchmark-plan.json both emit this shape; local values are not cloud-comparable, and no result recommends a shard configuration.", + "type": "object", + "required": ["schema_version", "workload_id", "engine", "dataset_digest", "environment", "metrics"], + "additionalProperties": false, + "properties": { + "schema_version": { "const": 1 }, + "workload_id": { "type": "string", "minLength": 1 }, + "engine": { "enum": ["d1", "r2", "redb", "turso"] }, + "dataset_digest": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$" }, + "environment": { + "type": "object", + "required": [ + "runner_version", + "git_revision", + "hardware_model", + "cpu_count", + "memory_bytes", + "os_kernel", + "runtime_versions", + "start_time_utc", + "cache_mode", + "storage_shard_count", + "dataset_digest" + ], + "additionalProperties": false, + "properties": { + "runner_version": { "type": "string", "minLength": 1 }, + "git_revision": { "type": "string", "minLength": 1 }, + "hardware_model": { "type": "string", "minLength": 1 }, + "cpu_count": { "type": "integer", "minimum": 1 }, + "memory_bytes": { "type": "integer", "minimum": 1 }, + "os_kernel": { "type": "string", "minLength": 1 }, + "runtime_versions": { "type": "object" }, + "start_time_utc": { "type": "string", "format": "date-time" }, + "cache_mode": { "enum": ["cold", "warm"] }, + "storage_shard_count": { "enum": [1, 4, 16, 64] }, + "dataset_digest": { "type": "string", "pattern": "^sha256:[0-9a-f]{64}$" } + } + }, + "metrics": { + "type": "object", + "required": ["p50_ms", "p95_ms", "p99_ms", "throughput_ops_s", "error_rate"], + "additionalProperties": false, + "properties": { + "p50_ms": { "type": "number", "minimum": 0 }, + "p95_ms": { "type": "number", "minimum": 0 }, + "p99_ms": { "type": "number", "minimum": 0 }, + "throughput_ops_s": { "type": "number", "minimum": 0 }, + "error_rate": { "type": "number", "minimum": 0, "maximum": 1 }, + "native_billed_units": { "type": "number", "minimum": 0 }, + "durability_rpo": { "type": "string" }, + "replica_lag": { "type": "string" } + } + }, + "raw_samples": { + "type": "array", + "items": { "type": "number", "minimum": 0 } + }, + "correctness": { + "type": "object", + "description": "The workload-oracle summary for the fixture the run used; a result whose correctness block is absent or failing is not evidence.", + "required": ["fixture_digest_verified", "reference_transitions_executed_and_matched", "engine_operation_capability_mappings_checked"], + "additionalProperties": false, + "properties": { + "fixture_digest_verified": { "type": "boolean" }, + "reference_transitions_executed_and_matched": { "type": "integer", "minimum": 0 }, + "engine_operation_capability_mappings_checked": { "type": "integer", "minimum": 0 }, + "timings_measured": { "type": "boolean" }, + "provider_calls": { "type": "integer", "minimum": 0 } + } + } + } +} diff --git a/pkgs/id/benchmarks/src/lib.rs b/pkgs/id/benchmarks/src/lib.rs new file mode 100644 index 0000000000..0b6a022828 --- /dev/null +++ b/pkgs/id/benchmarks/src/lib.rs @@ -0,0 +1,353 @@ +//! Reference store + generation-key model for the #9133 benchmark +//! contract (slice C9133-01, issue #10153). +//! +//! This is a direct Rust port of the design's Python reference oracle +//! (`doc/2026-11-13T03-40-00Z_design_id-atlas-summit/part-c/benchmark-workload-oracle.py`): +//! a finite, timer-free, provider-free model whose transitions the +//! synthetic workload fixture pins row-by-row. It is a specification +//! model for benchmark adapters, not a production store. + +use serde_json::{json, Value}; +use sha2::{Digest, Sha256}; +use std::collections::{BTreeMap, HashMap, HashSet}; + +pub const ENGINES: [&str; 4] = ["d1", "r2", "redb", "turso"]; + +/// Canonical fixture content identity: `sha256:` + hex of the exact bytes. +pub fn content_id(bytes: &[u8]) -> String { + format!("sha256:{}", hex::encode(Sha256::digest(bytes))) +} + +/// Test-only key profile; the property tested is uniqueness/non-reuse, +/// not a production object-key encoding recommendation. +pub fn physical_key(content_id: &str, generation: u64) -> String { + let short = &content_id.split(':').nth(1).expect("content id shape")[..8]; + format!("fixture/sha256-{short}/gen-{generation}") +} + +/// Engine capability mapping for one plan cell, mirroring the Python +/// oracle's `support_level` exactly (same text probes, same order). +pub fn support_level(op_id: &str, engine: &str, cell: &str) -> String { + let text = cell.to_lowercase().replace('-', " "); + if op_id == "metadata_scan" && engine == "r2" { + return if text.contains("otherwise unsupported") { + "unsupported" + } else { + "supported" + } + .to_string(); + } + if (op_id == "ref_commit_if_live" || op_id == "ref_remove") && engine == "r2" { + return if text.contains("external transactional authority") { + "external-authority-required" + } else { + "supported" + } + .to_string(); + } + if op_id == "object_tombstone_delete" { + if engine == "r2" { + return if text.contains("external authoritative fence") { + "external-authority-fence-required" + } else { + "unsupported" + } + .to_string(); + } + return if text.contains("authority transaction only") { + "authority-fence-only" + } else { + "unsupported" + } + .to_string(); + } + if op_id == "object_delete_captured_key" { + if engine == "r2" { + return if text.contains("plain deleteobject on captured never reused key") { + "plain-delete-captured-never-reused-key-after-fence" + } else { + "unsupported" + } + .to_string(); + } + if engine == "d1" { + return if text.contains("delete captured generation row") { + "delete-captured-key-after-fence" + } else { + "unsupported" + } + .to_string(); + } + return if text.contains("authority fence then external plain delete") + && text.contains("never reused") + { + "authority-then-plain-delete-captured-key" + } else { + "unsupported" + } + .to_string(); + } + if text.contains("unsupported") { + "unsupported".to_string() + } else { + "supported".to_string() + } +} + +#[derive(Clone, Copy, PartialEq, Eq, Debug)] +enum Lifecycle { + Live, + Tombstoned, +} + +impl Lifecycle { + fn as_str(&self) -> &'static str { + match self { + Lifecycle::Live => "Live", + Lifecycle::Tombstoned => "Tombstoned", + } + } +} + +#[derive(Clone)] +struct Generation { + lifecycle: Lifecycle, + refs: HashSet, + row_revision: u64, + key: String, +} + +struct Row { + bytes: Vec, + metadata: Value, + current: u64, + generations: BTreeMap, +} + +/// The finite reference store. All operations return the observed +/// transition as a JSON object in exactly the fixture's shape. +#[derive(Default)] +pub struct ReferenceStore { + rows: HashMap, + physical: HashMap>, + ever_used_keys: HashSet, +} + +impl ReferenceStore { + pub fn new() -> Self { + Self::default() + } + + fn expected_id(fixture: &Value) -> &str { + fixture["expected_content_id"].as_str().expect("fixture id") + } + + pub fn execute(&mut self, op_id: &str, args: &Value, fixture: &Value) -> Value { + match op_id { + "blob_put_if_absent" => self.put(args, fixture), + "blob_get" => { + let row = &self.rows[Self::expected_id(fixture)]; + let generation = row.current; + let gen = &row.generations[&generation]; + json!({ + "bytes_hex": hex::encode(&self.physical[&gen.key]), + "generation": generation, + "lifecycle": gen.lifecycle.as_str(), + }) + } + "metadata_lookup" => { + let row = &self.rows[Self::expected_id(fixture)]; + json!({"metadata": row.metadata, "generation": row.current}) + } + "metadata_scan" => { + let prefix = args["prefix"].as_str().expect("prefix"); + let mut ids: Vec<&String> = self + .rows + .iter() + .filter(|(cid, row)| { + row.generations[&row.current].lifecycle == Lifecycle::Live + && cid.starts_with(prefix) + && fixture["tenant"] == "tenant-a" + }) + .map(|(cid, _)| cid) + .collect(); + ids.sort(); + json!({"content_ids": ids}) + } + "ref_commit_if_live" => { + let row = self + .rows + .get_mut(Self::expected_id(fixture)) + .expect("row exists"); + let generation = args["generation"].as_u64().expect("generation"); + match row.generations.get_mut(&generation) { + Some(gen) if gen.lifecycle == Lifecycle::Live => { + gen.refs + .insert(args["reference"].as_str().expect("reference").to_string()); + json!({ + "accepted": true, + "generation": generation, + "reference_count": gen.refs.len(), + }) + } + _ => json!({"accepted": false, "reason": "generation-fenced"}), + } + } + "ref_remove" => { + let row = self + .rows + .get_mut(Self::expected_id(fixture)) + .expect("row exists"); + let generation = args["generation"].as_u64().expect("generation"); + let gen = row + .generations + .get_mut(&generation) + .expect("generation exists"); + let reference = args["reference"].as_str().expect("reference"); + let removed = gen.refs.remove(reference); + json!({"removed": removed, "reference_count": gen.refs.len()}) + } + "object_tombstone_delete" => { + let row = self + .rows + .get_mut(Self::expected_id(fixture)) + .expect("row exists"); + let generation = args["generation"].as_u64().expect("generation"); + let gen = row + .generations + .get_mut(&generation) + .expect("generation exists"); + if !gen.refs.is_empty() { + json!({ + "tombstoned": false, + "reason": "references-present", + "lifecycle": gen.lifecycle.as_str(), + }) + } else { + gen.lifecycle = Lifecycle::Tombstoned; + json!({ + "tombstoned": true, + "generation": generation, + "physical_key": gen.key, + "lifecycle": "Tombstoned", + }) + } + } + "object_delete_captured_key" => { + let id = Self::expected_id(fixture).to_string(); + let row = self.rows.get_mut(&id).expect("row exists"); + let generation = args["generation"].as_u64().expect("generation"); + let gen = &row.generations[&generation]; + assert_eq!( + gen.lifecycle, + Lifecycle::Tombstoned, + "delete before authoritative fence" + ); + let key = gen.key.clone(); + assert!(self.ever_used_keys.contains(&key)); + assert!(row + .generations + .iter() + .all(|(n, other)| *n == generation || other.key != key)); + let deleted = self.physical.remove(&key).is_some(); + let current = row.current; + let current_gen = &row.generations[¤t]; + json!({ + "deleted_key": key, + "deleted": deleted, + "generation_2_key_present": current == 2 && self.physical.contains_key(¤t_gen.key), + "generation_2_reference_count": current_gen.refs.len(), + "content_id_unchanged": id == content_id(&row.bytes), + }) + } + other => panic!("no reference model for {other}"), + } + } + + fn put(&mut self, args: &Value, fixture: &Value) -> Value { + let raw = hex::decode(args["bytes_hex"].as_str().expect("bytes_hex")).expect("hex"); + let cid = content_id(&raw); + assert_eq!( + cid, + fixture["expected_content_id"].as_str().expect("fixture id"), + "fixture digest mismatch" + ); + if let Some(prior) = self.rows.get_mut(&cid) { + let current = prior.current; + let cur_lifecycle = prior.generations[¤t].lifecycle; + if args.get("resurrection").and_then(Value::as_bool) == Some(true) { + assert_eq!(cur_lifecycle, Lifecycle::Tombstoned); + assert_eq!( + prior.bytes, raw, + "resurrection must preserve canonical content identity" + ); + let generation = current + 1; + let key = physical_key(&cid, generation); + assert!( + !self.ever_used_keys.contains(&key), + "physical generation key reused" + ); + prior.generations.insert( + generation, + Generation { + lifecycle: Lifecycle::Live, + refs: HashSet::new(), + row_revision: 1, + key: key.clone(), + }, + ); + prior.current = generation; + self.physical.insert(key.clone(), raw); + self.ever_used_keys.insert(key.clone()); + return json!({ + "accepted": true, "created": true, "generation": generation, + "physical_key": key, "lifecycle": "Live", "row_revision": 1, + "content_id": cid, + }); + } + let gen = &prior.generations[¤t]; + if gen.lifecycle == Lifecycle::Tombstoned { + return json!({ + "accepted": false, "created": false, "generation": current, + "lifecycle": "Tombstoned", "reason": "explicit-resurrection-required", + }); + } + assert_eq!(prior.bytes, raw); + assert_eq!(prior.metadata, args["metadata"]); + return json!({ + "accepted": true, "created": false, "generation": current, + "lifecycle": "Live", "reference_count": gen.refs.len(), + "row_revision": gen.row_revision, + }); + } + let generation = 1; + let key = physical_key(&cid, generation); + assert!(!self.ever_used_keys.contains(&key)); + let mut generations = BTreeMap::new(); + generations.insert( + generation, + Generation { + lifecycle: Lifecycle::Live, + refs: HashSet::new(), + row_revision: 1, + key: key.clone(), + }, + ); + self.rows.insert( + cid.clone(), + Row { + bytes: raw.clone(), + metadata: args["metadata"].clone(), + current: generation, + generations, + }, + ); + self.physical.insert(key.clone(), raw); + self.ever_used_keys.insert(key.clone()); + json!({ + "accepted": true, "created": true, "generation": generation, + "physical_key": key, "lifecycle": "Live", "row_revision": 1, + "content_id": cid, + }) + } +} diff --git a/pkgs/id/benchmarks/tests/workload_oracle.rs b/pkgs/id/benchmarks/tests/workload_oracle.rs new file mode 100644 index 0000000000..0e233beb03 --- /dev/null +++ b/pkgs/id/benchmarks/tests/workload_oracle.rs @@ -0,0 +1,170 @@ +//! Reference oracle for the #9133 benchmark contract (C9133-01): +//! executes the synthetic workload fixture against the finite +//! reference store in `id_benchmarks` and compares every transition +//! and every engine capability mapping row-by-row, exactly as the +//! design's Python oracle (benchmark-workload-oracle.py) does. +//! No timings, no provider calls. +//! +//! Oracle: the fixture + plan are the specification; the reference +//! store is the model under test. Digest is recomputed from the +//! fixture's exact bytes (SHA-256 of the put payload). + +use id_benchmarks::{content_id, support_level, ReferenceStore, ENGINES}; +use serde_json::Value; +use std::collections::BTreeMap; +use std::path::PathBuf; + +fn crate_root() -> PathBuf { + PathBuf::from(env!("CARGO_MANIFEST_DIR")) +} + +fn design_dir() -> PathBuf { + crate_root() + .join("../../../doc/2026-11-13T03-40-00Z_design_id-atlas-summit/part-c") + .canonicalize() + .expect("design part-c dir exists") +} + +fn read_json(path: &PathBuf) -> Value { + serde_json::from_str(&std::fs::read_to_string(path).expect("read json")).expect("parse json") +} + +#[test] +fn workload_oracle() { + // The crate's fixture copy must be byte-identical to the design's + // owned fixture, so the two can never drift apart silently. + let fixture_bytes = std::fs::read(crate_root().join("fixtures/synthetic-workload.json")) + .expect("crate fixture"); + let design_fixture_bytes = + std::fs::read(design_dir().join("synthetic-workload.json")).expect("design fixture"); + assert_eq!( + fixture_bytes, design_fixture_bytes, + "fixture copy drifted from the design fixture" + ); + + let fixture: Value = serde_json::from_slice(&fixture_bytes).expect("parse fixture"); + let plan = read_json(&design_dir().join("benchmark-plan.json")); + assert_eq!(fixture["format"], "id-atlas-synthetic-workload/v3"); + + let plan_ops: BTreeMap = plan["logical_operations"] + .as_array() + .expect("plan ops") + .iter() + .map(|row| (row["id"].as_str().expect("op id").to_string(), row.clone())) + .collect(); + for (op_id, row) in &plan_ops { + for engine in ENGINES { + let cell = row.get(engine).and_then(Value::as_str); + assert!( + matches!(cell, Some(s) if !s.is_empty()), + "plan cell {op_id}/{engine}" + ); + } + } + + // Fixture digest, recomputed from the fixture's exact put bytes. + let first = &fixture["operations"][0]; + let raw = hex::decode(first["input"]["bytes_hex"].as_str().expect("bytes_hex")).expect("hex"); + assert_eq!( + content_id(&raw), + fixture["expected_content_id"], + "fixture digest mismatch" + ); + + let mut store = ReferenceStore::new(); + let mut executed = 0usize; + for step in fixture["operations"].as_array().expect("operations") { + let op_id = step["id"].as_str().expect("step id"); + let row = plan_ops + .get(op_id) + .unwrap_or_else(|| panic!("unmapped operation: {op_id}")); + + // Every engine capability mapping for this operation. + let mut actual_support = serde_json::Map::new(); + for engine in ENGINES { + let cell = row[engine].as_str().expect("plan cell"); + actual_support.insert( + engine.to_string(), + Value::String(support_level(op_id, engine, cell)), + ); + } + assert_eq!( + Value::Object(actual_support), + step["engine_support"], + "engine support mismatch for {op_id}" + ); + + // The transition itself. + let mut observed = store.execute(op_id, &step["input"], &fixture); + if step["expected"].get("content_id").is_none() { + // Mirrors the Python oracle: content_id is only part of the + // observed shape when the fixture step expects it. + observed + .as_object_mut() + .expect("observed object") + .remove("content_id"); + } + assert_eq!( + observed, step["expected"], + "transition mismatch for {op_id}" + ); + executed += 1; + } + + // Summary, mirroring benchmark-workload-oracle-output.txt. + assert_eq!(executed, 16, "reference transitions executed"); + assert_eq!( + executed * ENGINES.len(), + 64, + "engine capability mappings checked" + ); +} + +#[test] +fn result_schema_is_present_and_well_formed() { + let schema = read_json(&crate_root().join("result-v1.schema.json")); + assert_eq!(schema["title"], "id-benchmarks result v1"); + let required: Vec<&str> = schema["required"] + .as_array() + .expect("required list") + .iter() + .filter_map(Value::as_str) + .collect(); + for field in [ + "schema_version", + "engine", + "dataset_digest", + "environment", + "metrics", + ] { + assert!( + required.contains(&field), + "result schema must require {field}" + ); + } + // The environment block carries the plan's environment_fields. + let env_required: Vec<&str> = schema["properties"]["environment"]["required"] + .as_array() + .expect("environment required list") + .iter() + .filter_map(Value::as_str) + .collect(); + for field in [ + "runner_version", + "git_revision", + "hardware_model", + "cpu_count", + "memory_bytes", + "os_kernel", + "runtime_versions", + "start_time_utc", + "cache_mode", + "storage_shard_count", + "dataset_digest", + ] { + assert!( + env_required.contains(&field), + "environment must require {field}" + ); + } +}