Skip to content

The agent that grows with you

test: run the native HUD gesture C contract on the Linux JS lane

teknium136f165a1626b
diff --git a/apps/desktop/electron/hud-modifier-native.test.ts b/apps/desktop/electron/hud-modifier-native.test.ts
new file mode 100644
index 00000000000..1d2b1d92583
--- /dev/null
+++ b/apps/desktop/electron/hud-modifier-native.test.ts
@@ -0,0 +1,35 @@
+import assert from 'node:assert/strict'
+import { execFileSync } from 'node:child_process'
+import { mkdtempSync, rmSync } from 'node:fs'
+import { tmpdir } from 'node:os'
+import { resolve } from 'node:path'
+
+import { test } from 'vitest'
+
+// hud-modifier-gesture.h is the clean-tap state machine the macOS (.m) and
+// Linux XI2 (-x11.c) helpers both include. Compile its C contract and run it
+// wherever a C toolchain ships with the runner: Linux (the JS CI lane) and
+// macOS. Windows uses the separate C# port.
+test.skipIf(process.platform === 'win32')(
+ 'native modifier gesture state machine only summons on a clean, bounded two-modifier tap',
+ () => {
+ const dir = mkdtempSync(resolve(tmpdir(), 'hermes-hud-gesture-'))
+
+ try {
+ const binary = resolve(dir, 'gesture')
+ const source = resolve(import.meta.dirname, 'native', 'hud-modifier-gesture.test.c')
+ const flags = ['-std=c11', '-Wall', '-Wextra', '-Werror', source, '-o', binary]
+
+ if (process.platform === 'darwin') {
+ execFileSync('xcrun', ['--sdk', 'macosx', 'clang', ...flags])
+ } else {
+ execFileSync('cc', flags)
+ }
+
+ assert.match(execFileSync(binary, [], { encoding: 'utf8', timeout: 5_000 }), /assertions passed/)
+ } finally {
+ rmSync(dir, { force: true, recursive: true })
+ }
+ },
+ 30_000
+)
diff --git a/apps/desktop/electron/native/hud-modifier-gesture.test.c b/apps/desktop/electron/native/hud-modifier-gesture.test.c
new file mode 100644
index 00000000000..08e56068e09
--- /dev/null
+++ b/apps/desktop/electron/native/hud-modifier-gesture.test.c
@@ -0,0 +1,59 @@
+#include "hud-modifier-gesture.h"
+#include <assert.h>
+#include <stdio.h>
+
+int main(void) {
+ // Either press/release ordering is valid, but neither first release summons.
+ for (unsigned first = 1; first <= 2; first++) {
+ for (unsigned last = 1; last <= 2; last++) {
+ HudModifierGesture s = {0};
+ assert(!HudModifierUpdate(&s, first, false, false, 10));
+ assert(!HudModifierUpdate(&s, 3, false, false, 20));
+ assert(!HudModifierUpdate(&s, last, false, false, 30));
+ assert(HudModifierUpdate(&s, 0, false, false, 40));
+ assert(!HudModifierUpdate(&s, 0, false, false, 50));
+ }
+ }
+ // A foreign event at any phase permanently cancels this attempt, even if
+ // the foreign key/button is released before the target modifiers.
+ for (int phase = 0; phase < 3; phase++) {
+ HudModifierGesture s = {0};
+ HudModifierUpdate(&s, 1, false, phase == 0, 10);
+ HudModifierUpdate(&s, 3, false, phase == 1, 20);
+ HudModifierUpdate(&s, 2, false, phase == 2, 30);
+ assert(!HudModifierUpdate(&s, 0, false, false, 40));
+ HudModifierUpdate(&s, 1, false, false, 50);
+ HudModifierUpdate(&s, 3, false, false, 60);
+ HudModifierUpdate(&s, 2, false, false, 70);
+ assert(HudModifierUpdate(&s, 0, false, false, 80));
+ }
+ // Extra modifiers, held keys/buttons, and partial-release re-press cannot arm.
+ for (int kind = 0; kind < 3; kind++) {
+ HudModifierGesture s = {0};
+ HudModifierUpdate(&s, 1, kind == 1, false, 10);
+ HudModifierUpdate(&s, kind == 0 ? 7 : 3, kind == 1, false, 20);
+ if (kind == 0) HudModifierUpdate(&s, 3, false, false, 25);
+ HudModifierUpdate(&s, 2, false, false, 30);
+ if (kind == 2) {
+ HudModifierUpdate(&s, 3, false, false, 35);
+ HudModifierUpdate(&s, 2, false, false, 36);
+ }
+ assert(!HudModifierUpdate(&s, 0, false, false, 40));
+ }
+ for (unsigned initial = 1; initial <= 3; initial++) {
+ HudModifierGesture s = {0};
+ HudModifierUpdate(&s, initial, true, true, 0);
+ HudModifierUpdate(&s, 3, false, false, 10);
+ HudModifierUpdate(&s, 2, false, false, 20);
+ assert(!HudModifierUpdate(&s, 0, false, false, 30));
+ }
+ for (uint64_t duration = 500; duration <= 501; duration++) {
+ HudModifierGesture s = {0};
+ HudModifierUpdate(&s, 1, false, false, 10);
+ HudModifierUpdate(&s, 3, false, false, 20);
+ HudModifierUpdate(&s, 2, false, false, 30);
+ assert(HudModifierUpdate(&s, 0, false, false, 10 + duration) == (duration == 500));
+ }
+ puts("native modifier gesture assertions passed");
+ return 0;
+}