Recipes
A recipe is a YAML file that describes a whole run: which files, how many, how large, and what your system should do with each. Commit it beside your tests and the test files stop being binaries in your repository. Anyone rebuilds them from the recipe, byte for byte.
What a recipe looks like
# fixtures.yaml
version: 1
seed: 7741
defaults:
label: true
targets:
- id: invoices
format: pdf
count: 25
size: 300kb
name: invoice_{index:04}.pdf
properties:
pages: 3
page_size: a4
expected: accept
- id: over_the_limit
format: png
count: 2
size: 12mb
expected:
outcome: reject
reason: size_limit
- id: bundle
format: zip
contains:
- format: txt
count: 200
size: 4kb
output:
dir: ./fixtures
manifest: manifest.json
tfg validate fixtures.yaml
tfg generate fixtures.yaml
Every recipe has a version and a list of targets. A target is one kind of
file: it needs an id, a format and exactly one of size,
size-range, boundary or contains. Two of them is an error,
and so is none.
An invalid recipe writes no files at all. validate and
generate report every problem at once, each naming the key it is about, so one run
shows everything to fix.
Keys of the whole recipe
Every key a recipe accepts is listed here, read from the program when this page is built. A key marked as not built yet is refused with a message saying so, never ignored.
| Key | What it does |
|---|---|
allow_nondeterministic | Consent to formats whose bytes differ from run to run. Every format of this build repeats to the byte, so true is refused for now and the line can be left out. |
defaults | Settings every target takes unless it says otherwise. |
defaults.fill | How the content of the files is made. Not built yet: a recipe with this key is refused, and the content always comes from the seed. |
defaults.label | Whether each file carries a short label saying which run made it. true unless you say otherwise. The label is written so that the file stays valid. |
engine | The version of tfg the recipe needs. Not built yet: a recipe with this key is refused, and the manifest records the version that ran. |
extends | A preset to build on, written as preset:size-boundaries. Its files come first, and the targets of the recipe are added after them. |
locale | The language of the generated content. Only en is available, so any other value is refused, and the line can be left out. |
output | Where the run writes. |
output.dir | The directory for the files and the manifest. A relative path is read from the directory you run in, not from the one the recipe is in. --out replaces it. |
output.manifest | The file name of the manifest. manifest.json unless you say otherwise. |
output.split_threshold | Splitting a large manifest into several files. Not built yet: a recipe with this key is refused, and the manifest is always one file. |
policy | Rules for settling the expectations that depend on your system. Not built yet: a recipe with this key is refused. Write expected on each target instead. |
seed | The number every byte of the run comes from. The same seed gives the same files on any machine. 0 unless you say otherwise. |
targets | The list of things to produce. Every target needs an id, a format and exactly one of size, size-range, boundary or contains. |
version | The version of the recipe format. Required, and 1 in this build. |
with | The settings of the preset named in extends, written the way its flags take them, such as limit: 5mb. A setting left out takes its default, and the manifest says so. |
Keys of a target
| Key | What it does |
|---|---|
targets.boundary | Three files around a limit: one byte under it, the limit itself and one byte over it. Written as a size, such as 5mb. |
targets.contains | For an archive: the files inside it, as a list of entries, each with a format, a count and a size. |
targets.count | How many files the target makes. 1 unless you say otherwise. |
targets.damage | Ways to break the files on purpose, applied in the order listed. Each one is a name, such as zero-head, or a type with its settings. tfg damage lists them. |
targets.expected | What your system should do with these files: accept, reject, sanitize or unspecified, alone or with a reason. The manifest carries it beside every file. |
targets.fill | How the content of these files is made. Not built yet: a recipe with this key is refused. |
targets.format | The format of the files, by its id, such as pdf or png. tfg formats lists them. |
targets.group | A name of your own for the kind of case these files are. The manifest carries it, so a report can group by it. |
targets.id | The name of the target. It is unique in the recipe, the seeds of its files come from it, and the manifest names it beside every file in target_id. |
targets.label | Whether these files carry the label. Overrides defaults.label for this target alone. |
targets.name | The template for the file names, such as invoice_{index:04}.pdf. {index:04} is the number of the file, four digits or more, and the only placeholder there is. |
targets.properties | The settings of the format, such as pages for a PDF or width and height for a picture. The page of format settings lists every one. |
targets.purpose | A sentence or two on what these files are and why they are in the set. The manifest carries it, and the instructions written beside the manifest are made from it. |
targets.send-as | The name to give these files to your system under, when it is one no disk stores, such as ../climbed_out.jpg. The file keeps an ordinary name on disk, and the manifest carries this one in send_as. |
targets.size | The exact size of every file, such as 300kb, 10mb or a plain byte count. Units count in 1024s. smallest makes a picture as small as it can be at its width and height. |
targets.size-range | A size drawn for each file from a range, such as 1kb-8kb. The draw comes from the seed, so the same seed gives the same sizes. |
How to write a size
A size is a number with a unit: b, kb, mb, gb
or tb. Units count in 1024s, the way a file manager does, so 10mb is
10 485 760 bytes. kib, mib, gib and tib mean the
same and say so. A fraction works, as in 1.5mb, and so does a plain byte count, as in
10485761.
size: 300kb- every file of the target is exactly that largesize-range: 1kb-8kb- each file gets a size from the range, drawn from the seedboundary: 5mb- three files: one byte under, the limit itself, one byte oversize: smallest- a picture as small as it can be at thewidthandheightyou set
When a format cannot reach a size, the run is refused before anything is written, with the smallest size the format can make and what to change. A size is never rounded quietly.
How to name the files
name is a template. {index:04} is the number of the file, padded to four
digits, and it is the only placeholder there is. Without a template a file is named after its target,
as invoices_0001.pdf.
name: invoice_{index:04}.pdf
A name no disk stores, such as ../climbed_out.jpg, goes in send-as. The file
keeps an ordinary name on disk, and the manifest carries the other one in send_as, for
the test to upload it under.
How to declare what your system should do
Short form, when the outcome is enough. Long form, when the reason matters:
expected: accept
expected:
outcome: reject
reason: size_limit
The outcomes are accept, reject, sanitize, unspecified.
The reasons are a closed list, so a report can group by them:
content_malformed, count_limit, dimensions_limit, duplicate, encoding_invalid, extension_rule, filename_invalid, filename_too_long, filename_traversal, malware_signature, mime_mismatch, nesting_depth, none, size_limit, size_zero.
A reason names the rule in play, not the verdict. That is why one reason can sit
under either outcome: a file one byte under a limit is accept, and the rule it is about
is still size_limit. Where the right reaction depends on how your system is set up, the
manifest says unspecified and explains why, rather than guessing.
How to break files on purpose
damage is a list, applied in the order written. Each entry is a name, or a
type with its settings. The file still has the size you asked for:
targets:
- id: broken
format: png
count: 5
size: 2mb
damage:
- zero-head
- type: truncate
missing: 30
expected:
outcome: reject
reason: content_malformed
tfg damage lists the damages and what each takes. Asking for accept beside a
damage that breaks the rules of the format is refused, because nothing could meet it. More in
Corrupt test files.
How to fill an archive
contains lists what goes inside a ZIP or a TAR.GZ. Each entry has a format, a count and
a size, and every file inside is a real file of its format. The archive is as large as what it
holds:
targets:
- id: bundle
format: zip
contains:
- format: pdf
count: 3
size: 200kb
- format: csv
count: 10
size: 8kb
The settings of the archive itself, such as compression, depth or a password, are in Format settings.
How to build on a preset
A recipe can start from the set of a preset and add its own targets after it. with gives
the preset its settings, written the way its flags take them:
version: 1
seed: 7
extends: preset:size-boundaries
with:
limit: 5mb
format: png
targets:
- id: our-legacy-format
format: tiff
count: 1
size: 3mb
This makes the same files as tfg preset eject size-boundaries --limit 5mb --format png
with the extra target typed under it. A target whose id the preset already uses is
refused, never quietly replaced. The manifest names the preset, and lists the settings you left to
its defaults.
How to check a recipe before a commit
tfg validate fixtures.yaml
tfg recipe fmt fixtures.yaml --check
validate says whether the recipe makes sense and what it would make, and writes nothing.
recipe fmt --check says whether the file is laid out in its settled shape, and
recipe fmt -w lays it out, comments kept. Run both in a pre-commit hook.
Ready recipes to download and change are in the recipe gallery.