-
Notifications
You must be signed in to change notification settings - Fork 2
feat: add Supermodel dead-code benchmark plugin #4
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c05fa91
feat: add Supermodel dead-code benchmark plugin
greynewell f071523
fix: always place analysis JSON in SupermodelBenchmark.create_environ…
greynewell 06db08a
fix: address review findings on Supermodel benchmark PR
jonathanpopham 0be0b0a
fix: resolve supermodel tasks on recall only, not P & R
greynewell c087928
fix: don't filter dead code candidates with 'no references' reason
greynewell 6f247d9
fix: address remaining review comments on Supermodel benchmark
greynewell 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
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,122 @@ | ||
| """Shared utilities for benchmark implementations.""" | ||
|
|
||
| import json | ||
| import logging | ||
| import subprocess | ||
| from pathlib import Path | ||
| from typing import Any | ||
|
|
||
| logger = logging.getLogger("mcpbr.benchmarks") | ||
|
|
||
|
|
||
| def extract_findings_from_text(text: str, findings_key: str = "dead_code") -> list[dict[str, Any]]: | ||
| """Extract findings array from text/patch content by locating a JSON key. | ||
|
|
||
| Searches for a JSON key (e.g. "dead_code") and extracts the associated array | ||
| using bracket-depth matching. Handles brackets inside JSON strings correctly. | ||
|
|
||
| Args: | ||
| text: Raw text that may contain a JSON object with the findings key. | ||
| findings_key: The JSON key whose array value to extract. | ||
|
|
||
| Returns: | ||
| List of finding dicts, or empty list if not found/parseable. | ||
| """ | ||
| findings: list[dict[str, Any]] = [] | ||
| try: | ||
| marker = f'"{findings_key}"' | ||
| start = text.find(marker) | ||
| if start == -1: | ||
| return findings | ||
| arr_start = text.find("[", start) | ||
| if arr_start == -1: | ||
| return findings | ||
| # Bracket-depth matching that respects JSON strings | ||
| depth = 0 | ||
| in_string = False | ||
| escape_next = False | ||
| for i, c in enumerate(text[arr_start:], arr_start): | ||
| if escape_next: | ||
| escape_next = False | ||
| continue | ||
| if c == "\\": | ||
| if in_string: | ||
| escape_next = True | ||
| continue | ||
| if c == '"': | ||
| in_string = not in_string | ||
| continue | ||
| if in_string: | ||
| continue | ||
| if c == "[": | ||
| depth += 1 | ||
| elif c == "]": | ||
| depth -= 1 | ||
| if depth == 0: | ||
| arr_text = text[arr_start : i + 1] | ||
| parsed = json.loads(arr_text) | ||
| if isinstance(parsed, list): | ||
| findings = parsed | ||
| break | ||
| except (json.JSONDecodeError, ValueError): | ||
| pass | ||
| return findings | ||
|
|
||
|
|
||
| def init_git_workdir(host_workdir: str, timeout: int = 30) -> None: | ||
| """Initialize a git repo in a workdir so the harness can track modifications. | ||
|
|
||
| Args: | ||
| host_workdir: Path to the working directory. | ||
| timeout: Timeout in seconds for each git command. | ||
| """ | ||
| subprocess.run( | ||
| ["git", "init"], cwd=host_workdir, capture_output=True, check=False, timeout=timeout | ||
| ) | ||
| subprocess.run( | ||
| ["git", "config", "user.email", "mcpbr@test.com"], | ||
| cwd=host_workdir, | ||
| capture_output=True, | ||
| check=False, | ||
| timeout=timeout, | ||
| ) | ||
| subprocess.run( | ||
| ["git", "config", "user.name", "MCPBR"], | ||
| cwd=host_workdir, | ||
| capture_output=True, | ||
| check=False, | ||
| timeout=timeout, | ||
| ) | ||
| subprocess.run( | ||
| ["git", "add", "-A"], | ||
| cwd=host_workdir, | ||
| capture_output=True, | ||
| check=False, | ||
| timeout=timeout, | ||
| ) | ||
| subprocess.run( | ||
| ["git", "commit", "-m", "Initial"], | ||
| cwd=host_workdir, | ||
| capture_output=True, | ||
| check=False, | ||
| timeout=timeout, | ||
| ) | ||
|
|
||
|
|
||
| def safe_write_file(host_workdir: str, file_path: str, content: str) -> None: | ||
| """Write a file within host_workdir, raising if the path escapes containment. | ||
|
|
||
| Args: | ||
| host_workdir: Root directory that all writes must stay within. | ||
| file_path: Relative path of the file to write. | ||
| content: File content. | ||
|
|
||
| Raises: | ||
| ValueError: If the resolved path is outside host_workdir. | ||
| """ | ||
| root = Path(host_workdir).resolve() | ||
| full_path = (root / file_path).resolve() | ||
| if not full_path.is_relative_to(root): | ||
| raise ValueError(f"Path traversal detected: {file_path!r} escapes {host_workdir!r}") | ||
| full_path.parent.mkdir(parents=True, exist_ok=True) | ||
| full_path.write_text(content) | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Diff fallback will usually read the deleted
REPORT.jsonarray.This parser grabs the first
"{findings_key}"array it sees. In a normal unified diff, that is often the removed placeholder like- "dead_code": [], so fallback scoring returns an empty list even when the patch later adds real findings. Please prefer the last valid array after the key, or explicitly handle added diff lines.Also applies to: 38-60
🤖 Prompt for AI Agents