Skip to content

Commit 535005f

Browse files
Copilotjaypatrickclaude
authored
Fix Rust workflow failures: missing test imports and formatting (#201)
* Deleted dummy files * Add event pipeline with zero-trust validation and file locking This commit adds a comprehensive event pipeline system across all three rules compilers (.NET, Python, Rust) with the following features: ## Event System - CompilationStarted, ConfigurationLoaded, CompilationCompleted, CompilationError - SourceLoading/SourceLoaded - track source processing with metrics - ChunkStarted/ChunkCompleted/ChunksMerging/ChunksMerged - chunking events - Validation - zero-trust checkpoints with severity levels (Info/Warning/Error/Critical) ## File Locking - FileLockService for acquiring read/write locks on local source files - SHA-256 hash computation for integrity verification - Cross-platform support (fcntl on Unix, file handles on Windows) - Lock events: FileLockAcquired, FileLockReleased, FileLockFailed ## Chunking (from previous work) - Parallel compilation via source chunking for improved performance - ChunkingOptions, ChunkMetadata, ChunkedCompilationResult types - Automatic deduplication during merge - --benchmark CLI flag for all compilers ## Documentation - docs/event-pipeline.md - comprehensive event pipeline guide - docs/chunking-guide.md - parallel chunking documentation ## Tests - .NET: 97 tests pass - Python: 132 tests pass - Rust: 47 tests pass 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com> * Initial plan (#200) Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> * Initial plan * Fix Rust workflow failures: add missing imports and format code Co-authored-by: jaypatrick <1800595+jaypatrick@users.noreply.github.com> * Merge main branch to resolve conflicts and sync with latest changes Co-authored-by: jaypatrick <1800595+jaypatrick@users.noreply.github.com> --------- Signed-off-by: Jayson Knight <jayson.knight@jaysonknight.com> Co-authored-by: Jayson Knight <jayson.knight@jaysonknight.com> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: jaypatrick <1800595+jaypatrick@users.noreply.github.com>
1 parent 345de1f commit 535005f

7 files changed

Lines changed: 67 additions & 51 deletions

File tree

src/adguard-validation/adguard-validation-core/src/archive.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ pub fn cleanup_old_archives<P: AsRef<Path>>(archive_root: P, retention_days: u32
136136
#[cfg(test)]
137137
mod tests {
138138
use super::*;
139-
use std::io::Write;
140139
use tempfile::TempDir;
141140

142141
#[test]

src/adguard-validation/adguard-validation-core/src/file_conflict.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ pub fn resolve_conflict<P: AsRef<Path>>(path: P, strategy: ConflictStrategy) ->
8080
#[cfg(test)]
8181
mod tests {
8282
use super::*;
83+
use std::fs;
8384
use tempfile::TempDir;
8485

8586
#[test]

src/adguard-validation/adguard-validation-core/src/validator.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ impl Validator {
9292
#[cfg(test)]
9393
mod tests {
9494
use super::*;
95-
use crate::config::VerificationMode;
9695
use std::io::Write;
9796
use tempfile::{NamedTempFile, TempDir};
9897

src/rules-compiler-rust/src/chunking.rs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -457,12 +457,14 @@ async fn compile_single_chunk_async(
457457

458458
// Write config to temp file
459459
let json = to_json(&config)?;
460-
tokio::fs::write(&temp_config_path, &json).await.map_err(|e| {
461-
CompilerError::file_system(
462-
format!("writing chunk config to {}", temp_config_path.display()),
463-
e,
464-
)
465-
})?;
460+
tokio::fs::write(&temp_config_path, &json)
461+
.await
462+
.map_err(|e| {
463+
CompilerError::file_system(
464+
format!("writing chunk config to {}", temp_config_path.display()),
465+
e,
466+
)
467+
})?;
466468

467469
// Get compiler command
468470
let (cmd, args) = get_compiler_command(
@@ -475,11 +477,10 @@ async fn compile_single_chunk_async(
475477
}
476478

477479
// Execute compiler asynchronously
478-
let output = Command::new(&cmd)
479-
.args(&args)
480-
.output()
481-
.await
482-
.map_err(|e| CompilerError::process_execution(format!("{} {}", cmd, args.join(" ")), e))?;
480+
let output =
481+
Command::new(&cmd).args(&args).output().await.map_err(|e| {
482+
CompilerError::process_execution(format!("{} {}", cmd, args.join(" ")), e)
483+
})?;
483484

484485
if !output.status.success() {
485486
let stderr = String::from_utf8_lossy(&output.stderr);
@@ -694,11 +695,7 @@ mod tests {
694695
String::new(),
695696
"||test.com^".to_string(),
696697
],
697-
vec![
698-
"||other.com^".to_string(),
699-
String::new(),
700-
String::new(),
701-
],
698+
vec!["||other.com^".to_string(), String::new(), String::new()],
702699
];
703700

704701
let (rules, duplicates_removed) = merge_chunks(&chunk_results);

src/rules-compiler-rust/src/events.rs

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
//! dispatcher.add_handler(Box::new(MyHandler));
2626
//! ```
2727
28+
use sha2::{Digest, Sha256};
2829
use std::collections::HashMap;
2930
use std::fs::File;
3031
use std::io::{self, Read};
@@ -505,7 +506,9 @@ impl Default for EventDispatcher {
505506
impl EventDispatcher {
506507
/// Create a new event dispatcher.
507508
pub fn new() -> Self {
508-
Self { handlers: Vec::new() }
509+
Self {
510+
handlers: Vec::new(),
511+
}
509512
}
510513

511514
/// Add an event handler.
@@ -520,22 +523,25 @@ impl EventDispatcher {
520523

521524
/// Raise the compilation starting event.
522525
pub fn raise_compilation_starting(&self, args: &mut CompilationStartedEventArgs) {
523-
tracing::debug!("Raising CompilationStarting event to {} handlers", self.handlers.len());
526+
tracing::debug!(
527+
"Raising CompilationStarting event to {} handlers",
528+
self.handlers.len()
529+
);
524530
for handler in &self.handlers {
525531
handler.on_compilation_starting(args);
526532
if args.cancel {
527-
tracing::info!(
528-
"Compilation cancelled: {:?}",
529-
args.cancel_reason
530-
);
533+
tracing::info!("Compilation cancelled: {:?}", args.cancel_reason);
531534
break;
532535
}
533536
}
534537
}
535538

536539
/// Raise the configuration loaded event.
537540
pub fn raise_configuration_loaded(&self, args: &ConfigurationLoadedEventArgs) {
538-
tracing::debug!("Raising ConfigurationLoaded event to {} handlers", self.handlers.len());
541+
tracing::debug!(
542+
"Raising ConfigurationLoaded event to {} handlers",
543+
self.handlers.len()
544+
);
539545
for handler in &self.handlers {
540546
handler.on_configuration_loaded(args);
541547
}
@@ -643,11 +649,7 @@ impl EventDispatcher {
643649
for handler in &self.handlers {
644650
handler.on_chunk_started(args);
645651
if args.skip {
646-
tracing::info!(
647-
"Chunk {} skipped: {:?}",
648-
args.chunk_index,
649-
args.skip_reason
650-
);
652+
tracing::info!("Chunk {} skipped: {:?}", args.chunk_index, args.skip_reason);
651653
break;
652654
}
653655
}
@@ -695,15 +697,21 @@ impl EventDispatcher {
695697

696698
/// Raise the compilation completed event.
697699
pub fn raise_compilation_completed(&self, args: &CompilationCompletedEventArgs) {
698-
tracing::debug!("Raising CompilationCompleted event to {} handlers", self.handlers.len());
700+
tracing::debug!(
701+
"Raising CompilationCompleted event to {} handlers",
702+
self.handlers.len()
703+
);
699704
for handler in &self.handlers {
700705
handler.on_compilation_completed(args);
701706
}
702707
}
703708

704709
/// Raise the compilation error event.
705710
pub fn raise_compilation_error(&self, args: &mut CompilationErrorEventArgs) {
706-
tracing::debug!("Raising CompilationError event to {} handlers", self.handlers.len());
711+
tracing::debug!(
712+
"Raising CompilationError event to {} handlers",
713+
self.handlers.len()
714+
);
707715
for handler in &self.handlers {
708716
handler.on_compilation_error(args);
709717
}
@@ -934,11 +942,7 @@ mod tests {
934942

935943
#[test]
936944
fn test_validation_finding() {
937-
let finding = ValidationFinding::new(
938-
ValidationSeverity::Error,
939-
"E001",
940-
"Test error",
941-
);
945+
let finding = ValidationFinding::new(ValidationSeverity::Error, "E001", "Test error");
942946
assert_eq!(finding.severity, ValidationSeverity::Error);
943947
assert_eq!(finding.code, "E001");
944948
}

src/rules-compiler-rust/src/lib.rs

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,25 +80,38 @@ pub use error::{CompilerError, Result};
8080
// Re-export chunking types
8181
pub use chunking::{
8282
compile_chunks_async, estimate_speedup, merge_chunks, should_enable_chunking,
83-
split_into_chunks, ChunkedCompilationResult, ChunkingOptions, ChunkingStrategy, ChunkMetadata,
83+
split_into_chunks, ChunkMetadata, ChunkedCompilationResult, ChunkingOptions, ChunkingStrategy,
8484
};
8585

8686
// Re-export event types
8787
pub use events::{
88-
// Enums
89-
ValidationSeverity, FileLockType,
90-
// Event args
91-
CompilationStartedEventArgs, ConfigurationLoadedEventArgs, ValidationEventArgs,
92-
SourceLoadingEventArgs, SourceLoadedEventArgs,
93-
FileLockAcquiredEventArgs, FileLockReleasedEventArgs, FileLockFailedEventArgs,
94-
ChunkStartedEventArgs, ChunkCompletedEventArgs, ChunksMergingEventArgs, ChunksMergedEventArgs,
95-
CompilationCompletedEventArgs, CompilationErrorEventArgs,
96-
// Types
97-
ValidationFinding, EventTimestamp,
88+
ChunkCompletedEventArgs,
89+
ChunkStartedEventArgs,
90+
ChunksMergedEventArgs,
91+
ChunksMergingEventArgs,
92+
CompilationCompletedEventArgs,
93+
CompilationErrorEventArgs,
9894
// Trait and dispatcher
99-
CompilationEventHandler, EventDispatcher,
95+
CompilationEventHandler,
96+
// Event args
97+
CompilationStartedEventArgs,
98+
ConfigurationLoadedEventArgs,
99+
EventDispatcher,
100+
EventTimestamp,
101+
FileLockAcquiredEventArgs,
102+
FileLockFailedEventArgs,
100103
// File locking
101-
FileLockHandle, FileLockService,
104+
FileLockHandle,
105+
FileLockReleasedEventArgs,
106+
FileLockService,
107+
FileLockType,
108+
SourceLoadedEventArgs,
109+
SourceLoadingEventArgs,
110+
ValidationEventArgs,
111+
// Types
112+
ValidationFinding,
113+
// Enums
114+
ValidationSeverity,
102115
};
103116

104117
/// Library version from Cargo.toml.

src/rules-compiler-rust/src/main.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,10 @@ fn run_benchmark(rule_count: usize, max_parallel: Option<usize>) -> ExitCode {
194194
// Show scaling table
195195
println!("Expected speedups at different scales:");
196196
println!("--------------------------------------------------");
197-
println!("{:<15} {:<15} {:<15} Speedup", "Rules", "Sequential", "Parallel");
197+
println!(
198+
"{:<15} {:<15} {:<15} Speedup",
199+
"Rules", "Sequential", "Parallel"
200+
);
198201
println!("--------------------------------------------------");
199202

200203
for size in [10_000usize, 50_000, 200_000, 500_000] {

0 commit comments

Comments
 (0)