brewsorted-cli 0.8.5__tar.gz → 0.8.6__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.
Files changed (37) hide show
  1. {brewsorted_cli-0.8.5 → brewsorted_cli-0.8.6}/INSTALL.md +1 -1
  2. {brewsorted_cli-0.8.5 → brewsorted_cli-0.8.6}/PKG-INFO +2 -2
  3. {brewsorted_cli-0.8.5 → brewsorted_cli-0.8.6}/brewsorted_cli.egg-info/PKG-INFO +2 -2
  4. {brewsorted_cli-0.8.5 → brewsorted_cli-0.8.6}/pyproject.toml +1 -1
  5. {brewsorted_cli-0.8.5 → brewsorted_cli-0.8.6}/skills/brewsorted/SKILL.md +4 -3
  6. {brewsorted_cli-0.8.5 → brewsorted_cli-0.8.6}/skills/brewsorted/references/cli.md +9 -3
  7. {brewsorted_cli-0.8.5 → brewsorted_cli-0.8.6}/src/brewsorted_cli/__init__.py +1 -1
  8. {brewsorted_cli-0.8.5 → brewsorted_cli-0.8.6}/src/brewsorted_cli/client.py +18 -2
  9. {brewsorted_cli-0.8.5 → brewsorted_cli-0.8.6}/src/brewsorted_cli/main.py +26 -1
  10. {brewsorted_cli-0.8.5 → brewsorted_cli-0.8.6}/tests/test_cli.py +116 -0
  11. {brewsorted_cli-0.8.5 → brewsorted_cli-0.8.6}/brewsorted_cli.egg-info/SOURCES.txt +0 -0
  12. {brewsorted_cli-0.8.5 → brewsorted_cli-0.8.6}/brewsorted_cli.egg-info/dependency_links.txt +0 -0
  13. {brewsorted_cli-0.8.5 → brewsorted_cli-0.8.6}/brewsorted_cli.egg-info/entry_points.txt +0 -0
  14. {brewsorted_cli-0.8.5 → brewsorted_cli-0.8.6}/brewsorted_cli.egg-info/requires.txt +0 -0
  15. {brewsorted_cli-0.8.5 → brewsorted_cli-0.8.6}/brewsorted_cli.egg-info/top_level.txt +0 -0
  16. {brewsorted_cli-0.8.5 → brewsorted_cli-0.8.6}/setup.cfg +0 -0
  17. {brewsorted_cli-0.8.5 → brewsorted_cli-0.8.6}/skills/brewsorted/__init__.py +0 -0
  18. {brewsorted_cli-0.8.5 → brewsorted_cli-0.8.6}/skills/brewsorted/agents/openai.yaml +0 -0
  19. {brewsorted_cli-0.8.5 → brewsorted_cli-0.8.6}/skills/brewsorted/tests/acceptance_scenarios.json +0 -0
  20. {brewsorted_cli-0.8.5 → brewsorted_cli-0.8.6}/skills/brewsorted/tests/test_skill.py +0 -0
  21. {brewsorted_cli-0.8.5 → brewsorted_cli-0.8.6}/src/brewsorted_cli/auth_state.py +0 -0
  22. {brewsorted_cli-0.8.5 → brewsorted_cli-0.8.6}/src/brewsorted_cli/http.py +0 -0
  23. {brewsorted_cli-0.8.5 → brewsorted_cli-0.8.6}/src/brewsorted_cli/oauth_discovery.py +0 -0
  24. {brewsorted_cli-0.8.5 → brewsorted_cli-0.8.6}/src/brewsorted_cli/oauth_login.py +0 -0
  25. {brewsorted_cli-0.8.5 → brewsorted_cli-0.8.6}/src/brewsorted_cli/product_feedback.py +0 -0
  26. {brewsorted_cli-0.8.5 → brewsorted_cli-0.8.6}/src/brewsorted_cli/skills.py +0 -0
  27. {brewsorted_cli-0.8.5 → brewsorted_cli-0.8.6}/src/brewsorted_cli/updates.py +0 -0
  28. {brewsorted_cli-0.8.5 → brewsorted_cli-0.8.6}/tests/test_anonymous_status.py +0 -0
  29. {brewsorted_cli-0.8.5 → brewsorted_cli-0.8.6}/tests/test_auth_state.py +0 -0
  30. {brewsorted_cli-0.8.5 → brewsorted_cli-0.8.6}/tests/test_oauth_discovery.py +0 -0
  31. {brewsorted_cli-0.8.5 → brewsorted_cli-0.8.6}/tests/test_oauth_login.py +0 -0
  32. {brewsorted_cli-0.8.5 → brewsorted_cli-0.8.6}/tests/test_product_feedback.py +0 -0
  33. {brewsorted_cli-0.8.5 → brewsorted_cli-0.8.6}/tests/test_protocol.py +0 -0
  34. {brewsorted_cli-0.8.5 → brewsorted_cli-0.8.6}/tests/test_proxy.py +0 -0
  35. {brewsorted_cli-0.8.5 → brewsorted_cli-0.8.6}/tests/test_ratio_workflow.py +0 -0
  36. {brewsorted_cli-0.8.5 → brewsorted_cli-0.8.6}/tests/test_skills.py +0 -0
  37. {brewsorted_cli-0.8.5 → brewsorted_cli-0.8.6}/tests/test_updates.py +0 -0
