Blender: cut the debug-mirror JSON intent door; one admission shape fix
Intents now enter only through the node (brokkr-ctl, a served peer, the sync organ). _import_debug_command_files, the debug-root glob in purge_command_intents and start_server's debug-root parameter are deleted; Debug Export Root stays export-only. Also live-2-lows: COMMAND_ID_SHAPE and REQUESTED_BY_SHAPE use fullmatch (a trailing newline passed), and _load_cultmesh's own-package set is pinned. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
50fe9c1aa1
commit
741e186c5a
9 changed files with 102 additions and 97 deletions
|
|
@ -30,7 +30,7 @@ broker.
|
|||
|
||||
- `surfaces/unity/Packages/com.gamecult.brokkr`: Unity editor package scaffold.
|
||||
- `surfaces/blender/brokkr_bridge`: Blender add-on target backed by
|
||||
CultLib's Python CultMesh node/server, with optional debug export/import
|
||||
CultLib's Python CultMesh node/server, with an optional debug export
|
||||
probes.
|
||||
- `brokkr-command`: .NET CLI that writes one Unity command intent through the
|
||||
project's directory store and reports the editor's receipt (`docs/provider-contract.md`).
|
||||
|
|
|
|||
|
|
@ -236,8 +236,8 @@ are the primitive for the push.
|
|||
collections (an edit buffer over the `.cc`); the stdin dump (a pipe, not state).
|
||||
- **Forbidden writers.** `execute_command` called around the primitive; operators run
|
||||
with undo on inside an agent action; unpushed agent writes; `ed.undo`/`ed.redo` from
|
||||
add-on code; any agent-sent Python; the debug-mirror JSON import as a door for intents
|
||||
(`blender_target.py` `_import_debug_command_files`); `brokkr-ctl` deciding anything;
|
||||
add-on code; any agent-sent Python; any reader that turns a file under
|
||||
the debug-mirror root into an intent (removed in cut-live-1); `brokkr-ctl` deciding anything;
|
||||
`ship_cc.py`'s envelope writes and any other direct `.cc` writer; `layout_revision`
|
||||
as a revision.
|
||||
- **Shared paths.** brokkr-ctl intents, panel buttons that act on the scene, sync-organ
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ class BrokkrPreferences(bpy.types.AddonPreferences):
|
|||
name="Debug Export Root",
|
||||
subtype="DIR_PATH",
|
||||
default=DEFAULT_DEBUG_MIRROR_ROOT,
|
||||
description="Optional JSON debug export/import root; CultMesh remains the mirror owner",
|
||||
description="Optional JSON debug export root (export only); CultMesh remains the mirror owner",
|
||||
)
|
||||
|
||||
import_dir: bpy.props.StringProperty(
|
||||
|
|
@ -476,7 +476,6 @@ class BROKKR_OT_start_server(bpy.types.Operator):
|
|||
prefs.serve_port,
|
||||
prefs.max_snapshot_documents,
|
||||
prefs.max_snapshot_bytes,
|
||||
prefs.debug_mirror_root,
|
||||
prefs.allow_non_loopback,
|
||||
prefs.require_session_token,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -109,11 +109,11 @@ class BrokkrBlenderTarget:
|
|||
self._server: Any | None = None
|
||||
self._guard: SessionGuard | None = None
|
||||
self._cultmesh_module: str = ""
|
||||
self._debug_mirror_root: str = ""
|
||||
self.import_dir: str = ""
|
||||
self.output_dir: str = ""
|
||||
self.nodes = na.NodeActions(bpy_module)
|
||||
self.agent_turn = False # true only inside run_intent
|
||||
self._wrote = True # run_intent: false when an accepted action changed nothing
|
||||
self._receipted: set[str] = set()
|
||||
|
||||
def configure_action_dirs(self, import_dir: str, output_dir: str) -> None:
|
||||
|
|
@ -150,9 +150,6 @@ class BrokkrBlenderTarget:
|
|||
debug_mirror_root: str = "",
|
||||
) -> list[dict[str, Any]]:
|
||||
node, documents = self._open_node(cache_path, cultlib_py_src)
|
||||
if debug_mirror_root:
|
||||
self._import_debug_command_files(node, documents["command_intent"], debug_mirror_root)
|
||||
|
||||
snapshot = node.database.snapshot()
|
||||
commands = snapshot.get(COMMAND_INTENT_SCHEMA, {})
|
||||
receipts: list[dict[str, Any]] = []
|
||||
|
|
@ -365,7 +362,6 @@ class BrokkrBlenderTarget:
|
|||
port: int,
|
||||
max_snapshot_documents: int,
|
||||
max_snapshot_bytes: int,
|
||||
debug_mirror_root: str = "",
|
||||
allow_non_loopback: bool = False,
|
||||
require_token: bool = False,
|
||||
) -> dict[str, Any]:
|
||||
|
|
@ -391,8 +387,7 @@ class BrokkrBlenderTarget:
|
|||
|
||||
self.stop_server()
|
||||
self._cultmesh_module = ""
|
||||
self._debug_mirror_root = self.resolve_debug_mirror_root(debug_mirror_root) if debug_mirror_root else ""
|
||||
purge_command_intents(node, documents["command_intent"], COMMAND_INTENT_SCHEMA, self._debug_mirror_root)
|
||||
purge_command_intents(node, documents["command_intent"], COMMAND_INTENT_SCHEMA)
|
||||
cultmesh, _cultcache = _load_cultmesh(cultlib_py_src)
|
||||
self._cultmesh_module = str(getattr(cultmesh, "__file__", "") or "")
|
||||
verse_catalog = cultmesh.CultMesh.create_verse_catalog()
|
||||
|
|
@ -463,7 +458,7 @@ class BrokkrBlenderTarget:
|
|||
finally:
|
||||
try:
|
||||
if was_running and self._node is not None:
|
||||
purge_command_intents(self._node, self._documents["command_intent"], COMMAND_INTENT_SCHEMA, self._debug_mirror_root)
|
||||
purge_command_intents(self._node, self._documents["command_intent"], COMMAND_INTENT_SCHEMA)
|
||||
finally:
|
||||
self._server = None
|
||||
self._server_key = None
|
||||
|
|
@ -535,7 +530,7 @@ class BrokkrBlenderTarget:
|
|||
denial = "Intent has no commandId of 1 to 128 letters, digits, '_' or '-'."
|
||||
elif command_id in self._receipted:
|
||||
denial = f"commandId {command_id!r} was already receipted; ids are single-use."
|
||||
elif not isinstance(requested_by, str) or not REQUESTED_BY_SHAPE.match(requested_by):
|
||||
elif not isinstance(requested_by, str) or not REQUESTED_BY_SHAPE.fullmatch(requested_by):
|
||||
denial = "Intent has no requestedBy of the form '<mind>/<agent>'."
|
||||
elif action not in MUTATING_ACTIONS and action not in READ_ACTIONS and action not in na.NodeActions.ACTIONS:
|
||||
denial = f"Unsupported Blender command action: {action}"
|
||||
|
|
@ -550,11 +545,12 @@ class BrokkrBlenderTarget:
|
|||
label = f"Brokkr {requested_by}: {action} {command_id[:8]}"
|
||||
push = action not in READ_ACTIONS and action not in NO_SCENE_CHANGE_ACTIONS
|
||||
self.agent_turn = True
|
||||
self._wrote = True
|
||||
try:
|
||||
try:
|
||||
receipt = self._dispatch(context, command)
|
||||
if receipt["status"] != "accepted":
|
||||
push = False # returned a refusal: it wrote nothing
|
||||
if receipt["status"] != "accepted" or not self._wrote:
|
||||
push = False # a refusal, or an accepted no-op: it wrote nothing
|
||||
except sa.ActionRefused as error: # raised before any write: nothing to push
|
||||
receipt, push = self._receipt(command, "failed", str(error), ""), False
|
||||
except Exception as error: # a partial write is one undoable step, not part of her next action
|
||||
|
|
@ -621,6 +617,7 @@ class BrokkrBlenderTarget:
|
|||
return self._render_still(context, command)
|
||||
if action in na.NodeActions.ACTIONS:
|
||||
message, name = self.nodes.execute(action, command)
|
||||
self._wrote = self.nodes.changed
|
||||
return self._receipt(command, "accepted", message, name)
|
||||
return self._receipt(command, "failed", f"Unsupported Blender command action: {action}", "")
|
||||
|
||||
|
|
@ -1136,17 +1133,6 @@ class BrokkrBlenderTarget:
|
|||
self._documents = documents
|
||||
return node, documents
|
||||
|
||||
def _import_debug_command_files(self, node: Any, command_document: Any, debug_mirror_root: str) -> None:
|
||||
commands_root = Path(self.resolve_debug_mirror_root(debug_mirror_root)) / "blender" / "commands"
|
||||
for command_path in sorted(commands_root.glob("*.json")):
|
||||
with command_path.open("r", encoding="utf-8") as handle:
|
||||
command = json.load(handle)
|
||||
command_id = command.get("commandId") or command_path.stem
|
||||
command["schema"] = command.get("schema") or COMMAND_INTENT_SCHEMA
|
||||
command["commandId"] = command_id
|
||||
node.database.put(command_document, f"blender/commands/{command_id}", command)
|
||||
command_path.unlink(missing_ok=True)
|
||||
|
||||
def _write_debug_document(self, debug_mirror_root: str, relative_path: str, document: dict[str, Any]) -> None:
|
||||
path = Path(self.resolve_debug_mirror_root(debug_mirror_root)) / relative_path
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
|
@ -1272,7 +1258,7 @@ def _to_list(value: Any) -> list[float]:
|
|||
|
||||
|
||||
def _valid_command_id(value: Any) -> bool:
|
||||
return isinstance(value, str) and COMMAND_ID_SHAPE.match(value) is not None
|
||||
return isinstance(value, str) and COMMAND_ID_SHAPE.fullmatch(value) is not None
|
||||
|
||||
|
||||
def _vector(value: Any, size: int, fallback: Any) -> tuple[float, ...]:
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ from __future__ import annotations
|
|||
import hmac
|
||||
import ipaddress
|
||||
import secrets
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
PUT_SCHEMA_VERSIONS = ("cultnet.document_put_raw.v0", "cultnet.document_delete.v0")
|
||||
|
|
@ -91,17 +90,12 @@ def guarded_server_class(base: type, guard: SessionGuard) -> type:
|
|||
return GuardedServer
|
||||
|
||||
|
||||
def purge_command_intents(node: Any, command_document: Any, command_schema: str, debug_mirror_root: str) -> int:
|
||||
"""Delete every queued command intent from the node and every command JSON under
|
||||
<debug_mirror_root>/blender/commands. Returns how many were removed."""
|
||||
def purge_command_intents(node: Any, command_document: Any, command_schema: str) -> int:
|
||||
"""Delete every queued command intent from the node. Returns how many were removed."""
|
||||
removed = 0
|
||||
if node is not None:
|
||||
node.database.pull()
|
||||
for key in list(node.database.snapshot().get(command_schema, {})):
|
||||
node.database.delete(command_document, key)
|
||||
removed += 1
|
||||
if debug_mirror_root:
|
||||
for path in (Path(debug_mirror_root) / "blender" / "commands").glob("*.json"):
|
||||
path.unlink(missing_ok=True)
|
||||
removed += 1
|
||||
return removed
|
||||
|
|
|
|||
|
|
@ -65,8 +65,7 @@ after `Start Server`.
|
|||
Always on:
|
||||
|
||||
- `Start Server` and `Stop Server` purge queued command intents: every
|
||||
`brokkr.blender.command_intent.v0` record in the node and every
|
||||
`blender/commands/*.json` under `Debug Export Root`. Intents queued before a
|
||||
`brokkr.blender.command_intent.v0` record in the node. Intents queued before a
|
||||
start never run under the new session.
|
||||
- After `Start Server` the panel shows the bind address, port and the file
|
||||
`cultmesh_py` was actually loaded from (its `__file__`, not the preference).
|
||||
|
|
@ -96,9 +95,11 @@ Run the tests (no Blender needed; `CULTLIB_PACKAGES` adds the real-server tests)
|
|||
CULTLIB_PACKAGES=F:/Projects/CultLib/packages python -m unittest discover -s surfaces/blender/tests -v
|
||||
```
|
||||
|
||||
`Debug Export Root` may still emit readable JSON probe files under
|
||||
`.brokkr/blender-editor-debug`, but those files are debug/import glue. CultMesh
|
||||
owns the mirror state.
|
||||
`Debug Export Root` may still emit readable JSON snapshot and receipt files under
|
||||
`.brokkr/blender-editor-debug`. They are export only: nothing reads them back, and
|
||||
a JSON file placed there is never an intent. CultMesh owns the mirror state, and
|
||||
intents enter only through the node (`brokkr-ctl blender send`, a served peer, the
|
||||
sync organ).
|
||||
|
||||
## Local Smoke
|
||||
|
||||
|
|
@ -106,11 +107,13 @@ owns the mirror state.
|
|||
2. Open `View3D > Sidebar > Brokkr`.
|
||||
3. Click `Capture Snapshot`.
|
||||
4. Inspect `.brokkr/blender-editor.ccmp`.
|
||||
5. Drop a command intent JSON file into
|
||||
`.brokkr/blender-editor-debug/blender/commands/{commandId}.json`.
|
||||
5. Send an intent into the node:
|
||||
`brokkr-ctl blender send createObject --set objectType='"EMPTY"' --agent <name> --no-wait`
|
||||
(needs `EUREKA_INSTANCE` and `--store <abs path to .brokkr/blender-editor.ccmp>`).
|
||||
6. Click `Drain Commands`, or enable `Auto Drain Commands` to poll command
|
||||
intents once per second while the add-on is loaded.
|
||||
7. Inspect `.brokkr/blender-editor.ccmp` or the optional debug export
|
||||
7. Read the receipt with `brokkr-ctl blender wait <commandId> --store <path>`, or
|
||||
inspect `.brokkr/blender-editor.ccmp` or the optional debug export
|
||||
at `.brokkr/blender-editor-debug/blender/receipts/{commandId}.json`.
|
||||
8. Click `Start Server`.
|
||||
9. Use the reported `cultnet://host:port` endpoint from a CultMesh/CultNet
|
||||
|
|
|
|||
|
|
@ -10,7 +10,8 @@ are drained by the add-on's own 1 s timer as one undo step each, with write-once
|
|||
leave unset to prove a stock install>
|
||||
blender --factory-startup --python agent_turn_queue.py -- <out>
|
||||
|
||||
Intents are put into the node database as brokkr-ctl does (no debug-mirror files). Writes
|
||||
Intents are put into the node database as brokkr-ctl does; a command JSON dropped under the debug
|
||||
root is never an intent. Writes
|
||||
<out>.result.json, then quits Blender. Undo is read only here, by this driver.
|
||||
"""
|
||||
import importlib
|
||||
|
|
@ -43,7 +44,7 @@ except ImportError:
|
|||
prefs = bpy.context.preferences.addons[MODULE].preferences
|
||||
CACHE = str(SCRATCH / "queue.ccmp")
|
||||
prefs.cultmesh_cache_path = CACHE
|
||||
prefs.debug_mirror_root = "" # the debug-mirror door is not used here
|
||||
prefs.debug_mirror_root = str(SCRATCH / "debug") # export only: q1 drops a command file there and it must stay inert
|
||||
prefs.output_dir = str(SCRATCH / "out")
|
||||
prefs.import_dir = ""
|
||||
prefs.auto_drain_commands = True
|
||||
|
|
@ -130,6 +131,10 @@ def drained(*ids):
|
|||
|
||||
def q1():
|
||||
push("driver baseline")
|
||||
door = SCRATCH / "debug" / "blender" / "commands"
|
||||
door.mkdir(parents=True, exist_ok=True)
|
||||
(door / "door-0001.json").write_text(json.dumps(
|
||||
{"commandId": "door-0001", "requestedBy": "nibu/hands", "action": "createObject", "objectType": "MESH", "name": "QDoor"}))
|
||||
queue("aaaaaaaa-0001", action="createObject", objectType="MESH", name="QCube", location=[4, 0, 0],
|
||||
requestedBy="nibu/hands", note="queue test")
|
||||
|
||||
|
|
@ -141,6 +146,10 @@ def q1_check():
|
|||
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"
|
||||
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()
|
||||
and receipt("door-0001") is None and (SCRATCH / "debug" / "blender" / "receipts" / "aaaaaaaa-0001.json").exists(),
|
||||
names())
|
||||
check("queue: intent removed from the queue after the drain", "blender/commands/aaaaaaaa-0001" not in pending(), list(pending()))
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -164,6 +164,44 @@ class AgentTurnTests(unittest.TestCase):
|
|||
self.assertEqual(self.bpy.created, [])
|
||||
self.assertEqual(self.bpy.undo.pushes, [])
|
||||
|
||||
def test_trailing_newline_does_not_pass_the_id_shapes(self):
|
||||
self.assertFalse(bt._valid_command_id("okid\n"))
|
||||
receipt = self.run_action(action="createObject", objectType="EMPTY", commandId="okid\n")
|
||||
self.assertEqual(receipt["status"], "denied")
|
||||
receipt = self.run_action(action="createObject", objectType="EMPTY", requestedBy="nibu/hands\n")
|
||||
self.assertEqual(receipt["status"], "denied")
|
||||
self.assertEqual(self.bpy.created, [])
|
||||
|
||||
def test_load_cultmesh_pins_its_own_package_set(self):
|
||||
# an unrelated module named like a CultLib package is a missing dependency, not "CultLib is absent"
|
||||
self.assertEqual(bt.CULTLIB_PY_PACKAGES, ("cultcache-py", "cultnet-py", "cultmesh-py"))
|
||||
root = Path(tempfile.mkdtemp())
|
||||
self.addCleanup(lambda: __import__("shutil").rmtree(root, ignore_errors=True))
|
||||
src = root / "cultmesh-py" / "src" / "cultmesh_py"
|
||||
src.mkdir(parents=True)
|
||||
(src / "__init__.py").write_text("import cultnet_py") # an own package that is absent here
|
||||
saved = {k: sys.modules.pop(k) for k in ("cultmesh_py", "cultcache_py", "cultnet_py") if k in sys.modules}
|
||||
saved_path = list(sys.path)
|
||||
self.addCleanup(lambda: (sys.modules.update(saved), sys.path.__setitem__(slice(None), saved_path)))
|
||||
with self.assertRaises(RuntimeError) as caught:
|
||||
bt._load_cultmesh(str(root))
|
||||
self.assertIn("requires CultLib's Python packages", str(caught.exception))
|
||||
|
||||
def test_debug_command_file_is_not_executed(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
commands = Path(tmp) / "blender" / "commands"
|
||||
commands.mkdir(parents=True)
|
||||
door = commands / "door-1.json"
|
||||
door.write_text('{"commandId": "door-1", "requestedBy": "nibu/hands", "action": "createObject", "objectType": "EMPTY"}')
|
||||
node = FakeNode({})
|
||||
docs = {"command_intent": "i", "command_receipt": "r"}
|
||||
with unittest.mock.patch.object(self.target, "_open_node", return_value=(node, docs)):
|
||||
receipts = self.target.drain_commands(self.context, "cache", "src", tmp)
|
||||
self.assertEqual(receipts, [])
|
||||
self.assertEqual(node.puts, [])
|
||||
self.assertEqual(self.bpy.created, [])
|
||||
self.assertTrue(door.exists())
|
||||
|
||||
def test_load_cultmesh_names_the_missing_module(self):
|
||||
root = Path(tempfile.mkdtemp())
|
||||
self.addCleanup(lambda: __import__("shutil").rmtree(root, ignore_errors=True))
|
||||
|
|
|
|||
|
|
@ -144,48 +144,29 @@ class FakeNode:
|
|||
|
||||
|
||||
class PurgeTests(unittest.TestCase):
|
||||
def make_debug_root(self, tmp):
|
||||
commands = Path(tmp) / "blender" / "commands"
|
||||
commands.mkdir(parents=True)
|
||||
(commands / "a.json").write_text("{}")
|
||||
(commands / "b.json").write_text("{}")
|
||||
(commands / "note.txt").write_text("keep")
|
||||
receipts = Path(tmp) / "blender" / "receipts"
|
||||
receipts.mkdir()
|
||||
(receipts / "r.json").write_text("{}")
|
||||
return commands, receipts
|
||||
def test_purge_removes_queued_intents(self):
|
||||
node = FakeNode(["c1", "c2"])
|
||||
removed = sg.purge_command_intents(node, "DOC", bt.COMMAND_INTENT_SCHEMA)
|
||||
self.assertEqual(removed, 2)
|
||||
self.assertEqual(node.database.deleted, [("DOC", "c1"), ("DOC", "c2")])
|
||||
|
||||
def test_purge_removes_queued_intents_and_debug_command_files_only(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
commands, receipts = self.make_debug_root(tmp)
|
||||
node = FakeNode(["c1", "c2"])
|
||||
removed = sg.purge_command_intents(node, "DOC", bt.COMMAND_INTENT_SCHEMA, tmp)
|
||||
self.assertEqual(removed, 4)
|
||||
self.assertEqual(node.database.deleted, [("DOC", "c1"), ("DOC", "c2")])
|
||||
self.assertEqual(sorted(p.name for p in commands.iterdir()), ["note.txt"])
|
||||
self.assertTrue((receipts / "r.json").exists())
|
||||
|
||||
def test_purge_without_a_debug_root_or_node_is_quiet(self):
|
||||
self.assertEqual(sg.purge_command_intents(None, "DOC", bt.COMMAND_INTENT_SCHEMA, ""), 0)
|
||||
def test_purge_without_a_node_is_quiet(self):
|
||||
self.assertEqual(sg.purge_command_intents(None, "DOC", bt.COMMAND_INTENT_SCHEMA), 0)
|
||||
|
||||
def test_stop_server_purges_and_revokes(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
commands, _ = self.make_debug_root(tmp)
|
||||
target = bt.BrokkrBlenderTarget(types.SimpleNamespace())
|
||||
stopped = []
|
||||
target._server = types.SimpleNamespace(stop=lambda: stopped.append(True))
|
||||
target._guard = sg.SessionGuard()
|
||||
guard = target._guard
|
||||
old = guard.token
|
||||
target._node = FakeNode(["c1"])
|
||||
target._documents = {"command_intent": "DOC"}
|
||||
target._debug_mirror_root = tmp
|
||||
target.stop_server()
|
||||
self.assertEqual(stopped, [True])
|
||||
self.assertEqual(target._node.database.keys, [])
|
||||
self.assertEqual(sorted(p.name for p in commands.iterdir()), ["note.txt"])
|
||||
self.assertFalse(guard.admits({sg.TOKEN_FIELD: old}))
|
||||
self.assertEqual(target.session_token, "")
|
||||
target = bt.BrokkrBlenderTarget(types.SimpleNamespace())
|
||||
stopped = []
|
||||
target._server = types.SimpleNamespace(stop=lambda: stopped.append(True))
|
||||
target._guard = sg.SessionGuard()
|
||||
guard = target._guard
|
||||
old = guard.token
|
||||
target._node = FakeNode(["c1"])
|
||||
target._documents = {"command_intent": "DOC"}
|
||||
target.stop_server()
|
||||
self.assertEqual(stopped, [True])
|
||||
self.assertEqual(target._node.database.keys, [])
|
||||
self.assertFalse(guard.admits({sg.TOKEN_FIELD: old}))
|
||||
self.assertEqual(target.session_token, "")
|
||||
|
||||
def test_stop_server_revokes_and_purges_even_when_the_socket_stop_raises(self):
|
||||
target = bt.BrokkrBlenderTarget(types.SimpleNamespace())
|
||||
|
|
@ -229,24 +210,19 @@ class RealServerTests(unittest.TestCase):
|
|||
def setUp(self):
|
||||
self.tmp = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(self.tmp.cleanup)
|
||||
self.debug = str(Path(self.tmp.name) / "debug")
|
||||
commands = Path(self.debug) / "blender" / "commands"
|
||||
commands.mkdir(parents=True)
|
||||
(commands / "stale.json").write_text("{}")
|
||||
self.cache = str(Path(self.tmp.name) / "node.ccmp")
|
||||
self.target = bt.BrokkrBlenderTarget(types.SimpleNamespace(
|
||||
path=types.SimpleNamespace(abspath=lambda p: p)))
|
||||
self.addCleanup(self.target.stop_server)
|
||||
|
||||
def start(self, **kwargs):
|
||||
return self.target.start_server(self.cache, PACKAGES, "127.0.0.1", 0, 100, 1 << 20, self.debug, **kwargs)
|
||||
return self.target.start_server(self.cache, PACKAGES, "127.0.0.1", 0, 100, 1 << 20, **kwargs)
|
||||
|
||||
def test_default_start_has_no_token_and_purges_stale_debug_commands(self):
|
||||
def test_default_start_has_no_token(self):
|
||||
status = self.start()
|
||||
self.assertTrue(status["running"])
|
||||
self.assertFalse(status["tokenRequired"])
|
||||
self.assertEqual(self.target.session_token, "")
|
||||
self.assertEqual(list((Path(self.debug) / "blender" / "commands").glob("*.json")), [])
|
||||
self.assertTrue(status["cultmeshModule"].endswith("__init__.py"))
|
||||
self.assertIn("cultmesh_py", status["cultmeshModule"])
|
||||
self.assertTrue(status["loopback"])
|
||||
|
|
@ -311,17 +287,17 @@ class RealServerTests(unittest.TestCase):
|
|||
self.assertEqual(self.queued(self.cache), [])
|
||||
|
||||
def test_allow_true_goes_through_start_server_and_unticking_stops_it(self):
|
||||
status = self.target.start_server(self.cache, PACKAGES, "0.0.0.0", 0, 100, 1 << 20, self.debug,
|
||||
status = self.target.start_server(self.cache, PACKAGES, "0.0.0.0", 0, 100, 1 << 20,
|
||||
allow_non_loopback=True)
|
||||
self.assertTrue(status["running"])
|
||||
self.assertFalse(status["loopback"])
|
||||
with self.assertRaises(sg.BindRefused):
|
||||
self.target.start_server(self.cache, PACKAGES, "0.0.0.0", 0, 100, 1 << 20, self.debug,
|
||||
self.target.start_server(self.cache, PACKAGES, "0.0.0.0", 0, 100, 1 << 20,
|
||||
allow_non_loopback=False)
|
||||
self.assertFalse(self.target.server_status()["running"])
|
||||
|
||||
def test_unticking_the_allow_stops_a_running_non_loopback_server(self):
|
||||
self.target.start_server(self.cache, PACKAGES, "0.0.0.0", 0, 100, 1 << 20, self.debug,
|
||||
self.target.start_server(self.cache, PACKAGES, "0.0.0.0", 0, 100, 1 << 20,
|
||||
allow_non_loopback=True)
|
||||
self.target.enforce_bind_policy(False)
|
||||
self.assertFalse(self.target.server_status()["running"])
|
||||
|
|
@ -378,7 +354,7 @@ class RealServerTests(unittest.TestCase):
|
|||
|
||||
def test_non_loopback_bind_is_refused_before_anything_starts(self):
|
||||
with self.assertRaises(sg.BindRefused):
|
||||
self.target.start_server(self.cache, PACKAGES, "0.0.0.0", 0, 100, 1 << 20, self.debug)
|
||||
self.target.start_server(self.cache, PACKAGES, "0.0.0.0", 0, 100, 1 << 20)
|
||||
self.assertFalse(self.target.server_status()["running"])
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue