LLeMbas CLI 2.0 is LLeMbas-server-specific (CLI rule 2). Removed: the anthropic, gemini, ollama and responses clients, context discovery and llama-swap unloading (discover.ts), the Connection schema with its dialect, auth, key_cmd, discover, unload_url and one_model_at_a_time, the model `fallback` (it only ever moved to another server), effort_map and cache, and the multi-connection refs. Kept: openai-chat, http, sse, think, effort, tokens and all of src/lembas. - connections.yaml holds the login (`type: webui`, as lembas login writes it). A custom entry from 1.x is read past with a warning that says how to log in, so an old file still starts; with several logins left, the latest is used and the others named. - A model's ref is the id the server serves it under; the older forms (`<login>/<id>`, `<login>/<model>`) still resolve and config.yaml is rewritten once. Without a login there is no model, and the error (and the first-run screen, now the sign-in alone) says `lembas login <address>`. - A login to another server signs this machine out of the previous one. - The window is the server's word (no discovery); a capacity group comes from the server's `capacity.group` alone; embeddings use the server's /v1/embeddings. - `lembas models` lists the server's models; install.sh's starter files, the README and the JSON schemas say the same. Tests: every fixture is a login now (the fake server lists models, answers other GETs with 404, and can hand one model to another script, as a server with several backends); the dialect suites and the cross-connection tests are gone with their code. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
96 lines
3.8 KiB
TypeScript
96 lines
3.8 KiB
TypeScript
import { afterEach, expect, test } from "bun:test"
|
||
import { existsSync, mkdirSync, mkdtempSync, readFileSync, writeFileSync } from "node:fs"
|
||
import { tmpdir } from "node:os"
|
||
import { join } from "node:path"
|
||
import { testRender } from "@opentui/solid"
|
||
import { paths } from "../../src/config/paths.ts"
|
||
import { trustOf } from "../../src/project/root.ts"
|
||
import { Boot } from "../../src/tui/index.tsx"
|
||
import { fakeProvider } from "../fake-provider.ts"
|
||
|
||
let setup: Awaited<ReturnType<typeof testRender>> | undefined
|
||
afterEach(() => setup?.renderer.destroy())
|
||
|
||
async function boot(cwd: string) {
|
||
const fake = fakeProvider([])
|
||
mkdirSync(paths.config, { recursive: true })
|
||
writeFileSync(join(paths.config, "connections.yaml"), `connections:\n fake:\n type: webui\n url: ${fake.url}\n models: { fake/m: {} }\n`, { mode: 0o600 })
|
||
writeFileSync(join(paths.config, "config.yaml"), "model: fake/m\n")
|
||
let quit = 0
|
||
setup = await testRender(() => <Boot options={{ cwd, store: false }} onQuit={() => quit++} />, { width: 100, height: 30 })
|
||
const frame = async () => {
|
||
for (let i = 0; i < 3; i++) {
|
||
await Bun.sleep(20)
|
||
await setup!.renderOnce()
|
||
}
|
||
return setup!.captureCharFrame()
|
||
}
|
||
return { frame, quits: () => quit, fake }
|
||
}
|
||
|
||
test("first run: trust → git init → .agent/ created, .gitignore updated, session opens", async () => {
|
||
const cwd = mkdtempSync(join(tmpdir(), "ph-first-"))
|
||
const b = await boot(cwd)
|
||
expect(await b.frame()).toContain("Trust this directory?")
|
||
setup!.mockInput.pressEnter()
|
||
expect(await b.frame()).toContain("No git repository here. Create one?")
|
||
setup!.mockInput.pressEnter()
|
||
const f = await b.frame()
|
||
expect(f).toContain("trusted this directory")
|
||
expect(f).toContain("initialised an empty git repository")
|
||
expect(f).toContain("created .agent/")
|
||
expect(trustOf(cwd)).toBe("trusted")
|
||
expect(existsSync(join(cwd, ".git"))).toBe(true)
|
||
expect(existsSync(join(cwd, ".agent", "config.yaml"))).toBe(true)
|
||
expect(readFileSync(join(cwd, ".gitignore"), "utf8")).toContain("/.agent/local/")
|
||
b.fake.stop()
|
||
})
|
||
|
||
test("first run: read-only skips the project dir; a file named .agent sends it to .lembas", async () => {
|
||
const cwd = mkdtempSync(join(tmpdir(), "ph-first-"))
|
||
Bun.spawnSync(["git", "init", "-q", cwd])
|
||
writeFileSync(join(cwd, ".agent"), "someone else's file")
|
||
const b = await boot(cwd)
|
||
expect(await b.frame()).toContain("Trust this directory?")
|
||
setup!.mockInput.pressArrow("down")
|
||
setup!.mockInput.pressEnter()
|
||
const f = await b.frame()
|
||
expect(f).toContain("opened read-only")
|
||
expect(f).toContain(" plan · fake/m")
|
||
expect(existsSync(join(cwd, ".lembas"))).toBe(false)
|
||
b.fake.stop()
|
||
|
||
const cwd2 = mkdtempSync(join(tmpdir(), "ph-first-"))
|
||
Bun.spawnSync(["git", "init", "-q", cwd2])
|
||
writeFileSync(join(cwd2, ".agent"), "someone else's file")
|
||
setup!.renderer.destroy()
|
||
const b2 = await boot(cwd2)
|
||
await b2.frame()
|
||
setup!.mockInput.pressEnter()
|
||
expect(await b2.frame()).toContain("created .lembas/")
|
||
expect(existsSync(join(cwd2, ".lembas", "config.yaml"))).toBe(true)
|
||
expect(readFileSync(join(cwd2, ".agent"), "utf8")).toContain("someone else's")
|
||
b2.fake.stop()
|
||
})
|
||
|
||
test("a known directory skips the questions", async () => {
|
||
const cwd = mkdtempSync(join(tmpdir(), "ph-first-"))
|
||
const { setTrust } = await import("../../src/project/root.ts")
|
||
setTrust(cwd, "trusted")
|
||
const b = await boot(cwd)
|
||
expect(await b.frame()).toContain("❯")
|
||
b.fake.stop()
|
||
})
|
||
|
||
test("first run: ctrl+c leaves, and nothing is written", async () => {
|
||
const cwd = mkdtempSync(join(tmpdir(), "ph-first-"))
|
||
const b = await boot(cwd)
|
||
expect(await b.frame()).toContain("Trust this directory?")
|
||
setup!.mockInput.pressCtrlC()
|
||
await b.frame()
|
||
expect(b.quits()).toBe(1)
|
||
expect(trustOf(cwd)).toBeUndefined()
|
||
expect(existsSync(join(cwd, ".agent"))).toBe(false)
|
||
b.fake.stop()
|
||
})
|