| 38 | format!("blake3:{}", h.finalize().to_hex()) |
| 39 | } |
| 40 | pub fn create(binary: &Path, root: &Path, config: &Path) -> Result<Fixture> { |
| 41 | let mut repo = Repository::init(root)?; |
| 42 | let working_copy = repo.require_working_copy_id()?; |
| 43 | repo.init_vault()?; |
| 44 | write(root, "base.txt", b"shared base\n")?; |
| 45 | repo.add(working_copy, "base.txt", TrackingOptions::default())?; |
| 46 | repo.record( |
| 47 | working_copy, |
| 48 | ChangeHeader::new("base"), |
| 49 | RecordOptions::new() |
| 50 | .with_all(false) |
| 51 | .paths(vec!["base.txt"]) |
| 52 | .sync_vault(false) |
| 53 | .enrich_kg(false), |
| 54 | )?; |
| 55 | repo.create_draft_view("feature", "dev")?; |
| 56 | drop(repo); |
| 57 | cli(binary, root, config, &["view", "switch", "feature"])?; |
| 58 | let repo = Repository::open_existing(root)?; |
| 59 | let working_copy = repo.require_working_copy_id()?; |
| 60 | let made = repo.vault_intent_create(IntentCreateOptions { |
| 61 | title: "Replicated intent".into(), |
| 62 | priority: None, |
| 63 | assignee: None, |
| 64 | labels: vec![], |
| 65 | session_id: None, |
| 66 | turn_id: None, |
| 67 | kind: None, |
| 68 | })?; |
| 69 | let entry = repo.vault_intent_show(&made.id)?; |
| 70 | let fm: Map<String, Value> = serde_json::from_str(&entry.frontmatter_json)?; |
| 71 | let body = String::from_utf8(entry.content_bytes)?; |
| 72 | let key = KeyPair::generate(); |
| 73 | let identity = Identity::from_public_key("acceptance", key.public.clone()); |
| 74 | let signed = atomic_canonical::proof::attest( |
| 75 | atomic_canonical::lift::lift_intent(&fm, &body)?, |
| 76 | &identity, |
| 77 | &key, |
| 78 | ); |
| 79 | let signed_path = format!( |
| 80 | "attestations/{}/attested.md", |
| 81 | made.id |
| 82 | .chars() |
| 83 | .map(|c| if c.is_ascii_alphanumeric() || c == '-' || c == '_' { |
| 84 | c |
| 85 | } else { |
| 86 | '_' |
| 87 | }) |
| 88 | .collect::<String>() |
| 89 | ); |
| 90 | let hash = source_hash(&fm, &body); |
| 91 | let signed_json = serde_json::to_string_pretty(&signed)?; |
| 92 | repo.vault_store( |
| 93 | &signed_path, |
| 94 | VaultEntryType::Attestation, |
| 95 | signed_json.as_bytes().to_vec(), |
| 96 | json!({"sourceContentHash":hash,"intentId":made.id}).to_string(), |
| 97 | )?; |