1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
//! Deterministic cache key generation
//!
//! This module provides deterministic cache key generation for lifecycle phases,
//! enabling reproducible builds and efficient caching of phase execution results.
//!
//! ## Features
//!
//! - **Deterministic keys**: Same inputs always produce same cache key
//! - **SHA256 hashing**: Uses SHA256 for reliable key generation
//! - **Input tracking**: Includes phase name, commands, environment, and input files
//! - **Reproducible builds**: Enables caching based on actual inputs
//!
//! ## Cache Key Components
//!
//! The cache key includes:
//! - Phase name
//! - Command lines (sorted)
//! - Environment variables (sorted by key)
//! - Input file contents (SHA256 hashes)
//!
//! ## Examples
//!
//! ### Generating a Cache Key
//!
//! ```rust,no_run
//! use crate::lifecycle::cache::cache_key;
//! use crate::lifecycle::Result;
//!
//! # fn main() -> Result<()> {
//! let phase_name = "build";
//! let cmd_lines = vec!["cargo build --release".to_string()];
//! let env = vec![("RUSTFLAGS".to_string(), "-C opt-level=3".to_string())];
//! let inputs = vec!["Cargo.toml".to_string(), "src/main.rs".to_string()];
//!
//! let key = cache_key(phase_name, &cmd_lines, &env, &inputs);
//! println!("Cache key: {}", key);
//! # Ok(())
//! # }
//! ```
//!
//! ### Using Cache Keys for Conditional Execution
//!
//! ```rust,no_run
//! use crate::lifecycle::cache::cache_key;
//! use crate::lifecycle::Result;
//! use std::collections::HashSet;
//!
//! # fn main() -> Result<()> {
//! let mut executed_keys = HashSet::new();
//!
//! let key = cache_key("test", &vec!["cargo test".to_string()], &[], &[]);
//!
//! if !executed_keys.contains(&key) {
//! // Execute phase
//! executed_keys.insert(key);
//! }
//! # Ok(())
//! # }
//! ```
use ;
use ;
use Path;
/// Generate deterministic cache key for a phase
///
/// Cache key is based on:
/// - Phase name
/// - Command lines
/// - Environment variables (sorted)
/// - Input file contents
/// Check if cache is valid for given key
/// Store cache marker
// Unit tests removed - covered by integration_test.rs:
// - test_cache_key_generation (comprehensive cache key testing)
// - test_cache_key_deterministic (determinism verification)
// - test_cache_key_changes_with_inputs (input sensitivity)
// And by behavior_tests.rs cache invalidation contracts