Skip to content

Commit 0319b44

Browse files
committed
get tests failing again (yay?)
1 parent 149a567 commit 0319b44

4 files changed

Lines changed: 171 additions & 1 deletion

File tree

crates/berry-bench-bin/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ struct BenchmarkResult {
4646
virtual_usage_bytes: Option<usize>,
4747
}
4848

49+
#[allow(clippy::cast_precision_loss)]
4950
fn calculate_stats(times: &[f64]) -> (f64, f64, f64, f64) {
5051
let mean = times.iter().sum::<f64>() / times.len() as f64;
5152
let variance = times.iter().map(|&x| (x - mean).powi(2)).sum::<f64>() / times.len() as f64;

crates/berry-core/src/parse.rs

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,4 +1316,83 @@ __metadata:
13161316
}
13171317
}
13181318
}
1319+
1320+
#[test]
1321+
fn test_parse_peer_dependencies_meta_real_format() {
1322+
// Test parsing the actual format found in resolutions-patches.yarn.lock
1323+
// This demonstrates the parsing issue where the parser fails on real-world data
1324+
let input = r" peerDependenciesMeta:
1325+
graphql-ws:
1326+
optional: true
1327+
react:
1328+
optional: true
1329+
react-dom:
1330+
optional: true
1331+
subscriptions-transport-ws:
1332+
optional: true
1333+
";
1334+
1335+
let result = parse_peer_dependencies_meta_block(input);
1336+
1337+
match result {
1338+
Ok((remaining, meta)) => {
1339+
println!("Successfully parsed peerDependenciesMeta: {meta:?}");
1340+
println!("Remaining: '{remaining}'");
1341+
assert_eq!(meta.len(), 4, "Should parse 4 peer dependency meta entries");
1342+
assert!(remaining.is_empty(), "Should consume all input");
1343+
}
1344+
Err(e) => {
1345+
println!("Failed to parse peerDependenciesMeta: {e:?}");
1346+
// This test is expected to fail, demonstrating the parsing issue
1347+
// The parser should be fixed to handle this real-world format
1348+
panic!("Parser fails on real-world peerDependenciesMeta format: {e:?}");
1349+
}
1350+
}
1351+
}
1352+
1353+
#[test]
1354+
fn test_parse_package_with_peer_dependencies_meta_real_format() {
1355+
// Test parsing a complete package entry with the real peerDependenciesMeta format
1356+
let input = r#" version: 6.0.0
1357+
resolution: "@actions/github@npm:6.0.0"
1358+
dependencies:
1359+
"@actions/http-client": "npm:^2.2.0"
1360+
"@octokit/core": "npm:^5.0.1"
1361+
"@octokit/plugin-paginate-rest": "npm:^9.0.0"
1362+
"@octokit/plugin-rest-endpoint-methods": "npm:^10.0.0"
1363+
peerDependenciesMeta:
1364+
graphql-ws:
1365+
optional: true
1366+
react:
1367+
optional: true
1368+
react-dom:
1369+
optional: true
1370+
subscriptions-transport-ws:
1371+
optional: true
1372+
checksum: 10/d3744a5416c7ba33057b1ed247fa4b30da167a6b490898968e6e03870424906c3b4b1910829dc5b26622393e3f203b6ad26e7f6a2c2e9505dc0f9e915432482a
1373+
languageName: node
1374+
linkType: hard
1375+
"#;
1376+
1377+
let result = parse_package_properties(input);
1378+
1379+
match result {
1380+
Ok((remaining, package)) => {
1381+
println!("Successfully parsed package with peerDependenciesMeta");
1382+
println!("Remaining: '{remaining}'");
1383+
assert_eq!(
1384+
package.peer_dependencies_meta.len(),
1385+
4,
1386+
"Should parse 4 peer dependency meta entries"
1387+
);
1388+
assert!(remaining.is_empty(), "Should consume all input");
1389+
}
1390+
Err(e) => {
1391+
println!("Failed to parse package with peerDependenciesMeta: {e:?}");
1392+
// This test is expected to fail, demonstrating the parsing issue
1393+
// The parser should be fixed to handle this real-world format
1394+
panic!("Parser fails on real-world package with peerDependenciesMeta: {e:?}");
1395+
}
1396+
}
1397+
}
13191398
}

