Development¶
Running the tests¶
Start the development shell:
Inside that shell, run the full suite, one context, or full coverage:
sbcl --script run-tests.lisp
AITOOLS_TEST_CONTEXT=search sbcl --script run-tests.lisp
AITOOLS_COVERAGE=1 sbcl --script run-tests.lisp
Outside it, set CL_SOURCE_REGISTRY to a parent directory containing a
checkout directory for each dependency. For example, put these pinned
checkouts below $HOME/src/nerima-lisp:
- Direct dependencies: cl-cli, cl-weave, cl-json-kit, cl-regex-kit, cl-codec-kit, cl-host-kit, cl-boundary-kit, cl-concurrent-kit, and cl-process-kit.
- Transitive dependencies: cl-date-kit, cl-log-kit, and cl-parser-kit.
Use the versions pinned in flake.nix.
The //: suffix makes ASDF search the dependency trees below that directory.
run-tests.lisp adds this checkout to ASDF automatically, then
loads aitools and runs asdf:test-system "aitools/test". That operation
discovers registered aitools/test/<context> systems through ASDF. With
AITOOLS_TEST_CONTEXT set, it loads only that context's tests; without it, it
loads every context system and aitools/test/shared.
The aitools/test operation signals an error when a test fails or the execution
policy rejects the result, including a file in a selected test system that
registers specs but executes none, or a skip or todo outside its allowlist. A
file whose specs are all skipped for allowed reasons is exempt from the
execution requirement.
run-tests.lisp catches that error, prints a one-line diagnostic, and exits 1;
it exits 0 when the operation completes. The per-spec report printed to stdout
includes the executed count and any allowed unrun specs.
AITOOLS_COVERAGE always measures the full test set and cannot be combined
with AITOOLS_TEST_CONTEXT.
For the full-suite host gate against the Nix-delivered binary, run:
apps.test starts a fresh SBCL process and loads run-host-tests.lisp from
the flake's filtered source tree in the Nix store, not the writable checkout.
It builds CL_SOURCE_REGISTRY inline from that source and the pinned test
dependencies, and sets
AITOOLS_E2E_BINARY to the delivered bin/aitools. Each invocation
creates a fresh ASDF compilation cache in AITOOLS_HOST_CACHE_DIR and
ignores inherited output translations, so it cannot reuse the host's old
compiled files.
The runner loads aitools/test and runs every registered spec without a
context filter. Success requires a nonempty selection and no todos, failures,
or errors. Skips fail the host gate. The report includes the store
source (SOURCE), delivered binary (BINARY), JSON results, and
POLICY_EXECUTED count.
JSON results appear only after all specs finish. If the run is interrupted,
use stderr's [start] and [end] lines to identify the last attempted spec;
an incomplete run is not a passing gate.
The Linux checks.x86_64-linux.default and checks.x86_64-linux.coverage
test gates use timeoutSeconds = 1800. The host runner uses
timeout -k 30s 1800s: it sends the timeout signal after 1800 seconds and
forces termination after another 30 seconds if the process is still running.
Flake checks¶
The flake supports x86_64-linux and aarch64-darwin. The checks differ
by platform:
| Check | What it runs |
|---|---|
checks.x86_64-linux.default |
The full Nix test suite against the pinned dependencies. CL_PROCESS_KIT_SPAWN is set so the bg specs run, and AITOOLS_E2E_BINARY points t/e2e/ at the delivered package. |
checks.x86_64-linux.coverage |
The full suite with AITOOLS_COVERAGE=1, using the same delivered package and test dependencies. |
checks.aarch64-darwin.default |
Delivery artifacts: the host test runner and spawn helper must be executable, and the delivered binary's schema must return status: ok with nonempty, uniquely named commands. It does not run the full suite. |
checks.<system>.paredit-lint |
paredit-cli's structural lint over every Lisp source in the filtered distribution tree: delimiters must balance. It does not check layout. |
checks.<system>.formatting |
treefmt over the Nix sources. |
checks.<system>.docs |
mkdocs build --strict of this site. |
Darwin's native ps and top cannot run under the Nix build sandbox's
mandatory Seatbelt policy. On Darwin, nix flake check therefore checks
delivery artifacts, Lisp syntax, docs, and formatting; run nix run .#test
as well for the full suite on the host against that delivery.
CI (.github/workflows/ci.yml) splits the suite, static checks, and allocation
measurements so each has its own job limit:
| Job | Runner | Gates | Job timeout |
|---|---|---|---|
check |
ubuntu-latest (x86_64-linux) |
checks.x86_64-linux.coverage, the full suite with coverage. |
35 minutes |
check-linux-tests |
ubuntu-latest (x86_64-linux) |
checks.x86_64-linux.default, the full suite without coverage. |
35 minutes |
check-linux-static |
ubuntu-latest (x86_64-linux) |
Generated reference check, all-system flake evaluation, paredit-lint, docs, formatting, and git diff --check across the commits introduced by the workflow event. |
25 minutes |
check-linux-allocation |
ubuntu-latest (x86_64-linux) |
Cold- and warm-cache allocation measurements. | 10 minutes |
check-darwin-nix |
macos-15 (aarch64-darwin) |
Generated reference check and nix flake check --print-build-logs. |
30 minutes |
check-darwin-host |
macos-15 (aarch64-darwin) |
nix run .#test --print-build-logs and cold- and warm-cache allocation measurements. |
40 minutes |
The Linux test jobs have five minutes beyond the Nix test timeout, so the
derivation can report its 30-minute limit before Actions cancels the job.
The Darwin host job starts after check-darwin-nix and leaves time for setup
and the delivery build before its 30-minute spec timeout begins.
check-linux-static evaluates every check output on both supported systems
without building them, then builds the Linux lint, docs, and formatting checks.
Actions checks out a clean tree, so the check compares the event's commit range
explicitly. The Linux static job fetches full history and runs the check once.
Pushes compare the previous ref tip with the pushed commit. Pull requests use
the first parent of the event's two-parent merge commit as the base. Manual
runs compare the merge base with origin/main to the dispatched commit. The
check fails if it cannot resolve a base or head commit, including an initial
push with no previous commit or a pull request head without exactly two
resolvable parents.
The workflow grants only contents: read, and checkout does not persist its
token in .git/config. Pull-request runs can pull from Cachix but cannot write;
only non-pull-request events on main can write to the cache.
To include files git does not track yet, use the same path: flake reference
for both gates:
The distribution filter keeps .lisp and .asd files plus
skills/aitools/SKILL.md, but excludes scratch directories whose names start
with .release-probe., .session-audit-, or .store-fd-probe.. Including a
new test file does not register its specs: add it to its test system as
described below.
To build one check or the binary alone:
system=$(nix eval --raw --impure --expr 'builtins.currentSystem')
nix build ".#checks.$system.paredit-lint" --print-build-logs
nix build ".#packages.$system.docs" --no-link --print-build-logs
nix build # -> ./result/bin/aitools
packages.default also carries cl-process-kit-spawn, the helper that
bg start uses to detach, next to bin/aitools.
Building the binary¶
nix build produces the delivered binary in two SBCL processes. The
overrideOutputs definition in flake.nix imports
nix/delivery-overrides.nix to set up this build:
aitools-cli-faslscompiles and loads every FASL (compiled Lisp file) in theaitools/cliclosure through cl-nix-forge'slispDerivation, without dumping an image.- cl-nix-forge's
mkExecutablerunsasdf:program-oponaitools/cliover that precompiled tree in a fresh process. The fasls carry the same normalized store timestamp as their sources, so ASDF loads them without recompiling, and the dumped core never shares a heap with the compiler.
The result is copied, with cl-process-kit-spawn added to bin/, into
packages.default. The pinned cl-nix-forge is v0.6.1, whose .asd reader
evaluates a large .asd such as aitools.asd within Nix's default
max-call-depth; see Benchmarks.
Test layout¶
t/unit/<context>/ domain and application specs with fake dependencies
t/integration/ the structure test, gitignore parity with git,
real-filesystem adapters, crash recovery, CLI round trips
t/perf/ allocation tests
t/support/ JSON assertions and the store fault-injection adapter
t/e2e/ the built binary against the shell commands it replaces
(AITOOLS_E2E_BINARY names the binary; otherwise the
harness builds one)
The e2e properties compare the delivered binary with in-process dispatch on generated inputs. They also check generated envelope keys, schema versions, and error codes against command schemas.
Tests use cl-weave (describe, it, expect); no other test framework is
used. t/support/store-fault-injection.lisp binds the store's fault hook so
that a named step of the write protocol can throw (an in-process model of a
crash that still releases the flock), signal an I/O error, or end a forked
child process outright. The recovery tests use it to stop a write after each
step and check the next run's recovered result.
The component lists¶
Each context's ASD (ASDF system definition) under packages/ owns its library
and test systems. Context ASDs define aitools/test-support/<context> systems
for helpers shared across test contexts.
aitools.asd loads those ASD files and
composes the root systems; it also owns the shared data system and CLI
composition root. The production and test components are:
- library files (
domain/,application/,infrastructure/), relative to each context'ssrc/(for examplepackages/feature/env/src/), in that context's ASD. The rootaitoolssystem depends on the context systems. - presentation files, also under the context's
src/, are registered by context ASDs and loaded throughaitools/cli. - data files, relative to the repository's
data/, are listed in the sharedaitools/datasystem inaitools.asd. They load before the library systems into the sharedaitools.datapackage. - test files, relative to
t/, are listed underaitools/test/<context>in their context ASDs. Shared package and support files live inaitools/test/base; shared, structural, integration, and end-to-end tests live inaitools/test/shared. The rootaitools/testsystem discovers registered context systems dynamically.aitools/test/basedepends on bothcl-weaveandcl-weave/spec, so every context can write specification checks (defspec,it-spec) without declaring either system.
Each .lisp file under t/ must be a component of exactly one test system.
The registration check excludes t/**/fixtures/, t/perf/,
t/integration/structure-budget-baselines/, and
t/integration/structure-context-allowances/. The two pidfd files
t/unit/process/pidfd-test.lisp and t/integration/process-pidfd-test.lisp
may be unregistered on hosts other than Linux x86-64 or Linux arm64.
The contexts appear in load order: core kernel, protocol, workspace, text,
store, then feature search, inspect, journal, edit, process, org, env, md,
util, and net. A context loads after every context whose application package it
calls: journal before edit (edit registers its tx rebase replayers with
journal), inspect before edit and edit before util.
To add or move context library or presentation files, edit that context's ASD.
Update aitools.asd when adding shared data or changing root system
dependencies. To add or move context tests, edit that context's
aitools/test/<context> components in its ASD. Shared test components belong
in aitools-test-system.lisp.
Adding a command¶
- Put the logic in the owning context: pure rules in
domain/, the flow inapplication/as a function that accepts:on-ok,:on-partial, and:on-errorcontinuations, then calls exactly one with the result fields. -
In
presentation/, define command builders and schemas, then pass command declarations toaitools.protocol.application:register-command-declarationsfromregister-<context>-commands (registry dependency-value):(aitools.protocol.application:register-command-declarations registry (list (aitools.protocol.application:define-command "doc.get" (:group "doc" :command-builder #'%get-command :schema (%schema "doc.get")))) dependency-value)define-commandtakes the command name and its options. Its command builder receives the dependency value and produces the cl-cli command;register-command-declarationsapplies the declaration's group and schema. 3. For a new feature context, define its dependency constructor andaitools/cli::define-context-command-registrationform inpackages/feature/<ctx>/src/composition/context-registration.lisp. Pass the context name,register-<context>-commands, and the constructor. Existing contexts use their own registration file; update the constructor when a command needs new effects. Each dependency constructor returns acl-boundary-kitboundary context and attaches capabilities withboundary-context-with. Infrastructure supplies production adapters; application flows retrieve capabilities withboundary-context-require, and tests provide fakes under the same keys. The registration macro stores the constructor without inspecting it or its result; the composition root passes the returned context to the registration function unchanged. 4. Each command builder returns a cl-cli command with a handler. The handler returns a command result for dispatch by calling the application flow throughaitools.protocol.application:call-with-command-result/k. That function returns the command result produced by the flow's one continuation. If the flow needs a new effect, add the capability it needs to the boundary context. Production constructors assemble production boundaries; tests provide fakes for the same capabilities. 5. Put static tables shared across files or consumed by reference generation indata/<layer>/<context>/*-data.lisp. Keep computed values and behavior in their owning layer. 6. Add specs undert/. List production files in the context's ASD components and tests in itsaitools/test/<context>system. Shared tests go inaitools-test-system.lisp. Regenerate the reference when a command schema changes.
Regenerating the reference¶
The command index and context pages under Commands,
the error table in Errors, and the correspondence
table in Using aitools from an agent are generated. The
correspondence table uses source data from
data/domain/protocol/correspondence-table-data.lisp.
Regenerate them after changing a command schema, the error catalog, or
data/domain/protocol/correspondence-table-data.lisp:
sbcl --script docs/tools/generate-reference.lisp
sbcl --script docs/tools/generate-reference.lisp --check
The --check form fails when generated text is stale without rewriting files.
It needs the same CL_SOURCE_REGISTRY as run-tests.lisp. It loads
aitools/cli and calls each context's register-<context>-commands into a
fresh registry. It rewrites marked regions and the generated context pages.
Review the diff before committing.