WIP (does not build): DraftClass on DraftError; create() call sites take a ModelFamily argument

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Weksa 2026-11-10 14:26:14 +00:00
commit 2259b9f8c3
4 changed files with 78 additions and 16 deletions

View file

@ -47,6 +47,67 @@ pub struct PacketDraft {
pub struct DraftError {
pub line: usize,
pub column: usize,
/// What kind of reading failure, from serde's own fixed vocabulary. It
/// never holds a token of the answer.
pub class: DraftClass,
}
/// Why an answer is not a draft: a closed set of classes, never the offending
/// text, so a record may keep it for a held-out item.
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
pub enum DraftClass {
/// Not JSON.
Syntax,
/// JSON that ends early.
Eof,
MissingField,
UnknownField,
/// A value of the wrong JSON type, such as a bare integer for an id.
InvalidType,
/// A value of the right type that is not one of the field's: a node id
/// spelled `entity:x`, a number out of range.
InvalidValue,
Other,
}
impl DraftClass {
/// The code a round record keeps.
pub fn code(self) -> &'static str {
match self {
DraftClass::Syntax => "syntax",
DraftClass::Eof => "eof",
DraftClass::MissingField => "missing-field",
DraftClass::UnknownField => "unknown-field",
DraftClass::InvalidType => "invalid-type",
DraftClass::InvalidValue => "invalid-value",
DraftClass::Other => "other",
}
}
fn of(e: &serde_json::Error) -> Self {
use serde_json::error::Category;
match e.classify() {
Category::Syntax => DraftClass::Syntax,
Category::Eof => DraftClass::Eof,
Category::Io => DraftClass::Other,
// Only the leading words of serde's message are read, and only to
// pick one of these classes; the message is not kept.
Category::Data => {
let msg = e.to_string();
if msg.starts_with("missing field") {
DraftClass::MissingField
} else if msg.starts_with("unknown field") {
DraftClass::UnknownField
} else if msg.starts_with("invalid type") {
DraftClass::InvalidType
} else if msg.starts_with("invalid value") {
DraftClass::InvalidValue
} else {
DraftClass::Other
}
}
}
}
}
impl fmt::Display for DraftError {
@ -72,6 +133,7 @@ fn from_json<T: DeserializeOwned>(answer: &str) -> Result<T, DraftError> {
serde_json::from_str(answer.trim()).map_err(|e| DraftError {
line: e.line(),
column: e.column(),
class: DraftClass::of(&e),
})
}

View file

@ -2059,7 +2059,7 @@ mod tests {
entities: &entities,
},
"fake-model",
"bag", crate::run::LowererReach::ToolLessRelay,
"bag", crate::run::LowererReach::ToolLessRelay, ModelFamily::Unrecorded
)
.unwrap();
let mut model = fake();

View file

