Skip to content

Commit 30f0a45

Browse files
committed
try again...
1 parent ba22d5f commit 30f0a45

9 files changed

Lines changed: 1405 additions & 110 deletions

File tree

.claude/settings.local.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"Bash(cat:*)",
99
"Bash(git log:*)",
1010
"Bash(find:*)",
11-
"Skill(implement-test-handler)"
11+
"Skill(implement-test-handler)",
12+
"Bash(grep:*)"
1213
],
1314
"deny": [],
1415
"ask": []

CTT-Remote.md

Lines changed: 368 additions & 0 deletions
Large diffs are not rendered by default.

ctt/project/Config/Saved Items/002_E6D68AF7.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
<NetworkKey Class="0" Value="CE07372267DCB354DB216761B6E9C378" />
66
<NetworkKey Class="1" Value="30B5CCF3F482A92E2F63A5C5E218149A" />
77
<NetworkKey Class="2" Value="21A29A69145E38C1601DFF55E2658521" />
8-
<NetworkKey Class="3" Value="3D54A7E5DE9D444B28B479CF13B4CA70" />
9-
<NetworkKey Class="4" Value="C2B0A8CE070B71F409A889BCCC54A49B" />
8+
<NetworkKey Class="3" Value="0F4F7E178A4207A0BBEFBF991C66F814" />
9+
<NetworkKey Class="4" Value="72D42391F7ECE63BE1B38B25D085ECD4" />
1010
</SecuritySettings>
1111
<Node Id="1" NodeInfo="D39603020100" RoleType="0" NodeType="255" CommandClasses="5E989F556C568F74">
1212
<SecurityExtension Keys="0x87" CommandClasses="85595A7A87728E7386" />

ctt/project/Root Device/Root Device.cttproj

Lines changed: 963 additions & 88 deletions
Large diffs are not rendered by default.

dut/zwave-js/run.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -470,21 +470,31 @@ async function main(): Promise<void> {
470470
process.exit(1);
471471
});
472472

