Privacy: pieces of other open files with a suggestion, and the names of other open files with a
message, now come only from files inside the working directory, never from a file that looks
like it holds secrets (one table, tests/rules/private_files.json, which the VS Code extension
reads too), and never from one the project's .gitignore leaves out. In a file that looks secret
no suggestion is asked for; said once. :help llembas-privacy says what is and is not sent.
- require("llembas").cli(): the one function that decides where the LLeMbas CLI is (PATH, then
~/.local/bin); LLeMbas IDE and its launcher follow it.
- A late answer from an agent that was replaced (:LLeMbasNew!, :LLeMbasRestart) no longer ends
the new turn.
- :LLeMbasOpen judges a file by its first bytes and its name (llembas.shown), as VS Code does.
- The existing sign-in is read by whole lines; an address that reads as an option is refused.
- A protocol line over the limit is dropped whole, not the message after it; a notification
that fails is noted in :LLeMbasLog.
- After :cd the remembered settings of the new directory hold.
- Versions: "1.2.3junk" is no version, as in VS Code.
- tests/rules/: versions, private files, server addresses, sign-in lines, protocol lines and
openable files, as data both editors' suites read (scripts/test-nvim.sh rules).
- The stand-in agent answers _lembas/session/delete as the CLI does ({deleted}, no notification
on serve --stdio).
- Texts: one sentence for "still working" and one for "this CLI is too old"; plain words in
:LLeMbasStatus and the length presets; the help card is "LLeMbas — commands and keys".
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
81 lines
3.6 KiB
Lua
81 lines
3.6 KiB
Lua
-- The rules both editors keep, against the cases in tests/rules/ (the VS Code extension reads the
|
|
-- same files in vscode/tests/rules.test.js). Run by scripts/test-nvim.sh:
|
|
-- nvim --headless -u NONE --cmd "set rtp+=nvim" -l nvim/tests/rules.lua
|
|
local here = vim.fn.fnamemodify(debug.getinfo(1, "S").source:sub(2), ":p:h")
|
|
local repo = vim.fs.normalize(here .. "/../..")
|
|
vim.opt.rtp:append(repo .. "/nvim")
|
|
|
|
local failed, ran = 0, 0
|
|
local function check(name, cond, extra)
|
|
ran = ran + 1
|
|
if cond then print("ok " .. name) else
|
|
failed = failed + 1
|
|
print("FAIL " .. name .. (extra and ("\n " .. tostring(extra)) or ""))
|
|
end
|
|
end
|
|
local function cases(name)
|
|
local f = assert(io.open(repo .. "/tests/rules/" .. name .. ".json", "rb"))
|
|
local text = f:read("*a")
|
|
f:close()
|
|
return vim.json.decode(text, { luanil = { object = true, array = true } })
|
|
end
|
|
local function unhex(s) return (s:gsub("%x%x", function(h) return string.char(tonumber(h, 16)) end)) end
|
|
|
|
local L = require("llembas")
|
|
local private = require("llembas.private")
|
|
local login = require("llembas.login")
|
|
local rpc = require("llembas.rpc")
|
|
local shown = require("llembas.shown")
|
|
|
|
-- versions
|
|
local versions = cases("versions")
|
|
for _, c in ipairs(versions.compare) do
|
|
check(("versions: %q against %q is %d"):format(c[1], c[2], c[3]), L.compare_versions(c[1], c[2]) == c[3], vim.inspect(L.compare_versions(c[1], c[2])))
|
|
check(("versions: and %q against %q is %d"):format(c[2], c[1], -c[3]), L.compare_versions(c[2], c[1]) == -c[3])
|
|
end
|
|
for _, v in ipairs(versions.not_versions) do
|
|
check(("versions: %q is no version"):format(v), L.compare_versions(v, "1.0.0") == nil and L.compare_versions("1.0.0", v) == nil)
|
|
end
|
|
|
|
-- files that are never sent along
|
|
local files = cases("private_files")
|
|
for _, p in ipairs(files.secret) do check("private: looks secret: " .. p, private.looks_secret(p) == true) end
|
|
for _, p in ipairs(files.plain) do check("private: does not look secret: " .. p, private.looks_secret(p) == false) end
|
|
for _, c in ipairs(files.inside) do
|
|
check(("private: %s inside %s: %s"):format(c[1], vim.inspect(c[2]), tostring(c[3])), private.inside(c[1], c[2]) == c[3])
|
|
end
|
|
|
|
-- the server's address
|
|
local addresses = cases("server_address")
|
|
for _, a in ipairs(addresses.ok) do check(("address: %q is taken"):format(a), login.address(a) == vim.trim(a)) end
|
|
for _, a in ipairs(addresses.refused) do check(("address: %q is refused"):format(a), login.address(a) == nil) end
|
|
|
|
-- the sign-in's events, in whatever pieces they arrive
|
|
for i, c in ipairs(cases("login_events")) do
|
|
local got = {}
|
|
local feed = login._reader(function(ev) got[#got + 1] = ev.event end)
|
|
for _, chunk in ipairs(c.chunks) do feed(chunk) end
|
|
check(("login: case %d reads %s"):format(i, vim.inspect(c.events)), vim.deep_equal(got, c.events), vim.inspect(got))
|
|
end
|
|
|
|
-- a line longer than the reader keeps
|
|
local lines = cases("rpc_lines")
|
|
for i, c in ipairs(lines.cases) do
|
|
local got = {}
|
|
local reader = setmetatable({ buf = "", err = "", max_line = lines.max, on = {} }, rpc)
|
|
reader._message = function(_, msg) got[#got + 1] = msg.method end
|
|
for _, chunk in ipairs(c.chunks) do reader:_feed(chunk) end
|
|
vim.wait(500, function() return #got >= #c.methods end, 5)
|
|
vim.wait(20)
|
|
check(("rpc: case %d keeps %s"):format(i, vim.inspect(c.methods)), vim.deep_equal(got, c.methods), vim.inspect(got))
|
|
end
|
|
|
|
-- what may be opened
|
|
for _, c in ipairs(cases("openable")) do
|
|
local kind = shown.openable(unhex(c.head), c.name)
|
|
check(("open: %s is %s"):format(c.name, tostring(c.kind)), kind == c.kind, tostring(kind))
|
|
end
|
|
|
|
print(("RAN %d, failed %d"):format(ran, failed))
|
|
vim.cmd(failed == 0 and "qall!" or "cquit!")
|