Skip to content

Commit 18cddbc

Browse files
committed
wip vibing
1 parent c7134b7 commit 18cddbc

File tree

7 files changed

+92
-27
lines changed

7 files changed

+92
-27
lines changed

crates/agent/src/agent/agent_config/parse.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ mod tests {
221221
let resource = "file://project/README.md";
222222
assert_eq!(ResourceKind::parse(resource, &sys).unwrap(), ResourceKind::File {
223223
original: resource,
224-
file_path: "project/README.md".to_string()
224+
file_path: "/home/testuser/project/README.md".to_string()
225225
});
226226

227227
let resource = "file://~/project/**/*.rs";

crates/agent/src/agent/tools/fs_read.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -197,23 +197,28 @@ pub struct FileReadContext {}
197197
mod tests {
198198
use super::*;
199199
use crate::agent::util::test::TestDir;
200-
use crate::util::test::TestProvider;
200+
use crate::util::test::{
201+
TestBase,
202+
TestProvider,
203+
};
201204

202205
#[tokio::test]
203206
async fn test_fs_read_single_file() {
204-
let test_provider = TestProvider::new();
205-
let test_dir = TestDir::new().with_file(("test.txt", "line1\nline2\nline3")).await;
207+
let test_base = TestBase::new()
208+
.await
209+
.with_file(("test.txt", "line1\nline2\nline3"))
210+
.await;
206211

207212
let tool = FsRead {
208213
ops: vec![FsReadOp {
209-
path: test_dir.join("test.txt").to_string_lossy().to_string(),
214+
path: test_base.join("test.txt").to_string_lossy().to_string(),
210215
limit: None,
211216
offset: None,
212217
}],
213218
};
214219

215-
assert!(tool.validate(&test_provider).await.is_ok());
216-
let result = tool.execute(&test_provider).await.unwrap();
220+
assert!(tool.validate(&test_base).await.is_ok());
221+
let result = tool.execute(&test_base).await.unwrap();
217222
assert_eq!(result.items.len(), 1);
218223
if let ToolExecutionOutputItem::Text(content) = &result.items[0] {
219224
assert_eq!(content, "line1\nline2\nline3");
@@ -224,7 +229,7 @@ mod tests {
224229
async fn test_fs_read_with_offset_and_limit() {
225230
let test_provider = TestProvider::new();
226231
let test_dir = TestDir::new()
227-
.with_file(("test.txt", "line1\nline2\nline3\nline4\nline5"))
232+
.with_file_sys(("test.txt", "line1\nline2\nline3\nline4\nline5"), &test_provider)
228233
.await;
229234

230235
let tool = FsRead {
@@ -245,9 +250,9 @@ mod tests {
245250
async fn test_fs_read_multiple_files() {
246251
let test_provider = TestProvider::new();
247252
let test_dir = TestDir::new()
248-
.with_file(("file1.txt", "content1"))
253+
.with_file_sys(("file1.txt", "content1"), &test_provider)
249254
.await
250-
.with_file(("file2.txt", "content2"))
255+
.with_file_sys(("file2.txt", "content2"), &test_provider)
251256
.await;
252257

253258
let tool = FsRead {

crates/agent/src/agent/tools/fs_write.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ mod tests {
393393
#[tokio::test]
394394
async fn test_str_replace_single_occurrence() {
395395
let test_provider = TestProvider::new();
396-
let test_dir = TestDir::new().with_file(("test.txt", "hello world")).await;
396+
let test_dir = TestDir::new().with_file_sys(("test.txt", "hello world"), &test_provider).await;
397397

398398
let tool = FsWrite::StrReplace(StrReplace {
399399
path: test_dir.join("test.txt").to_string_lossy().to_string(),
@@ -411,7 +411,7 @@ mod tests {
411411
#[tokio::test]
412412
async fn test_str_replace_multiple_occurrences() {
413413
let test_provider = TestProvider::new();
414-
let test_dir = TestDir::new().with_file(("test.txt", "foo bar foo")).await;
414+
let test_dir = TestDir::new().with_file_sys(("test.txt", "foo bar foo"), &test_provider).await;
415415

416416
let tool = FsWrite::StrReplace(StrReplace {
417417
path: test_dir.join("test.txt").to_string_lossy().to_string(),
@@ -429,7 +429,7 @@ mod tests {
429429
#[tokio::test]
430430
async fn test_str_replace_no_match() {
431431
let test_provider = TestProvider::new();
432-
let test_dir = TestDir::new().with_file(("test.txt", "hello world")).await;
432+
let test_dir = TestDir::new().with_file_sys(("test.txt", "hello world"), &test_provider).await;
433433

434434
let tool = FsWrite::StrReplace(StrReplace {
435435
path: test_dir.join("test.txt").to_string_lossy().to_string(),
@@ -444,7 +444,7 @@ mod tests {
444444
#[tokio::test]
445445
async fn test_insert_at_line() {
446446
let test_provider = TestProvider::new();
447-
let test_dir = TestDir::new().with_file(("test.txt", "line1\nline2\nline3")).await;
447+
let test_dir = TestDir::new().with_file_sys(("test.txt", "line1\nline2\nline3"), &test_provider).await;
448448

449449
let tool = FsWrite::Insert(Insert {
450450
path: test_dir.join("test.txt").to_string_lossy().to_string(),
@@ -461,7 +461,7 @@ mod tests {
461461
#[tokio::test]
462462
async fn test_insert_append() {
463463
let test_provider = TestProvider::new();
464-
let test_dir = TestDir::new().with_file(("test.txt", "existing")).await;
464+
let test_dir = TestDir::new().with_file_sys(("test.txt", "existing"), &test_provider).await;
465465

466466
let tool = FsWrite::Insert(Insert {
467467
path: test_dir.join("test.txt").to_string_lossy().to_string(),

crates/agent/src/agent/tools/image_read.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ pub fn is_supported_image_type(path: impl AsRef<Path>) -> bool {
230230
mod tests {
231231
use super::*;
232232
use crate::agent::util::test::TestDir;
233+
use crate::util::test::TestProvider;
233234

234235
// Create a minimal valid PNG for testing
235236
fn create_test_png() -> Vec<u8> {
@@ -254,7 +255,9 @@ mod tests {
254255

255256
#[tokio::test]
256257
async fn test_read_valid_image() {
257-
let test_dir = TestDir::new().with_file(("test.png", create_test_png())).await;
258+
let test_dir = TestDir::new()
259+
.with_file_sys(("test.png", create_test_png()), &TestProvider::new())
260+
.await;
258261

259262
let tool = ImageRead {
260263
paths: vec![test_dir.join("test.png").to_string_lossy().to_string()],
@@ -271,10 +274,11 @@ mod tests {
271274

272275
#[tokio::test]
273276
async fn test_read_multiple_images() {
277+
let test_provider = TestProvider::new();
274278
let test_dir = TestDir::new()
275-
.with_file(("image1.png", create_test_png()))
279+
.with_file_sys(("image1.png", create_test_png()), &test_provider)
276280
.await
277-
.with_file(("image2.png", create_test_png()))
281+
.with_file_sys(("image2.png", create_test_png()), &test_provider)
278282
.await;
279283

280284
let tool = ImageRead {
@@ -290,7 +294,9 @@ mod tests {
290294

291295
#[tokio::test]
292296
async fn test_validate_unsupported_format() {
293-
let test_dir = TestDir::new().with_file(("test.txt", "not an image")).await;
297+
let test_dir = TestDir::new()
298+
.with_file_sys(("test.txt", "not an image"), &TestProvider::new())
299+
.await;
294300

295301
let tool = ImageRead {
296302
paths: vec![test_dir.join("test.txt").to_string_lossy().to_string()],

crates/agent/src/agent/tools/ls.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -369,9 +369,9 @@ mod tests {
369369
async fn test_ls_basic_directory() {
370370
let test_provider = TestProvider::new();
371371
let test_dir = TestDir::new()
372-
.with_file(("file1.txt", "content1"))
372+
.with_file_sys(("file1.txt", "content1"), &test_provider)
373373
.await
374-
.with_file(("file2.txt", "content2"))
374+
.with_file_sys(("file2.txt", "content2"), &test_provider)
375375
.await;
376376

377377
let tool = Ls {
@@ -394,9 +394,9 @@ mod tests {
394394
async fn test_ls_recursive() {
395395
let test_provider = TestProvider::new();
396396
let test_dir = TestDir::new()
397-
.with_file(("root.txt", "root"))
397+
.with_file_sys(("root.txt", "root"), &test_provider)
398398
.await
399-
.with_file(("subdir/nested.txt", "nested"))
399+
.with_file_sys(("subdir/nested.txt", "nested"), &test_provider)
400400
.await;
401401

402402
let tool = Ls {
@@ -418,9 +418,9 @@ mod tests {
418418
async fn test_ls_with_ignore_patterns() {
419419
let test_provider = TestProvider::new();
420420
let test_dir = TestDir::new()
421-
.with_file(("keep.txt", "keep"))
421+
.with_file_sys(("keep.txt", "keep"), &test_provider)
422422
.await
423-
.with_file(("ignore.log", "ignore"))
423+
.with_file_sys(("ignore.log", "ignore"), &test_provider)
424424
.await;
425425

426426
let tool = Ls {
@@ -452,7 +452,7 @@ mod tests {
452452
#[tokio::test]
453453
async fn test_ls_validate_file_not_directory() {
454454
let test_provider = TestProvider::new();
455-
let test_dir = TestDir::new().with_file(("file.txt", "content")).await;
455+
let test_dir = TestDir::new().with_file_sys(("file.txt", "content"), &test_provider).await;
456456

457457
let tool = Ls {
458458
path: test_dir.join("file.txt").to_string_lossy().to_string(),

crates/agent/src/agent/util/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,8 @@ mod tests {
202202
async fn test_read_file_with_max_limit() {
203203
// Test file with 30 bytes in length
204204
let test_file = "123456789\n".repeat(3);
205-
let d = TestDir::new().with_file(("test.txt", &test_file)).await;
205+
let test_provider = crate::util::test::TestProvider::new();
206+
let d = TestDir::new().with_file_sys(("test.txt", &test_file), &test_provider).await;
206207

207208
// Test not truncated
208209
let (content, bytes_truncated) = read_file_with_max_limit(d.join("test.txt"), 100, "...").await.unwrap();

crates/agent/src/agent/util/test.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,59 @@ use super::providers::{
1414
SystemProvider,
1515
};
1616

17+
/// Test helper that wraps a temporary directory and test [SystemProvider].
18+
#[derive(Debug)]
19+
pub struct TestBase {
20+
test_dir: TestDir,
21+
provider: TestProvider,
22+
}
23+
24+
impl TestBase {
25+
/// Creates a new temporary directory with the following defaults configured:
26+
/// - env vars: HOME=$tempdir_path/home/testuser
27+
/// - cwd: $tempdir_path
28+
/// - home: $tempdir_path/home/testuser
29+
pub async fn new() -> Self {
30+
let test_dir = TestDir::new();
31+
let home_path = test_dir.path().join("home/testuser");
32+
tokio::fs::create_dir_all(&home_path)
33+
.await
34+
.expect("failed to create test home directory");
35+
let provider = TestProvider::new_with_base(home_path).with_cwd(test_dir.path());
36+
Self { test_dir, provider }
37+
}
38+
39+
/// Returns a resolved path using the generated temporary directory as the base.
40+
pub fn join(&self, path: impl AsRef<Path>) -> PathBuf {
41+
self.test_dir.path().join(path)
42+
}
43+
44+
pub async fn with_file(mut self, file: impl TestFile) -> Self {
45+
self.test_dir = self.test_dir.with_file_sys(file, &self.provider).await;
46+
self
47+
}
48+
}
49+
50+
impl EnvProvider for TestBase {
51+
fn var(&self, input: &str) -> Result<String, VarError> {
52+
self.provider.var(input)
53+
}
54+
}
55+
56+
impl HomeProvider for TestBase {
57+
fn home(&self) -> Option<PathBuf> {
58+
self.provider.home()
59+
}
60+
}
61+
62+
impl CwdProvider for TestBase {
63+
fn cwd(&self) -> Result<PathBuf, std::io::Error> {
64+
self.provider.cwd()
65+
}
66+
}
67+
68+
impl SystemProvider for TestBase {}
69+
1770
#[derive(Debug)]
1871
pub struct TestDir {
1972
temp_dir: tempfile::TempDir,

0 commit comments

Comments
 (0)