Skip to content

Integration tests run as four parts and an isolation gates part, each on its own stack - #290

Merged
zlareb1 merged 1 commit into
mainfrom
ci/integration-shards
Nov 6, 2026
Merged

zlareb1 merged 1 commit into
mainfrom
ci/integration-shards

Conversation

@zlareb1

@zlareb1 zlareb1 commented Nov 6, 2026 •

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

Changelog entry (one or two sentences a user of Loom can read without the diff; the release pull request collects these into the release notes):

...

Why

pytest integration (ClickHouse service) was the longest job on main: 54 to 62 minutes for pytest tests/integration, then 8 minutes for the tenant-isolation gates against an auth-on server, after 2 minutes of setup. The tests wait on refresh cycles, lease lapses and the server far more than they use the runner's CPU, so the suite splits across runners with little lost to setup.

The job is now a matrix of five parts. Each part has its own runner, ClickHouse, migrations and extractor:

  • Parts 1 to 4 each run a quarter of pytest tests/integration, chosen by LOOM_TEST_SHARD=k/4, against an auth-off server and an S3 store of their own.
  • The isolation gates part runs the provider staging tests, the isolation gates against the auth-on server, and the analyzer corpus. Those three steps were the tail of the old job. It boots only the auth-on server, since nothing in it reads the auth-off server or the S3 store.

tests/_shards.py does the split, called from tests/conftest.py, so LOOM_TEST_SHARD splits whatever suite pytest collected. It deals whole files, heaviest first by test count, to the lightest part. Whole files keep every module-scoped fixture in one part. The split depends only on the collected file names and counts, so the four parts cover every collected test exactly once. The conftest deselects the other parts' tests, which pytest reports as deselected. A malformed or out-of-range LOOM_TEST_SHARD is a usage error (exit 4), never a silent empty run.

Separate stacks are safer here than pytest-xdist against one server. The destructive tests stop merges or run OPTIMIZE, and other tests change runtime overrides, so a test running beside them on a shared ClickHouse could see their effects. In separate stacks the parts share nothing.

Each part's server logs upload as server-log-<part> (server-log-isolation for the gates part), and the parts list their 20 slowest tests (--durations=20), so the next split can be checked against real times. The job timeout drops from 90 to 45 minutes.

Scope and risk

CI configuration, the root test conftest, a split helper with a unit test (tests/unit/test_test_shards.py), and the testing docs. No server code changes. Without LOOM_TEST_SHARD a local run collects and runs everything, as before.

The split is weighted by test count, not time, so parts can differ in duration. This PR's run measures the spread. If one part runs far longer than the others, the next step is to weight by the --durations the parts print.

Compatibility, rollout and rollback

  • Wire: none.
  • Operator steps: none. No required status check names the old job.
  • Rollback: revert.

Tests

  • tests/unit/test_test_shards.py: the spec parser accepts k/n and refuses out-of-range or malformed specs; keep deselects the other parts' files, leaves a run without the variable whole, and turns a bad spec into pytest.UsageError. Every file lands in exactly one part. The parts stay within one file's weight of each other. The split ignores input order.
  • Against the real collection (pytest tests/integration --collect-only on a migrated private stack): 1,942 tests in total, and the parts hold 486, 486, 485 and 485. They sum to 1,942. LOOM_TEST_SHARD=5/4 exits 4.
  • test_test_inventory.py, test_doc_links.py, test_public_copy.py, test_agent_instructions.py and test_package_contracts.py pass.

Measured on this PR's CI run at 7452425, the parts' totals add up to main's single run exactly:

part 1 part 2 part 3 part 4 main, one job
passed 469 466 456 481 1,872
failed 0 2 0 3 5
skipped 17 18 28 1 64
xpassed 0 0 1 0 1
pytest step 15:36 12:01 10:05 17:08 61:42
job 17:13 13:34 11:39 18:44 63:38

