From: Vsevolod Stakhov Date: Wed, 19 Nov 2025 12:44:15 +0000 (+0000) Subject: [Fix] Preserve metatables in shallowcopy and save test configs X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a29cf4046ed5615dcb0b4e6a5146fcd0d16bab98;p=thirdparty%2Frspamd.git [Fix] Preserve metatables in shallowcopy and save test configs - Fix shallowcopy to preserve metatables when copying schema objects - Ensure configdump output and input config are always saved to robot-save even if configdump crashes with assertion failure --- diff --git a/lualib/lua_shape/core.lua b/lualib/lua_shape/core.lua index 528f08f1be..9afeeb4b9a 100644 --- a/lualib/lua_shape/core.lua +++ b/lualib/lua_shape/core.lua @@ -25,6 +25,11 @@ local function shallowcopy(t) for k, v in pairs(t) do result[k] = v end + -- Preserve metatable if present + local mt = getmetatable(t) + if mt then + setmetatable(result, mt) + end return result end diff --git a/lualib/lua_shape/registry.lua b/lualib/lua_shape/registry.lua index 0140998850..e5118a92a8 100644 --- a/lualib/lua_shape/registry.lua +++ b/lualib/lua_shape/registry.lua @@ -26,6 +26,11 @@ local function shallowcopy(t) for k, v in pairs(t) do result[k] = v end + -- Preserve metatable if present + local mt = getmetatable(t) + if mt then + setmetatable(result, mt) + end return result end diff --git a/test/functional/lib/rspamd.robot b/test/functional/lib/rspamd.robot index 1bda5e5c2e..eb69fed4ef 100644 --- a/test/functional/lib/rspamd.robot +++ b/test/functional/lib/rspamd.robot @@ -321,6 +321,9 @@ Run Rspamd [Arguments] ${check_port}=${RSPAMD_PORT_NORMAL} Export Rspamd Variables To Environment + # Copy config file to TMPDIR so it gets saved on teardown + Copy File ${CONFIG} ${RSPAMD_TMPDIR}/rspamd.conf + # Dump templated config or errors to log ${result} = Run Process ${RSPAMADM} ... --var\=TMPDIR\=${RSPAMD_TMPDIR} @@ -336,10 +339,37 @@ Run Rspamd ... env:ASAN_OPTIONS=quarantine_size_mb=2048:malloc_context_size=20:fast_unwind_on_malloc=0:log_path=${RSPAMD_TMPDIR}/rspamd-asan # We need to send output to files (or discard output) to avoid hanging Robot ... stdout=${RSPAMD_TMPDIR}/configdump.stdout stderr=${RSPAMD_TMPDIR}/configdump.stderr + + # Always save configdump output to files, even if it failed + # First save process output directly to ensure we have something even if files weren't created + ${stdout_exists} = Run Keyword And Return Status File Should Exist ${RSPAMD_TMPDIR}/configdump.stdout + ${stderr_exists} = Run Keyword And Return Status File Should Exist ${RSPAMD_TMPDIR}/configdump.stderr + + IF not ${stdout_exists} + # File wasn't created, use process stdout if available + ${stdout_len} = Get Length ${result.stdout} + IF ${stdout_len} > 0 + Create File ${RSPAMD_TMPDIR}/configdump.stdout ${result.stdout} + ELSE + Create File ${RSPAMD_TMPDIR}/configdump.stdout + END + END + + IF not ${stderr_exists} + # File wasn't created, use process stderr if available + ${stderr_len} = Get Length ${result.stderr} + IF ${stderr_len} > 0 + Create File ${RSPAMD_TMPDIR}/configdump.stderr ${result.stderr} + ELSE + Create File ${RSPAMD_TMPDIR}/configdump.stderr + END + END + IF ${result.rc} == 0 ${configdump} = Get File ${RSPAMD_TMPDIR}/configdump.stdout encoding_errors=ignore ELSE ${configdump} = Get File ${RSPAMD_TMPDIR}/configdump.stderr encoding_errors=ignore + Log Configdump failed with rc=${result.rc} level=WARN END Log ${configdump}