Testing
Where Karyo's tests live, which runner finds them, what each kind proves, and which workflow runs
them. A pull request runs none of them: its CI proves only that Karyo builds and starts
(the delivery pipeline). The nightly workflow runs
every suite below each night on main.
Derived from the source tree, config/test-runner-contracts.json and .github/workflows/nightly.yml.
Backend tests are centralised in the aggregator
| Location | Coverage |
|---|---|
services/karyo-app/src/test |
Assembled application, domain contracts and fixtures |
libs/karyo-license/src/test |
Licence compatibility library |
services/inventory-service/karyo-inventory-ext-example/src/test |
Inventory extension example |
Almost every backend test lives in one module, and the great majority of the Kotlin sources there
are @QuarkusTest classes, each of which boots the assembled application. ./gradlew test runs
the whole suite - core and engine modules together - with three sets reported as skipped: the four
Pact provider tests, which need a broker, when none is named (contract testing),
the nine Keycloak realm classes, which run in a task of their own (realm tests), and
the two live judgment checks, which need a TypeSafe key (the live judgment check).
At the Karyo 2.0.0 release the engine suites are ordinary files of this
test source set
(services/karyo-app/src/test), not a graft from elsewhere: the crossdock/, forecasting/,
monitors/, simulation/, slotting/, streaming/, threepl/ and wave/ packages test the
engine modules against the same assembled application as everything else, and the smaller
historical packages test the public -api contracts of those engines.
Why, and what it costs
No document explains the arrangement; it follows from @QuarkusTest. A Quarkus test boots the CDI
container, and a -core module in isolation is not a bootable application: it has no aggregated
extension set, no datasource, no Flyway locations, and its SPI dependencies are unsatisfied because
the implementing beans live in modules it must not depend on. Testing one module in isolation would
mean that module providing fake implementations of every contract it consumes. Testing it in the
aggregator means testing it against the real ones. For a system whose central risk is cross-module
interaction, that is the more valuable test.
The costs are real and visible in the build:
- Memory. Every application start loads the application's classes again, and a JVM never
returns the Metaspace and native memory of an earlier start, so a test JVM's size follows the
number of starts it makes, not its heap.
services/karyo-app/build.gradle.kts,tasks.withType<Test>, forkEverydiscards the JVM every 40 classes to bound that, and the same block gives it a 2 GB heap, the serial collector, C1-only compilation and caps on Metaspace, code cache and direct memory. Measured on the 52 inventory classes, one JVM peaked at 3.5 GB resident with the earlier 5 GB heap and at 2.2-2.4 GB with these settings, every test passing in the same wall time; with all 52 classes in one JVM, Metaspace grew to 1171 MB over seven starts. The worst 40-class fork makes about nine starts, about 1.5 GB of Metaspace, so the cap is 2g and a test JVM is up to about 4 GB resident (about 2.4 GB typical). - Application starts. A test JVM starts the application once for each distinct test profile
and set of restricted test resources it meets, and a fresh PostgreSQL container with it. About 37
classes carry one of those. Quarkus's own class orderer, which it enforces and which refuses to
be replaced, runs the classes of one profile together, so each starts once per JVM. Quarkus
compares profile classes, not their overrides, so classes that need the same overrides share one
profile class (every demo class names
DemoWithHistoryProfile). - Feedback time. No module can be tested alone, so any change re-runs against the full application.
- Extractability. ADR 0006 and
ADR 0007 keep modules extractable by forbidding
foreign
coredependencies and cross-boundary foreign keys. The test suite is the part that would not travel: an extracted module would have no tests of its own. - Failure legibility. One failed Quarkus boot can skip most of the suite. Read the skipped count as well as the failures.
Runner discovery
config/test-runner-contracts.json is shared by the root build.gradle.kts, both Vitest configs and
both Playwright configs, so discovery rules are not forked into prose or a second config. Five
contracts cover the ordinary suites:
- gradle: prefixes
buildSrc/,libs/,services/, path segment/src/test/, withrequire_unfilteredandrequire_junit_platform. - playwright: every spec file under
tests/e2e/tests/, withforbid_skipsenforced by a custom reporter (tests/e2e/fixtures/no-skipped-tests-reporter.ts) andforbid_only. - vitest-mobile and vitest-web: the two front-end trees.
- node-test: every
*.test.tsfile undertests/e2e/fixtures/, the fixture helper tests the nightly run executes throughnpm run test:helpers(.github/workflows/nightly.yml,jobs.frontend.steps: Browser helpers and collection (no live stack)) with the Node.js built-in test runner (node --test). A helper test that runs a script withspawnSync("bash")under aPATHof symlinked tools hangs unless it passesstdio: ["ignore", "pipe", "pipe"](tests/e2e/fixtures/node-runtime-preflight.test.tsdoes).
The same file's operational_sources list owns every operational source, its runner and the
reason it is kept out of the ordinary suites. The licence utility uses the operationalTest
Gradle task; browser proofs use tests/e2e/playwright.operational.config.ts and their explicitly
commissioned targets. None runs in CI.
The realm suites are not operational sources. They stay ordinary files of
services/karyo-app/src/test, so the gradle contract still owns them and test still
discovers and compiles them; a condition skips them there (realm tests).
Contract testing
Pact provider tests exist for four providers (auth/pact, inventory/pact, layout/pact,
product/pact under services/karyo-app/src/test/kotlin/com/karyo/), with consumer tests under
frontend/web/src/test/pact/. Each provider test
fetches its pacts from the broker named by pact.broker.url, and runs only when one is named
(services/karyo-app/src/test/kotlin/com/karyo/auth/pact/AuthPactProviderTest.kt, AuthPactProviderTest). The
condition is @RequiresPactBroker
(services/karyo-app/src/test/kotlin/com/karyo/app/pact/RequiresPactBroker.kt): with no broker
named, JUnit skips the class and reports why; with one named, a broker that cannot be reached, or
that holds no pact for the provider, fails the test. None of the four ignores I/O errors or an
empty broker, because a verification that passes when its target is unreachable is worse than no
verification.
The Gradle test task forwards pact.broker.url into the forked test JVM
(services/karyo-app/build.gradle.kts, providers.systemProperty("pact.broker.url")). A -D on the Gradle command line does not reach a
forked Test JVM, so without the forwarding a named broker would never enable the tests.
The four therefore run in one place: the nightly test job (.github/workflows/nightly.yml, jobs.test). It
starts an ephemeral broker, generates the console's consumer pacts with Vitest, publishes them and
fails unless there are exactly four, and names the broker in the same Gradle invocation that runs
every other backend test, so they share its compile but boot an application and database of their
own. The pact-verify job (jobs.pact-verify), which keeps the check name Pact verification,
then reads that job's result files and the pacts it published, and fails unless the number of
interactions verified equals the number published. In any local run that names no broker, the
four are reported as skipped, not passed.
Realm tests
Nine classes run against a real Keycloak and a shipped realm: the import, bootstrap, upgrade and
scope parity of the production realm, the dev realm's claim mappers, the agent realm's
authorization-code flow, sign-in events, enrolled-identity enforcement, the access migration and
access provisioning. Each starts at least one Keycloak container of its own, about 80 s of class
time in all, and few changes touch what they prove. So each carries @RealmTest
(services/karyo-app/src/test/kotlin/com/karyo/app/auth/RealmTest.kt), which tags it realm
and enables it only when karyo.realm-tests is true:
testreports the nine as skipped, with the reason, and boots nothing for them. It skips them by condition rather than by a tag filter, because the root build forbids filters ontest(build.gradle.kts,gradle.taskGraph.whenReady)../gradlew :services:karyo-app:realmTestruns them: the same source set and test JVM settings, therealmtag selected and the property set (services/karyo-app/build.gradle.kts,realmTest). It needs a container runtime, astestdoes.- The nightly
realm-testjob runs that task (.github/workflows/nightly.yml,jobs.realm-test).
So a pull request that breaks a realm merges green, and the next nightly run reports it in the
ci-nightly issue. A pull request's Karyo starts check does import the production realm and sign
in through it, which catches a realm Keycloak cannot import or a broken browser client, but none
of the nine suites' checks. One class that starts a Keycloak stays in test:
AuthPactProviderTest, because pact-verify reads exactly four provider results from that job.
A change to a realm or to the identity code is proved by realmTest, not by ./gradlew test
alone.
The live judgment check
The judgment engine seam (ADR 0064)
is tested without a key or a network. The question builders are pinned by golden files in
services/karyo-app/src/test/resources/judgment, the answer parser is tested against shapes taken from
TypeSafe's published examples, the client runs against a local stand-in server, and every behaviour test of
a later decision class uses StubJudgmentEngine. None of that proves that a real answer parses.
One class does: TypeSafeLiveCheck sends the shared synthetic request to api.typesafe.ai three times and
asserts the typed shape, the pinned model jev-1.13.0 and that the repeats agree. It names no warehouse, so
no demo or customer row leaves the machine. It carries @JudgmentLiveCheck
(services/karyo-app/src/test/kotlin/com/karyo/ai/JudgmentLiveCheck.kt), which tags it judgment-live and
enables it only when karyo.judgment-live-checks is true:
testreports its two tests as skipped, with the reason, and boots nothing for them.TYPESAFE_API_KEY=... ./gradlew :services:karyo-app:judgmentLiveCheckruns them (services/karyo-app/build.gradle.kts,judgmentLiveCheck). Without the key the class starts and skips with the reason, so the report shows a skipped check and never a green one.- No workflow runs it: the key is the owner's. The owner ran it on 2026-10-26, and the release evidence records the model, the tokens and the answers. Repeat it when the pinned model moves.
Front-end and browser tests
- Vitest, in both front ends:
npm test(vitest run) infrontend/weband infrontend/mobilereports the current file and test counts, which move with almost every change and so are not pinned here. The nightly run executes both (.github/workflows/nightly.yml,jobs.frontend.steps: Console lint and unit tests, Floor app lint and unit tests); a pull request only builds them (.github/workflows/ci.yml,jobs.frontend). - Playwright, in
tests/e2e: 36 spec files and 100 tests, which need a running stack (scripts/run-e2e.sh). The nightly run does not raise a stack for them; it runs the fixture helper tests and collects every spec with--list(nightly.yml,jobs.frontend.steps: Browser helpers and collection (no live stack)), which proves they parse and that every fixture resolves, not that they pass.
Running the browser specs, and keeping them true
The nightly run collects the specs and never runs them, so a spec can rot unseen. Run the ones you touch against an isolated stack (selecting the deployment).
- Export the stack's identity first.
scripts/run-e2e.shprobesBASE_URL; if the probe fails it runscompose up -dwith no-p(scripts/run-e2e.sh, the$COMPOSE_CMD -f "$COMPOSE_FILE" up -dline). ExportCOMPOSE_PROJECT_NAME, both image tags andNGINX_HTTP_PORTbefore it, so a failed probe cannot start a stack under another project's name. - It provisions and removes its own users. The script creates the
e2e-suite-*users and cleans them up; it needsKEYCLOAK_ADMIN_CLIENT_SECRET, which it reads from the privatescripts/.env.prodon a local target. Itsplaywright install --with-depsstep needs root; on failure it falls back to a browser-only install, which is not a test failure. The database sweep stays off unlessKARYO_PG_CONTAINERnames a disposable container. --listprints nothing by itself. The config's reporters arehtmland the skip reporter; pass--reporter=listto see the collected tests.- Scope a locator to the thing under test. A page-wide
getByRole("row", { name })can match a second row: an order's line row carries an SKU that contains the order number once case is ignored. Use the helperordersTableRow(tests/e2e/fixtures/orders-page.ts), and scope a form'sgetByLabelcalls to its dialog. - Prove an absence with a request log. To assert that a page does not write on view, record the
requests and wait for
waitForLoadState("networkidle")(tests/e2e/tests/packing.spec.ts). A spec that checks the screen alone can pass on the buggy build by winning the race with the refetch.
The performance harness
tests/gatling is a Gatling load generator, not a test in the senses above. It is a Gradle build of
its own that the root settings.gradle.kts does not include, no runner in
config/test-runner-contracts.json finds it, and no CI job starts it. Someone runs it by hand against
a local session, and a run asserts only that no request failed. One of its simulations measures the
insight reads (forecasts, reorder simulation, flow state and projection), whose ceilings are stated in
the HTTP API surface. Its unit tests, which pin the rules
for which host a run may reach, run with ./gradlew -p tests/gatling test and need no stack. See
performance testing.
Identity tests
Synthetic @OidcSecurity identities characterize legacy resources but do not prove protocol
validation. Strict identity tests use signed access tokens against a real managed Keycloak fixture
and an in-process standards-only OIDC discovery/JWKS server. They cover signature, algorithm,
time, audience, exact issuer/subject enrollment, typed claims, role narrowing, suspension,
unlinking, resolver outage, service principals and two configured issuers with the same subject.
Repository tests use real PostgreSQL constraints for issuer aliases, cursor keys and migration
state. Browser unit tests pin PKCE state/deep-link restoration, session-only storage, refresh and
logout behavior; live Playwright remains an explicit isolated-stack check rather than a consequence
of --list.
The operational browser/floor scope proof is
organization-scope.operational.ts.
Commission a disposable localhost nginx stack through the
identity upgrade procedure
before running it. Set KARYO_SCOPE_PROOF_FIXTURE to the reviewed fixture JSON; its ScopeFixture
interface owns the input shape. Keep its password outside source control and evidence archives.
From tests/e2e, select only this proof with:
npm run test:operational -- organization-scope.operational.ts
The spec does not enroll personas, activate grants or reset the target. It checks browser record and forged-header isolation plus offline work retained for its original account; merely collecting it is not evidence of those outcomes.
Scope guard tests
Nine guards cover the consumers of the operational scope. G1 is the compiler opt-in of RawScopeAccess.
Five are JUnit tests under services/karyo-app/src/test/kotlin/com/karyo/security/guards that reflect
over the classpath and read the source tree; they boot no application. G9 is a pair of Vitest source tests,
scope-purity.test.ts, one in each front end. G2 and G7 have no test of their own: review keeps them.
config/scope-consumers.json is the registry the backend guards compare against, and a registry line
needs a reason a reviewer has accepted. The guards, what each fails on and how the registry shrinks are in
Identity and tenancy.
Convention guards
Three guards catch a convention that nothing else checks. The Gradle task reads Gradle's own project model; the two JUnit classes read the checked-in tree and boot no application.
| Guard | Fails when |
|---|---|
verifyModuleBoundaries (buildSrc/src/main/kotlin/com/karyo/conventions/VerifyModuleBoundaries.kt, wired in the root build.gradle.kts) |
a module other than karyo-app has a project dependency on a -core outside the two recorded waivers, in any configuration and however the build file declares it, or a waiver names no dependency |
CatalogueDefaultsTest (services/karyo-app/src/test/kotlin/com/karyo/auth/config/CatalogueDefaultsTest.kt) |
a default written beside the system-property catalogue disagrees with it, or a catalogue key cannot be read as its type |
DocumentTemplateAllowlistTest (services/karyo-app/src/test/kotlin/com/karyo/docstore/DocumentTemplateAllowlistTest.kt) |
a template that ships is not on the override allowlist, or an entry names no template |
verifyModuleBoundaries is a dependency of every Test task and of every check, so ./gradlew test
runs it. The two JUnit classes run with ./gradlew test like every other backend test, and they live in the
aggregator for the same reason the rest do.
Environment
Backend tests use Quarkus Dev Services: Testcontainers starts PostgreSQL (postgres:16-alpine), and
Compose Dev Services is disabled for tests so every run starts from a clean database
(services/karyo-app/src/test/resources/application.properties, quarkus.compose.devservices.enabled, quarkus.http.test-port, quarkus.datasource.devservices.*). No Keycloak Dev Service starts,
because the OIDC server URL is configured explicitly; the classes that need a real Keycloak start
one through their own test resource, restricted to the annotated class, and all of them but
AuthPactProviderTest run in the realmTest task (realm tests). Each test JVM listens on a
random HTTP port and starts its own PostgreSQL Dev Service, which is never kept for reuse, whatever
testcontainers.reuse.enable says. So suites in parallel worktrees neither race for a port nor
share a database. Classes with the same Quarkus test profile share an application and database,
so tests must use unique synthetic IDs rather than assume an empty one. A stock fixture in Business
Unit 1 keys its stock by a product it created (testProduct() in com.karyo.support), not by an
item id it invented, because stock selection matches only the item id, the Facility and the state.
Whole-database identity manifest reviews share
auth/support/IsolatedIdentityDatabaseProfile, which selects the existing current_access_test
database; CurrentAccessKeycloakIT uses it for the complete access-migration snapshot.
The same isolation lets one machine run test JVMs side by side. The Test task reads
-PkaryoTestForks (services/karyo-app/build.gradle.kts, maxParallelForks) and defaults to one.
The nightly run passes -PkaryoTestForks=3 on the nebula runner, which has 32 cores and 61 GiB of memory with no
cap, so that three Tests jobs fit on that host at once (nightly.yml, jobs.test.steps: Run every module test task).
Each JVM starts its own application and PostgreSQL, so a test must not assume any other class has
run, in this JVM or another. The Tests job measures what the suite cost - the peak memory of its
processes and containers, the test counts and every application start - and prints it in its log
(nightly.yml, jobs.test.steps: What the suite cost; scripts/ci-test-metrics.sh); read the current
figures there.
A test names its Business Unit by a number it invented, and production refuses a row for a Business Unit
with no Facility (ADR 0040). The
test classpath alone carries db/migration/common/V90000001__test_business_unit_provisioning.sql and the
request filter com.karyo.support.TestBusinessUnitProvisioner: the first time a number appears in a synthetic
token or header, or a test asks TestOrganizations.facilityOf for it, it gets a Business Unit and a fixture
Facility. No row insert provisions one, and a test of the production refusal (layout/FacilityStampingTest)
simply writes without a Facility. Any
Docker-compatible container runtime works; the nightly run's is the runner's rootless Podman, reached through a
Podman API service the job starts for itself and names in DOCKER_HOST
for the test step (scripts/ci-podman-api.sh; the reason is under "A container API of each job's
own" in the delivery pipeline). The nightly run executes the suite (nightly.yml, jobs.test.steps: Run every module test task) after starting that service and
asking it to answer (nightly.yml, jobs.test.steps: Container runtime), then removes every container the suite started, even from a
cancelled run (nightly.yml, jobs.test.steps: Remove the containers the suite started), and stops the service (nightly.yml, jobs.test.steps: Stop the Podman API service).
Related
- The delivery pipeline - every CI job, not only the test ones
- Developer onboarding - running the suites locally
- Performance testing - the opt-in Gatling harness
- Modules and boundaries - why the modules cannot be tested alone