* Spike: typed parameter contracts and JSON Schemas for solid.box and solid.extrude The schema RFC's spike (plan/schema-spike.md). solid.box and solid.extrude get typed contracts with generated JSON Schemas (2020-12), checked in front of the unchanged handlers by a per-session level: off (the default, which changes nothing), warn (the call runs and gains param_warnings) or strict (the call is refused and the design left alone). Also engine.describe and the MCP tool describe_command, `solidcraft-cli mcp --param-check off|warn|strict`, a FeatureResult type for feature replies, and an env-var audit recorder (SOLIDCRAFT_PARAM_AUDIT) used to check the contracts against every test. Local spike branch; not for upstream as is (see the results report). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Parameter contracts: put the audit recorder behind a feature; drop two ignored test keys The audit recorder is now on only in a build with the engine's `param-audit` feature and `SOLIDCRAFT_PARAM_AUDIT` set. Its code is still compiled, linted and tested without the feature. `scripts/param_audit.py` summarises a test run's audit logs, and the schema module's docs give the steps for converting a further command. Two tests passed keys their command ignores, which the audit found: `position` on `solid.box` (`hole_face_tests.rs`) and `symmetric` on `solid.extrude` (`face_tests.rs`). Both are removed, so the tests build what they always did. Comments no longer call the contracts a spike. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: bherbruck <brennen.herbruck@gmail.com>
This commit is contained in:
@@ -35,6 +35,7 @@ mod edit;
|
||||
mod face;
|
||||
mod features;
|
||||
mod features_more;
|
||||
pub(crate) use features::profiles as feature_profiles;
|
||||
pub use features::{auto_operation, extrude_reach};
|
||||
pub use sketch_modify::trim_piece;
|
||||
mod component_link;
|
||||
@@ -96,6 +97,7 @@ pub type Run = fn(&mut Session, &Value) -> Result<Value>;
|
||||
/// evaluate as usual).
|
||||
pub type LiveRun = fn(&mut Session, &Value) -> Result<(Value, Option<crate::LiveEdit>)>;
|
||||
pub type Enabled = fn(&Session) -> std::result::Result<(), String>;
|
||||
pub type SchemaFn = fn() -> schemars::Schema;
|
||||
|
||||
pub struct CommandSpec {
|
||||
pub id: &'static str,
|
||||
@@ -120,6 +122,11 @@ pub struct CommandSpec {
|
||||
pub reads_model: bool,
|
||||
/// Registered but not built yet (see `planned!`): the GitHub issue number that tracks it.
|
||||
pub planned: Option<&'static str>,
|
||||
/// The command's typed parameter contract, which carries its input schema; `None` until
|
||||
/// the command is converted (see `crate::schema`).
|
||||
pub contract: Option<&'static dyn crate::schema::Contract>,
|
||||
/// The JSON Schema of a successful result; `None` until described.
|
||||
pub output: Option<SchemaFn>,
|
||||
}
|
||||
|
||||
impl CommandSpec {
|
||||
@@ -138,6 +145,8 @@ impl CommandSpec {
|
||||
live: None,
|
||||
reads_model: true,
|
||||
planned: None,
|
||||
contract: None,
|
||||
output: None,
|
||||
}
|
||||
}
|
||||
/// Not built yet; `issue` tracks building it.
|
||||
@@ -168,6 +177,16 @@ impl CommandSpec {
|
||||
self.shortcut = Some(k);
|
||||
self
|
||||
}
|
||||
/// The command's typed parameter contract (see `crate::schema`).
|
||||
pub const fn contract(mut self, c: &'static dyn crate::schema::Contract) -> Self {
|
||||
self.contract = Some(c);
|
||||
self
|
||||
}
|
||||
/// The JSON Schema of a successful result.
|
||||
pub const fn output(mut self, f: SchemaFn) -> Self {
|
||||
self.output = Some(f);
|
||||
self
|
||||
}
|
||||
pub const fn params(mut self, p: &'static str) -> Self {
|
||||
self.params = p;
|
||||
self
|
||||
@@ -325,7 +344,7 @@ pub(crate) fn did_you_mean(id: &str) -> String {
|
||||
}
|
||||
|
||||
/// Levenshtein distance: the single-character edits that turn `a` into `b`.
|
||||
fn edit_distance(a: &str, b: &str) -> usize {
|
||||
pub(crate) fn edit_distance(a: &str, b: &str) -> usize {
|
||||
let b: Vec<char> = b.chars().collect();
|
||||
let mut row: Vec<usize> = (0..=b.len()).collect();
|
||||
for (i, ca) in a.chars().enumerate() {
|
||||
|
||||
Reference in New Issue
Block a user