Files
LLeMbas-CLI/tests/approval.test.ts
T
HomerandClaude Opus 5.5 f20e8c4307 Context hygiene at insert time: result ids, read stubs, the cap, recall
Harness spec 3.0.0 (context.md, loop.json `context`), in session/results.ts,
applied by the engine when a result goes into the conversation and never
afterwards:

- every result is headed by its id ([#0001]); a read also by the path as
  given, its lines, the file's length and the first 8 hex digits of the
  content's SHA-256; an empty file says so;
- a read of an unchanged file whose lines lie inside an earlier full read is
  a stub naming it; a list/glob/grep repeated with the same arguments and the
  same result is "Same result as #…";
- output over 400 lines or 40,000 characters keeps head and tail with the
  elided line; the full result is kept with the session (a new `results`
  table in sessions.db, gone with the session);
- edit, multiedit, write and apply_patch answer with their hunks under a
  bracket with the new content's hash; a new file is "Created, N lines.";
- recall (new built-in tool) shows any stored result, or a range of it, also
  after a resume; ids are never reused;
- compaction appends the table of the reads still in the conversation to the
  summary.

A stub only ever points at a result still in the conversation, so after a
compaction, an /undo or a rewind the file is read in full. compaction.prune
is gone: cutting old outputs in place threw the prompt cache away (an old
config's key is dropped with a warning). blocks/context.md is in the prompt
wherever recall is offered. Conformance runner for the `context` area (11
cases pass).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 20:27:17 +00:00

50 lines
2.5 KiB
TypeScript

// A command corrected on its approval card (after LLeMbas): what the user wrote is judged again —
// the hardline and a written deny hold for it — and the model is told that the line it wrote is
// not the one that ran.
import { afterEach, expect, test } from "bun:test"
import { mkdirSync, mkdtempSync, writeFileSync } from "node:fs"
import { tmpdir } from "node:os"
import { join } from "node:path"
import { createApp } from "../src/app.ts"
import type { AskReply } from "../src/bus/index.ts"
import { paths } from "../src/config/paths.ts"
import { delta, fakeProvider, toolCall, type Fake } from "./fake-provider.ts"
let fake: Fake | undefined
afterEach(() => fake?.stop())
function app(edit: string, config = "") {
fake = fakeProvider([{ chunks: [toolCall(0, "b1", "bash", '{"command":"echo one"}')] }, { chunks: [delta({ content: "ok" }, "stop")] }])
mkdirSync(paths.config, { recursive: true })
writeFileSync(join(paths.config, "connections.yaml"), `connections:\n f:\n dialect: openai-chat\n base_url: ${fake.url}\n models: { m: {} }\n`, { mode: 0o600 })
writeFileSync(join(paths.config, "config.yaml"), `model: f/m\ntitles: prompt\n${config}`)
return createApp({ cwd: mkdtempSync(join(tmpdir(), "ph-approve-")), mode: "manual", store: false, snapshots: false, asker: { ask: async (): Promise<AskReply> => ({ kind: "once", command: edit }) } })
}
const result = () => fake!.requests[1].messages.at(-1).content as string
test("the edited command runs, and the result says so first", async () => {
const a = app("echo two")
await a.engine.prompt("go")
expect(result()).toStartWith("[#0001]\nThe user changed the command before allowing it. What ran: echo two")
expect(result()).toContain("two")
expect(result()).not.toContain("one\n")
})
test("an edit onto the hardline is refused, and nothing runs", async () => {
const a = app("rm -rf /")
await a.engine.prompt("go")
expect(result()).toContain("The user changed the command to `rm -rf /`, and that is refused")
})
test("an edit onto a written deny is refused, also behind a wrapper", async () => {
const a = app("sudo -u x git push origin main", 'permission:\n bash: { "git push *": deny }\n')
await a.engine.prompt("go")
expect(result()).toContain("and that is refused: denied by permission rules")
})
test("allowing the command as it was written is an ordinary allow", async () => {
const a = app("echo one")
await a.engine.prompt("go")
expect(result()).not.toContain("The user changed the command")
})