mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-27 16:59:43 +01:00
Scripts: a native file with a tag id that is not a whole number opens
A tag id in a native file that is negative, a fraction or text read as an error, so the whole file failed to open. It now reads as 0, and opening gives the tag a new id as it does for a missing or repeated id, with its name and value kept. The Scripts line in docs/target-app-parity.md now describes PageItem.tags and Document.tags separately: Document.tags reads, renames and deletes tags but its add throws.
This commit is contained in:
1 parent
986da7d0b4
commit
b0f74500ee
3 files changed
+32
-2
No files matched your search
@@ -58,7 +58,7 @@ pub struct ObjectTag {
|
||||
/// Distinct among the object's tags: a new tag takes an id from
|
||||
/// [`crate::Document::alloc_tag_id`], and deleting a tag raises the next node id above its id,
|
||||
/// so a deleted tag's id is not given out again.
|
||||
#[serde(default)]
|
||||
#[serde(default, deserialize_with = "lenient_tag_id")]
|
||||
pub id: u64,
|
||||
#[serde(default)]
|
||||
pub name: String,
|
||||
@@ -66,6 +66,13 @@ pub struct ObjectTag {
|
||||
pub value: String,
|
||||
}
|
||||
|
||||
/// Reading a native file never fails over a tag id that is not a whole number from 0 to
|
||||
/// `u64::MAX` (a negative one, a fraction, text): it reads as 0, and
|
||||
/// [`crate::Document::tidy_tags`] gives the tag a new id.
|
||||
fn lenient_tag_id<'de, D: serde::Deserializer<'de>>(d: D) -> Result<u64, D::Error> {
|
||||
Ok(serde_json::Value::deserialize(d)?.as_u64().unwrap_or(0))
|
||||
}
|
||||
|
||||
impl ObjectAttributes {
|
||||
/// Keeps the tags within the limits: the first [`MAX_TAGS`] whose name and value are at most
|
||||
/// [`MAX_TAG_TEXT`] bytes. → whether any was dropped.
|
||||
|
||||
@@ -260,3 +260,26 @@ fn tags_survive_native_save_and_open_and_hostile_ones_are_trimmed() {
|
||||
ids.dedup();
|
||||
assert_eq!(ids.len(), MAX_TAGS);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_file_with_a_tag_id_that_is_not_a_whole_number_opens_and_the_tag_gets_a_new_id() {
|
||||
let (s, a, _) = doc();
|
||||
let mut doc = (*s.active().unwrap().doc).clone();
|
||||
doc.node_mut(a).unwrap().edit_attrs(|at| {
|
||||
at.tags =
|
||||
["k0", "k1", "k2"].iter().enumerate().map(|(i, n)| ObjectTag { id: 424_240 + i as u64, name: (*n).into(), value: "v".into() }).collect();
|
||||
});
|
||||
let mut hostile = String::from_utf8(vectorcraft_format::save(&doc, false)).unwrap();
|
||||
for (from, to) in [("\"id\":424240", "\"id\":-1"), ("\"id\":424241", "\"id\":1.5"), ("\"id\":424242", "\"id\":\"x\"")] {
|
||||
assert!(hostile.contains(from), "{from}");
|
||||
hostile = hostile.replace(from, to);
|
||||
}
|
||||
let back = vectorcraft_format::load(hostile.as_bytes()).unwrap();
|
||||
let t = crate::cmd::tags::tags_of(back.node(a).unwrap());
|
||||
assert_eq!(t.iter().map(|t| (t.name.as_str(), t.value.as_str())).collect::<Vec<_>>(), [("k0", "v"), ("k1", "v"), ("k2", "v")]);
|
||||
let mut ids: Vec<u64> = t.iter().map(|t| t.id).collect();
|
||||
assert!(ids.iter().all(|id| *id >= 1 && *id < back.peek_next_id()), "{ids:?}");
|
||||
ids.sort_unstable();
|
||||
ids.dedup();
|
||||
assert_eq!(ids.len(), 3);
|
||||
}
|
||||
@@ -1032,7 +1032,7 @@ Moved from the ROADMAP's "Shipped so far" on 2026-10-10. Update it when a featur
|
||||
- The control server writes each reply through a 64 KiB buffer. On Windows 11 it sends the 17 MB `document.inspect` reply of a document with 50,000 objects on one layer to a client over loopback in 0.09 s instead of 34 s.
|
||||
- Scripts: File › Scripts › Other Script… and `script.run` run a JavaScript file against the open documents as one transaction with one undo step for each changed document. A failed or stopped run puts every document back. `crates/engine/src/tests/script_run.rs`.
|
||||
- Scripts: the global `app` gives the open documents, new documents from a startup preset and a `DocumentPreset`, the active document, each document's selection and its page items with their names, notes, visibility, lock, opacity, position, size, bounds and stacking order, and moves and copies them into or beside other objects, as the help pages https://ai-scripting.docsforadobe.dev/jsobjref/Application/, https://ai-scripting.docsforadobe.dev/jsobjref/Documents/, https://ai-scripting.docsforadobe.dev/jsobjref/DocumentPreset/, https://ai-scripting.docsforadobe.dev/jsobjref/Document/, https://ai-scripting.docsforadobe.dev/jsobjref/PageItems/, https://ai-scripting.docsforadobe.dev/jsobjref/PageItem/ and https://ai-scripting.docsforadobe.dev/jsobjref/GroupItem/ describe them; each change runs a command inside the run's transaction (`docs/mcp.md`). Layers, paths, type and the other classes are not there yet. `crates/engine/src/tests/script_dom.rs`.
|
||||
- Scripts: `PageItem.tags` and `Document.tags` read, add, rename and delete an object's tags, name and value pairs that the native file keeps, as the help pages https://ai-scripting.docsforadobe.dev/jsobjref/Tags/ and https://ai-scripting.docsforadobe.dev/jsobjref/Tag/ describe them, through `object.tags` and the `object.tag.*` commands, at most 64 tags an object (`docs/mcp.md`). `crates/engine/src/tests/script_tags.rs`.
|
||||
- Scripts: `PageItem.tags` reads, adds, renames and deletes an object's tags, name and value pairs that the native file keeps, and `Document.tags` reads, renames and deletes the tags of every page item but adds none (its `add` throws; a script adds a tag through the page item's `tags`), as the help pages https://ai-scripting.docsforadobe.dev/jsobjref/Tags/ and https://ai-scripting.docsforadobe.dev/jsobjref/Tag/ describe them, through `object.tags` and the `object.tag.*` commands, at most 64 tags an object (`docs/mcp.md`). `crates/engine/src/tests/script_tags.rs`.
|
||||
- Scripts: Window › Script Console shows each run's `$.write` and `$.writeln` output, `vc.log` entries, uncaught error with the script's name, line and column, and a report of its time, host calls and slowest commands, keeping at most 2,048 lines and counting the lines it dropped. `script.run`'s report carries the same data, and `script.console`, `script.console.clear` and `ui.copyScriptConsole` read, clear and copy it. `crates/engine/src/tests/script_console.rs`.
|
||||
- Scripts: the status bar translates its own words around a failed run's error and the app's own error messages, and shows text the script threw itself (a value, an error it made, or an error whose name or message it changed) as it is, even when that text reads like one of the app's messages. `script.run`'s report gives `messageOrigin` (`script` or `built-in`), and the advice about objects other applications give their scripts follows only the app's own reference errors. VectorCraft's own rule. `crates/js/src/interp_tests.rs`, `crates/engine/src/tests/script_run.rs`, `crates/ui-egui/src/chrome/tests.rs`.
|
||||
- Scripts: the `$` object has the other members the Dollar object page lists (https://extendscript.docsforadobe.dev/extendscript-tools-features/dollar-object/), from `$.about()` to `$.version`, and scripts have the global `localize(object, ...values)` (https://extendscript.docsforadobe.dev/extendscript-tools-features/localizing-extendscript-strings/), `toSource(value)` and `Object.prototype.toSource()`. Each run starts with the interface's locale, and what a script changes in `$` lasts only for that run. `crates/engine/src/tests/script_dollar.rs`, `crates/js/src/extension_tests.rs`.
|
||||
|
||||
Reference in new issue
Block a user