@@ -29,7 +29,7 @@ Install uv or pipx first if necessary; Python and ordinary package dependencies
29
29
  are required. No private repository access is needed.
30
30
 
31
31
  ```bash
32
- client_version=0.8.5
32
+ client_version=0.8.6
33
33
  uv tool install --python python3.12 "brewsorted-cli==$client_version"
34
34
  # Alternative: pipx install --python python3.12 "brewsorted-cli==$client_version"
35
35
  brewsorted skills install --destination "$HOME/.codex/skills/brewsorted"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: brewsorted-cli
3
- Version: 0.8.5
3
+ Version: 0.8.6
4
4
  Summary: Portable HTTP client for the BrewSorted API
5
5
  Project-URL: Homepage, https://brewsorted.com
6
6
  Project-URL: Documentation, https://brewsorted.com/downloads.html
@@ -42,7 +42,7 @@ Install uv or pipx first if necessary; Python and ordinary package dependencies
42
42
  are required. No private repository access is needed.
43
43
 
44
44
  ```bash
45
- client_version=0.8.5
45
+ client_version=0.8.6
46
46
  uv tool install --python python3.12 "brewsorted-cli==$client_version"
47
47
  # Alternative: pipx install --python python3.12 "brewsorted-cli==$client_version"
48
48
  brewsorted skills install --destination "$HOME/.codex/skills/brewsorted"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: brewsorted-cli
3
- Version: 0.8.5
3
+ Version: 0.8.6
4
4
  Summary: Portable HTTP client for the BrewSorted API
5
5
  Project-URL: Homepage, https://brewsorted.com
6
6
  Project-URL: Documentation, https://brewsorted.com/downloads.html
@@ -42,7 +42,7 @@ Install uv or pipx first if necessary; Python and ordinary package dependencies
42
42
  are required. No private repository access is needed.
43
43
 
