diff options
| author | Pjotr Prins <pjotr.public01@thebird.nl> | 2026-11-14 16:01:55 +0000 |
|---|---|---|
| committer | Pjotr Prins <pjotr.public01@thebird.nl> | 2026-11-14 16:01:55 +0000 |
| commit | 05907254d44ccde0aa0c1f536d2ba838d0645402 (patch) | |
| tree | a2abf7978944730426a4452e654425a8f6e02b34 /src | |
| parent | 0d016ee2211fe08722377c4089ce24fa4c98ccdf (diff) | |
| download | genenetwork4-05907254d44ccde0aa0c1f536d2ba838d0645402.tar.gz | |
gemma: read ccwl's YAML when checking the workflow's inputs, and fix two stale tests
`ccwl compile` emits CWL as YAML (its only other target is dot), so the
new input check must read that shape -- it was parsing JSON and would
have turned a working request into a 502. A hand-written scan of the
`inputs:` block, deliberately not a YAML dependency: ccwl's output is
machine-generated and unvaried, and adding serde_yaml would mean
regenerating the crate list in guix.scm for one small check.
Two tests were stale in ways only the package's own check phase shows:
- tests/auth.rs built AuthToken literals without the new `scheme`/`id`
fields, so the crate's integration tests did not compile;
- test/python/test_envelope.py asserted that /version carries no `next`
links, which stopped being true when every read endpoint gained them
("always offer the next step"). The deployed build fails that test
too, so it is not a regression from this work -- but it did block
`guix build -f guix.scm` at the python-rest-test phase.
Verified with the packaged binary (guix build -f guix.scm, all phases
including both test suites): POST /compute/gemma/ravanan through ravanan
and the Slurm container returned 200 with 636 rows in 13.6 s, on a
request authenticated with a gn4ai_ short token -- the log line naming
user zachs, scheme opaque and token smoke-2.
Diffstat (limited to 'src')
| -rw-r--r-- | src/gemma.rs | 117 |
1 files changed, 70 insertions, 47 deletions
diff --git a/src/gemma.rs b/src/gemma.rs index e221c3b..b6f3779 100644 --- a/src/gemma.rs +++ b/src/gemma.rs @@ -1050,34 +1050,72 @@ fn ravanan_output_paths<'a>(outputs: &'a Value, id: &str) -> Result<Vec<&'a str> /// The input names a compiled CWL workflow declares, and which of them have /// no default (so they must be supplied). /// -/// ccwl compiles to JSON, so this is a plain parse: `{"inputs": {"name": -/// {...}}}`. Used to catch a binary and a workflow source from different -/// commits before ravanan runs -- cwltool's own complaint about a missing -/// input ("Type mismatch for input `kinship_pheno_file'; expected `File' but -/// got `null'") does not say that the cause is a stale `.scm` in the -/// deployment's checkout. +/// `ccwl compile` emits **CWL as YAML** (its only other target is dot), so this +/// reads that shape rather than JSON: a top-level `inputs:` key, then one +/// two-space-indented `name:` per input, with that input's own fields (such as +/// `default:`) indented further. Deliberately not a YAML parser and not a new +/// dependency -- ccwl's output is machine-generated and unvaried, and a +/// `serde_yaml` in the tree would mean regenerating the crate list in +/// `guix.scm` for one small check. Anything it does not understand surfaces as +/// "declares no inputs", which is reported as a mismatch rather than ignored. fn workflow_inputs(compiled_path: &Path) -> Result<(Vec<String>, Vec<String>), GemmaError> { let text = std::fs::read_to_string(compiled_path).map_err(GemmaError::Io)?; - let document: Value = serde_json::from_str(&text).map_err(|error| { - GemmaError::WorkflowMismatch(format!( - "the compiled workflow is not JSON ({error}); is GEMMA_RAVANAN_WORKFLOW a ccwl source?" - )) - })?; - let inputs = document - .get("inputs") - .and_then(Value::as_object) - .ok_or_else(|| { - GemmaError::WorkflowMismatch("the compiled workflow declares no inputs".to_string()) - })?; - let mut declared = Vec::new(); + let mut lines = text.lines().peekable(); + // Find the top-level `inputs:` block. + let mut in_inputs = false; + for line in lines.by_ref() { + if line.trim_end() == "inputs:" { + in_inputs = true; + break; + } + } + if !in_inputs { + return Err(GemmaError::WorkflowMismatch( + "the compiled workflow has no top-level `inputs:` block; is \ + GEMMA_RAVANAN_WORKFLOW a ccwl source?" + .to_string(), + )); + } + let mut required = Vec::new(); - for (name, spec) in inputs { + let mut declared = Vec::new(); + let mut current: Option<(String, bool)> = None; + for line in lines { + let indented = line.len() - line.trim_start_matches(' ').len(); + if indented == 0 { + break; // e.g. `outputs:` -- the inputs block has ended. + } + let trimmed = line.trim(); + if trimmed.is_empty() || trimmed.starts_with('#') { + continue; + } + if indented == 2 { + if let Some((name, has_default)) = current.take() { + declared.push(name.clone()); + if !has_default { + required.push(name); + } + } + if let Some(name) = trimmed.strip_suffix(':') { + current = Some((name.trim().to_string(), false)); + } + } else if trimmed.starts_with("default:") { + if let Some((_, has_default)) = current.as_mut() { + *has_default = true; + } + } + } + if let Some((name, has_default)) = current.take() { declared.push(name.clone()); - let has_default = spec.get("default").is_some(); if !has_default { - required.push(name.clone()); + required.push(name); } } + if declared.is_empty() { + return Err(GemmaError::WorkflowMismatch( + "the compiled workflow declares no inputs".to_string(), + )); + } declared.sort(); required.sort(); Ok((declared, required)) @@ -1467,22 +1505,13 @@ mod tests { /// A stale `gemma-loco.scm` in the deployment's checkout is a deployment /// mistake with an inscrutable symptom (cwltool: "expected File but got - /// null"); the check names it instead. + /// null"); the check names it instead. The fixture is the shape + /// `ccwl compile` actually emits: YAML, two-space-indented input names. #[test] fn a_workflow_from_another_commit_is_refused_by_name() { - let path = std::env::temp_dir().join(format!("gn4-wf-{}.json", std::process::id())); - std::fs::write( - &path, - r#"{"class":"Workflow","inputs":{ - "genotype_file":{"type":"File"}, - "pheno_file":{"type":"File"}, - "snps_file":{"type":"File"}, - "lmm":{"type":"string"}, - "chromosomes":{"type":"string[]"}}}"#, - ) - .unwrap(); - // This build sends kinship_pheno_file, which the older workflow - // above does not declare. + let path = std::env::temp_dir().join(format!("gn4-wf-{}.cwl", std::process::id())); + let older = "cwlVersion: v1.2\nclass: Workflow\ninputs:\n genotype_file:\n type: File\n pheno_file:\n type: File\n snps_file:\n type: File\n lmm:\n type: string\n chromosomes:\n type: string[]\noutputs:\n assoc:\n type: File\n"; + std::fs::write(&path, older).unwrap(); let error = check_workflow_inputs( &path, &[ @@ -1503,18 +1532,12 @@ mod tests { assert!(message.contains("same commit"), "says what to do: {message}"); assert!(matches!(error, GemmaError::WorkflowMismatch(_))); - // The matching workflow passes. - std::fs::write( - &path, - r#"{"class":"Workflow","inputs":{ - "genotype_file":{"type":"File"}, - "pheno_file":{"type":"File"}, - "kinship_pheno_file":{"type":"File"}, - "snps_file":{"type":"File"}, - "lmm":{"type":"string"}, - "chromosomes":{"type":"string[]"}}}"#, - ) - .unwrap(); + // A defaulted input is declared but not required. + let current = "cwlVersion: v1.2\nclass: Workflow\ninputs:\n genotype_file:\n type: File\n pheno_file:\n type: File\n kinship_pheno_file:\n type: File\n snps_file:\n type: File\n lmm:\n type: string\n default: \"9\"\n chromosomes:\n type: string[]\noutputs: {}\n"; + std::fs::write(&path, current).unwrap(); + let (declared, required) = workflow_inputs(&path).expect("parses"); + assert!(declared.contains(&"kinship_pheno_file".to_string()), "{declared:?}"); + assert!(!required.contains(&"lmm".to_string()), "defaulted: {required:?}"); check_workflow_inputs( &path, &[ |
