about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPjotr <wrk@bosa.lan>2026-11-07 17:17:19 +0000
committerPjotr <wrk@bosa.lan>2026-11-07 17:17:19 +0000
commit2307d5e2db5ce8efae19a647bd48b4311be34607 (patch)
treeaefc0a48a38cd69fd0f38f8c163ad77ad8d8317a
parent9fa03035b9f21352c1c8b93681cc1bc1ce4cf6ff (diff)
downloadgenenetwork4-2307d5e2db5ce8efae19a647bd48b4311be34607.tar.gz
version: document the provenance fields, and assert they agree
* README.md (/version): the example carries dirty/source_digest/branch,
and the prose says why a stamp can lag a commit -- a binary built from a
dirty tree must not claim that commit -- and that build.rs re-stamps on
a commit because it watches the ref, not just .git/HEAD.
* docs/www/ai-instruction.md: comparing against a clone means comparing
the part before "-dirty", with source_digest for the exact build.
* tests/version.rs: `dirty` mirrors the suffix, branch is non-empty, and
source_digest is 16 hex digits or unknown.
-rw-r--r--README.md14
-rw-r--r--docs/www/ai-instruction.md11
-rw-r--r--tests/version.rs17
3 files changed, 34 insertions, 8 deletions
diff --git a/README.md b/README.md
index a134131..c0beb28 100644
--- a/README.md
+++ b/README.md
@@ -63,7 +63,8 @@ Details, including example responses, below.
   {
     "data": {
       "name": "GeneNetwork4", "short_name": "GN4AI", "version": 4.0,
-      "release": 1, "date": "20261008", "git": "208eeac"
+      "release": 1, "date": "20261107", "git": "9fa0303",
+      "dirty": false, "source_digest": "2f7f77ed4ace92c1", "branch": "main"
     },
     "meta": {
       "state": "complete",
@@ -77,7 +78,16 @@ Details, including example responses, below.
 
   `date` and `git` are the HEAD commit's date and short hash, embedded at
   build time (see `build.rs`); they describe the commit the binary was
-  built from, not the time it happened to be compiled.
+  built from, not the time it happened to be compiled. `git` carries a
+  `-dirty` suffix when that build had uncommitted changes -- so a binary
+  can never claim to be a commit its code does not match -- and
+  `source_digest` is a hash over the compiled source files, which tells
+  two builds of the same commit apart where a commit hash cannot.
+  `branch` is the branch HEAD was on, or `HEAD` when detached. `build.rs`
+  declares `.git/HEAD`, the ref it points at and `.git/index` as
+  rerun triggers, so a rebuild after a commit re-stamps rather than
+  reusing the old hash; committing without rebuilding does not move the
+  stamp, which is the point.
 
 - `GET /species` - returns a JSON array of all species in the `Species`
   table, mirroring GeneNetwork3's `gn3.db.species.get_all_species`:
diff --git a/docs/www/ai-instruction.md b/docs/www/ai-instruction.md
index bb71a98..b1b2586 100644
--- a/docs/www/ai-instruction.md
+++ b/docs/www/ai-instruction.md
@@ -47,10 +47,13 @@ as HTML mentioning Anubis, stop — do not retry, and use the copy of this
 document you were given.
 
 To check you and the server are looking at the same revision, compare
-the clone's `git -C genenetwork4 log -1 --format=%h` with the `git` field of
-`GET /gn4/version`; they need not match exactly (docs can be newer than
-the running build), but a large gap means the API may not have what the
-docs describe.
+the clone's `git -C genenetwork4 log -1 --format=%h` with the `git` field
+of `GET /gn4/version`; they need not match exactly (docs can be newer
+than the running build), but a large gap means the API may not have what
+the docs describe. A `git` value ending in `-dirty` means that binary was
+built from a working tree with uncommitted changes: compare the part
+before `-dirty`, and quote `source_digest` if you need to identify the
+exact build.
 
 ```
 1. You are given a token     → by the GeneNetwork team, out of band
diff --git a/tests/version.rs b/tests/version.rs
index 29ae4c5..0753367 100644
--- a/tests/version.rs
+++ b/tests/version.rs
@@ -32,7 +32,20 @@ async fn version_returns_ok_with_json_record() {
     assert_eq!(record["short_name"], "GN4AI");
     assert_eq!(record["version"], 4.0);
     assert_eq!(record["release"], 1);
-    // date and git are set at build time (see build.rs); just check shape.
+    // Stamped at build time (see build.rs): check the shape, and that the
+    // three provenance fields agree with each other.
     assert_eq!(record["date"].as_str().unwrap().len(), 8);
-    assert!(!record["git"].as_str().unwrap().is_empty());
+    let git = record["git"].as_str().unwrap();
+    assert!(!git.is_empty());
+    assert_eq!(
+        record["dirty"].as_bool().unwrap(),
+        git.ends_with("-dirty"),
+        "`dirty` mirrors the -dirty suffix: {record}"
+    );
+    assert!(!record["branch"].as_str().unwrap().is_empty());
+    let digest = record["source_digest"].as_str().unwrap();
+    assert!(
+        digest == "unknown" || (digest.len() == 16 && digest.chars().all(|c| c.is_ascii_hexdigit())),
+        "a 64-bit hex digest, or unknown: {digest}"
+    );
 }