Skip to content

test: add prejudge test scripts.#17

Merged
LeiGuo622 merged 1 commit into
mainfrom
feat/add-prejudge-test
Apr 26, 2026
Merged

test: add prejudge test scripts.#17
LeiGuo622 merged 1 commit into
mainfrom
feat/add-prejudge-test

Conversation

@LeiGuo622
Copy link
Copy Markdown
Owner

No description provided.

Copilot AI review requested due to automatic review settings April 26, 2026 11:47
@LeiGuo622 LeiGuo622 merged commit 54627c4 into main Apr 26, 2026
3 checks passed
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a standalone batch script to run the prejudge analysis across CVE commits listed in a CSV and write results back out to a new CSV, supporting manual/operational validation of src/prejudge behavior.

Changes:

  • Introduces test/test_prejudge.py CLI script to read an input CSV, run PrejudgeController.analyze_and_report() per commit, and write a Prejudge_Result column.
  • Adds basic input file / directory existence checks and prints progress/results to stdout.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread test/test_prejudge.py
Comment on lines +69 to +72
# Capture the output from analyze_and_report
from io import StringIO
import sys

Copy link

Copilot AI Apr 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StringIO (and even sys) are imported inside the per-row loop. Since these imports are constant, move them to module scope (or at least outside the loop) to reduce noise and avoid repeated work; using contextlib.redirect_stdout also simplifies this block.

Copilot uses AI. Check for mistakes.
Comment thread test/test_prejudge.py
from pathlib import Path

# Add src directory to path to import prejudge module
sys.path.insert(0, str(Path(__file__).parent.parent / "src" / "prejudge"))
Copy link

Copilot AI Apr 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sys.path tweak doesn’t match the comment: the code inserts .../src/prejudge (not .../src). Either update the comment, or (preferably) add .../src and import PrejudgeController via the package (and ensure PrejudgeController’s internal imports work in that mode).

Suggested change
sys.path.insert(0, str(Path(__file__).parent.parent / "src" / "prejudge"))
sys.path.insert(0, str(Path(__file__).parent.parent / "src"))

Copilot uses AI. Check for mistakes.
Comment thread test/test_prejudge.py
for row in reader:
cve_id = row['CVE-ID']
commit_id = row['Mainline_Commit']
status = row['Status']
Copy link

Copilot AI Apr 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

status = row['Status'] is assigned but never used. This can be removed, or used in the output (e.g., to filter rows) to avoid dead code and keep the script easier to maintain.

Suggested change
status = row['Status']

Copilot uses AI. Check for mistakes.
Comment thread test/test_prejudge.py
Comment on lines +73 to +86
# Capture stdout
old_stdout = sys.stdout
sys.stdout = captured_output = StringIO()

controller.analyze_and_report(commit_id)

# Restore stdout
sys.stdout = old_stdout
prejudge_result = captured_output.getvalue().strip()

except Exception as e:
prejudge_result = f"Error: {str(e)}"
print(f" Error: {e}")

Copy link

Copilot AI Apr 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If controller.analyze_and_report() raises, sys.stdout is never restored (because restoration only happens on the success path). This can leave the rest of the script writing into the StringIO buffer. Use a try/finally (or contextlib.redirect_stdout) so stdout is always restored even on exceptions.

Copilot uses AI. Check for mistakes.
@LeiGuo622 LeiGuo622 deleted the feat/add-prejudge-test branch April 26, 2026 11:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants