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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
//! RED Tests for TDG --with-git-context CLI flag
//!
//! Sprint 65 Phase 2: CLI integration tests
#[cfg_attr(coverage_nightly, coverage(off))]
#[cfg(test)]
mod tests {
use crate::cli::TdgOutputFormat;
use std::path::PathBuf;
// Helper: Get repository root
fn get_repo_root() -> PathBuf {
let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let mut current = manifest_dir.clone();
loop {
let git_dir = current.join(".git");
if git_dir.exists() && git_dir.join("HEAD").exists() {
return current;
}
if !current.pop() {
return manifest_dir.parent().unwrap().to_path_buf();
}
}
}
// GREEN TEST 1: TdgCommandConfig should have with_git_context field
#[test]
fn test_tdg_command_config_has_with_git_context_field() {
// Arrange
use crate::cli::handlers::tdg_handlers::TdgCommandConfig;
let config = TdgCommandConfig {
path: PathBuf::from("."),
command: None,
format: TdgOutputFormat::Table,
config: None,
quiet: false,
include_components: false,
min_grade: None,
output: None,
with_git_context: true, // Sprint 65
explain: false, // Issue #78
threshold: 10, // Issue #78
baseline: None, // Issue #78
viz: false, // trueno-viz integration
viz_theme: String::from("default"),
};
// Act & Assert
assert!(
config.with_git_context,
"Should have with_git_context field"
);
}
// GREEN TEST 2: TdgCommandConfig with_git_context defaults to false
#[test]
fn test_tdg_command_config_git_context_defaults_false() {
// Arrange
use crate::cli::handlers::tdg_handlers::TdgCommandConfig;
let config = TdgCommandConfig {
path: PathBuf::from("."),
command: None,
format: TdgOutputFormat::Table,
config: None,
quiet: false,
include_components: false,
min_grade: None,
output: None,
with_git_context: false, // Should default to false (backward compat)
explain: false, // Issue #78
threshold: 10, // Issue #78
baseline: None, // Issue #78
viz: false, // trueno-viz integration
viz_theme: String::from("default"),
};
// Act & Assert
assert!(!config.with_git_context, "Should default to false");
}
// RED TEST 3: Analyzer should extract git context when flag enabled
#[test]
#[should_panic(expected = "not implemented")]
fn test_analyzer_extracts_git_context_when_enabled() {
// Arrange
let repo_path = get_repo_root();
let _test_file = repo_path.join("server/src/lib.rs");
// Act: Analyze with with_git_context = true
// This will be implemented in GREEN phase
unimplemented!("Need to implement git context extraction in analyzer");
// Assert
// Result should have git_context populated
}
// RED TEST 4: Analyzer should NOT extract git context when flag disabled
#[test]
#[should_panic(expected = "not implemented")]
fn test_analyzer_skips_git_context_when_disabled() {
// Arrange
let repo_path = get_repo_root();
let _test_file = repo_path.join("server/src/lib.rs");
// Act: Analyze with with_git_context = false (default)
// This will be implemented in GREEN phase
unimplemented!("Need to implement default behavior (no git context)");
// Assert
// Result should have git_context = None
}
// RED TEST 5: Git context should be shown in table format output
#[test]
#[should_panic(expected = "not implemented")]
fn test_table_output_shows_git_context() {
// Arrange
let _repo_path = get_repo_root();
// Act: Run pmat tdg with --with-git-context --format table
// This will be implemented in GREEN phase
unimplemented!("Need to implement table output with git context");
// Assert
// Output should contain:
// - "Git Context:"
// - "Commit:"
// - "Branch:"
// - "Author:"
}
// RED TEST 6: Git context should be included in JSON output
#[test]
#[should_panic(expected = "not implemented")]
fn test_json_output_includes_git_context() {
// Arrange
let _repo_path = get_repo_root();
// Act: Run pmat tdg with --with-git-context --format json
// This will be implemented in GREEN phase
unimplemented!("Need to implement JSON output with git context");
// Assert
// JSON should have "git_context" field with:
// - commit_sha
// - branch
// - author_name
// - author_email
}
// RED TEST 7: --no-git-context flag should explicitly disable
#[test]
#[should_panic(expected = "not implemented")]
fn test_no_git_context_flag_disables_extraction() {
// Arrange
let _repo_path = get_repo_root();
// Act: Run pmat tdg with --no-git-context
// This will be implemented in GREEN phase
unimplemented!("Need to implement --no-git-context flag");
// Assert
// Result should have git_context = None even in git repo
}
// RED TEST 8: Git context extraction should be fast (<100ms overhead)
#[test]
#[should_panic(expected = "not implemented")]
fn test_git_context_extraction_performance() {
// Arrange
let repo_path = get_repo_root();
let _test_file = repo_path.join("server/src/lib.rs");
// Act: Time the git context extraction
unimplemented!("Need to implement performance test");
// Assert
// Git context extraction should add <100ms overhead
}
// RED TEST 9: Git context should work with non-git directories
#[test]
#[should_panic(expected = "not implemented")]
fn test_git_context_graceful_in_non_git_dir() {
use tempfile::TempDir;
// Arrange: Create temp directory (not a git repo)
let _temp_dir = TempDir::new().unwrap();
// Act: Run pmat tdg with --with-git-context in non-git dir
unimplemented!("Need to implement graceful handling of non-git dirs");
// Assert
// Should complete successfully with git_context = None
// Should NOT error
}
// RED TEST 10: Git context in dirty working directory
#[test]
#[should_panic(expected = "not implemented")]
fn test_git_context_in_dirty_working_dir() {
// Arrange
let _repo_path = get_repo_root();
// Act: Run pmat tdg with --with-git-context
// (Working directory may have uncommitted changes)
unimplemented!("Need to implement dirty dir handling");
// Assert
// Git context should still be extracted
// is_clean field should reflect actual state
}
}