diff --git a/Jenkinsfile b/Jenkinsfile index 5155906..f3806ca 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -12,7 +12,7 @@ pipeline { } stage('Test') { - steps { sh './test.sh' } + steps { sh './tests/test.sh' } } } diff --git a/README.md b/README.md index a0765ac..478ef77 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ integration repository or diagnostic tools. ## Render one report ```bash -bash tools/render.sh examples/example-report.yaml --output report.pdf +./render.sh examples/example-report.yaml --output report.pdf ``` The renderer validates the input, loads an optional report-relative logo, and diff --git a/docs/development.md b/docs/development.md index a800e81..0af36b9 100644 --- a/docs/development.md +++ b/docs/development.md @@ -6,11 +6,11 @@ authoring are documented in the main [README](../README.md) and ## Test environment -Tests require uv and Typst. `test.sh` creates `.venv` and synchronizes the pinned +Tests require uv and Typst. `tests/test.sh` creates `.venv` and synchronizes the pinned packages from `requirements.txt`, and invokes Python only from that environment. ```bash -./test.sh +./tests/test.sh ``` Poppler's `pdfinfo` and `pdftotext` enable additional pagination and extracted diff --git a/docs/report-contract.md b/docs/report-contract.md index e8ef91d..17d6d85 100644 --- a/docs/report-contract.md +++ b/docs/report-contract.md @@ -11,10 +11,10 @@ Typst and Bash are required at runtime. From this component checkout: ```bash bash tools/validate.sh examples/example-report.yaml bash tools/validate.sh examples/example-report.json -./test.sh +./tests/test.sh ``` -`./test.sh` creates and synchronizes `.venv` with uv before invoking Python. +`./tests/test.sh` creates and synchronizes `.venv` with uv before invoking Python. Python is not used by validation or rendering. Validation needs no sibling repositories and works from any working directory using explicit paths. It writes no files. Exit codes: 0 valid, 1 invalid/unreadable input or missing dependencies, 2 CLI usage error. @@ -25,7 +25,7 @@ Errors identify the offending JSON path; unsupported file extensions are rejecte After installing Typst: ```bash -bash tools/render.sh examples/example-report.yaml --output output/report.pdf +./render.sh examples/example-report.yaml --output output/report.pdf ``` Validation always runs before Typst. Relative branding assets resolve from the diff --git a/tools/render.sh b/render.sh similarity index 98% rename from tools/render.sh rename to render.sh index 64721d0..05fd02b 100755 --- a/tools/render.sh +++ b/render.sh @@ -2,7 +2,7 @@ # Render a Reportist v1 YAML/JSON document without a Python runtime. set -euo pipefail -root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P) +root=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P) usage() { echo "Usage: $0 INPUT [--output PDF] [--typst COMMAND] [--force]" >&2; exit 2; } fail() { echo "error: $*" >&2; exit 1; } diff --git a/requirements.txt b/requirements.txt index e15a37b..734c234 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,5 +1,5 @@ # Pinned dependencies for the Python test oracle. -# Update versions here intentionally, then run ./test.sh. +# Update versions here intentionally, then run ./tests/test.sh. attrs==26.1.0 # via # jsonschema diff --git a/tests/support_render.py b/tests/support_render.py index c1a2036..83a0878 100644 --- a/tests/support_render.py +++ b/tests/support_render.py @@ -5,7 +5,7 @@ import subprocess ROOT = Path(__file__).resolve().parents[1] def render(input_path, output_path, typst="typst", force=False): - command = ["bash", str(ROOT / "tools/render.sh"), str(input_path), "--output", str(output_path), "--typst", str(typst)] + command = ["bash", str(ROOT / "render.sh"), str(input_path), "--output", str(output_path), "--typst", str(typst)] if force: command.append("--force") result = subprocess.run(command, text=True, capture_output=True) diff --git a/tests/support_validation.py b/tests/support_validation.py index a7d3af0..c319a30 100644 --- a/tests/support_validation.py +++ b/tests/support_validation.py @@ -11,7 +11,7 @@ try: from jsonschema import Draft202012Validator, FormatChecker import yaml except ImportError: - raise SystemExit("Prepare test dependencies with: ./test.sh") + raise SystemExit("Prepare test dependencies with: ./tests/test.sh") SCHEMA = json.loads((Path(__file__).resolve().parents[1] / "schema/report.schema.json").read_text()) Draft202012Validator.check_schema(SCHEMA) diff --git a/test.sh b/tests/test.sh similarity index 83% rename from test.sh rename to tests/test.sh index eff8349..c2e561d 100755 --- a/test.sh +++ b/tests/test.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash set -euo pipefail -cd "$(dirname "${BASH_SOURCE[0]}")" +cd "$(dirname "${BASH_SOURCE[0]}")/.." uv venv --python 3.11 --allow-existing .venv uv pip sync --python .venv/bin/python requirements.txt .venv/bin/python -m unittest discover -s tests -p 'test_*.py' -v diff --git a/tests/test_render.py b/tests/test_render.py index 67ee977..9fb563a 100644 --- a/tests/test_render.py +++ b/tests/test_render.py @@ -93,7 +93,7 @@ class RenderTests(unittest.TestCase): def test_cli_runs_outside_repository(self): output = self.work / "outside-cwd.pdf" result = subprocess.run([ - "bash", str(ROOT / "tools" / "render.sh"), + "bash", str(ROOT / "render.sh"), str(ROOT / "examples" / "minimal-report.json"), "--output", str(output), ], cwd=self.work, text=True, capture_output=True) self.assertEqual(result.returncode, 0, result.stderr) @@ -133,7 +133,7 @@ class RenderTests(unittest.TestCase): ".git", ".ci-venv", "__pycache__", "*.pyc")) output = self.work / "standalone.pdf" result = subprocess.run([ - "bash", str(standalone / "tools" / "render.sh"), + "bash", str(standalone / "render.sh"), str(standalone / "examples" / "example-report.yaml"), "--output", str(output), "--typst", TYPST, ], cwd=self.work, text=True, capture_output=True) diff --git a/tools/render-all.sh b/tools/render-all.sh index 42ddaa2..b932673 100755 --- a/tools/render-all.sh +++ b/tools/render-all.sh @@ -10,7 +10,7 @@ count=0 while IFS= read -r -d '' input; do relative=${input#"$input_dir/"}; output="$output_dir/$relative.pdf"; mkdir -p "$(dirname "$output")" arguments=(--output "$output"); [[ "$force" == false ]]||arguments+=(--force); [[ -z "$typst_command" ]]||arguments+=(--typst "$typst_command") - "$root/tools/render.sh" "$input" "${arguments[@]}"; ((count+=1)) + "$root/render.sh" "$input" "${arguments[@]}"; ((count+=1)) done < <(find "$input_dir" -type f \( -name '*.json' -o -name '*.yaml' -o -name '*.yml' \) -print0 | sort -z) ((count > 0))||{ echo "$input_dir: no YAML or JSON reports found" >&2; exit 1; } echo "Rendered $count reports into $output_dir"