Repository navigation
fix(delivery): a repository row is not a pull request #6459
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
vivekchand
wants to merge
2
commits into
main
Choose a base branch
from
fix/delivered-row-labels
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
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,128 @@ | ||
| """The Delivered tab's rows must read as what they are. | ||
|
|
||
| Found by looking at the rendered tab rather than at its data: the | ||
| Repositories view showed `vivekchand/clawmetry #vivekchand/clawmetry` and a | ||
| chip reading "100 pull requests" over a table of repositories. Both come | ||
| from the same cause: ``query_delivery`` carries ``kind`` on the envelope, | ||
| not on each row, so ``!r.kind`` was true for every row and every row was | ||
| rendered in pull-request form. | ||
|
|
||
| Uses the shipped template and app.js with synthetic API fixtures, never a | ||
| live store or the user's browser. | ||
| """ | ||
| import json | ||
| from pathlib import Path | ||
|
|
||
| ROOT = Path(__file__).resolve().parents[1] | ||
|
|
||
| REPO_ROWS = [ | ||
| {"repo": "vivekchand/clawmetry", "ref": "vivekchand/clawmetry", | ||
| "sessions": 94, "cost_usd": 0, "confidence": 1.0, "confidence_min": 1.0, | ||
| "role": "explored", "basis": "pr_reference", "evidence": "git remote -v", | ||
| "title": "", "state": "", "url": "", "merged_at": 0}, | ||
| {"repo": "huggingface/lerobot", "ref": "huggingface/lerobot", | ||
| "sessions": 3, "cost_usd": 0, "confidence": 1.0, "confidence_min": 1.0, | ||
| "role": "explored", "basis": "pr_reference", | ||
| "evidence": "git clone https://github.com/huggingface/lerobot.git", | ||
| "title": "", "state": "", "url": "", "merged_at": 0}, | ||
| ] | ||
| PR_ROWS = [ | ||
| {"repo": "vivekchand/clawmetry", "ref": "6450", "sessions": 2, | ||
| "cost_usd": 12.5, "confidence": 1.0, "confidence_min": 1.0, | ||
| "role": "authored", "basis": "pr_reference", | ||
| "evidence": "gh pr view 6450", "title": "A fold", "state": "merged", | ||
| "url": "https://github.com/vivekchand/clawmetry/pull/6450", | ||
| "merged_at": 0}, | ||
| ] | ||
| BRANCH_ROWS = [ | ||
| {"repo": "", "ref": "feat/case-fold", "sessions": 1, "cost_usd": 0, | ||
| "confidence": 1.0, "confidence_min": 1.0, "role": "authored", | ||
| "basis": "pr_reference", "evidence": "git push origin feat/case-fold", | ||
| "title": "", "state": "", "url": "", "merged_at": 0}, | ||
| ] | ||
| TOTALS = {"attributed_usd": 10.0, "unattributed_usd": 2.0, | ||
| "sessions_attributed": 3, "artifacts": 3} | ||
|
|
||
|
|
||
| def _page(browser, rows_by_kind): | ||
| context = browser.new_context(viewport={"width": 1280, "height": 900}) | ||
| page = context.new_page() | ||
| errors = [] | ||
| page.on("pageerror", lambda e: errors.append(str(e))) | ||
| page.on("console", | ||
| lambda m: errors.append(m.text) if m.type == "error" else None) | ||
| html = ('<!doctype html><html data-theme="dark"><head><meta charset="utf-8">' | ||
| '</head><body>' | ||
| + (ROOT / "clawmetry/templates/tabs/delivery.html").read_text() | ||
| + "</body></html>") | ||
|
|
||
| def route(request_route): | ||
| path = request_route.request.url.split("delivery.test", 1)[-1] | ||
| if path == "/": | ||
| request_route.fulfill(content_type="text/html", body=html) | ||
| return | ||
| kind = "pr" | ||
| if "kind=" in path: | ||
| kind = path.split("kind=", 1)[1].split("&")[0] | ||
| body = {"rows": rows_by_kind.get(kind, []), "totals": TOTALS, | ||
| "available": True, "kind": kind} | ||
| request_route.fulfill(content_type="application/json", | ||
| body=json.dumps(body)) | ||
|
|
||
| context.route("https://delivery.test/**", route) | ||
| page.goto("https://delivery.test/") | ||
| page.evaluate("""() => { | ||
| window.t = (key, _x, fallback) => fallback || key; | ||
| window.escHtml = s => String(s === undefined || s === null ? '' : s) | ||
| .replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>') | ||
| .replace(/"/g, '"'); | ||
| }""") | ||
| page.add_script_tag(path=str(ROOT / "clawmetry/static/js/app.js")) | ||
| return context, page, errors | ||
|
|
||
|
|
||
| def test_a_repository_row_is_not_rendered_as_a_pull_request(_shared_chromium): | ||
| context, page, errors = _page(_shared_chromium, {"repo": REPO_ROWS}) | ||
| try: | ||
| page.select_option("#dlv-kind", "repo") | ||
| page.wait_for_function( | ||
| "() => document.querySelectorAll('#dlv-table tbody tr').length > 0") | ||
| first = page.locator("#dlv-table tbody tr td").first.inner_text().strip() | ||
| assert first == "vivekchand/clawmetry", first | ||
| assert "#" not in page.locator("#dlv-table").inner_text() | ||
| # The count chip must name what the table actually lists. | ||
| summary = page.locator("#dlv-summary").inner_text() | ||
| assert "repositories" in summary, summary | ||
| assert "pull requests" not in summary.split("not tied")[-1], summary | ||
| assert errors == [], errors | ||
| finally: | ||
| context.close() | ||
|
|
||
|
|
||
| def test_a_pull_request_row_still_reads_repo_then_number(_shared_chromium): | ||
| """The half a kind-aware label could quietly break.""" | ||
| context, page, errors = _page(_shared_chromium, {"pr": PR_ROWS}) | ||
| try: | ||
| page.evaluate("loadDelivery()") | ||
| page.wait_for_function( | ||
| "() => document.querySelectorAll('#dlv-table tbody tr').length > 0") | ||
| first = page.locator("#dlv-table tbody tr td").first.inner_text() | ||
| assert "vivekchand/clawmetry #6450" in first, first | ||
| assert "pull requests" in page.locator("#dlv-summary").inner_text() | ||
| assert errors == [], errors | ||
| finally: | ||
| context.close() | ||
|
|
||
|
|
||
| def test_a_branch_row_shows_the_branch_and_no_hash(_shared_chromium): | ||
| context, page, errors = _page(_shared_chromium, {"branch": BRANCH_ROWS}) | ||
| try: | ||
| page.select_option("#dlv-kind", "branch") | ||
| page.wait_for_function( | ||
| "() => document.querySelectorAll('#dlv-table tbody tr').length > 0") | ||
| first = page.locator("#dlv-table tbody tr td").first.inner_text().strip() | ||
| assert first == "feat/case-fold", first | ||
| assert "branches" in page.locator("#dlv-summary").inner_text() | ||
| assert errors == [], errors | ||
| finally: | ||
| context.close() |
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.
The blueprint specifies that each SessionArtifact model row should have a required 'kind' field (one of pr/repo/branch/commit/file), but the API implementation places 'kind' only on the response envelope, requiring rows to fall back to the view-level kind during rendering.