44
44
  ```bash
45
- client_version=0.8.5
45
+ client_version=0.8.6
46
46
  uv tool install --python python3.12 "brewsorted-cli==$client_version"
47
47
  # Alternative: pipx install --python python3.12 "brewsorted-cli==$client_version"
48
48
  brewsorted skills install --destination "$HOME/.codex/skills/brewsorted"
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "brewsorted-cli"
7
- version = "0.8.5"
7
+ version = "0.8.6"
8
8
  description = "Portable HTTP client for the BrewSorted API"
9
9
  readme = "INSTALL.md"
10
10
  requires-python = ">=3.11"
@@ -101,9 +101,10 @@ echoing or probing a foreign identity.
101
101
  confirms them. For an image the user supplies or confirms for a Roastery,
102
102
  Coffee, Equipment item, Water profile, Drink type, or Brew method, convert it to
103
103
  JPEG, PNG, or WebP when needed, run `brewsorted images upload PATH`, then
104
- attach the returned `id` with the record's `--image-id`. For metadata or
105
- deletion, use the returned `user/id` image handle. Never invent or
106
- search for an image.
104
+ attach the returned `id` with the record's `--image-id`. For metadata,
105
+ download, or deletion, use the returned `user/id` image handle. Use
106
+ `brewsorted images download USERNAME/UUID PATH` to inspect a stored Coffee bag
107
+ photo for label details. Never invent or search for an image.
107
108
  4. Run the smallest command that satisfies the request once and use its JSON
108
109
  result. For coffee records, after a successful non-delete mutation, read the exact returned ID
109
110
  with the documented `get` operation, or the documented retrieval command when
@@ -297,9 +297,15 @@ in an update. Brew methods support create, list, get, update, and delete; create
297
297
  requires a unique nonblank name, while description and image are optional.
298
298
  Resolve a requested method with `brew-methods list --q` and use its ID. Equipment
299
299
  never selects a method, and a custom method does not imply Suggestion support.
300
- `images get USERNAME/UUID`
301
- inspects metadata and `images delete USERNAME/UUID` soft-deletes an image only when none
302
- of those catalog records references it.
300
+ `images get USERNAME/UUID` inspects metadata. `images delete USERNAME/UUID`
301
+ soft-deletes an image when no catalog record references it.
302
+
303
+ To inspect a stored Coffee bag photo, combine the Coffee's Username and
304
+ `image_id` as `USERNAME/UUID`, then run
305
+ `brewsorted images download USERNAME/UUID /path/to/bag.webp`. Open the path in
306
+ the JSON `path` field. The file contains the retained display WebP. Choose an
307
+ unused path in an existing directory to preserve existing files, since a
308
+ successful download replaces a file at that path.
303
309
 
304
310
  Equipment types are fixed: `brewer`, `grinder`, `kettle`, `scale`, `server`,
305
311
  `filter`, and `other`. Names are not unique. When a lookup has multiple plausible
@@ -1,5 +1,5 @@
1
1
  """HTTP-only BrewSorted command-line client."""
2
2
 
3
- __version__ = "0.8.5"
3
+ __version__ = "0.8.6"
4
4
 
5
5
  USER_AGENT = f"BrewSorted-CLI/{__version__}"
@@ -15,7 +15,7 @@ from .http import http_client
15
15
  ResponseKind = Literal[
16
16
  "item", "image", "list", "system_list", "health", "comparison", "context", "preview",
17
17
  "strategy_list", "suggestion", "suggestion_list", "attempt", "feedback",
18
- "feedback_list", "capabilities",
18
+ "feedback_list", "capabilities", "webp",
19
19
  ]
20
20
 
21
21
  QUALIFIED_ID = re.compile(r"^[a-z0-9][a-z0-9-]{1,30}[a-z0-9]/[1-9][0-9]*$")
@@ -460,9 +460,25 @@ class ApiClient:
460
460
  raise InvalidServerResponse(status, "expected an empty body for HTTP 204")
461
461
  return None
462
462
  media_type = response.headers.get("content-type", "").split(";", 1)[0].strip().lower()
463
- expected_media_type = "application/problem+json" if response.is_error else "application/json"
463
+ if response.is_error:
464
+ expected_media_type = "application/problem+json"
465
+ elif response_kind == "webp":
466
+ expected_media_type = "image/webp"
467
+ else:
468
+ expected_media_type = "application/json"
464
469
  if media_type != expected_media_type:
465
470
  raise InvalidServerResponse(status, f"expected Content-Type {expected_media_type}")
471
+ if expected_media_type == "image/webp":
472
+ content = response.content
473
+ # The RIFF size describes all bytes after the first eight.
474
+ if (
475
+ len(content) < 20
476
+ or content[:4] != b"RIFF"
477
+ or content[8:12] != b"WEBP"
478
+ or int.from_bytes(content[4:8], "little") != len(content) - 8
479
+ ):
480
+ raise InvalidServerResponse(status, "expected a complete WebP response body")
481
+ return content
466
482
  try:
467
483
  payload = response.json(parse_constant=_reject_json_constant)
468
484
  except ValueError as exc:
@@ -7,6 +7,7 @@ import os
7
7
  import re
8
8
  import sys
9
9
  from pathlib import Path
10
+ from tempfile import NamedTemporaryFile
10
11
  from typing import Any, Callable
11
12
  from urllib.parse import urlsplit, urlunsplit
12
13
  from uuid import UUID
@@ -83,6 +84,20 @@ def _image_handle(value: str) -> str:
83
84
  return value
84
85
 
85
86
 
87
+ def _save_image(path: str, content: bytes) -> dict[str, str]:
88
+ temporary_path = None
89
+ try:
90
+ # Keep the temporary file on the destination filesystem for atomic replacement.
91
+ with NamedTemporaryFile(dir=Path(path).parent, prefix=".brewsorted-", delete=False) as output:
92
+ temporary_path = Path(output.name)
93
+ output.write(content)
94
+ os.replace(temporary_path, path)
95
+ finally:
96
+ if temporary_path is not None:
97
+ temporary_path.unlink(missing_ok=True)
98
+ return {"path": path}
99
+
100
+
86
101
  def _web_origin(value: str | None) -> str | None:
87
102
  if value is None:
88
103
  return None
@@ -355,6 +370,9 @@ def build_parser() -> argparse.ArgumentParser:
355
370
  upload.add_argument("path")
356
371
  image_get = image_operations.add_parser("get")
357
372
  image_get.add_argument("id", type=_image_handle)
373
+ download = image_operations.add_parser("download", help="save the retained display WebP")
374
+ download.add_argument("id", type=_image_handle, metavar="USERNAME/UUID")
375
+ download.add_argument("path", metavar="PATH", help="local destination, replaced on success")
358
376
  image_delete = image_operations.add_parser("delete")
359
377
  image_delete.add_argument("id", type=_image_handle)
360
378
 
@@ -597,6 +615,9 @@ def _dispatch(args: argparse.Namespace, client: ApiClient) -> Any:
597
615
  return client.request(
598
616
  "GET", f"/v1/images/{args.id}", response_kind="image"
599
617
  )
618
+ if operation == "download":
619
+ content = client.request("GET", f"/v1/images/{args.id}/display", response_kind="webp")
620
+ return _save_image(args.path, content)
600
621
  return client.request("DELETE", f"/v1/images/{args.id}")
601
622
  if resource == "bag-adjustments":
602
623
  if operation in {"create", "list"}:
@@ -715,7 +736,11 @@ def _dispatch(args: argparse.Namespace, client: ApiClient) -> Any:
715
736
 
716
737
 
717
738
  def _write(value: Any, *, stream=None) -> None:
718
- print(json.dumps(value, indent=2, ensure_ascii=False), file=stream or sys.stdout)
739
+ stream = stream or sys.stdout
740
+ try:
741
+ print(json.dumps(value, indent=2, ensure_ascii=False), file=stream)
742
+ except UnicodeEncodeError:
743
+ print(json.dumps(value, indent=2), file=stream)
719
744
 
720
745
 
721
746
  def main(argv: list[str] | None = None, *, client: ApiClient | None = None) -> int:
@@ -1,7 +1,9 @@
1
1
  import json
2
+ from io import BytesIO, TextIOWrapper
2
3
  from pathlib import Path
3
4
 
4
5
  import httpx
6
+ import pytest
5
7
 
6
8
  from brewsorted_cli import __version__
7
9
  from brewsorted_cli.client import ApiClient
@@ -133,6 +135,120 @@ def test_image_upload_get_and_delete_use_multipart_and_uuid_responses(tmp_path,
133
135
  ]
134
136
 
135
137
 
138
+ IMAGE_HANDLE = "test-user/d9428888-122b-41e1-b85c-61cd3cbb3210"
139
+ # A lossless, 1×1 WebP.
140
+ DISPLAY_WEBP = (
141
+ b"RIFF\x1e\x00\x00\x00WEBPVP8L\x11\x00\x00\x00/\x00\x00\x00\x00"
142
+ b"\x07\xd0\xa0\n\x97\xa1\xff\x81\x88\xe8\x7f\x00\x00"
143
+ )
144
+
145
+
146
+ @pytest.mark.parametrize("existing", [False, True])
147
+ def test_image_download_saves_display_webp_and_reports_destination(tmp_path, capsys, existing):
148
+ destination = tmp_path / "coffee bag.webp"
149
+ if existing:
150
+ destination.write_bytes(b"previous file")
151
+
152
+ def handler(request):
153
+ assert request.method == "GET"
154
+ assert str(request.url) == f"https://coffee.example/api/v1/images/{IMAGE_HANDLE}/display"
155
+ assert request.headers["authorization"] == "Bearer header.payload.signature"
156
+ return httpx.Response(200, content=DISPLAY_WEBP, headers={"Content-Type": "image/webp"})
157
+
158
+ assert main(["images", "download", IMAGE_HANDLE, str(destination)], client=mock_client(handler)) == 0
159
+ output = capsys.readouterr()
160
+ assert json.loads(output.out) == {"path": str(destination)}
161
+ assert output.err == ""
162
+ assert destination.read_bytes() == DISPLAY_WEBP
163
+ assert list(tmp_path.iterdir()) == [destination]
164
+
165
+
166
+ def test_image_download_reports_unicode_path_on_ascii_stdout(tmp_path, monkeypatch):
167
+ destination = tmp_path / "café.webp"
168
+
169
+ def handler(request):
170
+ return httpx.Response(200, content=DISPLAY_WEBP, headers={"Content-Type": "image/webp"})
171
+
172
+ with TextIOWrapper(BytesIO(), encoding="ascii") as stdout, monkeypatch.context() as patch:
173
+ patch.setattr("sys.stdout", stdout)
174
+ assert main([
175
+ "images", "download", IMAGE_HANDLE, str(destination),
176
+ ], client=mock_client(handler)) == 0
177
+ stdout.seek(0)
178
+ assert json.load(stdout) == {"path": str(destination)}
179
+ assert destination.read_bytes() == DISPLAY_WEBP
180
+
181
+
182
+ @pytest.mark.parametrize(("status", "code"), [(403, "capability_denied"), (404, "not_found")])
183
+ def test_image_download_preserves_json_api_errors(tmp_path, capsys, status, code):
184
+ destination = tmp_path / "bag.webp"
185
+
186
+ def handler(request):
187
+ return httpx.Response(status, json={
188
+ "type": "about:blank", "title": "Denied", "detail": "Private image details",
189
+ "status": status, "code": code,
190
+ }, headers={"Content-Type": "application/problem+json"})
191
+
192
+ assert main(["images", "download", IMAGE_HANDLE, str(destination)], client=mock_client(handler)) == 4
193
+ output = capsys.readouterr()
194
+ assert output.out == ""
195
+ problem = json.loads(output.err)
196
+ assert (problem["status"], problem["code"]) == (status, code)
197
+ assert "Private image details" not in output.err
198
+ assert list(tmp_path.iterdir()) == []
199
+
200
+
201
+ def test_image_download_cleans_up_when_destination_cannot_be_replaced(tmp_path, capsys):
202
+ destination = tmp_path / "bag.webp"
203
+ destination.mkdir()
204
+
205
+ def handler(request):
206
+ return httpx.Response(200, content=DISPLAY_WEBP, headers={"Content-Type": "image/webp"})
207
+
208
+ assert main(["images", "download", IMAGE_HANDLE, str(destination)], client=mock_client(handler)) == 2
209
+ output = capsys.readouterr()
210
+ assert output.out == ""
211
+ assert json.loads(output.err)["code"] == "cli_input_error"
212
+ assert destination.is_dir()
213
+ assert list(tmp_path.iterdir()) == [destination]
214
+
215
+
216
+ @pytest.mark.parametrize(("media_type", "content"), [
217
+ ("application/json", b'{}'),
218
+ ("image/webp", DISPLAY_WEBP[:-1]),
219
+ ])
220
+ def test_image_download_rejects_invalid_rendition(tmp_path, capsys, media_type, content):
221
+ destination = tmp_path / "bag.webp"
222
+ destination.write_bytes(b"previous file")
223
+
224
+ def handler(request):
225
+ return httpx.Response(200, content=content, headers={"Content-Type": media_type})
226
+
227
+ assert main(["images", "download", IMAGE_HANDLE, str(destination)], client=mock_client(handler)) == 6
228
+ output = capsys.readouterr()
229
+ assert output.out == ""
230
+ assert json.loads(output.err)["code"] == "invalid_server_response"
231
+ assert destination.read_bytes() == b"previous file"
232
+
233
+
234
+ def test_image_download_leaves_no_file_if_connection_drops(tmp_path, capsys):
235
+ destination = tmp_path / "bag.webp"
236
+
237
+ class InterruptedResponse(httpx.SyncByteStream):
238
+ def __iter__(self):
239
+ yield DISPLAY_WEBP[:20]
240
+ raise httpx.ReadError("connection dropped")
241
+
242
+ def handler(request):
243
+ return httpx.Response(200, stream=InterruptedResponse(), headers={"Content-Type": "image/webp"})
244
+
245
+ assert main(["images", "download", IMAGE_HANDLE, str(destination)], client=mock_client(handler)) == 3
246
+ output = capsys.readouterr()
247
+ assert output.out == ""
248
+ assert json.loads(output.err)["code"] == "backend_unavailable"
249
+ assert list(tmp_path.iterdir()) == []
250
+
251
+
136
252
  def test_setup_catalogs_attach_images_and_brew_methods_can_clear_them(capsys, tmp_path):
137
253
  image_id = "11111111-1111-4111-8111-111111111111"
138
254
  requests = []
File without changes