diff --git a/.github/workflows/resources.yml b/.github/workflows/resources.yml index 87a7247..2315f2f 100644 --- a/.github/workflows/resources.yml +++ b/.github/workflows/resources.yml @@ -6,6 +6,7 @@ on: - "resources/**" - "tests/**" - "scripts/check-resources.py" + - "scripts/verify-oee-export.py" - "scripts/render-resource-guides.py" - "scripts/new-course-workspace" - ".github/workflows/resources.yml" @@ -14,6 +15,7 @@ on: - "resources/**" - "tests/**" - "scripts/check-resources.py" + - "scripts/verify-oee-export.py" - "scripts/render-resource-guides.py" - "scripts/new-course-workspace" - ".github/workflows/resources.yml" @@ -30,11 +32,12 @@ jobs: repository: 0xbuffdev/open-engineering-education path: _oee persist-credentials: false - - name: Validate catalogue only (no active v1 maps) - run: python3 scripts/check-resources.py + fetch-depth: 0 + - name: Validate all maps against exact source commits + run: python3 scripts/check-resources.py --oee _oee - name: Reject stale generated reading guides - run: python3 scripts/render-resource-guides.py --check - - name: Strict v2 shape and pinned export regression suite + run: python3 scripts/render-resource-guides.py --oee _oee --check + - name: Strict v2 and pinned source export regression suite run: python3 -m unittest discover -s tests -p 'test_*.py' -v - name: Verify unmapped scaffolding and preserve learner files shell: bash diff --git a/README.md b/README.md index da6e41d..89299b1 100644 --- a/README.md +++ b/README.md @@ -147,7 +147,7 @@ A completion claim should be supported by inspectable evidence, not by a checked The [public resource library](resources/README.md) contains optional book and online resources and a strict v2 mapping schema. Its historical SEF1 mapping and guide have been retired because they describe a different curriculum. No reviewed v2 course mapping or guide is currently published. -Courses currently initialize **without a reading-plan snapshot** while the new v2 map undergoes pinned-source and human editorial review. Learner-owned `resources.md` remains available, and existing learner directories are never overwritten. Public resources stay independent of private 0xNAND content. +Courses currently initialize **without a reading-plan snapshot** while the new v2 map undergoes pinned-source and human editorial review. Once a map exists, its validator resolves the exact OEE Git commit recorded in that map, not the checkout's moving HEAD. Learner-owned `resources.md` remains available, and existing learner directories are never overwritten. Public resources stay independent of private 0xNAND content. ## Evidence and reproducibility diff --git a/resources/README.md b/resources/README.md index d9cf857..48c376a 100644 --- a/resources/README.md +++ b/resources/README.md @@ -28,11 +28,11 @@ python3 -m unittest discover -s tests -p 'test_*.py' -v python3 scripts/render-resource-guides.py --check ~~~ -For a newly reviewed v2 map and an independently generated pinned OEE Toolkit export, use: +For a future reviewed v2 map, validate against its **exact local OEE Git commit**: ~~~sh -python3 scripts/check-resources.py --course SEF1 --export /path/to/pinned-SEF1-export.json -python3 scripts/render-resource-guides.py --course SEF1 --export /path/to/pinned-SEF1-export.json --stdout +python3 scripts/check-resources.py --course SEF1 --oee /path/to/open-engineering-education --json +python3 scripts/render-resource-guides.py --course SEF1 --oee /path/to/open-engineering-education --stdout ~~~ -The export consumer checks source identity, module/lesson locators and outcome/assessment references. The caller must independently prove that the export was derived from the named Git commit; a JSON claim alone is not cryptographic provenance. Source lookup and end-to-end binding remain WS-I01; editorial resource review is WS-I02; safe final publishing and regeneration are WS-I04. A map presented without its pinned export **fails closed as source_missing**. No new course guide has yet been accepted. +The resource validator now invokes the public OEE Toolkit directly on the map's recorded full Git commit and checks the derived export's exact source identity, modules, lessons, outcomes and assessments. When the commit is missing or unsupported, it returns **incomplete** (exit `3`) rather than using `HEAD`. The selected local checkout must be trusted; Git object IDs do not independently authenticate repository origin. Human bibliography/edition review remains separate (WS-I02), as does safe mapped-guide publishing (WS-I04). No current SEF1 map or reading guide has been accepted. diff --git a/scripts/README.md b/scripts/README.md index 3b08c88..329b37c 100644 --- a/scripts/README.md +++ b/scripts/README.md @@ -32,15 +32,9 @@ version, wrong SHA, unknown assessment, missing outcome coverage or changed module/lesson locator **fails explicitly**. There is no v1 reader, conversion process or fallback to the checkout's moving HEAD. -This export consumer is a narrow reference-checking seam, not an editorial review. WS-I03 now provides one active v2 schema, and historical v1 SEF1 data is only a negative fixture. WS-I01 will wire exact source Git-object lookup into the validator, WS-I02 will author a new reviewed map, and WS-I04 will harden guide publishing. No active course mapping is currently approved. +This standalone export consumer is a narrow interface check, not proof of source provenance or an editorial review. WS-I01 now invokes the public OEE Toolkit on each v2 map's exact locally available Git commit, then checks the freshly derived export with this consumer. Old schema v1 is rejected. WS-I02 will author a reviewed map and WS-I04 will harden guide publishing. No active reviewed map has been published yet. -The source revision text in an exported file is **not cryptographic proof** -by itself. For trusted provenance, derive exports from the actual selected -OEE Git commit with the public Toolkit, and compare the generated bytes -against the pinned golden fixtures in that repository. This consumer does -not fetch commits or accept arbitrary source revision claims as verified. -Passing it establishes **interface consistency only**, not pedagogical -conformance, learner evidence or resource/editorial review. +Do not use a standalone, externally provided export as proof of source provenance. The Workspace resource validator runs the public OEE Toolkit against the selected local Git commit, then checks the export. Its SHA identifies local bytes but does not authenticate the origin of an untrusted checkout. These checks establish structural consistency, **not** educational conformance, resource verification or learner achievement. ## Prerequisites @@ -125,19 +119,26 @@ Test generation in a disposable directory before relying on a changed script in ## Public reading plans -There is currently **no active reviewed map or public study guide**. The retired SEF1 v1 mapping must not be used for the redesigned OEE modules. Unmapped course scaffolding creates notes, labs, exercises, and an editable resources log without a reading plan. +There is currently no reviewed active v2 course mapping. Unmapped course scaffolding +creates independent learner notes and resources logs without a reading plan. +The old SEF1 v1 map is a negative regression fixture, never current study advice. + +For mapped courses, validation now invokes the **single OEE Toolkit parser** on +the map's full Git SHA from a local OEE checkout. Neither the worktree nor HEAD +is a fallback. No v1 reader, automatic remapping or arbitrary supplied export +is accepted by the full resource validator. ```sh -python3 scripts/check-resources.py +python3 scripts/check-resources.py --oee /path/to/open-engineering-education +python3 scripts/check-resources.py --oee /path/to/open-engineering-education --course SEF1 --json +python3 scripts/render-resource-guides.py --oee /path/to/open-engineering-education --course SEF1 --stdout python3 -m unittest discover -s tests -p 'test_*.py' -v -python3 scripts/render-resource-guides.py --check ``` -For a future reviewed v2 map, validation requires the exact pinned Toolkit export: - -```sh -python3 scripts/check-resources.py --course SEF1 --export /path/to/pinned-export.json -python3 scripts/render-resource-guides.py --course SEF1 --export /path/to/pinned-export.json --stdout -``` +The resource-check exit codes are `0` for structurally passed, `1` for +invalid references and `3` for missing or unsupported pinned sources. +With no active maps, the command checks the public catalogue only. This +does not imply a reviewed curriculum mapping or learner certification. -Without a source export, mapped validation and guide generation fail closed; there is no fallback to the checkout's HEAD. Automatic commit resolution and review/publishing gates belong to WS-I01, WS-I02, and WS-I04. The generator continues to protect existing learner directories. +WS-I02 owns SEF1 human resource remapping, WS-I04 owns publication-safe +guide writes, and WS-I11 owns remaining upstream drift notifications. diff --git a/scripts/check-resources.py b/scripts/check-resources.py index fa83142..7eeeb91 100644 --- a/scripts/check-resources.py +++ b/scripts/check-resources.py @@ -6,7 +6,10 @@ from __future__ import annotations import argparse +import functools import importlib.util +import os +import subprocess import json import re import sys @@ -29,6 +32,7 @@ class Check: def __init__(self): self.errors: list[str] = [] self.warnings: list[str] = [] + self.incomplete: list[str] = [] def error(self, location: str, msg: str): self.errors.append(f"{location}: {msg}") @@ -36,6 +40,9 @@ def error(self, location: str, msg: str): def warn(self, location: str, msg: str): self.warnings.append(f"{location}: {msg}") + def missing(self, location: str, msg: str): + self.incomplete.append(f"{location}: {msg}") + def text(value): return isinstance(value, str) and bool(value.strip()) @@ -233,6 +240,7 @@ def validate_map_shape(mapping, catalog, check, loc): return len(check.errors) == before +@functools.lru_cache(maxsize=1) def load_consumer(): name = "oee_workspace_export_consumer" spec = importlib.util.spec_from_file_location(name, ROOT / "scripts" / "verify-oee-export.py") @@ -242,18 +250,74 @@ def load_consumer(): return module -def validate_maps(catalog, check, course_filter=None, export_path=None): +class PinnedSourceError(Exception): + """Typed failure to obtain a supported immutable OEE course export.""" + + def __init__(self, category: str, detail: str): + super().__init__(detail) + self.category = category + + +def read_pinned_export(oee: Path, revision: str, course: str) -> dict: + """Ask the single public Toolkit parser to read the map's local Git commit. + + No HEAD, worktree, network or user-supplied JSON export is a substitute. + """ + if not isinstance(revision, str) or not SHA.fullmatch(revision): + raise PinnedSourceError("unsupported_format", "full lowercase commit SHA required") + if not isinstance(course, str) or not CODE.fullmatch(course): + raise PinnedSourceError("invalid_reference", "invalid course code") + repo = oee.expanduser().resolve() + if not repo.is_dir(): + raise PinnedSourceError("source_missing", "local OEE Git checkout not found") + argv = [ + sys.executable, "-m", "tooling.oee_toolkit", "export", + "--repo", str(repo), "--revision", revision, + "--course", course, "--output", "-", + ] + try: + result = subprocess.run(argv, cwd=repo, capture_output=True, + timeout=90, check=False) + except (OSError, subprocess.TimeoutExpired) as exc: + raise PinnedSourceError("tool_error", f"Toolkit execution: {type(exc).__name__}") from exc + if result.returncode: + stderr = result.stderr.decode("utf-8", errors="replace") + detail = " ".join(stderr.strip().splitlines()[:3])[:500] or "Toolkit export failed" + if result.returncode == 3: + category = "unsupported_format" if "unsupported_format" in stderr else "source_missing" + elif result.returncode == 1: + category = "invalid_reference" + else: + category = "tool_error" + raise PinnedSourceError(category, detail) + try: + exported = json.loads(result.stdout.decode("utf-8")) + except (UnicodeError, ValueError) as exc: + raise PinnedSourceError("tool_error", "invalid Toolkit export JSON") from exc + if not isinstance(exported, dict): + raise PinnedSourceError("tool_error", "Toolkit export must be an object") + return exported + + +def check_pinned_map(mapping: dict, oee: Path) -> dict: + canon = mapping["curriculum"] + consumer = load_consumer() + exported = read_pinned_export(oee, canon["revision"], canon["course"]) + checked = consumer.check_export(exported, canon["revision"]) + consumer.check_map(mapping, checked) + return checked + + +def validate_maps(catalog, check, course_filter=None, oee=None): paths = sorted(MAPPINGS.rglob("*.json")) if course_filter: - paths = [path for path in paths if path.stem == course_filter] + paths = [p for p in paths if p.stem == course_filter] if not paths: if course_filter: check.error("mappings", f"unmapped course {course_filter}; no active v2 map") return - if export_path is not None and len(paths) != 1: - check.error("mappings", "--export requires exactly one selected map (--course CODE)") - return - consumer = load_consumer() if export_path is not None else None + source = oee or Path(os.environ.get( + "OEE_REPO", str(ROOT.parent / "open-engineering-education"))) for path in paths: loc = str(path.relative_to(ROOT)) mapping = load_json(path, check) @@ -265,32 +329,52 @@ def validate_maps(catalog, check, course_filter=None, export_path=None): if path.parent.name != program or path.stem != course: check.error(loc, f"map path must be mappings/{program}/{course}.json") continue - if consumer is None: - check.error(loc, "source_missing: exact pinned OEE export required; automatic Git resolution pending WS-I01") - continue try: - verified = consumer.check_export(consumer.load_json(export_path), canon["revision"]) - consumer.check_map(mapping, verified) - except consumer.ContractError as exc: - check.error(loc, f"{exc.category}: {exc.code}: {exc}") + check_pinned_map(mapping, source) + except PinnedSourceError as exc: + if exc.category in ("source_missing", "unsupported_format"): + check.missing(loc, f"{exc.category}: {exc}") + else: + check.error(loc, f"{exc.category}: {exc}") + except load_consumer().ContractError as exc: + if exc.category in ("missing_input", "unsupported_format"): + check.missing(loc, f"{exc.category}: {exc.code}: {exc}") + else: + check.error(loc, f"{exc.category}: {exc.code}: {exc}") def main(): parser = argparse.ArgumentParser(description=__doc__) - parser.add_argument("--course", help="check one active v2 course map") - parser.add_argument("--export", type=Path, help="independently generated pinned OEE export-format-v1 JSON") + parser.add_argument("--oee", type=Path, default=Path(os.environ.get( + "OEE_REPO", str(ROOT.parent / "open-engineering-education"))), + help="trusted local OEE Git checkout; never fetches") + parser.add_argument("--course", help="check one active v2 map") + parser.add_argument("--json", action="store_true", help="machine-readable diagnostics") args = parser.parse_args() check = Check() catalog = validate_catalog(check) - validate_maps(catalog, check, args.course, args.export) - for warning in check.warnings: - print(f"WARNING: {warning}", file=sys.stderr) - for error in check.errors: - print(f"ERROR: {error}", file=sys.stderr) - print(f"Resource check: {len(catalog)} catalogue IDs, {len(check.warnings)} warnings, {len(check.errors)} errors") - if not list(MAPPINGS.rglob("*.json")): - print("No active v2 resource maps; catalog validation only.") - return 1 if check.errors else 0 + validate_maps(catalog, check, args.course, args.oee) + status = "failed" if check.errors else "incomplete" if check.incomplete else "passed" + if args.json: + print(json.dumps({ + "outcome": status, "errors": check.errors, + "incomplete": check.incomplete, "warnings": check.warnings, + "cataloguedResources": len(catalog), + "manualReviewRequired": True + }, sort_keys=True, separators=(",", ":"))) + else: + for warning in check.warnings: + print(f"WARNING: {warning}", file=sys.stderr) + for missing in check.incomplete: + print(f"INCOMPLETE: {missing}", file=sys.stderr) + for error in check.errors: + print(f"ERROR: {error}", file=sys.stderr) + print(f"Resource check: {len(catalog)} catalogue IDs, " + f"{len(check.warnings)} warnings, {len(check.incomplete)} incomplete, " + f"{len(check.errors)} errors") + if not list(MAPPINGS.rglob("*.json")): + print("No active v2 resource maps; catalog validation only.") + return {"passed": 0, "failed": 1, "incomplete": 3}[status] if __name__ == "__main__": diff --git a/scripts/new-course-workspace b/scripts/new-course-workspace index 58b6532..aef50b4 100644 --- a/scripts/new-course-workspace +++ b/scripts/new-course-workspace @@ -133,8 +133,8 @@ if [[ -f "$mapping_file" ]]; then echo "Python 3 is required for public resource mapping." >&2 exit 1 fi - python3 "$workspace_repo_root/scripts/check-resources.py" --course "$course" - python3 "$workspace_repo_root/scripts/render-resource-guides.py" --course "$course" --stdout >/dev/null + python3 "$workspace_repo_root/scripts/check-resources.py" --oee "$oee_repo" --course "$course" + python3 "$workspace_repo_root/scripts/render-resource-guides.py" --oee "$oee_repo" --course "$course" --stdout >/dev/null fi mkdir -p "$lab_dir" "$exercise_dir" "$notes_dir" diff --git a/scripts/render-resource-guides.py b/scripts/render-resource-guides.py index a6a5d4a..6860e57 100644 --- a/scripts/render-resource-guides.py +++ b/scripts/render-resource-guides.py @@ -8,6 +8,7 @@ import argparse import json +import os import re import subprocess import sys @@ -110,7 +111,7 @@ def render(mapping, catalog): return "\n".join(lines) -def outputs(course_filter, export_path): +def outputs(course_filter, oee_repo): catalog = load_catalog() found = False for path in sorted(MAPPINGS.rglob("*.json")): @@ -121,11 +122,9 @@ def outputs(course_filter, export_path): if course_filter and code != course_filter: continue found = True - if export_path is None: - raise ValueError("source_missing: mapped guides require a reviewed, pinned --export") checked = subprocess.run( [sys.executable, str(ROOT / "scripts" / "check-resources.py"), - "--course", code, "--export", str(export_path)], + "--course", code, "--oee", str(oee_repo)], capture_output=True, text=True, check=False) if checked.returncode: raise ValueError("resource map failed pinned-source validation: " + checked.stderr.strip()) @@ -142,8 +141,9 @@ def main(): modes.add_argument("--check", action="store_true", help="verify all guides match their mappings") modes.add_argument("--stdout", action="store_true", help="print one course guide") parser.add_argument("--course", help="course code (required with --stdout)") - parser.add_argument("--export", type=Path, - help="independently generated pinned OEE Toolkit export for one selected map") + parser.add_argument("--oee", type=Path, default=Path(os.environ.get( + "OEE_REPO", str(ROOT.parent / "open-engineering-education"))), + help="local OEE Git checkout supplying the map's exact pinned commit") args = parser.parse_args() if args.stdout and not args.course: parser.error("--stdout requires --course") @@ -152,7 +152,7 @@ def main(): if args.check and args.course: parser.error("--check validates all guides; omit --course") try: - results = list(outputs(args.course, args.export)) + results = list(outputs(args.course, args.oee)) if args.stdout: if len(results) != 1: raise ValueError("Expected exactly one mapped course") diff --git a/tests/test_pinned_resource_source.py b/tests/test_pinned_resource_source.py new file mode 100644 index 0000000..9e62d10 --- /dev/null +++ b/tests/test_pinned_resource_source.py @@ -0,0 +1,174 @@ +"""WS-I01: verify revision-pinned OEE Toolkit exports without a legacy reader.""" +from __future__ import annotations + +import copy +import importlib.util +import os +from pathlib import Path +import subprocess +import sys +import tempfile +import unittest +from unittest.mock import patch + +ROOT = Path(__file__).resolve().parents[1] +PIN = "cf7903f701582c7a1a3933d1eb65df0289e8a6aa" +OEE = Path(os.environ.get("OEE_REPO", str(ROOT / "_oee"))).resolve() +SPEC = importlib.util.spec_from_file_location( + "workspace_pinned_resources", ROOT / "scripts" / "check-resources.py" +) +checker = importlib.util.module_from_spec(SPEC) +sys.modules[SPEC.name] = checker +SPEC.loader.exec_module(checker) + + +def unmapped(export): + src, code = export["source"], export["course"]["code"] + return { + "schemaVersion": 2, "status": "draft", + "curriculum": { + "repository": src["repository"], + "revision": src["revision"], + "specification": src["specification"], + "course": code, "path": src["coursePath"], + }, + "modules": [ + {"number": item["number"], "title": item["title"], + "coverage": "unmapped", "gap": "Source references require editorial review", + "resources": []} + for item in export["modules"] + ], + } + + +class SourceFailureTests(unittest.TestCase): + def test_unknown_checkout_is_source_missing(self): + with tempfile.TemporaryDirectory() as directory: + with self.assertRaises(checker.PinnedSourceError) as caught: + checker.read_pinned_export(Path(directory) / "not-a-checkout", + PIN, "SEF1") + self.assertEqual(caught.exception.category, "source_missing") + + def test_short_sha_and_branch_name_rejected(self): + for ref in ("HEAD", "main", "a" * 7, "A" * 40): + with self.subTest(ref=ref): + with self.assertRaises(checker.PinnedSourceError) as caught: + checker.read_pinned_export(Path("."), ref, "SEF1") + self.assertEqual(caught.exception.category, "unsupported_format") + + def test_unsupported_schema_is_not_converted(self): + legacy = checker.load_json( + ROOT / "tests" / "fixtures" / "resource-map-v1-SEF1.json", + checker.Check(), + ) + findings = checker.Check() + self.assertFalse(checker.validate_map_shape(legacy, {}, findings, "legacy")) + self.assertIn("unsupported_schema", findings.errors[0]) + + def test_validator_has_one_markdown_parser_and_no_export_override(self): + body = (ROOT / "scripts" / "check-resources.py").read_text(encoding="utf-8") + self.assertNotIn("COURSE_MODULE =", body) + self.assertNotIn('parser.add_argument("--export"', body) + self.assertIn("tooling.oee_toolkit", body) + + +@unittest.skipUnless( + (OEE / "tooling" / "oee_toolkit" / "__main__.py").is_file(), + "needs local canonical OEE Toolkit checkout; resource CI supplies _oee", +) +class RealPinnedToolkitTests(unittest.TestCase): + @classmethod + def setUpClass(cls): + cls.export = checker.read_pinned_export(OEE, PIN, "SEF1") + cls.map = unmapped(cls.export) + + def test_map_matches_actual_pinned_source(self): + findings = checker.Check() + self.assertTrue(checker.validate_map_shape(self.map, {}, findings, "SEF1"), + findings.errors) + validated = checker.check_pinned_map(self.map, OEE) + self.assertEqual(validated["source"]["revision"], PIN) + self.assertEqual(validated["course"], "SEF1") + + def test_selected_commit_missing_does_not_fall_back_to_head(self): + altered = copy.deepcopy(self.map) + altered["curriculum"]["revision"] = "f" * 40 + with self.assertRaises(checker.PinnedSourceError) as caught: + checker.check_pinned_map(altered, OEE) + self.assertEqual(caught.exception.category, "source_missing") + + with tempfile.TemporaryDirectory(dir=ROOT / "resources") as folder: + maps = Path(folder) + path = maps / "SEF" / "SEF1.json" + path.parent.mkdir() + import json + path.write_text(json.dumps(altered), encoding="utf-8") + with patch.object(checker, "MAPPINGS", maps): + result = checker.Check() + checker.validate_maps({}, result, "SEF1", OEE) + self.assertEqual(result.errors, []) + self.assertEqual(len(result.incomplete), 1) + self.assertIn("source_missing", result.incomplete[0]) + + def test_module_and_outcome_changes_are_rejected(self): + broken = copy.deepcopy(self.map) + broken["modules"][0]["title"] = "Different course topic" + with self.assertRaisesRegex(checker.load_consumer().ContractError, "locator"): + checker.check_pinned_map(broken, OEE) + + broken = copy.deepcopy(self.map) + item = broken["modules"][0] + item.update(coverage="partial", resources=[{ + "resource": "R1", "role": "optional", "purpose": "Synthetic test", + "verification": "review-needed", + "part": {"type": "topics", "titles": ["Topic"]}, + "outcomeIds": ["SEF1-O9999"], "assessmentIds": ["SEF1-AS9999"], + }]) + with self.assertRaisesRegex(checker.load_consumer().ContractError, "unknown canonical"): + checker.check_pinned_map(broken, OEE) + + def test_pinned_results_ignore_new_head_and_dirty_worktree(self): + with tempfile.TemporaryDirectory() as folder: + copied = Path(folder) / "oee" + clone = subprocess.run( + ["git", "clone", "--local", "--quiet", str(OEE), str(copied)], + capture_output=True, text=True, check=False, + ) + self.assertEqual(clone.returncode, 0, clone.stderr) + changed = subprocess.run([ + "git", "-C", str(copied), + "-c", "user.name=Test", + "-c", "user.email=test@example.invalid", + "commit", "--quiet", "--allow-empty", "-m", "new moving head", + ], capture_output=True, text=True, check=False) + self.assertEqual(changed.returncode, 0, changed.stderr) + current = subprocess.run( + ["git", "-C", str(copied), "rev-parse", "HEAD"], + capture_output=True, text=True, check=True, + ).stdout.strip() + self.assertNotEqual(current, PIN) + (copied / "curriculum" / "SEF" / "SEF1.md").write_text( + "Dirty worktree must not affect the pinned course.", + encoding="utf-8", + ) + self.assertEqual(checker.read_pinned_export(copied, PIN, "SEF1"), + self.export) + self.assertEqual(checker.check_pinned_map(self.map, copied)["source"]["revision"], + PIN) + + def test_unsupported_old_course_format_and_unknown_course(self): + old = subprocess.run( + ["git", "-C", str(OEE), "rev-parse", "v0.1.0^{commit}"], + capture_output=True, text=True, check=False, + ) + self.assertEqual(old.returncode, 0, old.stderr) + with self.assertRaises(checker.PinnedSourceError) as caught: + checker.read_pinned_export(OEE, old.stdout.strip(), "SEF1") + self.assertIn(caught.exception.category, {"source_missing", "unsupported_format"}) + with self.assertRaises(checker.PinnedSourceError) as missing: + checker.read_pinned_export(OEE, PIN, "SEF9999") + self.assertEqual(missing.exception.category, "source_missing") + + +if __name__ == "__main__": + unittest.main()