znippy_plugin_git/lib.rs
1//! znippy handler for **git object stores** — the `git` package format.
2//!
3//! One archive holds one git repository (D12: one `.znippy` per repo). The
4//! consumer is `gunnar`, a pure-Rust git server whose `repack()` writes the cold
5//! tier.
6//!
7//! ## The two tiers a repository can be stored as
8//!
9//! | tier | data entries | what it preserves |
10//! |---|---|---|
11//! | **objects** | one per object, named by its **oid hex**, holding its canonical bytes `"<type> <size>\0<content>"` | the oid is checkable by re-hashing the entry |
12//! | **packs** | `pack-<id>.pack` + `pack-<id>.idx` | the client's own **deflate** and every **delta chain** |
13//!
14//! The object tier is the one this format was designed around and is what the
15//! `__gunnar_*` sub-indexes describe. **The pack tier is what gunnar actually
16//! seals**, and the reason is measured: a git object in a pack is already
17//! deflated and often a delta, so storing it inflated per oid costs an OpenZL
18//! decode plus a fresh zlib deflate on every fetch, for ever, and forecloses
19//! pack-copy permanently. gunnar measured an archive of 60000 small git objects
20//! at 3.4× *larger* than its input. See [`sections::GitIndexBuilder::pack_tier`].
21//!
22//! ## What this format adds on top of a plain archive
23//!
24//! | column / module | carries |
25//! |---|---|
26//! | `object_type` | `blob` / `tree` / `commit` / `tag` for the object tier; `packfile` / `pack-index` for the pack tier — typed listing with no reads |
27//! | `object_size` | content length, so quota gates and size analytics are index-only |
28//! | `__gunnar_oid__` | an `stree` over the first 8 bytes of every oid → its lookup row |
29//! | `__gunnar_graph__` | the commit graph as Arrow: `oid, parents[], tree, committer_time, generation` |
30//! | `__gunnar_reach__` | per-commit reachability bitmaps (roaring) over object ordinals |
31//! | `__gunnar_refs__` / `__gunnar_secrets__` | the server's push logs, on **either** tier |
32//!
33//! The last three object modules are emitted for the object tier only — a pack
34//! carries its own `.idx`, which is a better oid index than `__gunnar_oid__`
35//! because it addresses pack offsets.
36//!
37//! All of these modules are **reserved** (`znippy_common::is_reserved_module`),
38//! so `znippy list`, `decompress`, the iceberg sink and the manifest readers skip
39//! them exactly as they skip the lookup and the trie.
40//!
41//! ## Laws it honours
42//!
43//! **P-1** one archive = one ecosystem (`--format git`); **P-2** it writes only
44//! the columns it declared; **P-3** it is discovered through [`meta`]; **P-4** a
45//! malformed or hostile entry never panics — `object_type` degrades to
46//! `unknown` and the archive still writes.
47//!
48//! ## Who writes the reserved sections
49//!
50//! [`GitIndexBuilder`] does, handed to `ArrowIpcSink::with_reserved_builder` by
51//! the writer that knows the object set — gunnar's `repack()`. It is deliberately
52//! **not** wired into `znippy compress --format git`: the CLI's small-file batch
53//! pass never sees objects that take the big-file path, so a CLI-built index
54//! would be silently incomplete, and a silently incomplete oid index is worse
55//! than none. `znippy compress --format git` therefore writes the two columns and
56//! no reserved sections; `znippy run git lookup|graph` reads archives that carry
57//! them.
58//!
59//! Native builtin, registered in `znippy-cli/src/handlers.rs::builtin_handlers`.
60//! Deliberately **not** a WASM plugin: the oid index's hot path is `stree`, which
61//! needs AVX2, an mmap and prefetch, none of which wasm offers.
62
63use std::collections::HashMap;
64
65use znippy_common::plugin::{
66 default_command, ArchiveTypePlugin, Col, ExtensionRow, ExtensionValue, HandlerSpec,
67};
68
69/// The measured workloads behind the `znippy.git_*` benches (feature
70/// `bench-kernels`). Not linked into a shipped archiver.
71#[cfg(feature = "bench-kernels")]
72pub mod bench_kernels;
73/// The push path's archive writer: one trait, three durability contracts
74/// ([`FastWriter`](archive_write::FastWriter),
75/// [`SafeWriter`](archive_write::SafeWriter),
76/// [`UringWriter`](uring_write::UringWriter)).
77pub mod archive_write;
78pub(crate) mod archive_map;
79/// **Which implementation of each trait a store is built on.** One selector,
80/// read once at construction, never per operation — [`arms::StoreConfig`].
81pub mod arms;
82pub mod graph;
83pub mod index_layout;
84/// The shared, off-the-ack-path index builder — one indexer per account,
85/// gatling fan-out, index tables built last.
86pub mod indexer;
87pub mod memguard;
88pub mod progress;
89pub mod object;
90pub mod oid_index;
91/// Computing a git delta, for the one entry shape this engine cannot copy: a
92/// stored delta whose base falls outside the request and whose receiver holds
93/// nothing. The only place in this crate that computes one.
94pub mod delta;
95/// One pass over a pushed packfile's entries — the split the closure check
96/// falls out of. Ours, gated against gix's grammar entry for entry.
97pub mod pack_walk;
98pub mod pushlog;
99/// The read path as one stack: Ragnar `stree` in front, the Arrow index tables
100/// it points into, and the redb un-sealed tail it falls through to.
101pub mod read_stack;
102/// Pack entries to oids: the indexer's half of the split, off the ack path.
103pub mod resolve;
104/// §14's exploded objects table: resolved content, derived from the verbatim
105/// truth, built eagerly by the same indexer, droppable at any time.
106pub mod exploded;
107pub mod exploded_arrow;
108pub mod exploded_cache;
109pub use exploded_cache::{suppress_write_back, write_back_suppressed, SuppressWriteBack};
110pub mod forest;
111pub mod reach;
112pub mod refs;
113/// Store-side replication to another gunnar. **Deliberately empty** — signature
114/// and contract only, no transport.
115pub mod replicate;
116/// One repository's stored bytes in ONE FILE: [`replicate`]'s decisions with a
117/// body, and a file instead of a transport. `archive_out` / `archive_in`.
118pub mod archive_file;
119pub mod secrets;
120pub mod store;
121/// Garbage collection: one trait, two implementations
122/// ([`gc::CompactInPlace`] in place, [`gc::NewGeneration`] into a new
123/// generation — the default).
124pub mod gc;
125/// `GitOps` — the typed API gunnar calls, and the store that implements it.
126/// Base znippy never sees this trait.
127pub mod git_ops;
128/// `GitServe` — the **reading** contract: decoded reads, the `HEAD` accessor
129/// pair, negotiation and pack emission. Layered above [`git_ops`], answered out
130/// of Arrow IPC, and **containing no gix** — see the module header for why that
131/// is a rule rather than a coincidence.
132pub mod serve;
133/// **Stock `git` as the arbiter, inside a repository.** Test support only —
134/// nothing on a serving, storing or indexing path may call it, because it forks
135/// `git`. It is `pub` because `tests/concurrent_push.rs` compiles against the
136/// library, and it exists because `git index-pack --strict` *segfaults* outside
137/// a repository, which is how an oracle came to be incapable of failing.
138pub mod git_oracle;
139/// io_uring arm of [`archive_write`]. Linux only — the module is empty
140/// elsewhere rather than substituting a `pwrite` path under an io_uring name.
141pub mod uring_write;
142pub mod sections;
143#[cfg(test)]
144mod thin_storm;
145/// **The corpus the tests run on, generated rather than found.** Test support
146/// only, and compiled only under `cfg(test)`: it exists because the fixture
147/// used to be whichever repository `read_dir` handed back first on one
148/// developer's box. See the module header for the eight guards that measured.
149#[cfg(test)]
150pub(crate) mod pack_fixture;
151
152pub use archive_write::{ArchiveWrite, Faults, FastWriter, SafeWriter};
153pub use arms::{
154 ALL_ENV, DEFAULT_REDB_CACHE_BYTES, ENV_BOUNDARY_DELTA, ENV_EMIT_WORKERS, ENV_EXPLODE, ENV_GC,
155 ENV_BASE_BUDGET_BYTES, ENV_INDEX, ENV_INDEX_BATCH_ROWS, ENV_MEM_BUDGET_BYTES, ENV_MEM_BUDGET_PCT,
156 ENV_MEMINFO, ENV_REACH_COMMITS, ENV_REDB_CACHE, ENV_WRITER, GcArm, IndexArm, StoreConfig,
157 WriterArm, env_reads, env_reads_here, redb_cache_bytes, set_graph_cache_default, ENV_GRAPH_CACHE,
158 ENV_EXPLODE_BUDGET, ENV_RESOLVE_LOOKAHEAD_BYTES, ENV_RESOLVE_WORKERS,
159};
160/// **The runtime doors beside [`arms::set_graph_cache_default`]** — the whole of what a twin
161/// turns off or turns down, set from code instead of from the environment. An explicit
162/// environment variable still wins over every one of them; see each function.
163pub use exploded_arrow::{explode_default, set_explode_default};
164pub use exploded_cache::{budget_default, set_explode_budget_default};
165pub use resolve::{set_resolve_lookahead_default, set_resolve_workers_default};
166pub use indexer::{AccountIndexer, IndexJob, IndexRow, IndexerPool, Lookup, PushPath};
167#[cfg(target_os = "linux")]
168pub use uring_write::UringWriter;
169
170pub use graph::{CommitNode, decode_graph, graph_schema, read_graph};
171pub use object::{
172 GitHashKind, GitObject, GitObjectKind, PACKFILE_TYPE, PACK_INDEX_TYPE, PackFileKind, canonical,
173 is_oid_path, pack_path_kind, parse_canonical, parse_commit, tree_entries,
174};
175pub use oid_index::{GitOidIndex, OidEntry, OidHit, OidLayout, key_for_oid};
176pub use pushlog::{
177 CompactionPolicy, CompactionReport, Finish, PushLog, PushLogScan, scan_frames,
178};
179pub use reach::{ReachEntry, ReachPolicy, decode_reach, read_reach, reach_schema};
180pub use refs::{RefLog, RefState, RefUpdate, read_refs, refs_schema};
181pub use secrets::{SecretState, SecretUpdate, SecretsLog, read_secrets, secrets_schema};
182pub use sections::GitIndexBuilder;
183pub use git_ops::{
184 GitOps, GitStore, LookupPath, Oid, RefRow, SelectedStore, Stored, TxId, lookup_path,
185 open_from_env, open_selected,
186};
187pub use serve::{Caps, GitServe, PackStats, ReachSet, HEAD};
188/// The typed ref rejection, re-exported so a consumer of this crate reaches it
189/// without also naming the contract crate. `RefRejection::of(&err)` is the only
190/// sanctioned way to ask whether a ref write lost a race — never a message.
191pub use git_storage_trait::{Observed, RefCas, RefRejection, RefTarget};
192
193/// DenseUnion / `pkg_type` discriminant. Clear of the built-ins (1–25), media
194/// (25), skidbladnir (40) and rust-toolchain (41).
195pub const GIT_TYPE_ID: i8 = 42;
196
197/// `object_type` written when the entry is not parseable as a canonical git
198/// object. A distinct, queryable state — never a silent `blob`.
199pub const UNKNOWN_OBJECT_TYPE: &str = "unknown";
200
201/// Native git-object handler.
202pub struct NativeGitPlugin;
203
204impl NativeGitPlugin {
205 pub fn new() -> Self {
206 NativeGitPlugin
207 }
208}
209
210impl Default for NativeGitPlugin {
211 fn default() -> Self {
212 Self::new()
213 }
214}
215
216/// The git handler, stated once.
217pub static GIT_SPEC: HandlerSpec = HandlerSpec {
218 name: "git",
219 aliases: &["gunnar", "git-objects"],
220 type_id: GIT_TYPE_ID,
221 ecosystem: "Git object store (gunnar cold tier — one archive per repository)",
222 // Left empty on purpose, and it is not an oversight. A loose git object
223 // carries no extension at all — its name IS its oid — and the pack entries
224 // this handler also claims are matched on their whole `pack-<oid>.<ext>`
225 // shape, not on a suffix. `matches_path` is the authority.
226 extensions: &[],
227 description: "Stores a git repository: either canonical objects keyed by oid hex, \
228 with the reserved __gunnar_oid__ (stree) / __gunnar_graph__ (commit \
229 graph) / __gunnar_reach__ (reachability bitmaps) sub-indexes, or the \
230 pack tier (pack-<id>.pack / .idx) that preserves the client's deflate \
231 and its delta chains",
232 // `object_size` is UInt32: a git object larger than 4 GiB saturates here; its
233 // exact byte length is the base `uncompressed_size` column (u64, the authority).
234 fields: &[("object_type", Col::Utf8), ("object_size", Col::U32)],
235 commands: &[
236 ("inspect", "Print type/size/sha1/sha256 for a file of canonical git object bytes"),
237 ("lookup", "Resolve an oid against an archive's __gunnar_oid__ index: `git lookup <archive> <oid>`"),
238 ("graph", "Print an archive's commit graph (oid, generation, time, parents)"),
239 ("refs", "Print a live store's ref namespace: `git refs <store-root>`"),
240 ],
241};
242
243impl ArchiveTypePlugin for NativeGitPlugin {
244 fn spec(&self) -> &HandlerSpec {
245 &GIT_SPEC
246 }
247
248 /// **CLI-only string dispatch** (§13.3). A server never comes through here:
249 /// it holds a [`GitStore`] and calls [`GitOps`] directly, typed.
250 ///
251 /// `refs` is what that delegation looks like — open the store, call the trait
252 /// method, print what it returned, and carry no logic of its own. The three
253 /// commands beside it are older and are **archive inspection**, not store
254 /// operations: they read a *sealed* archive's sections, which is a different
255 /// thing from a live store and is deliberately not modelled as a `GitOps`
256 /// call. They are left as they are rather than bent through a trait that does
257 /// not describe them.
258 fn run_command(&self, cmd: &str, args: &[String]) -> anyhow::Result<()> {
259 match cmd {
260 "refs" => {
261 let root = args
262 .first()
263 .ok_or_else(|| anyhow::anyhow!("usage: git refs <store-root>"))?;
264 // Everything below this line is printing. The answer comes from
265 // the trait.
266 let store = GitStore::open(std::path::Path::new(root), "cli")?;
267 for r in store.refs()? {
268 println!(
269 "{}\t{}{}",
270 r.name,
271 r.oid.as_deref().map(hex::encode).unwrap_or_else(|| "-".into()),
272 match (&r.peeled, &r.symref_target) {
273 (Some(p), _) => format!("\t^{}", hex::encode(p)),
274 (None, Some(t)) => format!("\t-> {t}"),
275 (None, None) => String::new(),
276 }
277 );
278 }
279 Ok(())
280 }
281 "inspect" => {
282 let path = args
283 .first()
284 .ok_or_else(|| anyhow::anyhow!("usage: git inspect <object-file>"))?;
285 let data = std::fs::read(path)?;
286 match parse_canonical(&data) {
287 Some(obj) => {
288 println!("type: {}", obj.kind.as_str());
289 println!("size: {}", obj.payload.len());
290 println!("sha1: {}", GitHashKind::Sha1.oid_hex_of(&data));
291 println!("sha256: {}", GitHashKind::Sha256.oid_hex_of(&data));
292 Ok(())
293 }
294 None => anyhow::bail!(
295 "'{path}' is not canonical git object bytes (`<type> <size>\\0<content>`)"
296 ),
297 }
298 }
299 "lookup" => {
300 let (archive, oid) = match (args.first(), args.get(1)) {
301 (Some(a), Some(o)) => (a, o),
302 _ => anyhow::bail!("usage: git lookup <archive> <oid-hex>"),
303 };
304 let index = GitOidIndex::open(std::path::Path::new(archive))?.ok_or_else(|| {
305 anyhow::anyhow!("'{archive}' carries no __gunnar_oid__ index")
306 })?;
307 match index.lookup_hex(oid) {
308 Some(hit) => {
309 println!("oid: {oid}");
310 println!("lookup_row: {}", hit.lookup_row);
311 println!("ordinal: {}", hit.ordinal);
312 Ok(())
313 }
314 None => anyhow::bail!("oid '{oid}' is not in '{archive}'"),
315 }
316 }
317 "graph" => {
318 let archive = args
319 .first()
320 .ok_or_else(|| anyhow::anyhow!("usage: git graph <archive>"))?;
321 let nodes = read_graph(std::path::Path::new(archive))?.ok_or_else(|| {
322 anyhow::anyhow!("'{archive}' carries no __gunnar_graph__ section")
323 })?;
324 println!("commits: {}", nodes.len());
325 for n in &nodes {
326 println!(
327 " {} gen={} time={} parents=[{}]",
328 n.oid,
329 n.generation,
330 n.committer_time.map(|t| t.to_string()).unwrap_or_else(|| "-".into()),
331 n.parents.join(" ")
332 );
333 }
334 Ok(())
335 }
336 other => default_command(self, other, args),
337 }
338 }
339
340 /// A git archive's entries are either **oids** — the whole `relative_path`
341 /// is 40 or 64 lowercase hex characters — or the **packs** of a repository's
342 /// cold tier, `pack-<id>.pack` / `pack-<id>.idx`.
343 ///
344 /// Both are the same ecosystem and so belong to one handler (P-1). Which of
345 /// the two an archive holds is not a variant of the format: it is what the
346 /// writer had. gunnar's `repack()` produces a consolidated pack and seals
347 /// that, because a pack preserves the pushing client's own deflate and its
348 /// delta chains, and an inflated per-oid tier destroys both permanently.
349 fn matches_path(&self, path: &str) -> bool {
350 is_oid_path(path) || pack_path_kind(path).is_some()
351 }
352
353 fn extract_metadata(&self, path: &str, data: &[u8]) -> Option<ExtensionRow> {
354 if !self.matches_path(path) {
355 return None;
356 }
357 let mut f: HashMap<String, ExtensionValue> = HashMap::new();
358
359 // A pack is typed by its magic, never by its name. A name is a claim
360 // the writer made; the magic is what the bytes are. `pack-<hex>.pack`
361 // over something that is not a packfile degrades to `unknown` exactly
362 // as malformed object bytes do (P-4) — a wrong type in the index is
363 // worse than an honest absence, because it is queried and believed.
364 if let Some(kind) = pack_path_kind(path) {
365 let typed = if data.starts_with(kind.magic()) {
366 kind.as_str()
367 } else {
368 UNKNOWN_OBJECT_TYPE
369 };
370 f.insert("object_type".into(), ExtensionValue::Str(typed.into()));
371 f.insert(
372 "object_size".into(),
373 ExtensionValue::U32(data.len().min(u32::MAX as usize) as u32),
374 );
375 return Some(ExtensionRow { fields: f });
376 }
377
378 match parse_canonical(data) {
379 Some(obj) => {
380 f.insert("object_type".into(), ExtensionValue::Str(obj.kind.as_str().into()));
381 f.insert(
382 "object_size".into(),
383 ExtensionValue::U32(obj.payload.len().min(u32::MAX as usize) as u32),
384 );
385 }
386 None => {
387 // P-4: a decompress bomb, a truncated object or plain garbage
388 // still writes a row — typed `unknown`, sized by what is there.
389 f.insert(
390 "object_type".into(),
391 ExtensionValue::Str(UNKNOWN_OBJECT_TYPE.into()),
392 );
393 f.insert(
394 "object_size".into(),
395 ExtensionValue::U32(data.len().min(u32::MAX as usize) as u32),
396 );
397 }
398 }
399 Some(ExtensionRow { fields: f })
400 }
401}
402
403#[cfg(test)]
404mod tests {
405 use super::*;
406 use crate::object::canonical;
407
408 fn get<'a>(row: &'a ExtensionRow, k: &str) -> Option<&'a ExtensionValue> {
409 row.fields.get(k)
410 }
411
412 #[test]
413 fn claims_oid_paths_and_nothing_else() {
414 let p = NativeGitPlugin::new();
415 assert!(p.matches_path(&"a1b2c3d4".repeat(5))); // 40 hex
416 assert!(p.matches_path(&"0f".repeat(32))); // 64 hex
417 assert!(!p.matches_path("refs/heads/main"));
418 assert!(!p.matches_path("objects/pack/pack-abc.pack"));
419 assert!(!p.matches_path(&"A1B2C3D4".repeat(5)));
420 }
421
422 /// The pack tier's two file names are claimed, and only in the shape git
423 /// itself writes. A bare `.pack` suffix is not enough: an archive of
424 /// arbitrary files must not have its entries retyped as git packs.
425 #[test]
426 fn claims_the_pack_tier_by_its_whole_name_not_by_a_suffix() {
427 let p = NativeGitPlugin::new();
428 let id40 = "a1b2c3d4".repeat(5);
429 let id64 = "0f".repeat(32);
430 assert_eq!(pack_path_kind(&format!("pack-{id40}.pack")), Some(PackFileKind::Data));
431 assert_eq!(pack_path_kind(&format!("pack-{id64}.idx")), Some(PackFileKind::Index));
432 assert!(p.matches_path(&format!("pack-{id64}.pack")));
433 assert!(p.matches_path(&format!("objects/pack/pack-{id40}.idx")));
434
435 for not_ours in [
436 "pack-nothex.pack",
437 "somefile.pack",
438 "pack-.pack",
439 &format!("pack-{id40}.bitmap"),
440 &format!("pack-{}.pack", "A1B2C3D4".repeat(5)),
441 &format!("{id40}.pack"),
442 ] {
443 assert_eq!(pack_path_kind(not_ours), None, "wrongly claimed {not_ours}");
444 }
445 assert!(!p.matches_path("somefile.pack"));
446 }
447
448 /// A pack is typed by its **magic**, never by the name the writer chose.
449 /// A file called `pack-….pack` that does not start with `PACK` is
450 /// `unknown` — the same honest state malformed object bytes get (P-4).
451 #[test]
452 fn a_pack_is_typed_by_its_magic_and_a_liar_is_unknown() {
453 let p = NativeGitPlugin::new();
454 let id = "0f".repeat(32);
455
456 let mut pack = b"PACK".to_vec();
457 pack.extend_from_slice(&2u32.to_be_bytes());
458 pack.extend_from_slice(&7u32.to_be_bytes());
459 let row = p.extract_metadata(&format!("pack-{id}.pack"), &pack).unwrap();
460 assert_eq!(get(&row, "object_type"), Some(&ExtensionValue::Str(PACKFILE_TYPE.into())));
461 assert_eq!(get(&row, "object_size"), Some(&ExtensionValue::U32(pack.len() as u32)));
462
463 let idx = b"\xfftOc\x00\x00\x00\x02".to_vec();
464 let row = p.extract_metadata(&format!("pack-{id}.idx"), &idx).unwrap();
465 assert_eq!(get(&row, "object_type"), Some(&ExtensionValue::Str(PACK_INDEX_TYPE.into())));
466
467 // Now the liars. Each is named as a pack and is not one.
468 for (name, bytes) in [
469 (format!("pack-{id}.pack"), &b"NOTAPACK"[..]),
470 (format!("pack-{id}.idx"), &b"PACK\0\0\0\x02"[..]),
471 (format!("pack-{id}.pack"), &b""[..]),
472 ] {
473 let row = p.extract_metadata(&name, bytes).expect("a claimed path always yields a row");
474 assert_eq!(
475 get(&row, "object_type"),
476 Some(&ExtensionValue::Str(UNKNOWN_OBJECT_TYPE.into())),
477 "{name} carries {bytes:?}, which is not that kind of file — it must not be typed \
478 from its name"
479 );
480 }
481 }
482
483 #[test]
484 fn types_and_sizes_come_from_the_stored_bytes() {
485 let p = NativeGitPlugin::new();
486 let body = b"hello world";
487 let bytes = canonical(GitObjectKind::Blob, body);
488 let oid = GitHashKind::Sha256.oid_hex_of(&bytes);
489 let row = p.extract_metadata(&oid, &bytes).unwrap();
490 assert_eq!(get(&row, "object_type"), Some(&ExtensionValue::Str("blob".into())));
491 assert_eq!(get(&row, "object_size"), Some(&ExtensionValue::U32(body.len() as u32)));
492
493 let commit = canonical(GitObjectKind::Commit, b"tree x\n\nmsg\n");
494 let coid = GitHashKind::Sha1.oid_hex_of(&commit);
495 let crow = p.extract_metadata(&coid, &commit).unwrap();
496 assert_eq!(get(&crow, "object_type"), Some(&ExtensionValue::Str("commit".into())));
497 }
498
499 #[test]
500 fn garbage_degrades_to_unknown_and_never_panics() {
501 let p = NativeGitPlugin::new();
502 let oid = "d".repeat(64);
503 for bad in [&b""[..], &b"\0\0\0"[..], &[0xffu8; 4096][..], &b"blob 99\0short"[..]] {
504 let row = p.extract_metadata(&oid, bad).expect("a claimed path always yields a row");
505 assert_eq!(
506 get(&row, "object_type"),
507 Some(&ExtensionValue::Str(UNKNOWN_OBJECT_TYPE.into())),
508 "unparseable bytes must be typed `unknown`, never guessed"
509 );
510 assert_eq!(get(&row, "object_size"), Some(&ExtensionValue::U32(bad.len() as u32)));
511 }
512 }
513
514 #[test]
515 fn a_path_that_is_not_an_oid_yields_no_row() {
516 let p = NativeGitPlugin::new();
517 assert!(p.extract_metadata("HEAD", b"ref: refs/heads/main\n").is_none());
518 }
519
520 #[test]
521 fn meta_is_the_discovery_record() {
522 let m = NativeGitPlugin::new().meta();
523 assert_eq!(m.name, "git");
524 assert_eq!(m.type_id, GIT_TYPE_ID);
525 assert!(m.aliases.contains(&"gunnar".to_string()));
526 // inspect / lookup / graph / refs + the shared `coords`.
527 assert_eq!(m.commands.len(), 5);
528 assert!(
529 m.commands.iter().any(|c| c.name == "refs"),
530 "the GitOps-delegating command is not advertised"
531 );
532 }
533}