|
| 1 | +# ******************************************************************************* |
| 2 | +# Copyright (c) 2026 Contributors to the Eclipse Foundation |
| 3 | +# |
| 4 | +# See the NOTICE file(s) distributed with this work for additional |
| 5 | +# information regarding copyright ownership. |
| 6 | +# |
| 7 | +# This program and the accompanying materials are made available under the |
| 8 | +# terms of the Apache License Version 2.0 which is available at |
| 9 | +# https://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# SPDX-License-Identifier: Apache-2.0 |
| 12 | +# ******************************************************************************* |
| 13 | + |
| 14 | +"""Tests for verification_schema_sync_check.py.""" |
| 15 | + |
| 16 | +from __future__ import annotations |
| 17 | + |
| 18 | +import json |
| 19 | +import subprocess |
| 20 | +import sys |
| 21 | +from pathlib import Path |
| 22 | + |
| 23 | +_MY_PATH = Path(__file__).parent |
| 24 | +_CHECK_SCRIPT = _MY_PATH.parent / "verification_schema_sync_check.py" |
| 25 | + |
| 26 | + |
| 27 | +def _write_template(tmp_path: Path, description: str) -> Path: |
| 28 | + path = tmp_path / "module_verification_report.rst" |
| 29 | + path.write_text( |
| 30 | + """ |
| 31 | +Verification Report contains: |
| 32 | +
|
| 33 | +.. list-table:: Verification report section contract fields |
| 34 | + :header-rows: 1 |
| 35 | + :widths: 1 2 5 |
| 36 | +
|
| 37 | + * - section_index |
| 38 | + - section_key |
| 39 | + - section_description |
| 40 | + * - 1 |
| 41 | + - verification_coverage |
| 42 | + - DESCRIPTION_PLACEHOLDER |
| 43 | +""".replace("DESCRIPTION_PLACEHOLDER", description), |
| 44 | + encoding="utf-8", |
| 45 | + ) |
| 46 | + return path |
| 47 | + |
| 48 | + |
| 49 | +def _write_schema(tmp_path: Path, description: str | None) -> Path: |
| 50 | + schema = { |
| 51 | + "properties": { |
| 52 | + "verification_coverage": { |
| 53 | + "$ref": "./verification_coverage_schema.json", |
| 54 | + } |
| 55 | + } |
| 56 | + } |
| 57 | + if description is not None: |
| 58 | + schema["properties"]["verification_coverage"]["description"] = description |
| 59 | + |
| 60 | + path = tmp_path / "verification_report_schema.json" |
| 61 | + path.write_text(json.dumps(schema), encoding="utf-8") |
| 62 | + return path |
| 63 | + |
| 64 | + |
| 65 | +def _run_check(template_path: Path, schema_path: Path) -> subprocess.CompletedProcess: |
| 66 | + return subprocess.run( |
| 67 | + [ |
| 68 | + sys.executable, |
| 69 | + _CHECK_SCRIPT, |
| 70 | + "--process-template", |
| 71 | + str(template_path), |
| 72 | + "--report-schema", |
| 73 | + str(schema_path), |
| 74 | + "--section-key", |
| 75 | + "verification_coverage", |
| 76 | + ], |
| 77 | + capture_output=True, |
| 78 | + text=True, |
| 79 | + ) |
| 80 | + |
| 81 | + |
| 82 | +def test_sync_check_passes_on_matching_description(tmp_path: Path) -> None: |
| 83 | + description = ( |
| 84 | + "Coverage on requirements, architecture, and detailed design including " |
| 85 | + "test and inspection results." |
| 86 | + ) |
| 87 | + template_path = _write_template(tmp_path, description) |
| 88 | + schema_path = _write_schema(tmp_path, description) |
| 89 | + |
| 90 | + result = _run_check(template_path, schema_path) |
| 91 | + |
| 92 | + assert result.returncode == 0 |
| 93 | + assert "Schema sync check passed." in result.stdout |
| 94 | + |
| 95 | + |
| 96 | +def test_sync_check_fails_on_description_drift(tmp_path: Path) -> None: |
| 97 | + template_path = _write_template( |
| 98 | + tmp_path, |
| 99 | + "Coverage on requirements, architecture, and detailed design including test and inspection results.", |
| 100 | + ) |
| 101 | + schema_path = _write_schema( |
| 102 | + tmp_path, |
| 103 | + "Coverage-focused sections of the S-CORE process verification report.", |
| 104 | + ) |
| 105 | + |
| 106 | + result = _run_check(template_path, schema_path) |
| 107 | + |
| 108 | + assert result.returncode == 2 |
| 109 | + assert "Schema sync check failed:" in result.stdout |
| 110 | + |
| 111 | + |
| 112 | +def test_sync_check_fails_on_missing_description(tmp_path: Path) -> None: |
| 113 | + template_path = _write_template( |
| 114 | + tmp_path, |
| 115 | + "Coverage on requirements, architecture, and detailed design including test and inspection results.", |
| 116 | + ) |
| 117 | + schema_path = _write_schema(tmp_path, None) |
| 118 | + |
| 119 | + result = _run_check(template_path, schema_path) |
| 120 | + |
| 121 | + assert result.returncode == 2 |
| 122 | + assert "schema description missing" in result.stderr |
0 commit comments