diff --git a/docs/report-contract.md b/docs/report-contract.md index bc0f50e..eb05e68 100644 --- a/docs/report-contract.md +++ b/docs/report-contract.md @@ -86,9 +86,11 @@ for the validator to execute. The renderer must preserve that boundary. ## Branding and path resolution `branding` is optional and contains optional `organization`, `logo`, and `theme`. -A theme is an object with optional `font`, `mono_font`, and six-digit hex colors: +Set `branding.theme` to the built-in name `default` or `teal`, or provide an +object with optional `font`, `mono_font`, and six-digit hex colors: `ink`, `muted`, `line`, `paper_soft`, `accent`, `info`, `warning`, `critical`, -`success`. No organisation, author, logo, or incident name is hard-coded. +`success`. `default` matches the neutral fallback palette; `teal` selects a +blue-green palette. No organisation, author, logo, or incident name is hard-coded. Logo and artifact paths use relative forward-slash paths without parent/dot segments, backslashes, drive letters, or control characters. The renderer resolves @@ -109,7 +111,7 @@ are not accepted. YAML and JSON validation use the same schema and semantic chec Add an explicit version and title to legacy reports, retain `metadata.Date` and `metadata.Author`, and move `organization` into `branding.organization`. Resolve -named legacy palettes into explicit `branding.theme` values. Supply a logo only +named palettes to `branding.theme` names or explicit values. Supply a logo only when the report's owner provides it. Map diagnostic hypotheses and fixed domain sections into generic sections/cards; they are not a required renderer feature. Do not relabel Windows raw captures as report inputs. diff --git a/schema/report.schema.json b/schema/report.schema.json index de937f1..533bad9 100644 --- a/schema/report.schema.json +++ b/schema/report.schema.json @@ -79,55 +79,60 @@ "pattern": "^(?!/)(?!.*(?:^|/)\\.\\.?(?:/|$))[^\\\\:\\x00-\\x1f]+$(?![\\s\\S])" }, "theme": { - "type": "object", - "properties": { - "font": { - "type": "string", - "pattern": "\\S" - }, - "mono_font": { - "type": "string", - "pattern": "\\S" - }, - "ink": { - "type": "string", - "pattern": "^#[0-9a-fA-F]{6}$(?![\\s\\S])" - }, - "muted": { - "type": "string", - "pattern": "^#[0-9a-fA-F]{6}$(?![\\s\\S])" - }, - "line": { - "type": "string", - "pattern": "^#[0-9a-fA-F]{6}$(?![\\s\\S])" - }, - "paper_soft": { - "type": "string", - "pattern": "^#[0-9a-fA-F]{6}$(?![\\s\\S])" - }, - "accent": { - "type": "string", - "pattern": "^#[0-9a-fA-F]{6}$(?![\\s\\S])" - }, - "info": { - "type": "string", - "pattern": "^#[0-9a-fA-F]{6}$(?![\\s\\S])" - }, - "warning": { - "type": "string", - "pattern": "^#[0-9a-fA-F]{6}$(?![\\s\\S])" - }, - "critical": { - "type": "string", - "pattern": "^#[0-9a-fA-F]{6}$(?![\\s\\S])" - }, - "success": { - "type": "string", - "pattern": "^#[0-9a-fA-F]{6}$(?![\\s\\S])" + "oneOf": [ + {"type": "string", "enum": ["default", "teal"]}, + { + "type": "object", + "properties": { + "font": { + "type": "string", + "pattern": "\\S" + }, + "mono_font": { + "type": "string", + "pattern": "\\S" + }, + "ink": { + "type": "string", + "pattern": "^#[0-9a-fA-F]{6}$(?![\\s\\S])" + }, + "muted": { + "type": "string", + "pattern": "^#[0-9a-fA-F]{6}$(?![\\s\\S])" + }, + "line": { + "type": "string", + "pattern": "^#[0-9a-fA-F]{6}$(?![\\s\\S])" + }, + "paper_soft": { + "type": "string", + "pattern": "^#[0-9a-fA-F]{6}$(?![\\s\\S])" + }, + "accent": { + "type": "string", + "pattern": "^#[0-9a-fA-F]{6}$(?![\\s\\S])" + }, + "info": { + "type": "string", + "pattern": "^#[0-9a-fA-F]{6}$(?![\\s\\S])" + }, + "warning": { + "type": "string", + "pattern": "^#[0-9a-fA-F]{6}$(?![\\s\\S])" + }, + "critical": { + "type": "string", + "pattern": "^#[0-9a-fA-F]{6}$(?![\\s\\S])" + }, + "success": { + "type": "string", + "pattern": "^#[0-9a-fA-F]{6}$(?![\\s\\S])" + } + }, + "required": [], + "additionalProperties": false } - }, - "required": [], - "additionalProperties": false + ] } }, "required": [], diff --git a/templates/report.typ b/templates/report.typ index 9ca4d99..68522e8 100644 --- a/templates/report.typ +++ b/templates/report.typ @@ -9,7 +9,12 @@ #assert(type(report.metadata.at("Author", default: none)) == str and report.metadata.Author != "", message: "metadata.Author is required") #let get(data, key, default: none) = data.at(key, default: default) #let branding = get(report, "branding", default: (:)) -#let theme = get(branding, "theme", default: (:)) +#let theme-choice = get(branding, "theme", default: (:)) +#let theme = if theme-choice == "default" { (:) } else if theme-choice == "teal" { ( + ink: "#17212b", muted: "#526777", line: "#b9d8df", paper_soft: "#eef7f8", + accent: "#086f83", info: "#007f95", warning: "#a86712", + critical: "#a12e4b", success: "#19765b", + ) } else { theme-choice } #let color(key, fallback) = rgb(str(get(theme, key, default: fallback))) #let ink = color("ink", "#22262b") #let muted = color("muted", "#66707a") diff --git a/tests/test_render.py b/tests/test_render.py index 466b1e7..9fb470d 100644 --- a/tests/test_render.py +++ b/tests/test_render.py @@ -64,6 +64,20 @@ class RenderTests(unittest.TestCase): renderer.render(input_path, output, TYPST) self.assert_pdf(output) + def test_named_theme_renders_and_unknown_name_is_rejected(self): + report = {"schema_version": 1, "title": "Named theme", "metadata": { + "Date": "2026-09-15", "Author": "Synthetic Author"}, + "branding": {"organization": "Example", "theme": "teal"}} + input_path = self.work / "named-theme.json" + input_path.write_text(json.dumps(report), encoding="utf-8") + output = self.work / "named-theme.pdf" + renderer.render(input_path, output, TYPST) + self.assert_pdf(output) + report["branding"]["theme"] = "unknown" + input_path.write_text(json.dumps(report), encoding="utf-8") + with self.assertRaisesRegex(ValueError, "invalid report"): + renderer.render(input_path, self.work / "unknown-theme.pdf", TYPST) + def test_existing_output_requires_force_and_input_is_never_output(self): input_path = ROOT / "examples" / "minimal-report.json" output = self.work / "report.pdf" diff --git a/tools/export-json-all.sh b/tools/export-json-all.sh new file mode 100755 index 0000000..0d54705 --- /dev/null +++ b/tools/export-json-all.sh @@ -0,0 +1,26 @@ +#!/usr/bin/env bash +set -euo pipefail +root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P) +[[ $# -eq 3 && $2 == --output-dir ]]||{ echo "Usage: $0 INPUT_DIR --output-dir DIR" >&2; exit 2; } +input_dir=$(realpath "$1") +mkdir -p "$3" +output_dir=$(realpath "$3") +[[ "$output_dir" != "$input_dir" && "$output_dir" != "$input_dir"/* ]]||{ echo "output directory must be outside the input tree" >&2; exit 1; } +count=0 +while IFS= read -r -d '' input; do + relative=${input#"$input_dir/"} + output="$output_dir/${relative%.*}.json" + mkdir -p "$(dirname "$output")" + stage=$(mktemp -d "${TMPDIR:-/tmp}/reportist-export.XXXXXXXX") + trap 'rm -rf "$stage"' EXIT + cp "$input" "$stage/report.yaml" + cp "$root/tools/export-json.typ" "$stage/export.typ" + "$root/tools/validate.sh" "$input" >/dev/null + typst eval --root "$stage" --input report=report.yaml --in "$stage/export.typ" \ + 'query().first().value' >"$output" + rm -rf "$stage" + trap - EXIT + ((count+=1)) +done < <(find "$input_dir" -type f \( -name '*.yaml' -o -name '*.yml' \) -print0 | sort -z) +((count > 0))||{ echo "$input_dir: no YAML reports found" >&2; exit 1; } +echo "Exported $count report JSON files into $output_dir" diff --git a/tools/export-json.typ b/tools/export-json.typ new file mode 100644 index 0000000..e96c760 --- /dev/null +++ b/tools/export-json.typ @@ -0,0 +1,2 @@ +#let report = yaml(sys.inputs.at("report")) +#metadata(report) diff --git a/tools/render-all.sh b/tools/render-all.sh index b932673..21a9e25 100755 --- a/tools/render-all.sh +++ b/tools/render-all.sh @@ -8,7 +8,7 @@ while (($#)); do case $1 in --output-dir) (($# >= 2))||usage; output_dir=$2; shi [[ "$output_dir" != "$input_dir" && "$output_dir" != "$input_dir"/* ]]||{ echo "output directory must be outside the input tree" >&2; exit 1; } count=0 while IFS= read -r -d '' input; do - relative=${input#"$input_dir/"}; output="$output_dir/$relative.pdf"; mkdir -p "$(dirname "$output")" + 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/render.sh" "$input" "${arguments[@]}"; ((count+=1)) done < <(find "$input_dir" -type f \( -name '*.json' -o -name '*.yaml' -o -name '*.yml' \) -print0 | sort -z) diff --git a/tools/validate.typ b/tools/validate.typ index 6963683..3d743dc 100644 --- a/tools/validate.typ +++ b/tools/validate.typ @@ -59,10 +59,14 @@ #assert(nonempty(branding.at("organization", default: "x")), message: "invalid branding organization") #assert(portable(branding.at("logo", default: "x")), message: "invalid branding logo path") #let theme = branding.at("theme", default: (:)) -#assert(keys-allowed(theme, ("font", "mono_font", "ink", "muted", "line", "paper_soft", "accent", "info", "warning", "critical", "success")), message: "invalid theme field") -#for pair in theme.pairs() { - if pair.first() in ("font", "mono_font") { assert(nonempty(pair.last()), message: "invalid theme font") } - else { assert(type(pair.last()) == str and pair.last().match(regex("^#[0-9a-fA-F]{6}$")) != none, message: "invalid theme color") } +#if type(theme) == str { + assert(theme in ("default", "teal"), message: "unknown named theme") +} else { + assert(keys-allowed(theme, ("font", "mono_font", "ink", "muted", "line", "paper_soft", "accent", "info", "warning", "critical", "success")), message: "invalid theme field") + for pair in theme.pairs() { + if pair.first() in ("font", "mono_font") { assert(nonempty(pair.last()), message: "invalid theme font") } + else { assert(type(pair.last()) == str and pair.last().match(regex("^#[0-9a-fA-F]{6}$")) != none, message: "invalid theme color") } + } } #for section in report.at("sections", default: ()) { validate-section(section) } #for section in report.at("appendices", default: ()) { validate-section(section) }