From 261d3a9dac98dddca9adf79771398f3ba0004689 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Thu, 2 Oct 2025 09:48:38 +0200 Subject: [PATCH 1/2] Fix test-spec -> test_spec in JSON output The new report.py expects the test-spec key to be in a proper JSON compatible format. I.e., it looks for 'test_spec' rather than the old 'test-spec' used previously. This fixes the issue with missing test specification inline in the resulting PDF report. See 'Verify dynamic test-spec: .adoc' for a before-after example. Signed-off-by: Joachim Wiberg --- 9pm.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/9pm.py b/9pm.py index 17fdcd2..0c27b85 100755 --- a/9pm.py +++ b/9pm.py @@ -329,8 +329,8 @@ def parse_suite(suite_path, parent_suite_path, options, settings, name=None): test_spec_path = get_test_spec_path(case['case'], settings['test-spec']) if os.path.exists(test_spec_path): vcprint(pcolor.faint, f"Found test specification: {test_spec_path} for {case['case']}") - case['test-spec'] = test_spec_path - case['test-spec-sha'] = calculate_sha1sum(test_spec_path) + case['test_spec'] = test_spec_path + case['test_spec_sha'] = calculate_sha1sum(test_spec_path) else: vcprint(pcolor.faint, f"No test specification for {case['case']} ({test_spec_path})") From 3bd428e63107433008efde9d2011fd88c6b48fc9 Mon Sep 17 00:00:00 2001 From: Joachim Wiberg Date: Thu, 2 Oct 2025 10:16:02 +0200 Subject: [PATCH 2/2] Add regression test for test-spec JSON bug Signed-off-by: Joachim Wiberg --- self_test/cases/worker.adoc | 3 ++ self_test/run.py | 50 +++++++++++++++++++++++++++++++++ self_test/suites/test-spec.yaml | 5 ++++ self_test/test_json_format.py | 20 +++++++++++++ 4 files changed, 78 insertions(+) create mode 100644 self_test/cases/worker.adoc create mode 100644 self_test/suites/test-spec.yaml create mode 100755 self_test/test_json_format.py diff --git a/self_test/cases/worker.adoc b/self_test/cases/worker.adoc new file mode 100644 index 0000000..f63bb89 --- /dev/null +++ b/self_test/cases/worker.adoc @@ -0,0 +1,3 @@ += Worker Test Specification + +This is a test specification for the worker test case. diff --git a/self_test/run.py b/self_test/run.py index 80bc951..20adb5d 100755 --- a/self_test/run.py +++ b/self_test/run.py @@ -328,6 +328,55 @@ def test_repeat_flag(self): } ) + def test_spec_json_format(self): + """Verify test_spec and test_spec_sha keys in JSON output""" + + self.env = os.environ.copy() + self.env["NINEPM_TEST_DIR"] = self.create_unique_subdir() + + result = subprocess.run( + ["python3", self.ninepm, "suites/test-spec.yaml"], + cwd=self.script_dir, + text=True, + env=self.env, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + ) + + if VERBOSE: + print(result.stdout) + print(result.stderr, file=sys.stderr) + + assert result.returncode == 0, f"Failed with return code {result.returncode}" + + json_path = os.path.join(os.path.expanduser('~/.local/share/9pm/logs/last'), 'result.json') + assert os.path.exists(json_path), f"Could not find {json_path}" + + with open(json_path, 'r') as f: + data = json.load(f) + + def find_test_spec(obj): + if isinstance(obj, dict): + if 'test_spec' in obj: + return obj + for value in obj.values(): + result = find_test_spec(value) + if result: + return result + elif isinstance(obj, list): + for item in obj: + result = find_test_spec(item) + if result: + return result + return None + + case = find_test_spec(data['suite']) + assert case is not None, "Could not find test_spec in JSON" + assert 'test_spec' in case, "Missing test_spec key" + assert 'test_spec_sha' in case, "Missing test_spec_sha key" + + print_green(f"[PASS] Test spec JSON output") + def cleanup(self): """Cleanup temp directory after tests""" self.temp_dir_base.cleanup() @@ -357,6 +406,7 @@ def cleanup(self): tester.test_abort_flag() tester.test_repeat_flag() tester.test_proj_config() + tester.test_spec_json_format() print_green("All tests passed.") finally: tester.cleanup() diff --git a/self_test/suites/test-spec.yaml b/self_test/suites/test-spec.yaml new file mode 100644 index 0000000..2d59536 --- /dev/null +++ b/self_test/suites/test-spec.yaml @@ -0,0 +1,5 @@ +--- +- settings: + test-spec: .adoc + +- case: "../cases/worker.py" diff --git a/self_test/test_json_format.py b/self_test/test_json_format.py new file mode 100755 index 0000000..2f1f7e4 --- /dev/null +++ b/self_test/test_json_format.py @@ -0,0 +1,20 @@ +#!/usr/bin/env python3 +"""Verify test_spec and test_spec_sha keys in JSON output""" + +import sys +import os + +sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) + +from run import Test9pm + +if __name__ == "__main__": + tester = Test9pm() + try: + tester.test_spec_json_format() + sys.exit(0) + except AssertionError as e: + print(f"\n✗ Test failed: {e}") + sys.exit(1) + finally: + tester.cleanup()