fix(cve): the ISSUE_AUTOCLOSE summary line is logged on every scan, also with nothing to close
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 8m35s

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EYKjxacrr6K88DruUmP48p
This commit is contained in:
Sharang ParnerkarandClaude Opus 5.5 committed 2026-10-09 18:57:43 +02:00
1 parent f552a6a72a
commit e0b9ebee75
1 file changed
+63 -6
+63 -6
View File
@@ -238,8 +238,9 @@ const AUTOCLOSE_PER_SCAN: usize = 20;
/// Close the open issues in `settled` (each with the VEX statement that
/// settles its CVE) as `ISSUE_AUTOCLOSE` says: not at all, only counted, or
/// at most [`AUTOCLOSE_PER_SCAN`] with a comment. Every Gitea request waits
/// for its instance's slot ([`crate::trackers::gitea_limit`]). Logs one line
/// per target with counts only.
/// for its instance's slot ([`crate::trackers::gitea_limit`]). Unless off,
/// logs one line per target and scan with counts only, also when there is
/// nothing to close, so "ran, nothing to close" shows in the log.
///
/// # Returns
///
@@ -252,9 +253,6 @@ async fn autoclose(
target: &CveIssueTarget<'_>,
settled: &[(&TrackerIssue, &VexAssessment)],
) -> Result<u32, AgentError> {
if settled.is_empty() {
return Ok(0);
}
let tenant_id = target.tenant_id;
let target_id = target.target_id;
match target.autoclose {
@@ -943,11 +941,46 @@ mod tests {
pool.drop_tenant("cve-issues-vex").await.ok();
}
/// Log lines written while the returned guard lives (on this thread; a
/// `#[tokio::test]` runs on one).
fn capture_logs() -> (Arc<Mutex<Vec<u8>>>, tracing::subscriber::DefaultGuard) {
let buffer: Arc<Mutex<Vec<u8>>> = Arc::default();
let writer = buffer.clone();
let subscriber = tracing_subscriber::fmt()
.with_ansi(false)
.with_max_level(tracing::Level::INFO)
.with_writer(move || LogWriter(writer.clone()))
.finish();
(buffer, tracing::subscriber::set_default(subscriber))
}
struct LogWriter(Arc<Mutex<Vec<u8>>>);
impl std::io::Write for LogWriter {
fn write(&mut self, bytes: &[u8]) -> std::io::Result<usize> {
self.0.lock().unwrap().extend_from_slice(bytes);
Ok(bytes.len())
}
fn flush(&mut self) -> std::io::Result<()> {
Ok(())
}
}
/// The autoclose summary lines logged into `logs`.
fn summaries(logs: &Mutex<Vec<u8>>) -> Vec<String> {
String::from_utf8_lossy(&logs.lock().unwrap())
.lines()
.filter(|l| l.contains("CVE issues settled by VEX"))
.map(str::to_owned)
.collect()
}
#[tokio::test]
async fn autoclose_off_and_dry_run_leave_the_issue_open() {
let Some((pool, db)) = test_db("cve-issues-vex-off").await else {
return;
};
let (logs, _guard) = capture_logs();
let calls: Calls = Arc::default();
let tracker = tracker_at(fake_gitea(calls.clone()).await);
let mut okhttp = alert("okhttp", "3.12.0", "GHSA-3cqm-mf7h-prrj", "HIGH");
@@ -969,8 +1002,11 @@ mod tests {
CveIssueCounts::default()
);
assert_eq!(calls.lock().unwrap().len(), before);
// Off logs no summary.
assert!(summaries(&logs).is_empty());
// Dry run, against a Gitea that refuses every write: only counted.
// Dry run, against a Gitea that refuses every write: only counted,
// and a target with nothing to close says so too.
let writes: Calls = Arc::default();
let read_only = tracker_at(read_only_gitea(writes.clone()).await);
let dry = vex_target(&db, &read_only, IssueAutoclose::DryRun);
@@ -979,6 +1015,27 @@ mod tests {
CveIssueCounts::default()
);
assert!(writes.lock().unwrap().is_empty(), "{:?}", writes.lock());
let other = CveIssueTarget {
target_id: "target-2",
..vex_target(&db, &read_only, IssueAutoclose::DryRun)
};
sync_cve_issues(&other, &[], true).await.unwrap();
let lines = summaries(&logs);
assert_eq!(lines.len(), 2, "{lines:?}");
assert!(
lines[0].contains("tenant_id=\"cve-issues-vex\"")
&& lines[0].contains("target_id=\"target-1\"")
&& lines[0].contains("would_close=1 not_affected=0 fixed=1"),
"{}",
lines[0]
);
assert!(
lines[1].contains("target_id=\"target-2\"") && lines[1].contains("would_close=0"),
"{}",
lines[1]
);
// No title or path in the line.
assert!(!lines[0].contains("okhttp"), "{}", lines[0]);
assert_eq!(
db.tracker_issues()
.count_documents(doc! { "status": "open" })