Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
16 changes: 15 additions & 1 deletion .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ name: Container image
# release published before this file existed: a release event reads the
# workflow from the tagged commit, and v0.5.0's has none. A pull request that
# touches the image builds and tries it against the latest release and pushes
# nothing.
# nothing, and so does a release candidate: only stable releases become
# images.
on:
release:
types: [published]
Expand Down Expand Up @@ -77,6 +78,19 @@ jobs:
echo "::error::$tag is not published yet, and an image is only ever made of what people can download"
exit 1
fi
# Only stable releases become images. A release candidate stays a
# prerelease on GitHub, and its image is built and tried here the
# way a pull request's is, with nothing pushed.
if [[ "$tag" == *-* ]]; then
if [ "$EVENT" = workflow_dispatch ]; then
echo "::error::$tag is a release candidate, and only stable releases become images. Run this workflow with the tag of a stable release, such as v0.6.0."
exit 1
fi
if [ "$publish" = true ]; then
publish=false
echo "::notice::$tag is a release candidate, so its image is built and tried and nothing is pushed. Only stable releases become images."
fi
fi
is_latest=false
if [ "$tag" = "$latest" ]; then
is_latest=true
Expand Down
21 changes: 17 additions & 4 deletions .github/workflows/npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ name: npm packages
# It starts when the owner publishes a release, and can be run by hand for the
# latest one - a run that stopped half way stages only what is not staged or
# published yet. A pull request that touches the packages tries them against
# the latest release and stages nothing.
# the latest release and stages nothing, and so does a release candidate:
# npm only gets stable releases.
on:
release:
types: [published]
Expand Down Expand Up @@ -76,10 +77,22 @@ jobs:
echo "::error::$tag is not published yet, and npm only ever gets what people can download. Publish the release, and this workflow starts by itself."
exit 1
fi
# npm only ever gets stable releases. A release candidate stays a
# prerelease on GitHub, and its packages are made and tried here the
# way a pull request's are, with nothing staged.
if [[ "$tag" == *-* ]]; then
if [ "$EVENT" = workflow_dispatch ]; then
echo "::error::$tag is a release candidate, and npm only gets stable releases. Run this workflow with the tag of a stable release, such as v0.6.0."
exit 1
fi
if [ "$stage" = true ]; then
stage=false
echo "::notice::$tag is a release candidate, so its packages are made and tried and nothing is staged. npm only gets stable releases."
fi
fi
# npm files a release under latest whatever its age, so staging an
# older one would take latest away from the newest. A prerelease goes
# under next and takes nothing away.
if [ "$stage" = true ] && [[ "$tag" != *-* ]] && [ "$tag" != "$latest" ]; then
# older one would take latest away from the newest.
if [ "$stage" = true ] && [ "$tag" != "$latest" ]; then
echo "::error::$tag is not the latest release ($latest), and staging it would make npm install give people an older tfg. Run this workflow for $latest instead."
exit 1
fi
Expand Down
75 changes: 71 additions & 4 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ on:

permissions:
contents: read
pages: write
id-token: write

env:
GO_VERSION: "1.27.4"

# One deployment at a time, and a newer commit wins. Cancelling a running
# deployment mid-flight would be worse than letting it finish, so in-progress
Expand All @@ -31,7 +32,62 @@ concurrency:
cancel-in-progress: false

jobs:
# The files of the sample files page are not in the repository. The recipe
# beside the page makes them with the tfg of this commit, and every one is
# checked against the SHA256SUMS the page was rendered with before it may go
# out, so the sums a visitor reads are the sums of the bytes they download.
# A job of its own, with nothing but read access, because it builds and runs
# repository code and the job that publishes holds pages: write.
samples:
if: >-
github.event_name == 'workflow_dispatch' ||
(github.event.workflow_run.conclusion == 'success' &&
github.event.workflow_run.event == 'push' &&
github.event.workflow_run.head_repository.full_name == github.repository)
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
# The same commit the publish job checks out, for the same reason.
#
# CodeQL reports this checkout as actions/untrusted-checkout/medium. That
# query flags every checkout of a workflow_run head_sha in a job without
# write access, and by design it does not read the job's if. The if above
# lets only a push to main of this repository, or a person who can
# dispatch, reach this step, so the commit is never a fork's. Giving the
# job write access would move it under the queries that do read the if,
# which is the wrong trade for a job that runs repository code.
# nosemgrep: yaml.github-actions.security.workflow-run-target-code-checkout.workflow-run-target-code-checkout
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
ref: ${{ github.event.workflow_run.head_sha || github.sha }}

- uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
Comment thread
donislawdev marked this conversation as resolved.
Dismissed
with:
go-version: ${{ env.GO_VERSION }}

- name: make the sample files and check them against the page
env:
CGO_ENABLED: "0"
run: |
set -euo pipefail
go build -tags "$(cat .github/build-tags)" -o "$RUNNER_TEMP/tfg" ./cmd/tfg
"$RUNNER_TEMP/tfg" generate web/samples/samples.yaml --out web/public/samples
"$RUNNER_TEMP/tfg" tool checksum-check web/public/samples/SHA256SUMS

- uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
with:
name: sample-files
path: web/public/samples
if-no-files-found: error
retention-days: 1

publish:
needs: samples
permissions:
contents: read
pages: write
id-token: write
# A dispatch is a person asking on purpose. Everything else has to be CI
# saying the tree is good, ON THIS REPOSITORY, for a push.
#
Expand Down Expand Up @@ -67,8 +123,12 @@ jobs:
with:
persist-credentials: false
# The commit CI passed on, not whatever main happens to be now. On a
# dispatch there is no such commit and the default ref is right.
ref: ${{ github.event.workflow_run.head_sha || github.ref }}
# dispatch there is no such commit, and github.sha is the commit the
# branch was at when the run started - fixed for the whole run, so a
# push while the samples job works cannot pair its files with the
# pages of a newer commit, the way the branch name resolved twice
# could.
ref: ${{ github.event.workflow_run.head_sha || github.sha }}

- name: refuse to publish an empty site
# A misplaced path here would deploy nothing and take the site down
Expand All @@ -79,6 +139,13 @@ jobs:
test -f web/public/sitemap.xml
test -f web/public/CNAME

# The sample files the samples job made and checked. Nothing here builds
# or runs code of the repository.
- uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
with:
name: sample-files
path: web/public/samples

- uses: actions/configure-pages@45bfe0192ca1faeb007ade9deae92b16b8254a0d # v6.0.0

- uses: actions/upload-pages-artifact@fc324d3547104276b827a68afc52ff2a11cc49c9 # v5.0.0
Expand Down
14 changes: 13 additions & 1 deletion .github/workflows/pypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ name: PyPI packages
# and the publishing action puts an attestation of each file beside it. A run
# by hand can send them to TestPyPI instead, to see that PyPI takes them
# before a release depends on it. A pull request that touches the packages
# makes and tries them from the latest release and publishes nothing.
# makes and tries them from the latest release and publishes nothing, and so
# does a release candidate: PyPI only gets stable releases.

