Raven-1/tests/test_release_plugin_list.py
zhanghui 010ca4b44d
fix(*): probe raven web before launch and install plugins from the release list (#588)
## Summary

The one-line installers are served from `main` and install the latest
published release, so an ending on `raven web` (PR #476) shipped against
v0.1.13, which has no `web`: since 2026-09-17 every `curl
raven.evermind.ai/install.sh | sh` has ended in `No such command 'web'`
with exit code 2. This PR fixes that class of failure and the upgrade
defect behind the next release.

- **Probe rule.** Every `raven <sub>` call in `install.sh` and
`install.ps1` is preceded by `raven <sub> --help`. When the probe fails
the install ends on the one command every release has (`raven`), and
neither the stop nor the page's own exit code becomes the script's.
`RAVEN_NO_LAUNCH=1` skips the launch (CI, Dockerfiles); the PATH hint
the launch displaced is back.
- **The release says what it ships.** `release.yml` writes
`raven-plugins.txt`, one `name @ url` line per plugin wheel it just
built, beside the wheel and the constraints. Both installers derive
every URL from the release page redirect and hand the list to `uv tool
install --with-requirements`. No GitHub API call, no grepping asset
names out of its JSON. A release without a list (0.1.13 and older)
installs raven alone, as it effectively did before.
- **Upgrade keeps the plugins.** uv replaces a tool's requirement set
with what one command names, so the old helper (`raven[channels]` only)
uninstalled every plugin the installer had put in. The helper now
installs from the same list, descends one loss at a time (engines, then
the memory plugin, then the channel extras), and refuses to run without
the list rather than install raven alone. `raven upgrade` on an
up-to-date install whose list names a plugin it lacks reinstalls the
version with its plugins. The helper also moves a beta wheel URL's
deploy token into the request header (urllib reads `user:token@host` as
a host name) and copies it onto the list's URLs for uv.
- **Gates.** CI installs the latest release with the PR's scripts,
piped, on ubuntu and windows whenever an installer changes. The release
job installs itself from `dist/` with `install.sh` before the draft is
created and asserts the three plugin packages and `web` on the result.
The beta publisher builds and lists the same three plugin wheels. A
contract test holds the release workflow, the beta publisher, both
installers (remote list and local clone mode) and the helper to one
plugin list.

Decisions, for the reviewer: the plugins are not published to PyPI and
no names are reserved there; the list carries direct URLs, so no plugin
is ever resolved by name against an index. The LibreOffice and chromium
steps in the scripts are unchanged. The three hosted-memory plugins
(mem0, zep, memos) are built and uploaded as before but stay off the
default list.

## Type

- [x] Fix
- [ ] Feature
- [ ] Docs
- [ ] CI / tooling
- [ ] Refactor
- [ ] Other

## Verification

All installs below ran piped (`cat install.sh | sh`) in isolated
directories (own HOME, UV_TOOL_DIR, UV_TOOL_BIN_DIR, UV_CACHE_DIR,
RAVEN_HOME) with `RAVEN_MINIMAL=1`.

- `main`'s `install.sh` against the live latest release (v0.1.13): exit
2, `No such command 'web'`. This branch's `install.sh`, same
environment: exit 0, `Raven installed. Open a new terminal ... then run:
raven`; `raven --version` prints 0.1.13. With `RAVEN_NO_LAUNCH=1`: exit
0.
- A local release directory built by `scripts/publish_beta.py` (`_build`
at 0.1.14b1: raven wheel, three plugin wheels, constraints, list): this
branch's `install.sh` with `RAVEN_WHEEL_URL=file://...` installs raven
0.1.14b1, `python -c "import raven_everos, raven_design, raven_ppt"`
succeeds in the tool venv, and the uv receipt lists raven plus the three
plugins.
- The release workflow's two new step bodies (`Write the plugin list`,
`Install the release from dist with install.sh`) extracted and run
locally against that build: exit 0; removing one plugin wheel makes the
list step exit 1.
- The script's ending against the 0.1.14b1 install: `raven web --help`
exit 0, `raven web --stop` exit 0 with nothing to stop, `raven web
--foreground --port 18999` answers `GET /` with HTTP 200 after about 20
seconds.
- `uv run raven upgrade` and `uv run raven upgrade --check` from the
checkout against live GitHub: `Raven 0.1.13 is up to date.`, exit 0.
- `uv run pytest tests/integration/test_cli_upgrade_real_uv.py`: 2
passed. The test now installs the old fixture `--with` a companion wheel
and asserts the companion survives the upgrade; against `main`'s helper
the same test fails on that assertion.
- `uv run pytest tests/test_install_script.py
tests/test_release_plugin_list.py tests/test_updates_upgrade.py
tests/test_publish_beta.py tests/test_cli_smoke.py`: all pass (37 + 6 +
188 on the last run of each).
- `uv run pytest` (full suite, before the last installer rewrite): 23543
passed, 121 skipped, 4 failed. The 4 (`test_agents_oncall_launcher`,
`test_agents_code_launcher`, `test_agent_loop_token_budget`,
`test_ppt_engine_image_search`) fail identically on plain `github/main`
in a separate worktree.
- `uv run ruff check` and `uv run ruff format --check` on every touched
Python file: clean. `sh -n install.sh`, `bash -n install.sh`: clean.
Both workflow files parse.
- Not run here: the new CI job's Windows leg and the release gate inside
GitHub Actions (this PR is their first run). `install.ps1` has no local
PowerShell to execute it; its changes mirror `install.sh` and are pinned
by the text tests.

- [x] Relevant tests pass locally
- [x] Relevant lint / type checks pass locally
- [ ] User-facing docs or screenshots are updated when needed

## Risk

User-visible changes: the installers no longer fail on a release without
`web`; they print the plugins they install and a warning when a release
carries none; `raven upgrade` refuses to proceed when the target
release's plugin list cannot be fetched (previously it would install
raven alone and drop the plugins), and repairs an up-to-date install
that lacks listed plugins. The beta channel's next publish carries the
three plugin wheels and the list; a beta upgrade to a build published
before this change will refuse for lack of a list, and rerunning the
beta installer is the remedy.

