Skip to content

Commit ef1d867

Browse files
committed
Refactor API tests for project-scoped endpoints
- Updated tests for projects, search, specs, stats, and validation endpoints to support project-scoped routing. - Enhanced project creation and cleanup logic to handle single and multi-project modes. - Improved schema validation for responses in various tests. - Consolidated test cases to ensure they accurately reflect the new project-scoped structure. - Removed deprecated tests and added new ones to cover the updated API behavior.
1 parent b2b377b commit ef1d867

File tree

31 files changed

+770
-1045
lines changed

31 files changed

+770
-1045
lines changed

rust/leanspec-cli/src/commands/agent.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ use std::process::{Command, Stdio};
1111
/// Supported AI agents
1212
const SUPPORTED_AGENTS: &[&str] = &["claude", "copilot", "aider", "gemini", "cursor", "continue"];
1313

14+
#[allow(clippy::too_many_arguments)]
1415
pub fn run(
1516
specs_dir: &str,
1617
action: &str,

rust/leanspec-cli/src/commands/backfill.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std::fs;
99
use std::path::Path;
1010
use std::process::Command;
1111

12+
#[allow(clippy::too_many_arguments)]
1213
pub fn run(
1314
specs_dir: &str,
1415
specs: Option<Vec<String>>,

rust/leanspec-cli/src/commands/compact.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,12 @@ pub fn run(
3535
validate_ranges(&parsed_removes, total_lines)?;
3636

3737
if dry_run {
38-
display_dry_run(&spec, &content, &parsed_removes)?;
38+
display_dry_run(spec, &content, &parsed_removes)?;
3939
return Ok(());
4040
}
4141

4242
// Execute the compaction
43-
execute_compact(
44-
&readme_path,
45-
&spec,
46-
&content,
47-
&parsed_removes,
48-
output_format,
49-
)?;
43+
execute_compact(&readme_path, spec, &content, &parsed_removes, output_format)?;
5044

5145
Ok(())
5246
}
@@ -270,10 +264,8 @@ fn resolve_spec_path(specs_dir: &str, spec: &str) -> Result<std::path::PathBuf,
270264
let name_str = name.to_string_lossy();
271265

272266
// Match by number prefix (e.g., "045" matches "045-feature")
273-
if name_str.starts_with(spec) || name_str.contains(spec) {
274-
if entry.path().is_dir() {
275-
return Ok(entry.path());
276-
}
267+
if (name_str.starts_with(spec) || name_str.contains(spec)) && entry.path().is_dir() {
268+
return Ok(entry.path());
277269
}
278270
}
279271
}

rust/leanspec-cli/src/commands/examples.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub fn run(output_format: &str) -> Result<(), Box<dyn Error>> {
1919
println!();
2020

2121
for example in &examples {
22-
println!("{} {}", "📁".to_string(), example.name.cyan().bold());
22+
println!("📁 {}", example.name.cyan().bold());
2323
println!(" {}", example.description);
2424
println!(" URL: {}", example.url.dimmed());
2525
println!(" Tags: {}", example.tags.join(", ").dimmed());

rust/leanspec-cli/src/commands/init.rs

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,16 @@ pub fn run(specs_dir: &str, yes: bool, _template: Option<String>) -> Result<(),
1313
// Check if already initialized
1414
if specs_path.exists() && specs_path.is_dir() {
1515
let readme_exists = specs_path.join("README.md").exists();
16-
if !yes {
17-
if readme_exists {
18-
println!(
19-
"{}",
20-
"LeanSpec already initialized in this directory.".yellow()
21-
);
22-
println!(
23-
"Specs directory: {}",
24-
specs_path.display().to_string().cyan()
25-
);
26-
return Ok(());
27-
}
16+
if !yes && readme_exists {
17+
println!(
18+
"{}",
19+
"LeanSpec already initialized in this directory.".yellow()
20+
);
21+
println!(
22+
"Specs directory: {}",
23+
specs_path.display().to_string().cyan()
24+
);
25+
return Ok(());
2826
}
2927
}
3028

rust/leanspec-cli/src/commands/migrate.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use std::error::Error;
77
use std::fs;
88
use std::path::Path;
99

10+
#[allow(clippy::too_many_arguments)]
1011
pub fn run(
1112
specs_dir: &str,
1213
input_path: &str,
@@ -176,9 +177,7 @@ fn migrate_auto(
176177
fs::create_dir_all(&target_dir)?;
177178

178179
// Copy the file
179-
let target_file = if doc.name == "spec.md" {
180-
target_dir.join("README.md")
181-
} else if doc.name == "README.md" {
180+
let target_file = if doc.name == "spec.md" || doc.name == "README.md" {
182181
target_dir.join("README.md")
183182
} else {
184183
target_dir.join(&doc.name)

rust/leanspec-cli/src/commands/split.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,7 @@ pub fn run(
3939
let extractions: Vec<Extraction> = parsed_outputs
4040
.iter()
4141
.map(|output| {
42-
let extracted_lines: Vec<&str> = lines[(output.start - 1)..output.end]
43-
.iter()
44-
.copied()
45-
.collect();
42+
let extracted_lines: Vec<&str> = lines[(output.start - 1)..output.end].to_vec();
4643

4744
Extraction {
4845
file: output.file.clone(),
@@ -341,10 +338,8 @@ fn resolve_spec_path(specs_dir: &str, spec: &str) -> Result<std::path::PathBuf,
341338
let name = entry.file_name();
342339
let name_str = name.to_string_lossy();
343340

344-
if name_str.starts_with(spec) || name_str.contains(spec) {
345-
if entry.path().is_dir() {
346-
return Ok(entry.path());
347-
}
341+
if (name_str.starts_with(spec) || name_str.contains(spec)) && entry.path().is_dir() {
342+
return Ok(entry.path());
348343
}
349344
}
350345
}

rust/leanspec-cli/src/commands/timeline.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub fn run(specs_dir: &str, months: usize, output_format: &str) -> Result<(), Bo
2323
.map(|d| d.format("%Y-%m").to_string())
2424
.unwrap_or_else(|_| "unknown".to_string());
2525

26-
let entry = by_month.entry(month).or_insert(MonthStats::default());
26+
let entry = by_month.entry(month).or_default();
2727
entry.created += 1;
2828

2929
// Count completed specs
@@ -36,9 +36,7 @@ pub fn run(specs_dir: &str, months: usize, output_format: &str) -> Result<(), Bo
3636
if transition.status == SpecStatus::Complete {
3737
// Use chrono format for year-month extraction
3838
let completed_month = transition.at.format("%Y-%m").to_string();
39-
let completed_entry = by_month
40-
.entry(completed_month)
41-
.or_insert(MonthStats::default());
39+
let completed_entry = by_month.entry(completed_month).or_default();
4240
completed_entry.completed_this_month += 1;
4341
}
4442
}

rust/leanspec-cli/src/commands/tokens.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ pub fn run(
242242
.count();
243243

244244
println!();
245-
println!(" {} {} optimal/good", "✅", optimal);
245+
println!(" {} optimal/good", optimal);
246246
if warning > 0 {
247247
println!(" {} {} need attention", "⚠️".yellow(), warning);
248248
}

rust/leanspec-cli/src/commands/update.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::collections::HashMap;
66
use std::error::Error;
77
use std::path::Path;
88

9+
#[allow(clippy::too_many_arguments)]
910
pub fn run(
1011
specs_dir: &str,
1112
spec: &str,

0 commit comments

Comments
 (0)