gunk-dev/the-valley

README.md

source885985671589main's published tip history
2.8 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. The malformed
21vectors cover duplicate and unsorted paths, non-canonical lengths, invalid modes and hashes,
22unsupported entries such as a submodule or a directory, paths no tree can hold, and broken line
23structure.
24
25## Where the expected results come from
26
27Every `.delta` and `.sha256` file is written by [`vectors.py`](./vectors.py), a short Python script
28that uses only Python's standard library. It reads the JSON specs and nothing else. It computes each
29encoding straight from the specification: it hashes each file's content with SHA-256, keeps the
30paths whose mode or hash differ, sorts them bytewise, and writes the lines. It does not run git, and
31it shares no code with the Go module. So a result here is never what the Go code happened to
32produce.
33
34The script was run once, and its output is committed:
35
36```sh
37python3 -I delta/testdata/vectors.py delta/testdata
38```
39
40Run it the same way after adding or changing a vector, and commit what it writes.
41
42## How they are checked
43
44The `delta-unit` check runs three things:
45
46- `vectors.py --check`, which fails if any committed file differs from what the script writes, or if
47 a file is here that no vector makes;
48- `go test`, which builds each vector's two trees as real git objects, computes the delta with the
49 Go code from the trees and from commits of them, and requires the committed encoding and digest.
50 It then parses the encoding and requires it to write back byte for byte, and requires every
51 malformed vector to be refused;
52- `go vet`.
53
54Trees that no checkout can hold faithfully, such as a file and a directory at one path, cannot be
55written as JSON specs. `../tree_test.go` builds them with git directly and requires them to be
56refused.