Rollback: revert the commit. Releases published with `raven-plugins.txt`
keep working with the old scripts, which ignore the file.

- [x] Security impact considered
- [x] Backward compatibility considered
- [x] Rollback path is clear for risky changes

## Related Issues

N/A

---------

Co-authored-by: Claude (claude-fable-5-1) <noreply@anthropic.com>
2026-09-21 16:25:33 +08:00

90 lines
4.2 KiB
Python

"""One statement of what a complete install carries beside raven.
release.yml writes raven-plugins.txt from the plugin wheels it just built,
publish_beta.py builds and lists the same distributions for the beta channel,
and the upgrade helper keeps the everos line when the engines cannot build.
Three files, one list: these pins hold them equal, so adding a plugin in one
place turns red in the other two instead of drifting -- the drift that once
left the helper knowing one distribution while the installer shipped four.
"""
from __future__ import annotations
import re
from pathlib import Path
from raven.updates import upgrade
from scripts.publish_beta import PLUGIN_DISTRIBUTIONS, PLUGIN_LIST_NAME
ROOT = Path(__file__).resolve().parents[1]
RELEASE_YML = (ROOT / ".github" / "workflows" / "release.yml").read_text(encoding="utf-8")
def _step(text: str, name: str) -> str:
start = text.index(f"- name: {name}")
end = text.index("- name: ", start + 1)
return text[start:end]
def test_the_release_workflow_lists_exactly_the_beta_publisher_distributions() -> None:
step = _step(RELEASE_YML, "Write the plugin list")
listed = re.findall(r"dist/([a-z_]+)-\*\.whl", step)
assert listed == [name.replace("-", "_") for name in PLUGIN_DISTRIBUTIONS]
assert f"-eq {len(PLUGIN_DISTRIBUTIONS)}" in step, "the line count guards a glob that matched nothing"
for name in PLUGIN_DISTRIBUTIONS:
assert f"uv build --wheel plugins-dist/{name} -o dist" in RELEASE_YML
def test_the_release_uploads_the_list_beside_the_wheel_and_the_constraints() -> None:
create = RELEASE_YML[RELEASE_YML.index('gh release create "$tag"') :].splitlines()[0]
assert "dist/raven-constraints.txt" in create
assert f"dist/{PLUGIN_LIST_NAME}" in create
assert upgrade.PLUGIN_LIST_NAME == PLUGIN_LIST_NAME
assert f"dist/{PLUGIN_LIST_NAME}" in _step(RELEASE_YML, "Write the plugin list")
def test_the_installers_keep_the_same_distribution_on_their_memory_rung() -> None:
"""install.sh, install.ps1 and the upgrade helper each filter the list by
the memory plugin's name for the rung that drops the engines; one rename
must turn all three red."""
sh = (ROOT / "install.sh").read_text(encoding="utf-8")
ps1 = (ROOT / "install.ps1").read_text(encoding="utf-8")
memory = next(name for name in PLUGIN_DISTRIBUTIONS if "memory" in name)
assert f"grep '^{memory} ' \"$plugins\"" in sh
assert f'-match "^{memory} "' in ps1
for script in (sh, ps1):
assert f"/{PLUGIN_LIST_NAME}" in script
def test_the_local_clone_mode_installs_the_same_three_distributions() -> None:
"""Run from a checkout, the installers install the workspace members
editable instead of reading a release list; the members they name must be
the ones a release ships, or a clone and a release would disagree about
what a complete install is."""
sh = (ROOT / "install.sh").read_text(encoding="utf-8")
ps1 = (ROOT / "install.ps1").read_text(encoding="utf-8")
for script in (sh, ps1):
named = set(re.findall(r"plugins-dist[/\\]([a-z-]+)", script))
assert named == set(PLUGIN_DISTRIBUTIONS), named
def test_the_release_installs_itself_before_it_is_published() -> None:
"""The one check that can say a release is whole: its own installer, piped
like a user runs it, against the wheels and list this job built, with the
plugin packages and `web` asserted on the result."""
step = _step(RELEASE_YML, "Install the release from dist with install.sh")
assert "sh -c 'cat install.sh | sh'" in step
assert 'RAVEN_NO_LAUNCH: "1"' in step
assert "import raven_everos, raven_design, raven_ppt" in step
assert "web --help" in step
assert RELEASE_YML.index("Install the release from dist") < RELEASE_YML.index("Create draft GitHub Release")
def test_the_helper_keeps_a_distribution_the_release_actually_ships() -> None:
"""The memory-only rung filters the list by one name; a rename on either
side would leave that rung installing nothing and reporting nothing."""
match = re.search(r'\.partition\(" @ "\)\[0\]\.strip\(\) == "([a-z-]+)"', upgrade._UPGRADE_HELPER_SOURCE)
assert match is not None
assert match.group(1) in PLUGIN_DISTRIBUTIONS
assert upgrade._UPGRADE_HELPER_SOURCE.count(f"/{PLUGIN_LIST_NAME}") == 1