fix(url): also emit #datalabBackendUrl=<full URL> fragment - #27
Merged
Merged
Conversation
`colab url` previously emitted only `?dbu=<urlencoded path>`, which the Colab frontend's `Traits.getDatalabBackendUrl` reads. But some frontend code paths consult the hash-fragment form `#datalabBackendUrl=<full URL>` first and ignore `dbu`, so the query-only form silently failed for those users (the frontend fell through to allocating a fresh VM via `/tun/m/assign` instead of attaching to the existing session). New output format: https://<host>/notebooks/empty.ipynb?dbu=%2Ftun%2Fm%2F<endpoint>#datalabBackendUrl=<host>/tun/m/<endpoint> Key design points: - Fragment value is a FULL URL (with scheme + host), not just the path. - Fragment is emitted RAW (no URL encoding) because browsers don't decode the fragment before passing `location.hash` to page JS, and Colab's parser calls `new URL(rawString)` directly. Percent-encoding `:` or `/` here would break the parser. - Fragment host always matches `--host` so Colab's same-origin enforcement on embedded backend URLs doesn't block the connection, and `--host https://colab.sandbox.google.com` users get a sandbox fragment automatically. - The existing `?dbu=` param is kept for backwards compatibility and to handle frontend code paths that consult it instead. Three new test cases in tests/test_url.py: 1. test_url_fragment_is_not_url_encoded - asserts %3A and %2F are NOT present in the fragment, and the literal `://` IS. 2. test_url_both_signals_present - invariant: every URL has BOTH `?dbu=` and `#datalabBackendUrl=`. 3. test_url_open_flag_includes_fragment - --open propagates the fragment to webbrowser.open() (otherwise the launch attaches to a fresh VM). Existing tests updated to assert the fragment value alongside the existing `dbu` assertions (4 tests touched). Integration-verified live against synthetic session state with three host shapes (default research.google.com, sandbox.google.com, and trailing-slash); all produced correctly-shaped URLs with no `//` artifacts and host-matching fragments.
sethtroisi
approved these changes
May 27, 2026
sethtroisi
pushed a commit
that referenced
this pull request
May 27, 2026
…oup (#29) These three packages were declared in [project].dependencies, which forced every consumer that ran `pip install google-colab-cli` to also install the entire pytest test framework plus its transitive deps (coverage, iniconfig, pluggy) -- ~2.5MB of test machinery that user code never imports. The correct semantic for test dependencies is [dependency-groups].dev (PEP 735), which `uv sync` populates by default for contributors but is NOT advertised in the published wheel's metadata as a runtime requirement. Concrete impact measured by installing the resulting wheel into a fresh py3.13 venv (`uv pip install dist/*.whl`): Before: 57 packages, 200 MB site-packages After: 51 packages, 197 MB site-packages Gone: pytest, pytest-cov, pytest-mock, coverage, iniconfig, pluggy Beyond size, removing pytest from runtime deps stops dependency scanners (pipdeptree, pip-audit, dependabot, snyk) from treating pytest version pins as user-facing constraints -- previously, any downstream environment that pinned pytest 8.x for plugin compat would conflict with our floor of pytest>=9.0.2 even though no user code imports pytest. Verified: - `uv sync` + `uv run pytest tests/` -> 201 passed (dev group still installs everything contributors need) - `uv run ruff check .` -> clean - Built wheel + installed into fresh venv: no pytest/coverage/pluggy in site-packages, `colab version` works, `colab url` works (verifies #27 fragment fix is intact in the install path).
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
colab urlpreviously emitted only?dbu=<urlencoded path>. Some Colab frontend code paths consult#datalabBackendUrl=<full URL>first and ignoredbu— for those users the printed URL silently fell through to allocating a fresh VM via/tun/m/assigninstead of attaching to the existing session. Now we emit BOTH signals.New output format:
Design points
location.hashto page JS, and Colab's parser callsnew URL(rawString)directly. Encoding:→%3Ahere would break the parser.--hostso same-origin enforcement passes, and--host https://colab.sandbox.google.comusers get a sandbox fragment automatically.?dbu=param is kept for backwards compatibility.Tests
3 new test cases in
tests/test_url.py:test_url_fragment_is_not_url_encoded— asserts%3A/%2Fare NOT in the fragment, and literal://IS.test_url_both_signals_present— invariant: every URL has BOTH?dbu=and#datalabBackendUrl=.test_url_open_flag_includes_fragment—--openpropagates the fragment towebbrowser.open().4 existing tests updated to assert the fragment value alongside their existing
dbuassertions.Verification
uv run pytest tests/— 201 passed (was 198)uv run ruff check .— cleanAll three: no
//artifacts, fragment host matches page origin, fragment is raw not encoded.