diff --git a/src/slic3r/GUI/Mcp/McpStdioBridge.cpp b/src/slic3r/GUI/Mcp/McpStdioBridge.cpp index dcb8ec71f3..9783dd1547 100644 --- a/src/slic3r/GUI/Mcp/McpStdioBridge.cpp +++ b/src/slic3r/GUI/Mcp/McpStdioBridge.cpp @@ -50,6 +50,7 @@ #include #else #include +#include #include #include #include @@ -248,10 +249,15 @@ bool launch_app(const std::string& exe, const std::string& datadir, int port) if (pid == 0) { setsid(); // The GUI must not inherit the MCP stdio pipes, stderr included: it outlives the bridge, and - // would keep the client's pipe open and write into it once the client has gone. - std::freopen("/dev/null", "r", stdin); - std::freopen("/dev/null", "w", stdout); - std::freopen("/dev/null", "w", stderr); + // would keep the client's pipe open and write into it once the client has gone. Without + // /dev/null to put in their place it does not start, which the parent reports as a failed launch. + const int null_fd = open("/dev/null", O_RDWR); + if (null_fd < 0) + _exit(127); + for (int fd = STDIN_FILENO; fd <= STDERR_FILENO; ++fd) + dup2(null_fd, fd); + if (null_fd > STDERR_FILENO) + close(null_fd); std::vector args{exe, "--mcp"}; if (!datadir.empty()) { args.push_back("--datadir"); diff --git a/src/slic3r/GUI/Mcp/McpToolsLayers.cpp b/src/slic3r/GUI/Mcp/McpToolsLayers.cpp index 158c2be248..8d0747dd73 100644 --- a/src/slic3r/GUI/Mcp/McpToolsLayers.cpp +++ b/src/slic3r/GUI/Mcp/McpToolsLayers.cpp @@ -7,6 +7,7 @@ #include "slic3r/GUI/I18N.hpp" #include "McpTargets.hpp" #include "McpTools.hpp" +#include "slic3r/GUI/CommandCatalog.hpp" #include "slic3r/GUI/CommandTypes.hpp" #include "slic3r/GUI/GCodeViewer.hpp" #include "slic3r/GUI/GLCanvas3D.hpp" diff --git a/src/slic3r/GUI/Mcp/McpToolsReplay.cpp b/src/slic3r/GUI/Mcp/McpToolsReplay.cpp index 4ede338af9..eb00e87684 100644 --- a/src/slic3r/GUI/Mcp/McpToolsReplay.cpp +++ b/src/slic3r/GUI/Mcp/McpToolsReplay.cpp @@ -1,6 +1,7 @@ // replay_run and replay_export: deterministic replays of tool calls, and turning a session into one. #include "JobRegistry.hpp" +#include "slic3r/GUI/CommandCatalog.hpp" #include "slic3r/GUI/CommandTypes.hpp" #include "slic3r/GUI/I18N.hpp" #include "slic3r/GUI/NativeCommands.hpp" diff --git a/src/slic3r/GUI/Mcp/VideoOverlay.cpp b/src/slic3r/GUI/Mcp/VideoOverlay.cpp index fa24bb1c30..d036d82828 100644 --- a/src/slic3r/GUI/Mcp/VideoOverlay.cpp +++ b/src/slic3r/GUI/Mcp/VideoOverlay.cpp @@ -394,8 +394,8 @@ bool encode_jpeg(const uint8_t* rgb, int width, int height, int stride, int qual job->info.input_components = 3; job->info.in_color_space = JCS_RGB; jpeg_set_defaults(&job->info); - jpeg_set_quality(&job->info, quality, TRUE); - jpeg_start_compress(&job->info, TRUE); + jpeg_set_quality(&job->info, quality, true); + jpeg_start_compress(&job->info, true); for (int y = 0; y < height; ++y) { JSAMPROW row = const_cast(rgb + std::size_t(y) * std::size_t(stride)); jpeg_write_scanlines(&job->info, &row, 1); diff --git a/tests/automation/test_mcp_core.cpp b/tests/automation/test_mcp_core.cpp index 38971b8a6a..661f560f31 100644 --- a/tests/automation/test_mcp_core.cpp +++ b/tests/automation/test_mcp_core.cpp @@ -1634,10 +1634,12 @@ TEST_CASE("a plugin's session tools act only on the jobs of its own calls", "[Mc TEST_CASE("an unloaded plugin's calls start no job, nor do the children of one already running", "[Mcp]") { Harness h; + std::atomic started{false}; std::atomic release{false}; ToolResult child; h.registry.add(tool("make", GuardClass::Mutate, [](const json&, ToolContext&) { return ToolResult::ok(); })); h.registry.add(tool("slow", GuardClass::Mutate, [&](const json&, ToolContext& ctx) { + started = true; while (!release) std::this_thread::sleep_for(std::chrono::milliseconds(5)); child = ctx.call_child("make", json::object()); @@ -1645,9 +1647,10 @@ TEST_CASE("an unloaded plugin's calls start no job, nor do the children of one a })); h.timing.soft_budget = std::chrono::milliseconds(10000); h.start(); - // A call that was admitted before the unload and is still running when it comes. + // A call that was admitted before the unload and is still running when it comes. Its job is listed before its + // admission ends, and a block between the two refuses the call itself, so the test waits for its handler. std::thread running([&] { h.core->call_plugin(*h.registry.find("slow"), json::object(), "measure"); }); - while (h.jobs.running_owned_by("measure").empty()) + while (!started) std::this_thread::sleep_for(std::chrono::milliseconds(5)); h.jobs.block_owner("measure"); diff --git a/tests/slic3rutils/slic3rutils_tests_main.cpp b/tests/slic3rutils/slic3rutils_tests_main.cpp index b23e6731cd..27db64d7b2 100644 --- a/tests/slic3rutils/slic3rutils_tests_main.cpp +++ b/tests/slic3rutils/slic3rutils_tests_main.cpp @@ -1,17 +1,32 @@ #include #include +#include #include #include #include #include +#include + #include "catch2/interfaces/catch_interfaces_reporter.hpp" #include "slic3r/Utils/Http.hpp" namespace { +// Converts narrow boost paths as UTF-8 for the whole run, as the app does from startup +// (boost::nowide::nowide_filesystem() in OrcaSlicer.cpp). The plugin and script code relies on +// it, and without it Windows reads a path in the ANSI code page, which a machine set to UTF-8 +// hides and a non-ASCII path on any other breaks. +class AppPathConversion final : public Catch::EventListenerBase +{ +public: + using Catch::EventListenerBase::EventListenerBase; + + void testRunStarting(const Catch::TestRunInfo&) override { boost::nowide::nowide_filesystem(); } +}; + // Finalizes the embedded interpreter once, after the last test case, and never between cases. // CPython cannot be reinitialized after Py_Finalize (a second init aborts inside _datetime), and // the app likewise finalizes it only at exit, so the per-test fixtures tear down only the @@ -33,6 +48,7 @@ public: } // namespace +CATCH_REGISTER_LISTENER(AppPathConversion) CATCH_REGISTER_LISTENER(PythonInterpreterRunEnd) TEST_CASE("Check SSL certificates paths", "[Http][NotWorking]") { diff --git a/tests/slic3rutils/test_mcp_cad.cpp b/tests/slic3rutils/test_mcp_cad.cpp index a35567f218..3ff0d84928 100644 --- a/tests/slic3rutils/test_mcp_cad.cpp +++ b/tests/slic3rutils/test_mcp_cad.cpp @@ -71,6 +71,7 @@ #include #include #include +#include #include #include #include diff --git a/tests/slic3rutils/test_plugin_audit.cpp b/tests/slic3rutils/test_plugin_audit.cpp index 76ca0189e1..ab29914f32 100644 --- a/tests/slic3rutils/test_plugin_audit.cpp +++ b/tests/slic3rutils/test_plugin_audit.cpp @@ -1,6 +1,5 @@ #include #include -#include #include #include @@ -1020,14 +1019,6 @@ TEST_CASE("Plugin audit denies secret/certificate/config-like paths by keyword", namespace { -// Converts paths as UTF-8 for the test's lifetime, as the app does from startup -// (boost::nowide::nowide_filesystem() in OrcaSlicer.cpp). -struct Utf8PathConversion -{ - std::locale previous = boost::nowide::nowide_filesystem(); - ~Utf8PathConversion() { fs::path::imbue(previous); } -}; - // Switches the C library's character classification to a single-byte code page, as the app's UI // language does on Windows (Russian_Russia.1251), when the system has one. struct SingleByteCtypeLocale @@ -1057,7 +1048,7 @@ TEST_CASE("Plugin audit keyword check keeps non-Latin path names intact", "[audi // Lowering these names byte by byte in a single-byte C locale broke their UTF-8, and turning // the result back into a path threw out of the audit hook: the plugin call never returned. - const Utf8PathConversion utf8_paths; + // Paths convert as UTF-8, as in the app, for the whole test run (slic3rutils_tests_main.cpp). const SingleByteCtypeLocale ctype; INFO("single-byte C locale in use: " << (ctype.applied ? "yes" : "no")); diff --git a/tests/slic3rutils/test_python_script_runner.cpp b/tests/slic3rutils/test_python_script_runner.cpp index c2bb239ebc..2309be227b 100644 --- a/tests/slic3rutils/test_python_script_runner.cpp +++ b/tests/slic3rutils/test_python_script_runner.cpp @@ -2721,14 +2721,15 @@ TEST_CASE("a task queued when a cell is stopped never runs, and the next cell's if (!harness.initialized) SKIP("Bundled Python interpreter unavailable: " + PythonInterpreter::instance().last_error()); - SharedModule shared("_queued", {"ran"}); + SharedModule shared("_queued", {"ran", "submitted"}); HostedSession hosted; REQUIRE(hosted.session.submit(cell("import time, _queued\nfrom concurrent.futures import ThreadPoolExecutor\n" "ex = ThreadPoolExecutor(1)\n" "def spin():\n while True:\n time.sleep(0.01)\n" - "ex.submit(spin)\nsecond = ex.submit(_queued.ran.set)\n" + "ex.submit(spin)\nsecond = ex.submit(_queued.ran.set)\n_queued.submitted.set()\n" "while True:\n time.sleep(0.01)\n"))); - std::this_thread::sleep_for(std::chrono::milliseconds(500)); + // The stop comes after both submits: a task submitted after a stop is the session's next work, which runs. + REQUIRE(shared.wait("submitted", 10)); hosted.session.stop(); const WorkEvents stopped = await_work(hosted.session); REQUIRE(stopped.finished);