Files
hermes-agent/apps/desktop/electron/linux-launcher-ready.test.ts
teknium1 5d2acf7066 test(desktop): pin deferred launcher-entry writes and the terminal-launch control
- cmd_gui with DESKTOP_STARTUP_ID: the entry is installed only after the fake Electron
  writes the reveal byte to HERMES_DESKTOP_READY_FD (spawn precedes install).
- cmd_gui without DESKTOP_STARTUP_ID (control): install still precedes the spawn.
- DeferredDesktopEntryInstall.finish(): an app that exits without revealing heals
  exactly once, after the exit.
- linux-launcher-ready: one byte, fd closed, variable consumed; garbage/absent = no-op.

Docs: user-guide/desktop.md explains when the entry write happens for grid launches.
2026-09-15 18:29:37 -07:00

49 lines
1.4 KiB
TypeScript

import assert from 'node:assert/strict'
import { test } from 'vitest'
import { LAUNCHER_READY_FD_ENV, notifyLauncherWindowRevealed } from './linux-launcher-ready'
function createIo() {
const writes: Array<[number, string]> = []
const closes: number[] = []
return {
closes,
io: {
closeSync: (fd: number) => {
closes.push(fd)
},
writeSync: (fd: number, data: string) => {
writes.push([fd, data])
return data.length
}
},
writes
}
}
test('writes one byte to the launcher fd, closes it and consumes the variable', () => {
const env: NodeJS.ProcessEnv = { [LAUNCHER_READY_FD_ENV]: '7' }
const { closes, io, writes } = createIo()
assert.equal(notifyLauncherWindowRevealed(env, io), true)
assert.deepEqual(writes, [[7, 'r']])
assert.deepEqual(closes, [7])
assert.equal(LAUNCHER_READY_FD_ENV in env, false)
// A second reveal must not touch fd 7 again: the number may now belong to another file.
assert.equal(notifyLauncherWindowRevealed(env, io), false)
assert.equal(writes.length, 1)
})
test('a launch without the variable, or with a garbage value, is a no-op', () => {
const { io, writes } = createIo()
assert.equal(notifyLauncherWindowRevealed({}, io), false)
assert.equal(notifyLauncherWindowRevealed({ [LAUNCHER_READY_FD_ENV]: 'seven' }, io), false)
assert.equal(notifyLauncherWindowRevealed({ [LAUNCHER_READY_FD_ENV]: '-1' }, io), false)
assert.deepEqual(writes, [])
})