Files
MATTERMOST_OPENCLAW_LIVESTATUS/test/integration/poll-fallback.test.js
sol 868574d939 fix: remove dead delete+recreate and pin code, add poll fallback test
Phase 1 cleanup:
- Remove deletePost() method (dead code, replaced by PUT in-place updates)
- Remove _postInfo Map tracking (no longer needed)
- Remove pin/unpin API calls from watcher-manager.js (incompatible with PUT updates)
- Add JSDoc note on (edited) label limitation in _flushUpdate()
- Add integration test: test/integration/poll-fallback.test.js
- Fix addSession() lastOffset===0 falsy bug (0 was treated as 'no offset')
- Fix pre-existing test failures: add lastOffset:0 where tests expect backlog reads
- Fix pre-existing session-monitor test: create stub transcript files
- Fix pre-existing status-formatter test: update indent check for blockquote format
- Format plugin/ files with Prettier (pre-existing formatting drift)
2026-03-07 20:31:32 +00:00

78 lines
2.2 KiB
JavaScript

'use strict';
/**
* Integration test: poll-fallback
*
* Verifies that StatusWatcher detects file changes via the polling fallback
* (not just fs.watch). Creates a temp JSONL file, initializes a StatusWatcher,
* appends a line, and asserts the 'session-update' event fires within 1000ms.
*/
var describe = require('node:test').describe;
var it = require('node:test').it;
var beforeEach = require('node:test').beforeEach;
var afterEach = require('node:test').afterEach;
var assert = require('node:assert/strict');
var fs = require('fs');
var path = require('path');
var os = require('os');
var StatusWatcher = require('../../src/status-watcher').StatusWatcher;
function createTmpDir() {
return fs.mkdtempSync(path.join(os.tmpdir(), 'poll-fallback-test-'));
}
describe('StatusWatcher poll fallback', function () {
var tmpDir;
var watcher;
beforeEach(function () {
tmpDir = createTmpDir();
});
afterEach(function () {
if (watcher) {
watcher.stop();
watcher = null;
}
try {
fs.rmSync(tmpDir, { recursive: true, force: true });
} catch (_e) {
/* ignore */
}
});
it('emits session-update within 1000ms when a line is appended to the JSONL file', function (t, done) {
var transcriptFile = path.join(tmpDir, 'test-session.jsonl');
fs.writeFileSync(transcriptFile, '');
watcher = new StatusWatcher({ transcriptDir: tmpDir, idleTimeoutS: 600 });
// Use a saved offset of 0 so we read from beginning
watcher.addSession('test:poll', transcriptFile, { lastOffset: 0 });
var timer = setTimeout(function () {
done(new Error('session-update event not received within 1000ms'));
}, 1000);
watcher.once('session-update', function (sessionKey) {
clearTimeout(timer);
assert.equal(sessionKey, 'test:poll');
done();
});
// Append a valid JSONL line after a short delay to allow watcher setup
setTimeout(function () {
var record = {
type: 'message',
message: {
role: 'assistant',
content: [{ type: 'text', text: 'Poll fallback test line' }],
},
};
fs.appendFileSync(transcriptFile, JSON.stringify(record) + '\n');
}, 100);
});
});