persona-delta-verbs: fix Soul s1 findings (privacy case, bond validation, expiry, mutant tests)
This commit is contained in:
parent
b71da261d5
commit
98b45d083e
2 changed files with 255 additions and 17 deletions
|
|
@ -611,14 +611,16 @@ fn build_target(
|
|||
Ok(target)
|
||||
}
|
||||
|
||||
fn is_private_tag(tag: &str) -> bool {
|
||||
let lower = tag.trim().to_ascii_lowercase();
|
||||
lower == "private" || lower.starts_with("room:!")
|
||||
}
|
||||
|
||||
fn validate_public_tags(tags: &[String]) -> Result<Vec<String>, Trouble> {
|
||||
let mut out = Vec::with_capacity(tags.len());
|
||||
for raw in tags {
|
||||
let tag = require_non_empty("--tag", raw)?;
|
||||
if tag.eq_ignore_ascii_case("private")
|
||||
|| tag.strip_prefix("room:").is_some_and(|room| room.starts_with('!'))
|
||||
|| tag.to_ascii_lowercase().starts_with("room:!")
|
||||
{
|
||||
if is_private_tag(&tag) {
|
||||
return Err(Trouble::invalid(format!("tag `{tag}` is forbidden on public-Matrix persona entries")));
|
||||
}
|
||||
out.push(tag);
|
||||
|
|
@ -851,6 +853,9 @@ fn bond_update(
|
|||
}
|
||||
let summary = args.summary.as_deref().map(|s| require_non_empty("--summary", s)).transpose()?;
|
||||
let why = args.why.as_deref().map(|s| require_non_empty("--why", s)).transpose()?;
|
||||
if why.is_some() && summary.is_none() {
|
||||
return Err(Trouble::invalid("--why requires --summary"));
|
||||
}
|
||||
let trust = args.trust.as_deref().map(|s| parse_bound_or_delta("--trust", s)).transpose()?;
|
||||
let tension = args.tension.as_deref().map(|s| parse_bound_or_delta("--tension", s)).transpose()?;
|
||||
let intensity = args.intensity.as_deref().map(|s| parse_bound_or_delta("--intensity", s)).transpose()?;
|
||||
|
|
@ -952,6 +957,9 @@ fn bond_update(
|
|||
let new_summary = summary
|
||||
.as_ref()
|
||||
.ok_or_else(|| Trouble::invalid("--summary is required when creating a new bond"))?;
|
||||
if custom_kind.is_some() && kind.as_deref() != Some("custom") {
|
||||
return Err(Trouble::invalid("--custom-kind requires --kind custom when creating a new bond"));
|
||||
}
|
||||
let rel_kind = kind.as_deref().unwrap_or("unknown");
|
||||
if rel_kind == "custom" && custom_kind.is_none() {
|
||||
return Err(Trouble::invalid("--custom-kind is required when --kind is custom"));
|
||||
|
|
@ -1161,9 +1169,11 @@ fn intention_add(
|
|||
})
|
||||
.transpose()?;
|
||||
let actions = array_mut(state, &["candidateActions", "actions"])?;
|
||||
let now = Utc::now();
|
||||
if actions.iter().any(|action| {
|
||||
is_intention(action)
|
||||
&& action.get("status").and_then(Value::as_str) == Some("active")
|
||||
&& !is_expired_action(action, now)
|
||||
&& normalized_words(action.get("summary").and_then(Value::as_str).unwrap_or_default()) == wanted_words
|
||||
}) {
|
||||
return Err(Trouble::invalid("an active intention with the same summary already exists"));
|
||||
|
|
@ -1233,16 +1243,18 @@ fn intention_drop(
|
|||
|
||||
/// Legacy Persona State Standard privacy predicate (`select.rs:1818-1831`):
|
||||
/// true when `extensions.privacy == "private"`, a `"private"` tag is present,
|
||||
/// or any tag starts with `"room:!"` (DM room).
|
||||
/// or any tag starts with `"room:!"` (DM room), matched ASCII case-insensitively after trimming.
|
||||
pub(crate) fn is_private_entry(item: &Value) -> bool {
|
||||
if item.pointer("/extensions/privacy").and_then(Value::as_str).map(str::trim) == Some("private") {
|
||||
if item
|
||||
.pointer("/extensions/privacy")
|
||||
.and_then(Value::as_str)
|
||||
.is_some_and(|privacy| privacy.trim().eq_ignore_ascii_case("private"))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
item.get("tags").and_then(Value::as_array).is_some_and(|tags| {
|
||||
tags.iter().filter_map(Value::as_str).map(str::trim).any(|tag| {
|
||||
tag == "private" || tag.strip_prefix("room:").is_some_and(|room| room.starts_with('!'))
|
||||
})
|
||||
})
|
||||
item.get("tags")
|
||||
.and_then(Value::as_array)
|
||||
.is_some_and(|tags| tags.iter().filter_map(Value::as_str).any(is_private_tag))
|
||||
}
|
||||
|
||||
fn is_live_entry(item: &Value) -> bool {
|
||||
|
|
@ -1252,6 +1264,15 @@ fn is_live_entry(item: &Value) -> bool {
|
|||
)
|
||||
}
|
||||
|
||||
fn is_expired_action(action: &Value, now: DateTime<Utc>) -> bool {
|
||||
if str_at(action, &["readiness"]) == "expired" {
|
||||
return true;
|
||||
}
|
||||
let expires_at = str_at(action, &["expiresAt"]);
|
||||
!expires_at.is_empty()
|
||||
&& DateTime::parse_from_rfc3339(expires_at).is_ok_and(|at| at.with_timezone(&Utc) <= now)
|
||||
}
|
||||
|
||||
fn persona_seed(settings: &Settings) -> Result<u8, Trouble> {
|
||||
match settings.client()?.persona_get().map_err(Trouble::from)? {
|
||||
HuginnMindResponse::Persona(Some(view)) => {
|
||||
|
|
@ -1345,6 +1366,10 @@ fn render_thought_lines(out: &mut String, heading: &str, items: &[Value]) {
|
|||
}
|
||||
|
||||
pub(crate) fn render_seed(state: &Value, updated_at: &str, receipt_id: &str) -> String {
|
||||
render_seed_at(state, updated_at, receipt_id, Utc::now())
|
||||
}
|
||||
|
||||
fn render_seed_at(state: &Value, updated_at: &str, receipt_id: &str, now: DateTime<Utc>) -> String {
|
||||
let mut out = String::new();
|
||||
let persona_id = str_at(state, &["personaId"]);
|
||||
let public_name = one_line(str_at(state, &["publicName"]));
|
||||
|
|
@ -1589,7 +1614,7 @@ pub(crate) fn render_seed(state: &Value, updated_at: &str, receipt_id: &str) ->
|
|||
// Candidate actions / intentions
|
||||
let actions: Vec<&Value> = slice_at(state, &["candidateActions", "actions"])
|
||||
.iter()
|
||||
.filter(|item| !is_private_entry(item) && is_live_entry(item))
|
||||
.filter(|item| !is_private_entry(item) && is_live_entry(item) && !is_expired_action(item, now))
|
||||
.collect();
|
||||
if !actions.is_empty() {
|
||||
let _ = writeln!(out, "Intentions & Candidate Actions:");
|
||||
|
|
@ -1637,10 +1662,13 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn is_private_entry_matches_persona_state_standard() {
|
||||
assert!(!is_private_entry(&json!({ "id": "m1", "tags": ["about:meta", "room:#swarm:gamecult.org"] })));
|
||||
assert!(!is_private_entry(&json!({ "id": "m1", "tags": ["about:meta", "room:#swarm:gamecult.org", "Room:#swarm:gamecult.org"], "extensions": { "privacy": "public" } })));
|
||||
assert!(is_private_entry(&json!({ "id": "m2", "extensions": { "privacy": "private" } })));
|
||||
assert!(is_private_entry(&json!({ "id": "m2b", "extensions": { "privacy": " Private " } })));
|
||||
assert!(is_private_entry(&json!({ "id": "m3", "tags": ["private"] })));
|
||||
assert!(is_private_entry(&json!({ "id": "m3b", "tags": [" Private "] })));
|
||||
assert!(is_private_entry(&json!({ "id": "m4", "tags": ["room:!abc:gamecult.org"] })));
|
||||
assert!(is_private_entry(&json!({ "id": "m4b", "tags": [" Room:!abc:gamecult.org "] })));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -1680,7 +1708,8 @@ mod tests {
|
|||
{ "id": "mem2", "status": "crystallized", "target": { "kind": "self", "id": "eureka" }, "summary": "SECRET-DM", "tags": ["room:!dm:gamecult.org"] }
|
||||
],
|
||||
"incubation": [
|
||||
{ "id": "inc1", "status": "resolved", "target": { "kind": "self", "id": "eureka" }, "summary": "RESOLVED-INC" }
|
||||
{ "id": "inc1", "status": "resolved", "target": { "kind": "self", "id": "eureka" }, "summary": "RESOLVED-INC" },
|
||||
{ "id": "inc2", "status": "active", "target": { "kind": "self", "id": "eureka" }, "summary": "SECRET-INC-PRIV", "tags": ["Private"] }
|
||||
]
|
||||
},
|
||||
"agencyPressure": {
|
||||
|
|
@ -1730,7 +1759,7 @@ mod tests {
|
|||
for public_text in ["Public description", "Public value", "Public short term", "Public memory", "Public intention", "Public evidence", "Public bond", "Public sense", "curious", "updatedAt 2026-12-06T00:00:00Z receipt mind-commit-1"] {
|
||||
assert!(rendered.contains(public_text), "missing `{public_text}` in:\n{rendered}");
|
||||
}
|
||||
for forbidden in ["SECRET-PRIVATE-NOTE", "SECRET-VALUE", "SECRET-EXT", "RETIRED-ST", "SECRET-DM", "RESOLVED-INC", "SECRET-PRESSURE", "SECRET-EVIDENCE", "SECRET-VOIDBOT", "SECRET-LAST-EV", "SECRET-CLAIM", "SECRET-ACTUATOR"] {
|
||||
for forbidden in ["SECRET-PRIVATE-NOTE", "SECRET-VALUE", "SECRET-EXT", "RETIRED-ST", "SECRET-DM", "RESOLVED-INC", "SECRET-INC-PRIV", "SECRET-PRESSURE", "SECRET-EVIDENCE", "SECRET-VOIDBOT", "SECRET-LAST-EV", "SECRET-CLAIM", "SECRET-ACTUATOR"] {
|
||||
assert!(!rendered.contains(forbidden), "leaked `{forbidden}` in:\n{rendered}");
|
||||
}
|
||||
}
|
||||
|
|
@ -1904,4 +1933,42 @@ mod tests {
|
|||
assert!(!min_rendered.contains(absent), "unexpected `{absent}` in:\n{min_rendered}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn render_seed_at_filters_expired_intentions_at_exact_boundary() {
|
||||
let now = DateTime::parse_from_rfc3339("2026-12-06T12:00:00Z").unwrap().with_timezone(&Utc);
|
||||
let doc = json!({
|
||||
"personaId": "eureka",
|
||||
"publicName": "Eureka",
|
||||
"candidateActions": {
|
||||
"actions": [
|
||||
{
|
||||
"id": "i-live", "status": "active", "actionType": "custom", "customActionType": "intention",
|
||||
"readiness": "ready", "target": { "kind": "self", "id": "eureka" },
|
||||
"summary": "KEEP-FUTURE-INTENTION", "expiresAt": "2026-12-06T12:00:01Z"
|
||||
},
|
||||
{
|
||||
"id": "i-eq", "status": "active", "actionType": "custom", "customActionType": "intention",
|
||||
"readiness": "ready", "target": { "kind": "self", "id": "eureka" },
|
||||
"summary": "HIDE-BOUNDARY-INTENTION", "expiresAt": "2026-12-06T12:00:00Z"
|
||||
},
|
||||
{
|
||||
"id": "i-past", "status": "active", "actionType": "custom", "customActionType": "intention",
|
||||
"readiness": "waiting", "target": { "kind": "self", "id": "eureka" },
|
||||
"summary": "HIDE-PAST-INTENTION", "expiresAt": "2026-12-06T11:59:59Z"
|
||||
},
|
||||
{
|
||||
"id": "i-readiness", "status": "active", "actionType": "custom", "customActionType": "intention",
|
||||
"readiness": "expired", "target": { "kind": "self", "id": "eureka" },
|
||||
"summary": "HIDE-EXPIRED-READINESS", "expiresAt": "2026-12-06T13:00:00Z"
|
||||
}
|
||||
]
|
||||
}
|
||||
});
|
||||
let rendered = render_seed_at(&doc, "2026-12-06T12:00:00Z", "r-exp", now);
|
||||
assert!(rendered.contains("KEEP-FUTURE-INTENTION"), "{rendered}");
|
||||
for hidden in ["HIDE-BOUNDARY-INTENTION", "HIDE-PAST-INTENTION", "HIDE-EXPIRED-READINESS"] {
|
||||
assert!(!rendered.contains(hidden), "expired `{hidden}` leaked in:\n{rendered}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3574,6 +3574,74 @@ fn persona_delta_retries_stale_cas_bounded_and_preserves_identity() {
|
|||
assert!(fail.out.starts_with("Refused PersonaStale"), "{}", fail.out);
|
||||
assert_eq!(stale_puts.load(std::sync::atomic::Ordering::SeqCst), 3);
|
||||
|
||||
// 3b. Non-PersonaStale PersonaPut refusal fails immediately on attempt 1 without retrying.
|
||||
let non_stale_gets = Arc::new(std::sync::atomic::AtomicUsize::new(0));
|
||||
let non_stale_puts = Arc::new(std::sync::atomic::AtomicUsize::new(0));
|
||||
let nsg = Arc::clone(&non_stale_gets);
|
||||
let nsp = Arc::clone(&non_stale_puts);
|
||||
let non_stale = scripted(move |message| {
|
||||
let (_, req) = decode_request(message).unwrap();
|
||||
match req {
|
||||
HuginnMindRequest::PersonaGet { .. } => {
|
||||
nsg.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
|
||||
answer("persona_get", &HuginnMindResponse::Persona(Some(PersonaStateView {
|
||||
value: persona(INSTANCE, "2026-10-10T10:00:00Z"),
|
||||
updated_at: "2026-10-10T10:00:00Z".into(),
|
||||
receipt_id: "r-0".into(),
|
||||
})))
|
||||
}
|
||||
HuginnMindRequest::PersonaPut { .. } => {
|
||||
nsp.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
|
||||
answer("persona_put", &HuginnMindResponse::PersonaPut(PersonaPutOutcome::Refused(
|
||||
MindRefusal::PersonaNotCanonical,
|
||||
)))
|
||||
}
|
||||
other => panic!("unexpected {other:?}"),
|
||||
}
|
||||
});
|
||||
let non_stale_fail = at(
|
||||
non_stale.addr,
|
||||
&["persona", "mood", "set", "--faculty", "Hands", "--agent", "a", "--session", "s", "--feeling", "calm", "--value", "0.5"],
|
||||
None,
|
||||
);
|
||||
assert_eq!(non_stale_fail.code, 1, "{} {}", non_stale_fail.out, non_stale_fail.err);
|
||||
assert!(non_stale_fail.out.starts_with("Refused PersonaNotCanonical"), "{}", non_stale_fail.out);
|
||||
assert_eq!(non_stale_gets.load(std::sync::atomic::Ordering::SeqCst), 1);
|
||||
assert_eq!(non_stale_puts.load(std::sync::atomic::Ordering::SeqCst), 1);
|
||||
|
||||
// 3c. Client-side validate_document gate rejects invalid mutated state before PersonaPut is sent.
|
||||
let validate_puts = Arc::new(std::sync::atomic::AtomicUsize::new(0));
|
||||
let vp = Arc::clone(&validate_puts);
|
||||
let invalid_stored = scripted(move |message| {
|
||||
let (_, req) = decode_request(message).unwrap();
|
||||
match req {
|
||||
HuginnMindRequest::PersonaGet { .. } => {
|
||||
let mut doc = persona(INSTANCE, "2026-10-10T10:00:00Z");
|
||||
doc["provenance"]["authority"] = json!("imported");
|
||||
answer("persona_get", &HuginnMindResponse::Persona(Some(PersonaStateView {
|
||||
value: doc,
|
||||
updated_at: "2026-10-10T10:00:00Z".into(),
|
||||
receipt_id: "r-0".into(),
|
||||
})))
|
||||
}
|
||||
HuginnMindRequest::PersonaPut { .. } => {
|
||||
vp.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
|
||||
answer("persona_put", &HuginnMindResponse::PersonaPut(PersonaPutOutcome::Committed {
|
||||
receipt_id: "mind-commit-should-not-happen".into(),
|
||||
}))
|
||||
}
|
||||
other => panic!("unexpected {other:?}"),
|
||||
}
|
||||
});
|
||||
let invalid_gate = at(
|
||||
invalid_stored.addr,
|
||||
&["persona", "mood", "set", "--faculty", "Hands", "--agent", "a", "--session", "s", "--feeling", "calm", "--value", "0.5"],
|
||||
None,
|
||||
);
|
||||
assert_eq!(invalid_gate.code, 2, "{} {}", invalid_gate.out, invalid_gate.err);
|
||||
assert!(invalid_gate.err.starts_with("InvalidInput: "), "{}", invalid_gate.err);
|
||||
assert_eq!(validate_puts.load(std::sync::atomic::Ordering::SeqCst), 0);
|
||||
|
||||
// 3. Unavailable exits 3 without retry; absent exits 1.
|
||||
let unavail = at(
|
||||
closed_port(),
|
||||
|
|
@ -3657,10 +3725,13 @@ fn persona_seed_strips_all_legacy_private_markers_without_json() {
|
|||
},
|
||||
"thoughtMemory": {
|
||||
"shortTerm": [
|
||||
{ "id": "st-pub", "status": "active", "target": { "kind": "self", "id": INSTANCE }, "summary": "KEEP-PUBLIC-ST", "tension": "", "actionImplication": "", "createdAt": "2026-10-10T10:00:00Z", "updatedAt": "2026-10-10T10:00:00Z", "tags": ["room:#swarm:gamecult.org"] },
|
||||
{ "id": "st-pub", "status": "active", "target": { "kind": "self", "id": INSTANCE }, "summary": "KEEP-PUBLIC-ST", "tension": "", "actionImplication": "", "createdAt": "2026-10-10T10:00:00Z", "updatedAt": "2026-10-10T10:00:00Z", "tags": ["Room:#swarm:gamecult.org"], "extensions": { "privacy": "public" } },
|
||||
{ "id": "st-ext", "status": "active", "target": { "kind": "self", "id": INSTANCE }, "summary": "LEAK-ST-EXT", "tension": "", "actionImplication": "", "createdAt": "2026-10-10T10:00:00Z", "updatedAt": "2026-10-10T10:00:00Z", "extensions": { "privacy": "private" } },
|
||||
{ "id": "st-ext-case", "status": "active", "target": { "kind": "self", "id": INSTANCE }, "summary": "LEAK-ST-EXT-CASE", "tension": "", "actionImplication": "", "createdAt": "2026-10-10T10:00:00Z", "updatedAt": "2026-10-10T10:00:00Z", "extensions": { "privacy": " Private " } },
|
||||
{ "id": "st-tag", "status": "active", "target": { "kind": "self", "id": INSTANCE }, "summary": "LEAK-ST-TAG", "tension": "", "actionImplication": "", "createdAt": "2026-10-10T10:00:00Z", "updatedAt": "2026-10-10T10:00:00Z", "tags": ["private"] },
|
||||
{ "id": "st-tag-case", "status": "active", "target": { "kind": "self", "id": INSTANCE }, "summary": "LEAK-ST-TAG-CASE", "tension": "", "actionImplication": "", "createdAt": "2026-10-10T10:00:00Z", "updatedAt": "2026-10-10T10:00:00Z", "tags": ["Private"] },
|
||||
{ "id": "st-dm", "status": "active", "target": { "kind": "self", "id": INSTANCE }, "summary": "LEAK-ST-DM", "tension": "", "actionImplication": "", "createdAt": "2026-10-10T10:00:00Z", "updatedAt": "2026-10-10T10:00:00Z", "tags": ["room:!dm123:gamecult.org"] },
|
||||
{ "id": "st-dm-case", "status": "active", "target": { "kind": "self", "id": INSTANCE }, "summary": "LEAK-ST-DM-CASE", "tension": "", "actionImplication": "", "createdAt": "2026-10-10T10:00:00Z", "updatedAt": "2026-10-10T10:00:00Z", "tags": [" Room:!abc:gamecult.org "] },
|
||||
{ "id": "st-ret", "status": "retired", "target": { "kind": "self", "id": INSTANCE }, "summary": "LEAK-ST-RETIRED", "tension": "", "actionImplication": "", "createdAt": "2026-10-10T10:00:00Z", "updatedAt": "2026-10-10T10:00:00Z" }
|
||||
],
|
||||
"memories": [
|
||||
|
|
@ -3669,6 +3740,7 @@ fn persona_seed_strips_all_legacy_private_markers_without_json() {
|
|||
],
|
||||
"incubation": [
|
||||
{ "id": "w-pub", "status": "active", "target": { "kind": "self", "id": INSTANCE }, "summary": "KEEP-PUBLIC-INC", "tension": "", "actionImplication": "", "createdAt": "2026-10-10T10:00:00Z", "updatedAt": "2026-10-10T10:00:00Z" },
|
||||
{ "id": "w-priv", "status": "active", "target": { "kind": "self", "id": INSTANCE }, "summary": "LEAK-INC-PRIVATE", "tension": "", "actionImplication": "", "createdAt": "2026-10-10T10:00:00Z", "updatedAt": "2026-10-10T10:00:00Z", "extensions": { "privacy": "Private" } },
|
||||
{ "id": "w-res", "status": "resolved", "target": { "kind": "self", "id": INSTANCE }, "summary": "LEAK-INC-RESOLVED", "tension": "", "actionImplication": "", "createdAt": "2026-10-10T10:00:00Z", "updatedAt": "2026-10-10T10:00:00Z" }
|
||||
]
|
||||
},
|
||||
|
|
@ -3781,10 +3853,14 @@ fn persona_seed_strips_all_legacy_private_markers_without_json() {
|
|||
for leaked in [
|
||||
"LEAK-PRIVATE-NOTE",
|
||||
"LEAK-ST-EXT",
|
||||
"LEAK-ST-EXT-CASE",
|
||||
"LEAK-ST-TAG",
|
||||
"LEAK-ST-TAG-CASE",
|
||||
"LEAK-ST-DM",
|
||||
"LEAK-ST-DM-CASE",
|
||||
"LEAK-ST-RETIRED",
|
||||
"LEAK-MEM-DM",
|
||||
"LEAK-INC-PRIVATE",
|
||||
"LEAK-INC-RESOLVED",
|
||||
"LEAK-PRESSURE",
|
||||
"LEAK-ACTION-EVIDENCE",
|
||||
|
|
@ -3839,6 +3915,8 @@ fn persona_deltas_reject_private_tags_and_bad_bounds_before_wire() {
|
|||
&["persona", "mood", "set", "--faculty", "Hands", "--agent", "a", "--session", "s", "--clear-feeling", "calm", "--mean", "0.5"],
|
||||
&["persona", "mood", "set", "--faculty", "Hands", "--agent", "a", "--session", "s", "--clear-feeling", "calm", "--plasticity", "0.5"],
|
||||
&["persona", "bond", "update", "--faculty", "Hands", "--agent", "a", "--session", "s", "--person", "meta"],
|
||||
&["persona", "bond", "update", "--faculty", "Hands", "--agent", "a", "--session", "s", "--person", "meta", "--why", "missing summary"],
|
||||
&["persona", "bond", "update", "--faculty", "Hands", "--agent", "a", "--session", "s", "--person", "meta", "--trust", "+0.1", "--why", "missing summary"],
|
||||
&["persona", "bond", "update", "--faculty", "Hands", "--agent", "a", "--session", "s", "--person", "meta", "--trust", "1.5", "--summary", "x"],
|
||||
&["persona", "bond", "update", "--faculty", "Hands", "--agent", "a", "--session", "s", "--person", "meta", "--kind", "bogus", "--summary", "x"],
|
||||
&["persona", "bond", "update", "--faculty", "Hands", "--agent", "a", "--session", "s", "--person", "meta", "--status", "bogus", "--summary", "x"],
|
||||
|
|
@ -3854,9 +3932,11 @@ fn persona_deltas_reject_private_tags_and_bad_bounds_before_wire() {
|
|||
}
|
||||
assert!(seen.lock().unwrap().is_empty(), "invalid inputs must not hit the wire: {:?}", *seen.lock().unwrap());
|
||||
|
||||
// Creating a brand-new bond without --summary or --kind custom without --custom-kind exits 2 without sending PersonaPut.
|
||||
// Creating a brand-new bond without --summary, creating with --custom-kind without --kind custom,
|
||||
// or --kind custom without --custom-kind exits 2 without sending PersonaPut.
|
||||
for args in [
|
||||
&["persona", "bond", "update", "--faculty", "Hands", "--agent", "a", "--session", "s", "--person", "stranger", "--trust", "0.6"][..],
|
||||
&["persona", "bond", "update", "--faculty", "Hands", "--agent", "a", "--session", "s", "--person", "stranger", "--custom-kind", "my_custom", "--summary", "x"],
|
||||
&["persona", "bond", "update", "--faculty", "Hands", "--agent", "a", "--session", "s", "--person", "meta", "--kind", "custom", "--summary", "x"],
|
||||
] {
|
||||
let ran = at(spy.addr, args, None);
|
||||
|
|
@ -3864,3 +3944,94 @@ fn persona_deltas_reject_private_tags_and_bad_bounds_before_wire() {
|
|||
}
|
||||
assert!(seen.lock().unwrap().iter().all(|req| matches!(req, HuginnMindRequest::PersonaGet { .. })));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn persona_bond_custom_kind_and_expired_intention_semantics() {
|
||||
let (root, daemon) = mind(vec![]);
|
||||
let server = serve(root, daemon);
|
||||
let mut initial = persona(INSTANCE, "2026-10-10T10:00:00Z");
|
||||
initial["candidateActions"]["actions"] = json!([
|
||||
{
|
||||
"id": "i-past", "status": "active", "actionType": "custom", "customActionType": "intention",
|
||||
"readiness": "ready", "riskLevel": "low", "target": { "kind": "self", "id": INSTANCE },
|
||||
"summary": "Past expiry intention",
|
||||
"createdAt": "2020-01-01T00:00:00Z", "updatedAt": "2020-01-01T00:00:00Z",
|
||||
"expiresAt": "2020-01-02T00:00:00Z"
|
||||
},
|
||||
{
|
||||
"id": "i-readiness-exp", "status": "active", "actionType": "custom", "customActionType": "intention",
|
||||
"readiness": "expired", "riskLevel": "low", "target": { "kind": "self", "id": INSTANCE },
|
||||
"summary": "Readiness expired intention",
|
||||
"createdAt": "2026-10-10T10:00:00Z", "updatedAt": "2026-10-10T10:00:00Z",
|
||||
"expiresAt": "2099-01-01T00:00:00Z"
|
||||
},
|
||||
{
|
||||
"id": "i-future", "status": "active", "actionType": "custom", "customActionType": "intention",
|
||||
"readiness": "waiting", "riskLevel": "low", "target": { "kind": "self", "id": INSTANCE },
|
||||
"summary": "Future active intention",
|
||||
"createdAt": "2026-10-10T10:00:00Z", "updatedAt": "2026-10-10T10:00:00Z",
|
||||
"expiresAt": "2099-01-01T00:00:00Z"
|
||||
}
|
||||
]);
|
||||
seed_persona(server.addr, &initial);
|
||||
|
||||
// Seed hides expired intentions (both past expiresAt and readiness == expired) and keeps future ones.
|
||||
let seed_before = at(server.addr, &["persona", "seed"], None);
|
||||
assert_eq!(seed_before.code, 0, "{} {}", seed_before.out, seed_before.err);
|
||||
assert!(seed_before.out.contains("Future active intention"), "{}", seed_before.out);
|
||||
assert!(!seed_before.out.contains("Past expiry intention"), "{}", seed_before.out);
|
||||
assert!(!seed_before.out.contains("Readiness expired intention"), "{}", seed_before.out);
|
||||
|
||||
// Re-adding an intention whose previous entry expired succeeds; duplicating the unexpired future one still fails exit 2.
|
||||
for summary in ["Past expiry intention", "Readiness expired intention"] {
|
||||
let ok = at(
|
||||
server.addr,
|
||||
&["persona", "intention", "add", "--faculty", "Hands", "--agent", "a", "--session", "s", "--summary", summary],
|
||||
None,
|
||||
);
|
||||
assert_eq!(ok.code, 0, "{summary}: {} {}", ok.out, ok.err);
|
||||
}
|
||||
let dup_future = at(
|
||||
server.addr,
|
||||
&["persona", "intention", "add", "--faculty", "Hands", "--agent", "a", "--session", "s", "--summary", "future active intention"],
|
||||
None,
|
||||
);
|
||||
assert_eq!(dup_future.code, 2, "{} {}", dup_future.out, dup_future.err);
|
||||
assert!(dup_future.err.starts_with("InvalidInput: "), "{}", dup_future.err);
|
||||
|
||||
// Creating a new bond with --custom-kind without --kind custom fails exit 2; with --kind custom it commits and renders in seed.
|
||||
let bad_custom = at(
|
||||
server.addr,
|
||||
&["persona", "bond", "update", "--faculty", "Hands", "--agent", "a", "--session", "s", "--person", "deru", "--custom-kind", "my_custom", "--summary", "Peer"],
|
||||
None,
|
||||
);
|
||||
assert_eq!(bad_custom.code, 2, "{} {}", bad_custom.out, bad_custom.err);
|
||||
assert!(bad_custom.err.starts_with("InvalidInput: "), "{}", bad_custom.err);
|
||||
|
||||
let good_custom = at(
|
||||
server.addr,
|
||||
&["persona", "bond", "update", "--faculty", "Hands", "--agent", "a", "--session", "s", "--person", "deru", "--kind", "custom", "--custom-kind", "my_custom", "--summary", "Peer"],
|
||||
None,
|
||||
);
|
||||
assert_eq!(good_custom.code, 0, "{} {}", good_custom.out, good_custom.err);
|
||||
|
||||
// Updating that bond with --why without --summary fails exit 2 without mutating trust or lastEvidence.
|
||||
let bad_why = at(
|
||||
server.addr,
|
||||
&["persona", "bond", "update", "--faculty", "Hands", "--agent", "a", "--session", "s", "--person", "deru", "--trust", "+0.2", "--why", "Should not silently drop"],
|
||||
None,
|
||||
);
|
||||
assert_eq!(bad_why.code, 2, "{} {}", bad_why.out, bad_why.err);
|
||||
assert!(bad_why.err.starts_with("InvalidInput: "), "{}", bad_why.err);
|
||||
|
||||
let doc_after = fetch_persona_json(server.addr);
|
||||
let deru_bond = doc_after["affect"]["socialBonds"].as_array().unwrap().iter().find(|b| b["object"]["id"] == "deru").unwrap();
|
||||
assert_eq!(deru_bond["relationshipKind"], "custom");
|
||||
assert_eq!(deru_bond["customRelationshipKind"], "my_custom");
|
||||
assert_eq!(deru_bond["trust"], 0.5);
|
||||
assert!(deru_bond.get("lastEvidence").is_none());
|
||||
|
||||
let seed_after = at(server.addr, &["persona", "seed"], None);
|
||||
assert_eq!(seed_after.code, 0, "{} {}", seed_after.out, seed_after.err);
|
||||
assert!(seed_after.out.contains("deru [my_custom]"), "{}", seed_after.out);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue