diff --git a/skills/analytical-method-validation/SKILL.md b/skills/analytical-method-validation/SKILL.md index 6d193f01..30cc708c 100644 --- a/skills/analytical-method-validation/SKILL.md +++ b/skills/analytical-method-validation/SKILL.md @@ -5,7 +5,7 @@ license: MIT compatibility: Requires Python 3.11+. Scripts use only the standard library - no numpy, scipy, or network access. Statistical distributions are computed from first principles so results are reproducible in any conforming interpreter. allowed-tools: Read Write Edit Bash metadata: - version: "1.3" + version: "1.4" skill-author: K-Dense Inc. last-reviewed: "2026-07-27" --- diff --git a/skills/analytical-method-validation/scripts/_common.py b/skills/analytical-method-validation/scripts/_common.py index eb2feaeb..4e5bda92 100644 --- a/skills/analytical-method-validation/scripts/_common.py +++ b/skills/analytical-method-validation/scripts/_common.py @@ -829,7 +829,11 @@ def parse_rows(text: str, path_hint: str | None = None) -> list[dict[str, str]]: for item in payload: if not isinstance(item, dict): raise InputError("JSON rows must be objects") - rows.append({str(k): "" if v is None else str(v) for k, v in item.items()}) + # Match CSV/TSV whitespace handling while retaining null as empty. + rows.append({ + str(k).strip(): "" if v is None else str(v).strip() + for k, v in item.items() + }) if not rows: raise InputError("no data rows found") return rows diff --git a/tests/analytical-method-validation/test_scripts.py b/tests/analytical-method-validation/test_scripts.py index daa0ba9e..13683121 100644 --- a/tests/analytical-method-validation/test_scripts.py +++ b/tests/analytical-method-validation/test_scripts.py @@ -893,6 +893,33 @@ class TestCompareMethods(unittest.TestCase): class TestInputHandling(unittest.TestCase): + def test_json_csv_and_tsv_normalize_the_same_record(self): + record = {" level ": 0, " response ": " 10100 ", " sample ": " sample A ", " note ": None} + expected = [{"level": "0", "response": "10100", "sample": "sample A", "note": ""}] + for payload in ([record], {"rows": [record]}, {"data": [record]}): + with self.subTest(payload=payload): + rows = common.parse_rows(json.dumps(payload)) + self.assertEqual(rows, expected) + common.require_columns(rows, ["level", "response"]) + for delimiter in (",", "\t"): + with self.subTest(delimiter=delimiter): + text = delimiter.join(record) + "\n" + text += delimiter.join(("0", " 10100 ", " sample A ", "")) + "\n" + self.assertEqual(common.parse_rows(text), expected) + + def test_padded_json_produces_the_same_analysis_as_csv(self): + rows = common.parse_rows((FIXTURES / "calibration_good.csv").read_text()) + padded = [{f" {key} ": f" {value} " for key, value in row.items()} for row in rows] + result = subprocess.run( + [sys.executable, str(SCRIPTS_DIR / "check_response.py"), "-i", "-", "--format", "json"], + input=json.dumps(padded), capture_output=True, text=True, check=False, + ) + baseline = run_script("check_response", "-i", str(FIXTURES / "calibration_good.csv"), + "--format", "json") + self.assertEqual(baseline.returncode, 0, baseline.stderr) + self.assertEqual(result.returncode, 0, result.stderr) + self.assertEqual(json.loads(result.stdout), json.loads(baseline.stdout)) + def test_json_input_accepted(self): res = run_script("check_response", "-i", str(FIXTURES / "calibration_good.json"), "--format", "json")