diff --git a/Cargo.lock b/Cargo.lock index cedd285..1c9d7f7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -136,7 +136,7 @@ dependencies = [ [[package]] name = "cultcache-rs" version = "0.3.1" -source = "git+https://github.com/GameCult/CultLib.git?rev=baf4ecf78fae634fafef956d3b85420162c074bb#baf4ecf78fae634fafef956d3b85420162c074bb" +source = "git+https://github.com/GameCult/CultLib.git?rev=9fc4bdda6a8620f846b58e89ddf476f4676d3e89#9fc4bdda6a8620f846b58e89ddf476f4676d3e89" dependencies = [ "anyhow", "chrono", @@ -157,7 +157,7 @@ dependencies = [ [[package]] name = "cultcache-rs-derive" version = "0.2.0" -source = "git+https://github.com/GameCult/CultLib.git?rev=baf4ecf78fae634fafef956d3b85420162c074bb#baf4ecf78fae634fafef956d3b85420162c074bb" +source = "git+https://github.com/GameCult/CultLib.git?rev=9fc4bdda6a8620f846b58e89ddf476f4676d3e89#9fc4bdda6a8620f846b58e89ddf476f4676d3e89" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index c469605..5645f78 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,5 +6,5 @@ members = [ ] [workspace.dependencies] -cultcache-rs = { git = "https://github.com/GameCult/CultLib.git", rev = "baf4ecf78fae634fafef956d3b85420162c074bb", package = "cultcache-rs" } +cultcache-rs = { git = "https://github.com/GameCult/CultLib.git", rev = "9fc4bdda6a8620f846b58e89ddf476f4676d3e89", package = "cultcache-rs" } diff --git a/brokkr-ctl/src/blender.rs b/brokkr-ctl/src/blender.rs index e2a7a40..36e7245 100644 --- a/brokkr-ctl/src/blender.rs +++ b/brokkr-ctl/src/blender.rs @@ -267,18 +267,34 @@ fn wait_for_receipt( id: &str, limit: Duration, ) -> Result { - let started = Instant::now(); - loop { - if let Some(receipt) = read_receipt(store, id)? { + match poll_until(limit, POLL, || read_receipt(store, id))? { + Some(receipt) => { print_fields(&receipt); let status = receipt.get("status").and_then(Value::as_str).unwrap_or(""); - return Ok(Outcome::from_status(status).code()); + Ok(Outcome::from_status(status).code()) + } + None => { + println!("status: timeout"); + Ok(Outcome::Timeout.code()) + } + } +} + +/// Reads until `read` yields a value or `limit` passes, sleeping `poll` between reads. +fn poll_until( + limit: Duration, + poll: Duration, + mut read: impl FnMut() -> Result>, +) -> Result> { + let started = Instant::now(); + loop { + if let Some(found) = read()? { + return Ok(Some(found)); } if started.elapsed() >= limit { - println!("status: timeout"); - return Ok(Outcome::Timeout.code()); + return Ok(None); } - thread::sleep(POLL); + thread::sleep(poll); } } @@ -617,6 +633,25 @@ mod tests { assert!(build_intent("../x", "abc", "a/b", "", &[]).is_err()); } + #[test] + fn polling_sleeps_between_reads_and_stops_at_the_limit() { + let mut reads = 0; + let found: Option = poll_until(Duration::from_millis(400), Duration::from_millis(100), || { + reads += 1; + Ok(None) + }) + .unwrap(); + assert_eq!(found, None); + assert!((2..=6).contains(&reads), "{reads} reads: the sleep paces them"); + let mut reads = 0; + let found = poll_until(Duration::from_secs(5), Duration::from_millis(100), || { + reads += 1; + Ok((reads == 3).then_some("receipt")) + }) + .unwrap(); + assert_eq!((found, reads), (Some("receipt"), 3)); + } + #[test] fn statuses_map_to_exit_codes() { for (status, code) in [("accepted", 0), ("denied", 2), ("failed", 2), ("stopped", 3), ("weird", 2)] { diff --git a/brokkr-ctl/tests/cli.rs b/brokkr-ctl/tests/cli.rs index c3df5a6..6161f6b 100644 --- a/brokkr-ctl/tests/cli.rs +++ b/brokkr-ctl/tests/cli.rs @@ -105,6 +105,16 @@ fn a_missing_store_is_not_created() { assert!(!path.exists()); } +#[test] +fn wait_matches_the_exact_receipt_key() { + let dir = tempfile::tempdir().unwrap(); + // receipts whose keys merely end with, or start with, the waited id are other commands' receipts + let path = store_with_receipts(dir.path(), &[("xr1", "accepted"), ("r1x", "accepted")]); + let output = ctl(&path, &["wait", "r1", "--timeout", "0.3"], None); + assert_eq!(output.status.code(), Some(4), "{}", stdout(&output)); + assert!(stdout(&output).contains("status: timeout")); +} + #[test] fn exit_code_follows_the_receipt() { let dir = tempfile::tempdir().unwrap(); diff --git a/docs/architecture.md b/docs/architecture.md index 9b102a9..843dbeb 100644 --- a/docs/architecture.md +++ b/docs/architecture.md @@ -100,7 +100,7 @@ Derived State: - Unity package settings are adapter configuration, not Verse authority. - Blender add-on preferences are adapter configuration, not Verse authority. -- Blender JSON debug exports are inspection/import probes, not mirror authority. +- Blender JSON debug exports are export-only inspection output, not mirror authority and never read back as intents. - Unity and Blender sync UI fields are command/edit affordances; the `brokkr.sync.*` documents are the shared sync policy surface. - Ad hoc syncvar editors write `brokkr.sync.var.v0` policy records only; they diff --git a/docs/live-collab-target.md b/docs/live-collab-target.md index fcfedaa..2853e5a 100644 --- a/docs/live-collab-target.md +++ b/docs/live-collab-target.md @@ -99,7 +99,7 @@ resident service on that number); reading a record's stored version through Aeth **One agent turn primitive.** Every agent mutation in Blender goes through one function in the add-on: admit (sink enabled, `requestedBy` present, id unused, action typed and valid), run the action with every operator called `undo=False`, push exactly one undo -step labelled `Brokkr : `, write the receipt. A +step labelled `Brokkr : `, write the receipt. A refusal caught before any write pushes nothing and leaves the scene unchanged; an action that fails after writing pushes one step labelled `(failed)`, so the partial write is one undoable step. There is no second @@ -254,7 +254,7 @@ are the primitive for the push. | Blender command intent `brokkr.blender.command_intent.v0` (gains `requestedBy`, `note`) | `blender/commands/{commandId}`; ids single-use, minted by the writer (`brush-tree:ruling:blender-sink-mirrors-unity`) | Written once by a caller. Executed at most once or refused. Removed when its receipt is written. Never rewritten. | Callers write. The agent turn primitive alone decides admission and execution. | | Blender command receipt `brokkr.blender.command_receipt.v0` (gains `requestedBy`, `outcome` in accepted, denied, stopped, failed, `undoLabel`, `lookPath`) | `blender/receipts/{commandId}`, one per intent | Written once, after the primitive decides. Pruned by count with Unity's cap and prune rule. | The primitive alone. Callers and the panel read. | | Agent identity `requestedBy` | `/` stated by the caller | Carried on each intent into its receipt and undo label; not stored on its own. | The caller states it; the primitive refuses an intent without it. The session token proves admission, not identity. | -| Agent undo step | Blender undo entry `Brokkr : ` | One per accepted mutating intent; lives as Blender's stack does; never persisted by Brokkr. | Blender owns the stack; the primitive pushes; only the human undoes or redoes. | +| Agent undo step | Blender undo entry `Brokkr : ` | One per accepted mutating intent; lives as Blender's stack does; never persisted by Brokkr. | Blender owns the stack; the primitive pushes; only the human undoes or redoes. | | Blender session id | uuid minted at add-on register and on each `load_post` | Replaced when Blender restarts or a file loads. | The add-on alone. | | Human-edit sequences (snapshot: `humanEditSeq`, per-object `lastHumanEditSeq`) | Integers within a session id | Monotonic within a session; reset with it. Information for the agent; they gate nothing. | The add-on's depsgraph and undo handlers alone. | | Host snapshot `brokkr.blender.host_snapshot.v0` (gains Edit Mode selection, session id, sequences, sink state, authoring binding summary) | `blender/host/current`, overwritten | Refreshed on depsgraph update and after each intent. | The add-on alone. | diff --git a/surfaces/blender/brokkr_bridge/blender_manifest.toml b/surfaces/blender/brokkr_bridge/blender_manifest.toml index ec5feed..cbdf1d8 100644 --- a/surfaces/blender/brokkr_bridge/blender_manifest.toml +++ b/surfaces/blender/brokkr_bridge/blender_manifest.toml @@ -6,10 +6,8 @@ tagline = "Brokkr command intents, receipts and snapshots over CultMesh" maintainer = "GameCult " type = "add-on" blender_version_min = "5.3.0" -platforms = ["windows-x64"] license = ["SPDX:GPL-3.0-or-later"] -# CultLib's cultnet-py and cultcache-py import msgpack; Blender's Python does not ship it. The wheel is -# the installed msgpack 1.2.2 CPython 3.13 Windows build (Blender 5.3 runs Python 3.13). The C extension -# matters: CultLib at baf4ecf7 fails on msgpack's pure-Python fallback (object_pairs_hook gets a generator). -# Linux and macOS wheels are not bundled yet. -wheels = ["./wheels/msgpack-1.2.2-cp313-cp313-win_amd64.whl"] +# CultLib's cultnet-py and cultcache-py import msgpack; Blender's Python does not ship it. The wheel is one +# pure-Python msgpack 1.2.2 (no C extension), so the extension is platform-independent; CultLib 9fc4bdda +# (PR #180) decodes under msgpack's pure-Python fallback. Source and hash: docs/install.md. +wheels = ["./wheels/msgpack-1.2.2-py3-none-any.whl"] diff --git a/surfaces/blender/brokkr_bridge/blender_target.py b/surfaces/blender/brokkr_bridge/blender_target.py index 8684e8e..8302a69 100644 --- a/surfaces/blender/brokkr_bridge/blender_target.py +++ b/surfaces/blender/brokkr_bridge/blender_target.py @@ -542,7 +542,7 @@ class BrokkrBlenderTarget: self._receipted.add(command_id) return self._receipt(command, "denied", denial, "") - label = f"Brokkr {requested_by}: {action} {command_id[:8]}" + label = f"Brokkr {requested_by}: {action} {command_id[-8:]}" # the tail: uuid v7 ids lead with a timestamp, one value per minute push = action not in READ_ACTIONS and action not in NO_SCENE_CHANGE_ACTIONS self.agent_turn = True self._wrote = True diff --git a/surfaces/blender/brokkr_bridge/node_actions.py b/surfaces/blender/brokkr_bridge/node_actions.py index aba236d..389a536 100644 --- a/surfaces/blender/brokkr_bridge/node_actions.py +++ b/surfaces/blender/brokkr_bridge/node_actions.py @@ -254,6 +254,7 @@ class NodeActions: doomed = [l for l in tree.links if l.to_socket == into and (out is None or l.from_socket == out)] for link in doomed: tree.links.remove(link) + self.changed = bool(doomed) # no link matched: no undo step return f"Removed {len(doomed)} link(s).", tree.name def _linkSockets(self, command: dict[str, Any]) -> tuple[str, str]: diff --git a/surfaces/blender/brokkr_bridge/wheels/msgpack-1.2.2-cp313-cp313-win_amd64.whl b/surfaces/blender/brokkr_bridge/wheels/msgpack-1.2.2-cp313-cp313-win_amd64.whl deleted file mode 100644 index 83a8682..0000000 Binary files a/surfaces/blender/brokkr_bridge/wheels/msgpack-1.2.2-cp313-cp313-win_amd64.whl and /dev/null differ diff --git a/surfaces/blender/brokkr_bridge/wheels/msgpack-1.2.2-py3-none-any.whl b/surfaces/blender/brokkr_bridge/wheels/msgpack-1.2.2-py3-none-any.whl new file mode 100644 index 0000000..832d545 Binary files /dev/null and b/surfaces/blender/brokkr_bridge/wheels/msgpack-1.2.2-py3-none-any.whl differ diff --git a/surfaces/blender/docs/install.md b/surfaces/blender/docs/install.md index f29c195..6452905 100644 --- a/surfaces/blender/docs/install.md +++ b/surfaces/blender/docs/install.md @@ -33,7 +33,7 @@ The command prints the record count and leaves the source unwritten. Records a n CultLib's `cultnet-py` and `cultcache-py` import `msgpack`, and Blender's Python does not ship it. Install Brokkr as an extension so Blender installs it for you: `surfaces/blender/brokkr_bridge/blender_manifest.toml` lists the bundled wheel -`wheels/msgpack-1.2.2-cp313-cp313-win_amd64.whl`, which Blender unpacks into the extension's own +`wheels/msgpack-1.2.2-py3-none-any.whl`, which Blender unpacks into the extension's own site-packages when the extension is enabled. Build and install it: ```text @@ -41,12 +41,21 @@ blender --command extension build --source-dir surfaces/blender/brokkr_bridge -- blender --command extension install-file --repo user_default --enable /brokkr_bridge-0.2.0.zip ``` -The bundled wheel is msgpack 1.2.2 for CPython 3.13 on Windows x64 (Blender 5.3's Python), -repacked from the installed package with its Apache-2.0 licence; the extension is therefore -declared `windows-x64`, Blender 5.3 or newer. The C extension matters: CultLib at `baf4ecf7` -fails on msgpack's pure-Python fallback. Linux and macOS wheels are not bundled yet: there, -or in a plain add-on directory install, put `msgpack` into Blender's Python yourself. A -CultLib package missing a module is reported by that module's name, not as a missing +The wheel is one pure-Python msgpack, so the extension carries no platform restriction (Blender 5.3 or +newer, any OS). msgpack then runs its pure-Python fallback, which CultLib `9fc4bdda` (PR #180) decodes. + +Wheel provenance: msgpack 1.2.2 as installed on the build host (CPython 3.13, the PyPI release; nothing +was downloaded), repacked by `tools/build-msgpack-wheel.py` from its `msgpack/__init__.py`, `exceptions.py`, +`ext.py` and `fallback.py` (the `_cmsgpack` C extension is left out) with the package's METADATA and +Apache-2.0 `COPYING`. The repack is deterministic; rebuild and compare: + +```text +python tools/build-msgpack-wheel.py +sha256 0b53d2ea2e21782a670fc152bb104d97623cfa337940518016a6b7ded369af42 msgpack-1.2.2-py3-none-any.whl +``` + +In a plain add-on directory install the wheel is not unpacked: put `msgpack` into Blender's Python +yourself. A CultLib package missing a module is reported by that module's name, not as a missing CultLib package. The default node cache is: diff --git a/surfaces/blender/tests/live/agent_turn_queue.py b/surfaces/blender/tests/live/agent_turn_queue.py index f2b2d3c..1521ba0 100644 --- a/surfaces/blender/tests/live/agent_turn_queue.py +++ b/surfaces/blender/tests/live/agent_turn_queue.py @@ -39,6 +39,8 @@ bt = importlib.import_module(MODULE + ".blender_target") try: import msgpack R["msgpack"] = msgpack.__file__ + R["msgpack_packer"] = msgpack.Packer.__module__ # msgpack.fallback: the pure-Python codec, no C extension + R["msgpack_purepython_env"] = os.environ.get("MSGPACK_PUREPYTHON", "") except ImportError: R["msgpack"] = None prefs = bpy.context.preferences.addons[MODULE].preferences @@ -144,7 +146,7 @@ def q1_check(): R["receipts"]["q1"] = r S["q1_label"] = r and r.get("undoLabel") check("queue: createObject drained by the add-on timer, accepted, labelled, attributed", - r and r["status"] == "accepted" and r["undoLabel"] == "Brokkr nibu/hands: createObject aaaaaaaa" + r and r["status"] == "accepted" and r["undoLabel"] == "Brokkr nibu/hands: createObject aaa-0001" # the id's last 8 characters and r["requestedBy"] == "nibu/hands" and r["note"] == "queue test" and "QCube" in names(), r) check("queue: a command JSON under the debug root is inert (kept, never run, never receipted); the receipt export still lands", (SCRATCH / "debug" / "blender" / "commands" / "door-0001.json").exists() and "QDoor" not in names() diff --git a/surfaces/blender/tests/live/agent_turn_queue.result.json b/surfaces/blender/tests/live/agent_turn_queue.result.json index e76bb3f..e1c803e 100644 --- a/surfaces/blender/tests/live/agent_turn_queue.result.json +++ b/surfaces/blender/tests/live/agent_turn_queue.result.json @@ -15,8 +15,8 @@ "objectName": "QCube", "requestedBy": "nibu/hands", "note": "queue test", - "undoLabel": "Brokkr nibu/hands: createObject aaaaaaaa", - "observedAt": "2026-11-27T19:32:00.583673+00:00" + "undoLabel": "Brokkr nibu/hands: createObject aaa-0001", + "observedAt": "2026-11-27T20:02:43.826604+00:00" } }, { @@ -46,8 +46,8 @@ "objectName": "QCube", "requestedBy": "nibu/hands", "note": "queue test", - "undoLabel": "Brokkr nibu/hands: createObject aaaaaaaa", - "observedAt": "2026-11-27T19:32:00.583673+00:00" + "undoLabel": "Brokkr nibu/hands: createObject aaa-0001", + "observedAt": "2026-11-27T20:02:43.826604+00:00" } }, { @@ -63,7 +63,7 @@ "requestedBy": "nibu/hands", "note": "", "undoLabel": "", - "observedAt": "2026-11-27T19:32:02.587784+00:00" + "observedAt": "2026-11-27T20:02:45.831074+00:00" } }, { @@ -79,7 +79,7 @@ "requestedBy": "", "note": "", "undoLabel": "", - "observedAt": "2026-11-27T19:32:04.590532+00:00" + "observedAt": "2026-11-27T20:02:47.837505+00:00" } }, { @@ -134,8 +134,8 @@ "objectName": "QCube", "requestedBy": "nibu/hands", "note": "queue test", - "undoLabel": "Brokkr nibu/hands: createObject aaaaaaaa", - "observedAt": "2026-11-27T19:32:00.583673+00:00" + "undoLabel": "Brokkr nibu/hands: createObject aaa-0001", + "observedAt": "2026-11-27T20:02:43.826604+00:00" }, "q2_original": { "schema": "brokkr.blender.command_receipt.v0", @@ -146,8 +146,8 @@ "objectName": "QCube", "requestedBy": "nibu/hands", "note": "queue test", - "undoLabel": "Brokkr nibu/hands: createObject aaaaaaaa", - "observedAt": "2026-11-27T19:32:00.583673+00:00" + "undoLabel": "Brokkr nibu/hands: createObject aaa-0001", + "observedAt": "2026-11-27T20:02:43.826604+00:00" }, "q2_denial": { "schema": "brokkr.blender.command_receipt.v0", @@ -159,7 +159,7 @@ "requestedBy": "nibu/hands", "note": "", "undoLabel": "", - "observedAt": "2026-11-27T19:32:02.587784+00:00" + "observedAt": "2026-11-27T20:02:45.831074+00:00" }, "q3": { "schema": "brokkr.blender.command_receipt.v0", @@ -171,12 +171,12 @@ "requestedBy": "", "note": "", "undoLabel": "", - "observedAt": "2026-11-27T19:32:04.590532+00:00" + "observedAt": "2026-11-27T20:02:47.837505+00:00" }, "q6": [ { "schema": "brokkr.blender.command_receipt.v0", - "commandId": "8fe2e26fece047bcaca1b9938f1a030c", + "commandId": "3414cf427aa549ea9e9a52c4cfc61908", "action": "createObject", "status": "denied", "message": "Intent has no commandId of 1 to 128 letters, digits, '_' or '-'. (queue key blender/commands/bad-int)", @@ -184,11 +184,11 @@ "requestedBy": "nibu/hands", "note": "", "undoLabel": "", - "observedAt": "2026-11-27T19:32:08.599229+00:00" + "observedAt": "2026-11-27T20:02:51.875508+00:00" }, { "schema": "brokkr.blender.command_receipt.v0", - "commandId": "b1a5c7e22158468bb06f6b500c4fa2a7", + "commandId": "3c53313e68aa4d07ab6e3e330396567d", "action": "createObject", "status": "denied", "message": "Intent has no commandId of 1 to 128 letters, digits, '_' or '-'. (queue key blender/commands/bad-list)", @@ -196,7 +196,7 @@ "requestedBy": "nibu/hands", "note": "", "undoLabel": "", - "observedAt": "2026-11-27T19:32:08.621069+00:00" + "observedAt": "2026-11-27T20:02:51.901697+00:00" } ], "q5": [ @@ -210,7 +210,7 @@ "requestedBy": "nibu/hands", "note": "", "undoLabel": "", - "observedAt": "2026-11-27T19:32:10.606424+00:00" + "observedAt": "2026-11-27T20:02:53.881094+00:00" }, { "schema": "brokkr.blender.command_receipt.v0", @@ -222,7 +222,7 @@ "requestedBy": "nibu/hands", "note": "", "undoLabel": "", - "observedAt": "2026-11-27T19:32:10.629698+00:00" + "observedAt": "2026-11-27T20:02:53.905589+00:00" }, { "schema": "brokkr.blender.command_receipt.v0", @@ -234,10 +234,12 @@ "requestedBy": "nibu/hands", "note": "", "undoLabel": "", - "observedAt": "2026-11-27T19:32:10.665150+00:00" + "observedAt": "2026-11-27T20:02:53.944684+00:00" } ] }, - "msgpack": "F:\\aeth-wt\\brokkr-live-1.e2e\\res\\extensions\\.local\\lib\\python3.13\\site-packages\\msgpack\\__init__.py", + "msgpack": "F:\\aeth-wt\\brokkr-live-pins.e2e\\res\\extensions\\.local\\lib\\python3.13\\site-packages\\msgpack\\__init__.py", + "msgpack_packer": "msgpack.fallback", + "msgpack_purepython_env": "", "ok": true } \ No newline at end of file diff --git a/surfaces/blender/tests/live/agent_turn_undo.result.json b/surfaces/blender/tests/live/agent_turn_undo.result.json index 0437128..248b79b 100644 --- a/surfaces/blender/tests/live/agent_turn_undo.result.json +++ b/surfaces/blender/tests/live/agent_turn_undo.result.json @@ -5,7 +5,7 @@ { "name": "createObject accepted with undoLabel", "ok": true, - "detail": "Brokkr nibu/hands: createObject 00000001" + "detail": "Brokkr nibu/hands: createObject ent-turn" }, { "name": "transform applied", @@ -197,7 +197,7 @@ "name": "exportGltf and renderStill accepted with no undoLabel", "ok": true, "detail": [ - "Exported glTF to C:\\Users\\Meta\\AppData\\Local\\Temp\\brokkr-live2-_y_dg6ko\\object.glb (3484 bytes).", + "Exported glTF to C:\\Users\\Meta\\AppData\\Local\\Temp\\brokkr-live2-0ge72kvx\\object.glb (3484 bytes).", "Rendered still to object.png." ] }, @@ -215,19 +215,19 @@ { "intent": "createObject", "status": "accepted", - "undoLabel": "Brokkr nibu/hands: createObject 00000001", + "undoLabel": "Brokkr nibu/hands: createObject ent-turn", "message": "Blender object created." }, { "intent": "setObjectTransform", "status": "accepted", - "undoLabel": "Brokkr nibu/hands: setObjectTransform 00000002", + "undoLabel": "Brokkr nibu/hands: setObjectTransform ent-turn", "message": "Blender object transform updated." }, { "intent": "createObject", "status": "accepted", - "undoLabel": "Brokkr nibu/hands: createObject 00000003", + "undoLabel": "Brokkr nibu/hands: createObject ent-turn", "message": "Blender object created." }, { @@ -263,14 +263,14 @@ { "intent": "createObject", "status": "accepted", - "undoLabel": "Brokkr nibu/hands: createObject 00000009", + "undoLabel": "Brokkr nibu/hands: createObject ent-turn", "message": "Blender object created." }, { "intent": "exportGltf", "status": "accepted", "undoLabel": "", - "message": "Exported glTF to C:\\Users\\Meta\\AppData\\Local\\Temp\\brokkr-live2-_y_dg6ko\\object.glb (3484 bytes)." + "message": "Exported glTF to C:\\Users\\Meta\\AppData\\Local\\Temp\\brokkr-live2-0ge72kvx\\object.glb (3484 bytes)." }, { "intent": "renderStill", diff --git a/surfaces/blender/tests/test_agent_turn.py b/surfaces/blender/tests/test_agent_turn.py index 02706de..cf78e9b 100644 --- a/surfaces/blender/tests/test_agent_turn.py +++ b/surfaces/blender/tests/test_agent_turn.py @@ -56,12 +56,24 @@ class AgentTurnTests(unittest.TestCase): def test_accepted_receipt_carries_undo_label(self): receipt = self.run_action(action="createObject", objectType="EMPTY", commandId="abcdef0123456789", requestedBy="nibu/hands", note="x" * 300) - label = "Brokkr nibu/hands: createObject abcdef01" + label = "Brokkr nibu/hands: createObject 23456789" # the id's tail: uuid v7 ids lead with a timestamp self.assertEqual(self.bpy.undo.pushes, [label]) self.assertEqual(receipt["undoLabel"], label) self.assertEqual(receipt["requestedBy"], "nibu/hands") self.assertEqual(len(receipt["note"]), 200) + def test_two_sends_a_minute_apart_get_distinct_labels(self): + # brokkr-ctl ids are uuid v7: the first 8 hex are one value per 65 seconds, the tail is random + self.run_action(action="createObject", objectType="EMPTY", commandId="01a21e88" + "0" * 16 + "aaaa1111") + self.run_action(action="createObject", objectType="EMPTY", commandId="01a21e88" + "0" * 16 + "bbbb2222") + self.assertEqual(len(set(self.bpy.undo.pushes)), 2, self.bpy.undo.pushes) + + def test_architecture_page_does_not_call_the_debug_json_an_import_path(self): + page = (SOURCE.parents[3] / "docs" / "architecture.md").read_text(encoding="utf-8") + for line in page.splitlines(): + if "debug" in line.lower() and "json" in line.lower(): + self.assertNotRegex(line.lower(), r"import", line) + def test_refusal_pushes_nothing(self): receipt = self.run_action(action="createObject", objectType="BOGUS") self.assertEqual(receipt["status"], "failed") @@ -79,7 +91,7 @@ class AgentTurnTests(unittest.TestCase): self.bpy.ops.object.empty_add = boom receipt = self.run_action(action="createObject", objectType="EMPTY", commandId="deadbeef99") self.assertEqual(receipt["status"], "failed") - self.assertEqual(self.bpy.undo.pushes, ["Brokkr nibu/hands: createObject deadbeef (failed)"]) + self.assertEqual(self.bpy.undo.pushes, ["Brokkr nibu/hands: createObject adbeef99 (failed)"]) def test_agent_turn_flag_is_scoped(self): seen = [] diff --git a/surfaces/blender/tests/test_extension_wheel.py b/surfaces/blender/tests/test_extension_wheel.py new file mode 100644 index 0000000..36c3b0d --- /dev/null +++ b/surfaces/blender/tests/test_extension_wheel.py @@ -0,0 +1,43 @@ +"""The extension's one bundled wheel is pure Python, matches its recorded hash, and the manifest does not pin a platform.""" +from __future__ import annotations + +import base64 +import hashlib +import re +import tomllib +import unittest +import zipfile +from pathlib import Path + +ADDON = Path(__file__).resolve().parents[1] / "brokkr_bridge" +INSTALL = Path(__file__).resolve().parents[1] / "docs" / "install.md" + + +class ExtensionWheelTests(unittest.TestCase): + def setUp(self): + self.manifest = tomllib.loads((ADDON / "blender_manifest.toml").read_text(encoding="utf-8")) + + def test_one_pure_python_wheel_and_no_platform_restriction(self): + self.assertEqual(len(self.manifest["wheels"]), 1) + wheel = ADDON / self.manifest["wheels"][0] + self.assertTrue(wheel.name.endswith("-py3-none-any.whl"), wheel.name) + self.assertNotIn("platforms", self.manifest) + with zipfile.ZipFile(wheel) as z: + names = z.namelist() + self.assertEqual([n for n in names if n.endswith((".pyd", ".so", ".dylib"))], []) + self.assertIn("Root-Is-Purelib: true", z.read("msgpack-1.2.2.dist-info/WHEEL").decode()) + for line in z.read("msgpack-1.2.2.dist-info/RECORD").decode().splitlines(): + name, digest, size = line.split(",") + if digest: + data = z.read(name) + self.assertEqual(digest, "sha256=" + base64.urlsafe_b64encode(hashlib.sha256(data).digest()).rstrip(b"=").decode(), name) + self.assertEqual(int(size), len(data), name) + + def test_install_doc_records_the_wheel_hash(self): + wheel = ADDON / self.manifest["wheels"][0] + recorded = re.findall(r"\b[0-9a-f]{64}\b", INSTALL.read_text(encoding="utf-8")) + self.assertIn(hashlib.sha256(wheel.read_bytes()).hexdigest(), recorded) + + +if __name__ == "__main__": + unittest.main() diff --git a/surfaces/blender/tests/test_node_actions.py b/surfaces/blender/tests/test_node_actions.py index 6aeee39..f69cc07 100644 --- a/surfaces/blender/tests/test_node_actions.py +++ b/surfaces/blender/tests/test_node_actions.py @@ -559,7 +559,11 @@ class NodeActionTests(unittest.TestCase): self.accepted(action="linkSockets", treeKey="G", fromNode="a", fromSocket="Out", toNode="c", toSocket="A") self.accepted(action="linkSockets", treeKey="G", fromNode="b", fromSocket="Out", toNode="c", toSocket="Size") self.refused(action="unlinkSockets", treeKey="G", fromNode="zzz", fromSocket="Out", toNode="c", toSocket="A") - self.assertIn("Removed 0", self.accepted(action="unlinkSockets", treeKey="G", fromNode="b", fromSocket="Out", toNode="c", toSocket="A")["message"]) + pushes = len(self.bpy.undo.pushes) + empty = self.accepted(action="unlinkSockets", treeKey="G", fromNode="b", fromSocket="Out", toNode="c", toSocket="A") + self.assertIn("Removed 0", empty["message"]) + self.assertEqual(len(self.bpy.undo.pushes), pushes) # nothing changed: no undo step + self.assertEqual(empty["undoLabel"], "") self.assertEqual(len(tree.links), 2) self.assertIn("Removed 1", self.accepted(action="unlinkSockets", treeKey="G", fromNode="a", fromSocket="Out", toNode="c", toSocket="A")["message"]) self.assertEqual(len(tree.links), 1) diff --git a/tools/build-msgpack-wheel.py b/tools/build-msgpack-wheel.py new file mode 100644 index 0000000..a6d67af --- /dev/null +++ b/tools/build-msgpack-wheel.py @@ -0,0 +1,27 @@ +"""Repack the installed msgpack's pure-Python modules as one py3-none-any wheel (no download, no C extension). + +usage: python tools/build-msgpack-wheel.py +Deterministic: the same installed msgpack gives the same bytes, so the sha256 in install.md is checkable. +""" +import base64, hashlib, importlib.metadata as md, pathlib, sys, zipfile + +PURE = ("__init__.py", "exceptions.py", "ext.py", "fallback.py") # _cmsgpack is the C extension: left out +dist = md.distribution("msgpack") +version = dist.version +site = pathlib.Path(dist.locate_file("")) +files = {f"msgpack/{name}": (site / "msgpack" / name).read_bytes() for name in PURE} +info = f"msgpack-{version}.dist-info" +files[f"{info}/METADATA"] = dist.read_text("METADATA").encode() +files[f"{info}/top_level.txt"] = b"msgpack\n" +files[f"{info}/licenses/COPYING"] = (site / info / "licenses" / "COPYING").read_bytes() +files[f"{info}/WHEEL"] = b"Wheel-Version: 1.0\nGenerator: brokkr tools/build-msgpack-wheel.py\nRoot-Is-Purelib: true\nTag: py3-none-any\n" +digest = lambda data: "sha256=" + base64.urlsafe_b64encode(hashlib.sha256(data).digest()).rstrip(b"=").decode() +files[f"{info}/RECORD"] = ("".join(f"{n},{digest(d)},{len(d)}\n" for n, d in files.items()) + f"{info}/RECORD,,\n").encode() + +out = pathlib.Path(sys.argv[1]) / f"msgpack-{version}-py3-none-any.whl" +with zipfile.ZipFile(out, "w", zipfile.ZIP_DEFLATED) as z: + for name, data in files.items(): + entry = zipfile.ZipInfo(name, (1980, 1, 1, 0, 0, 0)) + entry.compress_type, entry.external_attr = zipfile.ZIP_DEFLATED, 0o644 << 16 + z.writestr(entry, data) +print(out, hashlib.sha256(out.read_bytes()).hexdigest())