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
//! Common utilities for integration tests
//!
//! This module provides shared functionality across all integration tests,
//! ensuring consistency and reducing duplication.
use Command;
use fs;
use PathBuf;
use TempDir;
// Import project initialization function
use ProjectContext;
/// Get the path to the `ie` binary
///
/// This function is compatible with both standard and custom target directories.
/// It first checks the `CARGO_BIN_EXE_ie` environment variable (set by cargo
/// when using custom target directories like in CI coverage tests), and falls
/// back to the standard `cargo_bin!()` macro for local development.
///
/// # Examples
///
/// ```no_run
/// use std::process::Command;
/// mod common;
///
/// let output = Command::new(common::ie_binary())
/// .arg("task")
/// .arg("list")
/// .output()
/// .unwrap();
/// ```
///
/// # Panics
///
/// Panics if the `ie` binary cannot be found in either the environment
/// variable or the standard cargo build directory.
// cargo_bin() is deprecated but needed for fallback
/// Create a Command for `ie` with proper environment isolation
///
/// This returns a Command pre-configured with:
/// - The correct `ie` binary path
/// - Environment isolation (HOME=/nonexistent) to prevent home directory fallback
///
/// # Examples
///
/// ```no_run
/// mod common;
///
/// let output = common::ie_command()
/// .current_dir(&temp_dir)
/// .arg("task")
/// .arg("list")
/// .assert()
/// .success();
/// ```
// Not all test files use this yet
/// Create a Command for `ie` with project directory override
///
/// This returns a Command pre-configured with:
/// - The correct `ie` binary path
/// - Current directory set to the specified directory
/// - Environment isolation (HOME=/nonexistent) to prevent home directory fallback
///
/// # Examples
///
/// ```no_run
/// mod common;
///
/// let output = common::ie_command_with_project_dir(&temp_dir.path())
/// .arg("task")
/// .arg("list")
/// .assert()
/// .success();
/// ```
// Used by MCP tests
/// Setup a test environment with an initialized intent-engine project
///
/// This creates a temporary directory with:
/// - A `.git` marker to prevent fallback to home project
/// - An initialized intent-engine database (via auto-init)
/// - Isolated environment variables to prevent home directory pollution
///
/// # Thread Safety
///
/// This function is thread-safe and can be called concurrently from multiple tests.
/// It uses `ProjectContext::initialize_project_at()` which doesn't rely on the
/// global current directory, avoiding race conditions in parallel test execution.
///
/// # Returns
///
/// A `TempDir` that will be automatically cleaned up when dropped.
///
/// # Examples
///
/// ```no_run
/// mod common;
///
/// #[test]
/// fn test_something() {
/// let temp_dir = common::setup_test_env();
/// // Use temp_dir for testing...
/// }
/// ```
// Not all test files use this yet
/// Get the current project directory for MCP tests
///
/// Since MCP server requires a fully initialized project and doesn't support
/// creating fresh projects easily, we use the current project directory
/// which is already properly set up.
// Used by MCP tests