Fix variable.update scopes: null not resetting to all supported

Fixes #443

Co-Authored-By: Claude Haiku 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
NetterSilver
2026-10-15 10:14:49 +00:00
co-authored by Claude Haiku 5.5
parent 8482c3e85b
commit 8e56820168
2 changed files with 27 additions and 1 deletions
+1 -1
View File
@@ -87,7 +87,7 @@ fn update(s: &mut Session, p: &Value) -> Result<Value> {
}
None => None,
};
let scopes = match get(p, "scopes") {
let scopes = match p.get("scopes") {
None => None,
Some(Value::Null) => Some(None),
Some(Value::Array(a)) => {
+26
View File
@@ -0,0 +1,26 @@
#![allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
use figcraft_engine::Session;
use serde_json::json;
fn scopes(session: &Session, variable: &str) -> Option<Vec<String>> {
session.doc().unwrap().variables.get(variable).unwrap().scopes.clone()
}
#[test]
fn null_restores_all_supported_properties() {
let mut session = Session::new();
session.execute("variable.createCollection", &json!({"name": "Theme"})).unwrap();
let result = session.execute("variable.create", &json!({"collection": "Theme", "name": "Accent", "type": "color"})).unwrap();
let variable = result["id"].as_str().unwrap();
assert_eq!(scopes(&session, variable), None);
session.execute("variable.update", &json!({"variable": variable, "scopes": []})).unwrap();
assert_eq!(scopes(&session, variable), Some(vec![]));
session.execute("variable.update", &json!({"variable": variable, "name": "Accent2"})).unwrap();
assert_eq!(scopes(&session, variable), Some(vec![]));
assert_eq!(session.execute("variable.update", &json!({"variable": variable, "scopes": null})).unwrap(), json!({"ok": true}));
assert_eq!(scopes(&session, variable), None);
session.execute("variable.update", &json!({"variable": variable, "scopes": []})).unwrap();
session.execute("variable.update", &json!({"variable": variable, "scopes": ["ALL_SCOPES"]})).unwrap();
assert_eq!(scopes(&session, variable), None);
}