Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ updates:
open-pull-requests-limit: 2
commit-message:
prefix: "deps"
# bgutil is excluded from the group: the plugin must move with the vendored server
# (vendor/bgutil-pot-provider/), which Dependabot cannot do, so its bump comes as a
# PR of its own that tests/test_pot_provider_pin.py turns red. Do the vendor move on
# that PR's branch (see "Updating the pin" in its README); the rest of the group
# stays mergeable.
groups:
python:
patterns: ["*"]
# The plugin hard-fails on a major mismatch with the vendored server script
# (vendor/bgutil-pot-provider/), so a major bump must move both together by hand
# (see "Updating the pin" in its README). Drop this ignore once that upgrade lands.
ignore:
- dependency-name: "bgutil-ytdlp-pot-provider"
update-types: ["version-update:semver-major"]
exclude-patterns: ["bgutil-ytdlp-pot-provider"]
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ On launch MeadowLark probes the provider and, if anything is missing, shows a **
| Component | Where |
|---|---|
| Provider plugin | importable `yt_dlp_plugins.extractor.getpot_bgutil_script` (from `uv sync`) |
| Deno runtime ≥ 2.0 | `deno.exe` in `.venv/Scripts` (from `uv sync`) |
| Deno runtime ≥ 2.4.3 | `deno.exe` in `.venv/Scripts` (from `uv sync`) |
| Generate script | `{server_home}/src/generate_once.ts` |
| Script dependencies | `{server_home}/node_modules` |

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dependencies = [
"pyqt6>=6.9.1",
"requests>=2.32.5",
"wakepy>=0.10.2.post1",
"bgutil-ytdlp-pot-provider>=1.3.1",
"bgutil-ytdlp-pot-provider>=2.0.2",
"yt-dlp>=2025.7.21",
"yt-dlp-ejs>=0.8.0",
"genekit",
Expand Down
17 changes: 12 additions & 5 deletions src/pot_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
from .config import POT_PROVIDER_SERVER_HOME, VENV_SCRIPTS_DIR

# Mirror BgUtilScriptDenoPTP: script at {server_home}/src/generate_once.ts, deps
# under {server_home}/node_modules, Deno >= 2.0.0.
# under {server_home}/node_modules, Deno >= 2.4.3 (_JSRT_MIN_VER, plugin 2.0.2).
_SCRIPT_RELPATH: tuple[str, ...] = ("src", "generate_once.ts")
_NODE_MODULES = "node_modules"
_DENO_MIN_VERSION = (2, 0, 0)
_DENO_MIN_VERSION = (2, 4, 3)
_DENO_VERSION_TIMEOUT_S = 5.0
_DENO_VERSION_RE = re.compile(r"deno\s+(\d+)\.(\d+)\.(\d+)")

Expand Down Expand Up @@ -71,7 +71,7 @@ def summary(self) -> str:
if not self.plugin_installed:
missing.append("provider plugin (bgutil-ytdlp-pot-provider)")
if not self.deno_ok:
missing.append("Deno runtime (>= 2.0)")
missing.append(f"Deno runtime (>= {'.'.join(map(str, _DENO_MIN_VERSION))})")
if not self.script_found:
missing.append("generate_once.ts script")
if not self.node_modules_found:
Expand Down Expand Up @@ -102,7 +102,7 @@ def _plugin_importable() -> bool:


def _deno_ok(scripts_dir: Path) -> bool:
"""Return True if deno.exe exists in ``scripts_dir`` and reports version >= 2.0.0."""
"""Return True if ``scripts_dir`` has a deno.exe at version >= ``_DENO_MIN_VERSION``."""
deno = scripts_dir / "deno.exe"
if not deno.is_file():
return False
Expand Down Expand Up @@ -171,7 +171,14 @@ def _script_cache_dir(server_home: Path) -> Path:


def build_warm_cmd(deno: str | Path, server_home: Path) -> list[str]:
"""Return the exact argv BgUtilScriptDenoPTP uses for its version probe."""
"""
Return the exact argv BgUtilScriptDenoPTP uses for its version probe.

Mirrors plugin 2.x ``_resolve_script_path``, which realpath-resolves
``server_home``; the warm-up must cache the same file paths the probe loads,
or it silently fails to warm the probe.
"""
server_home = Path(os.path.realpath(server_home))
node_mods = server_home / _NODE_MODULES
cache = _script_cache_dir(server_home)
return [
Expand Down
40 changes: 34 additions & 6 deletions tests/test_pot_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@
- find_spec raises ImportError/ValueError -> False

src.pot_provider._deno_ok (additional boundaries)
- exact min version (2.0.0) -> True
- exact min version (2.4.3) -> True
- just below min patch (2.4.2) -> False
- just below min minor (2.3.9) -> False
- just below min major (1.99.99) -> False
- multiline stdout, version on line 1 -> True
- extra internal whitespace -> True
- empty / None stdout -> False
- unparseable / incomplete version -> False
- prerelease suffix (2.0.0-rc.1) -> True (documents permissive parsing)
- prerelease suffix (2.4.3-rc.1) -> True (documents permissive parsing)
- non-zero returncode -> False, even with valid-looking stdout
- subprocess timeout / OSError -> False (swallowed)
- deno.exe path is a directory -> False, subprocess never invoked
Expand Down Expand Up @@ -245,7 +247,7 @@ def test_status_frozen_dataclass_blocks_attribute_delete() -> None:

_ALL_MISSING_LABELS = {
"plugin_installed": "provider plugin (bgutil-ytdlp-pot-provider)",
"deno_ok": "Deno runtime (>= 2.0)",
"deno_ok": "Deno runtime (>= 2.4.3)",
"script_found": "generate_once.ts script",
"node_modules_found": "script dependencies (node_modules)",
}
Expand Down Expand Up @@ -284,7 +286,7 @@ def test_summary_component_order_is_stable_when_all_missing() -> None:
)
assert status.summary() == (
"provider plugin (bgutil-ytdlp-pot-provider), "
"Deno runtime (>= 2.0), "
"Deno runtime (>= 2.4.3), "
"generate_once.ts script, "
"script dependencies (node_modules)"
)
Expand Down Expand Up @@ -332,17 +334,21 @@ def test_plugin_importable_false_on_value_error() -> None:
@pytest.mark.parametrize(
("stdout", "expected"),
[
("deno 2.0.0 (release, x86_64-pc-windows-msvc)", True),
("deno 2.4.3 (release, x86_64-pc-windows-msvc)", True),
("deno 2.4.2 (release)", False),
("deno 2.3.9 (release)", False),
("deno 1.99.99 (release)", False),
("deno 2.5.4 (stable)\nv8 12.4.254.21\ntypescript 5.6.2\n", True),
("deno 2.5.4 (release)", True),
("", False),
("deno version unknown", False),
("deno 2.5", False),
("deno 2.0.0-rc.1 (canary)", True),
("deno 2.4.3-rc.1 (canary)", True),
],
ids=[
"exact-min-boundary",
"just-below-min-patch",
"just-below-min-minor",
"just-below-min-major",
"multiline-first-line",
"extra-whitespace",
Expand Down Expand Up @@ -692,6 +698,28 @@ def test_build_warm_cmd_escapes_literal_commas(
assert "a,,b" not in cmd[-2]


def test_build_warm_cmd_realpaths_server_home(
tmp_path: Path,
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""Plugin 2.x realpath-resolves server_home; the warm-up argv must follow suit."""
link = tmp_path / "link"
real = tmp_path / "real"
monkeypatch.setenv("XDG_CACHE_HOME", str(tmp_path / "xdg"))
monkeypatch.setattr(
"src.pot_provider.os.path.realpath",
lambda p: str(real) if Path(p) == link else str(p),
)
cmd = pot_provider.build_warm_cmd("deno", link)

ffi = next(a for a in cmd if a.startswith("--allow-ffi="))
read = next(a for a in cmd if a.startswith("--allow-read="))
assert ffi == f"--allow-ffi={real / 'node_modules'}"
assert str(real / "node_modules") in read
assert cmd[-2] == str(real / "src" / "generate_once.ts")
assert str(link) not in " ".join(cmd)


# ---------------------------------------------------------------------------
# build_warm_env — environment construction
# ---------------------------------------------------------------------------
Expand Down
73 changes: 73 additions & 0 deletions tests/test_pot_provider_pin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
"""
Guards that the bgutil plugin and the vendored server stay on the same version.

The ``bgutil-ytdlp-pot-provider`` plugin (a PyPI dependency) and the server script it
runs (vendored under ``vendor/bgutil-pot-provider/``) must move together. A
lockfile-only bump of the plugin makes its ``_check_version`` fail, so no GVS PO token
is minted and every 1080p download 403s at the media stage.

On failure, follow "Updating the pin" in ``vendor/bgutil-pot-provider/README.md``.
"""

import json
import re
import tomllib
from pathlib import Path

from src import pot_provider

_REPO_ROOT = Path(__file__).resolve().parent.parent
_VENDOR = _REPO_ROOT / "vendor" / "bgutil-pot-provider"
_PIN_HINT = "follow 'Updating the pin' in vendor/bgutil-pot-provider/README.md"
_DENO_DEP_RE = re.compile(r"^deno\s*>=\s*(\d+)\.(\d+)\.(\d+)")


def _vendored_version() -> str:
package_json = json.loads((_VENDOR / "server" / "package.json").read_text(encoding="utf-8"))
return str(package_json["version"])


def _project_dependencies() -> list[str]:
pyproject = tomllib.loads((_REPO_ROOT / "pyproject.toml").read_text(encoding="utf-8"))
return list(pyproject["project"]["dependencies"])


def test_vendored_server_matches_installed_plugin() -> None:
from yt_dlp_plugins.extractor import getpot_bgutil

# __version__ is the value the plugin's _check_version compares against the script.
assert getpot_bgutil.__version__ == _vendored_version(), (
f"bgutil plugin and vendored server differ; {_PIN_HINT}"
)


def test_vendor_readme_records_current_pin() -> None:
readme = (_VENDOR / "README.md").read_text(encoding="utf-8")
match = re.search(r"\*\*Pinned tag:\*\* `([^`]+)`", readme)
assert match is not None, "vendor README lost its 'Pinned tag' line"
assert match.group(1) == _vendored_version(), f"README pin is stale; {_PIN_HINT}"


def test_pyproject_floor_is_vendored_version() -> None:
expected = f"bgutil-ytdlp-pot-provider>={_vendored_version()}"
assert expected in _project_dependencies(), (
f"pyproject.toml floor must be {expected!r}; {_PIN_HINT}"
)


def test_deno_min_version_mirrors_plugin() -> None:
from yt_dlp_plugins.extractor.getpot_bgutil_script import BgUtilScriptDenoPTP

plugin_min = BgUtilScriptDenoPTP._JSRT_MIN_VER # pyright: ignore[reportPrivateUsage, reportAttributeAccessIssue]
assert plugin_min == pot_provider._DENO_MIN_VERSION, ( # pyright: ignore[reportPrivateUsage]
f"_DENO_MIN_VERSION drifted from the plugin's _JSRT_MIN_VER; {_PIN_HINT}"
)


def test_pyproject_deno_floor_meets_plugin_min() -> None:
matches = [m for dep in _project_dependencies() if (m := _DENO_DEP_RE.match(dep))]
assert len(matches) == 1, "expected exactly one 'deno>=X.Y.Z' dependency in pyproject.toml"
floor = tuple(int(g) for g in matches[0].groups())
assert floor >= pot_provider._DENO_MIN_VERSION, ( # pyright: ignore[reportPrivateUsage]
f"pyproject deno floor {floor} is below the provider minimum"
)
10 changes: 10 additions & 0 deletions tests/test_repo_hygiene.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,13 @@ def test_cookies_and_user_state_ignored(path: str) -> None:
def test_dependabot_watches_uv_lockfile() -> None:
config = (_REPO_ROOT / ".github" / "dependabot.yml").read_text(encoding="utf-8")
assert 'package-ecosystem: "uv"' in config


def test_dependabot_excludes_bgutil_from_python_group() -> None:
# Without the exclusion, bgutil's bump rides in the grouped PR and turns the whole
# group red (tests/test_pot_provider_pin.py), blocking unrelated dependency updates.
config = (_REPO_ROOT / ".github" / "dependabot.yml").read_text(encoding="utf-8")
uncommented = "\n".join(
line for line in config.splitlines() if not line.lstrip().startswith("#")
)
assert 'exclude-patterns: ["bgutil-ytdlp-pot-provider"]' in uncommented
8 changes: 4 additions & 4 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 31 additions & 6 deletions vendor/bgutil-pot-provider/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ used in "script-deno" mode to mint the per-video GVS PO token that YouTube requi
for 1080p+ downloads (yt-dlp #12482).

- **Upstream:** https://github.com/Brainicism/bgutil-ytdlp-pot-provider
- **Pinned tag:** `1.3.1` — must match the `bgutil-ytdlp-pot-provider` version pinned in
- **Pinned tag:** `2.0.2` — must match the `bgutil-ytdlp-pot-provider` version pinned in
`pyproject.toml` / `uv.lock` (the plugin's `_check_version` hard-fails on a major mismatch).
- **License:** GPL-3.0 — see [LICENSE](LICENSE) (copied verbatim from upstream at the pinned tag).

Only the text source is vendored (`src/`, `deno.lock`, `package.json`, `package-lock.json`,
`tsconfig.json`, etc.). The installed `node_modules/` is **generated**, not committed — run:
Only the text source is vendored (`src/`, `deno.json`, `deno.lock`, `package.json`,
`package-lock.json`, `tsconfig.json`, etc.). The installed `node_modules/` is **generated**, not committed — run:

```
uv run python scripts/setup_pot_provider.py
Expand All @@ -22,6 +22,31 @@ points `POT_PROVIDER_SERVER_HOME` here (dev) or at the bundled `bgutil-server` d

## Updating the pin

Re-clone the new tag's `server/` directory over this one (excluding `node_modules/`,
`build/`, `.git/`), bump the pin in `pyproject.toml`, run `uv lock`, and re-run
`scripts/setup_pot_provider.py --force`.
`tests/test_pot_provider_pin.py` fails when the plugin, this directory, the pin above, or the
Deno-minimum mirror drift apart. Dependabot opens bgutil bumps as a PR of their own (excluded from
the Python group), so do the steps below on that PR's branch.

1. Replace the vendored source. Clone the new tag, then remove the tracked `server/` files and copy
the clone's `server/` in, so files upstream deleted are deleted here too (gitignored
`node_modules/` stays):
```
git clone --depth 1 --branch <tag> https://github.com/Brainicism/bgutil-ytdlp-pot-provider.git <clone-dir>
git rm -r -q vendor/bgutil-pot-provider/server
cp -r <clone-dir>/server/. vendor/bgutil-pot-provider/server/
git add vendor/bgutil-pot-provider/server
```
Compare `LICENSE` against the clone's (ignoring line endings) and update the **Pinned tag** line
above.
2. Bump the floor in `pyproject.toml`, run `uv lock --upgrade-package bgutil-ytdlp-pot-provider`,
then `uv sync`.
3. **Delete** `server/node_modules` and run `uv run python scripts/setup_pot_provider.py`. Do not
use `--force`: `deno install` does not prune packages the new lock dropped, and
`scripts/collect_licenses.py` walks `node_modules/.deno`, so stale packages would ship and get
licence-listed.
4. Diff the plugin's `getpot_bgutil.py` and `getpot_bgutil_script.py` between the old and new tags
and update the mirrors in `src/pot_provider.py` (`_DENO_MIN_VERSION`, `build_warm_cmd`). Raise
the `deno` floor in `pyproject.toml` if the plugin's minimum moved past it.
5. Run `uv run pytest tests/test_pot_provider_pin.py`.
6. Restart the app, then do a real, full 1080p download with `VID_DL_YTDLP_VERBOSE=true` and check
the "Invoking http downloader" URL for `pot=`. Never use `--test`: a 10 KB probe passes while
real downloads 403.
6 changes: 4 additions & 2 deletions vendor/bgutil-pot-provider/server/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM node:25-bookworm-slim AS install
FROM node:26-bookworm-slim AS install
USER node
WORKDIR /app

Expand All @@ -23,8 +23,9 @@ COPY --from=build_node /app/build /app/build

EXPOSE 4416
ENTRYPOINT ["/usr/local/bin/node", "build/main.js"]
CMD ["--host", "0.0.0.0"]

FROM denoland/deno:debian-2.6.9 AS server_deno
FROM denoland/deno:debian-2.9.5 AS server_deno
USER deno
WORKDIR /app
ENV DENO_DIR=/app/.cache/deno
Expand All @@ -42,3 +43,4 @@ ENTRYPOINT [ \
"/usr/bin/deno", "run", "--allow-env", "--allow-net", \
"--allow-ffi=/app/node_modules", "--allow-read=/app/node_modules", \
"/app/src/main.ts"]
CMD ["--host", "0.0.0.0"]
5 changes: 5 additions & 0 deletions vendor/bgutil-pot-provider/server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ If you are interested in using the script/server standalone for generating your

# Server

**Options**

- `-p, --port <PORT>`: The port on which the server listens.
- `-H, --host <HOST>`: Host/IP to listen on. Repeat it or separate values with commas to bind multiple addresses. Defaults to localhost only (`127.0.0.1` and `::1`).

**Endpoints**

- **POST /get_pot**: Generate a new POT.
Expand Down
3 changes: 3 additions & 0 deletions vendor/bgutil-pot-provider/server/deno.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"allowScripts": ["npm:@swc/core@1.16.0", "npm:canvas@3.2.3"]
}
Loading
Loading