fix: bind successful receipt organ contract
Human-Responsibility: ICE-GL∞ / 冰朔 Persona-Author: ICE-P-ZY001 / 铸渊 Execution-Runtime: Codex desktop / DEV-20260810-014 Development-ID: DEV-20260810-014 Authorization-Scope: GH-PNCC persona runtime source and tests only; no UI, deployment, or execution limb Source-Anchor: user instruction to continue GH-PNCC from repository facts and verifiable receipts
This commit is contained in:
parent
47c8fc4751
commit
c58f9c5991
7 changed files with 115 additions and 21 deletions
|
|
@ -183,6 +183,7 @@ successful_receipt_wake_checkpoint_evidence_binding_source_implemented: 100
|
|||
successful_receipt_wake_event_boundary_evidence_binding_source_implemented: 100
|
||||
successful_receipt_wake_runtime_state_evidence_binding_source_implemented: 100
|
||||
successful_receipt_wake_organ_mode_evidence_binding_source_implemented: 100
|
||||
successful_receipt_wake_organ_contract_evidence_binding_source_implemented: 100
|
||||
general_purpose_persona_runtime_implemented: 0
|
||||
human_live_projection_implemented: 0
|
||||
hololake_integrated: 0
|
||||
|
|
|
|||
|
|
@ -2764,29 +2764,35 @@ fn validate_persisted_lifecycle_terminal_evidence(
|
|||
&terminal_event.event_hash[..20]
|
||||
);
|
||||
let first_event = events.first().ok_or("PERSONA_EVENT_CHAIN_EMPTY")?;
|
||||
let wake_manifest =
|
||||
load_manifest_at_git_head(Path::new(&record.repository_path), &first_event.git_head)
|
||||
.map_err(|_| "PERSONA_LIFECYCLE_COMPLETION_EVIDENCE_MISMATCH".to_string())?;
|
||||
if wake_manifest.persona_id != record.persona_id {
|
||||
return Err("PERSONA_LIFECYCLE_COMPLETION_EVIDENCE_MISMATCH".into());
|
||||
}
|
||||
let wake_organ = wake_manifest
|
||||
.organs
|
||||
.iter()
|
||||
.find(|organ| organ.organ_id == record.active_organ)
|
||||
.ok_or("PERSONA_LIFECYCLE_COMPLETION_EVIDENCE_MISMATCH")?;
|
||||
let expected_organ_contract = serde_json::to_value(
|
||||
organ_contract(wake_organ)
|
||||
.map_err(|_| "PERSONA_LIFECYCLE_COMPLETION_EVIDENCE_MISMATCH".to_string())?,
|
||||
)
|
||||
.map_err(|error| format!("PERSONA_LIFECYCLE_EVIDENCE_SERIALIZATION_FAILED: {error}"))?;
|
||||
let expected_brain_entry =
|
||||
repository_file(Path::new(&record.repository_path), &record.brain_entry)
|
||||
.map_err(|_| "PERSONA_LIFECYCLE_COMPLETION_EVIDENCE_MISMATCH".to_string())?;
|
||||
let expected_brain_entry = expected_brain_entry.to_string_lossy();
|
||||
let expected_wake_checkpoint = match record.wake_checkpoint_path.as_ref() {
|
||||
Some(path) => path.clone(),
|
||||
None => {
|
||||
let wake_manifest = load_manifest_at_git_head(
|
||||
Path::new(&record.repository_path),
|
||||
&first_event.git_head,
|
||||
)
|
||||
.map_err(|_| "PERSONA_LIFECYCLE_COMPLETION_EVIDENCE_MISMATCH".to_string())?;
|
||||
if wake_manifest.persona_id != record.persona_id {
|
||||
return Err("PERSONA_LIFECYCLE_COMPLETION_EVIDENCE_MISMATCH".into());
|
||||
}
|
||||
repository_file(
|
||||
Path::new(&record.repository_path),
|
||||
&wake_manifest.current_checkpoint,
|
||||
)
|
||||
.map_err(|_| "PERSONA_LIFECYCLE_COMPLETION_EVIDENCE_MISMATCH".to_string())?
|
||||
.to_string_lossy()
|
||||
.into_owned()
|
||||
}
|
||||
None => repository_file(
|
||||
Path::new(&record.repository_path),
|
||||
&wake_manifest.current_checkpoint,
|
||||
)
|
||||
.map_err(|_| "PERSONA_LIFECYCLE_COMPLETION_EVIDENCE_MISMATCH".to_string())?
|
||||
.to_string_lossy()
|
||||
.into_owned(),
|
||||
};
|
||||
let matches = lifecycle.get("schema").and_then(serde_json::Value::as_str)
|
||||
== Some("hololake.pncc-lifecycle-run-receipt/v1")
|
||||
|
|
@ -2826,6 +2832,7 @@ fn validate_persisted_lifecycle_terminal_evidence(
|
|||
&& wake.get("activeOrgan").and_then(serde_json::Value::as_str)
|
||||
== Some(record.active_organ.as_str())
|
||||
&& wake.get("organMode").and_then(serde_json::Value::as_str) == Some(expected_organ_mode)
|
||||
&& wake.get("organContract") == Some(&expected_organ_contract)
|
||||
&& wake.get("attribution") == Some(&expected_attribution)
|
||||
&& wake.get("receiptId").and_then(serde_json::Value::as_str)
|
||||
== Some(expected_wake_receipt_id.as_str())
|
||||
|
|
@ -4530,6 +4537,50 @@ mod tests {
|
|||
assert!(error.contains("PERSONA_LIFECYCLE_COMPLETION_EVIDENCE_MISMATCH"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rejects_a_rehashed_completed_receipt_with_forged_wake_organ_contract() {
|
||||
let repo = persona_repo();
|
||||
let runtime = tempfile::TempDir::new().unwrap();
|
||||
let input = lifecycle_fact_input(repo.path());
|
||||
let first = run_idempotent_lifecycle_at(
|
||||
runtime.path(),
|
||||
input.clone(),
|
||||
"2026-08-11T00:00:00.000Z",
|
||||
"2026-08-11T00:00:01.000Z",
|
||||
|runtime_root, input, timestamp| {
|
||||
run_fact_task_at(runtime_root, input, timestamp, |_, _| {
|
||||
Ok(r#"{"summary":"Recoverable receipt.","facts":[{"statement":"The brain exists.","evidencePaths":["brain/CORE.hdlp"]}],"limitations":[]}"#.into())
|
||||
})
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
let session_id = first.lifecycle["sessionId"].as_str().unwrap();
|
||||
let mut record = load_session_record(runtime.path(), session_id).unwrap();
|
||||
record.request_id = None;
|
||||
record.request_fingerprint = None;
|
||||
record.lifecycle_receipt_hash = None;
|
||||
write_session_record(runtime.path(), &record).unwrap();
|
||||
|
||||
let receipt_path = session_directory(runtime.path(), session_id)
|
||||
.unwrap()
|
||||
.join("lifecycle-receipt.json");
|
||||
let mut persisted: PersistedPersonaLifecycleReceipt =
|
||||
serde_json::from_slice(&fs::read(&receipt_path).unwrap()).unwrap();
|
||||
persisted.lifecycle["wakeReceipt"]["organContract"]["realityActionsAllowed"] = true.into();
|
||||
persisted.lifecycle["wakeReceipt"]["organContract"]["permissions"] =
|
||||
serde_json::json!(["EXECUTE_REALITY_ACTION"]);
|
||||
persisted.lifecycle_receipt_hash =
|
||||
hex_digest(&persisted_lifecycle_payload_bytes(&persisted).unwrap());
|
||||
fs::write(
|
||||
&receipt_path,
|
||||
serde_json::to_vec_pretty(&persisted).unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
let error = inspect_lifecycle_request_at(runtime.path(), &input).unwrap_err();
|
||||
assert!(error.contains("PERSONA_LIFECYCLE_COMPLETION_EVIDENCE_MISMATCH"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reconstructs_legacy_wake_checkpoint_evidence_from_the_wake_git_head() {
|
||||
let repo = persona_repo();
|
||||
|
|
|
|||
Loading…
Reference in a new issue