Skip to content
Open
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
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,8 @@
*.mp4 binary
*.mhl text

# Fuzz seeds are exact bytes: a CRLF or a stray encoding is the test case.
tests/fuzz_corpus/** binary

# Keep generated/vendored material out of language stats and diffs.
docs/** linguist-documentation
18 changes: 0 additions & 18 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,24 +91,6 @@ jobs:
- run: offloader info
- run: pytest -q

fuzz:
name: property tests (soak)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.13"
cache: pip
- run: |
python -m pip install --upgrade pip
python -m pip install -e ".[dev]"
- name: Run the property tests at soak depth
# All three property modules: test_fuzz.py fuzzes what a filename can
# contain, test_fuzz_edges.py what a card can contain, and
# test_edge_cases.py the layers between the bytes and the paperwork.
run: pytest tests/test_fuzz.py tests/test_fuzz_edges.py tests/test_edge_cases.py --fuzz -q

build:
name: build the distribution
runs-on: ubuntu-latest
Expand Down
146 changes: 146 additions & 0 deletions .github/workflows/fuzz.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
name: Fuzz

# The soak: every property test at a deep example budget. Too slow for every
# pull request, where the ordinary suite already runs each property at 100
# examples and replays the committed seed corpus. Here it runs nightly and on
# demand, on Linux and on Windows, whose paths, junctions and file locking are
# where a card offload is most likely to differ.
#
# Permissions are split as in markcopy's fuzz workflow: the job that runs
# untrusted-input tests holds a read-only token, and only the reporting job
# can write issues.

on:
schedule:
- cron: "17 3 * * *"
workflow_dispatch:
inputs:
examples:
description: Examples per property (the --fuzz default is 3000)
required: false
default: "3000"

permissions:
contents: read

concurrency:
group: fuzz-${{ github.ref }}
cancel-in-progress: false

env:
QT_QPA_PLATFORM: offscreen
PYTHONUTF8: "1"

jobs:
soak:
name: soak / ${{ matrix.os }}
runs-on: ${{ matrix.os }}
timeout-minutes: 60
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest]
steps:
- uses: actions/checkout@v4
# Replaced by the test output below. If setup fails first, this is the
# log the artifact carries, so that platform still gets an issue.
- run: echo "The soak did not reach the tests." > soak.log
shell: bash
- uses: actions/setup-python@v5
with:
python-version: "3.13"
cache: pip
- run: |
python -m pip install --upgrade pip
python -m pip install -e ".[dev]"

# Hypothesis replays every failing example it has saved before
# generating new ones, so a failure found one night is retried first
# the next. A per-run key with a prefix restore carries the newest
# database forward.
- uses: actions/cache@v4
with:
path: .hypothesis
key: hypothesis-${{ matrix.os }}-${{ github.run_id }}
restore-keys: hypothesis-${{ matrix.os }}-

- name: Run every property test at soak depth
shell: bash
env:
OFFLOADER_FUZZ_EXAMPLES: ${{ inputs.examples || '3000' }}
# The whole suite, so a new fuzz module needs no change here.
run: |
set -o pipefail
pytest --fuzz -q 2>&1 | tee soak.log

- name: Keep the log and the example database
# Not `failure()`: a job that hits timeout-minutes ends cancelled.
if: ${{ !success() }}
uses: actions/upload-artifact@v4
with:
name: soak-${{ matrix.os }}
path: |
soak.log
.hypothesis/
retention-days: 30

report:
name: file the failure
needs: soak
# Any soak outcome but success, timeouts included. A run cancelled by
# hand files one too; close it if it says nothing.
if: ${{ always() && needs.soak.result != 'success' }}
runs-on: ubuntu-latest
permissions:
contents: read
issues: write
actions: read
steps:
- uses: actions/download-artifact@v4
with:
pattern: soak-*
- name: Open or update an issue per failing platform
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
run: |
shopt -s nullglob
folders=(soak-*/)
if [ ${#folders[@]} -eq 0 ]; then
# Failed before the log existed: setup, install, or a timeout.
folders=("soak-unknown/")
fi
for folder in "${folders[@]}"; do
platform="${folder#soak-}"; platform="${platform%/}"
title="Fuzz failure: ${platform}"
{
echo "The nightly soak failed on \`${platform}\`: ${RUN_URL}"
echo
if [ -f "${folder}soak.log" ]; then
echo "Each falsifying example is printed with a \`@reproduce_failure\`"
echo "line that replays it locally. The log and the example database"
echo "are attached to the run as \`soak-${platform}\`."
echo
echo '```'
found=$(sed -n -E '/^(FAILED|E |Falsifying|@reproduce_failure)/p' "${folder}soak.log" | head -n 80)
if [ -n "${found}" ]; then
echo "${found}"
else
# No test failed: setup broke, or the job ran out of time.
tail -n 40 "${folder}soak.log"
fi
echo '```'
else
echo "No log was produced: the job failed before the tests ran or"
echo "timed out. Treat the harness as broken until the run says why."
fi
} > body.md
existing=$(gh issue list --state open --search "in:title \"${title}\"" \
--json number,title --jq ".[] | select(.title == \"${title}\") | .number" | head -n 1)
if [ -n "${existing}" ]; then
gh issue comment "${existing}" --body-file body.md
else
gh issue create --title "${title}" --body-file body.md
fi
done
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dist/
.venv-build/
venv/
.pytest_cache/
.hypothesis/
.coverage
htmlcov/
*.log
Expand Down
13 changes: 10 additions & 3 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,13 @@ python -m pytest -q
Run the deeper property checks when relevant to safety or parser changes:

```powershell
python -m pytest tests/test_fuzz.py tests/test_fuzz_edges.py tests/test_edge_cases.py --fuzz -q
python -m pytest tests/test_fuzz.py tests/test_fuzz_edges.py tests/test_fuzz_parsers.py tests/test_fuzz_state.py tests/test_fuzz_engine.py tests/test_edge_cases.py --fuzz -q
```

A module that starts reading outside input needs an entry in
`tests/fuzz_surfaces.json` in the same change: a fuzz target, or a stated gap.
See CONTRIBUTING's "Fuzz targets".

Build Python distributions when packaging changes:

```powershell
Expand All @@ -161,8 +165,11 @@ reference outputs for formats and checksums over tests that mirror the writer.
See CONTRIBUTING for existing synthetic BRAW/BWF fixtures and failure helpers.

CI configuration is in [ci.yml](.github/workflows/ci.yml): cross-platform
tests, a Python minimum-version job, ffmpeg coverage, property-test soak, and
wheel/sdist validation. A configured job is not evidence of a passing run.
tests, a Python minimum-version job, ffmpeg coverage, and wheel/sdist
validation. The property-test soak runs nightly and on demand in
[fuzz.yml](.github/workflows/fuzz.yml) on Linux and Windows, and a failure
opens or updates a `Fuzz failure: <os>` issue. A configured job is not
evidence of a passing run.
Report what was actually executed and any skips or environment limitations.

## Implementation, documentation, and releases
Expand Down
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,37 @@ project uses [semantic versioning][semver].

## [Unreleased]

### Fixed

Found by `tests/test_fuzz_parsers.py` and `tests/test_fuzz_state.py`, which
fuzz the documents offloader reads back and the files it keeps between
runs. Each fix has the reproduction that found it.

- **One damaged byte in a previous ASC MHL manifest cost the next one.** An
XML declaration reading `encoding="TF-8"` raised `LookupError`, and a
multi-byte encoding a `ValueError`, where the reader expected only a parse
error. The ASC MHL report then failed (recorded, not silent) instead of
starting a new generation. `verify` now reports such a manifest as one that
will not parse.
- **A deeply nested state file stopped the history loading.** `[[[[...`
raised `RecursionError`, which `read_json` did not treat as damage, so the
promise that a corrupt state file never stops an offload did not hold.
- **One overflowing count dropped a history record.** A `file_count` of
`1e400` made `int()` raise `OverflowError`, losing the record and the
duplicate-card warning its fingerprint provides. The count is now zero.
- **An iXML frame rate of `inf` reached the sound report.** `float()` accepts
`inf`, and a huge ratio overflows to it. Non-finite rates are now ignored,
like a zero or negative one.

### Changed

- **The property-test soak runs nightly, on Linux and Windows.** It took
about 7 minutes on every pull request and ran on Linux only. `fuzz.yml`
now runs it on a schedule and on demand, keeps Hypothesis's database of
failing examples between runs, and opens or updates a `Fuzz failure: <os>`
issue with the reproduction when it fails. Pull requests still run every
property at the quick budget and replay the seed corpus.

- **Full verification is the default.** The read-back is the only mode that
proves what is on the destination device, and the default should be the one
whose "Verified" means the most. Applies to the engine's options, new
Expand Down
40 changes: 39 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pip install -e ".[dev]"

```sh
pytest # run the full suite
pytest --fuzz # property tests at 3000 examples each, about 3 min
pytest --fuzz # property tests at 3000 examples each, about 7 min
ruff check src tests
pytest --cov=offloader --cov-report=term-missing
```
Expand All @@ -60,6 +60,44 @@ python tools/screenshots.py # rewrites docs/images/
It runs the real app against a throwaway config directory and invented volumes,
so it neither reads your presets nor puts your drive labels in the README.

## Fuzz targets

[`tests/fuzz_surfaces.json`](tests/fuzz_surfaces.json) lists every module
that reads or renders input offloader did not write, with the property tests
that fuzz it, or a `gap` saying what is not fuzzed yet. A module that starts
parsing card data, a manifest, a timeline or a state file comes with an entry
in the same change: a new target, or an honest gap. `tests/test_fuzz_surfaces.py`
fails on an unclassified module, a target that is not a `@given` test, a fuzz
test no surface claims, or a soak workflow that no longer runs on a schedule.

The soak (`pytest --fuzz`, about 3000 examples per property) is too slow for
every pull request, so [`fuzz.yml`](.github/workflows/fuzz.yml) runs it
nightly on Linux and Windows, and on demand with a chosen example count
(`OFFLOADER_FUZZ_EXAMPLES` locally). Pull requests still run every property
at 100 examples and replay the seed corpus. A nightly failure opens or
updates a `Fuzz failure: <os>` issue with the falsifying examples and their
`@reproduce_failure` lines; paste one above the failing test to replay it,
then fix it as below.

A target checks the answer, not just that nothing raised. Wrap the call in
`fuzz_oracle.bounded` (documented exceptions only, a time and memory ceiling)
and add the property only a correct parser satisfies: a round trip, a
reference implementation, or for anything that feeds a verdict, that a pass
is backed by a hash taken now. Use `fuzz_oracle.scaled(n)` for a per-test
example budget, so `--fuzz` still deepens it.

Byte-level targets live in [`tests/fuzz_targets.py`](tests/fuzz_targets.py)
as `bytes -> None` functions, so the Hypothesis tests and the seed replay
state each property once. Their seeds are in `tests/fuzz_corpus/<target>/`,
generated from the unit-test builders by `python tests/make_fuzz_seeds.py`
(small, reproducible, never copied off a real card), and
`tests/test_fuzz_corpus.py` replays every one on each test run.

A bug a target finds becomes three things in the same change: the fix, a
deterministic regression test, and the failing input, both as an `@example`
on the target that found it and as a `regress-<what>` seed in
`make_fuzz_seeds.py`. Check that the test and the seed fail without the fix.

## Testing without a card

Almost nobody has a 27 GB BRAW clip, a sound cart and a failing card reader to
Expand Down
35 changes: 32 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -638,12 +638,12 @@ Full verification only when every present destination was hashed.
```sh
pip install -e ".[dev]"
pytest # run the full suite
pytest --fuzz # same suite, 3000 examples per property (~3 min)
pytest --fuzz # same suite, 3000 examples per property (~7 min)
ruff check src tests
pytest --cov=offloader --cov-report=term-missing
```

1383 tests at 87% line coverage. They cover formatting against the reference's
1454 tests at 87% line coverage. They cover formatting against the reference's
exact strings, checksum vectors and streaming equivalence, copy/verify
behaviour including simulated destination corruption, pause/resume/cancel
concurrency, retry discrimination, BRAW container parsing, ffprobe parsing,
Expand All @@ -662,7 +662,7 @@ real camera file when one is present.

### Property-based testing

Three modules use [Hypothesis][hyp] to assert invariants over generated input
Six modules use [Hypothesis][hyp] to assert invariants over generated input
rather than over a handful of fixtures, each aimed at a different layer:

- **`tests/test_fuzz.py`: what a filename can contain.** Names come off camera
Expand All @@ -673,6 +673,35 @@ rather than over a handful of fixtures, each aimed at a different layer:
atom headers lie, a tree that maps two sources onto one destination, a
directory junction pointing at its own parent, a retry policy someone
hand-edited into a preset.
- **`tests/test_fuzz_parsers.py`: what someone else wrote.** The iXML a
recorder put in a WAV, the ASC MHL a previous offload left behind, the
manifest `verify` is asked to vouch for, the `file:` URLs in a timeline.
Manifests are written by the test, not by `reports/`, and `verify` is
checked against hashes taken by the test: a report that passed must be
backed by a hash taken now, and a flipped byte, a deleted file, a dropped
digest or a hash marked failed must never pass. Every target also runs under
the shared oracle in `tests/fuzz_oracle.py`: only documented exceptions, a
time and memory ceiling per input, and no NaN or infinity in the result.
- **`tests/test_fuzz_state.py`: what is kept between runs.** The state file,
the history and the CLI's control file. Damaged content may be ignored but
never guessed at: a garbled control file never pauses or cancels a job, a
cancel stays final, claiming the control path never overwrites a file that
is not a control word, and a damaged history field costs that field, not
the record and its duplicate-card warning.

The byte-level properties also replay a committed seed corpus
(`tests/fuzz_corpus/`) on every run, including the input behind every bug the
fuzzers have found, so those stay fixed without `--fuzz`.
- **`tests/test_fuzz_engine.py`: whole offloads under faults.** A random card
against destinations that may already hold a good copy, a stale one or a
same-size impostor, while source reads, writes, fsync or promotion fail
(transiently or for good), a staged copy is corrupted before its reread, or
the job is cancelled mid-flight. Checked against the bytes on disk: no
partial survives, every final file is the old one or exactly the source, a
different existing file survives unless replacing was asked for, nothing
marked Verified differs from the source, and a "Verified" job saw no fault
that kept failing. Planting a skipped checksum comparison or a no-op cleanup
in the engine fails it within the quick budget.
- **`tests/test_edge_cases.py`: the layers between the bytes and the
paperwork.** What ffprobe hands back, what a number formats to, what a digest
compares equal to, what a name renders to.
Expand Down
4 changes: 2 additions & 2 deletions docs/release-plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ tests or builds were run for this documentation task.
| --- | --- | --- |
| Product | Engine, CLI, Qt desktop app, reports, BRAW/BWF support, optional timeline import | Exercise the frozen application against representative workflows |
| Version | One source in `src/offloader/_version.py` used by package metadata and the Windows bundle | Confirm the frozen release identity across all published assets |
| CI | Windows/macOS/Linux tests on Python 3.13, Linux Python 3.10, ffmpeg job, property-test soak, wheel/sdist build and metadata checks | Install built artifacts in fresh environments; build and smoke-test Windows desktop artifacts |
| CI | Windows/macOS/Linux tests on Python 3.13, Linux Python 3.10, ffmpeg job, nightly property-test soak on Linux and Windows, wheel/sdist build and metadata checks | Install built artifacts in fresh environments; build and smoke-test Windows desktop artifacts |
| Distribution | Frozen bundle, NSIS installer path, source and bundle inventories, and checksums | Hardware-key signing, clean-machine installation, release workflow, and publication documentation |
| Dependencies | Minimum versions and optional extras | Recorded build environment and pinned release dependency sets |
| Media tools | ffmpeg/ffprobe discovered externally; copying works without them | Explicit installer dependency policy and useful missing-tool messaging |
Expand Down Expand Up @@ -127,7 +127,7 @@ not elapsed time; set a public date after the first clean-machine pilot.
| 1. Release foundation | Single version source; frozen scope; dependency pins; build instructions; chosen artifact names and repository | A clean checkout produces matching package/app/report versions; release identity is unambiguous |
| 2. Windows package | PyInstaller spec and entry points; icon/version metadata; NSIS installer; third-party notices; media-tool status | GUI and CLI work on a clean Windows account without Python; reports render and manifests re-verify |
| 3. Trust and installation | Signing integration; signature verification; safe active-job handling; install/upgrade/uninstall checks | Both executable and installer signatures validate; install lifecycle preserves user data and never interrupts a job |
| 4. Candidate qualification | All existing CI jobs green for the exact source commit; artifact smoke tests; integrity acceptance matrix below | Every gate has recorded evidence; no unexplained skips, false success, data loss, or blocking install defects |
| 4. Candidate qualification | All existing CI jobs green for the exact source commit, including a dispatched soak run; no open `Fuzz failure:` issue; artifact smoke tests; integrity acceptance matrix below | Every gate has recorded evidence; no unexplained skips, false success, data loss, or blocking install defects |
| 5. Private pilot | Same candidate tested by 3 to 5 willing users on disposable copies of real media | At least 3 complete offload/re-verify workflows across 2 independent Windows machines; all blocking findings resolved and retested |
| 6. Public beta | GitHub prerelease; verified asset downloads; quick start; known limits; support instructions; brief demo | A new user can install, run, locate the reports, and report a problem using the published instructions |
| 7. Stabilize | Triage pilot/public reports; publish fixes with fresh versions; retain prior assets | At least one week of observation plus repeat acceptance evidence and no open integrity, installation, or recovery blockers before a normal release |
Expand Down
Loading
Loading