spec_driven_docs/
self_depend.rs1pub mod fragments;
16pub mod leftovers;
17pub mod manager;
18pub mod pin;
19pub mod stamp;
20pub mod status;
21pub mod txn;
22pub mod venue;
23
24use crate::domain::manifest::CANON_SOURCE;
25
26pub const BINARY_NAME: &str = "sdd";
28
29pub const SYNC_LINE: &str = "sdd self-depend sync --apply || true";
31
32pub const ENVRC: &str = ".envrc";
34
35#[must_use]
38pub fn coordinates() -> (&'static str, &'static str) {
39 let path = CANON_SOURCE
40 .trim_start_matches("https://github.com/")
41 .trim_end_matches(".git");
42 path.split_once('/').unwrap_or((path, ""))
43}
44
45#[must_use]
47pub fn slug() -> String {
48 let (owner, repo) = coordinates();
49 format!("{owner}/{repo}")
50}
51
52pub fn parse_tag(value: &str) -> Result<semver::Version, String> {
59 let tail = value.trim().rsplit('/').next().unwrap_or(value).trim();
60 let bare = tail.strip_prefix('v').unwrap_or(tail);
61 let version: semver::Version = bare
62 .parse()
63 .map_err(|_| format!("{value} is not a release tag: expected v<major>.<minor>.<patch>"))?;
64 if !version.pre.is_empty() || !version.build.is_empty() {
65 return Err(format!("{value} is not a released triple"));
66 }
67 Ok(version)
68}
69
70#[cfg(test)]
71mod tests {
72 #![allow(clippy::unwrap_used, reason = "a test panics as its failure signal")]
73
74 use super::*;
75
76 #[test]
77 fn the_coordinates_come_from_the_canon_source() {
78 let (owner, repo) = coordinates();
79 assert!(!owner.is_empty());
80 assert_eq!(repo, "spec-driven-docs");
81 assert!(CANON_SOURCE.ends_with(&slug()));
82 }
83
84 #[test]
85 fn a_tag_parses_in_every_spelling() {
86 assert_eq!(parse_tag("v0.2.16").unwrap().to_string(), "0.2.16");
87 assert_eq!(parse_tag("0.2.16").unwrap().to_string(), "0.2.16");
88 assert_eq!(
89 parse_tag("https://example.invalid/releases/tag/v1.2.3")
90 .unwrap()
91 .to_string(),
92 "1.2.3"
93 );
94 assert!(parse_tag("v1.2.3-rc.1").is_err());
95 assert!(parse_tag("latest").is_err());
96 }
97}