TestCommitUUIDFormat locks in the wire format buf v1.69.0 requires. buf.util.FromDashless (private/pkg/uuidutil/uuidutil.go) parses the commit id by: 1. Asserting length == 32 2. Inserting dashes at the standard positions 3. Calling uuid.Parse, which validates the version and variant bits A regress
(t *testing.T)
| 18 | // the version/variant stamps fails step 3 with a parse error. Both |
| 19 | // shapes must be guarded. |
| 20 | func TestCommitUUIDFormat(t *testing.T) { |
| 21 | const sha = "81353411f7b010d5b9ebeb1899066aac18a36701" |
| 22 | got := commitUUID(sha) |
| 23 | |
| 24 | if len(got) != 32 { |
| 25 | t.Fatalf("commitUUID(%q) length = %d, want 32 (buf v1.69.0 expects a dashless UUID)", sha, len(got)) |
| 26 | } |
| 27 | for _, r := range got { |
| 28 | if !((r >= '0' && r <= '9') || (r >= 'a' && r <= 'f')) { |
| 29 | t.Fatalf("commitUUID(%q) = %q contains non-lowercase-hex character %q", sha, got, r) |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | // Version nibble: 4xxx (random UUID). byte 6 of the 16-byte UUID |
| 34 | // renders as chars 12-13 of the dashless hex string. |
| 35 | version := string(got[12]) |
| 36 | if version != "4" { |
| 37 | t.Fatalf("commitUUID(%q) version nibble = %q, want \"4\" (random UUID)", sha, version) |
| 38 | } |
| 39 | |
| 40 | // Variant nibble: 8/9/a/b. byte 8 of the 16-byte UUID renders as |
| 41 | // chars 16-17 of the dashless hex string; we only check the first |
| 42 | // char (high two bits), which must be one of {8,9,a,b}. |
| 43 | switch got[16] { |
| 44 | case '8', '9', 'a', 'b': |
| 45 | default: |
| 46 | t.Fatalf("commitUUID(%q) variant high nibble = %q, want one of 8/9/a/b (RFC 4122)", sha, got[16]) |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | // TestCommitUUIDDeterminism ensures the same git SHA always maps to the |
| 51 | // same UUID. Without this, buf.lock would hold a UUID that is invalid |
nothing calls this directly
no test coverage detected