feat: derive autoresponder schedule from backend

This commit is contained in:
Marek Miklewicz
2026-06-02 19:55:07 +02:00
parent a0bd158a2e
commit f3abc7b33f
19 changed files with 248 additions and 43 deletions
+21
View File
@@ -0,0 +1,21 @@
<?php
declare(strict_types=1);
require_once PLUGIN_ROOT . '/exec/lib/Settings.php';
require_once PLUGIN_ROOT . '/exec/lib/BackendRuntimeConfig.php';
test('backend runtime sync invokes backend script when setting changes', function (): void {
$settingsPath = TEST_TMP . '/backend-runtime.conf';
test_write($settingsPath, "GLOBAL_AUTORESPONDER_BACKEND=exim\n");
$settings = Settings::load($settingsPath);
$script = TEST_TMP . '/backend.sh';
test_write($script, "#!/bin/sh\necho \"$1\" >> " . escapeshellarg(TEST_TMP . '/called.log') . "\nmkdir -p " . escapeshellarg(TEST_TMP . '/config') . "\nprintf '{\"active_backend\":\"%s\"}\\n' \"$1\" > " . escapeshellarg(TEST_TMP . '/config/backend-state.json') . "\n");
chmod($script, 0700);
BackendRuntimeConfig::sync($settings, $script, TEST_TMP . '/config/backend-state.json');
assert_same("exim\n", file_get_contents(TEST_TMP . '/called.log'));
BackendRuntimeConfig::sync($settings, $script, TEST_TMP . '/config/backend-state.json');
assert_same("exim\n", file_get_contents(TEST_TMP . '/called.log'), 'Script should not run again when backend is already active');
});