-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathjavascript_framework_detection.rs
More file actions
375 lines (322 loc) · 13.6 KB
/
Copy pathjavascript_framework_detection.rs
File metadata and controls
375 lines (322 loc) · 13.6 KB
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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
use std::path::Path;
use syncable_cli::analyzer::{
AnalysisConfig, DetectedLanguage, TechnologyCategory, framework_detector::detect_frameworks,
};
#[test]
fn test_javascript_framework_detection_with_file_indicators() {
// Test Next.js detection through config file
let language = DetectedLanguage {
name: "JavaScript".to_string(),
version: Some("18.0.0".to_string()),
confidence: 0.9,
files: vec![
std::path::PathBuf::from("next.config.js"),
std::path::PathBuf::from("pages/index.js"),
],
main_dependencies: vec![
"next".to_string(),
"react".to_string(),
"react-dom".to_string(),
],
dev_dependencies: vec!["eslint".to_string()],
package_manager: Some("npm".to_string()),
};
let config = AnalysisConfig::default();
let project_root = Path::new(".");
let technologies = detect_frameworks(project_root, &[language], &config).unwrap();
// Should detect Next.js with high confidence due to config file
let nextjs = technologies.iter().find(|t| t.name == "Next.js");
assert!(nextjs.is_some(), "Next.js should be detected");
let nextjs = nextjs.unwrap();
assert!(matches!(nextjs.category, TechnologyCategory::MetaFramework));
assert!(nextjs.is_primary);
assert!(nextjs.confidence > 0.9); // High confidence from config file detection
// Should also detect React as a dependency
let react = technologies.iter().find(|t| t.name == "React");
assert!(react.is_some(), "React should be detected");
}
#[test]
fn test_expo_detection_with_config_file() {
// Test Expo detection through config file
let language = DetectedLanguage {
name: "JavaScript".to_string(),
version: Some("18.0.0".to_string()),
confidence: 0.9,
files: vec![
std::path::PathBuf::from("app.json"),
std::path::PathBuf::from("App.js"),
],
main_dependencies: vec![
"expo".to_string(),
"react".to_string(),
"react-native".to_string(),
],
dev_dependencies: vec![],
package_manager: Some("npm".to_string()),
};
let config = AnalysisConfig::default();
let project_root = Path::new(".");
let technologies = detect_frameworks(project_root, &[language], &config).unwrap();
// Should detect Expo with high confidence due to config file
let expo = technologies.iter().find(|t| t.name == "Expo");
assert!(expo.is_some(), "Expo should be detected");
let expo = expo.unwrap();
assert!(matches!(expo.category, TechnologyCategory::MetaFramework));
assert!(expo.is_primary);
assert!(expo.confidence > 0.9); // High confidence from config file detection
}
#[test]
fn test_tanstack_start_detection_with_config_file() {
// Test TanStack Start detection through config file with specific content
let language = DetectedLanguage {
name: "JavaScript".to_string(),
version: Some("18.0.0".to_string()),
confidence: 0.9,
files: vec![std::path::PathBuf::from("app.config.ts")],
main_dependencies: vec![
"@tanstack/react-start".to_string(),
"react".to_string(),
"vinxi".to_string(),
],
dev_dependencies: vec![],
package_manager: Some("npm".to_string()),
};
let config = AnalysisConfig::default();
let project_root = Path::new(".");
let technologies = detect_frameworks(project_root, &[language], &config).unwrap();
// Should detect TanStack Start with high confidence
let tanstack = technologies.iter().find(|t| t.name == "Tanstack Start");
assert!(tanstack.is_some(), "Tanstack Start should be detected");
let tanstack = tanstack.unwrap();
assert!(matches!(
tanstack.category,
TechnologyCategory::MetaFramework
));
assert!(tanstack.is_primary);
assert!(tanstack.confidence > 0.9); // High confidence from dependency + config file
}
#[test]
fn test_react_native_detection_with_config_file() {
// Test React Native detection through config file
let language = DetectedLanguage {
name: "JavaScript".to_string(),
version: Some("18.0.0".to_string()),
confidence: 0.9,
files: vec![std::path::PathBuf::from("react-native.config.js")],
main_dependencies: vec!["react-native".to_string(), "react".to_string()],
dev_dependencies: vec![],
package_manager: Some("npm".to_string()),
};
let config = AnalysisConfig::default();
let project_root = Path::new(".");
let technologies = detect_frameworks(project_root, &[language], &config).unwrap();
// Should detect React Native with high confidence due to config file
let react_native = technologies.iter().find(|t| t.name == "React Native");
assert!(react_native.is_some(), "React Native should be detected");
let react_native = react_native.unwrap();
assert!(matches!(
react_native.category,
TechnologyCategory::FrontendFramework
));
assert!(react_native.is_primary);
assert!(react_native.confidence > 0.9); // High confidence from config file detection
}
#[test]
fn test_expo_react_native_detection_should_not_detect_nextjs() {
// Test Expo React Native detection that should NOT detect Next.js
let language = DetectedLanguage {
name: "JavaScript".to_string(),
version: Some("4.0.0".to_string()),
confidence: 0.95,
files: vec![
std::path::PathBuf::from("app.json"),
std::path::PathBuf::from("App.tsx"),
std::path::PathBuf::from("android/build.gradle"),
std::path::PathBuf::from("ios/Podfile"),
],
main_dependencies: vec![
"expo".to_string(),
"react-native".to_string(),
"react".to_string(),
"next".to_string(), // This dependency should not cause Next.js to be detected
],
dev_dependencies: vec![],
package_manager: Some("npm".to_string()),
};
let config = AnalysisConfig::default();
let project_root = Path::new(".");
let technologies = detect_frameworks(project_root, &[language], &config).unwrap();
// Should detect Expo as primary, not Next.js
let expo = technologies.iter().find(|t| t.name == "Expo");
let nextjs = technologies.iter().find(|t| t.name == "Next.js");
assert!(expo.is_some(), "Should detect Expo");
assert!(expo.unwrap().is_primary, "Expo should be primary");
assert!(
nextjs.is_none(),
"Should not detect Next.js in Expo project"
);
}
#[test]
fn test_encore_backend_detection() {
// Test Encore backend detection
let language = DetectedLanguage {
name: "TypeScript".to_string(),
version: Some("4.0.0".to_string()),
confidence: 0.95,
files: vec![
std::path::PathBuf::from("main.go"),
std::path::PathBuf::from("service/user.go"),
std::path::PathBuf::from("encore.app"),
],
main_dependencies: vec!["encore.dev".to_string()],
dev_dependencies: vec![],
package_manager: Some("go mod".to_string()),
};
let config = AnalysisConfig::default();
let project_root = Path::new(".");
let technologies = detect_frameworks(project_root, &[language], &config).unwrap();
// Should detect Encore as primary
let encore = technologies.iter().find(|t| t.name == "Encore");
assert!(encore.is_some(), "Should detect Encore");
assert!(encore.unwrap().is_primary, "Encore should be primary");
}
#[test]
fn test_encore_detection_should_not_detect_nextjs() {
// Test Encore detection that should NOT detect Next.js
let language = DetectedLanguage {
name: "JavaScript".to_string(),
version: Some("4.0.0".to_string()),
confidence: 0.95,
files: vec![
std::path::PathBuf::from("encore.app"),
std::path::PathBuf::from("service/api.encore.service.ts"),
],
main_dependencies: vec![
"encore.dev".to_string(),
"next".to_string(), // This dependency should not cause Next.js to be detected
],
dev_dependencies: vec![],
package_manager: Some("npm".to_string()),
};
let config = AnalysisConfig::default();
let project_root = Path::new(".");
let technologies = detect_frameworks(project_root, &[language], &config).unwrap();
// Should detect Encore as primary, not Next.js
let encore = technologies.iter().find(|t| t.name == "Encore");
let nextjs = technologies.iter().find(|t| t.name == "Next.js");
assert!(encore.is_some(), "Should detect Encore");
assert!(encore.unwrap().is_primary, "Encore should be primary");
assert!(
nextjs.is_none(),
"Should not detect Next.js in Encore project"
);
}
#[test]
fn test_false_positive_expo_detection_in_pure_typescript_project() {
// Test case for the false positive Expo detection in a pure TypeScript project
// This reproduces the issue reported by the user
let language = DetectedLanguage {
name: "TypeScript".to_string(),
version: Some(">=20.0.0".to_string()),
confidence: 0.92499995,
files: vec![
std::path::PathBuf::from("eslint.config.js"),
std::path::PathBuf::from("src/tools/write-file.ts"),
std::path::PathBuf::from("src/tools/read-file.ts"),
std::path::PathBuf::from("src/tools/insert.ts"),
std::path::PathBuf::from("src/tools/docker.ts"),
std::path::PathBuf::from("src/tools/directoryContext.ts"),
std::path::PathBuf::from("src/tools/ls.ts"),
std::path::PathBuf::from("src/tools/grep.ts"),
std::path::PathBuf::from("src/tools/edit.ts"),
std::path::PathBuf::from("src/tools/index.ts"),
std::path::PathBuf::from("src/tools/read-many-files.ts"),
std::path::PathBuf::from("src/agents/repo-analysis-agent.ts"),
std::path::PathBuf::from("src/agents/docker-agent.ts"),
std::path::PathBuf::from("src/agents/infra-agent.ts"),
std::path::PathBuf::from("src/toolkits/generateFileToolkit.ts"),
std::path::PathBuf::from("src/toolkits/fullRepoToolkit.ts"),
std::path::PathBuf::from("src/toolkits/dockerToolkit.ts"),
std::path::PathBuf::from("src/toolkits/minimalRepoToolkit.ts"),
std::path::PathBuf::from("src/supervisors/tech-lead-supervisor.ts"),
std::path::PathBuf::from("src/supervisors/application-supervisor.ts"),
std::path::PathBuf::from("src/supervisors/devops-supervisor.ts"),
std::path::PathBuf::from("src/index.ts"),
],
main_dependencies: vec![
"@ai-sdk/anthropic".to_string(),
"@types/glob".to_string(),
"@voltagent/cli".to_string(),
"@voltagent/core".to_string(),
"@voltagent/langfuse-exporter".to_string(),
"@voltagent/logger".to_string(),
"@voltagent/vercel-ai".to_string(),
"dockerode".to_string(),
"dotenv".to_string(),
"glob".to_string(),
"tar-fs".to_string(),
"zod".to_string(),
],
dev_dependencies: vec![],
package_manager: Some("npm".to_string()),
};
let config = AnalysisConfig::default();
let project_root = Path::new(".");
let technologies = detect_frameworks(project_root, &[language], &config).unwrap();
// Print all detected technologies for debugging
println!("Detected technologies:");
for tech in &technologies {
println!(
" - {} (confidence: {:.2}, primary: {})",
tech.name, tech.confidence, tech.is_primary
);
}
// Should NOT detect Expo in this pure TypeScript project
let expo = technologies.iter().find(|t| t.name == "Expo");
if let Some(expo_tech) = expo {
println!("ERROR: Expo incorrectly detected!");
println!(" Confidence: {}", expo_tech.confidence);
println!(" Is primary: {}", expo_tech.is_primary);
panic!(
"Expo should NOT be detected in a pure TypeScript project without Expo dependencies"
);
} else {
println!("SUCCESS: Expo not detected (as expected)");
}
}
#[test]
fn test_legitimate_expo_detection_still_works() {
// Test that legitimate Expo detection still works after our fix
let language = DetectedLanguage {
name: "JavaScript".to_string(),
version: Some("18.0.0".to_string()),
confidence: 0.9,
files: vec![
std::path::PathBuf::from("app.json"),
std::path::PathBuf::from("App.js"),
],
main_dependencies: vec![
"expo".to_string(),
"react".to_string(),
"react-native".to_string(),
],
dev_dependencies: vec![],
package_manager: Some("npm".to_string()),
};
let config = AnalysisConfig::default();
let project_root = Path::new(".");
let technologies = detect_frameworks(project_root, &[language], &config).unwrap();
// Should detect Expo with high confidence due to config file and proper dependencies
let expo = technologies.iter().find(|t| t.name == "Expo");
assert!(
expo.is_some(),
"Expo should be detected with proper dependencies"
);
let expo = expo.unwrap();
assert!(matches!(expo.category, TechnologyCategory::MetaFramework));
assert!(expo.is_primary);
assert!(expo.confidence > 0.9); // High confidence from config file and dependencies
println!("SUCCESS: Expo correctly detected with legitimate dependencies");
println!(" Confidence: {}", expo.confidence);
println!(" Is primary: {}", expo.is_primary);
}