on:
release:
Expand Down Expand Up @@ -80,6 +81,17 @@ jobs:
echo "::error::$tag is not published yet, and PyPI only ever gets what people can download. Publish the release, and this workflow starts by itself."
exit 1
fi
# PyPI only ever gets stable releases. A release candidate stays a
# prerelease on GitHub, and its wheels are made and tried here the
# way a pull request's are. TestPyPI, by hand, may still take one.
if [[ "$tag" == *-* ]] && [ "$index" = pypi ]; then
if [ "$EVENT" = workflow_dispatch ]; then
echo "::error::$tag is a release candidate, and PyPI only gets stable releases. Run this workflow with the tag of a stable release, such as v0.6.0, or choose testpypi."
exit 1
fi
index=none
echo "::notice::$tag is a release candidate, so its wheels are made and tried and nothing goes to PyPI. PyPI only gets stable releases."
fi
{
echo "tag=$tag"
echo "version=${tag#v}"
Expand Down
34 changes: 34 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,40 @@ because it turns other people's test suites red.

## [Unreleased]

### Added

- **Sample files to download on the website.** One file of every format at
exactly 1 MB, corrupt PDF, Word, Excel, PowerPoint, JPG, PNG, MP4 and ZIP
files, CSV, JSON and Excel tables for an import, and placeholder pictures in
common sizes. Each comes with its SHA-256 and what the manifest expects a
system to do with it. All of them come from one recipe published beside
them, so `tfg generate samples.yaml` makes the same bytes on any machine.
- **File upload test cases on the website.** A checklist from the size limit
to a file name that leaves its folder, each case with the file that tests it
and the outcome to expect, in every language of the site.
- **A page about the tools on the website.** Checking an archive for zip slip
and zip bombs before unpacking it, and checking or writing SHA-256 checksums.

### Changed

- **npm, PyPI and the container image get stable releases only.** A release
candidate stays a prerelease on GitHub, so `npm install`, `pip install` and
the image never give you one. While the code on `main` is a release
candidate, the README and the website name the last stable release in their
install commands.
- **The README says what the tool can do in full**: presets, damaged files, a
name no disk stores, the tools, and the packages for pytest and Node.

### Fixed

- **`tfg tool checksum-write` no longer promises to notice any change in the
folder.** Its question is now "How will I know later that none of these files
changed?". `checksum-check` checks the files the checksum file lists, so a
file added to the folder later is not noticed.
- **The examples in the README and on the documentation page each write into a
folder of their own.** Run one after another, the second used to stop at the
manifest the first had left in the same folder.

## [0.6.0-rc1] - 2026-11-18

### Breaking
Expand Down
76 changes: 58 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,69 @@ needs it finds out it exists.

## ⚡ What it can do

**Make real files**

- **Hit an exact size, to the byte** - ask for 10485761 bytes and get exactly
that, never a silently rounded file.
- **Write 32 real formats** - a generated PNG opens in an image viewer, a DOCX
- **Write 32 real formats** - documents, pictures, text, archives, mail,
telemetry, sound and video. A generated PNG opens in an image viewer, a DOCX
opens in Word, a ZIP extracts. Not padded zeros with an extension.
- **Say what should happen to each file** - the manifest carries an expected
outcome, so your test reads the assertion instead of you writing it out.
- **Repeat itself byte for byte** - same recipe and seed, same bytes, on any
machine. Commit a small recipe instead of large binary fixtures.
- **Build a boundary set in one command** - one byte under a limit, the limit
itself, one byte over. That is where off by one errors live.
- **Produce ten thousand files at once** - one command, one manifest, and sizes
drawn from the seed.
- **Take settings per format** - image dimensions, JPEG quality, PDF pages,
spreadsheet rows and columns, what goes inside an archive.
- **Fill an archive for real** - a ZIP that holds 200 documents, not a stub with
the right extension.
- **Take settings per format** - image dimensions, JPEG quality, PDF pages,
spreadsheet rows and columns.
- **Draw placeholder pictures** - a flat colour with its size written in the
middle, for laying out a page before the real pictures exist, as PNG, JPG or
SVG and as small as the picture allows.
- **Produce ten thousand files at once** - one command, one manifest, and sizes
drawn from the seed.

**Break files on purpose**

- **Make corrupt test files** - cut the end off a file the way an interrupted
upload does, overwrite its first bytes with zeros, or add junk after its end.
Any format, still at the exact size you asked for. See
[`tfg damage`](#tfg-damage).
- **Send a file under a name no disk stores** - such as `../climbed_out.jpg`,
to see what your upload does with a path in a file name. The file keeps its
own name and the manifest says which one to upload it under.

**Answer a testing question in one command**

- **Start from a preset** - ready-made sets for size limits, unexpected file
names, text encodings, table imports, picture sizes, the smallest valid files
and upload forms. Every file says what it is for. See [Presets](#-presets).
- **Build a boundary set** - one byte under a limit, the limit itself, one byte
over. That is where off by one errors live.
- **Say what should happen to each file** - the manifest carries an expected
outcome, so your test reads the assertion instead of you writing it out. Where
the answer depends on how your system is set up, it says so rather than guess.

**Fit into tests and CI**

- **Repeat itself byte for byte** - same recipe and seed, same bytes, on any
machine. Commit a small recipe instead of large binary fixtures.
- **Plug into your tests** - a pytest plugin, an npm package for Playwright,
Vitest and `node:test`, a Docker image, and a ready install step for GitHub
Actions. See [Install](#-install).
- **Fit into CI** - an exit code for every ending, machine readable output, and
nothing on standard output when a run fails.
- **Clean up after itself** - `verify` tells you nothing moved, `cleanup`
removes exactly what it wrote and nothing else.

**Check files you already have**

- **Check an archive before unpacking it** - a ZIP, TAR or gzip file is read
without unpacking anything, and you learn whether it would write outside its
folder, overwrite a file or fill the disk - the traps known as zip slip and
zip bomb. See [`tfg tool`](#tfg-tool).
- **Check checksums** - of one file against the one a download page gave you,
or of a whole folder against its SHA256SUMS, and write one for a folder.

**Your way**

- **Use a window or the command line** - the same engine in both. The window
has the presets, several batches at once and the tools, in English or Polish.
- **Work completely offline** - no account, no cloud, no telemetry, no update
check. The command line binary has no network stack compiled into it at all.
- **Cost nothing and stay out of your way** - GPL-3.0, and the files you
Expand Down Expand Up @@ -104,7 +144,7 @@ Arm. It holds the program from the release archive and nothing else, and it
runs with no network:

```
docker run --rm --network none -v "${PWD}:/work" ghcr.io/donislawdev/tfg:0.6.0-rc1 generate --format pdf --size 1mb
docker run --rm --network none -v "${PWD}:/work" ghcr.io/donislawdev/tfg:0.5.0 generate --format pdf --size 1mb
```

The files land in the current directory. On Linux add
Expand Down Expand Up @@ -522,8 +562,8 @@ Use them with `tfg generate --damage <id>`, repeatable and applied in the order
given, or with the `damage` key of a target in a recipe:

```
tfg generate --format png --size 20kb --count 10 --damage zero-head:bytes=16
tfg generate --format zip --size 5mb --damage truncate:missing=30
tfg generate --format png --size 20kb --count 10 --damage zero-head:bytes=16 --out ./zero-head-16
tfg generate --format zip --size 5mb --damage truncate:missing=30 --out ./cut
```

A damaged file names its damage in its label, beside the size it has on disk:
Expand Down Expand Up @@ -758,7 +798,7 @@ recipe. `tfg formats <id>` prints the allowed range or list for each:
| `yaml`, `toml` | none in this build - the document is a fixed shape, and a size is the only thing to ask for |

```
tfg generate --format jpg --size 500kb --set width=1920 --set height=1080 --set quality=85
tfg generate --format jpg --size 500kb --set width=1920 --set height=1080 --set quality=85 --out ./photos
```

**Ask for a size a format cannot reach and you get an error, never a file of the
Expand Down Expand Up @@ -906,7 +946,7 @@ On a Linux runner the Docker image needs no install step:

```yaml
- name: build the fixtures
run: docker run --rm --network none --user "$(id -u):$(id -g)" -v "$PWD:/work" ghcr.io/donislawdev/tfg:0.6.0-rc1 generate fixtures.yaml --out fixtures
run: docker run --rm --network none --user "$(id -u):$(id -g)" -v "$PWD:/work" ghcr.io/donislawdev/tfg:0.5.0 generate fixtures.yaml --out fixtures
```

Name the version rather than `latest`, so the same recipe gives the same bytes
Expand All @@ -926,7 +966,7 @@ names the SPDX predicate. On macOS this needs an Apple silicon runner, such as
env:
GH_TOKEN: ${{ github.token }}
run: |
version=0.6.0-rc1
version=0.5.0
arch=amd64
if [ "$RUNNER_ARCH" = ARM64 ]; then arch=arm64; fi
case "$RUNNER_OS" in
Expand Down Expand Up @@ -1034,7 +1074,7 @@ asked for, and the manifest says where a cut fell. [`tfg damage`](#tfg-damage) l
damage takes, and where the outcome depends on your system.

```
tfg generate --format png --size 2mb --damage zero-head --out ./out
tfg generate --format png --size 2mb --damage zero-head --out ./zero-head
```

### Which formats are coming next?
Expand Down
7 changes: 7 additions & 0 deletions internal/guard/mutationcoverage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,13 @@ var provenByProbe = map[string]string{
"TestWindowsHoldsTheTitleBarDarkOnceAsked": "a canary of its own - a window nobody asked about has to read as " +
"not dark before the asked one may read as dark - and a window of none has to be refused. What it cannot see, the " +
"look of the bar, was measured on Windows Server 2025 on 2026-11-18: 243 before, 32 after.",
"TestTheSampleFilesPageOffersAFileOfEveryFormat": "a canary of its own - a planted set missing a format and two " +
"sections, with an undamaged corrupt file, has to give every gap. Broken by hand on 2026-11-23 by taking the webp " +
"target out of web/samples/samples.yaml, and by taking the checksum-check line out of pages.yml: red both times.",
"TestAReleaseCandidateIsSentNowhereButGitHub": "a canary of its own - a which step that sends whatever it is " +
"given has to fail the same cases. Broken by hand on 2026-11-23 by the npm.yml, pypi.yml and docker.yml of " +
"main before the change: red six times, each of the three sending a published release candidate and taking " +
"one by hand.",
"TestTheTitleBarIsAskedForAgainAfterEveryChangeOfSettings": "a canary of its own - an ask made straight from the " +
"listener, before the toolkit's answer, has to leave the bar light. Broken by hand on 2026-11-18 by " +
"KeepTitleBarDark without fyne.Do: red. On a real window that day a build without KeepTitleBarDark left the bar " +
Expand Down
Loading
Loading