about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorPjotr <wrk@bosa.lan>2026-11-08 15:45:48 +0000
committerPjotr <wrk@bosa.lan>2026-11-08 15:45:48 +0000
commitfc0e8fff3c1bed8d40e982a0a5e808180e772590 (patch)
treebe76e5db9c0566adc50f9d193a786601010f554d /tests
parent386aed031612abc118e3390638cb5aff144be971 (diff)
downloadgenenetwork4-fc0e8fff3c1bed8d40e982a0a5e808180e772590.tar.gz
compute: refuse GEMMA permutations instead of ignoring them
`gemma-wrapper --permutate n` repeats the *whole* LOCO association scan
per permutation -- it shuffles the phenotype file and starts over -- so a
thousand permutations is thousands of full scans: hours to days on a real
panel, against the single slot `/compute/gemma` has. That is not a test
this deployment carries, and an assistant asked for significance
thresholds will ask for it, so the answer has to be an explicit one.

Until now the request type simply had no such field and serde ignores
unknown keys, which is the worst of the three outcomes: the caller gets a
200, no thresholds, and no indication that what it asked for was dropped.
`nperm`, `permutations` and `permutate` are now named fields and refused
with `422 permutations_not_supported`, naming the cost, pointing at
`POST /compute/rqtl` with `nperm` (the endpoint that does have the test,
over the same panel and values) and at the `actions` member every
successful GEMMA response already carries, pre-filled with exactly that
call. Zero keeps its usual meaning -- off -- so a client sharing one body
shape across the two endpoints still works.

* src/routes/gemma.rs: the three fields, the refusal before anything
  expensive runs, and the response note now saying permutations are
  refused rather than merely absent.
* tests/gemma.rs: `compute_gemma_refuses_permutations` pins all three
  spellings, the code, and that `nperm: 0` is not a request for any. It
  takes the compute lock: the gate answers before the handler does, so a
  concurrent job in the same test binary came back 409 instead.
* README.md, docs/www/ai-instruction.md: what to do instead -- judge a
  peak against the smallest `p_lrt`, and get thresholds from R/qtl.

273 tests pass; the same four as before do not.
Diffstat (limited to 'tests')
-rw-r--r--tests/gemma.rs64
1 files changed, 64 insertions, 0 deletions
diff --git a/tests/gemma.rs b/tests/gemma.rs
index b1a145d..7220e4c 100644
--- a/tests/gemma.rs
+++ b/tests/gemma.rs
@@ -632,3 +632,67 @@ async fn compute_gemma_fits_a_case_attribute_as_a_covariate() {
         "the error lists what the group has: {error}"
     );
 }
+
+/// Permutations are refused outright, not ignored: gemma-wrapper's
+/// `--permutate` repeats the whole LOCO scan per permutation, which is
+/// hours on a real panel. R/qtl has the test, so the error says so.
+#[tokio::test]
+async fn compute_gemma_refuses_permutations() {
+    // The gate answers before the handler does, so a job from another test
+    // in this binary would come back 409 instead of the refusal under test.
+    let _serial = serialised();
+    let Some(token) = common::auth_token().await else {
+        eprintln!("skipping compute_gemma_refuses_permutations: no token (see docs/gn-auth.md)");
+        return;
+    };
+
+    for field in ["nperm", "permutations", "permutate"] {
+        let mut body = serde_json::json!({
+            "genotype_file": test_data_path("BXD_geno.txt.gz"),
+            "snps_file": test_data_path("BXD_snps.txt"),
+            "trait_values": bxd_trait_values(),
+        });
+        body[field] = serde_json::json!(100);
+        let response =
+            common::post_json_with_token("POST /compute/gemma (permutations)", "/compute/gemma", &token, &body)
+                .await;
+        let status = response.status();
+        let bytes = response.into_body().collect().await.unwrap().to_bytes();
+        assert_eq!(
+            status,
+            StatusCode::UNPROCESSABLE_ENTITY,
+            "{field} must be refused: {}",
+            String::from_utf8_lossy(&bytes)
+        );
+        let error: Value = serde_json::from_slice(&bytes).unwrap();
+        assert_eq!(error["code"], "permutations_not_supported", "{error}");
+        let detail = error["detail"].as_str().unwrap();
+        assert!(detail.contains("100 permutations"), "{detail}");
+        assert!(
+            detail.contains("/compute/rqtl") && detail.contains("nperm"),
+            "the error points at the endpoint that can do it: {detail}"
+        );
+    }
+
+    // Zero permutations is not a request for any: the field is accepted
+    // and ignored, the way every other endpoint treats its own off-switch.
+    let body = serde_json::json!({
+        "genotype_file": test_data_path("BXD_geno.txt.gz"),
+        "snps_file": test_data_path("BXD_snps.txt"),
+        "trait_values": bxd_trait_values(),
+        "nperm": 0,
+        "lmm": 99,
+    });
+    let response =
+        common::post_json_with_token("POST /compute/gemma (nperm 0)", "/compute/gemma", &token, &body)
+            .await;
+    // Refused for the lmm value, which proves the request got past the
+    // permutation check rather than being rejected for it.
+    assert_eq!(response.status(), StatusCode::UNPROCESSABLE_ENTITY);
+    let bytes = response.into_body().collect().await.unwrap().to_bytes();
+    let error: Value = serde_json::from_slice(&bytes).unwrap();
+    assert!(
+        error["code"] != "permutations_not_supported",
+        "nperm 0 is not a permutation request: {error}"
+    );
+}