Desk wire: any bad fork id is fork_unknown, including the key and campaign the Mind derives from it
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
c64ce59c36
commit
7550514dcf
1 changed files with 35 additions and 2 deletions
|
|
@ -294,10 +294,15 @@ fn project(key: &str, stored: &PipelineDeskAnswer) -> Result<ForkDeskAnswer, Min
|
|||
/// question id, or whose id is over the 200-byte bound, names no fork), a body the shape step
|
||||
/// refused and a reused request id store nothing and have codes of their own; anything else,
|
||||
/// `Unavailable` included, passes through unchanged.
|
||||
/// The Mind's `DeskRequestInvalid` fields that come from the fork id alone.
|
||||
const FORK_FIELDS: [&str; 4] = ["fork", "desk_answer.fork", "desk_answer.key", "desk_answer.campaign"];
|
||||
|
||||
fn door_refusal(refused: MindRefusal) -> DeskResponse {
|
||||
match refused {
|
||||
MindRefusal::MissingReference { .. } | MindRefusal::CampaignMoved { .. } => DeskResponse::NotStored(fork_unknown()),
|
||||
MindRefusal::DeskRequestInvalid { field } if field == "fork" || field == "desk_answer.fork" => DeskResponse::NotStored(fork_unknown()),
|
||||
// Any bad fork id is `fork_unknown`. The Mind derives these four fields from the fork id alone
|
||||
// (the id's shape, its campaign root, the record key built from it), so each one is the fork.
|
||||
MindRefusal::DeskRequestInvalid { field } if FORK_FIELDS.contains(&field.as_str()) => DeskResponse::NotStored(fork_unknown()),
|
||||
MindRefusal::DeskRequestInvalid { field } => DeskResponse::NotStored(body_invalid(&field)),
|
||||
MindRefusal::DeskRequestIdConflict { .. } => {
|
||||
DeskResponse::NotStored(fork_refusal(ForkRefusalCode::RequestIdConflict, "request_id_conflict: this request_id was used for a different body".into()))
|
||||
|
|
@ -924,7 +929,7 @@ mod tests {
|
|||
}
|
||||
assert_eq!(head(&mind), before);
|
||||
// The mapping is by exact field: a field that merely ends in "fork" is a bad body.
|
||||
for field in ["desk_answer.fork", "fork"] {
|
||||
for field in ["desk_answer.fork", "fork", "desk_answer.key", "desk_answer.campaign"] {
|
||||
assert_eq!(not_stored(door_refusal(MindRefusal::DeskRequestInvalid { field: field.into() })).code, ForkRefusalCode::ForkUnknown, "{field}");
|
||||
}
|
||||
for field in ["notfork", "desk_answer.forks", "desk_answer.fork.x", "request"] {
|
||||
|
|
@ -932,6 +937,34 @@ mod tests {
|
|||
}
|
||||
}
|
||||
|
||||
/// Any bad fork id is `fork_unknown`, whichever field the Mind faults: the id's shape, its
|
||||
/// campaign root or the record key built from it. A bad field that is not the fork stays `body_invalid`.
|
||||
#[test]
|
||||
fn every_bad_fork_id_is_unknown_and_other_bad_fields_are_not() {
|
||||
let mut mind = desk();
|
||||
let hash = hash_of(&mind, FORK);
|
||||
let before = head(&mind);
|
||||
let forks = [
|
||||
"", // fork
|
||||
"eureka-state:epic:Q1", // fork: not a question id
|
||||
"eureka-state:question:Q 1", // desk_answer.fork
|
||||
":question:Q1", // desk_answer.campaign
|
||||
"Bad Root:question:Q1", // desk_answer.campaign
|
||||
"a:question:Q1.2", // desk_answer.key
|
||||
"eureka-state:question:Q99", // a well-formed id nothing holds
|
||||
];
|
||||
for fork in forks {
|
||||
let refusal = not_stored(ask(&mut mind, "x", wire(fork, &hash)).0);
|
||||
assert_eq!(refusal, fork_unknown(), "{fork:?}");
|
||||
assert_eq!(head(&mind), before, "{fork:?}");
|
||||
}
|
||||
let bad_choice = ForkAnswerRequest { answer: Some(ForkAnswer { choice: Some(String::new()), note: None }), ..wire(FORK, &hash) };
|
||||
let refusal = not_stored(ask(&mut mind, "x", bad_choice).0);
|
||||
assert_eq!(refusal.code, ForkRefusalCode::BodyInvalid);
|
||||
assert!(refusal.error.contains("desk_answer.choice"), "{refusal:?}");
|
||||
assert_eq!(head(&mind), before);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wire_codes_are_snake_case() {
|
||||
let table = [
|
||||
|
|
|
|||
Loading…
Reference in a new issue