Ships add-on: all-or-nothing bind, pin the cross-drive fallback

_bind_collection restores every aetheria.* key if the ID-property store
refuses a value, so a bad ship id or pending leaves the collection as it
was. smoke_package.py gains default-run cases: relpath raising ValueError
(the cross-drive signal) must store the absolute path and finish; a refused
id or pending must leave bound and unbound collections unchanged.
All commits build (Python only).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-10-10 20:38:17 +02:00
commit 92b82e9aa5
2 changed files with 53 additions and 6 deletions

View file

@ -300,13 +300,23 @@ def _bind_collection(collection, path, ship_id, pending=None):
stored = bpy.path.relpath(path)
except ValueError:
pass
collection["aetheria.asset_kind"] = "ship"
collection["aetheria.id"] = ship_id
collection["aetheria.ship_cc"] = stored
keys = ("aetheria.asset_kind", "aetheria.id", "aetheria.ship_cc", "aetheria.pending")
before = {key: collection[key] for key in keys if key in collection}
values = {"aetheria.asset_kind": "ship", "aetheria.id": ship_id, "aetheria.ship_cc": stored}
if pending:
collection["aetheria.pending"] = pending
elif "aetheria.pending" in collection:
del collection["aetheria.pending"]
values["aetheria.pending"] = pending
try:
for key, value in values.items():
collection[key] = value
if not pending and "aetheria.pending" in collection:
del collection["aetheria.pending"]
except Exception:
for key in keys: # the ID-property store refused a value: put every key back as it was
if key in before:
collection[key] = before[key]
elif key in collection:
del collection[key]
raise
class AETHERIA_OT_bind_ship_collection(bpy.types.Operator):

View file

@ -106,6 +106,43 @@ def bind_cases(ship, path, mods):
if result != {"FINISHED"} or not stored.startswith("//") or not same_file(bpy.path.abspath(stored), path):
raise SystemExit("Bind case same-drive: the stored path is not a resolving '//'-relative path")
# relpath raises ValueError across drives: the bind completes with the absolute path, without a second drive.
bpy.path.relpath = lambda *args, **kwargs: (_ for _ in ()).throw(ValueError("probe: path is on mount 'D:'"))
try:
result, stored = bind(ship, "cross-drive-forced")
finally:
bpy.path.relpath = relpath
if result != {"FINISHED"} or not os.path.isabs(stored) or not same_file(stored, path):
raise SystemExit("Bind case cross-drive-forced: the stored path is not the absolute .cc path")
# A value the ID-property store refuses leaves the collection exactly as it was, bound or not.
import aetheria_ships
for label, ship_id, pending in (("bad-id", object(), None), ("bad-pending", SHIP_ID, [object()])):
for key in list(ship.keys()):
if key.startswith("aetheria."):
del ship[key]
for bound in (False, True):
if bound:
aetheria_ships._bind_collection(ship, path, SHIP_ID, ["Old", "Ref"])
before = {key: ship[key] for key in ship.keys() if key.startswith("aetheria.")}
before = {key: (value.to_list() if hasattr(value, "to_list") else value) for key, value in before.items()}
try:
aetheria_ships._bind_collection(ship, path, ship_id, pending)
except Exception:
pass
else:
raise SystemExit(f"Bind case {label}: the store did not refuse the value")
after = {key: ship[key] for key in ship.keys() if key.startswith("aetheria.")}
after = {key: (value.to_list() if hasattr(value, "to_list") else value) for key, value in after.items()}
if after != before:
raise SystemExit(f"Bind case {label} bound={bound}: a refused bind left the collection half-bound")
aetheria_ships._bind_collection(ship, path, SHIP_ID)
for key in BIND_KEYS:
if key not in ship:
raise SystemExit("Bind case rebind: the collection lost its binding")
if "aetheria.pending" in ship:
raise SystemExit("Bind case rebind: a bind without pending kept the old pending")
other = os.environ.get("SMOKE_OTHER_DRIVE")
if not other:
print("BIND cross-drive skipped: SMOKE_OTHER_DRIVE is not set")