fix(app): a worker run's late lines keep its run's secrets masked
Each worker run's log sink keeps the values masked when it started (its secrets in use), so a line still being logged after a stop gave up waiting, and after the next start replaced the values in use, is still masked. The debug echo on stderr is masked the same way. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -150,3 +150,51 @@ async fn stop_returns_only_after_the_last_output_is_logged() {
|
||||
let lines = seen.lock().unwrap().clone();
|
||||
assert!(lines.iter().any(|l| l.contains("LAST")), "{lines:?}");
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
||||
async fn a_last_line_logged_after_the_stop_gave_up_is_masked_with_its_runs_secrets() {
|
||||
// The services started with the old key; the log of the last line is held up past the stop's
|
||||
// wait, and the next start replaces the values in use before that line is written.
|
||||
let hub = jarvis_app::logs::LogHub::new(None);
|
||||
jarvis_app::logs::install(hub.clone());
|
||||
hub.set_secrets_in_use(vec!["old-api-key-1".into()]);
|
||||
let fake = Fake::new("late");
|
||||
let mut o = fake.opts(false);
|
||||
o.env.insert("FAKE_LAST_LINES".into(), "1".into());
|
||||
let run = jarvis_app::worker_process::run_sink();
|
||||
let (started, done) = (std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false)),
|
||||
std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false)));
|
||||
let (s2, d2) = (started.clone(), done.clone());
|
||||
o.line_sink = Some(jarvis_app::worker_process::LineSink(std::sync::Arc::new(move |l: &str| {
|
||||
if l.contains("LAST") {
|
||||
s2.store(true, std::sync::atomic::Ordering::SeqCst);
|
||||
std::thread::sleep(Duration::from_secs(7));
|
||||
(run.0)(l);
|
||||
d2.store(true, std::sync::atomic::Ordering::SeqCst);
|
||||
} else {
|
||||
(run.0)(l);
|
||||
}
|
||||
})));
|
||||
let p = WorkerProcess::new(o).unwrap();
|
||||
let mut rx = p.subscribe();
|
||||
p.start();
|
||||
wait_for(&mut rx, |e| *e == ProcessEvent::Ready).await;
|
||||
tokio::time::timeout(Duration::from_secs(10), async {
|
||||
while !started.load(std::sync::atomic::Ordering::SeqCst) {
|
||||
tokio::time::sleep(Duration::from_millis(10)).await;
|
||||
}
|
||||
}).await.expect("no last line");
|
||||
p.stop().await;
|
||||
// The next start: only the new key is in use (and stored).
|
||||
hub.set_secrets(vec!["new-api-key-2".into()]);
|
||||
hub.set_secrets_in_use(vec!["new-api-key-2".into()]);
|
||||
tokio::time::timeout(Duration::from_secs(10), async {
|
||||
while !done.load(std::sync::atomic::Ordering::SeqCst) {
|
||||
tokio::time::sleep(Duration::from_millis(10)).await;
|
||||
}
|
||||
}).await.expect("the last line was never logged");
|
||||
let lines: Vec<String> = hub.query(None, jarvis_app::logs::Level::Debug, None, None, 100)
|
||||
.into_iter().map(|l| l.text).collect();
|
||||
let last = lines.iter().find(|l| l.contains("LAST")).expect("logged");
|
||||
assert!(last.contains("[비밀값]") && !last.contains("old-api-key-1"), "{lines:?}");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user