From 06caed5db13318f9482a8997e4a4b5fc821d9d8e Mon Sep 17 00:00:00 2001 From: Joel Natividad <1980690+jqnatividad@users.noreply.github.com> Date: Sun, 15 Nov 2026 22:34:17 -0500 Subject: [PATCH] feat!: require qsv 27.0.1, and test that minimum in CI qsv 27.0.1 is the first released qsv whose Data Schematics connect to qsv-clientd. Making it the one minimum (MIN_QSV_VERSION, was 25.0.0) removes the code that only ran with an older qsv: the "schematics won't go live" warning in the daemon and the tray, and the private `qsv get` cache for qsv before 27.0.0. An older qsv now raises QsvVersionError; `qsv-clientd serve` exits with it and the tray shows it as an error. Builds that report the withdrawn 27.0.0 are refused too. The new test-min-qsv CI job downloads the release MIN_QSV_VERSION names, checks that qsv, qsvlite and qsvdp report it, and runs the integration tests against each. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ci.yml | 32 ++++++++++++++++++ CHANGELOG.md | 17 ++++++++++ CLAUDE.md | 10 +++--- README.md | 9 +++-- pyproject.toml | 2 +- src/qsv_client/__init__.py | 2 +- src/qsv_client/client.py | 4 +-- src/qsv_client/daemon/config.py | 29 ---------------- src/qsv_client/daemon/fetch.py | 22 ++---------- src/qsv_client/daemon/server.py | 4 --- src/qsv_client/errors.py | 2 +- src/qsv_client/tray/controller.py | 15 --------- tests/conftest.py | 4 +-- tests/test_client.py | 52 ++++++++++++++--------------- tests/test_daemon.py | 2 +- tests/test_daemon_config_service.py | 19 ----------- tests/test_daemon_fetch.py | 42 +---------------------- tests/test_daemon_server_edges.py | 25 ++++++-------- tests/test_integration.py | 2 +- tests/test_tray_controller.py | 19 ++++------- 20 files changed, 115 insertions(+), 198 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e2952ed..12c4ebe 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -65,6 +65,38 @@ jobs: use_oidc: ${{ !github.event.pull_request.head.repo.fork }} fail_ci_if_error: false + # `test` uses whatever qsv was released last; this keeps the oldest qsv we accept working. + test-min-qsv: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: astral-sh/setup-uv@v6 + with: + python-version: "3.11" + - run: uv sync + - name: Download the qsv release named by MIN_QSV_VERSION + env: + GH_TOKEN: ${{ github.token }} + run: | + v=$(uv run python -c "import qsv_client; print(qsv_client.MIN_QSV_VERSION)") + mkdir -p "$RUNNER_TEMP/qsv" + gh release download "$v" --repo dathere/qsv --pattern "qsv-${v}-x86_64-unknown-linux-musl.zip" --dir "$RUNNER_TEMP/qsv" + unzip -o -q "$RUNNER_TEMP"/qsv/*.zip -d "$RUNNER_TEMP/qsv" + chmod +x "$RUNNER_TEMP"/qsv/qsv* + for b in qsv qsvlite qsvdp; do + reported=$("$RUNNER_TEMP/qsv/$b" --version) + case "$reported" in + "$b $v-"*) ;; + *) echo "expected $b $v, got: $reported"; exit 1 ;; + esac + done + - name: Integration tests (qsv) + run: QSV_BIN="$RUNNER_TEMP/qsv/qsv" uv run pytest -v tests/test_integration.py tests/test_integration_daemon.py + - name: Integration tests (qsvlite) + run: QSV_BIN="$RUNNER_TEMP/qsv/qsvlite" uv run pytest -q tests/test_integration.py + - name: Integration tests (qsvdp) + run: QSV_BIN="$RUNNER_TEMP/qsv/qsvdp" uv run pytest -q tests/test_integration.py + # Separate from `test` because Windows steps run in PowerShell and use the MSVC build. test-windows: strategy: diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c87d49..99e890f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,23 @@ All notable changes to this project are documented here. The format follows ## [Unreleased] +qsv 27.0.1 or later is now required, for everything. It is the first released qsv whose Data +Schematics connect to `qsv-clientd`, so there is no longer a separate, lower minimum for the +rest of the library. + +### Changed + +- **Behavior change:** qsv 27.0.1 or later is now required (`MIN_QSV_VERSION`, was 25.0.0). + An older qsv raises `QsvVersionError` before the first command, as a qsv older than 25.0.0 + did before. `qsv-clientd serve` exits with that error instead of starting with a warning + that schematics can't connect, and the tray shows it as an error instead of a + notification. Development builds of qsv that report 27.0.0 (the release that was + withdrawn) are now refused too; any qsv built since has a later version. +- `qsv-clientd` no longer gives `qsv get` a private cache of its own: every qsv it now accepts + keeps that cache readable by its owner only. +- CI runs the integration tests against qsv 27.0.1 (`qsv`, `qsvlite` and `qsvdp`) as well as + the latest release, so the minimum stays tested. + ### Security - On Windows, a `binary` that is a `.bat` or `.cmd` file (a sandbox wrapper, say) runs diff --git a/CLAUDE.md b/CLAUDE.md index 3b98140..f292d63 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -15,7 +15,8 @@ uv run pytest --cov # with branch coverage (config in pypro ``` CI runs lint, format check, and mypy, plus tests on ubuntu/macos x Python 3.11–3.14 against -qsv, qsvlite, and qsvdp (Linux only). +qsv, qsvlite, and qsvdp (Linux only), all from the latest qsv release. The `test-min-qsv` job +runs the integration tests against the release `MIN_QSV_VERSION` names (Linux, all three). On Windows (Python 3.11–3.14) it runs the full suite against qsv, plus the integration tests against qsvlite. Windows teardown uses Job Objects via ctypes (`_ProcessTree` in `_process.py`); type-check it with `uv run mypy --platform win32` (the lint job runs both). @@ -48,9 +49,10 @@ below the base commit's, and new or changed lines need 100% coverage. ## Invariants -- qsv 25.0.0 is the minimum (`MIN_QSV_VERSION`): the first `--capabilities` qsv with JSON - errors. `--capabilities` is probed before the first run; a binary that rejects the flag - raises `QsvVersionError`. `min_version=` can raise the floor, not lower it. +- qsv 27.0.1 is the minimum (`MIN_QSV_VERSION`): the first released qsv whose Data Schematics + connect to `qsv-clientd` (25.0.0 was the first with `--capabilities` and JSON errors, so + older binaries reject the flag). `--capabilities` is probed before the first run; a binary + that rejects the flag raises `QsvVersionError`. `min_version=` can raise the floor, not lower it. - Successful probes are cached process-wide in `client._caps_cache`, keyed by (path, size, mtime_ns) and shared by `Qsv` and `AsyncQsv`. A per-key lock (per event loop for async, held weakly so loops can be collected) dedups concurrent probes; sync and async diff --git a/README.md b/README.md index d794a2c..c6fdce9 100644 --- a/README.md +++ b/README.md @@ -25,8 +25,7 @@ subprocess pitfalls: Schematic from `qsv viz smart` work with its live data, with an optional system tray to run and control it. See [The qsv-clientd daemon](#the-qsv-clientd-daemon). -qsv itself is not bundled, and **qsv 25.0.0 or later** is required; live Data Schematics -need **qsv 27.0.1 or later** (with an older qsv, `qsv-clientd serve` and the tray say so). +qsv itself is not bundled, and **qsv 27.0.1 or later** is required. Install it from the [qsv releases](https://github.com/dathere/qsv/releases) or a [package manager](https://github.com/dathere/qsv#installation-options). @@ -116,7 +115,7 @@ cancellation propagates, so expect up to a few `kill_grace` periods. ### Capabilities and version checks ```python -qsv = Qsv(min_version="25.1.0") # QsvVersionError on first use if older +qsv = Qsv(min_version="28.0.0") # QsvVersionError on first use if older caps = qsv.capabilities caps.binary, caps.version, caps.features, caps.commands caps.has_feature("polars"), caps.has_command("describegpt") @@ -129,7 +128,7 @@ client per call costs nothing extra after the first. `qsv-clientd` (installed with the package) is a per-user daemon that runs qsv for local processes, through `DaemonClient` / `AsyncDaemonClient` (the same `run()` as `Qsv`), and for -open **Data Schematics** from `qsv viz smart` (qsv 27.0.1 or later). Once you approve a +open **Data Schematics** from `qsv viz smart`. Once you approve a schematic with a pairing code, it can drill into the rows behind a chart, refresh its statistics, re-render itself, run read-only queries and fetch the latest data. Large results are paged from the daemon, so every row is reachable. @@ -179,7 +178,7 @@ See [docs/DAEMON.md](docs/DAEMON.md) for the security model and protocol. | `QsvInferenceError` | `inference` (an LLM call failed) | 1 | | `QsvWriteError` | `write` (e.g. disk full) | 1 | | `QsvTimeout` | `timeout` (killed by this client) | 124 | -| `QsvVersionError` | `version` (binary older than 25.0.0, or than `min_version`) | | +| `QsvVersionError` | `version` (binary older than 27.0.1, or than `min_version`) | | | `QsvError` | anything else; base class of all of the above | | `QsvDaemonError` (the daemon refused a request; `status` and `code` say why) and its subclass diff --git a/pyproject.toml b/pyproject.toml index d463dde..4d48e3a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "hatchling.build" [project] name = "qsv-client" version = "0.6.1" -description = "Run the qsv CSV toolkit (25.0.0+) from Python: timeouts that kill the whole process tree, typed errors, capability detection, and a local daemon (with an optional system tray) for live Data Schematics (qsv 27.0.1+)." +description = "Run the qsv CSV toolkit (27.0.1+) from Python: timeouts that kill the whole process tree, typed errors, capability detection, and a local daemon (with an optional system tray) for live Data Schematics." readme = "README.md" license = "AGPL-3.0-or-later" license-files = ["LICENSE"] diff --git a/src/qsv_client/__init__.py b/src/qsv_client/__init__.py index 7ab0aef..f82f6e0 100644 --- a/src/qsv_client/__init__.py +++ b/src/qsv_client/__init__.py @@ -1,7 +1,7 @@ """Run the qsv CSV toolkit from Python. Timeouts kill the whole process tree, failures raise typed exceptions, and capability -detection replaces parsing ``qsv --version``. Requires qsv 25.0.0 or later. +detection replaces parsing ``qsv --version``. Requires qsv 27.0.1 or later. See https://github.com/dathere/qsv-client. """ diff --git a/src/qsv_client/client.py b/src/qsv_client/client.py index 70c3e8f..6fc7780 100644 --- a/src/qsv_client/client.py +++ b/src/qsv_client/client.py @@ -34,7 +34,7 @@ DEFAULT_BINARIES = ("qsv", "qsvmcp", "qsvdp", "qsvlite") #: oldest qsv this client supports: the first with ``--capabilities`` and ``QSV_ERROR_FORMAT`` -MIN_QSV_VERSION = "25.0.0" +MIN_QSV_VERSION = "27.0.1" Arg = str | os.PathLike[str] | int | float @@ -148,7 +148,7 @@ def __init__( ``QSV_LLM_APIKEY`` / ``QSV_LLM_BASE_URL`` / ``QSV_LLM_MODEL`` environment variables, so the key never appears in the process table. min_version: raise :class:`QsvVersionError` on first use if the binary is older. - The binary must be at least :data:`MIN_QSV_VERSION` (25.0.0) regardless; + The binary must be at least :data:`MIN_QSV_VERSION` (27.0.1) regardless; this can only raise that floor. A string that is not a version (``"major.minor.patch"``) raises ``ValueError`` here. kill_grace: seconds to wait between the polite stop (SIGTERM, or diff --git a/src/qsv_client/daemon/config.py b/src/qsv_client/daemon/config.py index ad4b5d7..c720c01 100644 --- a/src/qsv_client/daemon/config.py +++ b/src/qsv_client/daemon/config.py @@ -10,40 +10,11 @@ from dataclasses import dataclass, field, fields from pathlib import Path -from ..capabilities import parse_version - DEFAULT_PORT = 14470 """Loopback port for browsers (Data Schematics). qsv pro's API uses 14462.""" API_VERSION = 1 -# 27.0.0 was withdrawn before release, but builds of qsv master report it and have these -# features, so the version checks use it; what users are told names 27.0.1 -LIVE_SCHEMATICS_QSV = "27.0.0" -"""The first qsv whose Data Schematics connect to qsv-clientd.""" - -LIVE_SCHEMATICS_RELEASE = "27.0.1" -"""The first released qsv whose Data Schematics connect to qsv-clientd.""" - -PRIVATE_GET_CACHE_QSV = "27.0.0" -"""The first qsv that keeps its `get` cache readable by its owner only (on Unix).""" - - -def schematics_notice(qsv_version: object) -> str | None: - """Why schematics won't go live with this qsv, or None when they will (or it can't tell).""" - if not isinstance(qsv_version, str): - return None - try: - older = parse_version(qsv_version) < parse_version(LIVE_SCHEMATICS_QSV) - except ValueError: - return None - if not older: - return None - return ( - f"qsv {qsv_version} writes Data Schematics that can't connect to qsv-clientd. " - f"Live schematics need qsv {LIVE_SCHEMATICS_RELEASE} or later." - ) - def _home_override() -> Path | None: # one directory for everything; used by tests and for running several daemons side by side diff --git a/src/qsv_client/daemon/fetch.py b/src/qsv_client/daemon/fetch.py index a690b09..997c021 100644 --- a/src/qsv_client/daemon/fetch.py +++ b/src/qsv_client/daemon/fetch.py @@ -43,9 +43,8 @@ from typing import TYPE_CHECKING, Any from .._process import _finish_despite_cancel -from ..capabilities import parse_version from ._http import HttpError -from .config import PRIVATE_GET_CACHE_QSV, ensure_private_dir +from .config import ensure_private_dir from .registry import Dataset if TYPE_CHECKING: @@ -133,20 +132,15 @@ async def download( argv = ["get", url, "--name", name] if scheme == "ckan": argv += ["--ckan-api", _ckan_api_for(target)] - # both runs must see the same cache, or cache-fetch can't find the entry - env = _get_cache_env(daemon, caps.version_tuple) # qsv writes --output with the umask's mode (often 0644), and staging_dir may be # one others can read, so it writes into a directory only we can enter private = Path(tempfile.mkdtemp(prefix=".qsv-clientd-", dir=staging_dir)) try: output = private / incoming.name try: - await daemon._browser_run(ds, argv, timeout=timeout, env=env) + await daemon._browser_run(ds, argv, timeout=timeout) await daemon._browser_run( - ds, - ["get", "cache-fetch", name, "--output", str(output)], - timeout=timeout, - env=env, + ds, ["get", "cache-fetch", name, "--output", str(output)], timeout=timeout ) except HttpError as exc: if exc.code == "qsv_timeout": @@ -188,16 +182,6 @@ async def download( return incoming, target.via -def _get_cache_env(daemon: Daemon, qsv_version: tuple[int, int, int]) -> dict[str, str] | None: - """Before 27.0.0, qsv's get cache follows the umask, and downloads may be private, so give - it one only we can read. A QSV_CACHE_DIR the user set, and qsv 27.0.0+, are left alone.""" - if qsv_version >= parse_version(PRIVATE_GET_CACHE_QSV): - return None - if daemon.config.inherit_env and "QSV_CACHE_DIR" in os.environ: - return None - return {"QSV_CACHE_DIR": str(ensure_private_dir(daemon.home / "qsv-cache"))} - - async def _fetch_locked(daemon: Daemon, ds: Dataset, source: str, force: bool) -> dict[str, Any]: cache = ensure_private_dir(daemon.home / "cache" / ds.id) what = "the source URL" if ds.source_url else "the PID" diff --git a/src/qsv_client/daemon/server.py b/src/qsv_client/daemon/server.py index 24839c3..b5e3ecf 100644 --- a/src/qsv_client/daemon/server.py +++ b/src/qsv_client/daemon/server.py @@ -53,7 +53,6 @@ ensure_private_dir, local_token_path, runtime_dir, - schematics_notice, socket_path_error, state_dir, write_private_file, @@ -132,9 +131,6 @@ def socket_path(self) -> Path: async def start(self) -> None: caps = await self._qsv.capabilities() log.info("qsv-clientd %s using %s %s", __version__, caps.binary, caps.version) - notice = schematics_notice(caps.version) - if notice: - log.warning("%s", notice) ensure_private_dir(self.home) # bind everything before publishing the token: a second instance that fails to bind # must not replace the running daemon's credentials diff --git a/src/qsv_client/errors.py b/src/qsv_client/errors.py index 4178929..655f362 100644 --- a/src/qsv_client/errors.py +++ b/src/qsv_client/errors.py @@ -160,7 +160,7 @@ class QsvNotFound(FileNotFoundError): class QsvVersionError(QsvError): - """The qsv binary is older than 25.0.0, or than the client's ``min_version``. + """The qsv binary is older than 27.0.1, or than the client's ``min_version``. Raised before the command runs. ``exit_code``, ``args_run`` and ``stderr`` describe the ``--capabilities`` check, not the command. diff --git a/src/qsv_client/tray/controller.py b/src/qsv_client/tray/controller.py index 6b83c49..bdf2c3d 100644 --- a/src/qsv_client/tray/controller.py +++ b/src/qsv_client/tray/controller.py @@ -26,7 +26,6 @@ config_path, config_template, log_path, - schematics_notice, ) from ..daemon.host import DaemonHost from ..daemon.server import Daemon @@ -81,7 +80,6 @@ def __init__( self.notify: Notifier = nothing """Shows a desktop notification, on the worker thread.""" self._announced: set[str] = set() - self._qsv_noted: object = None self._state = TrayState() self._lock = threading.Lock() self._emit_lock = threading.Lock() @@ -225,17 +223,6 @@ def _announce(self, pairings: tuple[Pending, ...]) -> None: ) self._announced = codes - def _note_qsv(self, status: Mapping[str, Any]) -> None: - """Say once per qsv version when its schematics can't go live.""" - qsv = status.get("qsv") - version = qsv.get("version") if isinstance(qsv, Mapping) else None - if version == self._qsv_noted: - return - self._qsv_noted = version - notice = schematics_notice(version) - if notice: - self.notify("Data Schematics won't go live", notice) - def _attached(self, client: DaemonClient) -> None: status = self._status(client) pairings = self._pairings(client, status) @@ -251,7 +238,6 @@ def _attached(self, client: DaemonClient) -> None: error=None, ) self._announce(pairings) - self._note_qsv(status) log.info("attached to qsv-clientd (pid %s)", status.get("pid")) def _start(self) -> None: @@ -274,7 +260,6 @@ def _start(self) -> None: mode=Mode.HOSTED, status=status, pairings=pairings, datasets=datasets, service=None ) self._announce(pairings) - self._note_qsv(status) log.info("hosting qsv-clientd") def _stop_host(self) -> None: diff --git a/tests/conftest.py b/tests/conftest.py index a1bac1a..4a08e95 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -49,7 +49,7 @@ def fake_qsv(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Callable[[str], """Write an executable stand-in for qsv running the given Python body; return its path. The client probes ``--capabilities`` before its first run, so unless ``body`` mentions - ``--capabilities`` (to answer it itself), the stand-in answers as qsv 25.0.0. + ``--capabilities`` (to answer it itself), the stand-in answers as qsv 27.0.1. POSIX: a script with a shebang. Windows: the script plus a ``fake-qsv.cmd`` wrapper that runs it (the extra ``cmd.exe`` is inside the run's Job Object, so it is killed with it). @@ -58,7 +58,7 @@ def fake_qsv(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Callable[[str], prelude = 'import sys; sys.stdout.reconfigure(newline="\\n")\n' capabilities = ( 'if sys.argv[1:] == ["--capabilities"]:\n' - ' print(\'{"binary": "qsv", "version": "25.0.0", "error_formats": ["text", "json"]}\')\n' + ' print(\'{"binary": "qsv", "version": "27.0.1", "error_formats": ["text", "json"]}\')\n' " sys.exit(0)\n" ) diff --git a/tests/test_client.py b/tests/test_client.py index bb69ff5..b59b66c 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -116,7 +116,7 @@ def test_find_qsv_windows_path_without_extension( sys.stderr.write("some progress output\\n") if os.environ.get("QSV_ERROR_FORMAT", "").strip().lower() == "json": err = {"kind": kind, "level": "error", "message": "it went wrong", "exit_code": code, - "command": "select", "qsv_version": "25.1.0"} + "command": "select", "qsv_version": "27.1.0"} sys.stderr.write(json.dumps({"error": err}) + "\\n") else: sys.stderr.write(kind + " error: it went wrong\\n") @@ -181,7 +181,7 @@ def test_json_error_with_check_false_returns_result(fake_qsv: Callable[[str], st if sys.argv[1] == "--capabilities": print(json.dumps({ "binary": "qsv", - "version": os.environ.get("FAKE_VERSION", "25.1.0"), + "version": os.environ.get("FAKE_VERSION", "27.1.0"), "features": ["geocode", "polars"], "feature_versions": {"polars": "0.55.1"}, "commands": ["count", "select", "stats"], @@ -194,7 +194,7 @@ def test_json_error_with_check_false_returns_result(fake_qsv: Callable[[str], st def _check_caps(caps: qsv_client.Capabilities) -> None: - assert (caps.binary, caps.version, caps.version_tuple) == ("qsv", "25.1.0", (25, 1, 0)) + assert (caps.binary, caps.version, caps.version_tuple) == ("qsv", "27.1.0", (27, 1, 0)) assert caps.has_feature("polars") and not caps.has_feature("luau") assert caps.feature_versions == {"polars": "0.55.1"} assert caps.has_command("stats") and not caps.has_command("describegpt") @@ -208,7 +208,7 @@ def test_capabilities_from_json_are_probed_once( calls = tmp_path / "calls.txt" qsv = Qsv(fake_qsv(CAPABILITIES), env={"FAKE_CALLS": str(calls)}) _check_caps(qsv.capabilities) - assert qsv.version == "25.1.0" + assert qsv.version == "27.1.0" assert qsv.capabilities is qsv.capabilities assert qsv.count("x.csv") == 3 assert calls.read_text().split() == ["--capabilities", "count"] @@ -220,7 +220,7 @@ async def test_async_capabilities_from_json_are_probed_once( calls = tmp_path / "calls.txt" qsv = AsyncQsv(fake_qsv(CAPABILITIES), env={"FAKE_CALLS": str(calls)}) _check_caps(await qsv.capabilities()) - assert await qsv.version() == "25.1.0" + assert await qsv.version() == "27.1.0" assert await qsv.capabilities() is await qsv.capabilities() assert await qsv.count("x.csv") == 3 assert calls.read_text().split() == ["--capabilities", "count"] @@ -229,9 +229,9 @@ async def test_async_capabilities_from_json_are_probed_once( def test_min_version_from_capabilities_json(fake_qsv: Callable[[str], str], tmp_path: Path) -> None: env = {"FAKE_CALLS": str(tmp_path / "calls.txt")} binary = fake_qsv(CAPABILITIES) - assert Qsv(binary, env=env, min_version="25.1.0").count("x.csv") == 3 - with pytest.raises(QsvVersionError, match=r"at least 25\.2\.0"): - Qsv(binary, env=env, min_version="25.2.0").count("x.csv") + assert Qsv(binary, env=env, min_version="27.1.0").count("x.csv") == 3 + with pytest.raises(QsvVersionError, match=r"at least 27\.2\.0"): + Qsv(binary, env=env, min_version="27.2.0").count("x.csv") @pytest.mark.parametrize("cls", [Qsv, AsyncQsv]) @@ -247,9 +247,9 @@ async def test_async_min_version_from_capabilities_json( ) -> None: env = {"FAKE_CALLS": str(tmp_path / "calls.txt")} binary = fake_qsv(CAPABILITIES) - assert await AsyncQsv(binary, env=env, min_version="25.1.0").count("x.csv") == 3 - with pytest.raises(QsvVersionError, match=r"at least 25\.2\.0"): - await AsyncQsv(binary, env=env, min_version="25.2.0").count("x.csv") + assert await AsyncQsv(binary, env=env, min_version="27.1.0").count("x.csv") == 3 + with pytest.raises(QsvVersionError, match=r"at least 27\.2\.0"): + await AsyncQsv(binary, env=env, min_version="27.2.0").count("x.csv") def test_capabilities_are_shared_across_clients( @@ -261,8 +261,8 @@ def test_capabilities_are_shared_across_clients( for _ in range(3): assert Qsv(binary, env=env).count("x.csv") == 3 # min_version is still checked per client against the shared result - with pytest.raises(QsvVersionError, match=r"at least 25\.2\.0"): - Qsv(binary, env=env, min_version="25.2.0").count("x.csv") + with pytest.raises(QsvVersionError, match=r"at least 27\.2\.0"): + Qsv(binary, env=env, min_version="27.2.0").count("x.csv") assert calls.read_text().split() == ["--capabilities", "count", "count", "count"] @@ -275,8 +275,8 @@ async def test_async_capabilities_are_shared_across_clients( assert Qsv(binary, env=env).count("x.csv") == 3 for _ in range(2): assert await AsyncQsv(binary, env=env).count("x.csv") == 3 - with pytest.raises(QsvVersionError, match=r"at least 25\.2\.0"): - await AsyncQsv(binary, env=env, min_version="25.2.0").count("x.csv") + with pytest.raises(QsvVersionError, match=r"at least 27\.2\.0"): + await AsyncQsv(binary, env=env, min_version="27.2.0").count("x.csv") assert calls.read_text().split() == ["--capabilities", "count", "count", "count"] @@ -310,13 +310,13 @@ async def test_async_cached_capabilities_are_private_to_each_client( def test_replaced_binary_is_probed_again(fake_qsv: Callable[[str], str], tmp_path: Path) -> None: calls = tmp_path / "calls.txt" binary = fake_qsv(CAPABILITIES) - assert Qsv(binary, env={"FAKE_CALLS": str(calls)}).version == "25.1.0" + assert Qsv(binary, env={"FAKE_CALLS": str(calls)}).version == "27.1.0" # an in-place upgrade: same path, new mtime (on Windows `binary` is an unchanged .cmd # wrapper, so set it explicitly rather than rely on the rewrite) fake_qsv(CAPABILITIES + "\n# upgraded\n") st = os.stat(binary) os.utime(binary, ns=(st.st_atime_ns, st.st_mtime_ns + 1_000_000_000)) - assert Qsv(binary, env={"FAKE_CALLS": str(calls)}).version == "25.1.0" + assert Qsv(binary, env={"FAKE_CALLS": str(calls)}).version == "27.1.0" assert calls.read_text().split() == ["--capabilities", "--capabilities"] @@ -325,7 +325,7 @@ def test_too_old_version_is_cached_and_rechecked( ) -> None: calls = tmp_path / "calls.txt" binary = fake_qsv(CAPABILITIES) - env = {"FAKE_CALLS": str(calls), "FAKE_VERSION": "24.9.0"} + env = {"FAKE_CALLS": str(calls), "FAKE_VERSION": "27.0.0"} for _ in range(2): with pytest.raises(QsvVersionError): Qsv(binary, env=env).count("x.csv") @@ -358,7 +358,7 @@ def test_failed_probe_is_not_cached(fake_qsv: Callable[[str], str], tmp_path: Pa open(os.environ["FAKE_CALLS"], "a").write(sys.argv[1] + "\\n") if sys.argv[1] == "--capabilities": time.sleep(0.5) - print('{"binary": "qsv", "version": "25.1.0"}') + print('{"binary": "qsv", "version": "27.1.0"}') else: print("3") """ @@ -518,16 +518,16 @@ async def contend() -> None: assert len(qsv_client.client._async_probe_locks) == 0 -# min_version can raise the 25.0.0 floor, never lower it +# min_version can raise the 27.0.1 floor, never lower it @pytest.mark.parametrize("min_version", [None, "1.0.0"]) def test_floor_is_enforced_before_first_run( fake_qsv: Callable[[str], str], tmp_path: Path, min_version: str | None ) -> None: calls = tmp_path / "calls.txt" - env = {"FAKE_CALLS": str(calls), "FAKE_VERSION": "24.9.0"} + env = {"FAKE_CALLS": str(calls), "FAKE_VERSION": "27.0.0"} qsv = Qsv(fake_qsv(CAPABILITIES), env=env, min_version=min_version) # `except QsvError` around run() also catches a too-old binary - with pytest.raises(QsvError, match=r"qsv 24\.9\.0; at least 25\.0\.0") as e: + with pytest.raises(QsvError, match=r"qsv 27\.0\.0; at least 27\.0\.1") as e: qsv.count("x.csv") assert type(e.value) is QsvVersionError assert (e.value.kind, e.value.exit_code) == ("version", 0) @@ -540,9 +540,9 @@ async def test_async_floor_is_enforced_before_first_run( fake_qsv: Callable[[str], str], tmp_path: Path, min_version: str | None ) -> None: calls = tmp_path / "calls.txt" - env = {"FAKE_CALLS": str(calls), "FAKE_VERSION": "24.9.0"} + env = {"FAKE_CALLS": str(calls), "FAKE_VERSION": "27.0.0"} qsv = AsyncQsv(fake_qsv(CAPABILITIES), env=env, min_version=min_version) - with pytest.raises(QsvVersionError, match=r"qsv 24\.9\.0; at least 25\.0\.0"): + with pytest.raises(QsvVersionError, match=r"qsv 27\.0\.0; at least 27\.0\.1"): await qsv.count("x.csv") assert calls.read_text().split() == ["--capabilities"] @@ -559,7 +559,7 @@ async def test_async_floor_is_enforced_before_first_run( def test_binary_without_capabilities_is_too_old(fake_qsv: Callable[[str], str]) -> None: qsv = Qsv(fake_qsv(PRE_CAPABILITIES)) - with pytest.raises(QsvVersionError, match=r"does not support --capabilities.*25\.0\.0") as e: + with pytest.raises(QsvVersionError, match=r"does not support --capabilities.*27\.0\.1") as e: qsv.count("x.csv") # a QsvError, describing the --capabilities check that rejected the binary assert isinstance(e.value, QsvError) @@ -574,7 +574,7 @@ async def test_async_binary_without_capabilities_is_too_old( fake_qsv: Callable[[str], str], ) -> None: qsv = AsyncQsv(fake_qsv(PRE_CAPABILITIES)) - with pytest.raises(QsvVersionError, match=r"does not support --capabilities.*25\.0\.0"): + with pytest.raises(QsvVersionError, match=r"does not support --capabilities.*27\.0\.1"): await qsv.count("x.csv") with pytest.raises(QsvVersionError): await qsv.capabilities() diff --git a/tests/test_daemon.py b/tests/test_daemon.py index 6deef83..624aee3 100644 --- a/tests/test_daemon.py +++ b/tests/test_daemon.py @@ -381,7 +381,7 @@ def test_registration_checks_schematic_fingerprint( B3_QSV = """ import hashlib if sys.argv[1:] == ["--capabilities"]: - print('{"binary": "qsv", "version": "25.0.0", "error_formats": ["text", "json"],' + print('{"binary": "qsv", "version": "27.0.1", "error_formats": ["text", "json"],' ' "commands": ["blake3", "count"]}') sys.exit(0) if sys.argv[1] == "blake3": diff --git a/tests/test_daemon_config_service.py b/tests/test_daemon_config_service.py index 3d831e8..631abe9 100644 --- a/tests/test_daemon_config_service.py +++ b/tests/test_daemon_config_service.py @@ -482,22 +482,3 @@ def test_service_environment_copies_only_daemon_locations( monkeypatch.setenv("QSV_CLIENTD_SOCKET", "") # empty means unset assert "QSV_CLIENTD_SOCKET" not in service.service_environment() assert os.environ["QSV_LLM_APIKEY"] == "secret" - - -@pytest.mark.parametrize( - ("version", "noted"), - [ - ("26.0.0", True), - ("25.1.0-rc1", True), - ("27.0.0", False), - ("27.0.0-dev", False), - ("28.1.0", False), - ("not a version", False), - (None, False), - ], -) -def test_schematics_notice_names_qsv_27(version: object, noted: bool) -> None: - notice = config.schematics_notice(version) - assert (notice is not None) is noted - if notice: - assert f"qsv {version} " in notice and "qsv 27.0.1 or later" in notice diff --git a/tests/test_daemon_fetch.py b/tests/test_daemon_fetch.py index cc87d18..4dbb9ab 100644 --- a/tests/test_daemon_fetch.py +++ b/tests/test_daemon_fetch.py @@ -99,7 +99,7 @@ def doi_org(web: _Routes, monkeypatch: pytest.MonkeyPatch) -> list[tuple[str, An import json import os if sys.argv[1:] == ["--capabilities"]: - print(json.dumps({"binary": "qsv", "version": "26.0.0", "error_formats": ["text", "json"], + print(json.dumps({"binary": "qsv", "version": "27.0.1", "error_formats": ["text", "json"], "commands": ["get", "count", "slice"]})) sys.exit(0) with open(LOG, "a") as fh: @@ -252,46 +252,6 @@ async def test_a_failed_qsv_get_leaves_no_private_dir( assert list(staging.iterdir()) == [] -@pytest.mark.parametrize( - ("version", "users_own", "private"), - [("26.0.0", False, True), ("27.0.0", False, False), ("26.0.0", True, False)], -) -async def test_qsv_get_before_27_gets_a_private_cache( - fake_qsv: Callable[[str], str], - home: Path, - tmp_path: Path, - monkeypatch: pytest.MonkeyPatch, - version: str, - users_own: bool, - private: bool, -) -> None: - # qsv before 27.0.0 makes its get cache with the umask's modes - log = tmp_path / "argv.log" - mine = tmp_path / "mine" - if users_own: - monkeypatch.setenv("QSV_CACHE_DIR", str(mine)) - else: - monkeypatch.delenv("QSV_CACHE_DIR", raising=False) - body = GET_QSV.replace('"26.0.0"', f'"{version}"').replace( - 'fh.write(json.dumps(sys.argv[1:]) + "\\n")', - 'fh.write(json.dumps([sys.argv[1:], os.environ.get("QSV_CACHE_DIR")]) + "\\n")', - ) - daemon = _daemon(fake_qsv(f"LOG = {str(log)!r}\n" + body), home) - await fetch.download( - daemon, "https://example.invalid/d.csv", tmp_path, name="qsv-clientd-x.csv" - ) - calls = [json.loads(line) for line in log.read_text().splitlines()] - cache_dirs = {cache_dir for argv, cache_dir in calls if argv[0] == "get"} - own_cache = daemon.home / "qsv-cache" - if private: - assert cache_dirs == {str(own_cache)} # get and cache-fetch must share one cache - if sys.platform != "win32": - assert own_cache.stat().st_mode & 0o777 == 0o700 - else: - assert cache_dirs == {str(mine) if users_own else None} - assert not own_cache.exists() - - @pytest.mark.parametrize("ctype", ["text/html", "text/html; charset=utf-8"]) async def test_download_refuses_a_web_page( fake_qsv: Callable[[str], str], home: Path, tmp_path: Path, web: _Routes, ctype: str diff --git a/tests/test_daemon_server_edges.py b/tests/test_daemon_server_edges.py index 9ac0304..b4c3199 100644 --- a/tests/test_daemon_server_edges.py +++ b/tests/test_daemon_server_edges.py @@ -23,6 +23,7 @@ import pytest from daemon_helpers import DaemonThread, Reply +from qsv_client import QsvVersionError from qsv_client.daemon import DaemonConfig, server from qsv_client.daemon._http import HttpError from qsv_client.daemon.pairing import MAX_REQUESTS_PER_MINUTE @@ -222,7 +223,7 @@ def test_local_status_listing_and_unknown_routes( assert status["service"] == "qsv-clientd" and status["api"] == 1 assert status["pid"] == os.getpid() assert status["binary"] == d.daemon.binary - assert status["qsv"]["version"] == "25.0.0" + assert status["qsv"]["version"] == "27.0.1" assert status["jobs"] == {"max": 3, "running": 0} assert status["datasets"] == 1 and status["pending_pairings"] == 0 assert status["port"] == d.port @@ -490,7 +491,7 @@ def test_failed_fingerprint_at_registration_is_a_qsv_error( ) -> None: body = """ if sys.argv[1:] == ["--capabilities"]: - print('{"binary": "qsv", "version": "25.0.0", "error_formats": ["text", "json"],' + print('{"binary": "qsv", "version": "27.0.1", "error_formats": ["text", "json"],' ' "commands": ["blake3"]}') sys.exit(0) sys.stderr.write('{"error": {"kind": "io", "message": "cannot read input", "exit_code": 1,' @@ -846,7 +847,7 @@ def publish(staged: Path, path: Path) -> None: GET_GENERIC = """ import json if sys.argv[1:] == ["--capabilities"]: - print(json.dumps({"binary": "qsv", "version": "26.0.0", "error_formats": ["text", "json"], + print(json.dumps({"binary": "qsv", "version": "27.0.1", "error_formats": ["text", "json"], "commands": ["get", "count", "viz", "slice"]})) sys.exit(0) with open(LOG, "a") as fh: @@ -1167,16 +1168,12 @@ def test_a_page_from_this_data_lends_its_source( assert listed[ds_id]["source_url"] == "https://h.example/d.csv" -@pytest.mark.parametrize(("version", "noted"), [("26.0.0", True), ("27.0.0", False)]) -def test_serve_warns_when_qsv_schematics_cannot_go_live( - fake_qsv: Callable[[str], str], - start_daemon: StartDaemon, - caplog: pytest.LogCaptureFixture, - version: str, - noted: bool, +def test_a_qsv_older_than_the_minimum_stops_the_daemon_before_it_binds( + fake_qsv: Callable[[str], str], home: Path ) -> None: - caps = json.dumps({"binary": "qsv", "version": version, "error_formats": ["text", "json"]}) + caps = json.dumps({"binary": "qsv", "version": "26.0.0", "error_formats": ["text", "json"]}) body = f'if sys.argv[1:] == ["--capabilities"]:\n print({caps!r})\n sys.exit(0)\n' - with caplog.at_level(logging.WARNING, logger="qsv_client.daemon"): - start_daemon(fake_qsv(body)) - assert any("can't connect" in r.getMessage() for r in caplog.records) is noted + daemon = Daemon(DaemonConfig(binary=fake_qsv(body)), home=home, tcp_port=0) + with pytest.raises(QsvVersionError, match=r"qsv 26\.0\.0; at least 27\.0\.1"): + asyncio.run(daemon.start()) + assert not daemon.socket_path.exists() diff --git a/tests/test_integration.py b/tests/test_integration.py index 9c29e44..86fc8d3 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -1,4 +1,4 @@ -"""Against a real qsv 25.0.0+ binary ($QSV_BIN or `qsv` on PATH).""" +"""Against a real qsv 27.0.1+ binary ($QSV_BIN or `qsv` on PATH).""" from __future__ import annotations diff --git a/tests/test_tray_controller.py b/tests/test_tray_controller.py index fbfc6da..558b117 100644 --- a/tests/test_tray_controller.py +++ b/tests/test_tray_controller.py @@ -52,7 +52,7 @@ def _qsv_reporting(version: str) -> str: @pytest.fixture def make_daemon(home: Path, fake_qsv: Callable[[str], str]) -> Callable[[], Daemon]: # the first qsv whose schematics go live: older ones add a notification - binary = fake_qsv(_qsv_reporting("27.0.0")) + binary = fake_qsv(_qsv_reporting("27.0.1")) return lambda: Daemon(DaemonConfig(binary=binary), home=home, tcp_port=0) @@ -110,7 +110,7 @@ def test_hosts_a_daemon_when_none_is_running(make_controller: MakeController, ho c.on_change = seen.append state = _do(c, model.START) assert state.mode is Mode.HOSTED and state.status is not None - assert state.status["qsv"]["version"] == "27.0.0" + assert state.status["qsv"]["version"] == "27.0.1" assert [s.mode for s in seen] == [Mode.STARTING, Mode.HOSTED] assert DaemonClient().available() assert (home / "run" / "local-token").exists() @@ -398,24 +398,17 @@ def __call__(self, title: str, message: str) -> None: self.append((title, message)) -def test_a_qsv_older_than_27_is_noted_once( +def test_a_qsv_older_than_the_minimum_is_an_error( make_controller: MakeController, home: Path, fake_qsv: Callable[[str], str] ) -> None: binary = fake_qsv(_qsv_reporting("26.0.0")) c = make_controller( make_daemon=lambda: Daemon(DaemonConfig(binary=binary), home=home, tcp_port=0) ) - notes = Notes() - c.notify = notes _do(c, model.START) - _do(c, model.RESTART) - assert notes == [ - ( - "Data Schematics won't go live", - "qsv 26.0.0 writes Data Schematics that can't connect to qsv-clientd. " - "Live schematics need qsv 27.0.1 or later.", - ) - ] + state = c.state + assert state.mode is Mode.ERROR + assert state.error is not None and "qsv 26.0.0; at least 27.0.1 is required" in state.error @pytest.fixture