Making a Repeatable File Export

A repeatable export from unchanged inputs gives the same logical contents or bytes, depending on its declared guarantee.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Find a source of drift
  2. Test identical reruns
  3. Re-export the same snapshot without duplicating data
  4. State whether idempotence is semantic or byte-exact

Find a source of drift

Unordered directory enumeration can reorder rows while all values stay the same. Stable ordering by a relevant key fixes that source. See processing files in stable order.

Test identical reruns

Produce two independent exports from the same fixture and compare using the required equality. If creation times belong in the output, supply a fixed time when testing byte equality. Reproducing a run helps list the other inputs.[1]

Re-export the same snapshot without duplicating data

Suppose exporting the same report twice should leave one stable file containing lines A and B. Appending both lines each time yields A, B, A, B. Writing a complete candidate and replacing the old output applies the intended state directly. See atomic replacement.

First source snapshot → output A,B
Repeat same snapshot → output still A,B
Changed snapshot A,C → output A,C under the replace contract

State whether idempotence is semantic or byte-exact

Generated timestamps or unstable ordering can change bytes even if the report's data agree. If exact reproducibility matters, control those inputs. Test two retries of one snapshot and publication after a newer snapshot.

References

  1. Python Software Foundation, io: Core Tools for Working with Streams ↩