From 7f35c79ecc9d15bcd5aa8ceae7b6650c638b590f Mon Sep 17 00:00:00 2001 From: soul Date: Mon, 19 Oct 2026 00:20:00 +0200 Subject: [PATCH] Package refuses an agent-built hull unless its product is by the language's maker Language files carry their Faction record key (eighth element of the lang echo); Build records the maker it judged (aetheria.hull_maker); Package compares it with ship_cc.product_makers before writing anything (ruling hull-faction-is-product-maker, finding hull-names-its-own-faction). _art_takes_over is shared with _retire_hull_source. Unit tests untested at this commit until the Yggdrasil run; bpy smokes not run. Co-Authored-By: Claude Sonnet 5.5 --- .../ShipSchemaPinTests.cs | 1 + tools/blender/aetheria_ships/__init__.py | 47 +++++++++--- .../aetheria_ships/factions/pirate.scad | 3 +- .../blender/aetheria_ships/factions/rnd.scad | 4 +- .../aetheria_ships/factions/zhestokost.scad | 6 +- tools/blender/aetheria_ships/hull_source.py | 11 ++- tools/blender/aetheria_ships/ship_cc.py | 17 +++++ tools/blender/tests/smoke_hull_source.py | 75 +++++++++++++++---- tools/blender/tests/test_hull_source.py | 31 ++++++-- tools/blender/tests/test_ship_cc.py | 38 +++++++++- 10 files changed, 194 insertions(+), 39 deletions(-) diff --git a/tests/Aetheria.Shared.Tests/ShipSchemaPinTests.cs b/tests/Aetheria.Shared.Tests/ShipSchemaPinTests.cs index d47b418af..eeb4825c0 100644 --- a/tests/Aetheria.Shared.Tests/ShipSchemaPinTests.cs +++ b/tests/Aetheria.Shared.Tests/ShipSchemaPinTests.cs @@ -22,6 +22,7 @@ public sealed class ShipSchemaPinTests [InlineData("SCHEMATIC_LINES_SLOT", typeof(ShipAuthoring), nameof(ShipAuthoring.SchematicLines))] [InlineData("HULL_SHAPE_SLOT", typeof(HullData), nameof(HullData.Shape))] [InlineData("HULL_HARDPOINTS_SLOT", typeof(HullData), nameof(HullData.Hardpoints))] + [InlineData("PRODUCT_MANUFACTURER_SLOT", typeof(FactionProductData), nameof(FactionProductData.Manufacturer))] public void PythonSlotConstantsAreTheKeysOfTheMembersTheyNameInTheirComments(string constant, Type owner, string member) { Assert.Equal(KeyOf(owner, member), Integer(constant)); diff --git a/tools/blender/aetheria_ships/__init__.py b/tools/blender/aetheria_ships/__init__.py index 9bb79290f..761c254c7 100644 --- a/tools/blender/aetheria_ships/__init__.py +++ b/tools/blender/aetheria_ships/__init__.py @@ -25,7 +25,7 @@ from mathutils import Matrix, Vector from . import hull_grid, hull_source from .ship_cc import (HARDPOINT_MEMBERS, HARDPOINT_TYPE_NAMES, ROTATION_NAMES, capture_grease_pencil, decode_hardpoint, encode_hardpoint, layout_revision, read, read_layout, replace_layout, replace_lines, - replace_visual, valid_ship_id) + product_makers, replace_visual, valid_ship_id) MODEL_ASSET = "ship.glb" SOURCE = "Source" # child collection: the Tripo mesh, input to Rasterise, never exported @@ -1491,6 +1491,7 @@ def _frame_ship(context, collection, root, path, saved_shape): _recentre(root, hull_grid.cell_centre((float(origin[0]), float(origin[1])), centre[0], centre[1])) +HULL_MAKER = "aetheria.hull_maker" # on the collection: the Faction key of the language Build judged the hull against HULL_BUILT = "aetheria.hull_built" # on the collection: {object name: fingerprint} of what Build From Hull Source made HULL_COLLIDER = ("hull-collider", "collider", "Hull Collider") @@ -1619,27 +1620,50 @@ def _build_hull_source(context, collection): name, hull.zones[hull.body_zone], _hull_material(ship_id, "collider", (0.5, 0.5, 0.5))))) collider["aetheria.role"], collider["aetheria.id"] = role, anchor_id collection[HULL_BUILT] = {obj.name: _fingerprint(obj) for obj in made} + collection[HULL_MAKER] = hull.languages[hull.brief.faction].maker return hull -def _retire_hull_source(collection): - """Deletes the package's hull.scad when the body is the operator's: the collection holds render meshes that Build did - not make as they stand, and no zone mesh of Build's is left. The anchors and collider she kept are hers from then on. - A hull never built, or built and packaged as it stands, keeps its source. Returns whether the file was deleted.""" - source = _hull_source_file(collection) +def _art_takes_over(collection): + """Whether the body is the operator's: a hull.scad and a Ship Root exist, the collection holds render meshes that + Build did not make as they stand, and no zone mesh of Build's is left.""" root = _ship_root(collection) - if source is None or root is None: + if _hull_source_file(collection) is None or root is None: return False untouched, _ = _hull_built(collection) zones = [obj for obj in untouched if obj.type == "MESH" and "aetheria.role" not in obj] - if zones or not [obj for obj in _own_meshes(collection) if obj not in untouched]: + return not zones and bool([obj for obj in _own_meshes(collection) if obj not in untouched]) + + +def _retire_hull_source(collection): + """Deletes the package's hull.scad when the body is the operator's (_art_takes_over). The anchors and collider she + kept are hers from then on. A hull never built, or built and packaged as it stands, keeps its source. Returns whether + the file was deleted.""" + if not _art_takes_over(collection): return False - source.unlink() - if HULL_BUILT in collection: - del collection[HULL_BUILT] + _hull_source_file(collection).unlink() + for record in (HULL_BUILT, HULL_MAKER): + if record in collection: + del collection[record] return True +def _refuse_wrong_maker(collection, path, cultlib): + """Refuses, before Package writes anything, an agent-built hull (hull.scad still in the package and not taken over by + her art) unless the package holds a product and every product is by the maker of the language Build judged the hull + against (ruling hull-faction-is-product-maker). The product owns the maker; Build's record is only what it judged.""" + if _hull_source_file(collection) is None or _art_takes_over(collection): + return + maker = collection.get(HULL_MAKER) + if maker is None: + raise ValueError("Build From Hull Source first: Package needs the maker it judged the hull against") + makers = product_makers(path, cultlib) + if not makers: + raise ValueError("The package has no product: add one for the hull's maker before packaging") + if any(product != maker for product in makers): + raise ValueError("A product in the package is not by the maker of the hull's faction language") + + class AETHERIA_OT_build_hull_source(bpy.types.Operator): bl_idname = "aetheria.build_hull_source" bl_label = "Build From Hull Source" @@ -1675,6 +1699,7 @@ class AETHERIA_OT_package_ship(bpy.types.Operator): _refuse_loose_meshes(context, collection) _refuse_shared_ids(context, collection) cultlib = _brokkr_cultlib(context) + _refuse_wrong_maker(collection, path, cultlib) ship_id = collection["aetheria.id"] state = scene.aetheria_layout saved_shape, saved_rows, _ = read_layout(path, cultlib) diff --git a/tools/blender/aetheria_ships/factions/pirate.scad b/tools/blender/aetheria_ships/factions/pirate.scad index 8705869a1..47489b721 100644 --- a/tools/blender/aetheria_ships/factions/pirate.scad +++ b/tools/blender/aetheria_ships/factions/pirate.scad @@ -39,5 +39,6 @@ PI_ZONES = [["primer", [0.48, 0.27, 0.22]], // primer-red salvage plates PI_GLOW = [0.55, 0.85, 1.0]; PI_RADIATOR = [0.70, 0.68, 0.62]; // No body zone and no proportions: the donor's. The additions must make the top view visibly lopsided. -PI_LANG = ["pirate", PI_ZONES, "", PI_GLOW, PI_RADIATOR, [], ["asymmetric", 0.9]]; +// maker: the Pirates Faction record key in GameData/Aetheria.cc +PI_LANG = ["pirate", PI_ZONES, "", PI_GLOW, PI_RADIATOR, [], ["asymmetric", 0.9], "1d8a168def994a76a1ce7cb18f59c038"]; if (part == "lang") echo(lang = PI_LANG); diff --git a/tools/blender/aetheria_ships/factions/rnd.scad b/tools/blender/aetheria_ships/factions/rnd.scad index ae7da7241..971798555 100644 --- a/tools/blender/aetheria_ships/factions/rnd.scad +++ b/tools/blender/aetheria_ships/factions/rnd.scad @@ -26,5 +26,7 @@ RD_ZONES = [["primary", [0.72, 0.74, 0.76]], // the wedge ["recess", [0.10, 0.12, 0.18]]]; // windows, engine bank RD_GLOW = [1.0, 0.75, 0.3]; RD_RADIATOR = [0.40, 0.47, 0.56]; -RD_LANG = ["rnd", RD_ZONES, "primary", RD_GLOW, RD_RADIATOR, [[0.12, 0.35], [0.55, 1.1]], ["bilateral", 0.97]]; +// maker: the Rossum & Douglas Faction record key in GameData/Aetheria.cc +RD_LANG = ["rnd", RD_ZONES, "primary", RD_GLOW, RD_RADIATOR, [[0.12, 0.35], [0.55, 1.1]], ["bilateral", 0.97], + "adfb9b08-aabc-45c6-9586-915698a9c4b0"]; if (part == "lang") echo(lang = RD_LANG); diff --git a/tools/blender/aetheria_ships/factions/zhestokost.scad b/tools/blender/aetheria_ships/factions/zhestokost.scad index c00139dd8..9c4e65bb9 100644 --- a/tools/blender/aetheria_ships/factions/zhestokost.scad +++ b/tools/blender/aetheria_ships/factions/zhestokost.scad @@ -55,6 +55,8 @@ ZH_ZONES = [["primary", [0.42, 0.43, 0.45]], // iron grey: the stepped mass ["recess", [0.08, 0.08, 0.09]]]; // recessed machinery ZH_GLOW = [1.0, 0.62, 0.25]; ZH_RADIATOR = [0.50, 0.51, 0.52]; -// [faction, zones, body zone, glow, radiator, [height/width range, width/length range], symmetry rule] -ZH_LANG = ["zhestokost", ZH_ZONES, "primary", ZH_GLOW, ZH_RADIATOR, [[0.25, 0.6], [0.35, 0.75]], ["bilateral", 0.97]]; +// [faction, zones, body zone, glow, radiator, [height/width range, width/length range], symmetry rule, maker] +// maker: the Zhestokost Faction record key in GameData/Aetheria.cc, the Manufacturer of a product whose hull speaks this language +ZH_LANG = ["zhestokost", ZH_ZONES, "primary", ZH_GLOW, ZH_RADIATOR, [[0.25, 0.6], [0.35, 0.75]], ["bilateral", 0.97], + "16bad4f9-7fb5-41c5-8da0-dc76709eb7d3"]; if (part == "lang") echo(lang = ZH_LANG); diff --git a/tools/blender/aetheria_ships/hull_source.py b/tools/blender/aetheria_ships/hull_source.py index 08fa00b57..e513a7454 100644 --- a/tools/blender/aetheria_ships/hull_source.py +++ b/tools/blender/aetheria_ships/hull_source.py @@ -6,7 +6,8 @@ factions/: the checks read it from there, by the faction the brief names, and th with it (a hull that redefines or shadows an included language fails a check): brief ECHO brief = [faction, donor, role, [length_min, length_max], [tris_min, tris_max], reads] - lang ECHO lang = [faction, [[zone, [r, g, b]], ...], body zone, glow, radiator, proportion, symmetry] + lang ECHO lang = [faction, [[zone, [r, g, b]], ...], body zone, glow, radiator, proportion, symmetry, maker] + (maker: the faction's Faction record key in GameData/Aetheria.cc, the eighth element) (every included language file echoes its own, and so does factions/.scad run alone; a Pirate language has no body zone and no proportion) anchors ECHO anchor = [id, role, [x, y, z], yaw, parent] one line per anchor, yaw 0 nose, 90 port @@ -66,6 +67,7 @@ class Language: radiator: tuple proportion: Optional[tuple] # ((h/w min, max), (w/l min, max)); None for a language that takes its donor's symmetry: tuple # ("bilateral", minimum mirror overlap) or ("asymmetric", maximum mirror overlap) + maker: str # the Faction record key a product of this language's hulls names as its Manufacturer def zone_names(self): return [name for name, _ in self.zones] @@ -204,7 +206,7 @@ def read_languages(text): """Every language echoed in text, in echo order.""" languages = [] for raw in parse_echoes(text, "lang"): - if not isinstance(raw, list) or len(raw) != 7 or not isinstance(raw[1], list): + if not isinstance(raw, list) or len(raw) != 8 or not isinstance(raw[1], list): raise HullSourceError("A faction language has the wrong shape") zones = tuple((_text(z[0]), _vector(z[1], 3)) for z in raw[1] if isinstance(z, list) and len(z) == 2) if len(zones) != len(raw[1]): @@ -213,8 +215,11 @@ def read_languages(text): symmetry = _vector(raw[6], 2, numbers=False) if symmetry[0] not in ("bilateral", "asymmetric") or not _number(symmetry[1]): raise HullSourceError("A faction language names a symmetry rule it does not have") + maker = _text(raw[7]) + if not maker: + raise HullSourceError("A faction language names no maker") language = Language(_text(raw[0]), zones, _text(raw[2]), _vector(raw[3], 3), _vector(raw[4], 3), proportion, - symmetry) + symmetry, maker) if language.body and language.body not in language.zone_names(): raise HullSourceError("A faction language's body zone is not one of its zones") languages.append(language) diff --git a/tools/blender/aetheria_ships/ship_cc.py b/tools/blender/aetheria_ships/ship_cc.py index 41f53601f..7cc093389 100644 --- a/tools/blender/aetheria_ships/ship_cc.py +++ b/tools/blender/aetheria_ships/ship_cc.py @@ -23,6 +23,7 @@ TESTED_CULTCACHE_PY = "0.3.0" SCHEMA = "aetheria.ship_authoring" HULL_SCHEMA = "aetheria.hulldata" PRODUCT_SCHEMA = "aetheria.factionproductdata" +PRODUCT_MANUFACTURER_SLOT = 4 # FactionProductData.Manufacturer # MessagePack slots of the C# types, which own them (ShipAuthoring, ItemData.Shape, HullData.Hardpoints, # HardpointData). RETIRED_HULL_SLOT is the ShipAuthoring key that held the embedded hull before S1; no member owns it now. ShipSchemaPinTests in tests/Aetheria.Shared.Tests fails when any number or name below @@ -135,6 +136,22 @@ def read(path: str, cultlib_packages: str) -> ShipFile: return ShipFile(store, ship, hull, msgpack) +def product_makers(path: str, cultlib_packages: str) -> list[str]: + """The Manufacturer (Faction record key) of every product record in the file, in file order. C# owns products and + this only reads them: a product whose Manufacturer is missing or not a non-empty string is refused, naming nothing.""" + cultcache, msgpack = _libraries(cultlib_packages) + makers = [] + for envelope in cultcache.SingleFileMessagePackBackingStore(path).pull_all(): + if envelope.type != PRODUCT_SCHEMA: + continue + body = msgpack.unpackb(envelope.payload, raw=False) + maker = body[PRODUCT_MANUFACTURER_SLOT] if isinstance(body, list) and len(body) > PRODUCT_MANUFACTURER_SLOT else None + if not isinstance(maker, str) or not maker: + raise ValueError(f"A {PRODUCT_SCHEMA} record names no manufacturer") + makers.append(maker) + return makers + + def _stamped(record: Record, msgpack: Any): return replace( record.envelope, diff --git a/tools/blender/tests/smoke_hull_source.py b/tools/blender/tests/smoke_hull_source.py index f33666f2f..385c667ad 100644 --- a/tools/blender/tests/smoke_hull_source.py +++ b/tools/blender/tests/smoke_hull_source.py @@ -25,7 +25,13 @@ the hull.scad into the package and runs the panel's operators: Build after Package still works. The author replaces the zone meshes with her art and keeps Build's anchors and collider: Package deletes hull.scad in that one act and says so, and Build then refuses. - A hull that was never built keeps its hull.scad through the same deletion rule. + A hull that was never built keeps its hull.scad through the same deletion rule, and Package refuses it (no maker was + judged). + Package refuses an agent-built hull before it writes anything (ship.glb is not made) when the package holds no product, + or a product by another maker than the language Build judged it against (hull-names-its-own-faction); with a product by + that maker it accepts. Her art needs no product. + Build and Package refuse copies that share an aetheria.id, selecting the original and the copies, and delete nothing. + Package moves no row and turns no mount: every layout row is as authored after it, and a hand-turned mount keeps its yaw. """ import json @@ -51,16 +57,19 @@ FIXTURES = REPO / "tools" / "blender" / "tests" / "fixtures" / "hulls" THRUSTER, RADIATOR, BALLISTIC = "3", "6", "10" # fixture folder, ship id, stand-in box (x, y) metres and its length in cells, the layout rows (mount id, kind, cell), -# the body zone the collider copies, and the palette each zone must carry +# the body zone the collider copies, the palette each zone must carry, the Faction name of the maker whose language the +# hull speaks (AetherDb resolves it to the product's Manufacturer), and a Faction that is not its maker HULLS = ( ("zh-ammo-tender", "smoke.hull.tender", (10.0, 23.4), 12, (("Gun.D", BALLISTIC, (2, 3)), ("Th.L", THRUSTER, (0, 0)), ("Th.R", THRUSTER, (1, 0)), ("Ra.L", RADIATOR, (2, 0)), ("Ra.R", RADIATOR, (3, 0))), - "primary", {"primary": (0.42, 0.43, 0.45), "secondary": (0.20, 0.20, 0.22), "accent": (0.55, 0.22, 0.14), "recess": (0.08, 0.08, 0.09)}), + "primary", {"primary": (0.42, 0.43, 0.45), "secondary": (0.20, 0.20, 0.22), "accent": (0.55, 0.22, 0.14), "recess": (0.08, 0.08, 0.09)}, + "Zhestokost", "Pirates"), ("pi-fighter", "smoke.hull.fighter", (8.0, 15.0), 8, (("Gun.P", BALLISTIC, (3, 3)), ("Th.Main", THRUSTER, (0, 0)), ("Th.L", THRUSTER, (1, 0))), "rnd.primary", {"rnd.primary": (0.72, 0.74, 0.76), "primer": (0.48, 0.27, 0.22), "weld": (0.70, 0.68, 0.62), - "accent": (0.10, 0.62, 0.60), "rnd.accent": (0.90, 0.89, 0.84)}), + "accent": (0.10, 0.62, 0.60), "rnd.accent": (0.90, 0.89, 0.84)}, + "Pirates", "Zhestokost"), ) @@ -104,7 +113,8 @@ def generated(collection): def layout_rows(scene): - return [(hp.mount_id, hp.kind, hp.armor, hp.firing_arc, hp.footprint) for hp in scene.aetheria_layout.hardpoints] + return [(hp.mount_id, hp.kind, (hp.x, hp.y), hp.rotation, hp.armor, hp.firing_arc, hp.footprint) + for hp in scene.aetheria_layout.hardpoints] def glb_nodes(path): @@ -166,7 +176,7 @@ def check_built(collection, root, body, palette, anchors_by_role): return objects -def one_hull(scene, number, fixture, ship_id, extent, length, rows, body, palette): +def one_hull(scene, number, fixture, ship_id, extent, length, rows, body, palette, maker, other): collection, box, package = make_ship(scene, fixture, ship_id, extent, length, rows) state = scene.aetheria_layout root = bpy.data.objects[next(o.name for o in collection.all_objects if o.get("aetheria.ship_root"))] @@ -245,11 +255,39 @@ def one_hull(scene, number, fixture, ship_id, extent, length, rows, body, palett source.write_text(original, encoding="utf-8") print(f"PASS {number}.4 Build refuses a hull that breaks its brief") + # Package refuses an agent-built hull whose package has no product, or one by another maker, before it writes + # anything; the maker of the language Build judged it against is accepted. + ship_cc = str(package / "ship.cc") + require(collection.get("aetheria.hull_maker") and not (package / "ship.glb").exists(), "Build recorded no maker, or Package ran") + for label, expected, prepare in (("no product", "The package has no product", lambda: None), + ("a product by another maker", "not by the maker of the hull's faction language", + lambda: require(aetherdb(ship_cc, "product", ship_cc, other, "--name", "x") == 0, + "AetherDb could not write the other maker's product"))): + prepare() + select(box) + rows_now = layout_rows(scene) + result, message = run(bpy.ops.aetheria.package_ship) + report = scene.aetheria_package_report + require(result == {"CANCELLED"} and expected in report, f"Package took a hull with {label}: {report!r} {message!r}") + require(not (package / "ship.glb").exists(), f"Package wrote ship.glb for a hull with {label}") + require(layout_rows(scene) == rows_now, f"A refused Package changed a row ({label})") + for echoed in (ship_id, str(GAME), maker, other, collection["aetheria.hull_maker"]): + require(echoed not in report, f"The refusal echoes an input ({echoed})") + require(aetherdb(ship_cc, "product", ship_cc, other, "--remove") == 0 + and aetherdb(ship_cc, "product", ship_cc, maker, "--name", "x") == 0, "AetherDb could not swap the product") + # Package: the validator accepts the built ship and the GLB holds a node per anchor. + mount = bpy.data.objects[roles["weapon-mount"][0]] + straight = mount.rotation_euler.z + mount.rotation_euler.z = straight + 0.3 # hand-turned: Package turns no mount + turned, rows_authored = mount.rotation_euler.z, layout_rows(scene) select(box) result, message = run(bpy.ops.aetheria.package_ship) report = scene.aetheria_package_report require(result == {"FINISHED"} and "validator accepted" in report, f"Package refused the built ship: {report!r} {message!r}") + require(layout_rows(scene) == rows_authored, "Package changed a layout row") + require(abs(mount.rotation_euler.z - turned) < 1e-6, "Package turned a mount") + mount.rotation_euler.z = straight require(source.is_file(), "Package deleted a hull source whose hull is still built from it") nodes = {n.get("name"): n for n in glb_nodes(package / "ship.glb")} for role, ids in roles.items(): @@ -257,9 +295,8 @@ def one_hull(scene, number, fixture, ship_id, extent, length, rows, body, palett require(anchor_id in nodes, f"The GLB has no node for {anchor_id}") for zone in palette: require(zone in nodes, f"The GLB has no mesh node for zone {zone}") - moved = [r for r in (hp for hp in state.hardpoints) if r.mount_id in roles["weapon-mount"]] - print(f"INFO {number}.5 weapon rows after Package (fork package-derives-schematic-from-model): " - f"{[(hp.mount_id, (hp.x, hp.y)) for hp in moved]} (authored at {[r[2] for r in rows if r[1] == BALLISTIC]})") + saved = [(r[0], tuple(r[2])) for r in layout_rows(scene)] + require(saved == [(mount_id, cell) for mount_id, _, cell in rows], f"A row is not as authored after Package: {saved}") print(f"PASS {number}.5 Package accepts the built ship and keeps hull.scad") # What Package did to the built objects is not an edit: Build still replaces them. @@ -350,12 +387,14 @@ def one_hull(scene, number, fixture, ship_id, extent, length, rows, body, palett collection.objects.link(art) art.parent = root require(any(o.get("aetheria.role") for o in generated(collection).values()), "The scene kept no anchor of Build's") + require(aetherdb(ship_cc, "product", ship_cc, maker, "--remove") == 0, "AetherDb could not remove the product") # her art needs none select(box) result, message = run(bpy.ops.aetheria.package_ship) report = scene.aetheria_package_report require(result == {"FINISHED"} and "deleted hull.scad" in report, f"Package did not retire the hull source: {report!r} {message!r}") require(not source.exists(), "hull.scad is still there after the author's art was packaged") - require("aetheria.hull_built" not in collection, "The record of Build's objects outlived hull.scad") + require("aetheria.hull_built" not in collection and "aetheria.hull_maker" not in collection, + "The record of Build's objects or its maker outlived hull.scad") require(all(echoed not in report for echoed in (ship_id, str(GAME))), "The report echoes an input") select(box) result, message = run(bpy.ops.aetheria.build_hull_source) @@ -447,6 +486,11 @@ def clear(collection): bpy.data.objects.remove(obj) +def aetherdb(ship_path, *args): + """Runs one AetherDb ship-authoring command through the add-on's own runner; returns its exit code.""" + return sys.modules["aetheria_ships"]._aetherdb(bpy.context, *args, ship_cc=ship_path)[0] + + def never_built(scene): """A hull.scad whose hull was never built has no art in the collection: the deletion rule keeps it.""" ship_id = "smoke.hull.unbuilt" @@ -454,7 +498,12 @@ def never_built(scene): api = sys.modules["aetheria_ships"] require(api._retire_hull_source(collection) is False and (package / "hull.scad").is_file(), "A hull that was never built lost its hull.scad") - print("PASS 3 a hull that was never built keeps its hull.scad") + select(box) + result, message = run(bpy.ops.aetheria.package_ship) + report = scene.aetheria_package_report + require(result == {"CANCELLED"} and "Build From Hull Source first" in report and not (package / "ship.glb").exists(), + f"Package took a hull that was never built: {report!r}") + print("PASS 3 a hull that was never built keeps its hull.scad, and Package refuses it") def main(): @@ -487,9 +536,9 @@ def main(): require(not (MODS / ship_id).exists(), f"{MODS / ship_id} exists; remove it first") scene = bpy.context.scene previous = None - for number, (fixture, ship_id, extent, length, rows, body, palette) in enumerate(HULLS, start=1): + for number, (fixture, ship_id, extent, length, rows, body, palette, maker, other) in enumerate(HULLS, start=1): clear(previous) - previous = one_hull(scene, number, fixture, ship_id, extent, length, rows, body, palette) + previous = one_hull(scene, number, fixture, ship_id, extent, length, rows, body, palette, maker, other) clear(previous) never_built(scene) diff --git a/tools/blender/tests/test_hull_source.py b/tools/blender/tests/test_hull_source.py index a7bd201d2..c1045dba0 100644 --- a/tools/blender/tests/test_hull_source.py +++ b/tools/blender/tests/test_hull_source.py @@ -36,11 +36,14 @@ def echo(name, value): return f"ECHO: {name} = {json.dumps(value)}\n" +MAKER = "faction-record-key" + + def language(faction="zhestokost", zones=("primary", "secondary"), body="primary", proportion=((0.25, 0.6), (0.35, 0.75)), - symmetry=("bilateral", 0.97)): + symmetry=("bilateral", 0.97), maker=MAKER): palette = [[z, [0.1 * (i + 1), 0.2, 0.3]] for i, z in enumerate(zones)] return echo("lang", [faction, palette, body, [1, 0.6, 0.2], [0.5, 0.5, 0.5], [list(p) for p in proportion] if proportion - else [], list(symmetry)]) + else [], list(symmetry), maker]) def brief(faction="zhestokost", donor="", length=(8, 14), triangles=(10, 100)): @@ -325,7 +328,7 @@ class LanguageOwnershipTests(unittest.TestCase): def test_a_hull_that_redefines_its_palette_fails_and_is_still_coloured_from_the_file(self): fixture = Fixture() fixture.hull_lang = echo("lang", ["zhestokost", [["primary", [1, 0, 1]], ["secondary", [1, 0, 1]]], "primary", - [1, 0.6, 0.2], [0.5, 0.5, 0.5], [[0.25, 0.6], [0.35, 0.75]], ["bilateral", 0.97]]) + [1, 0.6, 0.2], [0.5, 0.5, 0.5], [[0.25, 0.6], [0.35, 0.75]], ["bilateral", 0.97], MAKER]) self.assertEqual(fixture.failed(), [self.OWN]) built = fixture.build() self.assertEqual(built.colours["primary"], built.languages["zhestokost"].colour("primary")) @@ -345,6 +348,13 @@ class LanguageOwnershipTests(unittest.TestCase): fixture.parts["secondary"] = (box(2, 6, -1, 1, 2, 3), "") # lopsided: the file's bilateral rule refuses it self.assertIn("the top view obeys the language's bilateral rule", fixture.failed()) + def test_a_hull_cannot_restate_its_languages_maker(self): + """The language file owns its maker (the Faction record key Package compares with the product's): an included + language echoed with another maker fails the includes-unchanged check, and the hull is read as the file's.""" + fixture = self.redefined(maker="another-faction-record-key") + self.assertEqual(fixture.failed(), [self.OWN]) + self.assertEqual(fixture.build().languages["zhestokost"].maker, MAKER) + def test_a_second_echo_of_the_language_after_the_first_fails(self): fixture = Fixture() fixture.hull_lang = language() + language(symmetry=("asymmetric", 0.99)) @@ -521,12 +531,21 @@ class RefusalTests(unittest.TestCase): fixture = Fixture() fixture.parts["anchors"] = ("", echo("anchor", anchor)) refused(fixture) - for raw in ([7, [["primary", [1, 1, 1]]], "primary", [1, 1, 1], [1, 1, 1], [], ["bilateral", 1]], - ["zhestokost", [[7, [1, 1, 1]]], "primary", [1, 1, 1], [1, 1, 1], [], ["bilateral", 1]], - ["zhestokost", [["primary", [1, 1, 1]]], 7, [1, 1, 1], [1, 1, 1], [], ["bilateral", 1]]): + for raw in ([7, [["primary", [1, 1, 1]]], "primary", [1, 1, 1], [1, 1, 1], [], ["bilateral", 1], MAKER], + ["zhestokost", [[7, [1, 1, 1]]], "primary", [1, 1, 1], [1, 1, 1], [], ["bilateral", 1], MAKER], + ["zhestokost", [["primary", [1, 1, 1]]], 7, [1, 1, 1], [1, 1, 1], [], ["bilateral", 1], MAKER]): with self.assertRaises(hs.HullSourceError): hs.read_languages(echo("lang", raw)) + def test_the_maker_is_the_eighth_element_of_a_language_echo(self): + self.assertEqual(hs.read_languages(language(maker="K1"))[0].maker, "K1") + raw = ["zhestokost", [["primary", [1, 1, 1]]], "primary", [1, 1, 1], [1, 1, 1], [], ["bilateral", 1]] + for bad in (raw, raw + [""], raw + [7], raw + ["K1", "extra"]): # seven elements, empty maker, not text, nine + with self.assertRaises(hs.HullSourceError) as caught: + hs.read_languages(echo("lang", bad)) + self.assertNotIn("K1", str(caught.exception)) + self.assertEqual(hs.read_languages(echo("lang", raw + ["K1"]))[0].maker, "K1") + def test_a_malformed_anchor_is_refused_without_echoing_it(self): fixture = Fixture() fixture.parts["anchors"] = ("", echo("anchor", [SECRET, "weapon-mount", [0, 0], 0, ""])) diff --git a/tools/blender/tests/test_ship_cc.py b/tools/blender/tests/test_ship_cc.py index b4ea9d313..403d32854 100644 --- a/tools/blender/tests/test_ship_cc.py +++ b/tools/blender/tests/test_ship_cc.py @@ -101,8 +101,10 @@ class ShipFileCase(unittest.TestCase): """Two products as C# stores them, one per maker; Python reads them as envelopes and never encodes one.""" entry = catalog("product-schema-1", ship_cc.PRODUCT_SCHEMA) store = cultcache_py.SingleFileMessagePackBackingStore(self.path) - store.push(envelope("mod-product:mod.skiff:faction:acme", ship_cc.PRODUCT_SCHEMA, entry, [None, "Acme Skiff", "Reliable."])) - store.push(envelope("mod-product:mod.skiff:faction:rival", ship_cc.PRODUCT_SCHEMA, entry, [None, "Rival Skiff", None, "tail"])) + store.push(envelope("mod-product:mod.skiff:faction:acme", ship_cc.PRODUCT_SCHEMA, entry, + [None, "Acme Skiff", "Reliable.", None, "acme-faction-key"])) + store.push(envelope("mod-product:mod.skiff:faction:rival", ship_cc.PRODUCT_SCHEMA, entry, + [None, "Rival Skiff", None, "tail", "rival-faction-key"])) def products(self): return {(e.type, e.key): e for e in cultcache_py.SingleFileMessagePackBackingStore(self.path).pull_all() @@ -214,6 +216,38 @@ class ReadTests(ShipFileCase): ship_cc.read(self.path, PACKAGES) +class ProductMakerTests(ShipFileCase): + """Manufacturer is slot 4 of a product, the Faction record key; Python reads it and never writes a product.""" + + def push_product(self, key, body): + entry = catalog("product-schema-1", ship_cc.PRODUCT_SCHEMA) + cultcache_py.SingleFileMessagePackBackingStore(self.path).push(envelope(key, ship_cc.PRODUCT_SCHEMA, entry, body)) + + def test_each_products_manufacturer_is_read_in_file_order(self): + self.add_products() + self.assertEqual(["acme-faction-key", "rival-faction-key"], ship_cc.product_makers(self.path, PACKAGES)) + + def test_a_file_with_no_product_has_no_maker(self): + self.assertEqual([], ship_cc.product_makers(self.path, PACKAGES)) + + def test_the_manufacturer_is_read_from_its_slot_not_from_a_neighbour(self): + self.push_product("mod-product:mod.skiff:faction:acme", [None, "name-slot", "description-slot", "design-slot", + "maker-slot", "roles-slot"]) + self.assertEqual(["maker-slot"], ship_cc.product_makers(self.path, PACKAGES)) + + def test_a_product_with_no_manufacturer_is_refused_naming_no_input(self): + canary = "canary-product-name" + for body in ([None, canary, "Reliable."], [None, canary, None, None, None], [None, canary, None, None, ""], + [None, canary, None, None, 7]): + with self.subTest(body=body): + self.setUp() + self.push_product("mod-product:mod.skiff:faction:" + canary, body) + with self.assertRaises(ValueError) as caught: + ship_cc.product_makers(self.path, PACKAGES) + self.assertNotIn(canary, str(caught.exception)) + self.assertNotIn(self.path, str(caught.exception)) + + class ProductCarryThroughTests(ShipFileCase): """Products lie beside the pair, owned by C#: every push rewrites the file and leaves them byte-identical."""