1use serde::Serialize;
17
18use crate::cli::status::StatusArgs;
19use crate::diagnostic::{Diagnostic, Reason};
20use crate::digest::Digest;
21use crate::error::RkError;
22use crate::landing::invariants::{self, InvariantFailure};
23use crate::landing::manifest::{self, Alignment, Manifest};
24use crate::landing::{self, Kind};
25use crate::output::Output;
26use crate::profile::RegistryAnswer;
27use crate::profile::{CapabilityRequests, GitWorkflow, ProfileSnapshot, ReleaseMode};
28use crate::projection::{Candidate, Projection, ProjectionInput, TargetEvidence};
29use crate::stage::CapabilityNote;
30use crate::{assess, embedded, registry};
31
32#[derive(Debug, Serialize)]
34struct Drift {
35 rendered: usize,
37 seeded: usize,
39}
40
41#[derive(Debug, Serialize)]
43struct StalePin {
44 tool: String,
46 landed: String,
48 available: String,
50}
51
52#[derive(Debug, Serialize)]
58struct Warning {
59 code: &'static str,
61 reason: String,
63}
64
65#[derive(Debug, Clone, Serialize)]
70struct SetupProof {
71 state: &'static str,
73 #[serde(skip_serializing_if = "Vec::is_empty")]
75 changed: Vec<String>,
76 #[serde(skip_serializing_if = "Option::is_none")]
78 reason: Option<&'static str>,
79 #[serde(skip_serializing_if = "Option::is_none")]
81 detail: Option<String>,
82}
83
84const SETUP_PROOF_REMEDIATION: &str = "run rk setup check --target ., then rk setup checkpoint --target ., and commit .release-kit/setup-proof.json; a step this forge cannot run goes in setup.excluded_steps with its reason, which keeps the proof complete";
87
88impl SetupProof {
89 fn of(standing: &crate::setup::proof::Standing) -> Self {
90 use crate::setup::proof::Standing;
91 let mut proof = Self {
92 state: standing.word(),
93 changed: Vec::new(),
94 reason: None,
95 detail: None,
96 };
97 match standing {
98 Standing::Stale { differences, .. } => proof.changed.clone_from(differences),
99 Standing::Invalid { reason, detail } => {
100 proof.reason = Some(reason);
101 proof.detail = Some(detail.clone());
102 }
103 Standing::Absent | Standing::Compatible(_) => {}
104 }
105 proof
106 }
107
108 fn failure(&self) -> Option<InvariantFailure> {
111 let (code, reason) = match self.state {
112 "absent" => (
113 "setup-proof-absent",
114 "no .release-kit/setup-proof.json is committed, so nothing proves the forge, the registry, and the bot meet the setup contract".to_owned(),
115 ),
116 "stale" => (
117 "setup-proof-stale",
118 format!(
119 "the committed setup proof was written for another setup contract; changed: {}",
120 self.changed.join(", ")
121 ),
122 ),
123 "invalid" => (
124 "setup-proof-invalid",
125 format!(
126 "the committed setup proof cannot be read: {}: {}",
127 self.reason.unwrap_or("invalid"),
128 self.detail.as_deref().unwrap_or("")
129 ),
130 ),
131 _ => return None,
132 };
133 Some(InvariantFailure {
134 code,
135 destination: crate::setup::proof::PROOF_PATH.to_owned(),
136 reason,
137 remediation: SETUP_PROOF_REMEDIATION,
138 })
139 }
140}
141
142fn setup_proof_of(
146 target: &camino::Utf8PathBuf,
147 manifest: &Manifest,
148) -> Result<Option<SetupProof>, RkError> {
149 if manifest.profile.release.mode != ReleaseMode::Automatic || manifest.profile.forge.is_none() {
150 return Ok(None);
151 }
152 Ok(Some(SetupProof::of(&crate::setup::proof::offline(target)?)))
153}
154
155const NESTED_HOOK_CONFIGURATION: &str = "nested-hook-configuration";
158
159const CODE_SCANNING_LICENCE: &str = "code-scanning-licence";
161
162#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
167#[serde(rename_all = "kebab-case")]
168pub enum Classification {
169 Setup,
171 Migration,
173 NeedsDecision,
175 Adopt,
177 Upgrade,
179 Drift,
181 Current,
183}
184
185impl Classification {
186 #[must_use]
188 pub const fn as_str(self) -> &'static str {
189 match self {
190 Self::Setup => "setup",
191 Self::Migration => "migration",
192 Self::NeedsDecision => "needs-decision",
193 Self::Adopt => "adopt",
194 Self::Upgrade => "upgrade",
195 Self::Drift => "drift",
196 Self::Current => "current",
197 }
198 }
199}
200
201const fn unrecorded(class: assess::Unrecorded) -> Classification {
204 match class {
205 assess::Unrecorded::Adopt => Classification::Adopt,
206 assess::Unrecorded::Assessed(assess::Classification::Greenfield) => Classification::Setup,
207 assess::Unrecorded::Assessed(assess::Classification::Brownfield) => {
208 Classification::Migration
209 }
210 assess::Unrecorded::Assessed(assess::Classification::NeedsDecision) => {
211 Classification::NeedsDecision
212 }
213 }
214}
215
216const fn recorded(alignment: Alignment, clean: bool) -> Option<Classification> {
220 match alignment {
221 Alignment::TargetNewer => None,
222 Alignment::BinaryNewer => Some(Classification::Upgrade),
223 Alignment::Aligned if clean => Some(Classification::Current),
224 Alignment::Aligned => Some(Classification::Drift),
225 }
226}
227
228#[derive(Debug, Clone, Serialize)]
230struct SentinelAt {
231 file: String,
233 line: usize,
235 text: String,
237}
238
239#[derive(Debug, Serialize)]
241struct LegacyPath {
242 path: String,
244 kind: &'static str,
246 active: bool,
248}
249
250fn legacy_state() -> Vec<LegacyPath> {
259 let Some(root) = crate::applog::state_root() else {
260 return Vec::new();
261 };
262 let mut found = Vec::new();
263 if let Ok(entries) = std::fs::read_dir(root.join(LEGACY_PLANS)) {
264 let mut plans: Vec<std::path::PathBuf> = entries
265 .flatten()
266 .filter(|entry| !entry.file_name().to_string_lossy().starts_with('.'))
267 .map(|entry| entry.path())
268 .filter(|path| path.is_dir())
269 .collect();
270 plans.sort();
271 for plan in plans {
272 let active = std::fs::read(plan.join("plan.json"))
273 .ok()
274 .and_then(|bytes| serde_json::from_slice::<serde_json::Value>(&bytes).ok())
275 .is_none_or(|document| document["readiness"].as_str() == Some("ready"));
276 found.push(LegacyPath {
277 path: plan.display().to_string(),
278 kind: "plan",
279 active,
280 });
281 }
282 }
283 let cache = root.join(LEGACY_RELEASE_CACHE);
284 if cache.is_dir() {
285 found.push(LegacyPath {
286 path: cache.display().to_string(),
287 kind: "release-cache",
288 active: false,
289 });
290 }
291 found
292}
293
294const LEGACY_PLANS: &str = "plans";
296
297const LEGACY_RELEASE_CACHE: &str = "release";
299
300const SCHEMA: &str = "rk.status/16";
302
303#[derive(Debug, serde::Serialize)]
305struct ConfigState {
306 state: &'static str,
307 pending: Vec<String>,
308}
309
310fn config_state(config: Option<&crate::config::Config>, record: Option<&Manifest>) -> ConfigState {
311 let pending = config
312 .zip(record)
313 .map_or_else(Vec::new, |(config, record)| {
314 crate::config::pending(config, record)
315 });
316 ConfigState {
317 state: if config.is_none() {
318 "absent"
319 } else if pending.is_empty() {
320 "aligned"
321 } else {
322 "pending"
323 },
324 pending,
325 }
326}
327
328#[derive(Debug, Serialize)]
330struct Report {
331 schema: &'static str,
333 landed: bool,
335 classification: Option<Classification>,
338 git_work_tree: bool,
340 config: ConfigState,
341 #[serde(skip_serializing_if = "Option::is_none")]
343 profile: Option<ProfileSnapshot>,
344 #[serde(skip_serializing_if = "Option::is_none")]
346 git: Option<GitWorkflow>,
347 #[serde(skip_serializing_if = "Option::is_none")]
349 capabilities: Option<CapabilityRequests>,
350 #[serde(skip_serializing_if = "Option::is_none")]
353 selection: Option<Vec<CapabilityNote>>,
354 #[serde(skip_serializing_if = "Option::is_none")]
355 rk_version: Option<String>,
356 #[serde(skip_serializing_if = "Option::is_none")]
357 binary_version: Option<&'static str>,
358 #[serde(skip_serializing_if = "Option::is_none")]
359 alignment: Option<Alignment>,
360 #[serde(skip_serializing_if = "Option::is_none")]
363 pin: Option<PinState>,
364 #[serde(skip_serializing_if = "Option::is_none")]
365 drift: Option<Drift>,
366 #[serde(skip_serializing_if = "Option::is_none")]
368 missing: Option<Vec<String>>,
369 #[serde(skip_serializing_if = "Option::is_none")]
370 stale_pins: Option<Vec<StalePin>>,
371 #[serde(skip_serializing_if = "Option::is_none")]
373 sentinels: Option<usize>,
374 #[serde(skip_serializing_if = "Option::is_none")]
376 sentinel_locations: Option<Vec<SentinelAt>>,
377 #[serde(skip_serializing_if = "Option::is_none")]
381 record_drift: Option<usize>,
382 #[serde(skip_serializing_if = "Option::is_none")]
385 invariant_failures: Option<Vec<InvariantFailure>>,
386 #[serde(skip_serializing_if = "Option::is_none")]
390 warnings: Option<Vec<Warning>>,
391 #[serde(skip_serializing_if = "Option::is_none")]
394 setup_proof: Option<SetupProof>,
395 #[serde(skip_serializing_if = "Option::is_none")]
401 pending: Option<usize>,
402 #[serde(skip_serializing_if = "Option::is_none")]
405 accepted_drift: Option<Vec<AcceptedNote>>,
406 #[serde(skip_serializing_if = "Option::is_none")]
409 stale_accepted_drift: Option<Vec<String>>,
410 #[serde(skip_serializing_if = "Option::is_none")]
412 violations: Option<Vec<String>>,
413 legacy_state: Vec<LegacyPath>,
415 #[serde(skip_serializing_if = "Option::is_none")]
417 migration: Option<OpenMigration>,
418}
419
420#[derive(Debug, Serialize)]
424struct PinState {
425 version: String,
427 #[serde(skip_serializing_if = "Option::is_none")]
429 latest: Option<String>,
430 behind: bool,
432}
433
434fn pin_state(out: Output, target: &camino::Utf8Path) -> Option<PinState> {
437 let version = crate::self_depend::pinned_version(target)?;
438 let key = crate::self_depend::observe(target).ok()?.key();
439 let latest = crate::self_depend::advice::cached_latest(&key)
440 .map(|latest| latest.trim_start_matches('v').to_owned());
441 let warning = crate::self_depend::advice::pending_from_cache(&key, &version);
442 if let Some(warning) = &warning {
443 out.result_line(warning.clone());
444 }
445 Some(PinState {
446 version,
447 latest,
448 behind: warning.is_some(),
449 })
450}
451
452#[derive(Debug, Serialize)]
454struct OpenMigration {
455 id: String,
457 #[serde(skip_serializing_if = "Option::is_none")]
459 workspace: Option<String>,
460 #[serde(skip_serializing_if = "Option::is_none")]
463 unfinished: Option<usize>,
464}
465
466fn open_migration(
471 target: &camino::Utf8Path,
472 config: Option<&crate::config::Config>,
473) -> Option<OpenMigration> {
474 let id = config.and_then(|config| config.migration.clone())?;
475 let workspace = crate::migrate::open_workspace(target).ok().flatten();
476 let unfinished = workspace
477 .as_ref()
478 .filter(|workspace| workspace.join(crate::migrate::REGISTRY_FILE).is_file())
479 .and_then(|workspace| crate::migrate::registry::load(workspace).ok())
480 .map(|registry| {
481 registry
482 .sources
483 .iter()
484 .filter(|source| !source.status.finished())
485 .count()
486 });
487 Some(OpenMigration {
488 id,
489 workspace: workspace.map(|workspace| workspace.to_string()),
490 unfinished,
491 })
492}
493
494fn render_migration(out: Output, migration: Option<&OpenMigration>) {
496 if let Some(migration) = migration {
497 out.result_line(format!(
498 "migration {} is open; rk migrate status reads it",
499 migration.id
500 ));
501 }
502}
503
504fn report_absent(
505 out: Output,
506 args: &StatusArgs,
507 config: Option<&crate::config::Config>,
508 git_work_tree: bool,
509) -> Result<(), RkError> {
510 let migration = open_migration(&args.target, config);
511 let classification = match assess::standing(&args.target, config)? {
512 assess::Standing::Migrating => Classification::Migration,
513 assess::Standing::Unrecorded(class) => unrecorded(class),
514 };
515 let legacy = legacy_state();
516 out.result_line(format!("config: {}", config_state(config, None).state));
517 out.result_line(format!("no landing at {}", args.target));
518 out.result_line(format!("classification: {}", classification.as_str()));
519 render_migration(out, migration.as_ref());
520 render_context(out, git_work_tree, &legacy);
521 let pin = pin_state(out, &args.target);
522 out.next(&[
523 format!(
524 "rk profile --target {} reports what a landing would select",
525 args.target
526 ),
527 format!("rk init --target {} lands the workflow", args.target),
528 format!(
529 "rk adopt --target {} records a landing made before the receipt existed",
530 args.target
531 ),
532 format!(
533 "rk stage --target {} stages this binary's candidate; the rk-setup skill carries the best-effort migration",
534 args.target
535 ),
536 ]);
537 out.emit(&Report {
538 schema: SCHEMA,
539 landed: false,
540 classification: Some(classification),
541 git_work_tree,
542 config: config_state(config, None),
543 profile: None,
544 git: None,
545 capabilities: None,
546 selection: None,
547 rk_version: None,
548 binary_version: None,
549 alignment: None,
550 pin,
551 drift: None,
552 missing: None,
553 stale_pins: None,
554 sentinels: None,
555 sentinel_locations: None,
556 record_drift: None,
557 invariant_failures: None,
558 warnings: None,
559 setup_proof: None,
560 pending: None,
561 accepted_drift: None,
562 stale_accepted_drift: None,
563 violations: args.check.then(|| vec!["no landing".to_owned()]),
564 legacy_state: legacy,
565 migration,
566 })?;
567 if args.check {
568 return Err(RkError::check_failed(
569 Diagnostic::new(
570 Reason::StateDrift,
571 format!("no landing at {}, and --check requires one", args.target),
572 )
573 .expected("a target carrying .release-kit/manifest.json")
574 .action("rk init lands the workflow; rk adopt records an existing landing; rk stage and the rk-setup skill carry the migration"),
575 ));
576 }
577 Ok(())
578}
579
580#[derive(Debug, Clone, Serialize)]
582struct AcceptedNote {
583 destination: String,
585 reason: String,
587}
588
589struct Observed {
591 drift_rendered: Vec<String>,
592 drift_digests: std::collections::BTreeMap<String, String>,
595 drift_reasons: std::collections::BTreeMap<String, String>,
598 drift_accepted: Vec<AcceptedNote>,
600 accepted_stale: Vec<String>,
602 drift_seeded: Vec<String>,
603 parameter_drift: Vec<String>,
606 record_drift: Vec<String>,
611 missing: Vec<String>,
612 stale: Vec<StalePin>,
613 sentinels: Vec<(String, usize, String)>,
614 invariants: Vec<InvariantFailure>,
615 warnings: Vec<Warning>,
617 setup_proof: Option<SetupProof>,
618 incompatible: Vec<String>,
624 pending: Option<Vec<String>>,
628 selection: Option<Vec<CapabilityNote>>,
630}
631
632#[allow(
641 clippy::too_many_lines,
642 reason = "one pass reads the target, judges it, and emits the one report every reader takes"
643)]
644pub fn run(args: &StatusArgs) -> Result<(), RkError> {
645 crate::requirements::require("rk status", &[crate::requirements::Tool::Git])?;
646 let out = Output::new(args.json);
647 if !args.target.is_dir() {
648 return Err(RkError::missing(
649 Diagnostic::new(
650 Reason::TargetNotFound,
651 format!("target {} is not a directory", args.target),
652 )
653 .expected("an existing repository to report on"),
654 ));
655 }
656 let config = crate::config::load(args.target.as_std_path())?;
657 let git_work_tree = assess::git_work_tree(&args.target)?;
658 let Some(manifest) = manifest::load(&args.target)? else {
659 return report_absent(out, args, config.as_ref(), git_work_tree);
660 };
661 if manifest
666 .profile
667 .release
668 .build
669 .as_ref()
670 .is_some_and(|build| build.command.is_some())
671 {
672 return Err(crate::profile::retired_build_command());
673 }
674
675 let migration = open_migration(&args.target, config.as_ref());
676 let accepted = config
677 .as_ref()
678 .map(|config| config.landing.accepted_drift.clone())
679 .unwrap_or_default();
680 let stated = Stated::of(config.as_ref(), &manifest);
681 let config = config_state(config.as_ref(), Some(&manifest));
682 out.result_line(format!("config: {}", config.state));
683 for key in &config.pending {
684 out.result_line(format!(
685 "config pending: {key}; rk upgrade --apply takes it up"
686 ));
687 }
688 let mut observed = observe(args, &manifest, &stated)?;
689 accept(&mut observed, &manifest, &accepted)?;
690 observed.setup_proof = setup_proof_of(&args.target, &manifest)?;
691 let alignment = manifest::alignment(&manifest.rk_version, env!("CARGO_PKG_VERSION"));
692 render_human(out, args, &manifest, alignment, &observed);
693 let pin = pin_state(out, &args.target);
694
695 let violations = violations_of(&observed);
696 let classification = if migration.is_some() && alignment != Alignment::TargetNewer {
700 Some(Classification::Migration)
701 } else {
702 recorded(alignment, violations.is_empty())
703 };
704 out.result_line(format!(
705 "classification: {}",
706 classification.map_or(
707 "none: the record is newer than this binary",
708 Classification::as_str
709 )
710 ));
711 render_migration(out, migration.as_ref());
712 let legacy = legacy_state();
713 render_context(out, git_work_tree, &legacy);
714 out.emit(&Report {
715 schema: SCHEMA,
716 landed: true,
717 classification,
718 git_work_tree,
719 config,
720 profile: Some(manifest.profile.clone()),
721 git: Some(manifest.git.clone()),
722 capabilities: Some(manifest.capabilities.clone()),
723 selection: observed.selection.clone(),
724 rk_version: Some(manifest.rk_version),
725 binary_version: Some(env!("CARGO_PKG_VERSION")),
726 alignment: Some(alignment),
727 pin,
728 drift: Some(Drift {
729 rendered: observed.drift_rendered.len() + observed.parameter_drift.len(),
730 seeded: observed.drift_seeded.len(),
731 }),
732 record_drift: Some(observed.record_drift.len()),
733 missing: Some(observed.missing.clone()),
734 stale_pins: Some(observed.stale),
735 sentinels: Some(observed.sentinels.len()),
736 sentinel_locations: Some(
737 observed
738 .sentinels
739 .iter()
740 .map(|(file, line, text)| SentinelAt {
741 file: file.clone(),
742 line: *line,
743 text: text.clone(),
744 })
745 .collect(),
746 ),
747 invariant_failures: Some(observed.invariants),
748 warnings: Some(observed.warnings),
749 setup_proof: observed.setup_proof.clone(),
750 pending: observed.pending.as_ref().map(Vec::len),
751 accepted_drift: Some(observed.drift_accepted.clone()),
752 stale_accepted_drift: Some(observed.accepted_stale.clone()),
753 violations: args.check.then(|| violations.clone()),
754 legacy_state: legacy,
755 migration,
756 })?;
757
758 if args.check && !violations.is_empty() {
759 return Err(RkError::check_failed(
760 Diagnostic::new(
761 Reason::StateDrift,
762 format!(
763 "the landing is not clean: {} violation{}",
764 violations.len(),
765 if violations.len() == 1 { "" } else { "s" }
766 ),
767 )
768 .expected(
769 "no rendered drift, no missing recorded file, no unresolved sentinel, no invariant failure",
770 ),
771 ));
772 }
773 Ok(())
774}
775
776fn render_context(out: Output, git_work_tree: bool, legacy: &[LegacyPath]) {
780 if !git_work_tree {
781 out.result_line("not a non-bare Git work tree: the method lands files a work tree commits");
782 }
783 for entry in legacy {
784 out.result_line(format!(
785 "LEGACY {} ({}, {})",
786 entry.path,
787 entry.kind,
788 if entry.active { "active" } else { "inactive" }
789 ));
790 }
791}
792
793fn accept(
803 observed: &mut Observed,
804 manifest: &Manifest,
805 accepted: &std::collections::BTreeMap<String, crate::config::AcceptedDrift>,
806) -> Result<(), RkError> {
807 for (destination, entry) in accepted {
808 let Some(file) = manifest.file(destination) else {
809 return Err(crate::config::invalid(format!(
810 "landing.accepted_drift names {destination}, which the receipt does not record"
811 )));
812 };
813 if file.kind != Kind::Rendered || file.placement != manifest::Placement::Whole {
814 return Err(crate::config::invalid(format!(
815 "landing.accepted_drift names {destination}, which is not a whole rendered file: only such a file has bytes release-kit owns whole"
816 )));
817 }
818 if !observed.drift_rendered.contains(destination) {
819 if !observed.missing.contains(destination) {
820 observed.accepted_stale.push(destination.clone());
821 }
822 continue;
823 }
824 if observed.drift_digests.get(destination) == Some(&entry.sha256) {
825 observed.drift_rendered.retain(|path| path != destination);
826 observed.drift_accepted.push(AcceptedNote {
827 destination: destination.clone(),
828 reason: entry.reason.clone(),
829 });
830 } else {
831 observed
832 .drift_reasons
833 .insert(destination.clone(), entry.reason.clone());
834 }
835 }
836 Ok(())
837}
838
839fn violations_of(observed: &Observed) -> Vec<String> {
843 observed
844 .drift_rendered
845 .iter()
846 .map(|path| {
847 let digest = observed.drift_digests.get(path).map_or("", String::as_str);
848 observed.drift_reasons.get(path).map_or_else(
849 || format!("rendered drift: {path}; its sha256 is {digest}"),
850 |reason| {
851 format!(
852 "rendered drift: {path}, edited past its accepted drift ({reason}); its sha256 is now {digest}"
853 )
854 },
855 )
856 })
857 .chain(
858 observed
859 .parameter_drift
860 .iter()
861 .map(|path| format!("parameter drift: {path}")),
862 )
863 .chain(
864 observed
865 .record_drift
866 .iter()
867 .map(|reason| format!("record drift: {reason}")),
868 )
869 .chain(
870 observed
871 .missing
872 .iter()
873 .map(|path| format!("missing: {path}")),
874 )
875 .chain(
876 observed
877 .sentinels
878 .iter()
879 .map(|(path, line, _)| format!("sentinel: {path}:{line}")),
880 )
881 .chain(
882 observed
883 .invariants
884 .iter()
885 .map(|failure| format!("invariant: {}: {}", failure.destination, failure.code)),
886 )
887 .chain(
888 observed
889 .setup_proof
890 .as_ref()
891 .and_then(SetupProof::failure)
892 .map(|failure| format!("setup proof: {}", failure.code)),
893 )
894 .collect()
895}
896
897struct Stated {
900 registry: Option<RegistryAnswer>,
902 required_check: String,
904}
905
906impl Stated {
907 fn of(config: Option<&crate::config::Config>, manifest: &Manifest) -> Self {
908 Self {
909 registry: config
910 .and_then(|config| config.profile.release.registry)
911 .or(manifest.profile.release.registry),
912 required_check: config.map_or_else(
915 || manifest.parameters.required_check.clone(),
916 |config| config.setup.required_check.clone(),
917 ),
918 }
919 }
920}
921
922#[allow(
925 clippy::too_many_lines,
926 reason = "one pass over the record and the disk answers every comparison the report states"
927)]
928fn observe(args: &StatusArgs, manifest: &Manifest, stated: &Stated) -> Result<Observed, RkError> {
929 let mut observed = Observed {
930 drift_rendered: Vec::new(),
931 drift_digests: std::collections::BTreeMap::new(),
932 drift_reasons: std::collections::BTreeMap::new(),
933 drift_accepted: Vec::new(),
934 accepted_stale: Vec::new(),
935 drift_seeded: Vec::new(),
936 parameter_drift: Vec::new(),
937 record_drift: Vec::new(),
938 missing: Vec::new(),
939 stale: Vec::new(),
940 sentinels: Vec::new(),
941 invariants: Vec::new(),
942 warnings: Vec::new(),
943 setup_proof: None,
944 incompatible: Vec::new(),
945 pending: None,
946 selection: None,
947 };
948 let aligned =
954 manifest::alignment(&manifest.rk_version, env!("CARGO_PKG_VERSION")) == Alignment::Aligned;
955 let projected = match project(args, manifest) {
956 Ok(projection) => Some(projection),
957 Err(err) if aligned => return Err(err),
958 Err(_) => None,
959 };
960 for file in &manifest.files {
961 let Some(bytes) = landing::read_recorded(&args.target, &file.destination)? else {
962 observed.missing.push(file.destination.clone());
963 continue;
964 };
965 if Digest::of(&bytes) != file.sha256 {
966 match file.kind {
967 Kind::Rendered => {
968 observed.drift_rendered.push(file.destination.clone());
969 observed
970 .drift_digests
971 .insert(file.destination.clone(), Digest::of(&bytes).to_string());
972 }
973 Kind::Seeded => observed.drift_seeded.push(file.destination.clone()),
974 Kind::State => {}
975 }
976 }
977 observed.invariants.extend(invariants::failures(
978 manifest.profile.release.driver.as_deref().unwrap_or(""),
979 manifest.profile.forge.as_deref().unwrap_or(""),
980 &file.destination,
981 &bytes,
982 stated.registry,
983 ));
984 let text = String::from_utf8_lossy(&bytes);
985 for (idx, line) in text.lines().enumerate() {
986 if line.contains(embedded::SENTINEL) {
987 observed.sentinels.push((
988 file.destination.clone(),
989 idx + 1,
990 line.trim().to_owned(),
991 ));
992 }
993 }
994 let defective = projected.as_ref().is_some_and(|projection| {
999 projection
1000 .collisions
1001 .iter()
1002 .any(|collision| collision.destination == file.destination)
1003 });
1004 if defective && !observed.drift_rendered.contains(&file.destination) {
1005 observed.drift_rendered.push(file.destination.clone());
1006 }
1007 }
1008 observed.invariants.extend(invariants::target_failures(
1013 manifest.profile.release.driver.as_deref().unwrap_or(""),
1014 manifest.profile.forge.as_deref().unwrap_or(""),
1015 &args.target,
1016 ));
1017 if manifest.profile.release.driver.as_deref() == Some("rust")
1020 && manifest.profile.forge.as_deref() == Some("github")
1021 {
1022 let dev_run = manifest
1023 .parameters
1024 .dev_environment
1025 .as_ref()
1026 .map_or("", |answer| answer.run.as_str());
1027 let gate = invariants::dist_targets_built(&args.target, &stated.required_check, dev_run);
1028 observed.invariants.extend(gate.failures);
1029 observed.warnings.extend(
1030 gate.limitations
1031 .into_iter()
1032 .map(|(code, reason)| Warning { code, reason }),
1033 );
1034 }
1035 observed.selection = projected.as_ref().map(|projection| {
1036 projection
1037 .capabilities
1038 .iter()
1039 .map(|selection| CapabilityNote::of(selection, projection))
1040 .collect()
1041 });
1042 if let Some(reason) = projected
1043 .as_ref()
1044 .and_then(|projection| projection.licence_refusal.clone())
1045 {
1046 observed.warnings.push(Warning {
1047 code: CODE_SCANNING_LICENCE,
1048 reason,
1049 });
1050 }
1051 for path in crate::hooks::unexcluded_nested_configs(args.target.as_std_path()) {
1054 observed.warnings.push(Warning {
1055 code: NESTED_HOOK_CONFIGURATION,
1056 reason: format!(
1057 "{path} is a hook configuration below the root, which prek runs as a project of its own; where it is no hook configuration of this project, list its directory in a root .prekignore"
1058 ),
1059 });
1060 }
1061 if let Some(projection) = projected.as_ref() {
1066 observed.incompatible.clone_from(&projection.record_defects);
1067 observed
1068 .record_drift
1069 .extend(projection.record_defects.iter().cloned());
1070 }
1071 if aligned && let Some(projection) = projected.as_ref() {
1072 observe_parameter_drift(manifest, projection, &mut observed);
1073 observe_record_set(manifest, projection, &mut observed.record_drift);
1074 }
1075 observed.pending = projected
1080 .as_ref()
1081 .map(|projection| pending_of(manifest, &projection.candidates));
1082 for (tool, landed) in &manifest.pins {
1086 if let Some(available) = registry::version_of(tool)
1087 && manifest::version_is_newer(&available, landed)
1088 {
1089 observed.stale.push(StalePin {
1090 tool: tool.clone(),
1091 landed: landed.clone(),
1092 available,
1093 });
1094 }
1095 }
1096 Ok(observed)
1097}
1098
1099fn observe_parameter_drift(manifest: &Manifest, projection: &Projection, observed: &mut Observed) {
1111 for candidate in &projection.candidates {
1112 if candidate.kind != Kind::Rendered {
1113 continue;
1114 }
1115 let Some(record) = manifest.file(&candidate.destination) else {
1116 continue;
1117 };
1118 if observed.drift_rendered.contains(&candidate.destination)
1119 || observed.missing.contains(&candidate.destination)
1120 {
1121 continue;
1122 }
1123 if Digest::of(recorded_form(candidate)) != record.sha256 {
1124 observed
1125 .parameter_drift
1126 .push(format!("{} (parameters)", candidate.destination));
1127 }
1128 }
1129}
1130
1131fn project(args: &StatusArgs, manifest: &Manifest) -> Result<Projection, RkError> {
1135 let evidence = TargetEvidence::gather(&args.target, Some(manifest))?;
1136 Projection::compute(&ProjectionInput {
1137 params: landing::Params::from_record(manifest),
1138 evidence,
1139 })
1140}
1141
1142fn recorded_form(candidate: &Candidate) -> &[u8] {
1145 candidate.region.as_deref().unwrap_or(&candidate.bytes)
1146}
1147
1148fn pending_of(manifest: &Manifest, projected: &[Candidate]) -> Vec<String> {
1157 let mut pending = Vec::new();
1158 for entry in projected {
1159 let changed = manifest.file(&entry.destination).is_none_or(|record| {
1160 record.kind != entry.kind
1161 || (entry.kind == Kind::Rendered
1162 && record.sha256 != Digest::of(recorded_form(entry)))
1163 });
1164 if changed {
1165 pending.push(entry.destination.clone());
1166 }
1167 }
1168 for file in &manifest.files {
1169 if !projected
1170 .iter()
1171 .any(|entry| entry.destination == file.destination)
1172 {
1173 pending.push(file.destination.clone());
1174 }
1175 }
1176 pending.sort();
1177 pending.dedup();
1178 pending
1179}
1180
1181fn observe_record_set(
1193 manifest: &Manifest,
1194 projection: &Projection,
1195 record_drift: &mut Vec<String>,
1196) {
1197 for entry in &projection.candidates {
1198 if manifest.file(&entry.destination).is_none() {
1199 record_drift.push(format!(
1200 "the recorded parameters project {}, which the receipt does not name",
1201 entry.destination
1202 ));
1203 }
1204 }
1205 for file in &manifest.files {
1206 let produced = projection
1207 .candidates
1208 .iter()
1209 .any(|entry| entry.destination == file.destination)
1210 || projection
1211 .omissions
1212 .iter()
1213 .any(|omission| omission.destination == file.destination);
1214 if !produced {
1215 record_drift.push(format!(
1216 "the receipt names {}, which the recorded parameters do not project",
1217 file.destination
1218 ));
1219 }
1220 }
1221}
1222
1223#[allow(
1225 clippy::too_many_lines,
1226 reason = "one pass prints every reportable condition in the order the report states them"
1227)]
1228fn render_human(
1229 out: Output,
1230 args: &StatusArgs,
1231 manifest: &Manifest,
1232 alignment: Alignment,
1233 observed: &Observed,
1234) {
1235 out.result_line(format!(
1236 "release-kit {} at {}: {}",
1237 manifest.rk_version,
1238 args.target,
1239 crate::commands::profile::describe(
1240 &manifest.profile,
1241 &manifest.git,
1242 &manifest.capabilities,
1243 &manifest.parameters.repo
1244 )
1245 ));
1246 for note in observed.selection.iter().flatten() {
1250 if note.status != "selected" {
1251 out.result_line(format!(
1252 "capability {}: {}{}",
1253 note.id,
1254 note.status,
1255 note.reason
1256 .as_deref()
1257 .map_or_else(String::new, |reason| format!(" ({reason})"))
1258 ));
1259 }
1260 }
1261 if alignment == Alignment::TargetNewer {
1262 out.result_line(format!(
1263 "binary {} is older than this landing; run the rk of the project's own environment, or move its pin with rk self-depend sync --apply",
1264 env!("CARGO_PKG_VERSION")
1265 ));
1266 }
1267 match observed.pending.as_deref() {
1268 None => out.result_line(format!(
1269 "this binary carries no projection for the recorded {} release on {}, so what an upgrade would change is unknown",
1270 manifest
1271 .profile
1272 .release
1273 .driver
1274 .as_deref()
1275 .unwrap_or("release-less"),
1276 manifest.profile.forge.as_deref().unwrap_or("no forge")
1277 )),
1278 Some(paths) => {
1279 for path in paths {
1280 out.result_line(format!("PENDING {path} (this binary would change it)"));
1281 }
1282 }
1283 }
1284 for path in &observed.drift_rendered {
1285 let digest = observed.drift_digests.get(path).map_or("", String::as_str);
1286 out.result_line(observed.drift_reasons.get(path).map_or_else(
1287 || {
1288 format!(
1289 "DRIFT {path} (rendered, release-kit-owned): sha256 {digest}; a deliberate edit is accepted under landing.accepted_drift with its reason and this digest"
1290 )
1291 },
1292 |reason| {
1293 format!(
1294 "DRIFT {path} (rendered, edited past its accepted drift: {reason}; sha256 now {digest})"
1295 )
1296 },
1297 ));
1298 }
1299 for note in &observed.drift_accepted {
1300 out.result_line(format!(
1301 "ACCEPTED {} (rendered, accepted drift: {})",
1302 note.destination, note.reason
1303 ));
1304 }
1305 for path in &observed.accepted_stale {
1306 out.result_line(format!(
1307 "STALE landing.accepted_drift entry for {path}: the file matches the receipt, so the entry can go"
1308 ));
1309 }
1310 for path in &observed.parameter_drift {
1311 out.result_line(format!(
1312 "DRIFT {path}: the recorded parameters do not render the recorded bytes"
1313 ));
1314 }
1315 for reason in &observed.record_drift {
1316 out.result_line(format!("DRIFT record: {reason}"));
1317 }
1318 for path in &observed.drift_seeded {
1319 out.result_line(format!("DRIFT {path} (seeded, target-owned)"));
1320 }
1321 for path in &observed.missing {
1322 out.result_line(format!("MISSING {path}"));
1323 }
1324 for pin in &observed.stale {
1325 out.result_line(format!(
1326 "STALE {} {} landed, {} in this binary",
1327 pin.tool, pin.landed, pin.available
1328 ));
1329 }
1330 for (path, line, text) in &observed.sentinels {
1331 out.result_line(format!("SENTINEL {path}:{line}: {text}"));
1332 }
1333 for failure in &observed.invariants {
1334 out.result_line(format!(
1335 "INVARIANT {} ({}): {}",
1336 failure.destination, failure.code, failure.reason
1337 ));
1338 }
1339 for warning in &observed.warnings {
1340 out.result_line(format!("WARNING ({}): {}", warning.code, warning.reason));
1341 }
1342 let proof_failure = observed.setup_proof.as_ref().and_then(SetupProof::failure);
1343 if let Some(proof) = &observed.setup_proof {
1344 out.result_line(format!("setup proof: {}", proof.state));
1345 }
1346 if let Some(failure) = &proof_failure {
1347 out.result_line(format!(
1348 "SETUP-PROOF ({}): {}",
1349 failure.code, failure.reason
1350 ));
1351 }
1352 let mut next = Vec::new();
1353 for failure in observed.invariants.iter().chain(&proof_failure) {
1354 next.push(format!("{}: {}", failure.destination, failure.remediation));
1355 }
1356 if !observed.incompatible.is_empty() {
1360 next.push(format!(
1361 "rk upgrade --release-mode none --target {} retires the release intent this target cannot run; name a driver and forge this release carries to keep one",
1362 args.target
1363 ));
1364 }
1365 if observed.record_drift.len() > observed.incompatible.len() {
1366 next.push(format!(
1367 "rk upgrade --target {} rewrites the receipt from its parameters",
1368 args.target
1369 ));
1370 }
1371 if observed
1372 .pending
1373 .as_deref()
1374 .is_none_or(|paths| !paths.is_empty())
1375 {
1376 next.push(format!(
1377 "rk upgrade --target {} takes this landing to {}",
1378 args.target,
1379 env!("CARGO_PKG_VERSION")
1380 ));
1381 }
1382 next.push(format!(
1383 "rk status --check --target {} exits 1 on a violation",
1384 args.target
1385 ));
1386 if manifest.profile.release.mode != ReleaseMode::Automatic {
1387 next.retain(|line| !line.contains("rk method operate"));
1388 }
1389 out.next(&next);
1390}
1391
1392#[cfg(test)]
1393mod tests {
1394 use super::{
1395 Classification, Drift, InvariantFailure, LegacyPath, OpenMigration, Report, SentinelAt,
1396 StalePin,
1397 };
1398 use crate::assess::{self, Facts, OwnLanding, Unrecorded};
1399 use crate::landing::CheckoutMode;
1400 use crate::landing::Integration;
1401 use crate::landing::manifest::Alignment;
1402 use crate::profile::{
1403 CapabilityRequests, GitWorkflow, ProfileSnapshot, ReleaseIntent, ReleaseMode,
1404 };
1405
1406 #[test]
1409 fn accepted_drift_does_not_silence_an_invariant() {
1410 let destination = ".gitlab-ci.yml".to_owned();
1411 let digest = "a".repeat(64);
1412 let mut observed = super::Observed {
1413 drift_rendered: vec![destination.clone()],
1414 drift_digests: std::iter::once((destination.clone(), digest.clone())).collect(),
1415 drift_reasons: std::collections::BTreeMap::new(),
1416 drift_accepted: Vec::new(),
1417 accepted_stale: Vec::new(),
1418 drift_seeded: Vec::new(),
1419 parameter_drift: Vec::new(),
1420 record_drift: Vec::new(),
1421 missing: Vec::new(),
1422 stale: Vec::new(),
1423 sentinels: Vec::new(),
1424 invariants: vec![crate::landing::invariants::InvariantFailure {
1425 code: "an-invariant",
1426 destination: destination.clone(),
1427 reason: "the accepted bytes break it".to_owned(),
1428 remediation: "restore it",
1429 }],
1430 warnings: Vec::new(),
1431 setup_proof: None,
1432 incompatible: Vec::new(),
1433 pending: None,
1434 selection: None,
1435 };
1436 let manifest: crate::landing::manifest::Manifest = serde_json::from_str(&format!(
1437 r#"{{"schema_version":12,"rk_version":"0.1.0","origin":"init","landed_at":"2026-08-29T00:00:00Z","profile":{{"technologies":["bash"],"forge":"gitlab","release":{{"mode":"automatic","driver":"bash","style":"trunk","line_prefix":"release/"}}}},"git":{{"trunk":"master","checkout_mode":"linked-worktree","integration":"local","merge_form":"squash"}},"capabilities":{{"nix_packaging":false,"reporting_policy":true,"scorecard":false,"workflow_guards":false}},"parameters":{{"repo":"acme/widget"}},"files":[{{"destination":".gitlab-ci.yml","kind":"rendered","sha256":"{}"}}],"pins":{{}}}}"#,
1438 crate::digest::Digest::of(b"candidate")
1439 ))
1440 .expect("the record parses");
1441 let accepted = std::iter::once((
1442 destination,
1443 crate::config::AcceptedDrift {
1444 reason: "deliberate".to_owned(),
1445 sha256: digest,
1446 },
1447 ))
1448 .collect();
1449 super::accept(&mut observed, &manifest, &accepted).expect("accepts");
1450 assert!(observed.drift_rendered.is_empty());
1451 let violations = super::violations_of(&observed);
1452 assert!(
1453 violations.iter().any(|line| line.contains("an-invariant")),
1454 "{violations:?}"
1455 );
1456 }
1457
1458 #[test]
1461 #[allow(
1462 clippy::too_many_lines,
1463 reason = "the snapshot states every field of both forms in one place"
1464 )]
1465 fn the_status_report_schema_snapshot_holds() {
1466 let landed = Report {
1467 schema: super::SCHEMA,
1468 landed: true,
1469 classification: Some(Classification::Upgrade),
1470 git_work_tree: true,
1471 config: super::ConfigState {
1472 state: "pending",
1473 pending: vec!["profile.release.style".into()],
1474 },
1475 profile: Some(ProfileSnapshot {
1476 technologies: vec!["rust".into()],
1477 forge: Some("github".into()),
1478 release: ReleaseIntent {
1479 mode: ReleaseMode::Automatic,
1480 driver: Some("rust".into()),
1481 style: Some(crate::landing::Style::Trunk),
1482 line_prefix: Some("release/".into()),
1483 registry: None,
1484 build: None,
1485 },
1486 }),
1487 git: Some(GitWorkflow {
1488 trunk: "master".into(),
1489 checkout_mode: CheckoutMode::LinkedWorktree,
1490 integration: Integration::Local,
1491 merge_form: crate::landing::MergeForm::Squash,
1492 }),
1493 capabilities: Some(CapabilityRequests {
1494 nix_packaging: true,
1495 reporting_policy: true,
1496 scorecard: false,
1497 code_scanning: Some(crate::landing::Provider::Semgrep),
1498 workflow_guards: Some(false),
1499 }),
1500 selection: Some(vec![]),
1501 rk_version: Some("0.1.0".into()),
1502 binary_version: Some("0.2.0"),
1503 alignment: Some(crate::landing::manifest::Alignment::BinaryNewer),
1504 pin: Some(super::PinState {
1505 version: "0.1.0".to_owned(),
1506 latest: Some("0.2.0".to_owned()),
1507 behind: true,
1508 }),
1509 drift: Some(Drift {
1510 rendered: 0,
1511 seeded: 1,
1512 }),
1513 missing: Some(vec![]),
1514 stale_pins: Some(vec![StalePin {
1515 tool: "release-plz".into(),
1516 landed: "0.3.160".into(),
1517 available: "0.3.170".into(),
1518 }]),
1519 sentinels: Some(1),
1520 sentinel_locations: Some(vec![SentinelAt {
1521 file: "release-plz.toml".into(),
1522 line: 18,
1523 text: "# TODO(release-kit): keep false for a binary-only crate".into(),
1524 }]),
1525 record_drift: Some(0),
1526 invariant_failures: Some(vec![InvariantFailure {
1527 code: "attestations-disabled",
1528 destination: "dist-workspace.toml".into(),
1529 reason: "github-attestations is not effectively true".into(),
1530 remediation: "set github-attestations = true in [dist]",
1531 }]),
1532 warnings: Some(vec![super::Warning {
1533 code: super::CODE_SCANNING_LICENCE,
1534 reason: "the target's license, LicenseRef-proprietary, does not state a codebase this release recognizes as open source".into(),
1535 }]),
1536 setup_proof: Some(super::SetupProof {
1537 state: "stale",
1538 changed: vec!["target.required_check".into()],
1539 reason: None,
1540 detail: None,
1541 }),
1542 pending: Some(2),
1543 accepted_drift: Some(vec![super::AcceptedNote {
1544 destination: ".gitlab-ci.yml".into(),
1545 reason: "the image carries a tool".into(),
1546 }]),
1547 stale_accepted_drift: Some(vec![]),
1548 violations: None,
1549 legacy_state: vec![LegacyPath {
1550 path: "/state/release-kit/plans/0123456789abcdef".into(),
1551 kind: "plan",
1552 active: true,
1553 }],
1554 migration: Some(OpenMigration {
1555 id: "20261009T140205Z".into(),
1556 workspace: Some(
1557 "/state/release-kit/migrations/widget-0123456789ab/20261009T140205Z".into(),
1558 ),
1559 unfinished: Some(2),
1560 }),
1561 };
1562 assert_eq!(
1563 serde_json::to_string(&landed).expect("a report serializes"),
1564 r##"{"schema":"rk.status/16","landed":true,"classification":"upgrade","git_work_tree":true,"config":{"state":"pending","pending":["profile.release.style"]},"profile":{"technologies":["rust"],"forge":"github","release":{"mode":"automatic","driver":"rust","style":"trunk","line_prefix":"release/"}},"git":{"trunk":"master","checkout_mode":"linked-worktree","integration":"local","merge_form":"squash"},"capabilities":{"nix_packaging":true,"reporting_policy":true,"scorecard":false,"code_scanning":"semgrep","workflow_guards":false},"selection":[],"rk_version":"0.1.0","binary_version":"0.2.0","alignment":"binary-newer","pin":{"version":"0.1.0","latest":"0.2.0","behind":true},"drift":{"rendered":0,"seeded":1},"missing":[],"stale_pins":[{"tool":"release-plz","landed":"0.3.160","available":"0.3.170"}],"sentinels":1,"sentinel_locations":[{"file":"release-plz.toml","line":18,"text":"# TODO(release-kit): keep false for a binary-only crate"}],"record_drift":0,"invariant_failures":[{"code":"attestations-disabled","destination":"dist-workspace.toml","reason":"github-attestations is not effectively true","remediation":"set github-attestations = true in [dist]"}],"warnings":[{"code":"code-scanning-licence","reason":"the target's license, LicenseRef-proprietary, does not state a codebase this release recognizes as open source"}],"setup_proof":{"state":"stale","changed":["target.required_check"]},"pending":2,"accepted_drift":[{"destination":".gitlab-ci.yml","reason":"the image carries a tool"}],"stale_accepted_drift":[],"legacy_state":[{"path":"/state/release-kit/plans/0123456789abcdef","kind":"plan","active":true}],"migration":{"id":"20261009T140205Z","workspace":"/state/release-kit/migrations/widget-0123456789ab/20261009T140205Z","unfinished":2}}"##
1565 );
1566 let absent = Report {
1567 landed: false,
1568 classification: Some(Classification::Setup),
1569 git_work_tree: false,
1570 config: super::ConfigState {
1571 state: "absent",
1572 pending: vec![],
1573 },
1574 profile: None,
1575 git: None,
1576 capabilities: None,
1577 selection: None,
1578 rk_version: None,
1579 binary_version: None,
1580 alignment: None,
1581 pin: None,
1582 drift: None,
1583 missing: None,
1584 stale_pins: None,
1585 sentinels: None,
1586 sentinel_locations: None,
1587 record_drift: None,
1588 invariant_failures: None,
1589 warnings: None,
1590 setup_proof: None,
1591 pending: None,
1592 accepted_drift: None,
1593 stale_accepted_drift: None,
1594 violations: None,
1595 legacy_state: vec![],
1596 migration: None,
1597 ..landed
1598 };
1599 assert_eq!(
1600 serde_json::to_string(&absent).expect("a report serializes"),
1601 r#"{"schema":"rk.status/16","landed":false,"classification":"setup","git_work_tree":false,"config":{"state":"absent","pending":[]},"legacy_state":[]}"#,
1602 "an absent landing reports the fields a caller can branch on"
1603 );
1604 let newer = Report {
1605 classification: None,
1606 ..absent
1607 };
1608 assert!(
1609 serde_json::to_string(&newer)
1610 .expect("a report serializes")
1611 .contains(r#""classification":null"#),
1612 "no classification is stated as null, never omitted"
1613 );
1614 }
1615
1616 fn facts() -> Facts {
1617 Facts {
1618 technologies: Vec::new(),
1619 forge: None,
1620 repo: None,
1621 release_markers: Vec::new(),
1622 collisions: Vec::new(),
1623 git: true,
1624 tags: 0,
1625 long_lived_branches: Vec::new(),
1626 }
1627 }
1628
1629 #[test]
1634 fn every_classification_has_its_rule() {
1635 let none = OwnLanding::default();
1636 let classify = |facts: &Facts, own: &OwnLanding| {
1637 super::unrecorded(assess::classify_unrecorded(facts, own))
1638 };
1639 assert_eq!(classify(&facts(), &none), Classification::Setup);
1640 let marked = Facts {
1641 release_markers: vec![".goreleaser.yaml".into()],
1642 ..facts()
1643 };
1644 assert_eq!(classify(&marked, &none), Classification::Migration);
1645 let tagged = Facts { tags: 3, ..facts() };
1646 assert_eq!(classify(&tagged, &none), Classification::NeedsDecision);
1647 let own = OwnLanding {
1650 regions: vec!["AGENTS.md".into()],
1651 rendered: Vec::new(),
1652 };
1653 let colliding = Facts {
1654 collisions: vec!["AGENTS.md".into()],
1655 release_markers: vec!["CHANGELOG.md".into()],
1656 ..facts()
1657 };
1658 assert_eq!(classify(&colliding, &own), Classification::Adopt);
1659 assert_eq!(
1660 assess::classify_unrecorded(&colliding, &own),
1661 Unrecorded::Adopt
1662 );
1663 assert_eq!(
1664 super::recorded(Alignment::BinaryNewer, false),
1665 Some(Classification::Upgrade)
1666 );
1667 assert_eq!(
1668 super::recorded(Alignment::Aligned, false),
1669 Some(Classification::Drift)
1670 );
1671 assert_eq!(
1672 super::recorded(Alignment::Aligned, true),
1673 Some(Classification::Current)
1674 );
1675 assert_eq!(super::recorded(Alignment::TargetNewer, true), None);
1676 for (class, word) in [
1677 (Classification::Setup, "setup"),
1678 (Classification::Migration, "migration"),
1679 (Classification::NeedsDecision, "needs-decision"),
1680 (Classification::Adopt, "adopt"),
1681 (Classification::Upgrade, "upgrade"),
1682 (Classification::Drift, "drift"),
1683 (Classification::Current, "current"),
1684 ] {
1685 assert_eq!(class.as_str(), word);
1686 assert_eq!(
1687 serde_json::to_string(&class).expect("serializes"),
1688 format!("\"{word}\"")
1689 );
1690 }
1691 }
1692}