Repository navigation
build: ship the explorer's web UI in the agentenv-framework wheel #52
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
earakely-scale
wants to merge
3
commits into
main
Choose a base branch
from
build/ship-explorer-ui
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
3 commits
Select commit
Hold shift + click to select a range
8127141
build: ship the explorer's web UI in the agentenv-framework wheel
earakely-scale 9626fcc
build: leave the explorer UI's source out of the sdist too
earakely-scale b968051
build: check every asset the explorer's index.html loads is in the wheel
earakely-scale 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 |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| """Fail unless a built agentenv-framework wheel carries the explorer's web UI: ``agent_env/explorer/static/index.html`` | ||
| and every ``/_next/`` script, stylesheet and font it references, so ``agent-env up`` serves a page that loads. | ||
|
|
||
| Usage: ``python .github/scripts/check_explorer_ui.py WHEEL``. Run by the release and by the ``ui`` job on pull requests. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import re | ||
| import sys | ||
| import zipfile | ||
| from pathlib import Path | ||
| from urllib.parse import unquote | ||
|
|
||
| STATIC = "agent_env/explorer/static/" | ||
| _ASSET = re.compile(r'(?:src|href)="/(_next/[^"?#]+)') | ||
|
|
||
|
|
||
| def ui_problems(wheel: Path) -> list[str]: | ||
| """What the wheel's explorer UI is missing; empty when index.html and every asset it references are there.""" | ||
| with zipfile.ZipFile(wheel) as archive: | ||
| names = set(archive.namelist()) | ||
| if STATIC + "index.html" not in names: | ||
| return [f"{STATIC}index.html is missing"] | ||
| # The catch-all page's chunk is referenced percent-encoded (%5B%5B...slug%5D%5D) but stored as [[...slug]]. | ||
| assets = sorted({unquote(a) for a in _ASSET.findall(archive.read(STATIC + "index.html").decode())}) | ||
| if not assets: | ||
| return [f"{STATIC}index.html references no /_next/ assets"] | ||
| return [f"{STATIC}{asset} is missing" for asset in assets if STATIC + asset not in names] | ||
|
|
||
|
|
||
| def main(argv: list[str]) -> int: | ||
| if len(argv) != 1: | ||
| print("usage: check_explorer_ui.py WHEEL", file=sys.stderr) | ||
| return 2 | ||
| problems = ui_problems(Path(argv[0])) | ||
| for problem in problems: | ||
| print(f"::error::the wheel's explorer UI is incomplete: {problem}") | ||
| if not problems: | ||
| print(f"{argv[0]}: the explorer UI's index.html and every asset it references are in the wheel") | ||
| return 1 if problems else 0 | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| sys.exit(main(sys.argv[1:])) |
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,63 @@ | ||
| """The wheel check in ``.github/scripts/check_explorer_ui.py``: the explorer's index.html and every ``/_next/`` asset | ||
| it references must be in the built wheel.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import importlib.util | ||
| import zipfile | ||
| from pathlib import Path | ||
|
|
||
| SCRIPT = Path(__file__).resolve().parents[2] / ".github" / "scripts" / "check_explorer_ui.py" | ||
| _spec = importlib.util.spec_from_file_location("check_explorer_ui", SCRIPT) | ||
| check_explorer_ui = importlib.util.module_from_spec(_spec) | ||
| _spec.loader.exec_module(check_explorer_ui) | ||
|
|
||
| STATIC = "agent_env/explorer/static/" | ||
| INDEX = ( | ||
| '<html><head><link rel="stylesheet" href="/_next/static/css/app.css"/>' | ||
| '<link rel="preload" href="/_next/static/media/font.woff2"/><link rel="icon" href="/favicon.ico"/></head>' | ||
| '<body><a href="/docs">Docs</a><script src="/_next/static/chunks/main.js?dpl=1"></script></body></html>' | ||
| ) | ||
| ASSETS = ["_next/static/css/app.css", "_next/static/media/font.woff2", "_next/static/chunks/main.js"] | ||
|
|
||
|
|
||
| def _wheel(tmp_path: Path, files: dict[str, str]) -> Path: | ||
| wheel = tmp_path / "agentenv_framework-1.0-py3-none-any.whl" | ||
| with zipfile.ZipFile(wheel, "w") as archive: | ||
| for name, text in files.items(): | ||
| archive.writestr(name, text) | ||
| return wheel | ||
|
|
||
|
|
||
| def test_a_wheel_with_index_html_and_every_asset_it_references_passes(tmp_path): | ||
| wheel = _wheel(tmp_path, {STATIC + "index.html": INDEX, **{STATIC + asset: "x" for asset in ASSETS}}) | ||
|
|
||
| assert check_explorer_ui.ui_problems(wheel) == [] | ||
|
|
||
|
|
||
| def test_each_referenced_asset_the_wheel_leaves_out_is_named(tmp_path): | ||
| wheel = _wheel(tmp_path, {STATIC + "index.html": INDEX, STATIC + ASSETS[0]: "x"}) | ||
|
|
||
| assert check_explorer_ui.ui_problems(wheel) == [ | ||
| f"{STATIC}_next/static/chunks/main.js is missing", | ||
| f"{STATIC}_next/static/media/font.woff2 is missing", | ||
| ] | ||
|
|
||
|
|
||
| def test_a_percent_encoded_reference_matches_the_file_stored_under_its_literal_name(tmp_path): | ||
| index = '<script src="/_next/static/chunks/pages/%5B%5B...slug%5D%5D-abc.js"></script>' | ||
| wheel = _wheel(tmp_path, {STATIC + "index.html": index, STATIC + "_next/static/chunks/pages/[[...slug]]-abc.js": "x"}) | ||
|
|
||
| assert check_explorer_ui.ui_problems(wheel) == [] | ||
|
|
||
|
|
||
| def test_a_wheel_without_index_html_fails(tmp_path): | ||
| wheel = _wheel(tmp_path, {"agent_env/__init__.py": ""}) | ||
|
|
||
| assert check_explorer_ui.ui_problems(wheel) == [f"{STATIC}index.html is missing"] | ||
|
|
||
|
|
||
| def test_an_index_html_that_references_no_built_assets_fails(tmp_path): | ||
| wheel = _wheel(tmp_path, {STATIC + "index.html": "<html><body>placeholder</body></html>"}) | ||
|
|
||
| assert check_explorer_ui.ui_problems(wheel) == [f"{STATIC}index.html references no /_next/ assets"] |
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.
If the sdist contains
explorer/ui/andtarstill has paths to list,grep -qstops at the first match and closes the pipe. Withpipefail,tarcan then fail from a broken pipe, making theifcondition false. The job passes instead of flagging the files. Letgrepread the full listing.Prompt To Fix With AI
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.
Good point. Both checks now run
.github/scripts/check_explorer_ui.py. It readsindex.htmlfrom the wheel and fails unless every/_next/script, stylesheet and font that page references is in the wheel too. Writing it surfaced a subtlety: the catch-all page's chunk is referenced percent-encoded (%5B%5B...slug%5D%5D) but stored as[[...slug]], so references are decoded before the lookup. Against real wheels: the full UI wheel passes, the same wheel with_next/stripped fails and names all 14 missing assets, and the current UI-less 0.9.1265 wheel fails on the missingindex.html.tst/unit/test_check_explorer_ui.pycovers those cases plus the encoded reference.