crates/berry-test/src/lib.rs

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,42 @@ mod tests {
6262
let result = parse_lockfile(&contents);
6363
assert!(
6464
result.is_ok(),
65-
"Should successfully parse minimal berry lockfile"
65+
"Should successfully parse lockfile: {filename}"
66+
);
67+
68+
let (remaining, lockfile) = result.unwrap();
69+
70+
// Critical validation: ensure the entire file was parsed
71+
if !remaining.is_empty() {
72+
println!(
73+
"WARNING: {} bytes remaining unparsed in {}",
74+
remaining.len(),
75+
filename
76+
);
77+
println!(
78+
"First 200 chars of unparsed content: '{}'",
79+
&remaining[..remaining.len().min(200)]
80+
);
81+
82+
// For now, we'll allow some unparsed content but log it
83+
// TODO: Fix parser to handle all content properly
84+
assert!(
85+
remaining.len() <= 1000,
86+
"Too much content remaining unparsed ({} bytes) in {}",
87+
remaining.len(),
88+
filename
89+
);
90+
}
91+
92+
// Verify we parsed at least some packages
93+
assert!(
94+
!lockfile.entries.is_empty(),
95+
"Should parse at least one package from {filename}"
96+
);
97+
98+
println!(
99+
"Successfully parsed {} packages from {filename}",
100+
lockfile.entries.len()
66101
);
67102
}
68103

debug_parse/src/main.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
use berry_core::parse::parse_lockfile;
2+
use berry_test::load_fixture;
3+
4+
fn main() {
5+
let fixture = load_fixture("resolutions-patches.yarn.lock");
6+
println!("File size: {} bytes", fixture.len());
7+
println!("File lines: {}", fixture.lines().count());
8+
9+
// Show first 500 characters
10+
println!("First 500 chars:");
11+
println!("{}", &fixture[..fixture.len().min(500)]);
12+
13+
let result = parse_lockfile(&fixture);
14+
match result {
15+
Ok((rest, lockfile)) => {
16+
println!("Parse successful!");
17+
println!("Remaining unparsed: {} bytes", rest.len());
18+
println!("Packages parsed: {}", lockfile.entries.len());
19+
println!("Metadata version: {}", lockfile.metadata.version);
20+
21+
if !rest.is_empty() {
22+
println!("First 500 chars of unparsed content:");
23+
println!("{}", &rest[..rest.len().min(500)]);
24+
25+
// Find the first package entry in the unparsed content
26+
if let Some(pos) = rest.find("\"@") {
27+
println!("First package entry in unparsed content (around position {}):", pos);
28+
let start = pos.saturating_sub(50);
29+
let end = (pos + 200).min(rest.len());
30+
println!("{}", &rest[start..end]);
31+
}
32+
33+
// Test parsing the problematic section
34+
println!("\nTesting problematic section:");
35+
let problematic_section = " peerDependenciesMeta:\n graphql-ws:\n optional: true\n react:\n optional: true\n react-dom:\n optional: true\n subscriptions-transport-ws:\n optional: true\n";
36+
println!("Problematic section: {}", problematic_section);
37+
38+
// Try to parse this section manually
39+
use berry_core::parse::parse_peer_dependencies_meta_block;
40+
match parse_peer_dependencies_meta_block(problematic_section) {
41+
Ok((rest, meta)) => {
42+
println!("Successfully parsed peerDependenciesMeta: {:?}", meta);
43+
println!("Remaining: '{}'", rest);
44+
}
45+
Err(e) => {
46+
println!("Failed to parse peerDependenciesMeta: {:?}", e);
47+
}
48+
}
49+
}
50+
}
51+
Err(e) => {
52+
println!("Parse failed: {:?}", e);
53+
}
54+
}
55+
}

0 commit comments

Comments
 (0)