about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPjotr Prins <pjotr.public01@thebird.nl>2026-11-14 16:01:55 +0000
committerPjotr Prins <pjotr.public01@thebird.nl>2026-11-14 16:01:55 +0000
commit05907254d44ccde0aa0c1f536d2ba838d0645402 (patch)
treea2abf7978944730426a4452e654425a8f6e02b34
parent0d016ee2211fe08722377c4089ce24fa4c98ccdf (diff)
downloadgenenetwork4-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.
-rw-r--r--src/gemma.rs117
-rw-r--r--test/python/test_envelope.py15
-rw-r--r--tests/auth.rs6
-rw-r--r--tests/tokens.rs18
4 files changed, 99 insertions, 57 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,
             &[
diff --git a/test/python/test_envelope.py b/test/python/test_envelope.py
index aa9ced3..c81e0a8 100644
--- a/test/python/test_envelope.py
+++ b/test/python/test_envelope.py
@@ -65,7 +65,20 @@ class EnvelopeTest(ServerTestCase):
             envelope["meta"]["request_id"], response.getheader("x-request-id")
         )
         self.assertEqual(envelope["notes"], [])
-        self.assertEqual(envelope["next"], [])
+        # /version used to carry no `next` links; the "always offer the next
+        # step" design gave every read endpoint some, so assert the shape --
+        # a list of {href, description} -- rather than emptiness. (This was
+        # stale in the repo and failed the package's own check phase, against
+        # a deployed build that had the links too.)
+        self.assertIsInstance(envelope["next"], list)
+        self.assertTrue(envelope["next"], "a read endpoint offers next steps")
+        for step in envelope["next"]:
+            self.assertIsInstance(step["href"], str)
+            self.assertIsInstance(step["description"], str)
+        self.assertTrue(
+            any(step["href"] == "/groups" for step in envelope["next"]),
+            envelope["next"],
+        )
 
     def test_errors_carry_the_request_id_and_took_ms(self):
         # The token extractor's 401: needs no database or gn-auth.
diff --git a/tests/auth.rs b/tests/auth.rs
index df89c9f..1541a6f 100644
--- a/tests/auth.rs
+++ b/tests/auth.rs
@@ -179,6 +179,8 @@ fn owner_is_authorised_and_stranger_is_not() {
     }
 
     let owner = AuthToken {
+        scheme: auth::Scheme::Jwt,
+        id: None,
         sub: "owner".to_string(),
         scope: "profile resource".to_string(),
         raw: token,
@@ -199,6 +201,8 @@ fn owner_is_authorised_and_stranger_is_not() {
     // resource at all -- gn-auth's own default, not something this
     // client invents.
     let stranger = AuthToken {
+        scheme: auth::Scheme::Jwt,
+        id: None,
         sub: "stranger".to_string(),
         scope: "profile resource".to_string(),
         raw: "not-a-real-token".to_string(),
@@ -229,6 +233,8 @@ fn authorisation_result_is_cached() {
     }
 
     let owner = AuthToken {
+        scheme: auth::Scheme::Jwt,
+        id: None,
         sub: "cache-test-owner".to_string(),
         scope: "profile resource".to_string(),
         raw: token,
diff --git a/tests/tokens.rs b/tests/tokens.rs
index f751c0b..b1b2b41 100644
--- a/tests/tokens.rs
+++ b/tests/tokens.rs
@@ -129,11 +129,11 @@ async fn a_token_minted_locally_authenticates_and_is_then_revoked() {
     .await;
     assert_eq!(response.status(), StatusCode::OK);
     let reply = json_of(response).await;
-    let token = reply["token"].as_str().expect("the secret, once").to_string();
+    let token = reply["data"]["token"].as_str().expect("the secret, once").to_string();
     assert!(token.starts_with("gn4ai_"), "{token}");
     assert_eq!(token.len(), 64, "{token}");
-    assert_eq!(reply["id"], "it-1");
-    assert_eq!(reply["status"], "active");
+    assert_eq!(reply["data"]["id"], "it-1");
+    assert_eq!(reply["data"]["status"], "active");
 
     // The listing never repeats the secret or its hash.
     let response = call(Method::GET, "/tokens", Some(local), None).await;
@@ -141,7 +141,7 @@ async fn a_token_minted_locally_authenticates_and_is_then_revoked() {
     let listing_text = listing.to_string();
     assert!(!listing_text.contains(&token), "the listing leaked the token");
     assert!(!listing_text.contains("sha256"));
-    assert_eq!(listing["tokens"][0]["id"], "it-1");
+    assert_eq!(listing["data"][0]["id"], "it-1");
 
     // A second mint with the same id is a conflict, not a server error.
     let response = call(
@@ -158,15 +158,15 @@ async fn a_token_minted_locally_authenticates_and_is_then_revoked() {
     let response = call_with_bearer(Method::GET, "/tokens/who", local, &token).await;
     assert_eq!(response.status(), StatusCode::OK);
     let who = json_of(response).await;
-    assert_eq!(who["scheme"], "opaque");
-    assert_eq!(who["subject"], "zachs");
-    assert_eq!(who["id"], "it-1");
-    assert!(who["created_at"].as_i64().is_some());
+    assert_eq!(who["data"]["scheme"], "opaque");
+    assert_eq!(who["data"]["subject"], "zachs");
+    assert_eq!(who["data"]["id"], "it-1");
+    assert!(who["data"]["created_at"].as_i64().is_some());
 
     // Revoking takes effect on the next request, with no restart.
     let response = call(Method::DELETE, "/tokens/it-1", Some(local), None).await;
     assert_eq!(response.status(), StatusCode::OK);
-    assert_eq!(json_of(response).await["status"], "revoked");
+    assert_eq!(json_of(response).await["data"]["status"], "revoked");
 
     let response = call_with_bearer(Method::GET, "/tokens/who", local, &token).await;
     assert_eq!(response.status(), StatusCode::UNAUTHORIZED);