feat: release Symcon 0.2.2 with object tree selection and hook recovery

This commit is contained in:
jhartworks committed 2026-11-09 12:50:45 +01:00
1 parent e1321b6b34
commit 1a78cde02d
8 files changed
+995 -541

No files matched your search

+50
View File
@@ -0,0 +1,50 @@
<?php
declare(strict_types=1);
// A small native-API fixture exercises the actual module export without a running Symcon server.
class IPSModuleStrict {}
$objects = [
10 => ['ParentID' => 0, 'ObjectName' => 'Haus / Altbau', 'ObjectType' => 0, 'ObjectPosition' => 2],
11 => ['ParentID' => 10, 'ObjectName' => 'Heizung', 'ObjectType' => 1, 'ObjectPosition' => 0],
12 => ['ParentID' => 11, 'ObjectName' => 'Temperatur', 'ObjectType' => 2, 'ObjectPosition' => 5],
13 => ['ParentID' => 12, 'ObjectName' => 'Bei Änderung', 'ObjectType' => 4, 'ObjectPosition' => 0],
14 => ['ParentID' => 10, 'ObjectName' => 'Temperatur-Link', 'ObjectType' => 6, 'ObjectPosition' => 1],
15 => ['ParentID' => 0, 'ObjectName' => 'Leer', 'ObjectType' => 0, 'ObjectPosition' => 9],
16 => ['ParentID' => 10, 'ObjectName' => 'Skript', 'ObjectType' => 3, 'ObjectPosition' => 0],
17 => ['ParentID' => 10, 'ObjectName' => 'Bild', 'ObjectType' => 5, 'ObjectPosition' => 0],
18 => ['ParentID' => 0, 'ObjectName' => 'I/O', 'ObjectType' => 1, 'ObjectPosition' => 0],
19 => ['ParentID' => 18, 'ObjectName' => 'I/O-Wert', 'ObjectType' => 2, 'ObjectPosition' => 0],
20 => ['ParentID' => 0, 'ObjectName' => 'Kern', 'ObjectType' => 1, 'ObjectPosition' => 0],
21 => ['ParentID' => 0, 'ObjectName' => 'Splitter', 'ObjectType' => 1, 'ObjectPosition' => 0],
22 => ['ParentID' => 0, 'ObjectName' => 'Konfigurator', 'ObjectType' => 1, 'ObjectPosition' => 0],
23 => ['ParentID' => 0, 'ObjectName' => 'Discovery', 'ObjectType' => 1, 'ObjectPosition' => 0],
24 => ['ParentID' => 0, 'ObjectName' => 'Visualisierung', 'ObjectType' => 1, 'ObjectPosition' => 0]
];
function IPS_GetChildrenIDs(int $id): array { global $objects; return array_keys(array_filter($objects, static fn(array $object): bool => $object['ParentID'] === $id)); }
function IPS_ObjectExists(int $id): bool { global $objects; return isset($objects[$id]); }
function IPS_GetObject(int $id): array { global $objects; return [...$objects[$id], 'ObjectIsHidden' => in_array($id, [10, 12], true), 'ObjectIcon' => 'Temperature']; }
function IPS_GetInstance(int $id): array { return ['ModuleInfo' => ['ModuleType' => [18 => 1, 20 => 0, 21 => 2, 22 => 4, 23 => 5, 24 => 6][$id] ?? 3]]; }
function IPS_GetName(int $id): string { global $objects; return $objects[$id]['ObjectName']; }
function IPS_GetLink(int $id): array { return ['TargetID' => 12]; }
function IPS_GetVariable(int $id): array { return ['VariableType' => 2, 'VariableProfile' => '', 'VariableCustomProfile' => '', 'VariableCustomAction' => 0, 'VariableAction' => 0]; }
function GetValue(int $id): float { return 21.5; }
function GetValueFormatted(int $id): string { return '21,5 °C'; }
function IPS_VariableProfileExists(string $profile): bool { return false; }
require __DIR__ . '/../NextFloor/module.php';
$module = new NextFloor();
$result = (new ReflectionMethod($module, 'objectTree'))->invoke($module);
$nodes = array_column($result['objects'], null, 'object_id');
function check(bool $condition, string $message): void { if (!$condition) throw new RuntimeException($message); }
check(count($nodes) === count($objects), 'Every native object must remain visible, including empty and non-variable objects');
check($nodes[12]['parent_id'] === 11 && $nodes[13]['parent_id'] === 12, 'Real parent IDs must be preserved');
check($nodes[10]['name'] === 'Haus / Altbau', 'Do not split object names into artificial branches');
check($nodes[12]['hidden'] === true && $nodes[12]['position'] === 5, 'Preserve hidden objects and console position');
check($nodes[14]['entity_id'] === $nodes[12]['entity_id'], 'A variable link selects its original target');
check(!isset($nodes[16]['entity_id']), 'Scripts are visible but are not variable selections');
check($nodes[10]['hidden'] === true && $nodes[11]['parent_id'] === 10, 'Hidden categories and all their children must be exported');
check(array_column(array_intersect_key($nodes, array_flip([18, 20, 21, 22, 23, 24])), 'module_type') === [1, 0, 2, 4, 5, 6], 'Export real module types for logical system grouping');
check($nodes[11]['module_type'] === 3 && $nodes[19]['parent_id'] === 18, 'Keep devices and system-variable parents unchanged in native export');
echo "OK: full native object hierarchy, positions, hidden nodes and variable links\n";
+136
View File
@@ -0,0 +1,136 @@
<?php
declare(strict_types=1);
// Exercise the actual module against a volatile, in-memory hook registry. This intentionally
// models startup/reload losing registrations; it is not a test against a running Symcon kernel.
const KR_READY = 10103;
const KR_INIT = 10102;
const IPS_KERNELSTARTED = 10001;
const KL_ERROR = 10205;
$kernelRunlevel = KR_INIT;
$nativeHooks = [];
function IPS_GetKernelRunlevel(): int { global $kernelRunlevel; return $kernelRunlevel; }
function check(bool $condition, string $message): void { if (!$condition) throw new RuntimeException($message); }
class IPSModuleStrict
{
protected int $InstanceID;
public array $attributes = [];
public array $properties = [];
public array $messages = [];
public array $timers = [];
public array $logs = [];
public int $status = 101;
public ?bool $registrationResult = true;
public bool $registrationThrows = false;
public function __construct(int $id) { $this->InstanceID = $id; }
public function Create(): void {}
public function ApplyChanges(): void
{
global $nativeHooks;
$nativeHooks = array_filter($nativeHooks, fn(int $owner): bool => $owner !== $this->InstanceID);
}
public function MessageSink(int $time, int $sender, int $message, array $data): void {}
protected function RegisterPropertyString(string $name, string $value): void { $this->properties[$name] ??= $value; }
protected function RegisterAttributeString(string $name, string $value): void { $this->attributes[$name] ??= $value; }
protected function RegisterAttributeInteger(string $name, int $value): void { $this->attributes[$name] ??= $value; }
protected function ReadAttributeString(string $name): string { return $this->attributes[$name]; }
protected function WriteAttributeString(string $name, string $value): void { $this->attributes[$name] = $value; }
protected function ReadPropertyString(string $name): string { return $this->properties[$name]; }
protected function RegisterMessage(int $sender, int $message): void { $this->messages[] = [$sender, $message]; }
protected function RegisterTimer(string $name, int $interval, string $script): void { $this->timers[$name] = ['interval' => $interval, 'script' => $script]; }
protected function SetTimerInterval(string $name, int $interval): void
{
check(isset($this->timers[$name]), 'Timer must have been registered in Create');
$this->timers[$name]['interval'] = $interval;
}
protected function SetVisualizationType(int $type): void {}
protected function SetStatus(int $status): void { $this->status = $status; }
protected function LogMessage(string $message, int $type): void { $this->logs[] = [$message, $type]; }
protected function RegisterHook(string $path): ?bool
{
global $nativeHooks;
check(IPS_GetKernelRunlevel() === KR_READY, 'Do not depend on WebHook Control before the kernel is ready');
if ($this->registrationThrows) throw new RuntimeException('WebHook Control unavailable');
if ($this->registrationResult !== false) $nativeHooks['/hook/' . $path] = $this->InstanceID;
return $this->registrationResult;
}
}
require __DIR__ . '/../NextFloor/module.php';
$module = new NextFloor(12345);
$module->Create();
check($nativeHooks === [] && $module->status === 104, 'Startup must wait instead of reporting a nonexistent hook as ready');
check(in_array([0, IPS_KERNELSTARTED], $module->messages, true), 'Module must listen for the completed kernel startup');
check($module->timers['WebHookRetry']['interval'] === 5000, 'Startup recovery must be scheduled');
$kernelRunlevel = KR_READY;
$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');
$token = $module->attributes['AccessToken'];
$module->attributes['Building'] = '{"preserved_project":true}';
$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');
$module->ApplyChanges();
check(isset($nativeHooks[$hook]), 'ApplyChanges restores hooks after module reload');
$module->registrationResult = false;
$module->ApplyChanges();
check($module->status === 200 && !isset($nativeHooks[$hook]), 'A rejected registration must not report ready');
check($module->timers['WebHookRetry']['interval'] === 5000, 'Rejected registration must be retried');
$logCount = count($module->logs);
try {
$module->OpenDesigner();
throw new LogicException('Must not return a dead designer URL');
} catch (RuntimeException $error) {
check(str_contains($error->getMessage(), 'WebHook nicht verfügbar'), 'Designer must show a useful registration error');
}
check(count($module->logs) === $logCount, 'Identical retry errors must not flood the log');
check(!str_contains($module->GetVisualizationTile(), '<iframe'), 'Failure produces an explanatory tile, not a broken iframe');
$module->registrationResult = true;
$module->RetryWebHook();
check(isset($nativeHooks[$hook]) && $module->status === 102, 'Retry must recover after WebHook Control becomes available');
$module->registrationThrows = true;
check(str_contains($module->RepairWebHook(), 'WebHook Control unavailable'), 'Repair button reports the native registration exception');
$module->registrationThrows = false;
$module->registrationResult = null; // compatibility with older native return-void implementations
check(str_contains($module->RepairWebHook(), 'WebHook registriert:'), 'A native void return is not an explicit rejection');
check($module->attributes['AccessToken'] === $token && $module->attributes['Building'] === '{"preserved_project":true}', 'Repair must preserve project and access token');
$other = new NextFloor(54321);
$other->Create();
check(isset($nativeHooks[$hook]) && isset($nativeHooks['/hook/nextfloor/54321']), 'Instances must keep independent routes');
// 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);
$_SERVER['REQUEST_URI'] = $hook . '/designer';
$process = new ReflectionMethod($module, 'ProcessHookData');
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');
$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']);
$_SERVER['SCRIPT_NAME'] = $hook . '/designer';
ob_start();
$process->invoke($module);
$fallback = ob_get_clean();
check(str_contains($fallback, 'window.__NEXTFLOOR_SYMCON__='), 'Dispatcher must accept SCRIPT_NAME when REQUEST_URI is absent');
$_GET['token'] = 'wrong-token';
ob_start();
$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";