Testing

kōjō’s tests come in layers, from unit tests that need only Go to end-to-end scenarios against a running local stack. This page lists each layer with the command that runs it and what it needs, then the fakes and mocks the tests are built on and the model recordings the mock provider replays. It is for people who change kōjō.

Test layers

Put a test in the lowest layer that can catch the mistake.

Layer Command Needs
Unit make test, make race Go only. No network.
Security make test (the suite is in the default build) Go only
Integration make integration Docker, or KOJO_TEST_DATABASE_URL
Driver conformance make conformance DRIVER=<driver> the driver’s backend
Chart make helm-lint, make helm-test helm; Docker, kind and Go
Skill evals make eval Docker
End to end make e2e a running local stack

Unit tests

make test runs go test ./.... Unit tests use no network: a surface tests against a fake of its forge or of Slack, model calls go to the mock provider, and the store is the in-memory one. The eval of the built-in skills also runs here, on the recordings under testdata/recordings/evals and the local fake driver.

Two build tags exist. integration marks the suites that need something outside the process: Postgres, a Docker daemon, a kind cluster, the sbx CLI. e2e marks the end-to-end scenarios, which need a running stack. make all runs neither, but make vet type-checks both and make lint-integration lints both.

The security suite

test/security holds the adversarial tests that need the whole factory. They run in the default build, so make test runs them, on the in-memory forge, a scripted model and the fake driver’s local mode.

