diff options
| author | Pjotr Prins <pjotr.public01@thebird.nl> | 2026-11-22 17:04:30 +0000 |
|---|---|---|
| committer | Pjotr Prins <pjotr.public01@thebird.nl> | 2026-11-22 17:04:30 +0000 |
| commit | 78712cc90cf84c553751f9ef5969dddc5960a195 (patch) | |
| tree | cdf6848d85393d7ae9d638c1c3649ba41d3e658b /src | |
| parent | 5eb207b0c5989d886e671372023bdb66abb679db (diff) | |
| download | genenetwork4-78712cc90cf84c553751f9ef5969dddc5960a195.tar.gz | |
gemma: keep the server's paths out of the reply's notes
The ravanan note carried the invocation verbatim -- "/gnu/store/...-ravanan" and "--store=/home/wrk/tmp/ai-root/slurm-share/..." -- and the workflow note carried the checkout path. Those notes are read in chats and pasted into repositories, so they were publishing the deployment's layout. redact_paths() keeps every token's file name and drops the directories: "which ravanan, which manifest, which workflow" survives, the server's layout does not. A unit test asserts no note can carry an absolute path again.
Diffstat (limited to 'src')
| -rw-r--r-- | src/gemma.rs | 70 |
1 files changed, 66 insertions, 4 deletions
diff --git a/src/gemma.rs b/src/gemma.rs index 58d1d53..c49446f 100644 --- a/src/gemma.rs +++ b/src/gemma.rs @@ -1649,6 +1649,42 @@ pub struct RavananWorkflow<'a> { pub manifest: &'a str, } +/// A note's worth of text with absolute paths reduced to their file names. +/// +/// A reply is read in chats and pasted into repositories; the server's own +/// `/gnu/store/...` and `/home/wrk/...` paths are implementation detail, and +/// they were reaching callers through the ravanan command line. The name is +/// kept -- which ravanan, which workflow, which store -- and only the +/// directory is dropped. +pub fn redact_paths(text: &str) -> String { + /// The file name of an absolute path, so "which tool, which file" survives + /// the redaction and only the directory goes. + fn short(path: &str) -> String { + Path::new(path) + .file_name() + .map(|name| name.to_string_lossy().into_owned()) + .unwrap_or_else(|| path.to_string()) + } + text.split_whitespace() + .map(|token| { + // A wrapper around a path: "ravanan (/gnu/store/...-ravanan", + // "(/home/wrk/...)", "--store=/home/wrk/...". + let is_edge = |c: char| matches!(c, ',' | ';' | ')' | '(' | '[' | ']' | '"' | '\''); + let inner = token.trim_matches(is_edge); + if let Some((flag, value)) = inner.split_once('=') { + if value.starts_with('/') { + return token.replace(inner, &format!("{flag}={}", short(value))); + } + } + if inner.starts_with('/') { + return token.replace(inner, &short(inner)); + } + token.to_string() + }) + .collect::<Vec<_>>() + .join(" ") +} + /// What running an artifact workflow needs: the ccwl source, the manifest its /// jobs resolve against, ravanan's own switches, and the outputs wanted. /// @@ -1938,7 +1974,7 @@ pub async fn compute_ravanan( // store holds it, so this is just the path. let store_path = store.map(Path::new); let store_note = store_path.map(|path| { - format!("pangemma's lmdb genotype store: {}", path.display()) + redact_paths(&format!("pangemma's lmdb genotype store: {}", path.display())) }); let inputs_yaml_path = Path::new(cache_dir).join(format!("{trait_key}-ravanan-inputs.yaml")); @@ -1982,14 +2018,14 @@ pub async fn compute_ravanan( ]; let batch_args = batch.ravanan_args(scratch); args.extend(batch_args.iter().map(String::as_str)); - let ravanan_note = format!( + let ravanan_note = redact_paths(&format!( "ravanan ({ravanan_cmd}, {} backend): {}", match batch { crate::config::RavananBatch::SingleMachine => "single-machine", crate::config::RavananBatch::SlurmApi { .. } => "slurm-api", }, args.join(" ") - ); + )); let chromosomes_note = format!( "Scattered {} itself over {} chromosome(s) via CWL scatter, one \ invocation per chromosome: {}", @@ -2109,7 +2145,9 @@ pub async fn compute_ravanan( let mut notes = vec![ ravanan_note, chromosomes_note, - format!("workflow: {workflow_scm_path} (compiled to {compiled_workflow_arg})"), + redact_paths(&format!( + "workflow: {workflow_scm_path} (compiled to {compiled_workflow_arg})" + )), ]; if let Some(note) = engine_note { notes.push(note); @@ -2738,3 +2776,27 @@ mod engine_tests { assert!(ravanan_output_paths(&many, "store").is_err()); } } + +#[cfg(test)] +mod redact_tests { + use super::redact_paths; + + /// A reply is pasted into chats and repositories; no note may carry the + /// server's own paths (measured on the release service: the ravanan command + /// line, with `/gnu/store/...-ravanan` and `/home/wrk/...`, reached + /// callers). + #[test] + fn redact_paths_leaves_no_absolute_path() { + let note = redact_paths( + "ravanan (/gnu/store/8b2iq-ravanan-0.2.0/bin/ravanan, slurm-api backend): \ + --store=/home/wrk/tmp/ai-root/slurm-share/gn4-ravanan-cache/ravanan-store \ + --guix-manifest=/home/wrk/x/manifest.scm cwl/gemma/store.cwl", + ); + assert!(!note.contains("/gnu/store"), "{note}"); + assert!(!note.contains("/home/"), "{note}"); + // The names stay: which ravanan, which manifest, which workflow. + assert!(note.contains("ravanan"), "{note}"); + assert!(note.contains("manifest.scm"), "{note}"); + assert!(note.contains("store.cwl"), "{note}"); + } +} |
