-
Notifications
You must be signed in to change notification settings - Fork 90
feat(issue-discovery): precise post-merge edit detection upgrade #434
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
corevibe555
wants to merge
4
commits into
entrius:test
Choose a base branch
from
corevibe555:feature/issue-402-post-merge-edit-detection
base: test
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
4 commits
Select commit
Hold shift + click to select a range
a4af442
feat(issue-discovery): precise post-merge edit detection (#402)
corevibe555 29f6329
fix(issue-discovery): use first:1 for userContentEdits (#402)
corevibe555 221e415
style: ruff format
corevibe555 a7c04cc
style: drop unused variable in test
corevibe555 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -95,6 +95,14 @@ | |
| ... on User { databaseId } | ||
| } | ||
| authorAssociation | ||
| userContentEdits(first: 1) { | ||
| nodes { editedAt } | ||
| } | ||
| timelineItems(itemTypes: [RENAMED_TITLE_EVENT], last: 1) { | ||
| nodes { | ||
| ... on RenamedTitleEvent { createdAt } | ||
| } | ||
| } | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To get last title edit time of the issue. |
||
| } | ||
| } | ||
| reviews(first: 3, states: APPROVED) { | ||
|
|
||
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
124 changes: 124 additions & 0 deletions
124
tests/validator/test_issue_discovery_post_merge_edit.py
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,124 @@ | ||
| """Post-merge body/title edit detection. | ||
|
|
||
| Benign activity (bot comments, labels) must not demote solved issues; | ||
| real body/title edits after merge must. | ||
| """ | ||
|
|
||
| from datetime import datetime, timedelta, timezone | ||
| from typing import Dict | ||
|
|
||
| from gittensor.classes import Issue, MinerEvaluation, PRState, PullRequest | ||
| from gittensor.constants import MIN_TOKEN_SCORE_FOR_BASE_SCORE | ||
| from gittensor.validator.issue_discovery.scoring import _collect_issues_from_prs | ||
| from gittensor.validator.utils.load_weights import RepositoryConfig | ||
|
|
||
| DISCOVERER_UID = 1 | ||
| SOLVER_UID = 2 | ||
| DISCOVERER_GH = '1001' | ||
| SOLVER_GH = '2002' | ||
| REPO = 'owner/repo' | ||
|
|
||
|
|
||
| def _merged_at() -> datetime: | ||
| return datetime(2025, 1, 1, 12, 0, tzinfo=timezone.utc) | ||
|
|
||
|
|
||
| def _make_issue( | ||
| *, | ||
| updated_at: datetime = None, | ||
| body_or_title_edited_at: datetime = None, | ||
| ) -> Issue: | ||
| return Issue( | ||
| number=42, | ||
| pr_number=7, | ||
| repository_full_name=REPO, | ||
| title='bug', | ||
| created_at=_merged_at() - timedelta(days=5), | ||
| closed_at=_merged_at(), | ||
| author_login='alice', | ||
| state='CLOSED', | ||
| author_github_id=DISCOVERER_GH, | ||
| updated_at=updated_at, | ||
| body_or_title_edited_at=body_or_title_edited_at, | ||
| ) | ||
|
|
||
|
|
||
| def _make_pr(issue: Issue) -> PullRequest: | ||
| return PullRequest( | ||
| number=7, | ||
| repository_full_name=REPO, | ||
| uid=SOLVER_UID, | ||
| hotkey='hk', | ||
| github_id=SOLVER_GH, | ||
| title='fix', | ||
| author_login='bob', | ||
| merged_at=_merged_at(), | ||
| created_at=_merged_at() - timedelta(days=1), | ||
| pr_state=PRState.MERGED, | ||
| token_score=float(MIN_TOKEN_SCORE_FOR_BASE_SCORE) + 10.0, | ||
| base_score=10.0, | ||
| issues=[issue], | ||
| ) | ||
|
|
||
|
|
||
| def _evaluations(pr: PullRequest) -> Dict[int, MinerEvaluation]: | ||
| discoverer = MinerEvaluation(uid=DISCOVERER_UID, hotkey='hk1', github_id=DISCOVERER_GH) | ||
| solver = MinerEvaluation(uid=SOLVER_UID, hotkey='hk2', github_id=SOLVER_GH) | ||
| solver.merged_pull_requests = [pr] | ||
| return {DISCOVERER_UID: discoverer, SOLVER_UID: solver} | ||
|
|
||
|
|
||
| def _repos() -> Dict[str, RepositoryConfig]: | ||
| return {REPO: RepositoryConfig(weight=1.0)} | ||
|
|
||
|
|
||
| def _run(pr: PullRequest): | ||
| from collections import defaultdict | ||
|
|
||
| from gittensor.validator.issue_discovery.scoring import _DiscovererData | ||
|
|
||
| evaluations = _evaluations(pr) | ||
| gh_to_uid = {DISCOVERER_GH: DISCOVERER_UID, SOLVER_GH: SOLVER_UID} | ||
| discoverer_data = defaultdict(lambda: _DiscovererData()) | ||
| _collect_issues_from_prs(evaluations, gh_to_uid, discoverer_data, _repos()) | ||
| return discoverer_data[DISCOVERER_GH] | ||
|
|
||
|
|
||
| def test_benign_updated_at_after_merge_is_ignored(): | ||
| """Bot activity bumps updated_at but not body_or_title_edited_at → stays solved.""" | ||
| issue = _make_issue( | ||
| updated_at=_merged_at() + timedelta(hours=1), # noisy bot bump | ||
| body_or_title_edited_at=None, | ||
| ) | ||
| pr = _make_pr(issue) | ||
| data = _run(pr) | ||
|
|
||
| assert data.solved_count == 1 | ||
| assert data.closed_count == 0 | ||
| assert len(data.scored_issues) == 1 | ||
|
|
||
|
|
||
| def test_real_body_edit_after_merge_demotes(): | ||
| """An actual body edit after merge demotes solved → closed.""" | ||
| issue = _make_issue( | ||
| updated_at=_merged_at() + timedelta(hours=1), | ||
| body_or_title_edited_at=_merged_at() + timedelta(hours=1), | ||
| ) | ||
| pr = _make_pr(issue) | ||
| data = _run(pr) | ||
|
|
||
| assert data.solved_count == 0 | ||
| assert data.closed_count == 1 | ||
| assert data.scored_issues == [] | ||
|
|
||
|
|
||
| def test_edit_before_merge_is_ignored(): | ||
| """Body edits prior to merge are fine.""" | ||
| issue = _make_issue( | ||
| body_or_title_edited_at=_merged_at() - timedelta(hours=1), | ||
| ) | ||
| pr = _make_pr(issue) | ||
| data = _run(pr) | ||
|
|
||
| assert data.solved_count == 1 | ||
| assert data.closed_count == 0 |
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.
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.
To get last body edit, first:1 will return newest edit time, proved by manual testing