-
Notifications
You must be signed in to change notification settings - Fork 24
Score 2774 traceability #484
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
FScholPer
wants to merge
6
commits into
main
Choose a base branch
from
score-2774-traceability
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fd1f3dd
feat(traceability): add coverage checker and reporting docs
FScholPer 59b1ced
add coverage check
FScholPer 9250faa
fix lint
FScholPer 1677f66
Merge branch 'main' into score-2774-traceability
FScholPer 499d02f
refactoring the coverage, metrics and dashboard
FScholPer e1dbfe7
add generic filters
FScholPer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -26,3 +26,4 @@ __pycache__/ | |
|
|
||
| # bug: This file is created in repo root on test discovery. | ||
| /consumer_test.log | ||
| .clwb | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,233 @@ | ||
| # ******************************************************************************* | ||
| # Copyright (c) 2026 Contributors to the Eclipse Foundation | ||
| # | ||
| # See the NOTICE file(s) distributed with this work for additional | ||
| # information regarding copyright ownership. | ||
| # | ||
| # This program and the accompanying materials are made available under the | ||
| # terms of the Apache License Version 2.0 which is available at | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # ******************************************************************************* | ||
|
|
||
| """Tests for traceability_coverage.py.""" | ||
|
|
||
| import json | ||
| import os | ||
| import subprocess | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| _MY_PATH = Path(__file__).parent | ||
|
|
||
|
|
||
| def _write_needs_json(tmp_path: Path) -> Path: | ||
| needs_json = tmp_path / "needs.json" | ||
| payload = { | ||
| "current_version": "main", | ||
| "versions": { | ||
| "main": { | ||
| "needs": { | ||
| "REQ_1": { | ||
| "id": "REQ_1", | ||
| "type": "tool_req", | ||
| "implemented": "YES", | ||
| "source_code_link": "src/foo.py:10", | ||
| "testlink": "", | ||
| }, | ||
| "REQ_2": { | ||
| "id": "REQ_2", | ||
| "type": "tool_req", | ||
| "implemented": "PARTIAL", | ||
| "source_code_link": "", | ||
| "testlink": "tests/test_foo.py::test_bar", | ||
| }, | ||
| "REQ_3": { | ||
| "id": "REQ_3", | ||
| "type": "tool_req", | ||
| "implemented": "NO", | ||
| "source_code_link": "", | ||
| "testlink": "", | ||
| }, | ||
| "TC_1": { | ||
| "id": "TC_1", | ||
| "type": "testcase", | ||
| "partially_verifies": "REQ_1, REQ_2", | ||
| "fully_verifies": "", | ||
| }, | ||
| "TC_2": { | ||
| "id": "TC_2", | ||
| "type": "testcase", | ||
| "partially_verifies": "", | ||
| "fully_verifies": "", | ||
| }, | ||
| "TC_3": { | ||
| "id": "TC_3", | ||
| "type": "testcase", | ||
| "partially_verifies": "", | ||
| "fully_verifies": "REQ_UNKNOWN", | ||
| }, | ||
| } | ||
| } | ||
| }, | ||
| } | ||
| needs_json.write_text(json.dumps(payload), encoding="utf-8") | ||
| return needs_json | ||
|
|
||
|
|
||
| def test_traceability_coverage_thresholds_pass(tmp_path: Path) -> None: | ||
| needs_json = _write_needs_json(tmp_path) | ||
| output_json = tmp_path / "summary.json" | ||
|
|
||
| result = subprocess.run( | ||
| [ | ||
| sys.executable, | ||
| _MY_PATH.parent / "traceability_coverage.py", | ||
| "--needs-json", | ||
| str(needs_json), | ||
| "--min-req-code", | ||
| "50", | ||
| "--min-req-test", | ||
| "50", | ||
| "--min-req-fully-linked", | ||
| "0", | ||
| "--min-tests-linked", | ||
| "60", | ||
| "--json-output", | ||
| str(output_json), | ||
| ], | ||
| capture_output=True, | ||
| text=True, | ||
| ) | ||
|
|
||
| assert result.returncode == 0 | ||
| assert "Threshold check passed." in result.stdout | ||
| assert output_json.exists() | ||
|
|
||
| summary = json.loads(output_json.read_text(encoding="utf-8")) | ||
| assert summary["requirements"]["total"] == 2 | ||
| assert summary["requirements"]["with_code_link"] == 1 | ||
| assert summary["requirements"]["with_test_link"] == 1 | ||
| assert summary["requirements"]["fully_linked"] == 0 | ||
| assert summary["tests"]["total"] == 3 | ||
| assert summary["tests"]["linked_to_requirements"] == 2 | ||
| assert len(summary["tests"]["broken_references"]) == 1 | ||
|
|
||
|
|
||
| def test_traceability_coverage_thresholds_fail(tmp_path: Path) -> None: | ||
| needs_json = _write_needs_json(tmp_path) | ||
|
|
||
| result = subprocess.run( | ||
| [ | ||
| sys.executable, | ||
| _MY_PATH.parent / "traceability_coverage.py", | ||
| "--needs-json", | ||
| str(needs_json), | ||
| "--min-req-code", | ||
| "80", | ||
| "--min-req-test", | ||
| "80", | ||
| "--min-req-fully-linked", | ||
| "80", | ||
| "--min-tests-linked", | ||
| "80", | ||
| ], | ||
| capture_output=True, | ||
| text=True, | ||
| ) | ||
|
|
||
| assert result.returncode == 2 | ||
| assert "Threshold check failed:" in result.stdout | ||
|
|
||
|
|
||
| def test_traceability_coverage_fails_on_broken_refs(tmp_path: Path) -> None: | ||
| needs_json = _write_needs_json(tmp_path) | ||
|
|
||
| result = subprocess.run( | ||
| [ | ||
| sys.executable, | ||
| _MY_PATH.parent / "traceability_coverage.py", | ||
| "--needs-json", | ||
| str(needs_json), | ||
| "--min-req-code", | ||
| "0", | ||
| "--min-req-test", | ||
| "0", | ||
| "--min-req-fully-linked", | ||
| "0", | ||
| "--min-tests-linked", | ||
| "0", | ||
| "--fail-on-broken-test-refs", | ||
| ], | ||
| capture_output=True, | ||
| text=True, | ||
| ) | ||
|
|
||
| assert result.returncode == 2 | ||
| assert "broken testcase references found:" in result.stdout | ||
|
|
||
|
|
||
| def test_traceability_coverage_prints_unlinked_requirements(tmp_path: Path) -> None: | ||
| needs_json = _write_needs_json(tmp_path) | ||
|
|
||
| result = subprocess.run( | ||
| [ | ||
| sys.executable, | ||
| _MY_PATH.parent / "traceability_coverage.py", | ||
| "--needs-json", | ||
| str(needs_json), | ||
| "--min-req-code", | ||
| "0", | ||
| "--min-req-test", | ||
| "0", | ||
| "--min-req-fully-linked", | ||
| "0", | ||
| "--min-tests-linked", | ||
| "0", | ||
| "--print-unlinked-requirements", | ||
| ], | ||
| capture_output=True, | ||
| text=True, | ||
| ) | ||
|
|
||
| assert result.returncode == 0 | ||
| assert "Unlinked requirement details:" in result.stdout | ||
| assert "Missing source_code_link: REQ_2" in result.stdout | ||
| assert "Missing testlink: REQ_1" in result.stdout | ||
| assert "Not fully linked: REQ_1, REQ_2" in result.stdout | ||
|
|
||
|
|
||
| def test_traceability_coverage_accepts_workspace_relative_needs_json( | ||
| tmp_path: Path, | ||
| ) -> None: | ||
| workspace = tmp_path / "workspace" | ||
| workspace.mkdir() | ||
| needs_json = _write_needs_json(workspace) | ||
|
|
||
| env = dict(os.environ) | ||
| env["BUILD_WORKSPACE_DIRECTORY"] = str(workspace) | ||
|
|
||
| result = subprocess.run( | ||
| [ | ||
| sys.executable, | ||
| _MY_PATH.parent / "traceability_coverage.py", | ||
| "--needs-json", | ||
| "needs.json", | ||
| "--min-req-code", | ||
| "0", | ||
| "--min-req-test", | ||
| "0", | ||
| "--min-req-fully-linked", | ||
| "0", | ||
| "--min-tests-linked", | ||
| "0", | ||
| ], | ||
| capture_output=True, | ||
| text=True, | ||
| cwd=tmp_path, | ||
| env=env, | ||
| ) | ||
|
|
||
| assert result.returncode == 0 | ||
| assert f"Traceability input: {needs_json}" in result.stdout |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.