From a2282f36664854063359e0fd3b83b24e628c3d6d Mon Sep 17 00:00:00 2001 From: BuckarooBanzay Date: Thu, 29 Oct 2026 11:28:32 +0100 Subject: [PATCH] Add mtt test harness with smoke and pipe network tests Co-Authored-By: Claude Sonnet 5.5 --- .github/workflows/test.yml | 15 +++++++++++++++ .luacheckrc | 2 +- docker-compose.yml | 15 +++++++++++++++ init.lua | 5 +++++ mod.conf | 2 +- mtt/network.spec.lua | 39 ++++++++++++++++++++++++++++++++++++++ mtt/smoketests.spec.lua | 23 ++++++++++++++++++++++ 7 files changed, 99 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/test.yml create mode 100644 docker-compose.yml create mode 100644 mtt/network.spec.lua create mode 100644 mtt/smoketests.spec.lua diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..46580b4 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,15 @@ +name: test +on: [push, pull_request] +jobs: + test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: buckaroobanzay/mtt@main + with: + modname: pipeworks + git_dependencies: | + https://github.com/BuckarooBanzay/mtt + https://github.com/OgelGames/fakelib + https://github.com/mt-mods/xcompat + https://github.com/mt-mods/basic_materials diff --git a/.luacheckrc b/.luacheckrc index 4946632..5bde6d4 100644 --- a/.luacheckrc +++ b/.luacheckrc @@ -16,5 +16,5 @@ read_globals = { "screwdriver", "unified_inventory", "i3", "mcl_experience", "awards", "xcompat", "fakelib", "vizlib", - "mcl_redstone", + "mcl_redstone","mtt" } diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..6388b16 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,15 @@ +services: + mtt: + image: ghcr.io/buckaroobanzay/mtt:latest + volumes: + - "./:/github/workspace" + environment: + INPUT_MODNAME: "pipeworks" + INPUT_TEST_MODE: "mod" + INPUT_MAPGEN: "singlenode" + INPUT_GIT_GAME_REPO: "https://github.com/minetest/minetest_game" + INPUT_GIT_DEPENDENCIES: | + https://github.com/BuckarooBanzay/mtt + https://github.com/OgelGames/fakelib + https://github.com/mt-mods/xcompat + https://github.com/mt-mods/basic_materials diff --git a/init.lua b/init.lua index 6d04627..b9f863b 100644 --- a/init.lua +++ b/init.lua @@ -132,4 +132,9 @@ if core.get_modpath("unified_inventory") and unified_inventory.registered_catego unified_inventory.add_category_items("automation", pipeworks.ui_cat_tube_list) end +if core.get_modpath("mtt") and mtt.enabled then + dofile(pipeworks.modpath.."/mtt/smoketests.spec.lua") + dofile(pipeworks.modpath.."/mtt/network.spec.lua") +end + core.log("info", "Pipeworks loaded!") diff --git a/mod.conf b/mod.conf index a3b5656..9372c73 100644 --- a/mod.conf +++ b/mod.conf @@ -2,5 +2,5 @@ name = pipeworks title = Pipeworks description = This mod uses mesh nodes and nodeboxes to supply a complete set of 3D pipes and tubes, along with devices that work with them. depends = basic_materials, xcompat, fakelib -optional_depends = mesecons, mesecons_mvps, digilines, signs_lib, unified_inventory, default, screwdriver, fl_mapgen, sound_api, i3, hades_core, hades_furnaces, hades_chests, mcl_mapgen_core, mcl_barrels, mcl_furnaces, mcl_blast_furnace, mcl_smoker, mcl_experience, vizlib, mapgen +optional_depends = mesecons, mesecons_mvps, digilines, signs_lib, unified_inventory, default, screwdriver, fl_mapgen, sound_api, i3, hades_core, hades_furnaces, hades_chests, mcl_mapgen_core, mcl_barrels, mcl_furnaces, mcl_blast_furnace, mcl_smoker, mcl_experience, vizlib, mapgen, mtt min_minetest_version = 5.10.0 diff --git a/mtt/network.spec.lua b/mtt/network.spec.lua new file mode 100644 index 0000000..fe96d60 --- /dev/null +++ b/mtt/network.spec.lua @@ -0,0 +1,39 @@ +-- chest -> filter-injector -> tube -> chest, running along the x-axis +mtt.register_with_area("chest -> injector -> tube -> chest", { + size = { x = 5, y = 3, z = 3 }, + emerged = true +}, function(pos1, _, callback) + local chest = "default:chest" + + local y, z = pos1.y + 1, pos1.z + 1 + local chest_in = { x = pos1.x, y = y, z = z } + local injector = { x = pos1.x + 1, y = y, z = z } + local tube = { x = pos1.x + 2, y = y, z = z } + local chest_out = { x = pos1.x + 3, y = y, z = z } + + core.set_node(chest_in, { name = chest, param2 = 0 }) + core.set_node(injector, { name = "pipeworks:filter", param2 = 0 }) + core.set_node(tube, { name = "pipeworks:tube_1" }) + core.set_node(chest_out, { name = chest, param2 = 0 }) + pipeworks.scan_for_tube_objects(tube) + + core.get_meta(injector):set_string("owner", "singleplayer") + core.get_meta(chest_in):get_inventory():add_item("main", "default:dirt 3") + + local node = core.get_node(injector) + core.registered_nodes["pipeworks:filter"].on_punch(injector, node, nil) + + -- itemwise injector, the item travels through the tube asynchronously + local inv_out = core.get_meta(chest_out):get_inventory() + local function check() + if inv_out:contains_item("main", "default:dirt") then + -- exactly one item moved per punch + assert(core.get_meta(chest_in):get_inventory():contains_item("main", "default:dirt 2")) + assert(not inv_out:contains_item("main", "default:dirt 2")) + callback() + else + core.after(0.2, check) + end + end + check() +end) diff --git a/mtt/smoketests.spec.lua b/mtt/smoketests.spec.lua new file mode 100644 index 0000000..b7e054a --- /dev/null +++ b/mtt/smoketests.spec.lua @@ -0,0 +1,23 @@ +-- mtt tests, only loaded if the "mtt" mod is present and enabled + +mtt.register("registered nodes", function(callback) + assert(core.registered_nodes["pipeworks:pipe_110000_empty"]) + assert(core.registered_nodes["pipeworks:pipe_110000_loaded"]) + assert(core.registered_nodes["pipeworks:tube_1"]) + assert(core.registered_nodes["pipeworks:trashcan"]) + if pipeworks.enable_autocrafter then + assert(core.registered_nodes["pipeworks:autocrafter"]) + end + callback() +end) + +mtt.register("pipe alias", function(callback) + assert(core.registered_aliases["pipeworks:pipe"] == "pipeworks:pipe_110000_empty") + callback() +end) + +mtt.register("tube api", function(callback) + assert(type(pipeworks.register_tube) == "function") + assert(type(pipeworks.scan_for_tube_objects) == "function") + callback() +end)