mirror of
https://github.com/NousResearch/hermes-agent.git
synced 2026-10-20 05:15:31 +00:00
Fifth main.cjs cluster peel. The two hermes:logs:* handlers (reveal, recent) move
verbatim into electron/logs-ipc.cjs behind a registerLogsIpc({ ipcMain,
DESKTOP_LOG_PATH, hermesLog, fileExists }) registrar. The log path and the
in-memory ring buffer live in the main process and are injected.
Channel names unchanged → preload + renderer untouched. Adds
electron/logs-ipc.test.cjs (surface invariant + recent-tail behavior).
44 lines
1.3 KiB
JavaScript
44 lines
1.3 KiB
JavaScript
'use strict'
|
|
|
|
const assert = require('node:assert/strict')
|
|
const test = require('node:test')
|
|
|
|
const { registerLogsIpc } = require('./logs-ipc.cjs')
|
|
|
|
function fakeIpcMain() {
|
|
const handlers = new Map()
|
|
|
|
return {
|
|
handlers,
|
|
handle(channel, handler) {
|
|
assert.ok(!handlers.has(channel), `duplicate registration for ${channel}`)
|
|
handlers.set(channel, handler)
|
|
}
|
|
}
|
|
}
|
|
|
|
test('registerLogsIpc wires only hermes:logs:* channels, each to a handler fn', () => {
|
|
const ipcMain = fakeIpcMain()
|
|
|
|
registerLogsIpc({ ipcMain, DESKTOP_LOG_PATH: '/tmp/desktop.log', fileExists: () => true, hermesLog: [] })
|
|
|
|
assert.deepEqual([...ipcMain.handlers.keys()].sort(), ['hermes:logs:recent', 'hermes:logs:reveal'])
|
|
|
|
for (const handler of ipcMain.handlers.values()) {
|
|
assert.equal(typeof handler, 'function')
|
|
}
|
|
})
|
|
|
|
test('logs:recent returns the injected path and the last 200 buffered lines', async () => {
|
|
const ipcMain = fakeIpcMain()
|
|
const hermesLog = Array.from({ length: 250 }, (_, i) => `line ${i}`)
|
|
|
|
registerLogsIpc({ ipcMain, DESKTOP_LOG_PATH: '/tmp/desktop.log', fileExists: () => true, hermesLog })
|
|
|
|
const res = await ipcMain.handlers.get('hermes:logs:recent')({})
|
|
|
|
assert.equal(res.path, '/tmp/desktop.log')
|
|
assert.equal(res.lines.length, 200)
|
|
assert.equal(res.lines[0], 'line 50')
|
|
assert.equal(res.lines.at(-1), 'line 249')
|
|
})
|