Skip to content

Commit 67dbb81

Browse files
author
alpsla
committed
rex(#4): Create Live Test Fixture - Rust
1 parent 6ac6281 commit 67dbb81

30 files changed

Lines changed: 397 additions & 4 deletions

packages/agents/src/fix-agent/__tests__/fixtures/live-test-rust/Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[package]
2+
name = "live-test-rust"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
[[bin]]
7+
name = "live-test-rust"
8+
path = "main.rs"
9+
10+
[dependencies]
Lines changed: 285 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,285 @@
1+
/*
2+
Live Test Rust File for Tier 2 Native Fixer Validation
3+
4+
This file contains INTENTIONAL issues that should be fixed by various tiers:
5+
6+
Tier 1/2 (rustfmt):
7+
- Inconsistent indentation
8+
- Missing/extra whitespace
9+
- Bad brace placement
10+
- Long lines that should be wrapped
11+
- Bad formatting in match arms
12+
- Inconsistent spacing around operators
13+
14+
Tier 2 (clippy --fix):
15+
- needless_return: Explicit return where implicit would work
16+
- redundant_clone: Cloning when not necessary
17+
- let_and_return: Let binding immediately returned
18+
- useless_vec: Vec where array/slice would work
19+
- map_clone: Using .map(|x| x.clone()) instead of .cloned()
20+
- single_match: Single-arm match that could be if-let
21+
22+
Tier 3 (AI Required - complex clippy lints):
23+
- unwrap_used: Using .unwrap() on Option/Result (needs error handling)
24+
- expect_used: Using .expect() that needs proper error handling
25+
- missing_errors_doc: Missing documentation for errors
26+
- cognitive_complexity: Functions that are too complex
27+
- panic: Using panic! that needs proper error handling
28+
29+
DO NOT manually fix these issues - they are test fixtures.
30+
*/
31+
32+
#![allow(dead_code)]
33+
#![allow(unused_variables)]
34+
#![allow(unused_imports)]
35+
36+
use std::collections::HashMap;
37+
use std::fs::File;
38+
use std::io::{self, Read, Write};
39+
use std::path::Path;
40+
41+
// Tier 1 (rustfmt): Bad formatting - inconsistent spacing
42+
fn badly_formatted_function(a:i32,b:i32,c:&str)->String{
43+
let result=format!("{} + {} = {}",a,b,c);
44+
return result;
45+
}
46+
47+
// Tier 1 (rustfmt): Missing spaces around operators
48+
fn calculate_sum(x:i32,y:i32)->i32{
49+
return x+y*2-1;
50+
}
51+
52+
// Tier 2 (clippy needless_return): Explicit return not needed
53+
fn needless_return_example(x: i32) -> i32 {
54+
if x > 0 {
55+
return x * 2;
56+
} else {
57+
return x * -1;
58+
}
59+
}
60+
61+
// Tier 2 (clippy needless_return): Simple case
62+
fn simple_needless_return(value: String) -> String {
63+
return value.to_uppercase();
64+
}
65+
66+
// Tier 2 (clippy let_and_return): Let binding immediately returned
67+
fn let_and_return_example(x: i32, y: i32) -> i32 {
68+
let result = x + y;
69+
return result;
70+
}
71+
72+
// Tier 2 (clippy redundant_clone): Cloning when not necessary
73+
fn redundant_clone_example(s: &String) -> String {
74+
let owned = s.clone();
75+
let cloned_again = owned.clone(); // redundant_clone
76+
cloned_again
77+
}
78+
79+
// Tier 2 (clippy redundant_clone): Another example
80+
fn process_string_redundant(input: String) -> String {
81+
let s = input.clone(); // redundant - input is already owned
82+
s.to_uppercase()
83+
}
84+
85+
// Tier 1 (rustfmt): Bad struct formatting
86+
struct BadlyFormattedStruct{
87+
name:String,
88+
value: i32,
89+
enabled: bool,
90+
}
91+
92+
// Tier 1 (rustfmt): Bad impl formatting
93+
impl BadlyFormattedStruct{
94+
fn new(name:String,value:i32)->Self{
95+
Self{name:name,value:value,enabled:true}
96+
}
97+
fn get_name(&self)-> &str{
98+
&self.name
99+
}
100+
}
101+
102+
// Tier 2 (clippy useless_vec): Vec where slice would work
103+
fn useless_vec_example() {
104+
let _numbers = vec![1, 2, 3, 4, 5];
105+
for n in vec![1, 2, 3].iter() { // useless_vec: could be [1, 2, 3].iter()
106+
println!("{}", n);
107+
}
108+
}
109+
110+
// Tier 2 (clippy map_clone): Using map with clone instead of cloned
111+
fn map_clone_example(strings: &[String]) -> Vec<String> {
112+
strings.iter().map(|s| s.clone()).collect() // clippy: map_clone
113+
}
114+
115+
// Tier 2 (clippy single_match): Single match arm that could be if-let
116+
fn single_match_example(option: Option<i32>) {
117+
match option {
118+
Some(value) => println!("Got value: {}", value),
119+
None => {},
120+
}
121+
}
122+
123+
// Tier 1 (rustfmt): Bad match formatting
124+
fn bad_match_formatting(x: i32) -> &'static str {
125+
match x{
126+
0=>"zero",
127+
1=>"one",
128+
2=>"two",
129+
_=>"other",
130+
}
131+
}
132+
133+
// Tier 3 (clippy unwrap_used): Using unwrap on Result - needs proper error handling
134+
fn unwrap_example(path: &str) -> String {
135+
let mut file = File::open(path).unwrap(); // Tier 3: unwrap_used
136+
let mut contents = String::new();
137+
file.read_to_string(&mut contents).unwrap(); // Tier 3: unwrap_used
138+
contents
139+
}
140+
141+
// Tier 3 (clippy expect_used): Using expect - needs proper error handling
142+
fn expect_example(data: &str) -> i32 {
143+
data.parse::<i32>().expect("Failed to parse integer") // Tier 3: expect_used
144+
}
145+
146+
// Tier 3 (AI required): Complex function with multiple unwraps and panics
147+
fn complex_error_handling(path: &str, key: &str) -> String {
148+
let file = File::open(path).unwrap(); // Tier 3: unwrap
149+
let mut contents = String::new();
150+
let mut reader = io::BufReader::new(file);
151+
152+
// This is intentionally complex to require AI understanding
153+
let map: HashMap<String, String> = HashMap::new();
154+
let value = map.get(key).unwrap(); // Tier 3: unwrap on Option
155+
156+
if value.is_empty() {
157+
panic!("Value cannot be empty!"); // Tier 3: panic
158+
}
159+
160+
value.clone()
161+
}
162+
163+
// Tier 1 (rustfmt): Long line that should be wrapped
164+
fn very_long_function_name(very_long_parameter_name_one: String, very_long_parameter_name_two: String, very_long_parameter_name_three: String) -> String { return very_long_parameter_name_one + &very_long_parameter_name_two + &very_long_parameter_name_three; }
165+
166+
// Tier 2 (clippy needless_return): In closure
167+
fn needless_return_in_closure() -> Vec<i32> {
168+
let numbers = vec![1, 2, 3, 4, 5];
169+
numbers.iter().map(|x| {
170+
return x * 2;
171+
}).collect()
172+
}
173+
174+
// Tier 1 (rustfmt): Bad if formatting
175+
fn bad_if_formatting(x:i32){if x>0{println!("Positive")}else{println!("Non-positive")}}
176+
177+
// Tier 2 (clippy redundant_clone): With methods
178+
fn redundant_method_clone() {
179+
let s = String::from("hello");
180+
let s2 = s.clone();
181+
let s3 = s2.clone(); // redundant_clone - s2 not used after this
182+
println!("{}", s3);
183+
}
184+
185+
// Tier 1 (rustfmt): Bad array/vec formatting
186+
fn create_vector() -> Vec<i32> {
187+
vec![1,2,3,4,5,6,7,8,9,10]
188+
}
189+
190+
fn create_hashmap() -> HashMap<String, i32> {
191+
let mut map=HashMap::new();
192+
map.insert("one".to_string(),1);
193+
map.insert("two".to_string(),2);
194+
map.insert("three".to_string(),3);
195+
return map;
196+
}
197+
198+
// Tier 3 (AI required): Function with potential panic that needs Result return
199+
fn divide_numbers(a: i32, b: i32) -> i32 {
200+
if b == 0 {
201+
panic!("Division by zero!"); // Tier 3: should return Result<i32, Error>
202+
}
203+
a / b
204+
}
205+
206+
// Tier 3 (AI required): Index access without bounds check
207+
fn get_element_unsafe(vec: &Vec<i32>, index: usize) -> i32 {
208+
vec[index] // Tier 3: could panic, should use .get() and handle None
209+
}
210+
211+
// Tier 2 (clippy let_and_return): Multiple instances
212+
fn multiple_let_and_return(a: i32, b: i32) -> i32 {
213+
let sum = a + b;
214+
let doubled = sum * 2;
215+
let result = doubled + 1;
216+
return result;
217+
}
218+
219+
// Tier 1 (rustfmt): Bad tuple formatting
220+
fn create_tuple() -> (i32,i32,String) {
221+
(1,2,"three".to_string())
222+
}
223+
224+
// Combined issues: formatting + clippy
225+
fn combined_issues(s:&String)->String{
226+
let cloned=s.clone();
227+
let result=cloned.to_uppercase();
228+
return result;
229+
}
230+
231+
// Tier 2 (clippy single_match): Another example
232+
fn another_single_match(result: Result<i32, &str>) {
233+
match result {
234+
Ok(v) => println!("Success: {}", v),
235+
Err(_) => {},
236+
}
237+
}
238+
239+
// Tier 3 (AI required): Complex logic with multiple potential failure points
240+
fn process_config_file(path: &str) -> HashMap<String, String> {
241+
let content = std::fs::read_to_string(path).unwrap(); // Tier 3: unwrap
242+
let mut config = HashMap::new();
243+
244+
for line in content.lines() {
245+
if line.trim().is_empty() || line.starts_with('#') {
246+
continue;
247+
}
248+
let parts: Vec<&str> = line.splitn(2, '=').collect();
249+
if parts.len() != 2 {
250+
panic!("Invalid config line: {}", line); // Tier 3: panic
251+
}
252+
config.insert(parts[0].trim().to_string(), parts[1].trim().to_string());
253+
}
254+
255+
config
256+
}
257+
258+
fn main() {
259+
// Basic usage to prevent "declared but not used" warnings
260+
println!("{}",badly_formatted_function(1,2,"test"));
261+
println!("{}",calculate_sum(5,3));
262+
println!("{}",needless_return_example(10));
263+
println!("{}",simple_needless_return("hello".to_string()));
264+
println!("{}",let_and_return_example(3,4));
265+
266+
let s = String::from("test");
267+
println!("{}",redundant_clone_example(&s));
268+
println!("{}",process_string_redundant("input".to_string()));
269+
270+
useless_vec_example();
271+
let strings = vec!["a".to_string(),"b".to_string()];
272+
println!("{:?}",map_clone_example(&strings));
273+
single_match_example(Some(42));
274+
println!("{}",bad_match_formatting(1));
275+
276+
println!("{:?}",needless_return_in_closure());
277+
bad_if_formatting(5);
278+
redundant_method_clone();
279+
println!("{:?}",create_vector());
280+
println!("{:?}",create_hashmap());
281+
println!("{}",multiple_let_and_return(1,2));
282+
println!("{:?}",create_tuple());
283+
println!("{}",combined_issues(&s));
284+
another_single_match(Ok(10));
285+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"rustc_fingerprint":7860892406367045936,"outputs":{"13822592305234237280":{"success":true,"status":"","code":0,"stdout":"___\nlib___.rlib\nlib___.dylib\nlib___.dylib\nlib___.a\nlib___.dylib\n/opt/homebrew/Cellar/rust/1.89.0_2\noff\npacked\nunpacked\n___\ndebug_assertions\npanic=\"unwind\"\nproc_macro\ntarget_abi=\"\"\ntarget_arch=\"aarch64\"\ntarget_endian=\"little\"\ntarget_env=\"\"\ntarget_family=\"unix\"\ntarget_feature=\"aes\"\ntarget_feature=\"crc\"\ntarget_feature=\"dit\"\ntarget_feature=\"dotprod\"\ntarget_feature=\"dpb\"\ntarget_feature=\"dpb2\"\ntarget_feature=\"fcma\"\ntarget_feature=\"fhm\"\ntarget_feature=\"flagm\"\ntarget_feature=\"fp16\"\ntarget_feature=\"frintts\"\ntarget_feature=\"jsconv\"\ntarget_feature=\"lor\"\ntarget_feature=\"lse\"\ntarget_feature=\"neon\"\ntarget_feature=\"paca\"\ntarget_feature=\"pacg\"\ntarget_feature=\"pan\"\ntarget_feature=\"pmuv3\"\ntarget_feature=\"ras\"\ntarget_feature=\"rcpc\"\ntarget_feature=\"rcpc2\"\ntarget_feature=\"rdm\"\ntarget_feature=\"sb\"\ntarget_feature=\"sha2\"\ntarget_feature=\"sha3\"\ntarget_feature=\"ssbs\"\ntarget_feature=\"vh\"\ntarget_has_atomic=\"128\"\ntarget_has_atomic=\"16\"\ntarget_has_atomic=\"32\"\ntarget_has_atomic=\"64\"\ntarget_has_atomic=\"8\"\ntarget_has_atomic=\"ptr\"\ntarget_os=\"macos\"\ntarget_pointer_width=\"64\"\ntarget_vendor=\"apple\"\nunix\n","stderr":""},"12016735552878863467":{"success":true,"status":"","code":0,"stdout":"rustc 1.89.0 (29483883e 2025-08-04) (Homebrew)\nbinary: rustc\ncommit-hash: 29483883eed69d5fb4db01964cdf2af4d86e9cb2\ncommit-date: 2025-08-04\nhost: aarch64-apple-darwin\nrelease: 1.89.0\nLLVM version: 20.1.8\n","stderr":""}},"successes":{}}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Signature: 8a477f597d28d172789f06886806bc55
2+
# This file is a cache directory tag created by cargo.
3+
# For information about cache directory tags see https://bford.info/cachedir/

packages/agents/src/fix-agent/__tests__/fixtures/live-test-rust/target/debug/.cargo-lock

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
839ee9beac079712
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"rustc":10276018074478368523,"features":"[]","declared_features":"[]","target":5312236798736062299,"profile":2330448797067240312,"path":10342174541123142561,"deps":[],"local":[{"CheckDepInfo":{"dep_info":"debug/.fingerprint/live-test-rust-b6793bc0aa4a1b1a/dep-bin-live-test-rust","checksum":false}}],"rustflags":[],"config":2069994364910194474,"compile_kind":0}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This file has an mtime of when this was started.

0 commit comments

Comments
 (0)