first draft of log explorer

This commit is contained in:
Pierre committed 2026-09-27 14:15:15 +02:00
1 parent 191e69eb1d
commit 400837b41a
16 files changed
+1495 -79

No files matched your search

+29
View File
@@ -0,0 +1,29 @@
const { test } = require('node:test');
const assert = require('node:assert/strict');
const { parseLine, rawTime } = require('../out/logModel');
test('raw log levels, app names and readable IDs', () => {
const e = parseLine('27-09-26 10:12:13 WARNING my_app: Alerte : détail [event=e1 trace=t1]', '/logs/main.log', 123);
assert.equal(e.event_id, 'e1'); assert.equal(e.app, 'my_app'); assert.equal(e.level, 'WARNING'); assert.equal(e.trace_id, 't1');
});
test('timestamps use the AppDaemon timezone instead of the workstation timezone', () => {
assert.equal(rawTime('27-09-26 10:12:13', 'Europe/Berlin'), Date.parse('2026-09-27T08:12:13Z'));
assert.equal(rawTime('27-01-26 10:12:13', 'Europe/Berlin'), Date.parse('2026-01-27T09:12:13Z'));
});
test('structured events retain causal links and evaluation values', () => {
const entry = {version:1,event_id:'e2',cause_ids:['e1'],probable_cause_ids:['e1'],message:'Condition',app:'app',kind:'evaluation',timestamp:'2026-09-27T08:12:13Z',values:{'sensor.a':true}};
assert.deepEqual(parseLine(JSON.stringify(entry), '/logs/events.jsonl', 0).values, entry.values);
});
test('invalid structured records and continuations are rejected', () => {
for (const value of ['{broken}', JSON.stringify({version:1,event_id:'e',cause_ids:[null],message:'bad',app:'app',timestamp:'now'}), ' File "app.py", line 3']) assert.equal(parseLine(value,'/logs/log',0),undefined);
});
test('decodes UTF-8, Windows-1252 and mixed historical log bytes', () => {
const { decodeLogLine } = require('../out/logModel');
assert.equal(decodeLogLine(Buffer.from('Échec – déjà 🔥')), 'Échec – déjà 🔥');
assert.equal(decodeLogLine(Buffer.from([0xc9,0x63,0x68,0x65,0x63,0x20,0x96,0x20,0xe9])), 'Échec – é');
assert.equal(decodeLogLine(Buffer.concat([Buffer.from('déjà → '),Buffer.from([0xe9])])), 'déjà → é');
assert.equal(decodeLogLine(Buffer.from([0xe9]), 'utf8'), '\ufffd');
});
test('raw initialization IDs are retained without structured events', () => {
const e=parseLine('27-09-26 10:12:13 INFO app: Setting up [event=e1 trace=t1] [init=init1]','log',0);
assert.equal(e.initialization_id,'init1'); assert.equal(e.phase,'initialization');
});