lean_ctx/core/rule_artifacts.rs
1//! The committed `LEAN-CTX.md` rule artifacts as `(relative_path, content)`
2//! pairs — the single source shared by the regenerator (`gen_rules` example)
3//! and the drift gate (`tests/rules_drift.rs`) so the project copy and the
4//! `rust/` copy can never disagree.
5//!
6//! Content is forced to the default profile (non-shadow, compression `Off`) so
7//! the committed bytes are independent of the developer's local lean-ctx config
8//! and stay deterministic (#498). The live writer
9//! (`hooks::ensure_project_agents_integration`) renders with the *user's* config
10//! instead — that is each user's own copy, not this repo's checked-in artifact.
11
12use crate::core::config::CompressionLevel;
13use crate::core::rules_canonical::{self, Wrapper};
14
15/// Project-relative paths of every committed dedicated-rules artifact. Add new
16/// real rule artifacts here — not docs examples or templates.
17pub const ARTIFACT_PATHS: &[&str] = &["LEAN-CTX.md", "rust/LEAN-CTX.md"];
18
19/// Canonical body of a project `LEAN-CTX.md`: the owner banner, the default
20/// dedicated rules block (non-shadow, compression `Off`), and a trailing
21/// newline. Inverse of what the drift gate reads back.
22#[must_use]
23pub fn canonical_body() -> String {
24 format!(
25 "{}\n{}\n",
26 rules_canonical::PROJECT_LEAN_CTX_OWNED_MARKER,
27 rules_canonical::render(false, Wrapper::Dedicated, CompressionLevel::Off)
28 )
29}
30
31/// `(relative_path, content)` for every artifact the generator writes. All
32/// artifacts share one canonical body today; the shape leaves room for
33/// per-path bodies later without changing callers.
34#[must_use]
35pub fn artifacts() -> Vec<(&'static str, String)> {
36 let body = canonical_body();
37 ARTIFACT_PATHS.iter().map(|p| (*p, body.clone())).collect()
38}
39
40#[cfg(test)]
41mod tests {
42 use super::*;
43
44 #[test]
45 fn canonical_body_is_owned_versioned_and_current() {
46 let body = canonical_body();
47 assert!(body.starts_with(rules_canonical::PROJECT_LEAN_CTX_OWNED_MARKER));
48 assert!(body.contains(&format!(
49 "<!-- version: {} -->",
50 rules_canonical::RULES_VERSION
51 )));
52 // The body must carry the v3 guidance it exists to ship.
53 assert!(body.contains("AGENT LOOP"));
54 assert!(body.contains("NAVIGATION PARADOX"));
55 assert!(body.ends_with('\n'));
56 }
57
58 #[test]
59 fn artifacts_cover_every_declared_path() {
60 let arts = artifacts();
61 assert_eq!(arts.len(), ARTIFACT_PATHS.len());
62 for (path, body) in arts {
63 assert!(ARTIFACT_PATHS.contains(&path));
64 assert!(!body.is_empty());
65 }
66 }
67}