From 41de84ba44fdea2922e0be0fa82a2ac057dc4ce9 Mon Sep 17 00:00:00 2001 From: fork Date: Sun, 22 Nov 2026 09:49:53 +0100 Subject: [PATCH 1/7] Fix CI on main: usage page th scope, audit guard exemptions, mod order The usage statistics page (#383) left three checks red: the table headers had no scope (every_rendered_page_is_accessible), usage::record, ::overview and ::spawn write without an audit entry and were not on NOT_AUDITED, and `mod usage;` was out of rustfmt's order in src/web/mod.rs. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 4 ++++ src/web/mod.rs | 2 +- templates/admin/usage.html | 6 +++--- tests/architecture_guards.rs | 12 ++++++++++++ 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb84566d..65b41454 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -104,6 +104,10 @@ see the notices in the README. ### Fixed +- **CI on `main` is green again.** The usage statistics page (#383) gives + its table headers a `scope` (accessibility check), its background and + reporting functions are named in the audit guard's `NOT_AUDITED` list with + their reasons, and the web module list is in rustfmt's order. - **Desktop: a slow STEP export no longer holds the check-in hostage** (#342). With *Create STEP exports* ticked, the files are uploaded first (parked), then exported, then checked in with the STEP files. *Cancel* diff --git a/src/web/mod.rs b/src/web/mod.rs index cd6c57d5..4b7e4a6b 100755 --- a/src/web/mod.rs +++ b/src/web/mod.rs @@ -17,7 +17,6 @@ mod attributes; mod auth_pages; mod bom; mod branding; -mod usage; mod changes; mod dashboard; mod desktop; @@ -35,6 +34,7 @@ mod revisions; mod season; mod simulations; mod uploads; +mod usage; mod webhooks; // posted by the identity provider: mounted outside the cross-site guard diff --git a/templates/admin/usage.html b/templates/admin/usage.html index 17a5307c..8f3110eb 100644 --- a/templates/admin/usage.html +++ b/templates/admin/usage.html @@ -55,16 +55,16 @@

Desktop apps, last {{ desktop.days }} days

{{ desktop.active_minutes }} active minutes in all.

- + {% for v, n in desktop.versions|dictsort %}{% endfor %}
VersionInstallations
VersionInstallations
{{ v }}{{ n }}
- + {% for v, n in desktop.os|dictsort %}{% endfor %} {% for v, n in desktop.packages|dictsort %}{% endfor %}
SystemInstallations
SystemInstallations
{{ v }}{{ n }}
package: {{ v }}{{ n }}
- + {% for a in actions %}{% endfor %} {% for p, n in desktop.cad_exports|dictsort %}{% endfor %}
ActionCount
ActionCount
{{ a }}{{ desktop.actions[a] or 0 }}
STEP export: {{ p }}{{ n }}
diff --git a/tests/architecture_guards.rs b/tests/architecture_guards.rs index 9e6ff557..c96447c1 100755 --- a/tests/architecture_guards.rs +++ b/tests/architecture_guards.rs @@ -257,6 +257,18 @@ const NOT_AUDITED: &[(&str, &str)] = &[ "request_digests::spawn", "starts the background task of request_digests::run_once", ), + ( + "usage::record", + "an anonymous desktop usage report (#383): no actor, nothing names the user", + ), + ( + "usage::overview", + "a read for the admin page; its only write creates the one usage_sharing row (default off)", + ), + ( + "usage::spawn", + "housekeeping of old usage reports and the stamp of what was shared last; no actor", + ), ]; #[derive(Debug, Default, Clone)] From 93e2fd47b0601a7b18ffe537c96fc38e7ae49fc5 Mon Sep 17 00:00:00 2001 From: fork Date: Sun, 22 Nov 2026 09:51:59 +0100 Subject: [PATCH 2/7] SolidCraft plugin: status and check run, one label per ribbon button SolidCraft refused status and check with "permission denied: edit command document.metadata from read entry": its command catalog classes document.metadata, assembly.bom and component.links as edit commands, and a read entry may only call read commands. Both entries are now declared edit (they still only read). The four ribbon buttons all read "TeamCraft" because a ribbon slot's name is the button label; they now carry the entry titles. A manifest test pins both; the finding and its source are in docs/src/research/solidcraft-design.md. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 7 +++++++ docs/src/research/solidcraft-design.md | 10 ++++++++++ plugins/solidcraft/README.md | 13 +++++++++---- plugins/solidcraft/plugin.json | 12 ++++++------ plugins/solidcraft/src/logic.rs | 18 ++++++++++++++++++ 5 files changed, 50 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 65b41454..3fc5cca8 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -108,6 +108,13 @@ see the notices in the README. its table headers a `scope` (accessibility check), its background and reporting functions are named in the audit guard's `NOT_AUDITED` list with their reasons, and the web module list is in rustfmt's order. +- **SolidCraft plugin: *status* and *check* run again, and each button has + its own label.** SolidCraft refused both with *permission denied: edit + command document.metadata from read entry*, because it classes the + commands they read with as edit commands, so they are now declared `edit` + (they still change nothing). The four ribbon buttons, all labelled + *TeamCraft* before, now read *TeamCraft status*, *Check for TeamCraft*, + *Link to TeamCraft item* and *Unlink from TeamCraft*. - **Desktop: a slow STEP export no longer holds the check-in hostage** (#342). With *Create STEP exports* ticked, the files are uploaded first (parked), then exported, then checked in with the STEP files. *Cancel* diff --git a/docs/src/research/solidcraft-design.md b/docs/src/research/solidcraft-design.md index 574fa83a..274c2994 100644 --- a/docs/src/research/solidcraft-design.md +++ b/docs/src/research/solidcraft-design.md @@ -114,6 +114,16 @@ Both are already skipped by the desktop app's `is_ignored`. SolidCraft's plugins are sandboxed WebAssembly components without sockets, HTTP or fetch: an add-in inside SolidCraft cannot talk to a TeamCraft server. +An entry declared `"effect": "read"` may only call commands SolidCraft's +command catalog classes as `read`; anything else fails with *permission +denied: edit command … from read entry*. A command is `edit` unless its +spec says it is read-only, and `document.metadata`, `assembly.bom` and +`component.links` do not (SolidCraft's open source, `crates/engine/src/cmd/` +and `crates/craft-plugin-wasm/src/native.rs`, as of November 2026). So the +plugin's `status` and `check` entries are declared `edit` even though they +only read. A ribbon slot's `name` is the label of the entry's button +(`crates/ui-egui/src/plugin_menu.rs`). + ## Decision * Read `.sc` designs on the server with TeamCraft's own bounded ZIP/JSON diff --git a/plugins/solidcraft/README.md b/plugins/solidcraft/README.md index fa0c6120..5cc379c7 100644 --- a/plugins/solidcraft/README.md +++ b/plugins/solidcraft/README.md @@ -15,16 +15,21 @@ working folder stay in the TeamCraft desktop app. ## Entries -All four are on the *TeamCraft* ribbon group (Plugins tab) and in the -Plugins menu. +Each has its own button in the ribbon's Plugins group (labelled as in the +table) and a row in the Plugins menu. | Entry | Effect | What it does | |-------|--------|--------------| -| **status** – *TeamCraft status* | read | The TeamCraft item and revision the design belongs to, the page of the revision on the server, and whether the design's part number and revision still say the same. | -| **check** – *Check for TeamCraft* | read | What keeps the design from going into TeamCraft cleanly: no part number, a part number or revision that differs from the linked item, BOM rows without a part number, one part number with two descriptions, quantities SolidCraft cannot add up, linked designs with an absolute path or two linked designs with the same file name. `ready` is true when only notes are left. | +| **status** – *TeamCraft status* | edit¹ | The TeamCraft item and revision the design belongs to, the page of the revision on the server, and whether the design's part number and revision still say the same. | +| **check** – *Check for TeamCraft* | edit¹ | What keeps the design from going into TeamCraft cleanly: no part number, a part number or revision that differs from the linked item, BOM rows without a part number, one part number with two descriptions, quantities SolidCraft cannot add up, linked designs with an absolute path or two linked designs with the same file name. `ready` is true when only notes are left. | | **link** – *Link to TeamCraft item* | edit | Writes item number, revision and (optional) name into the design properties (*Part number*, *Revision*, *Description*) and TeamCraft's object – for designs edited without the desktop app. Ids written by the desktop app are kept while the item stays the same. One undo step; save the design afterwards. | | **unlink** – *Unlink from TeamCraft* | edit | Removes TeamCraft's object; part number and revision stay. | +¹ *status* and *check* only read. They are declared `edit` because SolidCraft +classes `document.metadata`, `assembly.bom` and `component.links` as edit +commands and refuses them from a read entry (*permission denied: edit command +document.metadata from read entry*). + SolidCraft commands it calls (declared in `plugin.json`, none of them reads or writes files): `document.metadata`, `document.metadata.set`, `document.metadata.remove`, `assembly.bom`, `component.links`. diff --git a/plugins/solidcraft/plugin.json b/plugins/solidcraft/plugin.json index ae9f94c5..f13e4f5b 100644 --- a/plugins/solidcraft/plugin.json +++ b/plugins/solidcraft/plugin.json @@ -9,15 +9,15 @@ "entries": [ { "name": "status", - "effect": "read", + "effect": "edit", "input_schema": {"type": "object", "properties": {}}, - "slots": [{"kind": "ribbon", "name": "TeamCraft"}] + "slots": [{"kind": "ribbon", "name": "TeamCraft status"}] }, { "name": "check", - "effect": "read", + "effect": "edit", "input_schema": {"type": "object", "properties": {}}, - "slots": [{"kind": "ribbon", "name": "TeamCraft"}] + "slots": [{"kind": "ribbon", "name": "Check for TeamCraft"}] }, { "name": "link", @@ -32,13 +32,13 @@ "server": {"type": "string", "title": "TeamCraft server (https://…)", "maxLength": 256} } }, - "slots": [{"kind": "ribbon", "name": "TeamCraft"}] + "slots": [{"kind": "ribbon", "name": "Link to TeamCraft item"}] }, { "name": "unlink", "effect": "edit", "input_schema": {"type": "object", "properties": {}}, - "slots": [{"kind": "ribbon", "name": "TeamCraft"}] + "slots": [{"kind": "ribbon", "name": "Unlink from TeamCraft"}] } ], "commands": [ diff --git a/plugins/solidcraft/src/logic.rs b/plugins/solidcraft/src/logic.rs index 3f3eaea3..1e1fef5c 100644 --- a/plugins/solidcraft/src/logic.rs +++ b/plugins/solidcraft/src/logic.rs @@ -644,5 +644,23 @@ mod tests { assert!(commands.contains(&command), "{command} not declared"); } assert_eq!(manifest["id"], "teamcraft"); + // A ribbon slot's name is the button's label: four different ones, + // not four buttons that all read "TeamCraft". + let entries = manifest["runtime"]["entries"].as_array().unwrap(); + let mut labels: Vec<&str> = entries + .iter() + .map(|e| e["slots"][0]["name"].as_str().unwrap()) + .collect(); + assert!(labels.iter().all(|l| *l != "TeamCraft"), "{labels:?}"); + labels.sort_unstable(); + labels.dedup(); + assert_eq!(labels.len(), ENTRIES.len(), "one label per entry"); + // SolidCraft refuses a command it does not class as `read` from a + // read entry, and it classes document.metadata, assembly.bom and + // component.links as edit commands. So every entry is `edit`; status + // and check only read. + for e in entries { + assert_eq!(e["effect"], "edit", "{}", e["name"]); + } } } From 7e5aebdabdc01eb5828f61c96309d9fb087d60cf Mon Sep 17 00:00:00 2001 From: fork Date: Sun, 22 Nov 2026 09:53:15 +0100 Subject: [PATCH 3/7] Error page test: expect MiniJinja's escaped slash (#381) every_template_renders looked for "Page: /items/PRT-000042", but MiniJinja escapes / in text as /. The copied details are decoded by the browser. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 3 ++- src/templates.rs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3fc5cca8..2c7dcff6 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -107,7 +107,8 @@ see the notices in the README. - **CI on `main` is green again.** The usage statistics page (#383) gives its table headers a `scope` (accessibility check), its background and reporting functions are named in the audit guard's `NOT_AUDITED` list with - their reasons, and the web module list is in rustfmt's order. + their reasons, the web module list is in rustfmt's order, and the error + page test expects the escaped `/` MiniJinja writes (#381). - **SolidCraft plugin: *status* and *check* run again, and each button has its own label.** SolidCraft refused both with *permission denied: edit command document.metadata from read entry*, because it classes the diff --git a/src/templates.rs b/src/templates.rs index e2a0a487..d2f3201e 100755 --- a/src/templates.rs +++ b/src/templates.rs @@ -630,9 +630,10 @@ mod tests { "flash": null, "local_login": true, "path": "/items/PRT-000042", "time": "2026-11-22 08:00:00 UTC", "version": "0.2.12" }), ); + // (MiniJinja escapes `/` in text as `/`; the copied text is decoded) assert!( html.contains("data-copy=\"error-details\"") - && html.contains("Page: /items/PRT-000042") + && html.contains("Page: /items/PRT-000042") ); assert!(html.contains("Something went wrong <b>"), "escaped"); // a hosted live demo: the account on the login page, the banner on every page From 10554fc8c3133b081dd3db940ccd45fa5674b167 Mon Sep 17 00:00:00 2001 From: fork Date: Sun, 22 Nov 2026 10:03:25 +0100 Subject: [PATCH 4/7] SolidCraft plugin: failures explain themselves; tested on SolidCraft 0.45 Bad input names the field (SolidCraft shows only the reason), damaged teamcraft.pdm data is reported with the fix, and check no longer reports ready when the BOM or the linked designs could not be read. Command failures carry what to do. SolidCraft 0.45 ends a run on any failed command with its own message, so the plugin only calls commands that answer on any design; all four entries were run on the flatpak through solidcraft-cli, also on an empty design. The test host now answers a part with no BOM rows, as SolidCraft does. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 4 + docs/src/research/solidcraft-design.md | 7 + plugins/solidcraft/Cargo.lock | 835 +++++++++++++++++++++++++ plugins/solidcraft/README.md | 18 + plugins/solidcraft/src/lib.rs | 2 +- plugins/solidcraft/src/logic.rs | 171 ++++- 6 files changed, 1025 insertions(+), 12 deletions(-) create mode 100644 plugins/solidcraft/Cargo.lock diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c7dcff6..821fa08e 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -116,6 +116,10 @@ see the notices in the README. (they still change nothing). The four ribbon buttons, all labelled *TeamCraft* before, now read *TeamCraft status*, *Check for TeamCraft*, *Link to TeamCraft item* and *Unlink from TeamCraft*. + Failures explain themselves: bad input names the field, damaged TeamCraft + data in a design is reported with the fix, and *check* never reports + *ready* when it could not read the BOM or the linked designs. All four + entries were run on SolidCraft 0.45.0 (flatpak) through `solidcraft-cli`. - **Desktop: a slow STEP export no longer holds the check-in hostage** (#342). With *Create STEP exports* ticked, the files are uploaded first (parked), then exported, then checked in with the STEP files. *Cancel* diff --git a/docs/src/research/solidcraft-design.md b/docs/src/research/solidcraft-design.md index 274c2994..6a1cb19b 100644 --- a/docs/src/research/solidcraft-design.md +++ b/docs/src/research/solidcraft-design.md @@ -124,6 +124,13 @@ plugin's `status` and `check` entries are declared `edit` even though they only read. A ribbon slot's `name` is the label of the entry's button (`crates/ui-egui/src/plugin_menu.rs`). +A command that fails or is refused inside an entry ends the whole run: the +host records the first failure and returns it as the entry's result, even when +the guest handles the error (`crates/craft-plugin-wasm/src/native.rs`, +`fail` and `check`; seen on SolidCraft 0.45.0 with `solidcraft-cli`). A part +without components answers `assembly.bom` with no rows and +`component.links` with no links, so neither fails on a plain part. + ## Decision * Read `.sc` designs on the server with TeamCraft's own bounded ZIP/JSON diff --git a/plugins/solidcraft/Cargo.lock b/plugins/solidcraft/Cargo.lock new file mode 100644 index 00000000..1c652c89 --- /dev/null +++ b/plugins/solidcraft/Cargo.lock @@ -0,0 +1,835 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "adler2" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" + +[[package]] +name = "anyhow" +version = "1.0.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470" + +[[package]] +name = "auditable-serde" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c7bf8143dfc3c0258df908843e169b5cc5fcf76c7718bd66135ef4a9cd558c5" +dependencies = [ + "semver", + "serde", + "serde_json", + "topological-sort", +] + +[[package]] +name = "bitflags" +version = "2.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06" + +[[package]] +name = "cfg-if" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600" + +[[package]] +name = "crc32fast" +version = "1.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b929dd2a135771f40afabd1073f85eed59c800b7c61901e5c254270497dad64" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "displaydoc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6232dd377dcc64799954cbd3a9bb882e9cdc1308ccd87b1c098f1fb2eaf82a8" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", +] + +[[package]] +name = "equivalent" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00d174d5400e5e8fd687ad1049e2f578285fa914201b1af7e8b112a4546bd826" + +[[package]] +name = "flate2" +version = "1.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "626d4928326b646e70f65ed36fc7cf9f206bdb68a0019ee7c6b4709da4e084c4" +dependencies = [ + "crc32fast", + "miniz_oxide", + "zlib-rs", +] + +[[package]] +name = "foldhash" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" + +[[package]] +name = "form_urlencoded" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afa489199eaffb1211795df1c6236ce1ad0d41a6fa45250add73e3b02420f06e" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futures" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a31d2a3fbaaeb2af2368bbdd904aa8e812d3c04a1ee10d3171f52d556e5d0a3" +dependencies = [ + "futures-channel", + "futures-core", + "futures-executor", + "futures-io", + "futures-sink", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-channel" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f9e3d69d39e4862ffed03ed071a76f9a13ba1d9109d355b0f0aa6b15e393c4" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e" + +[[package]] +name = "futures-executor" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "031b47cf1a3c6cc8bc2fc76cd437f521619387907d469316e7c0bc278f1f5432" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53c0fa8157de1303bfffdaa1cc2a673bfffb60102f76b0ef4441659124373fed" + +[[package]] +name = "futures-macro" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb9654ba8355388abeb8dcb4fc62f511300867002afc858860463bdd9fe0c44" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", +] + +[[package]] +name = "futures-sink" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1944426bf7d03f1d14f708785e4b33efd750b36d48a157b836b3efc15ede8e1d" + +[[package]] +name = "futures-task" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd417de3d1d015fc3bfd2b1ea46dfc7bab72ef86f1cc7cc9c78e728b34a6d1fd" + +[[package]] +name = "futures-util" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "slab", +] + +[[package]] +name = "hashbrown" +version = "0.15.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" +dependencies = [ + "foldhash", +] + +[[package]] +name = "hashbrown" +version = "0.17.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "735eaa21a6a5ffb2e84362faaeb90c05ba8e19797ca30428478cb6ea3a4921bc" + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "icu_collections" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe090a42a0d3140fed8c63263ed1fecc02422cb2f4bfe55cd8de2de1b8e105dd" +dependencies = [ + "displaydoc", + "potential_utf", + "utf8_iter", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locale_core" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25d29b57c17c6528d0dc4c2141cfa2d08200465acb537a3909c8b9b8a4a984c0" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_normalizer" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "404a3b8c486f205c87fe7f23ab6894d84a4ad76d6e4671ae1981ba7def87c599" +dependencies = [ + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20f0088bfb7441f7a37fa0c9e20cb1e9cba1cac6b9ce8cd2a6dc44294f8e8cbc" + +[[package]] +name = "icu_properties" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ea83d991c56158f7cf898bf86436c1dfe7c07ee82fe88951f2695c9f37a379f" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_locale_core", + "icu_properties_data", + "icu_provider", + "zerotrie", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b98f29af82d02b163fe50161388350e743bb3107cc8e8c2f7314cb505faddfcf" + +[[package]] +name = "icu_provider" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413099315636c588ee8f011190b329b971a09a8fae9d157e01dcae8379468514" +dependencies = [ + "displaydoc", + "icu_locale_core", + "writeable", + "yoke", + "zerofrom", + "zerotrie", + "zerovec", +] + +[[package]] +name = "id-arena" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954" + +[[package]] +name = "idna" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb68373c0d6620ef8105e855e7745e18b0d00d3bdb07fb532e434244cdb9a714" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + +[[package]] +name = "indexmap" +version = "2.14.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc4e190f5d26ca7051642629da2c52fc03bde85a03197c99408dcd291734c855" +dependencies = [ + "equivalent", + "hashbrown 0.17.2", + "serde", + "serde_core", +] + +[[package]] +name = "itoa" +version = "1.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4" + +[[package]] +name = "leb128fmt" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2" + +[[package]] +name = "litemap" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47d9d19d1d6efa0109d2f65ff4c85cddd50bd572e5a00127ab10987290bcefae" + +[[package]] +name = "log" +version = "0.4.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d15f86d12da44cd8d4ec3c73984537eb7f4cadcb9776a575a0a8a05ca11005c" + +[[package]] +name = "memchr" +version = "2.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" + +[[package]] +name = "miniz_oxide" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b63fbc4a50860e98e7b2aa7804ded1db5cbc3aff9193adaff57a6931bf7c4b4c" +dependencies = [ + "adler2", + "simd-adler32", +] + +[[package]] +name = "once_cell" +version = "1.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" + +[[package]] +name = "percent-encoding" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" + +[[package]] +name = "pin-project-lite" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c938015719552d665fd0553b90d96cd7ff58e83e4c061ca99e6bb78865a72752" + +[[package]] +name = "potential_utf" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d83eb9bc6d8e5cf568e7a1101d60ee05e81ed50ea106026f3d18deeb046d7661" +dependencies = [ + "zerovec", +] + +[[package]] +name = "prettyplease" +version = "0.2.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" +dependencies = [ + "proc-macro2", + "syn 2.0.119", +] + +[[package]] +name = "proc-macro2" +version = "1.0.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "semver" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd" +dependencies = [ + "serde", + "serde_core", +] + +[[package]] +name = "serde" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde_core" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", +] + +[[package]] +name = "serde_json" +version = "1.0.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7e9cc8b1b85264074fbcc02a88680c4096b1e47df8f739dceb03bf482f04bd6" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "simd-adler32" +version = "0.3.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a219298ac11a56ea9a6d2120044824d6f01aeb034955e7af7bc16858527deea" + +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + +[[package]] +name = "smallvec" +version = "1.16.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3244542535d5de959d90ec55d1b5ff0fd2bb7b1310223907d5f11932847f7b59" + +[[package]] +name = "spdx" +version = "0.10.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3e17e880bafaeb362a7b751ec46bdc5b61445a188f80e0606e68167cd540fa3" +dependencies = [ + "smallvec", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" + +[[package]] +name = "syn" +version = "2.0.119" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "3.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ae9ccbea3a7b0b09443036490c8f34a8b1b760fd345e5c0dae0aac718faea79" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "synstructure" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "901704edd0dfe137f1987838ee4f259e4e063c31371bdb423f7ae38ec6f77f02" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", +] + +[[package]] +name = "teamcraft-solidcraft-plugin" +version = "0.1.0" +dependencies = [ + "serde_json", + "wit-bindgen", +] + +[[package]] +name = "tinystr" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abc840c238154d58f9e86b2792261edfde565a17696e1cda1a449de27979801a" +dependencies = [ + "displaydoc", + "zerovec", +] + +[[package]] +name = "topological-sort" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea68304e134ecd095ac6c3574494fc62b909f416c4fca77e440530221e549d3d" + +[[package]] +name = "unicode-ident" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563" + +[[package]] +name = "unicode-xid" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebc1c04c71510c7f702b52b7c350734c9ff1295c464a03335b00bb84fc54f853" + +[[package]] +name = "url" +version = "2.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f00cd2407bb42c0ef17be88d4cf020f5cceffd121665bac9b8b9493a369b3b1a" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", + "serde", +] + +[[package]] +name = "utf8_iter" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af3bd9d3e571c26fcce9d033b87ea5ab061b8d2ffe9b7a5675d810d68f03edf0" +dependencies = [ + "utf_types", +] + +[[package]] +name = "utf_types" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a3b425286980a367278453f3b6d28cdcb134b574e5a35824a6ff5eebad50bb6" + +[[package]] +name = "wasm-encoder" +version = "0.227.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80bb72f02e7fbf07183443b27b0f3d4144abf8c114189f2e088ed95b696a7822" +dependencies = [ + "leb128fmt", + "wasmparser", +] + +[[package]] +name = "wasm-metadata" +version = "0.227.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce1ef0faabbbba6674e97a56bee857ccddf942785a336c8b47b42373c922a91d" +dependencies = [ + "anyhow", + "auditable-serde", + "flate2", + "indexmap", + "serde", + "serde_derive", + "serde_json", + "spdx", + "url", + "wasm-encoder", + "wasmparser", +] + +[[package]] +name = "wasmparser" +version = "0.227.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f51cad774fb3c9461ab9bccc9c62dfb7388397b5deda31bf40e8108ccd678b2" +dependencies = [ + "bitflags", + "hashbrown 0.15.5", + "indexmap", + "semver", +] + +[[package]] +name = "wit-bindgen" +version = "0.41.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10fb6648689b3929d56bbc7eb1acf70c9a42a29eb5358c67c10f54dbd5d695de" +dependencies = [ + "wit-bindgen-rt", + "wit-bindgen-rust-macro", +] + +[[package]] +name = "wit-bindgen-core" +version = "0.41.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92fa781d4f2ff6d3f27f3cc9b74a73327b31ca0dc4a3ef25a0ce2983e0e5af9b" +dependencies = [ + "anyhow", + "heck", + "wit-parser", +] + +[[package]] +name = "wit-bindgen-rt" +version = "0.41.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4db52a11d4dfb0a59f194c064055794ee6564eb1ced88c25da2cf76e50c5621" +dependencies = [ + "bitflags", + "futures", + "once_cell", +] + +[[package]] +name = "wit-bindgen-rust" +version = "0.41.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d0809dc5ba19e2e98661bf32fc0addc5a3ca5bf3a6a7083aa6ba484085ff3ce" +dependencies = [ + "anyhow", + "heck", + "indexmap", + "prettyplease", + "syn 2.0.119", + "wasm-metadata", + "wit-bindgen-core", + "wit-component", +] + +[[package]] +name = "wit-bindgen-rust-macro" +version = "0.41.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad19eec017904e04c60719592a803ee5da76cb51c81e3f6fbf9457f59db49799" +dependencies = [ + "anyhow", + "prettyplease", + "proc-macro2", + "quote", + "syn 2.0.119", + "wit-bindgen-core", + "wit-bindgen-rust", +] + +[[package]] +name = "wit-component" +version = "0.227.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "635c3adc595422cbf2341a17fb73a319669cc8d33deed3a48368a841df86b676" +dependencies = [ + "anyhow", + "bitflags", + "indexmap", + "log", + "serde", + "serde_derive", + "serde_json", + "wasm-encoder", + "wasm-metadata", + "wasmparser", + "wit-parser", +] + +[[package]] +name = "wit-parser" +version = "0.227.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddf445ed5157046e4baf56f9138c124a0824d4d1657e7204d71886ad8ce2fc11" +dependencies = [ + "anyhow", + "id-arena", + "indexmap", + "log", + "semver", + "serde", + "serde_derive", + "serde_json", + "unicode-xid", + "wasmparser", +] + +[[package]] +name = "writeable" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ad82d2a33cdc9674dc7465672f271e096168fcdbe0f799d9e6db8c5892679dc" + +[[package]] +name = "yoke" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "417ef3fcf6c300b7dbd25c85531a746931c02ad536f3cf4786ed1e88223340b3" +dependencies = [ + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec8ebde2db3681e8c9980cc27822030e68752690ddfa9473e739aeb4dbde6d71" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", + "synstructure", +] + +[[package]] +name = "zerofrom" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ec05a11813ea801ff6d75110ad09cd0824ddba17dfe17128ea0d5f68e6c5272" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f75b4683f6c7f45248d4d64056a24298c6281e0993356d7d1b4a1a962ef10d4a" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", + "synstructure", +] + +[[package]] +name = "zerotrie" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ea269c3bd32f0a32c321907a2ae912ba6f4649bb0fc764a15627e99a7095a3f" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", +] + +[[package]] +name = "zerovec" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f58a2799cfe9a1670c7ea8edbd52ef8edb93cb37a7f83bf31ba9e35d9dae6a40" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.11.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3743ddbf47738d929cd1ae2e199d40d0162979dfe31aef8ae646d2bf00bf97a" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", +] + +[[package]] +name = "zlib-rs" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b268e58e7c693d7c271f93ffc4ba3b380412554231c85bf61ca7af91042a4112" + +[[package]] +name = "zmij" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b" diff --git a/plugins/solidcraft/README.md b/plugins/solidcraft/README.md index 5cc379c7..012e90aa 100644 --- a/plugins/solidcraft/README.md +++ b/plugins/solidcraft/README.md @@ -34,6 +34,24 @@ SolidCraft commands it calls (declared in `plugin.json`, none of them reads or writes files): `document.metadata`, `document.metadata.set`, `document.metadata.remove`, `assembly.bom`, `component.links`. +## When something fails + +The plugin needs neither a TeamCraft server nor the desktop app: TeamCraft +not running never makes it fail. What it says when something does go wrong: + +- **Bad input** to *Link to TeamCraft item* names the field and changes + nothing (*Item number is required. Nothing was changed.*). +- **A design without TeamCraft data** is *not linked*, with how to link it. + **Damaged TeamCraft data** (not an object) is reported, with *Link* or + *Unlink* as the fix. +- **A SolidCraft command that fails** ends the run: SolidCraft shows its own + message, prefixed *TeamCraft:*, and keeps the design as it was. The plugin + cannot catch it (SolidCraft 0.45). So the plugin only calls commands that + answer on any design – a part without components gives an empty BOM and no + links – and checks its input before it writes. On a host that hands the + error back, the plugin adds what to do, and *check* reports a BOM or link + list it could not read as a warning instead of *ready*. + ## Build ```sh diff --git a/plugins/solidcraft/src/lib.rs b/plugins/solidcraft/src/lib.rs index bd9b1bbc..471c240a 100644 --- a/plugins/solidcraft/src/lib.rs +++ b/plugins/solidcraft/src/lib.rs @@ -59,7 +59,7 @@ mod component { let params: serde_json::Value = serde_json::from_str(¶ms).map_err(|e| { PluginError::InvalidInput(FieldFailure { field: "params".into(), - reason: e.to_string(), + reason: format!("the entry's input is not JSON ({e}); nothing was changed"), }) })?; match logic::execute(&mut Commands, &entry, ¶ms) { diff --git a/plugins/solidcraft/src/logic.rs b/plugins/solidcraft/src/logic.rs index 1e1fef5c..2adfa3fd 100644 --- a/plugins/solidcraft/src/logic.rs +++ b/plugins/solidcraft/src/logic.rs @@ -31,18 +31,56 @@ pub enum EntryError { Unsupported(String), } +/// The label of a field of *Link to TeamCraft item*, as its dialog shows it. +fn label(field: &str) -> &str { + match field { + "item_number" => "Item number", + "revision" => "Revision", + "name" => "Item name", + "server" => "TeamCraft server", + other => other, + } +} + +/// A broken input. SolidCraft shows only the reason, so the reason names the +/// field itself (`Item number is required`, not `is required`). fn input(field: &str, reason: &str) -> EntryError { EntryError::Input { field: field.into(), - reason: reason.into(), + reason: format!("{} {reason}. Nothing was changed.", label(field)), } } +/// Why SolidCraft refused or failed `command`, in words a user can act on. +/// The plugin never talks to a TeamCraft server or the desktop app (it has no +/// network), so a failure here is always SolidCraft's answer about the open +/// design – TeamCraft not running is never the cause. +pub fn explain(command: &str, reason: &str) -> String { + let reason = reason.trim(); + let lower = reason.to_ascii_lowercase(); + let hint = if lower.contains("permission denied") || lower.contains("not granted") { + "This SolidCraft version does not let the TeamCraft plugin use it – install the TeamCraft \ + plugin that matches your SolidCraft version." + } else if lower.contains("cancel") { + "The run was stopped." + } else if lower.contains("limit") || lower.contains("fuel") || lower.contains("deadline") { + "The design is too large for the plugin's limits." + } else { + "Is a design open? Nothing in the design was changed." + }; + let reason = if reason.is_empty() { + "no reason given" + } else { + reason + }; + format!("SolidCraft could not run {command} ({reason}). {hint}") +} + fn call(host: &mut dyn Host, command: &str, args: Value) -> Result { host.run(command, args) .map_err(|reason| EntryError::Command { command: command.into(), - reason, + reason: explain(command, &reason), }) } @@ -84,6 +122,16 @@ fn text<'a>(map: &'a Map, key: &str) -> &'a str { .unwrap_or("") } +/// The message for a design whose TeamCraft data is not an object (written +/// by hand or by another tool), with what to do about it. +const DAMAGED: &str = "The design's TeamCraft data (teamcraft.pdm) is damaged. Use *Link to \ + TeamCraft item* to write it again, or *Unlink from TeamCraft* to remove it."; + +/// Whether the design has a TeamCraft entry that is not an object. +fn damaged(metadata: &Map) -> bool { + metadata.get(KEY).is_some_and(|v| !v.is_object()) +} + /// TeamCraft's object in the design, if there is one. fn teamcraft(metadata: &Map) -> Option<&Map> { metadata.get(KEY).and_then(Value::as_object) @@ -104,6 +152,15 @@ pub fn status(host: &mut dyn Host) -> Result { let (metadata, props) = properties(host)?; let part_number = text(&props, "part_number"); let revision = text(&props, "revision"); + if damaged(&metadata) { + return Ok(json!({ + "managed": false, + "damaged": true, + "part_number": part_number, + "revision": revision, + "message": DAMAGED, + })); + } let Some(tc) = teamcraft(&metadata) else { return Ok(json!({ "managed": false, @@ -179,6 +236,7 @@ pub fn check(host: &mut dyn Host) -> Result { )); } match teamcraft(&metadata) { + None if damaged(&metadata) => findings.push(finding("warning", DAMAGED.into())), None => findings.push(finding( "info", "Not linked to a TeamCraft item yet.".into(), @@ -221,9 +279,20 @@ pub fn check(host: &mut dyn Host) -> Result { /// BOM rows TeamCraft cannot match: no part number, a quantity SolidCraft /// cannot count, one part number with different descriptions. fn check_bom(host: &mut dyn Host, findings: &mut Vec) { - // a part without components has no rows; a failure is no finding - let Ok(bom) = host.run("assembly.bom", json!({"levels": "all"})) else { - return; + // a part without components answers with no rows; a failure means the + // rows were not checked, which must not read as "ready" + let bom = match host.run("assembly.bom", json!({"levels": "all"})) { + Ok(bom) => bom, + Err(reason) => { + findings.push(finding( + "warning", + format!( + "The bill of materials was not checked: {}", + explain("assembly.bom", &reason) + ), + )); + return; + } }; let rows = bom .get("rows") @@ -277,8 +346,18 @@ fn check_bom(host: &mut dyn Host, findings: &mut Vec) { /// working folder) or two links with the same file name in different /// folders (TeamCraft finds references by file name). fn check_links(host: &mut dyn Host, findings: &mut Vec) { - let Ok(links) = host.run("component.links", json!({})) else { - return; + let links = match host.run("component.links", json!({})) { + Ok(links) => links, + Err(reason) => { + findings.push(finding( + "warning", + format!( + "The linked designs were not checked: {}", + explain("component.links", &reason) + ), + )); + return; + } }; let links = links .get("links") @@ -401,11 +480,16 @@ mod tests { rows: Vec, links: Vec, calls: Vec<(String, Value)>, + /// Commands that fail, with SolidCraft's reason. + fail: Vec<(&'static str, &'static str)>, } impl Host for Fake { fn run(&mut self, command: &str, args: Value) -> Result { self.calls.push((command.to_string(), args.clone())); + if let Some((_, why)) = self.fail.iter().find(|(c, _)| *c == command) { + return Err((*why).to_string()); + } let props = |m: &Map| { let mut p = Map::new(); for k in [ @@ -442,9 +526,6 @@ mod tests { let was = self.metadata.remove(key).is_some(); Ok(json!({"removed": if was { vec![key] } else { vec![] }})) } - "assembly.bom" if self.rows.is_empty() => { - Err("the design has no components".into()) - } "assembly.bom" => Ok(json!({"rows": self.rows})), "component.links" => Ok(json!({"links": self.links})), other => Err(format!("unknown command {other}")), @@ -595,7 +676,11 @@ mod tests { ), ] { match link(&mut f, ¶ms) { - Err(EntryError::Input { field: got, .. }) => assert_eq!(got, field, "{params}"), + Err(EntryError::Input { field: got, reason }) => { + assert_eq!(got, field, "{params}"); + // SolidCraft shows only the reason: it names the field + assert!(reason.starts_with(label(field)), "{reason}"); + } other => panic!("{params}: {other:?}"), } } @@ -605,6 +690,70 @@ mod tests { ); } + /// No hard, unexplained failure: a refused or failed SolidCraft command + /// says which command, SolidCraft's reason and what to do. + #[test] + fn a_failed_command_is_explained() { + let mut refused = linked(); + refused.fail = vec![( + "document.metadata", + "permission denied: edit command document.metadata from read entry", + )]; + let Err(EntryError::Command { command, reason }) = status(&mut refused) else { + panic!("status must fail when the properties cannot be read"); + }; + assert_eq!(command, "document.metadata"); + assert!(reason.contains("permission denied") && reason.contains("matches your SolidCraft")); + let mut closed = Fake { + fail: vec![("document.metadata", "no design is open")], + ..Fake::default() + }; + let Err(EntryError::Command { reason, .. }) = check(&mut closed) else { + panic!("check must fail without properties"); + }; + assert!(reason.contains("no design is open") && reason.contains("Nothing in the design")); + assert!(explain("x", " ").contains("no reason given")); + let mut write = linked(); + write.fail = vec![("document.metadata.set", "the design is read-only")]; + let params = json!({"item_number": "TC-1", "revision": "A"}); + assert!(matches!( + link(&mut write, ¶ms), + Err(EntryError::Command { reason, .. }) if reason.contains("read-only") + )); + } + + /// A BOM or link list SolidCraft cannot give is a warning, never "ready". + #[test] + fn unread_bom_and_links_are_not_ready() { + let mut f = linked(); + f.fail = vec![ + ("assembly.bom", "evaluation failed"), + ("component.links", "evaluation failed"), + ]; + let c = check(&mut f).unwrap(); + assert_eq!(c["ready"], false); + let text = c["findings"].to_string(); + assert!(text.contains("bill of materials was not checked"), "{text}"); + assert!(text.contains("linked designs were not checked"), "{text}"); + // a plain part answers with no rows and no links: ready + assert_eq!(check(&mut linked()).unwrap()["ready"], true); + } + + /// TeamCraft data that is not an object is reported, and link repairs it. + #[test] + fn damaged_teamcraft_data_is_reported_and_repaired() { + let mut f = linked(); + f.metadata.insert(KEY.into(), json!("garbage")); + let s = status(&mut f).unwrap(); + assert_eq!(s["damaged"], true); + assert!(s["message"].as_str().unwrap().contains("damaged")); + let c = check(&mut f).unwrap(); + assert_eq!(c["ready"], false); + let params = json!({"item_number": "TC-1042", "revision": "B"}); + link(&mut f, ¶ms).unwrap(); + assert_eq!(status(&mut f).unwrap()["managed"], true); + } + #[test] fn unlink_removes_only_teamcrafts_object() { let mut f = linked(); From b8e4a2b4cd31b2a901c1e81cdcef06678160ac19 Mon Sep 17 00:00:00 2001 From: fork Date: Sun, 22 Nov 2026 10:07:31 +0100 Subject: [PATCH 5/7] Research: talking to the desktop app from inside SolidCraft MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A bridge folder granted to the plugin carries state (desktop app → plugin) and requests (plugin → desktop app); design properties keep identity only. Findings from SolidCraft's open source and the installed 0.45.0. Co-Authored-By: Claude Opus 5.5 --- docs/src/SUMMARY.md | 1 + docs/src/research/index.md | 1 + docs/src/research/solidcraft-bridge.md | 118 +++++++++++++++++++++++++ 3 files changed, 120 insertions(+) create mode 100644 docs/src/research/solidcraft-bridge.md diff --git a/docs/src/SUMMARY.md b/docs/src/SUMMARY.md index e3cefec6..887b84fb 100755 --- a/docs/src/SUMMARY.md +++ b/docs/src/SUMMARY.md @@ -99,3 +99,4 @@ - [A sandboxed extension layer](research/extension-layer.md) - [SolidCraft designs](research/solidcraft-design.md) - [3D preview of SolidCraft designs without an export](research/solidcraft-3d-preview.md) + - [Talking to the desktop app from inside SolidCraft](research/solidcraft-bridge.md) diff --git a/docs/src/research/index.md b/docs/src/research/index.md index ed659e99..1e353f92 100755 --- a/docs/src/research/index.md +++ b/docs/src/research/index.md @@ -20,6 +20,7 @@ accepted in TeamCraft, from people or from AI agents | [Translated UI: message catalogs](translated-ui.md) | JSON catalogs in `shared/i18n/` (ID → sentence with `{named}` placeholders, CLDR plural categories), read by Rust (`include_str!`) and JS (`Intl.PluralRules`); English fallback, guard tests for IDs and placeholders; no new dependency, Fluent as the upgrade path | 2026-11-22 | | [A sandboxed extension layer](extension-layer.md) | WebAssembly components on wasmtime behind a cargo feature: manifest + approval by SHA-256, versioned capabilities (`validate@1` at lifecycle transitions first, then `numbering@1`), no WASI/network/clock, fuel + memory + wall-time limits, data only through host functions with the acting user's rights, writes only through `services::*` | 2026-11-22 | | [3D preview of SolidCraft designs without an export](solidcraft-3d-preview.md) | keep the STEP export through `solidcraft-cli` (#368) and the embedded thumbnail; next read `cache/preview.bin` (SCMESH01) when present – rare until SolidCraft writes it by default; an own SCBREP05 B-rep reader with a display tessellator only later; never the imported blobs as a stand-in | 2026-11-22 | +| [Talking to the desktop app from inside SolidCraft](solidcraft-bridge.md) | a bridge folder `/.teamcraft/solidcraft/` granted to the plugin: the desktop app writes a heartbeat and the state of each revision, the plugin writes requests (check out, check in, open) – versioned JSON, no secrets, requests are untrusted intents; design properties keep identity only; no live badge until SolidCraft has panels | 2026-11-22 | | [A hosted live demo](live-demo.md) | one public read-only account (`TEAMCRAFT_DEMO_USER`, password on the login page; every non-`GET` request refused, per-address sign-in throttle only) on an instance seeded with the README demo data (NIST CAD models), reset nightly to a database snapshot; no open sign-up, no editing, no per-visitor instances | 2026-11-14 | | [One download to try TeamCraft on a laptop](local-test-server.md) | bundle PostgreSQL's programs (theseus-rs builds, PostgreSQL Licence, newest 18.x, checksum-checked) with the desktop app and the server as `teamcraft-server`; `teamcraft local` runs a private cluster (scram, random password, 127.0.0.1 only, free port, no socket) and the server, and stops both when the app's stdin pipe closes; separate *with local server* installers for Windows x64, macOS Apple silicon and Linux x86_64; no new crate, no SQLite, no `postgresql_embedded` | 2026-11-14 | | [Deprovisioning through the identity provider (SCIM 2.0)](scim-deprovisioning.md) | not now: the target audience's IdPs (university SAML/OIDC proxies, Keycloak) send no SCIM; the idle-SSO report, idle token lifetimes and OIDC back-channel logout cover what they can signal (#173 step 9). Later: `active: false` (boolean or string, `PATCH` or `PUT`) → *Offboard and deactivate* with a configured default, soft delete only | 2026-11-12 | diff --git a/docs/src/research/solidcraft-bridge.md b/docs/src/research/solidcraft-bridge.md new file mode 100644 index 00000000..5dbc5028 --- /dev/null +++ b/docs/src/research/solidcraft-bridge.md @@ -0,0 +1,118 @@ +# Talking to the desktop app from inside SolidCraft + +## Question + +The TeamCraft plugin for SolidCraft (`plugins/solidcraft`) knows only what is +in the open design. Can it show live TeamCraft state (checked out by whom, +the latest revision on the server, the lifecycle state) and ask the desktop +app to act (check out, check in, open the item) – and still never fail hard +when the desktop app is not running? + +## Sources + +SolidCraft's open source (MIT OR Apache-2.0), read at the 0.45.0 tag and on +`main` (November 2026), and the installed SolidCraft 0.45.0 (Flatpak +`io.tangencylabs.solidcraft`) driven through `solidcraft-cli`. Only +documentation and source were read; no program code was decompiled. + +| Topic | Where | +|-------|-------| +| Plugin interface (WIT `craft:plugin@0.2.0`): `files`, `clock`, `commands` | `plugins/solidcraft/wit/plugin.wit` (SolidCraft's, unchanged) | +| Folder grants in the manifest (`permissions.files`) | `crates/craft-plugin/src/lib.rs`, `crates/engine/src/plugin/package.rs` | +| What a refused or failed host call does | `crates/craft-plugin-wasm/src/native.rs` (`fail`, `check`, `read_file`) | +| Installing with folders (`plugin.install {approve: {folders}}`) | `docs/plugins.md` | +| Control channel (port file, token, `control.subscribe`, `ui.documents`) | `docs/control-protocol.md` | +| Plugin storage, panels, listeners | `docs/plugins.md` | +| Flatpak file access (`xdg-documents` only) | `packaging/linux/flatpak/` | + +## Findings + +### Channels SolidCraft 0.45 offers a plugin + +| Channel | Works for | Verdict | +|---------|-----------|---------| +| **Files in a granted folder** | plugin reads state the desktop app writes; plugin writes requests | **use** | +| Design properties (`document.metadata.set`) | – | no: an edit (undo step, unsaved design, stale state saved and checked in) | +| Plugin storage (`storage.*`) | desktop reads only | no: writes only inside the plugin's run, saved into the design | +| Control channel (`127.0.0.1`, token file) | desktop → SolidCraft: which designs are open, unsaved | later, optional | +| Opening a URL (`teamcraft://`) | – | no: the plugin interface has no such import | +| Panels, live badges | – | not in 0.45 (no panel; listeners from 0.46, read-only) | + +The plugin has no network, so it cannot reach the server or the desktop app +directly. A **folder grant** is the one channel in both directions: + +- The manifest names a folder (`permissions.files: [{name, read, write}]`); + the user picks the real path when installing, or `plugin.install` gets it + (`approve.folders`). It is one fixed absolute folder, not "the design's + folder". Hidden names *below* the grant root are refused, a hidden root is + fine. +- A file that is not there is an answer the plugin gets back (`#17899`); a + folder that was never granted, or any other refused call, ends the run + with SolidCraft's own message – the plugin cannot catch it. +- Files are at most 1 MiB. A read entry cannot write files. +- Under Flatpak only `~/Documents` is reachable. The desktop app's default + working folder is `~/Documents/TeamCraft`, so the bridge folder + `/.teamcraft/solidcraft` is reachable from both. + +### Design properties stay for identity + +`teamcraft.pdm` in the design (written by *Item data* or the plugin's +*Link*) keeps the stable identity: item number, revision and `revision_id`. +`revision_id` is the key into the bridge folder. Live state never goes into +the design. + +## Decision + +A **bridge folder** `/.teamcraft/solidcraft/` that both sides +read and write, JSON files of at most 4 KiB, versioned: + +- `desktop.json` – the desktop app's heartbeat (`schema + "teamcraft.solidcraft.desktop"`, `version 1`, `written_at` in ms, whether + the server is reachable), rewritten every 30 s. +- `state/.json` – the state of one revision in the working + folder: item number, revision, who has it checked out (display name, and + whether it is me), the latest revision on the server, the local state and + lifecycle state, the actions offered. +- `requests/--.json` – an intent from the plugin: + `check_out`, `check_in`, `open` or `refresh`. The desktop app deletes it + when handled; the result shows in the state file. + +Rules: + +- The desktop app writes atomically (hidden temp file, rename). Unknown + fields are ignored; a newer major `version` says "update the plugin" or + "update TeamCraft". +- **No secrets** in the bridge: no tokens, no server credentials, display + names only. The folder is created `0700` where the system has modes. +- Requests are **untrusted intents**: the `revision_id` must be one in the + desktop app's working folder state (`[A-Za-z0-9-]` only), requests older + than 10 minutes are ignored, links, non-regular and oversized files are + refused. `check_in` only opens the desktop app's own check-in dialog; it + never runs silently. +- The existing entries (*status*, *check*, *link*, *unlink*) never touch + files, so they keep working without the grant. The live part comes as new + entries. + +What the user sees: + +| Situation | Message | +|-----------|---------| +| No state file | TeamCraft has no live state for {item} revision {rev}. Start the TeamCraft desktop app – it shares the state of the revisions in your working folder. | +| Heartbeat older than 2 minutes | The TeamCraft desktop app is not running (last seen {age} ago). As of then: … | +| Server not reachable | The TeamCraft desktop app has no connection to the server. As of {age} ago: … | +| Fresh state | Checked out by you · latest on the server B (you have A) · In work | +| Request while the desktop app is not running | Request saved. TeamCraft does it when the desktop app starts (within 10 minutes). | + +### Works with 0.45 as it is, and what needs SolidCraft + +| Part | 0.45 | +|------|------| +| State and requests through the bridge folder | yes | +| State refreshed when the user runs an entry | yes | +| A badge or panel that updates by itself | needs SolidCraft panels | +| Opening the TeamCraft page from the plugin | needs a URL import | +| Recovering from a missing folder grant inside the plugin | needs SolidCraft (the run ends) | +| Bridge folders outside `~/Documents` under Flatpak | needs a wider Flatpak permission | + +The control channel (which designs are open and unsaved, *save before +check-in*) is a later step on the desktop side only. From e6ea3abbbd27015cc7fc23b437356efe0b04ffb9 Mon Sep 17 00:00:00 2001 From: fork Date: Sun, 22 Nov 2026 10:16:52 +0100 Subject: [PATCH 6/7] =?UTF-8?q?SolidCraft=20plugin=20=E2=86=94=20desktop?= =?UTF-8?q?=20app=20through=20a=20shared=20folder?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit SolidCraft plugins have no network. The plugin and the desktop app share /.teamcraft/solidcraft (research page solidcraft-bridge): - desktop (src/scbridge.rs): a heartbeat every 30 s, the state of each revision on every Workspace refresh, and every 5 s the plugin's requests - checked (a revision of this working folder, a known action, fresh, small, a regular file, name = content), removed, handed to the UI; ui/js/solidcraft-bridge.js asks before a check-out and opens the check-in dialog for a check-in. - plugin: entries live, check-out, check-in and open (folder grant `teamcraft`, clock); the desktop app not running is a message, never a failure. The old entries never touch files. - 14 cases in plugins/solidcraft/tests/ pass on SolidCraft 0.45.0 (solidcraft-cli plugin test --require-cases); build.sh also makes the .zip SolidCraft installs. The desktop side is not built locally (CI is the check). Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 13 + README.md | 2 +- desktop/README.md | 2 + desktop/src/commands.rs | 59 ++- desktop/src/main.rs | 3 + desktop/src/scbridge.rs | 352 ++++++++++++++++++ desktop/ui/js/main.js | 3 + desktop/ui/js/solidcraft-bridge.js | 44 +++ docs/OPEN_WORK.md | 8 +- docs/src/dev/threat-model.md | 1 + docs/src/guide/desktop.md | 14 + docs/src/research/solidcraft-bridge.md | 12 +- plugins/solidcraft/README.md | 32 +- plugins/solidcraft/build.sh | 5 + plugins/solidcraft/plugin.json | 32 +- plugins/solidcraft/src/bridge.rs | 247 ++++++++++++ plugins/solidcraft/src/lib.rs | 19 + plugins/solidcraft/src/logic.rs | 291 ++++++++++++++- .../tests/bridge-fresh/desktop.json | 1 + .../bridge-fresh/state-PRT_2D000042.A.json | 3 + .../solidcraft/tests/check-in-request.json | 1 + plugins/solidcraft/tests/check-linked.json | 1 + .../solidcraft/tests/check-out-request.json | 1 + .../tests/link-refuses-empty-number.json | 1 + plugins/solidcraft/tests/link.json | 1 + plugins/solidcraft/tests/linked.sc | Bin 0 -> 4028 bytes .../tests/live-desktop-not-running.json | 1 + plugins/solidcraft/tests/live-fresh.json | 1 + plugins/solidcraft/tests/live-not-linked.json | 1 + .../solidcraft/tests/live-without-folder.json | 1 + plugins/solidcraft/tests/open-not-linked.json | 1 + plugins/solidcraft/tests/open-request.json | 1 + plugins/solidcraft/tests/status-linked.json | 1 + plugins/solidcraft/tests/status-unlinked.json | 1 + plugins/solidcraft/tests/unlink.json | 1 + 35 files changed, 1136 insertions(+), 21 deletions(-) create mode 100644 desktop/src/scbridge.rs create mode 100644 desktop/ui/js/solidcraft-bridge.js create mode 100644 plugins/solidcraft/src/bridge.rs create mode 100644 plugins/solidcraft/tests/bridge-fresh/desktop.json create mode 100644 plugins/solidcraft/tests/bridge-fresh/state-PRT_2D000042.A.json create mode 100644 plugins/solidcraft/tests/check-in-request.json create mode 100644 plugins/solidcraft/tests/check-linked.json create mode 100644 plugins/solidcraft/tests/check-out-request.json create mode 100644 plugins/solidcraft/tests/link-refuses-empty-number.json create mode 100644 plugins/solidcraft/tests/link.json create mode 100644 plugins/solidcraft/tests/linked.sc create mode 100644 plugins/solidcraft/tests/live-desktop-not-running.json create mode 100644 plugins/solidcraft/tests/live-fresh.json create mode 100644 plugins/solidcraft/tests/live-not-linked.json create mode 100644 plugins/solidcraft/tests/live-without-folder.json create mode 100644 plugins/solidcraft/tests/open-not-linked.json create mode 100644 plugins/solidcraft/tests/open-request.json create mode 100644 plugins/solidcraft/tests/status-linked.json create mode 100644 plugins/solidcraft/tests/status-unlinked.json create mode 100644 plugins/solidcraft/tests/unlink.json diff --git a/CHANGELOG.md b/CHANGELOG.md index 821fa08e..548764ee 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,19 @@ see the notices in the README. ### Added +- **SolidCraft plugin ↔ desktop app** (research page *Talking to the desktop + app from inside SolidCraft*). SolidCraft plugins have no network, so the + plugin and the desktop app share `/.teamcraft/solidcraft`: + the app writes a heartbeat and the state of each revision it shows, the + plugin's new entries read it and leave requests – *TeamCraft live status*, + *Check out in TeamCraft*, *Check in with TeamCraft*, *Open in TeamCraft*. + The app checks each request (a revision of its working folder, a known + action, fresh, small, a regular file), asks before a check-out and opens its + check-in dialog for a check-in. The app not running is never an error: the + plugin says so and shows what the app last knew; a request waits 10 minutes. + The old entries need no folder. 14 cases in `plugins/solidcraft/tests/` run + on the real SolidCraft (`solidcraft-cli plugin test --require-cases`), and + `build.sh` also makes the `.zip` SolidCraft installs. - **SolidCraft designs show their picture** (#364). The preview image of a `.sc` design is the PNG SolidCraft embeds when saving with its model, read from the ZIP container with size and CRC checks and shown only when its key diff --git a/README.md b/README.md index 640f6b92..ec60a453 100755 --- a/README.md +++ b/README.md @@ -324,7 +324,7 @@ end-to-end tests against a real PostgreSQL. - **SolidCraft and FieldCraft** – [SolidCraft](https://github.com/tangency-labs/solidcraft) designs (`.sc`, checked by content) and [FieldCraft](https://github.com/tangency-labs/fieldcraft) models (`.fieldcraft`) are recognised, SolidCraft's embedded picture is the preview image, linked designs are - file references with quantities, SolidCraft's BOM CSV and the design itself import as a BOM, the desktop app exports designs to STEP with `solidcraft-cli`, a TeamCraft plugin for SolidCraft shows and checks the design's TeamCraft item inside SolidCraft, and their STEP and 3MF + file references with quantities, SolidCraft's BOM CSV and the design itself import as a BOM, the desktop app exports designs to STEP with `solidcraft-cli`, a TeamCraft plugin for SolidCraft shows and checks the design's TeamCraft item inside SolidCraft – and, through a folder shared with the desktop app, its live state and requests to check out, check in or open it – and their STEP and 3MF exports previewed – design, export and analysis in one revision ([more](https://warr-ev.github.io/TeamCraft/reference/interop.html)). diff --git a/desktop/README.md b/desktop/README.md index 088b3895..cae14cfc 100755 --- a/desktop/README.md +++ b/desktop/README.md @@ -35,6 +35,7 @@ TeamCraft server – it is a client, not an offline copy. | Park | *Park…* (Workspace tab, *More ▾*, the check-in dialog): the ticked files go up as new versions through the upload endpoint (`POST …/files`) and the check-out **stays** – work in progress survives a lost laptop. After somebody else released your check-out, the Workspace tab shows *Released by X; your local changes are kept and need a new check-out* (`released` of the server's file status) | | Native CAD previews | The preview image stored in Inventor and Solid Edge files in the Files tab, a picture of the 3D preview for NX and SOLIDWORKS files; on Windows *STEP* in the Workspace tab and *Create STEP exports … first* at check-in export with the installed Inventor or Solid Edge (COM automation through Windows PowerShell; uses your own licence); on every system SolidCraft designs (`.sc`) export through SolidCraft's `solidcraft-cli run --in … --out ….stp` (found through `SOLIDCRAFT_CLI`, `PATH` or the default install folders). A failed export never stops the check-in: the file goes without its STEP and the result says why | | SolidCraft item data | *Item data* in the Workspace tab (SolidCraft designs of your check-out, not open in SolidCraft): `solidcraft-cli run