Test What it checks
TestPromptInjectionInAnIssueStaysData Instructions planted in an issue reach the model as data, not as instructions.
TestUntrustedRequestCannotReachASkillThatWrites A request from someone who may not trigger writes never reaches a skill that changes the workspace.
TestSubagentIsHeldToItsSkillAndItsWorkspace A subagent cannot use a tool its skill does not list, or a path outside its workspace.
TestOnlyKojoBranchesCanBeWritten Writes to a branch that is not kojo/* are refused.
TestAPersonsBranchIsWrittenOnlyAsItsPullRequestsHead A branch outside kojo/* is written only as the head of the open, same-repository pull request the write names, at the head the core read: not without both, not for another branch, a closed pull request, a fork’s, or the default branch.
TestDryRunsAndDraftsStayInBounds A dry run is refused on a repository that is not enabled, and a skill draft never runs outside a dry run.
TestEvidenceCannotWidenASkillOrActivateAProposal Lessons and check output that carry instructions reach the proposing model of self-improvement only inside a fence, cannot make a proposal widen the skill, and nothing in the loop activates a proposal.
go test ./test/security/...

Sandbox escapes, blocked egress, “no secret inside the sandbox” and a clone credential that reaches git’s fetch only are covered by the driver conformance suite; the exact rule of what a read-only credential is set on is covered by the tests of internal/proxy, and its sbx counterpart by internal/sandbox/sbx. Security describes the trust boundary these tests defend.

Integration tests

make integration runs scripts/integration.sh, which runs go test -tags integration -count=1 -timeout 30m ./.... Arguments to the script replace ./....

The Postgres store suite reads KOJO_TEST_DATABASE_URL. When it is not set, the script starts pgvector/pgvector:0.8.7-pg17 on a free loopback port, creates the vector extension, points the variable at it and removes the container afterwards. KOJO_TEST_POSTGRES_IMAGE overrides the image.

make integration
KOJO_TEST_DATABASE_URL='postgres://kojo:kojo@127.0.0.1:5432/kojo_test?sslmode=disable' \
  bash scripts/integration.sh ./internal/store/...

A suite whose backend is missing skips itself and names the missing capability.

The conformance suite

test/conformance is the one suite every sandbox driver must pass. It covers create, exec, copy and destroy; exit codes; environment; stdin; streaming; a timeout that kills the command; the output cap; workspace persistence across a new driver instance; egress allow and deny, through the proxy and directly; credential placeholder to injection; no secret visible inside the sandbox; and TTL cleanup. A case the driver cannot run is skipped with the missing capability named.

make conformance runs scripts/conformance.sh:

DRIVER Runs Needs
fake (default) the default build, no tag nothing
docker -tags integration, the tests named TestDocker* a Docker daemon
k8s -tags integration, the tests named TestK8s* or TestKind* the cluster of make dev-kind; KUBECONFIG defaults to test/kind/.kubeconfig
sbx -tags integration, the tests named TestSBX* or TestSbx* the sbx CLI, signed in, on a host with hardware virtualization

So that a skip never counts as a pass, the script fails when no test of the driver ran, fails when a driver’s whole test was skipped, and lists the cases that skipped themselves with their reason.

make conformance
make dev-kind
make conformance DRIVER=k8s

On the kind cluster the suite uses the gvisor RuntimeClass by default; KOJO_K8S_RUNTIME_CLASS=runc runs it on plain containers. The driver’s own integration tests run with:

KOJO_K8S_KUBECONFIG=$PWD/test/kind/.kubeconfig go test -tags integration ./internal/sandbox/k8s/

test/kind/README.md describes the cluster: a node image with gVisor, Cilium as the CNI, the pinned Agent Sandbox release and two RuntimeClasses. test/kind/versions.env pins every version.

kind nodes are containers and cannot start Kata VMs, so on kind the suite runs with gVisor and with runc. On sbx the egress and credential cases run in TestRealEgressAndCredentials (internal/sandbox/sbx, tag integration) against public hosts, because sbx’s proxy cannot reach the suite’s throwaway upstream.

Chart tests

  • make helm-lint lints and renders the chart with the default values, each charts/kojo/ci/*-values.yaml and each charts/kojo/ci/render/*-values.yaml, and checks that the vendored Agent Sandbox manifest is the release pinned in test/kind/versions.env. It then runs scripts/helm-config-check.sh, which renders the ConfigMap for each values file and runs kojo config validate on it, so a chart that renders a kojo.yaml the binary rejects fails here. Last it runs go test ./test/chart/, which renders the chart with helm template and checks the objects it makes (the kojo-proxy replicas, their headless admin Service, readiness probe, PodDisruptionBudget, shared CA and network policy). go test ./... runs that package too, and skips it, saying so, when helm is not installed.
  • make helm-test creates or reuses the kind cluster kojo-ct, builds ghcr.io/xavidop/kojo:ci, loads it, applies the vendored Agent Sandbox release, and runs ct lint and ct install from the chart-testing image, once per ci/*-values.yaml, followed by helm test. scripts/helm-test.sh --delete deletes the cluster. That cluster has no gVisor and no Cilium: it checks that the chart installs and kōjō starts, not sandbox isolation.

Skill evals

make eval builds the binary and runs kojo eval --all --local -f evals/kojo.eval.yaml: every fixture under evals/fixtures, in the CLI’s own process, with an in-memory store and no forge (a case that needs issues or pull requests seeds its own in-memory one). evals/kojo.eval.yaml sets the mock provider on testdata/recordings/evals, so the run needs no key and no network, and the docker driver with the image alpine/git, so it needs a Docker daemon. It exits 1 below a pass rate of 1 (seed.activation.min_eval_pass_rate in that file).

make eval
make eval SKILL=fix-bug
make eval EVAL_ARGS="--min-pass-rate 0.5"

Only skills with fixtures are evaluated; every built-in skill has them. The report has one line per skill and one per case, and starts like this:

build-feature: 100% passed (1 case(s), $0.00)
  pass  shout-flag  1 attempt(s)  $0.00  similarity -
daily-digest: 100% passed (1 case(s), $0.00)
  pass  one-day  1 attempt(s)  $0.00  similarity -
dependency-review: 100% passed (1 case(s), $0.00)
  pass  mirror-upgrades  1 attempt(s)  $0.00  similarity 100%

Evals shows the whole run.

To evaluate on a running server instead, call kojo eval fix-bug with KOJO_SERVER and KOJO_TOKEN set. Evals explains fixtures and pass rates.

End-to-end scenarios

test/e2e holds whole flows through a running kōjō, its forge, its chat surface and its alert source, asserted on from the outside. The tests build only with the e2e tag and run against a stack that is already up:

Scenario What it checks
TestIssueToDraftPullRequest A maintainer mentions the bot on an issue; the session succeeds; a draft pull request from a kojo/ branch changes lib/mean.sh and tests/mean_test.sh; the bot comments on the issue; every step and audit entry is there.
TestSlackMentionGetsThreadedReply A mention through the Slack mock gets one reply, in the thread.
TestDayTwoChangeAppliesLiveAndRollsBack A budget change through the API is active at once and rolls back, without a restart.
TestCampaignAcrossRepositories A campaign over four copies of the demo repository, with a pilot of 2 and 2 at once: a confirmation below the estimate is refused; it pauses after the pilot and ends done once continued, never with more than two sessions open; each repository gets a draft pull request that links the campaign’s page, and the campaign shows each pull request’s state. A second campaign is cancelled while its sessions run, and they stop. A repository that could not start fails, and a retry runs it.
TestSentryAlert A signed event_alert delivery from Sentry starts a session with trigger alert, which reads the issue from the Sentry mock and opens a draft pull request whose commit is Fix Sentry issue <short ID>, never merged although the repository’s merge policy is auto_merge. The same delivery again starts nothing, a wrong signature gets 401, and a project in report mode opens no pull request.
TestConfigExportToFactory kojo config export --factory writes a repository’s dashboard skill, merge policy and schedule as .factory/ files with their modes, leaves trigger_permission out of factory.yaml, reports a second run unchanged, and refuses to overwrite a hand edit without --force. It builds the kojo binary of the working tree.
TestCommitsToAPersonsPullRequest A second Forgejo user opens a pull request on the demo repository; the maintainer adds the kojo:commit label and mentions the bot there. kōjō commits to that person’s branch on top of their commit instead of opening a pull request of its own, the pull request stays theirs, open and as it was, the audit log says the label decided and who added it (read from Forgejo’s timeline), and the bot comments the commit.
TestSettingsEditedInKojoGoToTheRepository The demo repository’s merge policy is moved into .factory/factory.yaml through the bot’s pull request, which the maintainer merges. An edit of the policy through the API is then answered 202 with a pull request on the file and changes nothing live; a second edit updates the same pull request; once merged, the push makes the new value live. The test removes the file again through a pull request.
make dev-sbx
make e2e

make e2e runs scripts/e2e.sh, which runs go test -tags e2e -count=1 -timeout 20m ./test/e2e/.... The tests find the stack through the KOJO_E2E_* variables that the dev scripts write to .kojo/e2e.env. For the kind stack the file also names the cluster, and the script forwards the three services to local ports while the tests run. Arguments to the script go to go test, for example bash scripts/e2e.sh -run Slack -v. The script fails when the stack is not described, when a scenario skipped itself and when none ran.

Models in these runs are the recordings of testdata/recordings/dev. With live models the campaign that is cancelled is cancelled at once, since no recording keeps its sessions busy.

CI runs the scenarios on every pull request, against the compose stack in the docker mode and against the kind stack, where sandboxes are Agent Sandbox pods on gVisor behind the Cilium egress policies. The nightly workflow runs them on the kind stack with live models.

Fakes and mocks

What Where Use
Fake sandbox driver internal/sandbox/fake fake.New(): sandboxes in memory, Exec answers what a test scripted. fake.NewLocal(dir): plain directories, and Exec runs the command on the host. Neither isolates anything.
In-memory forge internal/surfaces/forge/forgetest Repositories, issues, pull requests, permissions, branch protection and checks, for the core’s tests.
In-memory store internal/store/memory Unit tests and kojo eval --local. Nothing is persisted.
Slack mock test/slackmock Serves the part of the Slack Web API the adapter calls under /api/, plays users, and has a control API under /mock/.
Sentry mock test/sentrymock Serves the two calls of Sentry’s API that kōjō makes, the organization and an issue, for one organization and token. Every numeric issue ID exists, unresolved, with 3 events from 2 users and the short ID E2E-<id>.
Dashboard on demo data test/dashdev go run ./test/dashdev serves the dashboard on http://localhost:8088 with an in-memory store and demo data, to work on the web UI. -listen changes the address.
Mock model provider internal/models Replays recordings. See below.
Cloud model APIs internal/models/modelstest HTTP fakes of Azure OpenAI’s v1 API, Bedrock’s Converse and InvokeModel, and Vertex AI’s generateContent with a token endpoint for a generated service account key, for the tests of the azure, bedrock and vertexai providers and their doctor checks.

The Slack mock’s control API:

Request Effect
POST /mock/mention A user mentions the bot: {"channel","user","text","thread_ts"?}.
POST /mock/dm A direct message: {"user","text","thread_ts"?}.
POST /mock/click A click on a button: {"channel","ts","value","user"}.
POST /mock/users Adds a user: {"id","name","real_name","email"}.
POST /mock/redeliver Delivers an event again: {"event_id"}.
POST /mock/reset Forgets everything.
GET /mock/messages What kōjō posted; channel and thread_ts filter.

Recordings

The mock provider is a Genkit model that replays YAML recordings. models.recordings in kojo.yaml names the directory; every .yaml file under it is a list of recordings.

- purpose: subagent:fix-bug
  match: "lib/pages.sh"
  turns:
    - tool_calls:
        - { name: read_file, input: { path: lib/pages.sh } }
    - text: "The page count is an integer division, which rounds down. It has to round up."
- purpose: judge:fix-bug
  match: "lib/pages.sh"
  turns:
    - json: { pass: true, unmet: [], feedback: "" }
  • A recording is chosen by purpose (orchestrator, subagent:<skill>, judge:<skill>, risk; a trailing * matches any suffix) and, when set, by match, a substring of the prompt. Recordings with a match are tried first.
  • The turn replayed is the number of model replies already in the conversation, so replay is stateless and survives a resumed session.
  • repeat_last: true answers with the last turn once the turns are used up. Without it, a call past the last turn is an error.
  • A call with no matching recording is an error that names the purpose. A session treats it as a setup error and fails without a retry.

Two variables change this, in any process that builds the model gateway:

Variable Effect
KOJO_LIVE_MODELS=1 Ignores models.recordings and calls the real providers of the tiers.
KOJO_RECORD=1 With live models and models.recordings set: writes what the providers answer under <recordings>/recorded/, one file per session and purpose.

make record records the evals. It needs ANTHROPIC_API_KEY, and it costs what the calls cost:

export ANTHROPIC_API_KEY=...
make record SKILL=fix-bug

It sets both variables and runs kojo eval --local with evals/kojo.record.yaml, which is the eval config with real model tiers and models.recordings: out/recordings/evals. The answers land under out/recordings/evals/recorded/, which git ignores. Nothing replays them from there. Read each file like code and make sure no key or token is in it; a recording holds what the model said. Then move the ones you keep into testdata/recordings/evals/, with a match that selects them.

The repository has two sets of recordings:

Directory Replayed by
testdata/recordings/evals make eval, and the eval of the built-in skills in make test
testdata/recordings/dev the local stacks and make e2e
Scroll to move. + - zoom, 0 fit, Esc close.100%