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.json says 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 bundle demo/sfaef16e6.
  • expected/ holds the output files the replay must rebuild: seven for every case, and detection.yar as the eighth in elf-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 replay and compare every output file with expected/, 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.REJECTS appears 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.

CaseRecordedWhat it proves
rejectsscriptedevery reject code except cap_exceeded, one post each, next to accepted findings (byte-checked, call-cited, function, merged, technique)
cappedscripteda role's 201st post is rejected (cap_exceeded): 200 findings are kept, 5 posts are refused
disputesscripteda 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
emptyscripteda run whose board stayed empty: no findings, no board file, verdict undetermined
overclaimscripteda Reporter verdict of malicious that rests only on an unverified finding is shown as undetermined with low confidence
benign-cappedscripteda benign verdict never goes above moderate confidence, even with two verified findings and a byte-checked one
hostilescriptedhostile 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-benignreal pipelinethe demo ELF through the real pipeline: a benign verdict, no rejects, four byte-checked findings
elf-disputereal pipelinea 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-basicreal pipelinea PE32+ with an import table through host parse, Ghidra prep and the report
apk-basicreal pipelinean 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.

keptfindingsbyte-checkedcall-citedrefusedpostsrejectcodeswith adisputerejectsrejects, findings kept: 44rejects, byte-checked findings: 11rejects, call-cited findings: 11rejects, refused posts: 1212rejects, reject codes: 1212rejects, findings with a dispute: 00cappedcapped, findings kept: 200200capped, byte-checked findings: 00capped, call-cited findings: 00capped, refused posts: 55capped, reject codes: 11capped, findings with a dispute: 00disputesdisputes, findings kept: 66disputes, byte-checked findings: 44disputes, call-cited findings: 11disputes, refused posts: 33disputes, reject codes: 11disputes, findings with a dispute: 55emptyempty, findings kept: 00empty, byte-checked findings: 00empty, call-cited findings: 00empty, refused posts: 00empty, reject codes: 00empty, findings with a dispute: 00overclaimoverclaim, findings kept: 22overclaim, byte-checked findings: 11overclaim, call-cited findings: 00overclaim, refused posts: 00overclaim, reject codes: 00overclaim, findings with a dispute: 00benign-cappedbenign-capped, findings kept: 22benign-capped, byte-checked findings: 22benign-capped, call-cited findings: 00benign-capped, refused posts: 00benign-capped, reject codes: 00benign-capped, findings with a dispute: 00hostilehostile, findings kept: 2121hostile, byte-checked findings: 99hostile, call-cited findings: 00hostile, refused posts: 55hostile, reject codes: 22hostile, findings with a dispute: 00elf-benignelf-benign, findings kept: 66elf-benign, byte-checked findings: 44elf-benign, call-cited findings: 00elf-benign, refused posts: 00elf-benign, reject codes: 00elf-benign, findings with a dispute: 00elf-disputeelf-dispute, findings kept: 66elf-dispute, byte-checked findings: 55elf-dispute, call-cited findings: 00elf-dispute, refused posts: 11elf-dispute, reject codes: 11elf-dispute, findings with a dispute: 11pe-basicpe-basic, findings kept: 77pe-basic, byte-checked findings: 44pe-basic, call-cited findings: 00pe-basic, refused posts: 00pe-basic, reject codes: 00pe-basic, findings with a dispute: 00apk-basicapk-basic, findings kept: 77apk-basic, byte-checked findings: 44apk-basic, call-cited findings: 00apk-basic, refused posts: 00apk-basic, reject codes: 00apk-basic, findings with a dispute: 00
What the board of each case holds after the replay, counted from expected/board.json. Hover a number for its case and column.
Show as a table
CaseFindings keptByte-checked findingsCall-cited findingsRefused postsReject codesFindings with a dispute
rejects41112120
capped20000510
disputes641315
empty000000
overclaim210000
benign-capped220000
hostile2190520
elf-benign640000
elf-dispute650111
pe-basic740000
apk-basic740000

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 into tests/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 CI environment variable is set.
  • --proposal-dir DIR also copies the proposal to DIR, to read with diff -ru.
  • --record-real re-records the real pipeline cases with Docker and the two images, as a proposal for the same review.
  • --set-tool STRING writes 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.0 as 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.json names 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.key is a random key that makes the per-task markers of the mock run repeatable; run --replay reuses it. It protects nothing: the runs are benign, and the key only makes them repeatable.
  • The stored YARA result in detection.json of elf-dispute says 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 by test_the_scan_ignores_a_finding_line_without_the_tasks_nonce in tests/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 done event of status done, 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.py and 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.
SwarmLabRE alpha 0.1.0Edit this page on GitHub