fix: retain Symcon webhook registration and show configured view title
This commit is contained in:
1 parent
28dd3880b5
commit
0fed9dc5e5
6 files changed
+103
-33
No files matched your search
@@ -25,6 +25,7 @@ class IPSModuleStrict
|
||||
public int $status = 101;
|
||||
public ?bool $registrationResult = true;
|
||||
public bool $registrationThrows = false;
|
||||
public array $registrationRunlevels = [];
|
||||
|
||||
public function __construct(int $id) { $this->InstanceID = $id; }
|
||||
public function Create(): void {}
|
||||
@@ -53,7 +54,7 @@ class IPSModuleStrict
|
||||
protected function RegisterHook(string $path): ?bool
|
||||
{
|
||||
global $nativeHooks;
|
||||
check(IPS_GetKernelRunlevel() === KR_READY, 'Do not depend on WebHook Control before the kernel is ready');
|
||||
$this->registrationRunlevels[] = IPS_GetKernelRunlevel();
|
||||
if ($this->registrationThrows) throw new RuntimeException('WebHook Control unavailable');
|
||||
if ($this->registrationResult !== false) $nativeHooks['/hook/' . $path] = $this->InstanceID;
|
||||
return $this->registrationResult;
|
||||
@@ -62,26 +63,48 @@ class IPSModuleStrict
|
||||
|
||||
require __DIR__ . '/../NextFloor/module.php';
|
||||
$module = new NextFloor(12345);
|
||||
$hook = '/hook/nextfloor/12345';
|
||||
$module->Create();
|
||||
check($nativeHooks === [] && $module->status === 104, 'Startup must wait instead of reporting a nonexistent hook as ready');
|
||||
check(($nativeHooks[$hook] ?? null) === 12345 && $module->status === 104, 'Create registers the native hook early without reporting the initializing kernel as ready');
|
||||
check($module->registrationRunlevels === [KR_INIT], 'Create must register hooks during initialization, as required by the native lifecycle');
|
||||
check(in_array([0, IPS_KERNELSTARTED], $module->messages, true), 'Module must listen for the completed kernel startup');
|
||||
check(in_array([0, KR_READY], $module->messages, true), 'Module also restores its route as soon as the kernel becomes ready');
|
||||
check($module->timers['WebHookRetry']['interval'] === 5000, 'Startup recovery must be scheduled');
|
||||
|
||||
$kernelRunlevel = KR_READY;
|
||||
$nativeHooks = [];
|
||||
$module->MessageSink(1, 0, KR_READY, []);
|
||||
check(isset($nativeHooks[$hook]), 'KR_READY restores routes cleared after Create');
|
||||
$nativeHooks = [];
|
||||
$module->MessageSink(1, 0, IPS_KERNELSTARTED, []);
|
||||
$hook = '/hook/nextfloor/12345';
|
||||
check(($nativeHooks[$hook] ?? null) === 12345 && $module->status === 102, 'Kernel startup must restore the instance hook');
|
||||
check($module->timers['WebHookRetry']['interval'] === 0, 'Successful registration stops the retry timer');
|
||||
check($module->timers['WebHookRetry']['interval'] === 30000, 'Successful registration keeps maintenance active for delayed resets');
|
||||
$token = $module->attributes['AccessToken'];
|
||||
$module->attributes['Building'] = '{"preserved_project":true}';
|
||||
$module->properties['Title'] = ' Haus & Büro <West> ';
|
||||
|
||||
$nativeHooks = [];
|
||||
$link = $module->OpenDesigner();
|
||||
check(isset($nativeHooks[$hook]) && str_starts_with($link, 'link:' . $hook . '/designer?'), 'Opening the designer repairs a lost route before returning its URL');
|
||||
$nativeHooks = [];
|
||||
check(str_contains($module->GetVisualizationTile(), '<iframe') && isset($nativeHooks[$hook]), 'Opening a tile also repairs its route');
|
||||
check(str_contains($module->GetVisualizationTile(), 'title="Haus & Büro <West>"'), 'Tile iframe uses the escaped configured view name');
|
||||
$module->ApplyChanges();
|
||||
check(isset($nativeHooks[$hook]), 'ApplyChanges restores hooks after module reload');
|
||||
for ($reload = 0; $reload < 3; $reload++) {
|
||||
unset($nativeHooks[$hook]); // WebHook Control resets after our successful ApplyChanges.
|
||||
$module->RetryWebHook();
|
||||
check(isset($nativeHooks[$hook]) && $module->status === 102, 'Maintenance restores delayed hook loss without opening a designer or tile');
|
||||
check($module->timers['WebHookRetry']['interval'] === 30000, 'Maintenance must survive every successful recovery');
|
||||
}
|
||||
$kernelRunlevel = KR_INIT;
|
||||
$nativeHooks = [];
|
||||
$module->Create();
|
||||
$module->ApplyChanges();
|
||||
check($module->status === 104, 'Restart initialization must not report ready');
|
||||
$kernelRunlevel = KR_READY;
|
||||
$module->MessageSink(2, 0, IPS_KERNELSTARTED, []);
|
||||
check(isset($nativeHooks[$hook]) && $module->attributes['AccessToken'] === $token, 'A full restart restores the same route and retains the original access token');
|
||||
|
||||
$module->registrationResult = false;
|
||||
$module->ApplyChanges();
|
||||
@@ -110,6 +133,15 @@ check($module->attributes['AccessToken'] === $token && $module->attributes['Buil
|
||||
$other = new NextFloor(54321);
|
||||
$other->Create();
|
||||
check(isset($nativeHooks[$hook]) && isset($nativeHooks['/hook/nextfloor/54321']), 'Instances must keep independent routes');
|
||||
$kernelRunlevel = KR_INIT;
|
||||
$earlyFailure = new NextFloor(34567);
|
||||
$earlyFailure->registrationThrows = true;
|
||||
$earlyFailure->Create();
|
||||
check($earlyFailure->status === 104 && $earlyFailure->timers['WebHookRetry']['interval'] === 5000 && $earlyFailure->logs === [], 'An early startup registration failure waits and retries without an error log');
|
||||
$kernelRunlevel = KR_READY;
|
||||
$earlyFailure->registrationThrows = false;
|
||||
$earlyFailure->RetryWebHook();
|
||||
check(isset($nativeHooks['/hook/nextfloor/34567']) && $earlyFailure->status === 102, 'Unavailable early WebHook Control must recover automatically');
|
||||
|
||||
// Verify that returned URLs reach the real dispatcher, including Symcon's SCRIPT_NAME fallback.
|
||||
parse_str((string) parse_url(substr($link, 5), PHP_URL_QUERY), $_GET);
|
||||
@@ -119,6 +151,9 @@ ob_start();
|
||||
$process->invoke($module);
|
||||
$html = ob_get_clean();
|
||||
check(str_contains($html, 'window.__NEXTFLOOR_SYMCON__=') && str_contains($html, 'assets/nextfloor-designer.js'), 'Designer route must serve its host page');
|
||||
check(str_contains($html, '<title>Haus & Büro <West></title>'), 'Browser title uses the escaped configured view name');
|
||||
preg_match('/window\.__NEXTFLOOR_SYMCON__=(.*?);<\/script>/s', $html, $hostConfig);
|
||||
check(json_decode($hostConfig[1], true)['title'] === 'Haus & Büro <West>', 'Frontend receives the configured title as plain text');
|
||||
$version = json_decode((string) file_get_contents(__DIR__ . '/../library.json'), true)['version'];
|
||||
check(str_contains($html, 'nextfloor-designer.js?v=' . $version), 'A module update must invalidate the cached designer entry bundle');
|
||||
unset($_SERVER['REQUEST_URI']);
|
||||
@@ -133,4 +168,4 @@ $process->invoke($module);
|
||||
$unauthorized = ob_get_clean();
|
||||
check(http_response_code() === 403 && str_contains($unauthorized, 'forbidden'), 'Recovery must not bypass hook authentication');
|
||||
|
||||
echo "OK: kernel startup, reload, designer/tile recovery, failed registration, retry, repair, data preservation, routing and authentication\n";
|
||||
echo "OK: early registration, startup/update and delayed reset recovery, ongoing maintenance, titles, data preservation, routing and authentication\n";
|
||||
Reference in new issue
Block a user