microsoft/hve-core
Publicmirrored from https://github.com/microsoft/hve-coreAvailable
.github/skills/experimental/customer-card-render/tests/fuzz_harness.py
43lines · modecode
| 1 | # Copyright (c) Microsoft Corporation. |
| 2 | # SPDX-License-Identifier: MIT |
| 3 | |
| 4 | from __future__ import annotations |
| 5 | |
| 6 | import importlib.util |
| 7 | import sys |
| 8 | from pathlib import Path |
| 9 | |
| 10 | |
| 11 | def _load_module(): |
| 12 | script_path = Path(__file__).resolve().parents[1] / "scripts" / "generate_cards.py" |
| 13 | spec = importlib.util.spec_from_file_location("generate_cards", script_path) |
| 14 | module = importlib.util.module_from_spec(spec) |
| 15 | assert spec is not None and spec.loader is not None |
| 16 | sys.modules["generate_cards"] = module |
| 17 | spec.loader.exec_module(module) |
| 18 | return module |
| 19 | |
| 20 | |
| 21 | MODULE = _load_module() |
| 22 | |
| 23 | |
| 24 | def _exercise_parser(data: bytes) -> None: |
| 25 | text = data.decode("utf-8", errors="ignore") |
| 26 | MODULE.parse_frontmatter(text) |
| 27 | for heading in [ |
| 28 | "Description", |
| 29 | "Scenario Narrative", |
| 30 | "How Might We", |
| 31 | "Use Case Description", |
| 32 | "User Goal", |
| 33 | ]: |
| 34 | MODULE.extract_section(text, heading) |
| 35 | |
| 36 | |
| 37 | if __name__ == "__main__": |
| 38 | import sys |
| 39 | |
| 40 | import atheris |
| 41 | |
| 42 | atheris.Setup(sys.argv, _exercise_parser) |
| 43 | atheris.Fuzz() |
| 44 | |