fix(sast): stage every rule pack under a per-call unique tmp name
CI / Check (push) Skipped
CI / Detect Changes (pull_request) Skipped
CI / Deploy Agent (pull_request) Skipped
CI / Deploy Dashboard (pull_request) Skipped
CI / Deploy Docs (pull_request) Skipped
CI / Deploy MCP (pull_request) Skipped
CI / Check (pull_request) Successful in 9m24s

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DmXxNULoSNPvjF7buKipsB
This commit is contained in:
Sharang ParnerkarandClaude Opus 5.5 committed 2026-10-05 16:27:00 +02:00
1 parent 4f27ddaef2
commit 64ddaf37c1
1 file changed
+16 -2
+16 -2
View File
@@ -33,7 +33,9 @@ const RULE_PACKS: &[(&str, &str)] = &[
];
/// Write the bundled rule packs to stable temp paths (atomic: unique tmp +
/// rename).
/// rename). The tmp name is unique per call, not per process: scans run
/// concurrently in one agent, and a shared tmp file let one scan rename it
/// away while another was still writing it, failing that scan's SAST stage.
///
/// # Errors
///
@@ -45,7 +47,7 @@ async fn stage_cra_rules() -> Result<Vec<PathBuf>, CoreError> {
let mut staged_paths = Vec::with_capacity(RULE_PACKS.len());
for (name, rules) in RULE_PACKS {
let path = dir.join(name);
let tmp = dir.join(format!("{name}.{}.tmp", std::process::id()));
let tmp = dir.join(format!("{name}.{}.tmp", uuid::Uuid::new_v4()));
let staged = async {
tokio::fs::write(&tmp, rules).await?;
tokio::fs::rename(&tmp, &path).await
@@ -284,6 +286,18 @@ mod tests {
);
}
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
async fn concurrent_scans_all_get_the_rules() {
let tasks: Vec<_> = (0..32).map(|_| tokio::spawn(stage_cra_rules())).collect();
for task in tasks {
let paths = task.await.unwrap().expect("staged");
assert_eq!(paths.len(), RULE_PACKS.len());
for (path, (_, rules)) in paths.iter().zip(RULE_PACKS) {
assert_eq!(std::fs::read_to_string(path).unwrap(), *rules);
}
}
}
#[test]
fn every_rule_file_is_bundled() {
// A pack added to rules/ but not to RULE_PACKS would never run.