Put the test plan in the repository

In June 2023 I opened a pull request against elastic/kibana that added no code. It moved two Google Docs into a single Markdown file inside the plugin they described, added a template for writing more of them, and deleted a file called todo. Four files, 712 lines added, three removed. It collected 112 comments before it merged eight days later (#160685).

That comment count is the whole argument. Nobody had left 112 comments on those documents while they sat in Google Docs, and nobody was going to.

Some context, because this lived in a product most people have not used. Kibana's Security Solution is Elastic's SIEM, short for security information and event management, the screen a security team watches to find out that something bad is happening on their network. Its core object is a detection rule, which is a saved query plus a schedule, run against the customer's data every few minutes and writing an alert whenever it matches. Elastic's threat research team writes several hundred of these and ships them as a versioned package that Kibana downloads and installs. Those are the prebuilt rules. From August 2022 to December 2024 I worked on the team that owned installing them, upgrading them, and eventually letting customers edit them.

Installing and upgrading a package of several hundred rules has a lot of states. The package is present or absent, its rules are installed or not, a newer version exists or does not, and the customer's own edits either survive the upgrade or get overwritten. That is why it needed a plan.

What a plan written for review contains that a checklist does not

A test checklist is a list of things somebody intends to verify. It is written for the person who wrote it, and it stops being true without anybody noticing.

The template we settled on forced four things before any scenario appeared.

A terminology section, because half of a good scenario is naming. Ours defined the package, the registry it comes from, what "the real package" meant as opposed to mock rule assets written straight into an Elasticsearch index by the test setup, and what an air-gapped environment was. Once those words existed, every scenario below got shorter.

An assumptions section, for the things a scenario silently depends on. Which license tier the feature requires. Which privileges the user needs. Whether the registry is reachable unless a scenario says otherwise. These are the conditions that can change and invalidate the plan without a single word of the plan changing.

A non-functional requirements section. This is where the plan stopped being a list of clicks. Ours recorded that the workflows had to work with a package containing up to 15,000 historical rule versions, a ceiling imposed by Fleet, the part of Kibana that manages packages, and that Kibana must not die of an out-of-memory error while installing one.

Then the scenarios themselves, written in Gherkin, the Given/When/Then format that the Cucumber testing tool made common. Each one carried a line saying how it would be automated and at which layer. Scenario titles were Markdown headings, since the file had to read as a document too.

#### Scenario: Large package can be installed on a small Kibana instance

Automation: 1 integration test.

Given the package is not installed
And the package contains the largest amount of historical rule versions (15000)
And the Kibana instance has a memory heap size of 700 Mb
When user opens the Rule Management page
Then the package is installed without Kibana crashing with an Out Of Memory error

Under that scenario the plan carried a note saying that 600 Mb crashed Kibana every time, that 700 Mb survived 100 iterations on the CI job that reruns a single test over and over to catch flakiness, and where to find the build that showed it. That note is an empirical finding about the product, discovered while writing a test, and it now lives in the repository where the next person to touch package installation will trip over it.

The automation line is the part I would keep if I could keep only one. A scenario that says "8 integration tests with mock rules: 4 examples below times 2, because we split checking the API response from checking the installed rules" is a scenario someone has thought about. A scenario with no such line is a wish.

Gherkin's Examples table did more work than I expected. Several of our scenarios were the same flow run against two package shapes, with historical rule versions and without, and against two generations of the API, the legacy endpoint and its replacement. Four rows in a table, one scenario body. Here is the shape, reconstructed rather than copied, since the real ones carried more setup:

Scenario Outline: All prebuilt rules can be installed

Automation: 4 integration tests with mock rules.

Given the <package> package is available in the registry
When the user installs all prebuilt rules via the <endpoint> endpoint
Then every rule in <package> is installed

Examples:
  | package            | endpoint |
  | with-historical    | legacy   |
  | with-historical    | current  |
  | without-historical | legacy   |
  | without-historical | current  |

Written as prose, that would have been four near-identical paragraphs, and they would drift apart on the first edit.

Review is the point

The 112 comments were not style nits. People argued about whether a scenario was reachable, whether an assumption held on the Basic license, which is Elastic's free tier, and whether two scenarios were secretly the same scenario.

That argument was going to happen somewhere. In Google Docs it happens as comment threads that resolve into nothing and disappear when somebody restructures the file. In the repository it happened where the team already looked, under the same approval rules as code, and the result was a commit.

An earlier expansion of the same test coverage (#155241) drew 89 review comments while following a plan that still lived in a Google Doc. The reviewers had to hold the plan in one tab and the diff in another and check them against each other by hand. After the move, a reviewer could open the plan inside the same diff.

The plan is prose, and prose can lie

Moving the plan into the repository does not make it executable. What the co-location buys is that the lie becomes cheap to find.

The implementation landed a week after the plan, at +2,085 / -552 across 30 files (#161687), and its description was one line pointing at the plan file. That is the correspondence, stated where someone would look for it.

Two months later I rewrote a good chunk of that implementation (#165488) to address review feedback I had deferred in order to get the coverage landed. The rewrite deleted helper functions with names like assertRuleAvailableForInstallAndInstallOne in favour of explicit step-by-step actions, and pulled if/else branching and optional flags out of test helpers, because a helper with a flag is two tests pretending to be one. In the same pass I reread the plan against the tests that now existed, found two sections with no coverage behind them, filed a ticket and linked it from the plan.

That last part is the habit worth copying. The plan is only true at the moment someone checks it, so the check has to attach to something that already happens. For us it attached to the rewrite.

The obvious answer was neither of my two proofs of concept

The hard part in all of this was never the writing. It was controlling the input.

Prebuilt rules reach Kibana through Fleet, which downloads a package from a registry on the public internet. A test that installs the real package installs more than 700 rules, takes minutes, and changes whenever Elastic publishes a new version of it. Any assertion about counts or contents is unstable by construction.

In April 2023 I opened two proofs of concept on the same day to settle it. One installed the package from a zip file bundled into the Kibana build (#154539). The other pulled it from the registry through Fleet's package manager (#154549). I expected one of them to win.

Neither merged, and I was asking the wrong question. Picking one meant either testing the real download path in every scenario, which is slow and non-deterministic, or never testing it at all. What actually shipped was a split. Most tests wrote the underlying rule assets straight into the Elasticsearch index during setup, bypassing Fleet, which is fast, repeatable, and lets a scenario say "given 3 rules are installed" and mean exactly 3. A small number of tests installed the real package on purpose, because somebody has to find out when the registry changes shape.

The plan is where that decision is recorded, one scenario at a time, in the automation line. "1 end-to-end test with mock rules" and "2 end-to-end tests that install the real package" are different commitments, and putting them next to each other made the ratio visible. Once the mock-rule approach replaced the 700-rule install in most of the suites, a test suite that had been skipped for being too slow could be turned back on.

Eighteen months later, the plan changed like code

By December 2024 the single plan file had outgrown itself. Splitting it took +1,005 / -528 across three files (#203331), and it drew 92 comments.

Two things happened in that pull request that could not have happened in a document tool.

The file became three: installing rules, upgrading rules, and installing or upgrading the package itself. Those had grown into separate concerns, and the diff shows exactly which scenarios moved where.

The sections that were about to become obsolete were gathered at the end of the upgrade file, under headings marked as legacy, each one carrying a note saying which milestone would make it dead and that it should be deleted when that shipped. We were replacing a JSON diff view and a per-field diff view with a new customization workflow. Rather than delete those scenarios while the old behaviour was still live, we put them where deleting them later would be one contiguous cut.

Deletion is the part people skip. A plan nobody ever deletes from ends up describing a product that no longer exists, and you can spot one because it only ever grows.

I left that work in December 2024 and details will have moved since. The practice transfers anyway, and it costs one directory. Put the plan next to the code it describes, require review on it, write an automation line under every scenario, and when a section is about to die, move it to the bottom of the file and say so there.