Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/synapse/blob/main/evidence/a1-binary-codec/fixture-generator/src/main.rs # synapse A component of the AienOS ecosystem. Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `synapse / evidence / a1-binary-codec / fixture-generator / src / main.rs` 76 lines ยท 5322 bytes Raw Blame History 1 //! Writes legacy v1 (JSON) stores with the merged main-branch synapse-store, for ADR 0003 A1 fixtures. 2 use `ed25519`_dalek::SigningKey; 3 use std::path::Path; 4 use synapse_core::*; 5 use synapse_store::*; 6 7 fn cs(key: &SigningKey, label: &str, path: &str, content: &[u8], parents: Vec, extra_delete: bool, receipts: bool) -> (ChangesetEnvelope, Vec<(BlobDigest, Vec)>) { 8 let digest = BlobDigest::compute(content); 9 let mut mutations = vec![PathMutation { path: path.to_string(), op: MutationOp::Upsert { mode: FileMode::Executable755, blob_digest: digest, size_bytes: content.len() as u64 } }]; 10 if extra_delete { 11 mutations.push(PathMutation { path: format!("{path}.old"), op: MutationOp::Delete }); 12 } 13 let mut env = ChangesetEnvelope { 14 version: SYNAPSE_ENVELOPE_VERSION, 15 repo_id: RepoId::new("aien-spark/synapse").unwrap(), 16 base_git_oid: GitOid::compute_blob(b"a1 fixture base"), 17 parent_changesets: parents, 18 author_did: String::new(), 19 idempotency_key: IdempotencyKey::from_label(label), 20 created_at_ms: 1_000, 21 intent_summary: format!("A1 fixture {label}: \u{e9}t\u{e9} \u{1F980} \"quoted\" \\ back"), 22 mutations, 23 evidence_receipts: if receipts { vec![EvidenceAttachment { gate_name: "cargo-test".into(), passed: true, artifact_digest: [7u8; 32], summary: "ok\nline2".into() }] } else { vec![] }, 24 signature: vec![], 25 }; 26 env.sign(key); 27 (env, vec![(digest, content.to_vec())]) 28 } 29 30 fn id(o: IngestOutcome) -> ChangesetId { 31 match o { IngestOutcome::Committed { changeset_id, .. } => changeset_id, IngestOutcome::IdempotentDuplicate { changeset_id, .. } => changeset_id } 32 } 33 34 fn all_kinds(store: &mut SynapseStore, key: &SigningKey, tag: &str, parent: Option) -> ChangesetId { 35 let (e1, b1) = cs(key, &format!("{tag}-1"), &format!("src/{tag}/a.rs"), format!("fn {tag}() {{}}\n").as_bytes(), parent.into_iter().collect(), false, false); 36 let c1 = id(store.ingest_changeset(e1, &b1).unwrap()); 37 let (e2, b2) = cs(key, &format!("{tag}-2"), &format!("src/{tag}/b.rs"), b"\x00\xffbinary", vec![c1], true, true); 38 let c2 = id(store.ingest_changeset(e2, &b2).unwrap()); 39 store.attach_evaluation(c2, EvidenceAttachment { gate_name: "clippy".into(), passed: false, artifact_digest: [9u8; 32], summary: String::new() }).unwrap(); 40 store.record_review(c2, ReviewRecord { reviewer_did: "did:key:z6MkReviewerA1".into(), approved: true, comment: "lgtm \u{2713}".into(), recorded_at_ms: u64::MAX }).unwrap(); 41 store.record_github_projection(GitHubPullRequestProjection { repo_id: RepoId::new("aien-spark/synapse").unwrap(), pr_number: 22, changeset_id: c2, head_git_oid: GitOid::compute_blob(b"head"), base_git_oid: GitOid::ZERO, pr_branch_ref: format!("refs/heads/{tag}"), title: "A1 \u{1F680}".into(), body_markdown: "# body\n\n- item".into(), evidence_summary_digest: [3u8; 32], github_merged: false }).unwrap(); 42 store.record_canonical_promotion(RadicleCanonicalHead { repo_id: RepoId::new("aien-spark/synapse").unwrap(), default_branch: "main".into(), canonical_git_oid: GitOid::compute_blob(b"canon"), promoted_changeset_id: Some(c1), rad_id_commit_oid: GitOid::compute_blob(b"rad"), threshold: 2, verified_delegates: vec!["did:key:a".into(), "did:key:b".into()], verified_at_ms: 5 }).unwrap(); 43 store.record_canonical_promotion(RadicleCanonicalHead { repo_id: RepoId::new("aien-spark/other").unwrap(), default_branch: "trunk".into(), canonical_git_oid: GitOid::ZERO, promoted_changeset_id: None, rad_id_commit_oid: GitOid::ZERO, threshold: 0, verified_delegates: vec![], verified_at_ms: 0 }).unwrap(); 44 store.update_lease(c1, 9_999_999_999).unwrap(); 45 c2 46 } 47 48 fn write_expect(dir: &Path, store: &SynapseStore) { 49 let root = store.state_root_digest(None).unwrap(); 50 std::fs::write(dir.join("EXPECT"), format!("committed_seq {}\nstate_root {}\nlast_frame_sha256 {}\n", store.committed_seq().0, hex::encode(root), hex::encode(store.last_frame_sha256()))).unwrap(); 51 } 52 53 fn main() { 54 let out = Path::new(&std::env::args().nth(1).expect("out dir")).to_path_buf(); 55 let key = SigningKey::from_bytes(&[0xA1; 32]); 56 // 1. wal.log store: JSON frames, checkpoint.v1 (retention keeps everything), then JSON frames after it. 57 let d1 = out.join("v1-wal-log"); 58 let _ = std::fs::remove_dir_all(&d1); 59 { 60 let limits = StoreLimits { default_retention_window_ms: u64::MAX, ..Default::default() }; 61 let mut s = SynapseStore::open(&d1, FsyncPolicy::EveryCommit, RecoveryPolicy::StrictFailClosed, limits).unwrap(); 62 let last = all_kinds(&mut s, &key, "pre", None); 63 s.checkpoint_and_compact(2_000).unwrap(); 64 all_kinds(&mut s, &key, "post", Some(last)); 65 write_expect(&d1, &s); 66 } 67 // 2. wal.v2.log store (group commit): JSON metadata with inline blobs, small preallocation. 68 let d2 = out.join("v1-wal-v2-log"); 69 let _ = std::fs::remove_dir_all(&d2); 70 { 71 let limits = StoreLimits { default_retention_window_ms: u64::MAX, wal_prealloc_bytes: 64 * 1024, ..Default::default() }; 72 let mut s = SynapseStore::open(&d2, FsyncPolicy::GROUP_COMMIT_DEFAULT, RecoveryPolicy::StrictFailClosed, limits).unwrap(); 73 all_kinds(&mut s, &key, "gc", None); 74 write_expect(&d2, &s); 75 } 76 }