mirror of
https://github.com/mudler/LocalAI.git
synced 2026-08-03 12:00:43 -04:00
* chore(deps): bump cogito to v0.11 ahead of the nib harness nib is the agent harness that becomes 'local-ai chat'. It requires cogito v0.11, so pull that bump forward on its own: minimal version selection would apply it to LocalAI anyway, and both repos use cogito and cogito/clients. Landing it separately keeps the harness change reviewable. nib itself is not pinned yet. Nothing in LocalAI imports it, and 'go mod tidy' runs as a goreleaser before-hook in CI, so an unimported require line does not survive. It lands with its first importer. No LocalAI call site needed a change. Both cogito.WithMaxAttempts callers guard the argument above zero, so v0.11's new clamp is unreachable, and LocalAI's Multimedia values implement only URL(), so v0.11's new TypedMultimedia routing treats them as images exactly as v0.10 did. Binary size (cmd/local-ai): 200,301,381 -> 200,336,045 bytes (+34,664). A throwaway probe that links nib measured 201,042,243 bytes (+740,862 over the pre-change baseline). Assisted-by: Claude Code:claude-opus-5 [Bash] [Edit] [Write] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(chat): resolve and seed the agent state directory Assisted-by: Claude Code:claude-opus-5 [Bash] [Edit] [Write] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix(chat): write the agent config atomically and tighten its modes Replacing config.yaml in place truncated it first, so an interrupted write would have destroyed the api_key nib keeps in the same file. Stage through a sibling temp file and rename over the target instead, and match nib's 0700 directory mode. Assisted-by: Claude Code:claude-opus-5 [Bash] [Edit] [Write] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(chat): probe the endpoint and classify failures Probe lists what a LocalAI endpoint advertises and separates the two failures that need different advice: nothing listening, and rejected credentials. go-openai reports a rejected key as one of two concrete types depending on the error body, and both occur against a real LocalAI. The normal error handler sends an OpenAI error envelope, which arrives as *openai.APIError; the opaque-errors handler replies with a bare status and no body, which arrives as *openai.RequestError. Classifying on only one of them misses half the cases, so the status is read from either. A cancelled probe is not reported as an unreachable server, because it learned nothing about the endpoint, and neither is a reply that could not be parsed, because something did answer. Both would otherwise send the user off to start a server that may already be running. The model list is returned verbatim and in server order. LocalAI lists whatever it finds in the models directory, including stray archives and dotfiles, and deciding which advertised ids are real belongs to whoever presents them. Assisted-by: Claude Code:claude-opus-5 [Bash] [Edit] [Write] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(chat): resolve the model from flag, config, or the server Assisted-by: Claude Code:claude-opus-5 [Bash] [Edit] [Write] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * test(chat): pin that model resolution sorts a copy of the caller's slice The sort spec asserted only on what the chooser was offered, so replacing the defensive copy with an in-place sort of req.Available still passed all 37 specs. Assert the input slice's order after the call, so the guarantee cannot be dropped silently by a later refactor. Assisted-by: Claude Code:claude-opus-5 [Bash] [Edit] [Write] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(chat): offer to start a server when none is reachable Assisted-by: Claude Code:claude-opus-5 [Bash] [Edit] [Write] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix(chat): bound the server wait and pin readiness and stop semantics Set cmd.WaitDelay so a backend subprocess holding the child's stderr pipe cannot block cmd.Wait forever, which would leave exited unclosed, burn the whole shutdown grace on a clean exit, and leak the waiter goroutine. Two test gaps closed alongside it: the readiness spec now counts polls, so treating 503 as ready is observable, and Stop's single-interrupt contract is pinned by giving StartedServer interrupt/kill hooks that a spec can count. Assisted-by: Claude Code:claude-opus-5 [Bash] [Edit] [Write] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * refactor(chat): drive Stop through one process interface, hide exec plumbing Two independent interrupt/kill func fields plus a nil check admitted wirings no test could distinguish: the pair swapped, so a SIGKILL would strand the backends SIGINT exists to let local-ai run clean up, or kill left nil, so a wedged server never escalates. One two-method interface that *os.Process already satisfies leaves nothing to swap and nothing to nil. Also translate exec.ErrWaitDelay, whose text names an os/exec struct field, into what the user can act on. os/exec only substitutes that sentinel when the process exited without an error of its own, so no exit status is swallowed. Assisted-by: Claude Code:claude-opus-5 [Bash] [Edit] [Write] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * feat(chat): replace the REPL with the built-in agent local-ai chat is now the nib agent harness compiled into the binary: tool use behind an approval gate, sub-agents, MCP, plugins, and skills, all auto-configured against the local server. The REPL goes with it. Its model listing and its 401 classifier were duplicates of the ones Probe now owns, and the classifier was the version that misreads a bare 401 with no OpenAI error envelope, so keeping either would leave the package with two divergent answers to the same question. github.com/mudler/nib lands in go.mod in this commit rather than earlier: go mod tidy runs as a goreleaser before-hook on every PR, so a require line with no importer is stripped before it reaches CI. Assisted-by: Claude Code:claude-opus-5 [Bash] [Edit] [Write] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * refactor(chat): split the pre-agent phase out of Run and pin it Everything before the handoff is testable and nothing after it is: once app.Run owns the terminal there is no seam left. prepare draws that line, takes interactivity as a parameter so the prompts can be driven over a pipe, and hands Run the state dir, the model, and any server it started. The questions move onto one prompter that owns its buffered reader. A fresh bufio.Reader per question reads ahead and discards what it buffered, so the model choice typed behind an answer to "start a server?" was lost and the next question saw EOF. choose answers with a list index and refuses an empty offer, so a value that was never on the list cannot reach ResolveModel, which persists it and starts every later run against it. Assisted-by: Claude Code:claude-opus-5 [Bash] [Edit] [Write] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix(chat): bound each server check with a deadline Nothing bounded the model listing, so pointing chat at an address that accepts the connection and then never replies left the user with no output and no offer to start a server. The budget is context.WithTimeout rather than a cancel plus a timer. Probe deliberately refuses to call an endpoint unreachable on a context.Canceled, since a caller who gave up learned nothing about the server, and only honours a deadline. A cancel-based budget therefore expires as the one error that suppresses ErrUnreachable, exactly for the hung servers the offer exists to rescue. Assisted-by: Claude Code:claude-opus-5 [Bash] [Edit] [Write] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix(chat): tell the user when their model choice cannot be saved The choice is meant to be asked for once. When saving it fails the user is silently asked again on the next run, and the only trace was an xlog.Warn: the agent runs at log level error, and a --log-level=error run swallows it entirely. ModelRequest gains Notify for exactly this class of problem, one that is worth telling the user about but not worth failing over, and the chat wiring points it at the same writer the question was asked on. Assisted-by: Claude Code:claude-opus-5 [Bash] [Edit] [Write] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix(chat): stop a session's server when the process is signalled A server started for the session is stopped by a deferred call, and a signal skips deferred calls: a SIGTERM between the spawn and the exit left 'local-ai run' reparented to init with nothing left that knew to shut it down. Ctrl+C was already safe, but only incidentally, because the child shares this process' foreground process group. A signal handler rather than Pdeathsig on the child. Pdeathsig is Linux-only and, in Go, is delivered when the OS thread that forked exits rather than when the process does, so it can fire on a healthy parent. Setpgid would break the Ctrl+C that works today by taking the child out of the foreground group. SIGHUP joins SIGINT and SIGTERM: a terminal program whose terminal is gone has nobody left to talk to. The same context is what cancels the agent, which nib leaves to its embedder. Assisted-by: Claude Code:claude-opus-5 [Bash] [Edit] [Write] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix(chat): only skip the server checks for work that stays local Two argument shapes were classified wrongly. Every 'mcp ...' invocation counted as management, so 'local-ai chat mcp --stdio', which serves the agent over MCP and needs a model like any other session, was handed an empty one. And --init, whose shell snippet a user pastes into an rc file long before any server exists, went the other way: it demanded a running server to print a static string. The mcp split is asked of nib's own IsMCPManageSubcommand rather than restated here, so a verb added upstream cannot drift out of this list. Assisted-by: Claude Code:claude-opus-5 [Bash] [Edit] [Write] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix(chat): exit with the agent's status instead of reporting it twice nib writes what went wrong to stderr and returns nothing but an exit code, so returning that error unchanged had main log "Error running the application error=exit status 1" underneath the message the user had just read. The refusal to render the full-screen interface into a pipe is the one they meet in practice: it names --cli, and burying that hides the fix. ExitCodeError says "already reported, exit with this status". main honours it and prints nothing more, so a piped or redirected chat still fails a script the way it should. Assisted-by: Claude Code:claude-opus-5 [Bash] [Edit] [Write] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * style(chat): route interactive chatter through one writer helper The prompts and notices all write to a terminal, where a failed write is not worth failing the session over and the read that follows the question reports the real problem. say says that once instead of five discarded error returns. The command's one-line help comes along: chat is no longer "an interactive chat session". Assisted-by: Claude Code:claude-opus-5 [Bash] [Edit] [Write] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * docs(chat): record why the agent gets this process' streams Injecting them is what makes nib refuse to draw its full-screen interface into a pipe and name --cli, instead of rendering onto a terminal the caller may not own. The tradeoff is worth stating where the wiring is. Assisted-by: Claude Code:claude-opus-5 [Bash] [Edit] [Write] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix(chat): stop the session's server on cancellation, not on the way out The deferred Stop is reached only if the agent returns, and cancelling the context does not make it: nib hands the TUI to bubbletea without the context, so what actually unwinds a running session today is bubbletea's own SIGINT and SIGTERM handler. SIGHUP has no such backstop, and registering for it removed the default disposition that used to end the process outright, so kill -HUP left a live TUI with a cancelled context and the started server still running. runSession watches the context alongside the agent and stops the server the moment it is cancelled, so the guarantee no longer depends on what the agent does with cancellation. Stop is idempotent, so the deferred call stays correct and free. The doc comment on shutdownContext described the mechanism it was supposed to work by rather than the one that does. Corrected, bubbletea's handler included. ResolveModel now checks the chooser's answer against what it offered. The shipped chooser answers by list index and cannot be wrong, but ModelChooser is exported, the answer is persisted, and every later run starts against it, so the invariant belongs at the consumer. Assisted-by: Claude Code:claude-opus-5 [Bash] [Edit] [Write] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * chore(chat): bump nib to v0.5.1 v0.5.1 carries four fixes that matter to 'local-ai chat': - --init now names the embedder's command, so the emitted widget invokes 'local-ai chat' rather than a bare 'nib' the user does not have. - A piped CLI session that succeeds exits 0 instead of failing with EOF. - EOF at a tool-approval prompt denies the call rather than approving it, and the session exits 3 (app.ExitCodeApprovalNoInput) so a script can tell "answered" from "refused to act" without reading stdout. Read-only tools are unaffected and still run. ExitStatus already unwraps app.ExitError, so the code propagates with no change here. - RunTUI passes the context to bubbletea and gives up bubbletea's own signal handler, which makes shutdownContext the single owner of the signal and stops a SIGHUP leaving a wedged TUI behind. Verified against a live server on 127.0.0.1:8080: the three --init shells, a piped prompt exiting 0, a denied 'touch' that left no file and exited 3, a read-only 'ls' that still ran and exited 0, and a SIGHUP that unwound a TUI running under a pty. Two comment blocks in run.go described the old TUI behavior and are now wrong, so they are corrected in the same change. No behavior change: both shutdownContext and runSession are untouched, and stopping the server on cancellation is still worth keeping independent of how promptly nib unwinds. One known gap, not addressed here. The widget --init now emits runs 'output=$(local-ai chat --height 50%)', and runAgent injects Stdout unconditionally, so under $(...) nib refuses the TUI for a non-terminal stream. This is the cost the runAgent comment already anticipated, now that the snippets no longer hardcode standalone nib. Ctrl+Space should not be documented until that is decided. Assisted-by: Claude Code:claude-opus-5 [Bash] [Edit] [Write] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix(chat): let nib own stdout, so the Ctrl+Space widget works The widget 'local-ai chat --init' emits runs 'output=$(local-ai chat --height 50%)', which puts a pipe on stdout by construction. runAgent injected os.Stdout unconditionally, and nib refuses every mode but --cli when a stream it was handed is not a terminal, so Ctrl+Space printed "Re-run with --cli to use the injected streams" and inserted nothing. Verified against a pty before and after. nib reads a nil stream as "not injected" and falls back to the process stream, which is how an embedder asks for nib's own behavior. That is what stdout needs: the interface renders on /dev/tty but writes the chosen command to stdout even when stdout is a pipe, and that write is the whole of the shell-capture idiom. Stdin is deliberately left injected. A piped or redirected stdin really is ignored by the interface, so the refusal is the honest answer there, and it is the one users meet: 'echo q | local-ai chat' still says to re-run with --cli, once, exit 1. Nilling stdin the way stdout is nilled would delete that silently. Stderr is not gated by nib at all and is unchanged. One case does change and cannot be kept: 'local-ai chat > out.txt' from a terminal no longer refuses, because it is indistinguishable from the widget. It renders on /dev/tty and writes the capture line to the file, which is what standalone nib does. The app.Options literal moves into agentOptions so the decision is reachable from a spec rather than being a detail of a function that takes the terminal. Both sides of the asymmetry are pinned: reinstating 'Stdout: opts.Out' fails "hands nib nothing for the process stdout", and nilling stdin fails "hands the process stdin over". Also rewrites the last comments describing the pre-v0.5.1 behavior. Assisted-by: Claude Code:claude-opus-5 [Bash] [Edit] [Write] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * docs(chat): say what the stream refusal actually keys on Two comments still called it the refusal to render the interface "into a pipe". That was true when both stdin and stdout were injected, but a pipe on stdout no longer refuses, so the wording now points at precisely the case that was un-refused to make Ctrl+Space work. Only a stdin that cannot be read triggers it, and both comments now say so and name the command a user meets it with, 'echo q | local-ai chat'. The agentOptions doc also said a "file a caller chose" stays injected and refused, which reads as though 'local-ai chat > out.txt' still refuses. It does not: a shell redirect arrives as os.Stdout and is nil-ed like the widget's pipe, because the two differ only in being a regular file rather than a FIFO and nib's gate does not look at that. What stays injected is a writer an in-process caller chose for itself. Says that now, in the doc and in the spec comment that had the same ambiguity. Comments only. No behavior change. Assisted-by: Claude Code:claude-opus-5 [Bash] [Edit] [Write] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * docs: local-ai chat is now the built-in terminal agent `local-ai chat` was a plain chat prompt and is now an agent that runs shell commands behind an approval gate, so the pages that described a REPL were wrong rather than merely thin. Adds a Terminal agent feature page at /features/terminal-agent covering the approval gate, piped runs and their exit codes, Ctrl+Space, model resolution, state directory, and the pass-through management commands (including the `--yes` caveat that leaves a plugin installed but disabled in a script). The three-way "looking for something else" notice becomes four-way and moves into an agentic-routing shortcode. Four hand-kept copies of the same paragraph is what produced the drift the new page would otherwise have added to; the shortcode takes `current=` so each page still marks itself, and errors the build on a name that is not one of the four. Assisted-by: Claude Code:claude-opus-5 [Bash] [Edit] [Write] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * website: the agent is in the binary, not a second install The nib section sold a separate tool you also install, with a GitHub link as the only way in, which is now the wrong order: the agent ships compiled into local-ai, and the standalone binary is the second reason to care rather than the first. Leads with `local-ai chat`, keeps nib as the SSH-anywhere story, and adds a docs CTA pointing at the new Terminal agent page. id="nib" is left alone because localai.io/#nib is linked from outside. The two credits on the demo clip named nib as the thing that drove the machine; they now credit the agent in LocalAI, which is the same agent. Assisted-by: Claude Code:claude-opus-5 [Bash] [Edit] [Write] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * website: fix the exit keys, the plugin warning, and the redirect gap Three claims on the chat-agent pages that the code does not back. try-it-out told readers to press Ctrl+D. nib has no Ctrl+D handler: the full-screen interface quits on Esc or Ctrl+C, and Ctrl+D is only an exit in --cli, where it arrives as ordinary tty EOF. That sentence had replaced the removed /exit and /quit text, so the page was left with no working way to leave a session. Document both modes, since they differ. The plugin warning said nothing tells you the install stopped short. It does: the command prints that the plugin was left disabled. What it does not do is say so in its exit code, which is 0 either way. That is the part a script cannot work around, and it is the reason to pass --yes. Overstating it in the paragraph that gives the advice only makes the advice easier to dismiss. Redirecting stdout no longer refuses; the interface goes to /dev/tty and only the yanked command reaches the file. It is what lets the Ctrl+Space widget capture a command at all, since a redirect and out=$(...) are the same thing to the stream gate. It was documented nowhere. A non-terminal stdin is still refused, and the new text says which of the two it is. Assisted-by: Claude Code:claude-opus-5 [Bash] [Edit] [Write] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix(chat): make the CLI flags outrank the agent config file local-ai chat routed --endpoint, --model, --api-key, --trace-dir and --yolo through nib's app.Options.Defaults. Defaults are seeds: they sit beneath the config file, so the file silently undoes them. That made the flags accepted and inert, and not in an edge case, since EnsureStateDir writes base_url on the first run and the interactive picker writes model, so from the second run on the file carried a value for both. Observed against a live server: with base_url: http://127.0.0.1:9999/v1 in the config and --endpoint http://127.0.0.1:8080 on the command line, the probe hit 8080 and every agent turn posted to 9999. With model: gemma-4-e2b-it-qat-q4_0 in the config, --model lfm2.5-8b-a1b was ignored on the wire. nib v0.6.0 adds app.Options.Overrides, applied above the config file and above the bare environment block. Move the whole block there: all five values are decisions this invocation already made on the user's behalf, and a flag the config file can undo is not a flag. Nothing is left in Defaults, because LocalAI's one genuine seed, the initial base_url, is written into the config file by EnsureStateDir rather than handed to nib. Two limits come with the channel and are documented on agentOptions rather than worked around. An override can only raise a field, since nib cannot tell "set to the zero value" from "not set", so --yolo can turn approval off but nothing on the command line turns it back on over an approval_mode: auto in the file. And nib's own NIB_TRACE_DIR and NIB_YOLO are resolved after the config load and still outrank these, deliberately, upstream. The existing spec pinned that the right values reach app.Options, which they always did, which is exactly why it could not see nib discarding them. The new specs resolve the config the way app.Run resolves it, against a real config file that disagrees with every flag, and one asserts Defaults stays empty. docs/content/features/terminal-agent.md already documented --model as winning over the saved model; that was false before this change and is true now, so no docs edit was needed. Assisted-by: Claude Code:claude-opus-5 [Bash] [Edit] [Write] Signed-off-by: Ettore Di Giacinto <mudler@localai.io> * fix(chat): document intentional config file read Assisted-by: Codex:gpt-5 [gosec] --------- Signed-off-by: Ettore Di Giacinto <mudler@localai.io> Co-authored-by: Ettore Di Giacinto <mudler@localai.io> Co-authored-by: localai-org-maint-bot <306269227+localai-org-maint-bot@users.noreply.github.com>
630 lines
23 KiB
Go
630 lines
23 KiB
Go
package chat
|
|
|
|
import (
|
|
"bytes"
|
|
"context"
|
|
"encoding/json"
|
|
"errors"
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"syscall"
|
|
"time"
|
|
|
|
"github.com/mudler/nib/app"
|
|
nibconfig "github.com/mudler/nib/config"
|
|
nibtypes "github.com/mudler/nib/types"
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
// modelServer answers /v1/models with the given ids, as LocalAI does.
|
|
func modelServer(ids ...string) *httptest.Server {
|
|
return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
data := make([]map[string]string, 0, len(ids))
|
|
for _, id := range ids {
|
|
data = append(data, map[string]string{"id": id, "object": "model"})
|
|
}
|
|
w.Header().Set("Content-Type", "application/json")
|
|
Expect(json.NewEncoder(w).Encode(map[string]any{"object": "list", "data": data})).To(Succeed())
|
|
}))
|
|
}
|
|
|
|
var _ = Describe("prepare", func() {
|
|
var (
|
|
dir string
|
|
errOut *bytes.Buffer
|
|
)
|
|
|
|
BeforeEach(func() {
|
|
dir = GinkgoT().TempDir()
|
|
errOut = &bytes.Buffer{}
|
|
})
|
|
|
|
// optionsFor points a run at srv, with no input to read: the default is a
|
|
// session nobody can be asked anything in.
|
|
optionsFor := func(srv *httptest.Server) Options {
|
|
endpoint := "http://127.0.0.1:0"
|
|
base := endpoint + "/v1"
|
|
if srv != nil {
|
|
endpoint, base = srv.URL, srv.URL+"/v1"
|
|
}
|
|
return Options{
|
|
Endpoint: endpoint,
|
|
BaseURL: base,
|
|
StateDir: dir,
|
|
In: strings.NewReader(""),
|
|
Out: &bytes.Buffer{},
|
|
ErrOut: errOut,
|
|
}
|
|
}
|
|
|
|
It("uses the only model the server offers", func() {
|
|
srv := modelServer("the-only-model")
|
|
defer srv.Close()
|
|
|
|
p, err := prepare(context.Background(), optionsFor(srv), false)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(p.model).To(Equal("the-only-model"))
|
|
Expect(p.dir).To(Equal(dir))
|
|
Expect(p.server).To(BeNil(), "nothing was started, so nothing is owned")
|
|
})
|
|
|
|
It("seeds the agent config with the endpoint on first run", func() {
|
|
srv := modelServer("m")
|
|
defer srv.Close()
|
|
|
|
_, err := prepare(context.Background(), optionsFor(srv), false)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
data, err := os.ReadFile(ConfigPath(dir))
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(string(data)).To(ContainSubstring(srv.URL + "/v1"))
|
|
})
|
|
|
|
It("lets --model win over what the server offers", func() {
|
|
srv := modelServer("a", "b")
|
|
defer srv.Close()
|
|
|
|
opts := optionsFor(srv)
|
|
opts.Model = "not-listed-yet"
|
|
p, err := prepare(context.Background(), opts, false)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(p.model).To(Equal("not-listed-yet"))
|
|
})
|
|
|
|
It("advises about the API key when the server rejects it", func() {
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
w.WriteHeader(http.StatusUnauthorized)
|
|
}))
|
|
defer srv.Close()
|
|
|
|
_, err := prepare(context.Background(), optionsFor(srv), false)
|
|
Expect(err).To(HaveOccurred())
|
|
Expect(err.Error()).To(ContainSubstring("--api-key"))
|
|
Expect(err.Error()).To(ContainSubstring(srv.URL))
|
|
})
|
|
|
|
// Not interactive means nobody can answer the offer, so the advice has to
|
|
// stand on its own.
|
|
It("advises how to start a server when none is reachable", func() {
|
|
srv := modelServer()
|
|
url := srv.URL
|
|
srv.Close() // nothing is listening now
|
|
|
|
opts := optionsFor(nil)
|
|
opts.Endpoint, opts.BaseURL = url, url+"/v1"
|
|
_, err := prepare(context.Background(), opts, false)
|
|
Expect(err).To(HaveOccurred())
|
|
Expect(err.Error()).To(ContainSubstring("local-ai run"))
|
|
Expect(err.Error()).To(ContainSubstring(url))
|
|
})
|
|
|
|
// A server that accepts the connection and then never replies is the case
|
|
// the offer to start one exists for, so the budget has to expire as a
|
|
// deadline: Probe reads a cancellation as "the caller gave up" and refuses
|
|
// to call the endpoint unreachable on the strength of it.
|
|
It("treats a server that never answers as one that is not there", func(ctx SpecContext) {
|
|
release := make(chan struct{})
|
|
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
select {
|
|
case <-release:
|
|
case <-r.Context().Done():
|
|
}
|
|
}))
|
|
defer srv.Close()
|
|
defer close(release)
|
|
|
|
opts := optionsFor(srv)
|
|
opts.ProbeTimeout = 100 * time.Millisecond
|
|
_, err := prepare(context.Background(), opts, false)
|
|
Expect(err).To(HaveOccurred())
|
|
Expect(err.Error()).To(ContainSubstring("local-ai run"), "want the offer-a-server advice, got %v", err)
|
|
}, SpecTimeout(30*time.Second))
|
|
|
|
It("asks which model to use and remembers the answer", func() {
|
|
srv := modelServer("zeta", "alpha")
|
|
defer srv.Close()
|
|
|
|
opts := optionsFor(srv)
|
|
opts.In = strings.NewReader("2\n")
|
|
p, err := prepare(context.Background(), opts, true)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
// The list is sorted before it is shown, so 2 is zeta, not the second
|
|
// thing the server happened to name.
|
|
Expect(p.model).To(Equal("zeta"))
|
|
Expect(errOut.String()).To(ContainSubstring("1) alpha"))
|
|
Expect(errOut.String()).To(ContainSubstring("2) zeta"))
|
|
|
|
data, err := os.ReadFile(ConfigPath(dir))
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(string(data)).To(ContainSubstring("zeta"))
|
|
})
|
|
|
|
// The choice is prompted for once and remembered. When remembering it fails
|
|
// the user is about to be asked again on every future run, so they have to
|
|
// be told here: a log line is invisible at the default log level.
|
|
It("says so on the prompt when the choice cannot be remembered", func() {
|
|
srv := modelServer("zeta", "alpha")
|
|
defer srv.Close()
|
|
|
|
// A directory where the config file belongs: writable state dir,
|
|
// unwritable config, on any platform and as any user.
|
|
Expect(os.MkdirAll(ConfigPath(dir), 0o700)).To(Succeed())
|
|
|
|
opts := optionsFor(srv)
|
|
opts.In = strings.NewReader("1\n")
|
|
p, err := prepare(context.Background(), opts, true)
|
|
|
|
// Failing to remember the choice must not cost the user their session.
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(p.model).To(Equal("alpha"))
|
|
Expect(errOut.String()).To(ContainSubstring("could not be saved"), "the user has to learn they will be asked again")
|
|
})
|
|
|
|
It("does not ask again once a model is recorded", func() {
|
|
srv := modelServer("zeta", "alpha")
|
|
defer srv.Close()
|
|
|
|
Expect(PersistModel(dir, "alpha")).To(Succeed())
|
|
|
|
opts := optionsFor(srv)
|
|
opts.In = strings.NewReader("") // an answer would have nothing to read
|
|
p, err := prepare(context.Background(), opts, true)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(p.model).To(Equal("alpha"))
|
|
Expect(errOut.String()).To(BeEmpty())
|
|
})
|
|
|
|
It("says what to install when the server has no models", func() {
|
|
srv := modelServer()
|
|
defer srv.Close()
|
|
|
|
_, err := prepare(context.Background(), optionsFor(srv), false)
|
|
Expect(err).To(HaveOccurred())
|
|
Expect(err.Error()).To(ContainSubstring("models install"))
|
|
})
|
|
|
|
Describe("arguments that only touch local state", func() {
|
|
unreachable := func(args ...string) Options {
|
|
opts := optionsFor(nil) // port 0: nothing can ever answer here
|
|
opts.Args = args
|
|
return opts
|
|
}
|
|
|
|
DescribeTable("skips the server entirely",
|
|
func(args ...string) {
|
|
p, err := prepare(context.Background(), unreachable(args...), false)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(p.model).To(BeEmpty())
|
|
Expect(p.server).To(BeNil())
|
|
},
|
|
Entry("plugin", "plugin", "list"),
|
|
Entry("skill", "skill", "list"),
|
|
Entry("mcp add", "mcp", "add", "srv"),
|
|
Entry("mcp list", "mcp", "list"),
|
|
// The shell snippet is what a user puts in their rc file, long
|
|
// before any server exists.
|
|
Entry("the shell integration script", "--init", "zsh"),
|
|
Entry("the version", "--version"),
|
|
)
|
|
|
|
// Bare 'mcp' and its transport flags serve the agent over MCP, so they
|
|
// need a model like any other session. Only the verbs that edit the
|
|
// configured servers are local.
|
|
DescribeTable("still needs a server",
|
|
func(args ...string) {
|
|
_, err := prepare(context.Background(), unreachable(args...), false)
|
|
Expect(err).To(HaveOccurred())
|
|
Expect(err.Error()).To(ContainSubstring("local-ai run"))
|
|
},
|
|
Entry("mcp over stdio", "mcp", "--stdio"),
|
|
Entry("bare mcp", "mcp"),
|
|
)
|
|
})
|
|
|
|
// A reader per question would read ahead into a buffer it then discards, so
|
|
// the second question would see EOF whenever both answers were typed ahead.
|
|
// That is the shape of a real run: the offer to start a server is followed
|
|
// by the model prompt.
|
|
It("keeps reading answers from the same stream across questions", func() {
|
|
out := &bytes.Buffer{}
|
|
p := newPrompter(strings.NewReader("y\n2\n"), out)
|
|
|
|
yes, err := p.yesNo("Start one now?")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(yes).To(BeTrue())
|
|
|
|
chosen, err := p.choose([]string{"alpha", "zeta"})
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(chosen).To(Equal("zeta"))
|
|
})
|
|
|
|
// Whatever the chooser returns is persisted and used for every later run,
|
|
// so an answer that is not one of the offered models must never come back
|
|
// as one.
|
|
Describe("the model prompt", func() {
|
|
offered := []string{"alpha", "zeta"}
|
|
|
|
DescribeTable("refuses an answer that is not one of the numbers shown",
|
|
func(answer string) {
|
|
chosen, err := newPrompter(strings.NewReader(answer), &bytes.Buffer{}).choose(offered)
|
|
Expect(err).To(HaveOccurred())
|
|
Expect(chosen).To(BeEmpty())
|
|
},
|
|
Entry("nothing at all", ""),
|
|
Entry("a blank line", "\n"),
|
|
Entry("only spaces", " \n"),
|
|
Entry("zero", "0\n"),
|
|
Entry("past the end", "3\n"),
|
|
Entry("negative", "-1\n"),
|
|
Entry("a model name", "zeta\n"),
|
|
Entry("a number with a suffix", "1x\n"),
|
|
)
|
|
|
|
It("says how to answer when the answer was not a number", func() {
|
|
_, err := newPrompter(strings.NewReader("banana\n"), &bytes.Buffer{}).choose(offered)
|
|
Expect(err).To(HaveOccurred())
|
|
Expect(err.Error()).To(ContainSubstring("between 1 and 2"))
|
|
Expect(err.Error()).To(ContainSubstring("--model"))
|
|
})
|
|
|
|
It("returns the model shown against the number", func() {
|
|
chosen, err := newPrompter(strings.NewReader("1\n"), &bytes.Buffer{}).choose(offered)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(chosen).To(Equal("alpha"))
|
|
})
|
|
|
|
It("refuses to ask when there is nothing to offer", func() {
|
|
chosen, err := newPrompter(strings.NewReader("1\n"), &bytes.Buffer{}).choose(nil)
|
|
Expect(err).To(HaveOccurred())
|
|
Expect(chosen).To(BeEmpty())
|
|
})
|
|
})
|
|
|
|
// A server started for this session is stopped by a deferred call, which a
|
|
// signal skips: the process dies where it stands and leaves 'local-ai run'
|
|
// reparented to init.
|
|
Describe("shutdown signals", func() {
|
|
It("ends the session when the terminal goes away", func() {
|
|
ctx, stop := shutdownContext(context.Background())
|
|
defer stop()
|
|
|
|
self, err := os.FindProcess(os.Getpid())
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(self.Signal(syscall.SIGHUP)).To(Succeed())
|
|
|
|
Eventually(ctx.Done()).WithTimeout(5 * time.Second).Should(BeClosed())
|
|
Expect(ctx.Err()).To(MatchError(context.Canceled))
|
|
})
|
|
|
|
// SIGINT and SIGTERM cannot be delivered here to prove the same thing:
|
|
// Ginkgo registers for both to abort the suite, and a signal goes to
|
|
// every registered listener.
|
|
It("also listens for an interrupt and a terminate", func() {
|
|
Expect(shutdownSignals).To(ContainElements(os.Signal(os.Interrupt), os.Signal(syscall.SIGTERM)))
|
|
})
|
|
})
|
|
|
|
// Cancelling the context does unwind nib's TUI since v0.5.1, but how long
|
|
// that takes is nib's business, and the deferred Stop in Run is only reached
|
|
// once the agent returns. A server this process started is ours to end, so
|
|
// the guarantee is made here instead, where it does not depend on the agent
|
|
// at all. Before v0.5.1 there was no guarantee to be had on the SIGHUP path:
|
|
// bubbletea's own SIGINT and SIGTERM handler was the only thing that ever
|
|
// quit the program, and registering for SIGHUP took away the default
|
|
// disposition that used to end the process.
|
|
Describe("runSession", func() {
|
|
It("stops the session's server on cancellation, without waiting for the agent", func() {
|
|
server, proc := stoppableServer()
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
defer cancel()
|
|
|
|
err := runSession(ctx, server, func(ctx context.Context) error {
|
|
cancel()
|
|
Eventually(func() int32 { return proc.interrupts.Load() }).
|
|
WithTimeout(5 * time.Second).
|
|
Should(BeNumerically(">", 0), "the server has to be stopped while the agent is still running")
|
|
return nil
|
|
})
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(proc.lastSignal.Load()).To(Equal(os.Interrupt))
|
|
})
|
|
|
|
It("leaves the server alone for as long as the session lasts", func() {
|
|
server, proc := stoppableServer()
|
|
|
|
Expect(runSession(context.Background(), server, func(context.Context) error {
|
|
return nil
|
|
})).To(Succeed())
|
|
Expect(proc.interrupts.Load()).To(BeZero())
|
|
Expect(proc.kills.Load()).To(BeZero())
|
|
})
|
|
|
|
It("returns what the agent returned", func() {
|
|
failed := errors.New("the agent gave up")
|
|
server, _ := stoppableServer()
|
|
|
|
Expect(runSession(context.Background(), server, func(context.Context) error {
|
|
return failed
|
|
})).To(MatchError(failed))
|
|
})
|
|
|
|
// Most sessions run against a server the user already had, and there is
|
|
// nothing to stop then.
|
|
It("copes with a session that started no server", func() {
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
cancel()
|
|
|
|
Expect(runSession(ctx, nil, func(context.Context) error {
|
|
return nil
|
|
})).To(Succeed())
|
|
})
|
|
})
|
|
|
|
// Which streams reach nib decides two user-visible behaviours at once, and
|
|
// they pull in opposite directions, so both are pinned here rather than left
|
|
// to whoever next edits the literal.
|
|
//
|
|
// nib refuses every mode but --cli when a stream it was handed is not a
|
|
// terminal. That refusal is wanted for stdin, where it is what tells someone
|
|
// piping a question to re-run with --cli. It is not wanted for the process
|
|
// stdout, where it would refuse the Ctrl+Space widget that --init emits:
|
|
// out=$(local-ai chat --height 50%) puts a pipe on stdout by construction,
|
|
// and writing the chosen command into that pipe is the entire point.
|
|
Describe("agentOptions", func() {
|
|
// optionsWithStreams is a request that differs from the next only in
|
|
// what it was told to read and write.
|
|
optionsWithStreams := func(in io.Reader, out, errOut io.Writer) Options {
|
|
return Options{
|
|
BaseURL: "http://127.0.0.1:8080/v1",
|
|
In: in,
|
|
Out: out,
|
|
ErrOut: errOut,
|
|
}
|
|
}
|
|
|
|
Describe("stdout", func() {
|
|
// The regression this exists to catch: reinstating
|
|
// 'Stdout: opts.Out' breaks Ctrl+Space and nothing else notices.
|
|
It("hands nib nothing for the process stdout, so the capture widget is not refused", func() {
|
|
o := agentOptions(dir, "a-model", optionsWithStreams(os.Stdin, os.Stdout, os.Stderr))
|
|
Expect(o.Stdout).To(BeNil(), "injecting os.Stdout is what refuses out=$(local-ai chat)")
|
|
})
|
|
|
|
It("keeps a stdout the caller chose, which the refusal still guards", func() {
|
|
out := &bytes.Buffer{}
|
|
o := agentOptions(dir, "a-model", optionsWithStreams(os.Stdin, out, os.Stderr))
|
|
Expect(o.Stdout).To(BeIdenticalTo(out))
|
|
})
|
|
|
|
// Being an *os.File is not what makes a stream nib's own; being the
|
|
// process stdout is. This is a file an in-process caller opened for
|
|
// itself, not one a shell redirect handed over as stdout, which
|
|
// still arrives as os.Stdout and is still nil-ed. It was never going
|
|
// to receive the interface, so it stays injected and stays refused.
|
|
It("keeps a file that is not the process stdout", func() {
|
|
f, err := os.CreateTemp(GinkgoT().TempDir(), "captured")
|
|
Expect(err).ToNot(HaveOccurred())
|
|
DeferCleanup(f.Close)
|
|
|
|
o := agentOptions(dir, "a-model", optionsWithStreams(os.Stdin, f, os.Stderr))
|
|
Expect(o.Stdout).To(BeIdenticalTo(f))
|
|
})
|
|
})
|
|
|
|
Describe("stdin", func() {
|
|
// The opposite regression: nilling stdin the way stdout is nilled
|
|
// would silently drop the refusal that names --cli.
|
|
It("hands the process stdin over, so a piped session is still refused", func() {
|
|
o := agentOptions(dir, "a-model", optionsWithStreams(os.Stdin, os.Stdout, os.Stderr))
|
|
Expect(o.Stdin).To(BeIdenticalTo(os.Stdin))
|
|
})
|
|
|
|
It("hands over a stdin the caller chose", func() {
|
|
in := strings.NewReader("a question")
|
|
o := agentOptions(dir, "a-model", optionsWithStreams(in, os.Stdout, os.Stderr))
|
|
Expect(o.Stdin).To(BeIdenticalTo(in))
|
|
})
|
|
})
|
|
|
|
// nib gates stdin and stdout and nothing else, so there is no reason to
|
|
// hide the error stream from it.
|
|
It("hands the error stream over whatever it is", func() {
|
|
errOut := &bytes.Buffer{}
|
|
o := agentOptions(dir, "a-model", optionsWithStreams(os.Stdin, os.Stdout, errOut))
|
|
Expect(o.Stderr).To(BeIdenticalTo(errOut))
|
|
|
|
o = agentOptions(dir, "a-model", optionsWithStreams(os.Stdin, os.Stdout, os.Stderr))
|
|
Expect(o.Stderr).To(BeIdenticalTo(os.Stderr))
|
|
})
|
|
|
|
It("names the command a user would type, not the binary nib ships as", func() {
|
|
o := agentOptions(dir, "a-model", optionsWithStreams(os.Stdin, os.Stdout, os.Stderr))
|
|
Expect(o.ProgramName).To(Equal("local-ai chat"),
|
|
"the --init widget invokes this name, so a user has to be able to run it")
|
|
})
|
|
|
|
It("carries the resolved session through to nib", func() {
|
|
opts := optionsWithStreams(os.Stdin, os.Stdout, os.Stderr)
|
|
opts.Args = []string{"--cli"}
|
|
opts.APIKey = "a-key"
|
|
opts.TraceDir = "/traces"
|
|
|
|
o := agentOptions(dir, "the-model", opts)
|
|
Expect(o.Args).To(Equal([]string{"--cli"}))
|
|
Expect(o.BaseDir).To(Equal(dir))
|
|
Expect(o.Overrides.Model).To(Equal("the-model"))
|
|
Expect(o.Overrides.APIKey).To(Equal("a-key"))
|
|
Expect(o.Overrides.BaseURL).To(Equal("http://127.0.0.1:8080/v1"))
|
|
Expect(o.Overrides.TraceDir).To(Equal("/traces"))
|
|
// The model and the server are settled before nib starts, and the
|
|
// bare MODEL and API_KEY variables belong to some other tool.
|
|
Expect(o.SkipSetup).To(BeTrue())
|
|
Expect(o.SkipBareEnv).To(BeTrue())
|
|
})
|
|
|
|
// Defaults sit beneath the config file. Anything routed through them is
|
|
// accepted from the command line and then thrown away the moment the
|
|
// file carries the same key, which is the normal state rather than an
|
|
// edge case. Nothing this command resolves belongs there, so the channel
|
|
// stays empty and this says so: it is what fails if the block is moved
|
|
// back a rung.
|
|
It("seeds nothing, because a seed is not a flag", func() {
|
|
opts := optionsWithStreams(os.Stdin, os.Stdout, os.Stderr)
|
|
opts.APIKey = "a-key"
|
|
opts.TraceDir = "/traces"
|
|
opts.Yolo = true
|
|
|
|
Expect(agentOptions(dir, "the-model", opts).Defaults).To(Equal(nibtypes.Config{}),
|
|
"Defaults lose to the config file, so a value placed there is a flag that does nothing")
|
|
})
|
|
|
|
It("asks for automatic approval only when --yolo was given", func() {
|
|
opts := optionsWithStreams(os.Stdin, os.Stdout, os.Stderr)
|
|
Expect(agentOptions(dir, "a-model", opts).Overrides.ApprovalMode).To(BeEmpty())
|
|
|
|
opts.Yolo = true
|
|
Expect(agentOptions(dir, "a-model", opts).Overrides.ApprovalMode).To(Equal("auto"))
|
|
})
|
|
|
|
// The specs above pin what is handed over. These pin what nib does with
|
|
// it, which is the part that was wrong: every value below reached
|
|
// app.Options intact and was then discarded by the config load, so a
|
|
// spec that stops at the struct cannot see the bug. Resolving the config
|
|
// the way app.Run resolves it can.
|
|
Describe("the config nib actually resolves", func() {
|
|
// writeConfig puts a config file where nib will read it, with values
|
|
// that disagree with every flag under test.
|
|
writeConfig := func(body string) {
|
|
Expect(os.WriteFile(ConfigPath(dir), []byte(body), 0o600)).To(Succeed())
|
|
}
|
|
|
|
// resolve loads the config exactly as app.Run does, so the precedence
|
|
// under test is nib's own rather than a restatement of it here.
|
|
resolve := func(o app.Options) nibtypes.Config {
|
|
return nibconfig.LoadWith(nibconfig.LoadOptions{
|
|
BaseDir: o.BaseDir,
|
|
Defaults: o.Defaults,
|
|
Overrides: o.Overrides,
|
|
SkipBareEnv: o.SkipBareEnv,
|
|
})
|
|
}
|
|
|
|
It("sends the requests to the endpoint the flag named, not the one on disk", func() {
|
|
writeConfig("base_url: http://127.0.0.1:9999/v1\n")
|
|
|
|
opts := optionsWithStreams(os.Stdin, os.Stdout, os.Stderr)
|
|
opts.BaseURL = "http://127.0.0.1:8080/v1"
|
|
|
|
cfg := resolve(agentOptions(dir, "a-model", opts))
|
|
Expect(cfg.BaseURL).To(Equal("http://127.0.0.1:8080/v1"),
|
|
"--endpoint probed 8080; every turn has to go there too")
|
|
})
|
|
|
|
It("uses the model the flag named, not the one the picker recorded", func() {
|
|
writeConfig("model: recorded-model\n")
|
|
|
|
cfg := resolve(agentOptions(dir, "flag-model", optionsWithStreams(os.Stdin, os.Stdout, os.Stderr)))
|
|
Expect(cfg.Model).To(Equal("flag-model"))
|
|
})
|
|
|
|
It("uses the key the flag named, not the one nib saved", func() {
|
|
writeConfig("api_key: saved-key\n")
|
|
|
|
opts := optionsWithStreams(os.Stdin, os.Stdout, os.Stderr)
|
|
opts.APIKey = "flag-key"
|
|
|
|
cfg := resolve(agentOptions(dir, "a-model", opts))
|
|
Expect(cfg.APIKey).To(Equal("flag-key"))
|
|
})
|
|
|
|
It("turns approval off for --yolo even when the file demands it", func() {
|
|
writeConfig("approval_mode: prompt\n")
|
|
|
|
opts := optionsWithStreams(os.Stdin, os.Stdout, os.Stderr)
|
|
opts.Yolo = true
|
|
|
|
cfg := resolve(agentOptions(dir, "a-model", opts))
|
|
Expect(cfg.ApprovalMode).To(Equal("auto"))
|
|
})
|
|
|
|
// The other half of the same rule, and the reason an unset flag is
|
|
// not a demand for the empty string: an override only ever raises a
|
|
// field, so what the user configured survives a run that said
|
|
// nothing about it.
|
|
It("leaves what the file configured alone when no flag was given", func() {
|
|
writeConfig("api_key: saved-key\napproval_mode: prompt\n")
|
|
|
|
cfg := resolve(agentOptions(dir, "a-model", optionsWithStreams(os.Stdin, os.Stdout, os.Stderr)))
|
|
Expect(cfg.APIKey).To(Equal("saved-key"))
|
|
Expect(cfg.ApprovalMode).To(Equal("prompt"))
|
|
})
|
|
})
|
|
})
|
|
|
|
// nib reports its own failures on the error stream and returns nothing but
|
|
// a status, so anything that reaches here as one has already been explained
|
|
// once. The refusal to open a full-screen session on a stdin that cannot be
|
|
// read is the one users meet: 'echo q | local-ai chat' names --cli, and a
|
|
// second message on top would bury the fix.
|
|
Describe("ExitStatus", func() {
|
|
It("recognises a status the agent already explained", func() {
|
|
code, reported := ExitStatus(app.ExitError{Code: 2})
|
|
Expect(reported).To(BeTrue())
|
|
Expect(code).To(Equal(2))
|
|
})
|
|
|
|
It("finds one that has been wrapped", func() {
|
|
code, reported := ExitStatus(fmt.Errorf("running the agent: %w", app.ExitError{Code: 1}))
|
|
Expect(reported).To(BeTrue())
|
|
Expect(code).To(Equal(1))
|
|
})
|
|
|
|
It("leaves an ordinary failure to be reported", func() {
|
|
_, reported := ExitStatus(errors.New("no LocalAI server at http://127.0.0.1:8080"))
|
|
Expect(reported).To(BeFalse())
|
|
})
|
|
|
|
It("says nothing about a run that succeeded", func() {
|
|
_, reported := ExitStatus(nil)
|
|
Expect(reported).To(BeFalse())
|
|
})
|
|
})
|
|
|
|
It("reports a state dir it cannot create", func() {
|
|
blocked := filepath.Join(dir, "a-file")
|
|
Expect(os.WriteFile(blocked, []byte("not a dir"), 0o600)).To(Succeed())
|
|
|
|
opts := optionsFor(nil)
|
|
opts.StateDir = filepath.Join(blocked, "chat")
|
|
_, err := prepare(context.Background(), opts, false)
|
|
Expect(err).To(HaveOccurred())
|
|
Expect(err.Error()).To(ContainSubstring("agent state dir"))
|
|
})
|
|
})
|