gunk-dev/the-valley

README.md

sourcedc327acea347main's published tip history
3.3 KiB · Rendered
1# Conformance vectors for valley-delta-v1
2
3These files fix the valley-delta-v1 encoding and digest. Any implementation of the delta, this
4module or another, must produce exactly these bytes from these trees, and must refuse every
5malformed encoding here. The encoding itself is specified in [`../delta.go`](../delta.go).
6
7## What is here
8
9- `valid/<name>.json` lists the files of two trees, `pre` and `post`. Each file has a path, a mode
10 and its content. A path or content that JSON cannot carry as text is given in hex instead, as
11 `path_hex` or `content_hex`. A symlink's content is its target. `about` says what the vector
12 covers.
13- `valid/<name>.delta` is the exact encoding of the delta from `pre` to `post`.
14- `valid/<name>.sha256` is the digest of that encoding, in lowercase hex.
15- `malformed/<name>.delta` is an encoding a reader must refuse. The table in
16 [`vectors.py`](./vectors.py) says why each one is malformed.
17
18The valid vectors cover the empty delta, binary content, renames, mode-only changes, symlinks,
19deletions, CRLF, a missing final newline, and paths holding spaces and newlines. They also cover a
20file that becomes a directory, bytewise path order, and paths that are not UTF-8. One vector meets
21Linux's limits exactly: a name of 255 bytes and a symlink target of 4095 bytes. The malformed
22vectors cover duplicate and unsorted paths, non-canonical lengths, invalid modes and hashes,
23unsupported entries such as a submodule or a directory, and paths no tree can hold, such as one with
24a name of 256 bytes. They also cover a symlink with the hash of empty content, since no symlink's
25target is empty, and broken line structure.
26
27## Where the expected results come from
28
29Every `.delta` and `.sha256` file is written by [`vectors.py`](./vectors.py), a short Python script
30that uses only Python's standard library. It reads the JSON specs and nothing else. It computes each
31encoding straight from the specification: it hashes each file's content with SHA-256, keeps the
32paths whose mode or hash differ, sorts them bytewise, and writes the lines. It does not run git, and
33it shares no code with the Go module. So a result here is never what the Go code happened to
34produce.
35
36The script was run once, and its output is committed:
37
38```sh
39python3 -I delta/testdata/vectors.py delta/testdata
40```
41
42Run it the same way after adding or changing a vector, and commit what it writes.
43
44## How they are checked
45
46The `delta-unit` check runs three things:
47
48- `vectors.py --check`, which fails if any committed file differs from what the script writes, or if
49 a file is here that no vector makes;
50- `go test`, which builds each vector's two trees as real git objects, computes the delta with the
51 Go code from the trees and from commits of them, and requires the committed encoding and digest.
52 It then parses the encoding and requires it to write back byte for byte, and requires every
53 malformed vector to be refused;
54- `go vet`.
55
56Trees that no checkout can hold faithfully, such as a file and a directory at one path, cannot be
57written as JSON specs. `../tree_test.go` builds them with git directly and requires them to be
58refused. A symlink whose target holds a NUL or is longer than 4095 bytes is one of them. An encoding
59cannot show such a target, since it holds only the target's hash, so only the trees are refused.