Docs / Development / Golden cases
Golden cases
A golden case is a recorded run together with the files it must produce. The tests replay each case and compare every output file byte for byte.
What a case holds#
Each case is a folder, tests/golden/CASE/, with three parts:
case.jsonsays how the case was recorded, which sample it used and what it proves.- The sealed trace: the generated sample, the board's inputs in order, the layout, the events and the manifest. It sits in a folder named for the run id, except for
elf-dispute, whose trace is the demo bundledemo/sfaef16e6. expected/holds the output files the replay must rebuild: seven for every case, anddetection.yaras the eighth inelf-dispute, the one case that wrote a YARA rule.
What the tests check#
tests/test_golden.py runs these checks over every case. They need no Docker, no model and no network, because the traces were recorded once.
- Replay the trace with
swarmlabre replayand compare every output file withexpected/, byte for byte. - Replay it a second time and require the same bytes.
- Compare
expected/with the hashes in the trace's own manifest. The two were written by different code paths and have to agree. - Every reject code of
swarms.REJECTSappears in some case. - Every report carries MITRE's copyright notice, and no report says that a cited call was made by the agent that cited it.
- Record each scripted case again and require the committed trace byte for byte.
The cases#
There are 11 cases: 7 scripted and 4 recorded with the real pipeline. The table gives what each one proves, in the words of its case.json.
| Case | Recorded | What it proves |
|---|---|---|
rejects | scripted | every reject code except cap_exceeded, one post each, next to accepted findings (byte-checked, call-cited, function, merged, technique) |
capped | scripted | a role's 201st post is rejected (cap_exceeded): 200 findings are kept, 5 posts are refused |
disputes | scripted | a dispute settled as stands, wrong (refuted) and unresolved, one left open, every refused dispute post, and a spot check of a disputed call-cited finding |
empty | scripted | a run whose board stayed empty: no findings, no board file, verdict undetermined |
overclaim | scripted | a Reporter verdict of malicious that rests only on an unverified finding is shown as undetermined with low confidence |
benign-capped | scripted | a benign verdict never goes above moderate confidence, even with two verified findings and a byte-checked one |
hostile | scripted | hostile strings in the sample (a forged finding line, a forged ASSESSMENT, script and HTML, ANSI and bidi controls, a spreadsheet formula, a relay marker, an over-long value) reach the report only as cleaned, escaped or defanged text |
elf-benign | real pipeline | the demo ELF through the real pipeline: a benign verdict, no rejects, four byte-checked findings |
elf-dispute | real pipeline | a UTF-16 string, a dispute raised by Static, a round-2 plan that settles it, a duplicate reject and YARA rules; also the static demo's bundle |
pe-basic | real pipeline | a PE32+ with an import table through host parse, Ghidra prep and the report |
apk-basic | real pipeline | an APK (binary manifest, DEX, assets) through host parse, jadx prep, the Mobile ATT&CK matrix and the report |
A scripted case is a list of board inputs in tests/golden_cases.py, recorded through the same hooks a live run uses and without containers.
A real pipeline case ran once in the two containers with the scripted mock model, then was sealed and exported. Re-recording one needs Docker and both images: python3 tests/goldenrun.py --record-real.
The samples come from swarmlabre/corpus.py (python3 -m swarmlabre corpus DIR). They are made of known-benign bytes: reserved example domains (RFC 2606), documentation addresses (RFC 5737) and code that only exits. There is no EICAR file. SwarmLabRE takes ELF, PE and APK files, so a script cannot be a sample; the generator writes one anyway and a test pins the refusal message.
expected/board.json. Hover a number for its case and column.Show as a table
| Case | Findings kept | Byte-checked findings | Call-cited findings | Refused posts | Reject codes | Findings with a dispute |
|---|---|---|---|---|---|---|
rejects | 4 | 1 | 1 | 12 | 12 | 0 |
capped | 200 | 0 | 0 | 5 | 1 | 0 |
disputes | 6 | 4 | 1 | 3 | 1 | 5 |
empty | 0 | 0 | 0 | 0 | 0 | 0 |
overclaim | 2 | 1 | 0 | 0 | 0 | 0 |
benign-capped | 2 | 2 | 0 | 0 | 0 | 0 |
hostile | 21 | 9 | 0 | 5 | 2 | 0 |
elf-benign | 6 | 4 | 0 | 0 | 0 | 0 |
elf-dispute | 6 | 5 | 0 | 1 | 1 | 1 |
pe-basic | 7 | 4 | 0 | 0 | 0 | 0 |
apk-basic | 7 | 4 | 0 | 0 | 0 | 0 |
Change a golden file#
A change to the report code changes golden bytes, on purpose or by mistake, and the tests fail until someone decides which. The decision is a reviewed update in two steps.
$ python3 tests/goldenrun.py --update-golden $ python3 tests/goldenrun.py --update-golden --accept TOKEN
- The first command writes nothing to
tests/golden/CASE/. It re-records the scripted cases and reseals the recorded ones intotests/golden/.proposed/, prints every added, removed and changed file with a diff and a review token of 12 characters, and exits 1 when anything would change. - The second command applies exactly the proposal that was shown. It refuses a token that does not match the files on disk, and it refuses when the
CIenvironment variable is set. --proposal-dir DIRalso copies the proposal to DIR, to read withdiff -ru.--record-realre-records the real pipeline cases with Docker and the two images, as a proposal for the same review.--set-tool STRINGwrites STRING as the tool revision of every recorded trace in the proposal.
Resealing rebuilds the outputs and the two inputs that depend on the code, swarm.json and board.jsonl, from the recorded inputs and rewrites the manifest hashes. The posts, the sample, the layout and the events are never touched.
A new case follows the same flow: add it to tests/golden_cases.py, run --update-golden, read the list of new files and accept.
What the recordings name#
The four real pipeline recordings (elf-benign, elf-dispute, pe-basic and apk-basic) were made once with the real containers and the scripted mock model. Some of what they name belongs to the machine that recorded them.
- Their manifests and reports name
0.1.0as the tool version. A live run records the short commit id of its checkout instead, with "(with local changes)" added when the tree had changes. The recordings went through the reviewed update flow (--set-tool 0.1.0), so they name no commit that is missing from this repository. manifest.jsonnames the two Docker image ids (sha256:...) of the machine that recorded them. They identify that build. They are not published images, and another build has other ids.nonce.keyis a random key that makes the per-task markers of the mock run repeatable;run --replayreuses it. It protects nothing: the runs are benign, and the key only makes them repeatable.- The stored YARA result in
detection.jsonofelf-disputesays the proof was made by SwarmLabRE's own matcher, "this box has no YARA program". It is part of the recorded input and stays as recorded.
What the cases do not cover#
- A replay starts at
inputs.jsonl, after the@@SWARM <nonce>scan, so the cases cover only the board's side of the record. That a forged finding line (wrong nonce, indented, in the middle of a line) never reaches the board is tested bytest_the_scan_ignores_a_finding_line_without_the_tasks_nonceintests/test_golden.py, not by a golden case. Agent turns, tool results and the model's replies are recorded and not run again. - The per-role cap of 200 posts is covered by
capped. The run-wide cap of 1,000 findings, the cap of 400 refused posts and the 64 MiB cap of the model trace are not. - Every case ends with a
doneevent of statusdone, so no case is a failed, stopped or timed-out run. - The cases use five generated samples, and the largest is 2,048 bytes. There is no packed or obfuscated file, no 32-bit or ARM binary, no APK with more than one DEX file, and no script, which is not a sample type.
- Replay at the downstream level, with no sample kept, is tested on a generated run in
tests/test_replay.pyand not in a golden case. - The recordings were replayed on the machine that recorded them and on the CI runner (Ubuntu, Python 3.12). Other machines, other Python versions and other operating systems are untested.
- No golden check runs the containers. The four real pipeline traces record what they produced on one build of the two images.