@ -47,7 +47,7 @@ fn a_run_pins_its_stores_and_refuses_drift() {
entities: &e,
},
model,
"bag", weksa::run::LowererReach::ToolLessRelay,
"bag", weksa::run::LowererReach::ToolLessRelay, ModelFamily::Unrecorded
)
};
@ -148,7 +148,7 @@ fn a_run_works_on_its_own_copy_of_the_inventory() {
entities: &e,
},
"fake-model",
"bag", weksa::run::LowererReach::ToolLessRelay,
"bag", weksa::run::LowererReach::ToolLessRelay, ModelFamily::Unrecorded
)
.unwrap();
@ -223,7 +223,7 @@ fn create_refuses_a_root_that_holds_an_inventory_and_never_truncates_it() {
entities: &dao.entities,
},
"fake-model",
"bag", weksa::run::LowererReach::ToolLessRelay,
"bag", weksa::run::LowererReach::ToolLessRelay, ModelFamily::Unrecorded
)
};
@ -268,7 +268,7 @@ fn a_create_that_fails_leaves_no_inventory_and_the_retry_succeeds() {
entities,
},
"fake-model",
"bag", weksa::run::LowererReach::ToolLessRelay,
"bag", weksa::run::LowererReach::ToolLessRelay, ModelFamily::Unrecorded
)
};
// A directory opens for reading and fails mid-copy, after the destination exists.
@ -381,14 +381,14 @@ fn a_store_changed_between_its_digest_and_its_open_is_drift() {
entities: &e,
};
assert_eq!(
RunStores::create_between(&root, "t", paths(), "fake-model", "bag", weksa::run::LowererReach::ToolLessRelay, || more(&mut w)).err(),
RunStores::create_between(&root, "t", paths(), "fake-model", "bag", weksa::run::LowererReach::ToolLessRelay, ModelFamily::Unrecorded, || more(&mut w)).err(),
Some(RunError::Drift(DriftOf::Corpus))
);
assert!(!root.join("inventory.cc").exists());
// Not the copy and not the lock the store's open left beside it.
assert!(!root.join("inventory.cc.lock").exists());
assert_eq!(RunStores::open(&root).err(), Some(RunError::NoRun));
RunStores::create(&root, "t", paths(), "fake-model", "bag", weksa::run::LowererReach::ToolLessRelay).unwrap();
RunStores::create(&root, "t", paths(), "fake-model", "bag", weksa::run::LowererReach::ToolLessRelay, ModelFamily::Unrecorded).unwrap();
}
/// Runs `change` in the window between the pins and the open, at `open` and at
@ -411,7 +411,7 @@ fn window(
inventory: &i,
entities: &e,
};
let created = RunStores::create_between(&root, "t", paths, "fake-model", "bag", weksa::run::LowererReach::ToolLessRelay, || {
let created = RunStores::create_between(&root, "t", paths, "fake-model", "bag", weksa::run::LowererReach::ToolLessRelay, ModelFamily::Unrecorded, || {
change(&mut w, &root)
})
.err();
@ -828,7 +828,7 @@ fn dao_over(edit: impl FnOnce(&Path, &Path)) -> Dao {
entities: &entities,
},
"fake-model",
"bag", weksa::run::LowererReach::ToolLessRelay,
"bag", weksa::run::LowererReach::ToolLessRelay, ModelFamily::Unrecorded
)
.unwrap();
Dao {
@ -1477,15 +1477,15 @@ fn errors_echo_no_input() {
inventory: &missing,
entities: &missing,
};
let e = RunStores::create(&root, "ok", stores, "m", "bag", weksa::run::LowererReach::ToolLessRelay)
let e = RunStores::create(&root, "ok", stores, "m", "bag", weksa::run::LowererReach::ToolLessRelay, ModelFamily::Unrecorded)
.err()
.unwrap();
note(&e, &e);
let e = RunStores::create(&root, &format!("{canary}!"), stores, "m", "bag", weksa::run::LowererReach::ToolLessRelay)
let e = RunStores::create(&root, &format!("{canary}!"), stores, "m", "bag", weksa::run::LowererReach::ToolLessRelay, ModelFamily::Unrecorded)
.err()
.unwrap();
note(&e, &e);
let e = RunStores::create(&root, "ok", stores, &format!("{canary}\n"), "bag", weksa::run::LowererReach::ToolLessRelay)
let e = RunStores::create(&root, "ok", stores, &format!("{canary}\n"), "bag", weksa::run::LowererReach::ToolLessRelay, ModelFamily::Unrecorded)
.err()
.unwrap();
note(&e, &e);
@ -1519,7 +1519,7 @@ fn errors_echo_no_input() {
entities: &dao.entities,
},
"fake-model",
"bag", weksa::run::LowererReach::ToolLessRelay,
"bag", weksa::run::LowererReach::ToolLessRelay, ModelFamily::Unrecorded
)
.unwrap();
let mut model = cycle_fake(&format!("{{\"{canary}\":1}}"));
@ -2449,7 +2449,7 @@ fn a_changed_head_is_drift() {
entities: &dao.entities,
},
"fake-model",
"bag", weksa::run::LowererReach::ToolLessRelay,
"bag", weksa::run::LowererReach::ToolLessRelay, ModelFamily::Unrecorded
)
.unwrap();
assert_eq!(
@ -2768,7 +2768,7 @@ fn a_summary_line_says_how_lowerings_were_answered() {
inventory: &dao.inventory,
entities: &dao.entities,
};
RunStores::create(&root, "b", paths, "fake-model", "bag", LowererReach::BriefedSubagent)
RunStores::create(&root, "b", paths, "fake-model", "bag", LowererReach::BriefedSubagent, ModelFamily::Unrecorded)
.unwrap();
let run = RunStores::open(&root).unwrap();
assert_eq!(run.record().lowerer_reach, LowererReach::BriefedSubagent);

View file

@ -99,7 +99,7 @@ fn the_recall_probe_covers_all_six_original_items_and_names_no_work() {
},
"m",
"bag",
weksa::run::LowererReach::BriefedSubagent,
weksa::run::LowererReach::BriefedSubagent, ModelFamily::Unrecorded
)
.unwrap();
let mut model = Unrelated(vec![]);