- Shown files: Open is offered only for kinds that are merely displayed (pictures and plain text in the editor; PDF, sound, video in the system's viewer), and only when the first bytes and the name agree. Everything else is shown in its folder. The deny-list is gone. - fs.writeTextFile is offered: the text is put into the open document with one edit and saved before the answer; a file that is not open is an error, so the agent writes the disk itself. - An agent stopped on purpose lets go of its session at once, not when its exit is heard (a request in between left a stale session id). - Markdown: one budget of steps per parse, a cap on line and text length, no quadratic pattern left in headings or backtick runs; a reply is read as it grows, settled text only once, and the page is told less often the longer the reply is. - A second rewrite of a file is refused while one is being written; a new proposal clears the old one's texts. - Shown files and their temporary copies go when the chat is cleared. - llembas.chat.startMode is machine-scoped. - A shown text that is no file here opens as a read-only document. - One "applying" mark per document instead of one for all. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
70 lines
3.1 KiB
JavaScript
70 lines
3.1 KiB
JavaScript
'use strict';
|
|
const test = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const { Agent } = require('../src/agent');
|
|
const { tempDir, fakeAgent, until } = require('./helpers');
|
|
|
|
test('the hello says what this client is: an editor that shows media and has unsaved text', async (t) => {
|
|
const agent = fakeAgent(t, tempDir(t));
|
|
await agent.connect();
|
|
const hello = agent.log().find((m) => m.method === 'initialize');
|
|
assert.equal(hello.params.protocolVersion, 1);
|
|
assert.deepEqual(hello.params.clientCapabilities._meta.lembas, { editor: true, media: true, show: true });
|
|
assert.deepEqual(hello.params.clientCapabilities.fs, { readTextFile: true, writeTextFile: false }, 'writing is offered only by a client that can do it');
|
|
assert.ok(agent.ready && agent.has('editor') && agent.has('media') && !agent.has('fs'));
|
|
});
|
|
|
|
test('a client that can put text into its documents says so', async (t) => {
|
|
const agent = fakeAgent(t, tempDir(t), {}, { writeTextFile: true });
|
|
await agent.connect();
|
|
assert.deepEqual(agent.log().find((m) => m.method === 'initialize').params.clientCapabilities.fs, { readTextFile: true, writeTextFile: true });
|
|
});
|
|
|
|
test('every caller of connect gets the same start', async (t) => {
|
|
const agent = fakeAgent(t, tempDir(t));
|
|
const [a, b] = await Promise.all([agent.connect(), agent.connect()]);
|
|
assert.equal(a, b);
|
|
assert.equal(agent.log().filter((m) => m.method === 'initialize').length, 1);
|
|
});
|
|
|
|
test('an agent from before the editor methods has no capabilities', async (t) => {
|
|
const agent = fakeAgent(t, tempDir(t), { FAKE_AGENT_PLAIN: '1' });
|
|
await agent.connect();
|
|
assert.ok(!agent.has('editor'));
|
|
await assert.rejects(agent.request('_lembas/models', {}), (e) => e.code === -32601);
|
|
});
|
|
|
|
test('a command that does not exist is said in words, once', async (t) => {
|
|
const agent = new Agent({ command: 'lembas-that-is-not-installed', cwd: tempDir(t) });
|
|
const exits = [];
|
|
agent.on('exit', (e) => exits.push(e));
|
|
await assert.rejects(agent.connect(), /could not start lembas-that-is-not-installed: the command was not found/);
|
|
await assert.rejects(agent.request('x', {}), /not running/);
|
|
assert.equal(exits.length, 1);
|
|
assert.equal(exits[0].started, false);
|
|
});
|
|
|
|
test('an agent that exits fails what was asked and says its last words', async (t) => {
|
|
const agent = fakeAgent(t, tempDir(t));
|
|
await agent.connect();
|
|
const exits = [];
|
|
agent.on('exit', (e) => exits.push(e));
|
|
const r = await agent.request('session/new', { cwd: '/', mcpServers: [] });
|
|
const turn = agent.request('session/prompt', { sessionId: r.sessionId, prompt: [{ type: 'text', text: 'CRASH' }] });
|
|
await assert.rejects(turn, /the agent stopped \(exit 3\): not signed in: run lembas login/);
|
|
await until(() => exits.length === 1);
|
|
assert.equal(exits[0].code, 3);
|
|
assert.equal(exits[0].started, true);
|
|
assert.match(exits[0].last, /not signed in/);
|
|
});
|
|
|
|
test('stop ends the process', async (t) => {
|
|
const agent = fakeAgent(t, tempDir(t));
|
|
await agent.connect();
|
|
let gone = false;
|
|
agent.on('exit', () => (gone = true));
|
|
agent.stop();
|
|
await until(() => gone);
|
|
await assert.rejects(agent.request('x', {}), /not running/);
|
|
});
|