Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- MCP 可按稿件版本、节号和页码只读找回已存的整页复盘;缺少记录时明确返回空结果。
- MCP 客户端指南增加只翻旧检查记录的工具选择和调用示例。
- MCP 查旧检查单时可按新增原文定位上一版,并按该版实际排版查询指定节的末页。
- MCP 已固定的数值参数不会仅因整数与小数写法不同而重新排版。
- MCP 在作业和实验报告的笔迹建议中区分松散笔迹与偶发涂改,指明对应调节项和预览方法。

## v1.21.0 (2026-11-24)
Expand Down
52 changes: 52 additions & 0 deletions crates/panache-mcp/src/controls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ pub fn merge(current: &Changes, patch: &Changes, fonts: &[String]) -> Result<Cha
_ => false,
};
ensure!(valid, "Invalid {name}; expected {spec}");
// Keep the stored JSON representation when a numeric override is unchanged.
if spec["type"] == "number" && current.get(name).and_then(Value::as_f64) == value.as_f64() {
continue;
}
next.insert(name.clone(), value.clone());
}
Ok(next)
Expand Down Expand Up @@ -165,3 +169,51 @@ pub fn parameters(draft: &Snapshot<'_>, section: u32, changes: &Changes) -> Resu
params.validate(w, h, &Limits::default())?;
Ok(params)
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn equivalent_numbers_keep_the_stored_representation() -> Result<()> {
for (old, new) in [(json!(4), json!(4.0)), (json!(4.0), json!(4))] {
let current = Changes::from_iter([("word_spacing".into(), old.clone())]);
let patch = Changes::from_iter([
("word_spacing".into(), new),
("ink_opacity".into(), json!(77)),
]);
let merged = merge(&current, &patch, &[])?;
assert_eq!(merged["word_spacing"], old);
assert_eq!(merged["ink_opacity"], 77);
}
Ok(())
}

#[test]
fn numeric_overrides_can_be_pinned_changed_and_cleared() -> Result<()> {
let mut current = Changes::new();
for value in [json!(1), json!(1.25), Value::Null] {
let patch = Changes::from_iter([("word_spacing".into(), value.clone())]);
current = merge(&current, &patch, &[])?;
assert_eq!(
current.get("word_spacing"),
(!value.is_null()).then_some(&value)
);
}
Ok(())
}

#[test]
fn equal_values_still_require_a_valid_patch() {
for (name, old, new) in [
("ink_opacity", json!(77), json!(77.0)),
("word_spacing", json!(4), json!("4")),
("word_spacing", json!(10001), json!(10001.0)),
("ink_thickness", json!(0.25), json!(0.25)),
] {
let current = Changes::from_iter([(name.into(), old)]);
let patch = Changes::from_iter([(name.into(), new)]);
assert!(merge(&current, &patch, &[]).is_err());
}
}
}