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, Claim, 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 handler's claim: a loose object keyed by its oid hex, or a
217/// `pack-<oid>.pack` / `.idx` file.
218fn is_git_store_path(path: &str) -> bool {
219 is_oid_path(path) || pack_path_kind(path).is_some()
220}
221
222/// The git handler, stated once.
223pub static GIT_SPEC: HandlerSpec = HandlerSpec {
224 name: "git",
225 aliases: &["gunnar", "git-objects"],
226 type_id: GIT_TYPE_ID,
227 ecosystem: "Git object store (gunnar cold tier — one archive per repository)",
228 // Left empty on purpose, and it is not an oversight. A loose git object
229 // carries no extension at all — its name IS its oid — and the pack entries
230 // this handler also claims are matched on their whole `pack-<oid>.<ext>`
231 // shape, not on a suffix. `matches_path` is the authority.
232 extensions: &[],
233 claim: Claim::Layout(is_git_store_path),
234 description: "Stores a git repository: either canonical objects keyed by oid hex, \
235 with the reserved __gunnar_oid__ (stree) / __gunnar_graph__ (commit \
236 graph) / __gunnar_reach__ (reachability bitmaps) sub-indexes, or the \
237 pack tier (pack-<id>.pack / .idx) that preserves the client's deflate \
238 and its delta chains",
239 // `object_size` is UInt32: a git object larger than 4 GiB saturates here; its
240 // exact byte length is the base `uncompressed_size` column (u64, the authority).
241 fields: &[("object_type", Col::Utf8), ("object_size", Col::U32)],
242 commands: &[
243 ("inspect", "Print type/size/sha1/sha256 for a file of canonical git object bytes"),
244 ("lookup", "Resolve an oid against an archive's __gunnar_oid__ index: `git lookup <archive> <oid>`"),
245 ("graph", "Print an archive's commit graph (oid, generation, time, parents)"),
246 ("refs", "Print a live store's ref namespace: `git refs <store-root>`"),
247 ],
248};
249
250impl ArchiveTypePlugin for NativeGitPlugin {
251 fn spec(&self) -> &HandlerSpec {
252 &GIT_SPEC
253 }
254
255 /// **CLI-only string dispatch** (§13.3). A server never comes through here:
256 /// it holds a [`GitStore`] and calls [`GitOps`] directly, typed.
257 ///
258 /// `refs` is what that delegation looks like — open the store, call the trait
259 /// method, print what it returned, and carry no logic of its own. The three
260 /// commands beside it are older and are **archive inspection**, not store
261 /// operations: they read a *sealed* archive's sections, which is a different
262 /// thing from a live store and is deliberately not modelled as a `GitOps`
263 /// call. They are left as they are rather than bent through a trait that does
264 /// not describe them.
265 fn run_command(&self, cmd: &str, args: &[String]) -> anyhow::Result<()> {
266 match cmd {
267 "refs" => {
268 let root = args
269 .first()
270 .ok_or_else(|| anyhow::anyhow!("usage: git refs <store-root>"))?;
271 // Everything below this line is printing. The answer comes from
272 // the trait.
273 let store = GitStore::open(std::path::Path::new(root), "cli")?;
274 for r in store.refs()? {
275 println!(
276 "{}\t{}{}",
277 r.name,
278 r.oid.as_deref().map(hex::encode).unwrap_or_else(|| "-".into()),
279 match (&r.peeled, &r.symref_target) {
280 (Some(p), _) => format!("\t^{}", hex::encode(p)),
281 (None, Some(t)) => format!("\t-> {t}"),
282 (None, None) => String::new(),
283 }
284 );
285 }
286 Ok(())
287 }
288 "inspect" => {
289 let path = args
290 .first()
291 .ok_or_else(|| anyhow::anyhow!("usage: git inspect <object-file>"))?;
292 let data = std::fs::read(path)?;
293 match parse_canonical(&data) {
294 Some(obj) => {
295 println!("type: {}", obj.kind.as_str());
296 println!("size: {}", obj.payload.len());
297 println!("sha1: {}", GitHashKind::Sha1.oid_hex_of(&data));
298 println!("sha256: {}", GitHashKind::Sha256.oid_hex_of(&data));
299 Ok(())
300 }
301 None => anyhow::bail!(
302 "'{path}' is not canonical git object bytes (`<type> <size>\\0<content>`)"
303 ),
304 }
305 }
306 "lookup" => {
307 let (archive, oid) = match (args.first(), args.get(1)) {
308 (Some(a), Some(o)) => (a, o),
309 _ => anyhow::bail!("usage: git lookup <archive> <oid-hex>"),
310 };
311 let index = GitOidIndex::open(std::path::Path::new(archive))?.ok_or_else(|| {
312 anyhow::anyhow!("'{archive}' carries no __gunnar_oid__ index")
313 })?;
314 match index.lookup_hex(oid) {
315 Some(hit) => {
316 println!("oid: {oid}");
317 println!("lookup_row: {}", hit.lookup_row);
318 println!("ordinal: {}", hit.ordinal);
319 Ok(())
320 }
321 None => anyhow::bail!("oid '{oid}' is not in '{archive}'"),
322 }
323 }
324 "graph" => {
325 let archive = args
326 .first()
327 .ok_or_else(|| anyhow::anyhow!("usage: git graph <archive>"))?;
328 let nodes = read_graph(std::path::Path::new(archive))?.ok_or_else(|| {
329 anyhow::anyhow!("'{archive}' carries no __gunnar_graph__ section")
330 })?;
331 println!("commits: {}", nodes.len());
332 for n in &nodes {
333 println!(
334 " {} gen={} time={} parents=[{}]",
335 n.oid,
336 n.generation,
337 n.committer_time.map(|t| t.to_string()).unwrap_or_else(|| "-".into()),
338 n.parents.join(" ")
339 );
340 }
341 Ok(())
342 }
343 other => default_command(self, other, args),
344 }
345 }
346
347 /// A git archive's entries are either **oids** — the whole `relative_path`
348 /// is 40 or 64 lowercase hex characters — or the **packs** of a repository's
349 /// cold tier, `pack-<id>.pack` / `pack-<id>.idx`.
350 ///
351 /// Both are the same ecosystem and so belong to one handler (P-1). Which of
352 /// the two an archive holds is not a variant of the format: it is what the
353 /// writer had. gunnar's `repack()` produces a consolidated pack and seals
354 /// that, because a pack preserves the pushing client's own deflate and its
355 /// delta chains, and an inflated per-oid tier destroys both permanently.
356 fn extract_metadata(&self, path: &str, data: &[u8]) -> Option<ExtensionRow> {
357 if !self.matches_path(path) {
358 return None;
359 }
360 let mut f: HashMap<String, ExtensionValue> = HashMap::new();
361
362 // A pack is typed by its magic, never by its name. A name is a claim
363 // the writer made; the magic is what the bytes are. `pack-<hex>.pack`
364 // over something that is not a packfile degrades to `unknown` exactly
365 // as malformed object bytes do (P-4) — a wrong type in the index is
366 // worse than an honest absence, because it is queried and believed.
367 if let Some(kind) = pack_path_kind(path) {
368 let typed = if data.starts_with(kind.magic()) {
369 kind.as_str()
370 } else {
371 UNKNOWN_OBJECT_TYPE
372 };
373 f.insert("object_type".into(), ExtensionValue::Str(typed.into()));
374 f.insert(
375 "object_size".into(),
376 ExtensionValue::U32(data.len().min(u32::MAX as usize) as u32),
377 );
378 return Some(ExtensionRow { fields: f });
379 }
380
381 match parse_canonical(data) {
382 Some(obj) => {
383 f.insert("object_type".into(), ExtensionValue::Str(obj.kind.as_str().into()));
384 f.insert(
385 "object_size".into(),
386 ExtensionValue::U32(obj.payload.len().min(u32::MAX as usize) as u32),
387 );
388 }
389 None => {
390 // P-4: a decompress bomb, a truncated object or plain garbage
391 // still writes a row — typed `unknown`, sized by what is there.
392 f.insert(
393 "object_type".into(),
394 ExtensionValue::Str(UNKNOWN_OBJECT_TYPE.into()),
395 );
396 f.insert(
397 "object_size".into(),
398 ExtensionValue::U32(data.len().min(u32::MAX as usize) as u32),
399 );
400 }
401 }
402 Some(ExtensionRow { fields: f })
403 }
404}
405
406#[cfg(test)]
407mod tests {
408 use super::*;
409 use crate::object::canonical;
410
411 fn get<'a>(row: &'a ExtensionRow, k: &str) -> Option<&'a ExtensionValue> {
412 row.fields.get(k)
413 }
414
415 #[test]
416 fn claims_oid_paths_and_nothing_else() {
417 let p = NativeGitPlugin::new();
418 assert!(p.matches_path(&"a1b2c3d4".repeat(5))); // 40 hex
419 assert!(p.matches_path(&"0f".repeat(32))); // 64 hex
420 assert!(!p.matches_path("refs/heads/main"));
421 assert!(!p.matches_path("objects/pack/pack-abc.pack"));
422 assert!(!p.matches_path(&"A1B2C3D4".repeat(5)));
423 }
424
425 /// The pack tier's two file names are claimed, and only in the shape git
426 /// itself writes. A bare `.pack` suffix is not enough: an archive of
427 /// arbitrary files must not have its entries retyped as git packs.
428 #[test]
429 fn claims_the_pack_tier_by_its_whole_name_not_by_a_suffix() {
430 let p = NativeGitPlugin::new();
431 let id40 = "a1b2c3d4".repeat(5);
432 let id64 = "0f".repeat(32);
433 assert_eq!(pack_path_kind(&format!("pack-{id40}.pack")), Some(PackFileKind::Data));
434 assert_eq!(pack_path_kind(&format!("pack-{id64}.idx")), Some(PackFileKind::Index));
435 assert!(p.matches_path(&format!("pack-{id64}.pack")));
436 assert!(p.matches_path(&format!("objects/pack/pack-{id40}.idx")));
437
438 for not_ours in [
439 "pack-nothex.pack",
440 "somefile.pack",
441 "pack-.pack",
442 &format!("pack-{id40}.bitmap"),
443 &format!("pack-{}.pack", "A1B2C3D4".repeat(5)),
444 &format!("{id40}.pack"),
445 ] {
446 assert_eq!(pack_path_kind(not_ours), None, "wrongly claimed {not_ours}");
447 }
448 assert!(!p.matches_path("somefile.pack"));
449 }
450
451 /// A pack is typed by its **magic**, never by the name the writer chose.
452 /// A file called `pack-….pack` that does not start with `PACK` is
453 /// `unknown` — the same honest state malformed object bytes get (P-4).
454 #[test]
455 fn a_pack_is_typed_by_its_magic_and_a_liar_is_unknown() {
456 let p = NativeGitPlugin::new();
457 let id = "0f".repeat(32);
458
459 let mut pack = b"PACK".to_vec();
460 pack.extend_from_slice(&2u32.to_be_bytes());
461 pack.extend_from_slice(&7u32.to_be_bytes());
462 let row = p.extract_metadata(&format!("pack-{id}.pack"), &pack).unwrap();
463 assert_eq!(get(&row, "object_type"), Some(&ExtensionValue::Str(PACKFILE_TYPE.into())));
464 assert_eq!(get(&row, "object_size"), Some(&ExtensionValue::U32(pack.len() as u32)));
465
466 let idx = b"\xfftOc\x00\x00\x00\x02".to_vec();
467 let row = p.extract_metadata(&format!("pack-{id}.idx"), &idx).unwrap();
468 assert_eq!(get(&row, "object_type"), Some(&ExtensionValue::Str(PACK_INDEX_TYPE.into())));
469
470 // Now the liars. Each is named as a pack and is not one.
471 for (name, bytes) in [
472 (format!("pack-{id}.pack"), &b"NOTAPACK"[..]),
473 (format!("pack-{id}.idx"), &b"PACK\0\0\0\x02"[..]),
474 (format!("pack-{id}.pack"), &b""[..]),
475 ] {
476 let row = p.extract_metadata(&name, bytes).expect("a claimed path always yields a row");
477 assert_eq!(
478 get(&row, "object_type"),
479 Some(&ExtensionValue::Str(UNKNOWN_OBJECT_TYPE.into())),
480 "{name} carries {bytes:?}, which is not that kind of file — it must not be typed \
481 from its name"
482 );
483 }
484 }
485
486 #[test]
487 fn types_and_sizes_come_from_the_stored_bytes() {
488 let p = NativeGitPlugin::new();
489 let body = b"hello world";
490 let bytes = canonical(GitObjectKind::Blob, body);
491 let oid = GitHashKind::Sha256.oid_hex_of(&bytes);
492 let row = p.extract_metadata(&oid, &bytes).unwrap();
493 assert_eq!(get(&row, "object_type"), Some(&ExtensionValue::Str("blob".into())));
494 assert_eq!(get(&row, "object_size"), Some(&ExtensionValue::U32(body.len() as u32)));
495
496 let commit = canonical(GitObjectKind::Commit, b"tree x\n\nmsg\n");
497 let coid = GitHashKind::Sha1.oid_hex_of(&commit);
498 let crow = p.extract_metadata(&coid, &commit).unwrap();
499 assert_eq!(get(&crow, "object_type"), Some(&ExtensionValue::Str("commit".into())));
500 }
501
502 #[test]
503 fn garbage_degrades_to_unknown_and_never_panics() {
504 let p = NativeGitPlugin::new();
505 let oid = "d".repeat(64);
506 for bad in [&b""[..], &b"\0\0\0"[..], &[0xffu8; 4096][..], &b"blob 99\0short"[..]] {
507 let row = p.extract_metadata(&oid, bad).expect("a claimed path always yields a row");
508 assert_eq!(
509 get(&row, "object_type"),
510 Some(&ExtensionValue::Str(UNKNOWN_OBJECT_TYPE.into())),
511 "unparseable bytes must be typed `unknown`, never guessed"
512 );
513 assert_eq!(get(&row, "object_size"), Some(&ExtensionValue::U32(bad.len() as u32)));
514 }
515 }
516
517 #[test]
518 fn a_path_that_is_not_an_oid_yields_no_row() {
519 let p = NativeGitPlugin::new();
520 assert!(p.extract_metadata("HEAD", b"ref: refs/heads/main\n").is_none());
521 }
522
523 #[test]
524 fn meta_is_the_discovery_record() {
525 let m = NativeGitPlugin::new().meta();
526 assert_eq!(m.name, "git");
527 assert_eq!(m.type_id, GIT_TYPE_ID);
528 assert!(m.aliases.contains(&"gunnar".to_string()));
529 // inspect / lookup / graph / refs + the shared `coords`.
530 assert_eq!(m.commands.len(), 5);
531 assert!(
532 m.commands.iter().any(|c| c.name == "refs"),
533 "the GitOps-delegating command is not advertised"
534 );
535 }
536}