473-
// Handle shutdown signals
474-
process.on("SIGINT", async () => {
475-
console.log("Received SIGINT, shutting down...");
473+
async function shutdown(code: number): Promise<never> {
476474
if (server) await server.destroy().catch(() => {});
477475
if (driver) await driver.destroy().catch(() => {});
478476
ws?.close();
479-
process.exit(0);
477+
process.exit(code);
478+
}
479+
480+
process.on("SIGINT", () => {
481+
console.log("Received SIGINT, shutting down...");
482+
shutdown(0);
480483
});
481484

482-
process.on("SIGTERM", async () => {
485+
process.on("SIGTERM", () => {
483486
console.log("Received SIGTERM, shutting down...");
484-
if (server) await server.destroy().catch(() => {});
485-
if (driver) await driver.destroy().catch(() => {});
486-
ws?.close();
487-
process.exit(0);
487+
shutdown(0);
488+
});
489+
490+
process.on("uncaughtException", (error) => {
491+
console.error("Uncaught exception in runner:", error);
492+
shutdown(1);
493+
});
494+
495+
process.on("unhandledRejection", (reason) => {
496+
console.error("Unhandled rejection in runner:", reason);
497+
shutdown(1);
488498
});
489499
}
490500

interactive-tests.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
PI_CertificationData_Rev01
2+
3+
# TODO:
4+
## Wrong data reported by zwave-js:
5+
* DD_ManufacturerSpecificCCData_Rev01
6+
* DD_VersionCCData_Rev01
7+
8+
## Bug in Z-Wave JS:
9+
* CCR_UserCodeCC_Rev04
10+
11+
## Requires Wiki/Web browser access - filter out
12+
* CCT_CRC16EncapsulationCmdClassV1_Rev02
13+
* PI_CertificationData_Rev01

src/runner-host.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,15 @@ export interface RunnerHostOptions {
3333
ipcPort?: number;
3434
/** Timeout for runner to connect and send ready (ms, default: 30000) */
3535
readyTimeout?: number;
36+
/** Callback when runner process exits unexpectedly */
37+
onUnexpectedExit?: () => void;
3638
}
3739

3840
export class RunnerHost {
3941
private runnerPath: string;
4042
private ipcPort: number;
4143
private readyTimeout: number;
44+
private onUnexpectedExit?: () => void;
4245

4346
private wss?: WebSocketServer;
4447
private runnerProcess?: ChildProcess;
@@ -65,6 +68,7 @@ export class RunnerHost {
6568
this.runnerPath = path.resolve(options.runnerPath);
6669
this.ipcPort = options.ipcPort ?? DEFAULT_IPC_PORT;
6770
this.readyTimeout = options.readyTimeout ?? 30000;
71+
this.onUnexpectedExit = options.onUnexpectedExit;
6872

6973
// Create readline interface for user prompts
7074
this.rl = readline.createInterface({
@@ -316,10 +320,13 @@ export class RunnerHost {
316320

317321
this.runnerProcess.on("exit", (code, signal) => {
318322
if (code !== null) {
319-
console.log(c.dim(`Runner exited with code ${code}`));
323+
console.error(`Runner exited with code ${code}`);
320324
} else if (signal) {
321325
console.log(c.dim(`Runner killed by signal ${signal}`));
322326
}
327+
if (this.onUnexpectedExit) {
328+
this.onUnexpectedExit();
329+
}
323330
});
324331
}
325332

src/start.ts

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import * as fs from "fs";
44
import { fileURLToPath } from "url";
55
import { createWebSocketServer } from "./ws-server.ts";
66
import type { ManagedWebSocketServer } from "./ws-server.ts";
7-
import { runTestCases, closeCTT, getTestCases } from "./ctt-client.ts";
7+
import { runTestCases, closeCTT, getTestCases, cancelTestRun } from "./ctt-client.ts";
88
import { RunnerHost } from "./runner-host.ts";
99
import { CTTDeviceProxy, type FrameHandler } from "./ctt-device-proxy.ts";
1010
import c from "ansi-colors";
@@ -96,6 +96,7 @@ class ProcessManager {
9696
private wsServer?: ManagedWebSocketServer;
9797
private runnerHost?: RunnerHost;
9898
private deviceProxy?: CTTDeviceProxy;
99+
private isCleaningUp = false;
99100

100101
/**
101102
* Load PID file data if it exists
@@ -242,7 +243,8 @@ class ProcessManager {
242243
});
243244

244245
proc.on("exit", (code) => {
245-
console.log(`Z-Wave stack WSL process exited with code ${code}`);
246+
console.error(`Z-Wave stack WSL process exited with code ${code}, aborting...`);
247+
this.cleanup();
246248
});
247249

248250
this.processes.push({
@@ -359,6 +361,7 @@ class ProcessManager {
359361

360362
this.runnerHost = new RunnerHost({
361363
runnerPath: DUT_PATH,
364+
onUnexpectedExit: () => this.cleanup(),
362365
});
363366

364367
// Initialize the runner (spawns process, waits for ready)
@@ -415,7 +418,8 @@ class ProcessManager {
415418
});
416419

417420
cttProcess.on("exit", (code) => {
418-
console.log(`CTT-Remote exited with code ${code}`);
421+
console.error(`CTT-Remote exited with code ${code}, aborting...`);
422+
this.cleanup();
419423
});
420424

421425
const managedProcess: ManagedProcess = {
@@ -670,8 +674,30 @@ class ProcessManager {
670674
}
671675

672676
async cleanup(): Promise<void> {
677+
if (this.isCleaningUp) return;
678+
this.isCleaningUp = true;
679+
673680
console.log("Shutting down...");
674681

682+
// Cancel any running test and close CTT gracefully first
683+
try {
684+
await cancelTestRun();
685+
// Wait for test to actually stop before trying to close
686+
await setTimeout(2000);
687+
} catch {
688+
// Ignore - test may not be running
689+
}
690+
try {
691+
await closeCTT();
692+
} catch {
693+
// Ignore - CTT may already be closed
694+
}
695+
696+
// Close WebSocket server to stop incoming CTT messages
697+
if (this.wsServer) {
698+
await this.wsServer.close();
699+
}
700+
675701
// Stop DUT runner
676702
await this.stopRunner();
677703

@@ -692,11 +718,6 @@ class ProcessManager {
692718
// Ignore
693719
}
694720

695-
// Close WebSocket server
696-
if (this.wsServer) {
697-
await this.wsServer.close();
698-
}
699-
700721
// Clean up PID file on successful shutdown
701722
this.deletePidFile();
702723

zwave_stack/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ echo "Starting Z-Wave Stack..."
88
run_with_prefix() {
99
local prefix="$1"
1010
shift
11-
"$@" 2>&1 | while IFS= read -r line; do echo "[$prefix] $line"; done
11+
stdbuf -oL -eL "$@" 2>&1 | sed -u "s/^/[$prefix] /"
1212
}
1313

1414
# Start 3 controllers

0 commit comments

Comments
 (0)