redberry-cli 0.2.0__tar.gz → 0.3.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {redberry_cli-0.2.0/src/redberry_cli.egg-info → redberry_cli-0.3.0}/PKG-INFO +16 -2
- {redberry_cli-0.2.0 → redberry_cli-0.3.0}/README.md +15 -1
- redberry_cli-0.3.0/src/redberry_cli/_channel.py +6 -0
- redberry_cli-0.3.0/src/redberry_cli/_version.py +1 -0
- {redberry_cli-0.2.0 → redberry_cli-0.3.0}/src/redberry_cli/main.py +29 -4
- redberry_cli-0.3.0/src/redberry_cli/upgrade.py +184 -0
- {redberry_cli-0.2.0 → redberry_cli-0.3.0}/src/redberry_cli/vercel.py +15 -2
- {redberry_cli-0.2.0 → redberry_cli-0.3.0/src/redberry_cli.egg-info}/PKG-INFO +16 -2
- {redberry_cli-0.2.0 → redberry_cli-0.3.0}/src/redberry_cli.egg-info/SOURCES.txt +2 -0
- {redberry_cli-0.2.0 → redberry_cli-0.3.0}/tests/test_cli.py +20 -0
- redberry_cli-0.3.0/tests/test_cli_upgrade.py +190 -0
- {redberry_cli-0.2.0 → redberry_cli-0.3.0}/tests/test_cli_vercel.py +14 -0
- redberry_cli-0.2.0/src/redberry_cli/_channel.py +0 -5
- redberry_cli-0.2.0/src/redberry_cli/_version.py +0 -1
- {redberry_cli-0.2.0 → redberry_cli-0.3.0}/LICENSE +0 -0
- {redberry_cli-0.2.0 → redberry_cli-0.3.0}/NOTICE +0 -0
- {redberry_cli-0.2.0 → redberry_cli-0.3.0}/pyproject.toml +0 -0
- {redberry_cli-0.2.0 → redberry_cli-0.3.0}/setup.cfg +0 -0
- {redberry_cli-0.2.0 → redberry_cli-0.3.0}/src/redberry_cli/__init__.py +0 -0
- {redberry_cli-0.2.0 → redberry_cli-0.3.0}/src/redberry_cli/_cloud.py +0 -0
- {redberry_cli-0.2.0 → redberry_cli-0.3.0}/src/redberry_cli/_edits.py +0 -0
- {redberry_cli-0.2.0 → redberry_cli-0.3.0}/src/redberry_cli/_scan.py +0 -0
- {redberry_cli-0.2.0 → redberry_cli-0.3.0}/src/redberry_cli/_ts_tools.py +0 -0
- {redberry_cli-0.2.0 → redberry_cli-0.3.0}/src/redberry_cli/aws_lambda.py +0 -0
- {redberry_cli-0.2.0 → redberry_cli-0.3.0}/src/redberry_cli/azure_functions.py +0 -0
- {redberry_cli-0.2.0 → redberry_cli-0.3.0}/src/redberry_cli/instrument.py +0 -0
- {redberry_cli-0.2.0 → redberry_cli-0.3.0}/src/redberry_cli.egg-info/dependency_links.txt +0 -0
- {redberry_cli-0.2.0 → redberry_cli-0.3.0}/src/redberry_cli.egg-info/entry_points.txt +0 -0
- {redberry_cli-0.2.0 → redberry_cli-0.3.0}/src/redberry_cli.egg-info/requires.txt +0 -0
- {redberry_cli-0.2.0 → redberry_cli-0.3.0}/src/redberry_cli.egg-info/top_level.txt +0 -0
- {redberry_cli-0.2.0 → redberry_cli-0.3.0}/tests/test_cli_aws.py +0 -0
- {redberry_cli-0.2.0 → redberry_cli-0.3.0}/tests/test_cli_azure.py +0 -0
- {redberry_cli-0.2.0 → redberry_cli-0.3.0}/tests/test_cli_extract.py +0 -0
- {redberry_cli-0.2.0 → redberry_cli-0.3.0}/tests/test_scan.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: redberry-cli
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: The redberry command: sign in to Redberry and wire an agent's code to send its spans to your Redberry install.
|
|
5
5
|
Author: Redberry Labs
|
|
6
6
|
License-Expression: LicenseRef-PolyForm-Shield-1.0.0
|
|
@@ -51,8 +51,10 @@ or `pipx install redberry-cli`. Python 3.11 or later.
|
|
|
51
51
|
| `redberry connect --platform aws-lambda` | Wires a Node.js or Python Lambda function (below). |
|
|
52
52
|
| `redberry connect --platform azure-functions` | Wires a Node.js (v4) or Python (v2) Azure function app (below). |
|
|
53
53
|
| `redberry connect --platform vercel` | Wires a Next.js app on the Vercel AI SDK, and sets the project's `REDBERRY_*` variables (below). |
|
|
54
|
+
| `redberry upgrade` | Your company's Redberry installs and whether each runs the latest release; `redberry upgrade <id>` upgrades one (below). |
|
|
54
55
|
|
|
55
|
-
The API is `https://api.redberry.sbs`; `--api` or `REDBERRY_API_URL` selects another.
|
|
56
|
+
The API is `https://api.redberry.sbs`; `--api` or `REDBERRY_API_URL` selects another. Against any API other than
|
|
57
|
+
production, every command that calls it first says so on stderr (`Redberry dev (…)` or `Redberry custom (…)`). `--json` prints a
|
|
56
58
|
command's result for scripts.
|
|
57
59
|
|
|
58
60
|
## What `connect --platform` does
|
|
@@ -126,6 +128,18 @@ A `redberry-extract` on PATH is used as it is. Otherwise `connect` installs it:
|
|
|
126
128
|
overrides `~/.redberry`), from Redberry's package index with a short-lived download token that is passed to uv
|
|
127
129
|
in its environment only. Later runs reuse that install.
|
|
128
130
|
|
|
131
|
+
## `upgrade`: take Redberry's latest release
|
|
132
|
+
|
|
133
|
+
`redberry upgrade` lists your company's installs, the release each last reported, and whether a newer one is
|
|
134
|
+
out. `redberry upgrade <id>` upgrades one: it fetches the cloud's install script from the Redberry portal and runs
|
|
135
|
+
it on this machine with `--upgrade`, through the cloud's CLI as you are signed in to it (`gcloud`, `aws` or `az`;
|
|
136
|
+
on AWS, signed in to the install's account). The script keeps every choice the install was made with, asks
|
|
137
|
+
nothing and needs no install token, then reports the new release to Redberry. It is the same command the portal
|
|
138
|
+
shows, which you can also paste into the cloud's own shell.
|
|
139
|
+
|
|
140
|
+
It asks before it runs (`--yes` skips the question). An install that is already up to date is left alone unless
|
|
141
|
+
you pass `--force`. A stopped or revoked install is not upgraded: install it again from the portal.
|
|
142
|
+
|
|
129
143
|
## License
|
|
130
144
|
|
|
131
145
|
See [LICENSE](LICENSE) and [NOTICE](NOTICE).
|
|
@@ -24,8 +24,10 @@ or `pipx install redberry-cli`. Python 3.11 or later.
|
|
|
24
24
|
| `redberry connect --platform aws-lambda` | Wires a Node.js or Python Lambda function (below). |
|
|
25
25
|
| `redberry connect --platform azure-functions` | Wires a Node.js (v4) or Python (v2) Azure function app (below). |
|
|
26
26
|
| `redberry connect --platform vercel` | Wires a Next.js app on the Vercel AI SDK, and sets the project's `REDBERRY_*` variables (below). |
|
|
27
|
+
| `redberry upgrade` | Your company's Redberry installs and whether each runs the latest release; `redberry upgrade <id>` upgrades one (below). |
|
|
27
28
|
|
|
28
|
-
The API is `https://api.redberry.sbs`; `--api` or `REDBERRY_API_URL` selects another.
|
|
29
|
+
The API is `https://api.redberry.sbs`; `--api` or `REDBERRY_API_URL` selects another. Against any API other than
|
|
30
|
+
production, every command that calls it first says so on stderr (`Redberry dev (…)` or `Redberry custom (…)`). `--json` prints a
|
|
29
31
|
command's result for scripts.
|
|
30
32
|
|
|
31
33
|
## What `connect --platform` does
|
|
@@ -99,6 +101,18 @@ A `redberry-extract` on PATH is used as it is. Otherwise `connect` installs it:
|
|
|
99
101
|
overrides `~/.redberry`), from Redberry's package index with a short-lived download token that is passed to uv
|
|
100
102
|
in its environment only. Later runs reuse that install.
|
|
101
103
|
|
|
104
|
+
## `upgrade`: take Redberry's latest release
|
|
105
|
+
|
|
106
|
+
`redberry upgrade` lists your company's installs, the release each last reported, and whether a newer one is
|
|
107
|
+
out. `redberry upgrade <id>` upgrades one: it fetches the cloud's install script from the Redberry portal and runs
|
|
108
|
+
it on this machine with `--upgrade`, through the cloud's CLI as you are signed in to it (`gcloud`, `aws` or `az`;
|
|
109
|
+
on AWS, signed in to the install's account). The script keeps every choice the install was made with, asks
|
|
110
|
+
nothing and needs no install token, then reports the new release to Redberry. It is the same command the portal
|
|
111
|
+
shows, which you can also paste into the cloud's own shell.
|
|
112
|
+
|
|
113
|
+
It asks before it runs (`--yes` skips the question). An install that is already up to date is left alone unless
|
|
114
|
+
you pass `--force`. A stopped or revoked install is not upgraded: install it again from the portal.
|
|
115
|
+
|
|
102
116
|
## License
|
|
103
117
|
|
|
104
118
|
See [LICENSE](LICENSE) and [NOTICE](NOTICE).
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
"""Which Redberry API this build of the CLI talks to by default, and the known environments by address, so every
|
|
2
|
+
command says which one it uses. REDBERRY_API_URL and --api override the default."""
|
|
3
|
+
|
|
4
|
+
CHANNEL = "prod"
|
|
5
|
+
|
|
6
|
+
APIS = {"prod": "https://api.redberry.sbs", "dev": "https://api-dev.redberry.sbs"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.3.0"
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
"""``redberry login | whoami | logout | connect``: sign in, then wire an agent to the customer's Redberry
|
|
1
|
+
"""``redberry login | whoami | logout | connect | upgrade``: sign in, then wire an agent to the customer's Redberry
|
|
2
|
+
install.
|
|
2
3
|
|
|
3
4
|
**login** — a device-code sign-in, as ``gh auth login`` does it. The CLI prints a short code and a link;
|
|
4
5
|
someone signed in to the Redberry portal for your company opens it and approves the code (it need
|
|
@@ -25,8 +26,12 @@ Each shows the diff and asks before it changes a file (``--yes`` applies without
|
|
|
25
26
|
``--extract`` writes the agent's manifest (``.redberry/manifest.json``) with ``redberry-extract``: the one on
|
|
26
27
|
PATH, else one installed with uv into ``~/.redberry/extractor`` once the company's extractor licence is accepted.
|
|
27
28
|
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
**upgrade** — the company's installs and whether each runs Redberry's latest release; with an id, upgrades that
|
|
30
|
+
install by running its cloud's install script here with ``--upgrade`` (``redberry_cli.upgrade``).
|
|
31
|
+
|
|
32
|
+
The API is ``$REDBERRY_API_URL`` or ``--api`` (default ``https://api.redberry.sbs``). Off production, every command
|
|
33
|
+
that calls it first says so on stderr (``Redberry dev (…)`` or ``Redberry custom (…)``). Every prompt has a flag
|
|
34
|
+
(``--name``, ``--yes``), and ``--json`` prints the result for scripts and coding assistants.
|
|
30
35
|
"""
|
|
31
36
|
|
|
32
37
|
from __future__ import annotations
|
|
@@ -101,6 +106,12 @@ def session(api: str) -> dict[str, Any]:
|
|
|
101
106
|
return s
|
|
102
107
|
|
|
103
108
|
|
|
109
|
+
def environment(api: str) -> str:
|
|
110
|
+
"""``prod``, ``dev``, or ``custom`` for any other address."""
|
|
111
|
+
api = api.rstrip("/")
|
|
112
|
+
return next((name for name, url in _channel.APIS.items() if url == api), "custom")
|
|
113
|
+
|
|
114
|
+
|
|
104
115
|
def _detail(body: dict[str, Any]) -> str:
|
|
105
116
|
return str(body.get("detail") or body.get("error") or body)
|
|
106
117
|
|
|
@@ -116,7 +127,6 @@ def _cli_version() -> str:
|
|
|
116
127
|
def cmd_login(a, out=print, sleep=time.sleep) -> int:
|
|
117
128
|
api = a.api.rstrip("/")
|
|
118
129
|
machine = _machine_name()
|
|
119
|
-
out(f"Redberry: {api}")
|
|
120
130
|
status, start = call(api, "POST", "/api/cli/device/start", {"machine": machine} if machine else {})
|
|
121
131
|
if status == 404:
|
|
122
132
|
raise CliError(f"{api} doesn't support `redberry login`: check --api / REDBERRY_API_URL")
|
|
@@ -235,6 +245,12 @@ def cmd_connect(a, out=print, run=None) -> int:
|
|
|
235
245
|
return 0
|
|
236
246
|
|
|
237
247
|
|
|
248
|
+
def cmd_upgrade(a, out=print, run=None) -> int:
|
|
249
|
+
from redberry_cli import upgrade # the install script does the work, in the customer's cloud
|
|
250
|
+
|
|
251
|
+
return upgrade.cmd_upgrade(a, out=out, run=run)
|
|
252
|
+
|
|
253
|
+
|
|
238
254
|
_EXTRACT_BACKENDS = (("ANTHROPIC_API_KEY", "Anthropic", []),
|
|
239
255
|
("OPENAI_API_KEY", "OpenAI", ["--backend", "openai_compatible", "--base-url",
|
|
240
256
|
"https://api.openai.com/v1", "--model", "gpt-4.1-mini"]))
|
|
@@ -455,6 +471,12 @@ def parser() -> argparse.ArgumentParser:
|
|
|
455
471
|
vc.add_argument("--no-env", action="store_true",
|
|
456
472
|
help="print the REDBERRY_* variables instead of setting them with the Vercel CLI")
|
|
457
473
|
con.set_defaults(fn=cmd_connect)
|
|
474
|
+
up = sub.add_parser("upgrade", help="your installs' releases; with an id, upgrade that install to the latest")
|
|
475
|
+
up.add_argument("installation", nargs="?", help="the installation to upgrade (without it: list them)")
|
|
476
|
+
up.add_argument("--yes", action="store_true", help="upgrade without asking")
|
|
477
|
+
up.add_argument("--force", action="store_true", help="run the upgrade even when the install is up to date")
|
|
478
|
+
up.add_argument("--json", action="store_true", help="list the installations as JSON")
|
|
479
|
+
up.set_defaults(fn=cmd_upgrade)
|
|
458
480
|
return p
|
|
459
481
|
|
|
460
482
|
|
|
@@ -464,6 +486,9 @@ def main(argv: list[str] | None = None) -> int:
|
|
|
464
486
|
with contextlib.suppress(AttributeError, ValueError):
|
|
465
487
|
sys.stdout.reconfigure(line_buffering=True)
|
|
466
488
|
args = parser().parse_args(argv)
|
|
489
|
+
env = environment(args.api)
|
|
490
|
+
if env != "prod" and (args.cmd != "connect" or args.extract): # off production, say where, on stderr
|
|
491
|
+
print(f"Redberry {env} ({args.api.rstrip('/')})", file=sys.stderr)
|
|
467
492
|
try:
|
|
468
493
|
return args.fn(args)
|
|
469
494
|
except (CliError, _cloud.SetupError) as e:
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
"""``redberry upgrade``: the company's Redberry installs, whether each runs Redberry's latest release, and the
|
|
2
|
+
upgrade of one.
|
|
3
|
+
|
|
4
|
+
Without an id it lists the installs of the signed-in company: where each is, the release it last reported and
|
|
5
|
+
whether a newer one is out. With an id it upgrades that install: it fetches the cloud's install script from the
|
|
6
|
+
Redberry portal and runs it here with ``--upgrade``, through the cloud's CLI as it is signed in on this machine
|
|
7
|
+
(``gcloud``, ``aws`` or ``az``). The script keeps every choice the install was made with, asks nothing, needs no
|
|
8
|
+
install token, and reports the new release to Redberry. It is the same command the portal shows, which can also
|
|
9
|
+
be pasted into the cloud's own shell.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import json
|
|
15
|
+
import shutil
|
|
16
|
+
import subprocess
|
|
17
|
+
import sys
|
|
18
|
+
import tempfile
|
|
19
|
+
import time
|
|
20
|
+
import urllib.error
|
|
21
|
+
import urllib.parse
|
|
22
|
+
import urllib.request
|
|
23
|
+
from pathlib import Path
|
|
24
|
+
from typing import Any
|
|
25
|
+
|
|
26
|
+
from redberry_cli import _cloud
|
|
27
|
+
from redberry_cli.main import CliError, _detail, call, session
|
|
28
|
+
|
|
29
|
+
#: The cloud's CLI the install script runs, and where to get it.
|
|
30
|
+
CLOUD_CLIS = {
|
|
31
|
+
"gcp": ("gcloud", "https://cloud.google.com/sdk/docs/install, then `gcloud auth login`"),
|
|
32
|
+
"aws": ("aws", "https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html, then "
|
|
33
|
+
"`aws configure` or `aws sso login`"),
|
|
34
|
+
"azure": ("az", "https://learn.microsoft.com/cli/azure/install-azure-cli, then `az login`"),
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def installations(api: str, token: str) -> list[dict[str, Any]]:
|
|
39
|
+
status, body = call(api, "GET", "/api/cli/installations", token=token)
|
|
40
|
+
if status == 401:
|
|
41
|
+
raise CliError("your Redberry session has ended: run `redberry login`")
|
|
42
|
+
if status == 404:
|
|
43
|
+
raise CliError(f"{api} does not list installations yet: check --api / REDBERRY_API_URL")
|
|
44
|
+
if status != 200:
|
|
45
|
+
raise CliError(f"could not list your installations ({status}): {_detail(body)}")
|
|
46
|
+
return list(body.get("installations") or [])
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def where(i: dict[str, Any]) -> str:
|
|
50
|
+
if i.get("cloud") == "aws":
|
|
51
|
+
return f"account {i.get('account_id') or '?'}"
|
|
52
|
+
if i.get("cloud") == "azure":
|
|
53
|
+
return f"subscription {i.get('subscription_id') or '?'}"
|
|
54
|
+
return f"project {i.get('project_id') or '?'}"
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def state(i: dict[str, Any]) -> str:
|
|
58
|
+
if i.get("status") != "active":
|
|
59
|
+
return str(i.get("status") or "unknown")
|
|
60
|
+
if i.get("behind") is True:
|
|
61
|
+
return "update available"
|
|
62
|
+
if i.get("behind") is False:
|
|
63
|
+
return "up to date"
|
|
64
|
+
return "release not known" if not i.get("release") else "latest not known"
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _reported(i: dict[str, Any]) -> str:
|
|
68
|
+
release = i.get("release") or {}
|
|
69
|
+
if not release:
|
|
70
|
+
return "no release reported"
|
|
71
|
+
when = release.get("reported_at")
|
|
72
|
+
day = time.strftime("%Y-%m-%d", time.gmtime(when / 1000)) if isinstance(when, (int, float)) else None
|
|
73
|
+
return f"{release.get('tag') or '?'}" + (f", reported {day}" if day else "")
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def cmd_upgrade(a, out=print, run=None, fetch=None) -> int:
|
|
77
|
+
s = session(a.api)
|
|
78
|
+
rows = installations(a.api, s["token"])
|
|
79
|
+
if not a.installation:
|
|
80
|
+
return _list(a, rows, out)
|
|
81
|
+
found = [i for i in rows if i.get("id") == a.installation]
|
|
82
|
+
if not found:
|
|
83
|
+
known = ", ".join(i["id"] for i in rows if i.get("id")) or "none"
|
|
84
|
+
raise CliError(f"no installation {a.installation} for your company (yours: {known})")
|
|
85
|
+
i = found[0]
|
|
86
|
+
hint = i.get("upgrade")
|
|
87
|
+
if i.get("status") != "active" or not hint:
|
|
88
|
+
raise CliError(f"{i['id']} is {i.get('status') or 'not active'}: a stopped or revoked install is not "
|
|
89
|
+
"upgraded; install again with a new command from the Redberry portal")
|
|
90
|
+
if i.get("behind") is False and not a.force:
|
|
91
|
+
out(f"{i['id']} is up to date ({_reported(i)}); --force runs the upgrade anyway")
|
|
92
|
+
return 0
|
|
93
|
+
return _run_upgrade(a, i, hint, out, run or subprocess.run, fetch or _fetch)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def _list(a, rows: list[dict[str, Any]], out) -> int:
|
|
97
|
+
if a.json:
|
|
98
|
+
out(json.dumps({"installations": rows}, indent=2))
|
|
99
|
+
return 0
|
|
100
|
+
if not rows:
|
|
101
|
+
out("No Redberry installs for your company yet: the Redberry portal gives the install command.")
|
|
102
|
+
return 0
|
|
103
|
+
for i in rows:
|
|
104
|
+
out(f"{i.get('id')} {i.get('cloud')} {where(i)} {i.get('region') or '?'} "
|
|
105
|
+
f"{state(i)} ({_reported(i)})")
|
|
106
|
+
behind = [i for i in rows if i.get("behind") is True and i.get("upgrade")]
|
|
107
|
+
if behind:
|
|
108
|
+
out("")
|
|
109
|
+
out("Upgrade one with `redberry upgrade <id>`, here, signed in to its cloud; or run its command in the "
|
|
110
|
+
"cloud's shell:")
|
|
111
|
+
for i in behind:
|
|
112
|
+
out(f" {i['id']}: {i['upgrade']['command']}")
|
|
113
|
+
return 0
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def _run_upgrade(a, i: dict[str, Any], hint: dict[str, Any], out, run, fetch) -> int:
|
|
117
|
+
cloud = i.get("cloud")
|
|
118
|
+
if cloud not in CLOUD_CLIS:
|
|
119
|
+
raise CliError(f"{i['id']}: no upgrade for cloud {cloud!r} in this version of the CLI")
|
|
120
|
+
elsewhere = f"or run it in the cloud's shell: {hint['command']}"
|
|
121
|
+
bash = shutil.which("bash")
|
|
122
|
+
if not bash:
|
|
123
|
+
raise CliError(f"the upgrade runs a bash script and there is no bash here; {elsewhere}")
|
|
124
|
+
name, how = CLOUD_CLIS[cloud]
|
|
125
|
+
binary = {"aws": _cloud.aws_binary, "azure": _cloud.az_binary}.get(cloud, lambda: shutil.which("gcloud"))()
|
|
126
|
+
if not binary or not shutil.which(binary):
|
|
127
|
+
raise CliError(f"the upgrade runs the {name} CLI, which is not installed: {how}; {elsewhere}")
|
|
128
|
+
if cloud == "aws":
|
|
129
|
+
_check_aws_account(i, run, elsewhere)
|
|
130
|
+
args = [str(x) for x in hint.get("args") or []]
|
|
131
|
+
if "--upgrade" not in args:
|
|
132
|
+
args.append("--upgrade")
|
|
133
|
+
if i.get("behind") is None:
|
|
134
|
+
out(f"{i['id']}: its release is not known yet ({_reported(i)}); the upgrade takes the latest anyway")
|
|
135
|
+
if not a.yes:
|
|
136
|
+
if not sys.stdin.isatty():
|
|
137
|
+
raise CliError("the upgrade changes your cloud install: pass --yes to run it without a prompt")
|
|
138
|
+
answer = input(f"Upgrade {i['id']} ({cloud}, {where(i)}, {i.get('region')}) with {name} as signed in "
|
|
139
|
+
f"here, running Redberry's install script with {' '.join(args)}? [y/N] ")
|
|
140
|
+
if answer.strip().lower() not in ("y", "yes"):
|
|
141
|
+
out("Not upgraded")
|
|
142
|
+
return 1
|
|
143
|
+
script = fetch(hint["script_url"])
|
|
144
|
+
with tempfile.TemporaryDirectory(prefix="redberry-upgrade-") as tmp:
|
|
145
|
+
path = Path(tmp) / f"install-{cloud}.sh"
|
|
146
|
+
path.write_bytes(script)
|
|
147
|
+
out(f"Upgrading {i['id']} with {hint['script_url']} {' '.join(args)}")
|
|
148
|
+
try:
|
|
149
|
+
code = run([bash, str(path), *args]).returncode
|
|
150
|
+
except OSError as e:
|
|
151
|
+
raise CliError(f"could not run bash: {e}") from None
|
|
152
|
+
if code != 0:
|
|
153
|
+
raise CliError(f"the upgrade did not finish (exit {code}): the script's output above says why. Running it "
|
|
154
|
+
"again is safe")
|
|
155
|
+
out(f"Upgraded {i['id']}. `redberry upgrade` shows the release it reported.")
|
|
156
|
+
return 0
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def _check_aws_account(i: dict[str, Any], run, elsewhere: str) -> None:
|
|
160
|
+
"""The AWS script installs into the account the aws CLI is signed in to: it must be the install's."""
|
|
161
|
+
want = i.get("account_id")
|
|
162
|
+
r = _cloud.aws(run, ["aws", "sts", "get-caller-identity", "--query", "Account", "--output", "text"])
|
|
163
|
+
if r.returncode != 0:
|
|
164
|
+
raise CliError(f"the aws CLI is not signed in ({(r.stderr or '').strip()[-300:]}): `aws configure` or "
|
|
165
|
+
f"`aws sso login`; {elsewhere}")
|
|
166
|
+
have = (r.stdout or "").strip()
|
|
167
|
+
if want and have != want:
|
|
168
|
+
raise CliError(f"the aws CLI is signed in to account {have}, and {i['id']} is in account {want}: sign in "
|
|
169
|
+
f"to {want} (AWS_PROFILE), {elsewhere}")
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def _fetch(url: str) -> bytes:
|
|
173
|
+
"""The install script, over https (http only from this machine, for tests)."""
|
|
174
|
+
parts = urllib.parse.urlsplit(url)
|
|
175
|
+
if parts.scheme != "https" and not (parts.scheme == "http" and parts.hostname in ("127.0.0.1", "localhost")):
|
|
176
|
+
raise CliError(f"refusing to fetch the install script over {parts.scheme or 'no scheme'}: {url}")
|
|
177
|
+
try:
|
|
178
|
+
with urllib.request.urlopen(url, timeout=30) as r:
|
|
179
|
+
data = r.read()
|
|
180
|
+
except (urllib.error.URLError, TimeoutError, OSError) as e:
|
|
181
|
+
raise CliError(f"could not fetch the install script {url}: {e}") from None
|
|
182
|
+
if not data.startswith(b"#!"):
|
|
183
|
+
raise CliError(f"{url} is not a shell script")
|
|
184
|
+
return data
|
|
@@ -283,6 +283,15 @@ def _given(a, environ: dict[str, str]) -> dict[str, str]:
|
|
|
283
283
|
return given
|
|
284
284
|
|
|
285
285
|
|
|
286
|
+
def multi_route_note(agent: str, routes: list[Route]) -> str | None:
|
|
287
|
+
"""When more than one route calls a model: they are one agent (one name per app), so say so."""
|
|
288
|
+
if len(routes) < 2:
|
|
289
|
+
return None
|
|
290
|
+
return (f"This app has model calls in {len(routes)} routes ({', '.join(r.path for r in routes)}); they are "
|
|
291
|
+
f"recorded and priced as one agent, {agent}. To price agents separately, deploy them as separate "
|
|
292
|
+
"Vercel projects.")
|
|
293
|
+
|
|
294
|
+
|
|
286
295
|
def cmd_connect(a, out=print, run=None, ask=None, environ=None) -> int:
|
|
287
296
|
import os
|
|
288
297
|
import shutil
|
|
@@ -312,6 +321,9 @@ def cmd_connect(a, out=print, run=None, ask=None, environ=None) -> int:
|
|
|
312
321
|
"Vercel project: not linked here (.vercel/project.json; `vercel link` links it)")
|
|
313
322
|
say(f" agent {agent}: {', '.join(r.path for r in routes)}")
|
|
314
323
|
say(f" tools: {', '.join(t.name for t in tools) or 'none found by the static reader'}")
|
|
324
|
+
routes_note = multi_route_note(agent, routes)
|
|
325
|
+
if routes_note:
|
|
326
|
+
say(routes_note)
|
|
315
327
|
|
|
316
328
|
edits, edit_notes = plan_edits(repo, pkg, pkg_text, agent, routes)
|
|
317
329
|
notes += edit_notes
|
|
@@ -354,7 +366,8 @@ def cmd_connect(a, out=print, run=None, ask=None, environ=None) -> int:
|
|
|
354
366
|
result = {
|
|
355
367
|
"platform": PLATFORM, "vercel_project": description.get("vercel_project"), "agent_name": agent,
|
|
356
368
|
"routes": description["routes"], "edited": [str(e.path.relative_to(repo)) for e in edits],
|
|
357
|
-
"env": env, "env_set": env_set, "notes": notes, "
|
|
369
|
+
"env": env, "env_set": env_set, "notes": notes, "routes_note": routes_note,
|
|
370
|
+
"next": [install, "commit and deploy"],
|
|
358
371
|
}
|
|
359
372
|
if a.json:
|
|
360
373
|
out(json.dumps(result, indent=2))
|
|
@@ -381,4 +394,4 @@ def cmd_connect(a, out=print, run=None, ask=None, environ=None) -> int:
|
|
|
381
394
|
|
|
382
395
|
|
|
383
396
|
__all__ = ["DEPENDENCIES", "INSTRUMENTATION", "agent_routes", "check_app", "cmd_connect", "env_values",
|
|
384
|
-
"linked_project", "plan_edits", "read_env_file", "set_vercel_env"]
|
|
397
|
+
"linked_project", "multi_route_note", "plan_edits", "read_env_file", "set_vercel_env"]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: redberry-cli
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: The redberry command: sign in to Redberry and wire an agent's code to send its spans to your Redberry install.
|
|
5
5
|
Author: Redberry Labs
|
|
6
6
|
License-Expression: LicenseRef-PolyForm-Shield-1.0.0
|
|
@@ -51,8 +51,10 @@ or `pipx install redberry-cli`. Python 3.11 or later.
|
|
|
51
51
|
| `redberry connect --platform aws-lambda` | Wires a Node.js or Python Lambda function (below). |
|
|
52
52
|
| `redberry connect --platform azure-functions` | Wires a Node.js (v4) or Python (v2) Azure function app (below). |
|
|
53
53
|
| `redberry connect --platform vercel` | Wires a Next.js app on the Vercel AI SDK, and sets the project's `REDBERRY_*` variables (below). |
|
|
54
|
+
| `redberry upgrade` | Your company's Redberry installs and whether each runs the latest release; `redberry upgrade <id>` upgrades one (below). |
|
|
54
55
|
|
|
55
|
-
The API is `https://api.redberry.sbs`; `--api` or `REDBERRY_API_URL` selects another.
|
|
56
|
+
The API is `https://api.redberry.sbs`; `--api` or `REDBERRY_API_URL` selects another. Against any API other than
|
|
57
|
+
production, every command that calls it first says so on stderr (`Redberry dev (…)` or `Redberry custom (…)`). `--json` prints a
|
|
56
58
|
command's result for scripts.
|
|
57
59
|
|
|
58
60
|
## What `connect --platform` does
|
|
@@ -126,6 +128,18 @@ A `redberry-extract` on PATH is used as it is. Otherwise `connect` installs it:
|
|
|
126
128
|
overrides `~/.redberry`), from Redberry's package index with a short-lived download token that is passed to uv
|
|
127
129
|
in its environment only. Later runs reuse that install.
|
|
128
130
|
|
|
131
|
+
## `upgrade`: take Redberry's latest release
|
|
132
|
+
|
|
133
|
+
`redberry upgrade` lists your company's installs, the release each last reported, and whether a newer one is
|
|
134
|
+
out. `redberry upgrade <id>` upgrades one: it fetches the cloud's install script from the Redberry portal and runs
|
|
135
|
+
it on this machine with `--upgrade`, through the cloud's CLI as you are signed in to it (`gcloud`, `aws` or `az`;
|
|
136
|
+
on AWS, signed in to the install's account). The script keeps every choice the install was made with, asks
|
|
137
|
+
nothing and needs no install token, then reports the new release to Redberry. It is the same command the portal
|
|
138
|
+
shows, which you can also paste into the cloud's own shell.
|
|
139
|
+
|
|
140
|
+
It asks before it runs (`--yes` skips the question). An install that is already up to date is left alone unless
|
|
141
|
+
you pass `--force`. A stopped or revoked install is not upgraded: install it again from the portal.
|
|
142
|
+
|
|
129
143
|
## License
|
|
130
144
|
|
|
131
145
|
See [LICENSE](LICENSE) and [NOTICE](NOTICE).
|
|
@@ -13,6 +13,7 @@ src/redberry_cli/aws_lambda.py
|
|
|
13
13
|
src/redberry_cli/azure_functions.py
|
|
14
14
|
src/redberry_cli/instrument.py
|
|
15
15
|
src/redberry_cli/main.py
|
|
16
|
+
src/redberry_cli/upgrade.py
|
|
16
17
|
src/redberry_cli/vercel.py
|
|
17
18
|
src/redberry_cli.egg-info/PKG-INFO
|
|
18
19
|
src/redberry_cli.egg-info/SOURCES.txt
|
|
@@ -24,5 +25,6 @@ tests/test_cli.py
|
|
|
24
25
|
tests/test_cli_aws.py
|
|
25
26
|
tests/test_cli_azure.py
|
|
26
27
|
tests/test_cli_extract.py
|
|
28
|
+
tests/test_cli_upgrade.py
|
|
27
29
|
tests/test_cli_vercel.py
|
|
28
30
|
tests/test_scan.py
|
|
@@ -277,3 +277,23 @@ def test_instrument_follows_the_installed_anthropic_major(tmp_path, monkeypatch,
|
|
|
277
277
|
(tmp_path / "agent.py").write_text("import anthropic\nanthropic.Anthropic().messages.create(model='m', messages=[])\n")
|
|
278
278
|
instrument.set_temperature(tmp_path)
|
|
279
279
|
assert ('"temperature": 1.0' in (tmp_path / "agent.py").read_text()) is added
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
@pytest.mark.parametrize("api, label", [("https://api-dev.redberry.sbs/", "Redberry dev (https://api-dev.redberry.sbs)"),
|
|
283
|
+
("http://127.0.0.1:9", "Redberry custom (http://127.0.0.1:9)")])
|
|
284
|
+
def test_off_production_every_api_command_says_where_on_stderr(api, label, tmp_path, monkeypatch, capsys):
|
|
285
|
+
monkeypatch.setenv("XDG_CONFIG_HOME", str(tmp_path))
|
|
286
|
+
assert cli.main(["--api", api, "whoami"]) == 1 # not signed in: still says where it would have gone
|
|
287
|
+
err = capsys.readouterr().err
|
|
288
|
+
assert err.splitlines()[0] == label and "not signed in" in err
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
def test_production_adds_nothing(tmp_path, monkeypatch, capsys):
|
|
292
|
+
monkeypatch.setenv("XDG_CONFIG_HOME", str(tmp_path))
|
|
293
|
+
assert cli.main(["--api", "https://api.redberry.sbs", "whoami"]) == 1
|
|
294
|
+
assert capsys.readouterr().err == "redberry: not signed in: run `redberry login`\n"
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
def test_bare_connect_calls_no_api_and_names_none(capsys):
|
|
298
|
+
assert cli.main(["--api", "https://api-dev.redberry.sbs", "connect", "--json"]) == 0
|
|
299
|
+
assert "Redberry dev" not in capsys.readouterr().err
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"""`redberry upgrade`: the company's installs and their release, and the upgrade of one (its cloud's install script
|
|
2
|
+
run here with --upgrade), against a fake Redberry API over real HTTP and a fake subprocess.run."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import json
|
|
7
|
+
import threading
|
|
8
|
+
import time
|
|
9
|
+
from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
|
|
10
|
+
from types import SimpleNamespace
|
|
11
|
+
from typing import ClassVar
|
|
12
|
+
|
|
13
|
+
import pytest
|
|
14
|
+
|
|
15
|
+
from redberry_cli import main as cli
|
|
16
|
+
from redberry_cli import upgrade
|
|
17
|
+
|
|
18
|
+
SCRIPT = b"#!/usr/bin/env bash\necho upgrading\n"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class _Api(BaseHTTPRequestHandler):
|
|
22
|
+
state: ClassVar[dict] = {}
|
|
23
|
+
|
|
24
|
+
def log_message(self, *args): # quiet
|
|
25
|
+
pass
|
|
26
|
+
|
|
27
|
+
def _reply(self, status: int, body: bytes, kind: str = "application/json") -> None:
|
|
28
|
+
self.send_response(status)
|
|
29
|
+
self.send_header("Content-Type", kind)
|
|
30
|
+
self.send_header("Content-Length", str(len(body)))
|
|
31
|
+
self.end_headers()
|
|
32
|
+
self.wfile.write(body)
|
|
33
|
+
|
|
34
|
+
def do_GET(self):
|
|
35
|
+
if self.path.startswith("/install/"):
|
|
36
|
+
self.state["fetched"] = self.path
|
|
37
|
+
return self._reply(200, SCRIPT, "text/x-shellscript")
|
|
38
|
+
if self.path == "/api/cli/installations":
|
|
39
|
+
if self.headers.get("Authorization") != "Bearer rbcli_session":
|
|
40
|
+
return self._reply(401, b'{"detail": "Run `redberry login` first"}')
|
|
41
|
+
return self._reply(200, json.dumps({"installations": self.state["rows"]}).encode())
|
|
42
|
+
self._reply(404, b'{"detail": "Not Found"}')
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _row(api: str, id: str = "inst_gcp", cloud: str = "gcp", behind=True, status: str = "active", **kw) -> dict:
|
|
46
|
+
args = {"gcp": ["--project", "acme", "--region", "europe-west2", "--upgrade"],
|
|
47
|
+
"aws": ["--region", "eu-west-2", "--upgrade"],
|
|
48
|
+
"azure": ["--subscription", "s-1", "--region", "uksouth", "--upgrade"]}[cloud]
|
|
49
|
+
url = f"{api}/install/{cloud}.sh"
|
|
50
|
+
return {"id": id, "cloud": cloud, "project_id": "acme" if cloud == "gcp" else None,
|
|
51
|
+
"account_id": "123456789012" if cloud == "aws" else None,
|
|
52
|
+
"subscription_id": "s-1" if cloud == "azure" else None,
|
|
53
|
+
"region": args[args.index("--region") + 1], "status": status, "last_seen_at": 1,
|
|
54
|
+
"release": {"tag": "stable", "images": {"sink": "sha256:aa"}, "reported_at": 1_763_380_800_000},
|
|
55
|
+
"latest": {"tag": "stable", "images": {"sink": "sha256:bb"}}, "behind": behind,
|
|
56
|
+
"upgrade": None if status != "active" else
|
|
57
|
+
{"script_url": url, "args": args, "command": f"curl -fsSL {url} | bash -s -- {' '.join(args)}"}, **kw}
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
@pytest.fixture
|
|
61
|
+
def api(tmp_path, monkeypatch):
|
|
62
|
+
monkeypatch.setenv("XDG_CONFIG_HOME", str(tmp_path / "config"))
|
|
63
|
+
_Api.state = {"rows": []}
|
|
64
|
+
server = ThreadingHTTPServer(("127.0.0.1", 0), _Api)
|
|
65
|
+
threading.Thread(target=server.serve_forever, daemon=True).start()
|
|
66
|
+
url = f"http://127.0.0.1:{server.server_port}"
|
|
67
|
+
cli._save_credentials({url: {"token": "rbcli_session", "company": {"id": "co_acme", "name": "Acme Ltd"},
|
|
68
|
+
"expires_at": time.time() + 3600}})
|
|
69
|
+
# the cloud CLIs and bash are "installed"
|
|
70
|
+
monkeypatch.setattr(upgrade.shutil, "which", lambda name: f"/usr/bin/{name.rsplit('/', 1)[-1]}")
|
|
71
|
+
monkeypatch.setattr(upgrade._cloud, "aws_binary", lambda: "aws")
|
|
72
|
+
yield url
|
|
73
|
+
server.shutdown()
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
class _Run:
|
|
77
|
+
def __init__(self, code: int = 0, account: str = "123456789012"):
|
|
78
|
+
self.calls: list[list[str]] = []
|
|
79
|
+
self.code, self.account = code, account
|
|
80
|
+
self.script: bytes | None = None
|
|
81
|
+
|
|
82
|
+
def __call__(self, cmd, **kw):
|
|
83
|
+
self.calls.append(list(cmd))
|
|
84
|
+
if cmd[1:3] == ["sts", "get-caller-identity"]:
|
|
85
|
+
return SimpleNamespace(returncode=0, stdout=self.account + "\n", stderr="")
|
|
86
|
+
with open(cmd[1], "rb") as f: # the script, as fetched, in a temporary file
|
|
87
|
+
self.script = f.read()
|
|
88
|
+
return SimpleNamespace(returncode=self.code, stdout=None, stderr=None)
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def _main(api: str, *argv: str, run=None) -> int:
|
|
92
|
+
a = cli.parser().parse_args(["--api", api, "upgrade", *argv])
|
|
93
|
+
return cli.cmd_upgrade(a, run=run)
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def test_lists_the_installs_and_the_command_for_those_behind(api, capsys):
|
|
97
|
+
_Api.state["rows"] = [_row(api), _row(api, "inst_aws", "aws", behind=False),
|
|
98
|
+
_row(api, "inst_az", "azure", behind=None, release=None),
|
|
99
|
+
_row(api, "inst_old", status="stopped")]
|
|
100
|
+
assert _main(api) == 0
|
|
101
|
+
out = capsys.readouterr().out
|
|
102
|
+
assert "inst_gcp gcp project acme europe-west2 update available (stable, reported 2025-11-17)" in out
|
|
103
|
+
assert "inst_aws aws account 123456789012 eu-west-2 up to date" in out
|
|
104
|
+
assert "inst_az azure subscription s-1 uksouth release not known (no release reported)" in out
|
|
105
|
+
assert "inst_old gcp project acme europe-west2 stopped" in out
|
|
106
|
+
assert f"inst_gcp: curl -fsSL {api}/install/gcp.sh | bash -s -- --project acme --region europe-west2 --upgrade" in out
|
|
107
|
+
assert "inst_aws:" not in out and "inst_az:" not in out
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def test_json_lists_what_the_api_returned(api, capsys):
|
|
111
|
+
_Api.state["rows"] = [_row(api)]
|
|
112
|
+
assert _main(api, "--json") == 0
|
|
113
|
+
assert json.loads(capsys.readouterr().out) == {"installations": _Api.state["rows"]}
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def test_needs_a_session(api, capsys, monkeypatch):
|
|
117
|
+
cli._save_credentials({})
|
|
118
|
+
with pytest.raises(cli.CliError, match="redberry login"):
|
|
119
|
+
_main(api)
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def test_upgrades_one_by_running_its_script_with_upgrade(api, capsys):
|
|
123
|
+
_Api.state["rows"] = [_row(api)]
|
|
124
|
+
run = _Run()
|
|
125
|
+
assert _main(api, "inst_gcp", "--yes", run=run) == 0
|
|
126
|
+
assert _Api.state["fetched"] == "/install/gcp.sh"
|
|
127
|
+
(cmd,) = run.calls
|
|
128
|
+
assert cmd[0] == "/usr/bin/bash" and cmd[2:] == ["--project", "acme", "--region", "europe-west2", "--upgrade"]
|
|
129
|
+
assert run.script == SCRIPT
|
|
130
|
+
assert "Upgraded inst_gcp" in capsys.readouterr().out
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def test_an_install_that_is_up_to_date_is_left_alone_unless_forced(api, capsys):
|
|
134
|
+
_Api.state["rows"] = [_row(api, behind=False)]
|
|
135
|
+
run = _Run()
|
|
136
|
+
assert _main(api, "inst_gcp", "--yes", run=run) == 0
|
|
137
|
+
assert run.calls == [] and "up to date" in capsys.readouterr().out
|
|
138
|
+
assert _main(api, "inst_gcp", "--yes", "--force", run=run) == 0
|
|
139
|
+
assert len(run.calls) == 1
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def test_a_stopped_install_is_not_upgraded(api):
|
|
143
|
+
_Api.state["rows"] = [_row(api, status="stopped")]
|
|
144
|
+
with pytest.raises(cli.CliError, match="stopped or revoked"):
|
|
145
|
+
_main(api, "inst_gcp", "--yes", run=_Run())
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def test_an_unknown_id_names_the_companys_installs(api):
|
|
149
|
+
_Api.state["rows"] = [_row(api)]
|
|
150
|
+
with pytest.raises(cli.CliError, match="yours: inst_gcp"):
|
|
151
|
+
_main(api, "inst_nope", "--yes", run=_Run())
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def test_without_a_terminal_it_needs_yes(api, monkeypatch):
|
|
155
|
+
_Api.state["rows"] = [_row(api)]
|
|
156
|
+
monkeypatch.setattr("sys.stdin.isatty", lambda: False)
|
|
157
|
+
run = _Run()
|
|
158
|
+
with pytest.raises(cli.CliError, match="--yes"):
|
|
159
|
+
_main(api, "inst_gcp", run=run)
|
|
160
|
+
assert run.calls == []
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def test_aws_checks_the_signed_in_account_first(api):
|
|
164
|
+
_Api.state["rows"] = [_row(api, "inst_aws", "aws")]
|
|
165
|
+
run = _Run(account="999999999999")
|
|
166
|
+
with pytest.raises(cli.CliError, match="signed in to account 999999999999.*123456789012"):
|
|
167
|
+
_main(api, "inst_aws", "--yes", run=run)
|
|
168
|
+
assert len(run.calls) == 1 # sts only: the script never ran
|
|
169
|
+
run = _Run()
|
|
170
|
+
assert _main(api, "inst_aws", "--yes", run=run) == 0
|
|
171
|
+
assert run.calls[-1][2:] == ["--region", "eu-west-2", "--upgrade"]
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def test_a_missing_cloud_cli_gives_the_cloud_shell_command(api, monkeypatch):
|
|
175
|
+
_Api.state["rows"] = [_row(api, "inst_az", "azure")]
|
|
176
|
+
monkeypatch.setattr(upgrade._cloud, "az_binary", lambda: "az")
|
|
177
|
+
monkeypatch.setattr(upgrade.shutil, "which", lambda name: None if name == "az" else f"/usr/bin/{name}")
|
|
178
|
+
with pytest.raises(cli.CliError, match=r"az CLI, which is not installed.*bash -s -- --subscription s-1"):
|
|
179
|
+
_main(api, "inst_az", "--yes", run=_Run())
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def test_a_failed_script_is_reported(api):
|
|
183
|
+
_Api.state["rows"] = [_row(api)]
|
|
184
|
+
with pytest.raises(cli.CliError, match="exit 3"):
|
|
185
|
+
_main(api, "inst_gcp", "--yes", run=_Run(code=3))
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
def test_the_script_is_fetched_over_https_only():
|
|
189
|
+
with pytest.raises(cli.CliError, match="refusing"):
|
|
190
|
+
upgrade._fetch("http://claims.example/install/gcp.sh")
|
|
@@ -206,6 +206,20 @@ def test_connect_writes_the_app_and_sets_the_production_env(app, tmp_path):
|
|
|
206
206
|
assert rc == 0 and {p: p.read_text() for p in before} == before
|
|
207
207
|
|
|
208
208
|
|
|
209
|
+
def test_several_routes_are_one_agent_and_it_says_so(app):
|
|
210
|
+
note = ("This app has model calls in 2 routes (/api/chat, /api/refund); they are recorded and priced as one "
|
|
211
|
+
"agent, acme-support. To price agents separately, deploy them as separate Vercel projects.")
|
|
212
|
+
rc, out = _connect(app, "--yes", "--no-env", run=_Run())
|
|
213
|
+
assert rc == 0 and note in out
|
|
214
|
+
rc, out = _connect(app, "--yes", "--no-env", "--json", run=_Run())
|
|
215
|
+
assert rc == 0 and json.loads(out)["routes_note"] == note
|
|
216
|
+
shutil.rmtree(app / "app" / "api" / "refund") # one route: nothing to say
|
|
217
|
+
rc, out = _connect(app, "--yes", "--no-env", "--json", run=_Run())
|
|
218
|
+
assert rc == 0 and json.loads(out)["routes_note"] is None
|
|
219
|
+
rc, out = _connect(app, "--yes", "--no-env", run=_Run())
|
|
220
|
+
assert rc == 0 and "priced as one agent" not in out
|
|
221
|
+
|
|
222
|
+
|
|
209
223
|
def test_connect_asks_first_and_changes_nothing_when_not_told_yes(app, tmp_path):
|
|
210
224
|
before = {p: p.read_text() for p in app.rglob("*") if p.is_file()}
|
|
211
225
|
asked = []
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "0.2.0"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|