Neither of these two timings includes the analyzer corpus, which then still followed the failing gates and was skipped. The isolation gates part took 10:01 at 7452425, which still started the auth-off server and S3 store, and 10:41 at e4de5c2, which does not. The auth-on pass inside it took 8:00 and 8:52, against 8:01 on main in run 41961513217, the last main run whose suite passed. In run 42190790932 the suite failed, so main skipped the auth-on pass and the analyzer corpus: its 63:38 leaves them out.

One behaviour changes: the provider staging tests, the auth-on gates and the analyzer corpus now run whatever the suite or the check before them did. In the isolation gates part, the end-user issuer, the extractor, the analyzer corpus and the auth-on boot run unless the migrations failed or the run was cancelled (!cancelled()); the boot also needs the issuer and the extractor, whose settings the server reads, and the gates run only when the auth-on server booted. In every part, the issuer and the extractor run unless the migrations failed or the run was cancelled; the numbered parts' boot, S3 store and pytest steps keep the default, so any failure before them skips them. Before, a failure in the suite skipped the auth-on gates and the analyzer corpus, and a provider staging failure skipped everything after it. On main today the three leakage cases would also skip the analyzer corpus. Run 42237393836 at a4e2970 shows the new order: the gates fail on the three leakage cases, and the analyzer corpus runs after them. The corpus fails test_shapes_file_matches_builders (19 new shapes, 1 gone), a drift on main the skipped step had hidden, since fixed by regenerating tests/analyzer/shapes.txt on main. The longest part sets the job's wall clock at 18.7 minutes, down from 63.6.

The five failures are the ones main already has. In run 42190790932, main's pytest step fails these five with the same assertions:

  • the three test_cross_principal_leakage.py::test_every_read_op_against_a_collection_leaks_nothing cases (429s on the @me namespace);
  • test_knowledge_inspect_ingest.py::test_backlog_a_missing_extractor_and_missing_access_are_kept_apart;
  • test_namespace_tune_documents.py::test_tune_cuts_the_documents_again_and_writes_nothing.

The isolation gates part hits the same three leakage cases against the auth-on server. This PR changes no server code or test.

AI assistance in the code (leave one; writing this description with AI is fine):

  • AI-generated (an agent wrote most of the diff): Claude Code. The author checked the collected counts per part and the CI step conditions.

  • I can explain every line of this diff and how it interacts with the rest of Loom.

Checklist

  • make format-check, make lint, make typecheck and make test-unit pass; the integration suite passes if server behaviour changed.
  • Generated files are regenerated in this PR, not by hand.
  • A new migration is additive and numbered after the latest on main; no merged migration is edited.
  • A behaviour change to any file a plugin ships bumps both plugin manifests' version.
  • The frontend builds and its tests pass, if frontend/ changed.
  • Docs under docs/ describe the system as it now is.
  • Repository text has no dates, people, host names, internal namespaces, ticket or decision numbers.
  • Commits are signed off (git commit -s).

🤖 Generated with Claude Code

@zlareb1 zlareb1 changed the title The integration job runs as four parts of the suite and an isolation part, each on its own stack Integration tests run as four parts and an isolation gates part, each on its own stack Nov 6, 2026
@zlareb1
zlareb1 force-pushed the ci/integration-shards branch from 0e15a42 to 0b1ea32 Compare November 6, 2026 15:44
… on its own stack

One runner took 62 minutes for the suite and 8 for the auth-on gates. LOOM_TEST_SHARD=k/n keeps the k-th part, whole files dealt by test count (tests/_shards.py, called from tests/conftest.py). The isolation gates part runs the provider staging tests, the auth-on gates and the analyzer corpus as independent checks.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signed-off-by: zlareb1 <[email protected]>
@zlareb1
zlareb1 force-pushed the ci/integration-shards branch from f5ee233 to b02b3f3 Compare November 6, 2026 17:04
@zlareb1
zlareb1 merged commit a4ccc24 into main Nov 6, 2026
25 of 28 checks passed
@zlareb1
zlareb1 deleted the ci/integration-shards branch November 6, 2026 17:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant