Something went wrong. Try again.
small gleam coding and persistent agent daemon with a detachable cli and a canvas ui forked from okami.mom/albedo
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950// Editing a waiting message: which answers mean it was already read, and when a hold is renewed.import assert from 'node:assert/strict';import { readFile } from 'node:fs/promises';import { stripTypeScriptTypes } from 'node:module';import test from 'node:test';
const source = await readFile( new URL('../src/lib/queueEdit.ts', import.meta.url), 'utf8',);const code = stripTypeScriptTypes(source, { mode: 'transform' });const moduleURL = `data:text/javascript;base64,${Buffer.from(code).toString('base64')}`;const { isNotWaiting, renewalDelay, waitingSend } = await import(moduleURL);
test('a refused hold, edit or cancel says the message was already read', () => { assert.equal(isNotWaiting({ code: 'input_not_waiting' }), true); assert.equal(isNotWaiting({ code: 'queue_item_not_found' }), true); assert.equal(isNotWaiting({ code: 'input_not_editable' }), false); assert.equal(isNotWaiting(new Error('network down')), false); assert.equal(isNotWaiting(null), false);});
test('a hold renews a third into its lease, and never more than once a second', () => { assert.equal(renewalDelay(30000), 10000); assert.equal(renewalDelay(2000), 1000); assert.equal(renewalDelay(0), 1000);});
test('only an accepted, unfinished message still in the queue is editable', () => { const queued = [{ id: 'a' }, { id: 'b' }]; assert.equal(waitingSend({ id: 'a', accepted: true }, queued), true); assert.equal(waitingSend({ id: 'a' }, queued), false, 'not accepted yet'); assert.equal( waitingSend({ id: 'a', accepted: true }, []), false, 'already read', ); assert.equal( waitingSend({ id: 'a', accepted: true, error: 'x' }, queued), false, 'failed send', ); assert.equal( waitingSend({ id: 'a', accepted: true, continuation: true }, queued), false, 'continuation', ); assert.equal(waitingSend(undefined, queued), false);});