Files
LLeMbas-IDE/vscode/tests/agent.test.js
T
HomerandClaude Fable 5.2 3d548bbd73 VS Code / VSCodium: the extension's first version
A client of `lembas serve --stdio`, in vscode/: plain JavaScript, no
dependencies, no build. scripts/package-vscode.sh writes the .vsix with
Node alone; the version comes from VERSION.

- Chat in a side bar view: transcript, mode, the session's model, Stop,
  new session. Approval cards are answered there; one that carries ACP
  diff content opens the editor's diff view before the answer.
- Ask about a selection, with the editor context as _meta.lembas.editor.
- Rewrite a selection through _lembas/edit: proposed changes with
  Accept / Reject per change and for all, and a diff beside the file.
  Nothing is written before it is accepted.
- Autocomplete as an inline completion provider on _lembas/complete:
  debounced, the request before cancelled by its own id, a cancelled or
  stale answer shown as nothing. No model chosen: said once, with a
  button that opens the picker.
- The two model settings through _lembas/editor/settings, and a quick
  switch for the window that is saved nowhere.
- Files the agent shows (_lembas/show, _lembas/show/read): pictures in
  the chat, anything else a line with Open, under a size limit.
- fs/read_text_file answered from the open document.

Model output is untrusted: the extension's own Markdown reader makes a
tree of plain objects and the page builds elements and text from it,
under a Content-Security-Policy with one nonce'd script.

Tests (scripts/test-vscode.sh, node --test): the modules in src/ against
a stand-in agent, the package's structure, and extension.js against an
in-memory stand-in for the editor's API. Nothing was run inside VS Code.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-24 11:42:58 +00:00

64 lines
2.8 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 });
assert.ok(agent.ready && agent.has('editor') && agent.has('media') && !agent.has('fs'));
});
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/);
});