@biffo/cli 0.335.0 → 0.337.0

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.
@@ -42,7 +42,8 @@ plugin-template/
42
42
  │ └── main.py # Lambda entrypoint dispatching EventBridge events
43
43
  └── tests/
44
44
  ├── conftest.py
45
- ├── fakes.py # in-memory fake of the Core API's generic CRUD routes
45
+ ├── fakes.py # in-memory fake of the Core API's generic CRUD routes (bounds generated from the manifest)
46
+ ├── example_plugin_record_fixtures.py # captures real payloads into tests/captured/ (don't invent fixtures)
46
47
  └── test_example_plugin.py
47
48
  ```
48
49
 
@@ -18,15 +18,26 @@ from itertools import count
18
18
  from typing import Any
19
19
 
20
20
  import httpx
21
- from biffo_plugin_sdk import BiffoAPIClient
21
+ from biffo_plugin_sdk import BiffoAPIClient, ManifestSchema, SchemaViolation, load_manifest
22
+
23
+ from example_plugin.manifest import MANIFEST_PATH
22
24
 
23
25
  _BASE_PATH = "/api/v1/plugins/example-plugin"
24
26
 
25
27
 
26
28
  class FakeCoreApi:
27
- """Fake backing store for the plugin's own generic CRUD routes."""
29
+ """Fake backing store for the plugin's own generic CRUD routes.
30
+
31
+ Rejects what production rejects: on create it validates the payload
32
+ against the column bounds, types and NOT NULLs *generated from this
33
+ plugin's own `biffo.plugin.json` table declarations* (SDK `ManifestSchema`),
34
+ returning 422 like Core. Nothing here hand-writes a bound, so a manifest
35
+ change (e.g. `String(100)` -> `String(64)`) changes the fake with it.
36
+ """
28
37
 
29
38
  def __init__(self) -> None:
39
+ self._manifest = load_manifest(MANIFEST_PATH)
40
+ self._schema = ManifestSchema.from_manifest(self._manifest)
30
41
  self.tables: dict[str, list[dict[str, Any]]] = {"widgets": []}
31
42
  self.request_log: list[tuple[str, str]] = []
32
43
  self._ids = count(1)
@@ -60,6 +71,12 @@ class FakeCoreApi:
60
71
 
61
72
  if request.method == "POST":
62
73
  payload = json.loads(request.content or b"{}")
74
+ declared = self._schema.table_for_route(self._manifest, table)
75
+ if declared is not None:
76
+ try:
77
+ self._schema.validate(declared, payload)
78
+ except SchemaViolation as exc:
79
+ return httpx.Response(422, json={"detail": exc.problems})
63
80
  row = {"id": f"id-{next(self._ids)}", "tenant_id": "default", **payload}
64
81
  rows.append(row)
65
82
  return httpx.Response(201, json=row)
@@ -0,0 +1,43 @@
1
+ """Capture real payloads as this plugin's test fixtures (don't invent them).
2
+
3
+ A test can only check what its author already thought of, so a new plugin's
4
+ first fixtures come from the real system, not from a hand-written dict. Run,
5
+ against dev (never prod):
6
+
7
+ BIFFO_CORE_URL=https://core.dev.example.com BIFFO_CORE_TOKEN=<jwt> \\
8
+ uv run python tests/example_plugin_record_fixtures.py core_widgets_list \\
9
+ /api/v1/plugins/example-plugin/widgets
10
+
11
+ It GETs the path and writes `tests/captured/<shape>.json`, which you commit.
12
+ Agent outputs are captured the same way from code: call
13
+ `FixtureRecorder("tests/captured", record=True).capture("<shape>", fetch)` where
14
+ `fetch` runs the real agent once. Tests then replay with
15
+ `FixtureRecorder(CAPTURED).load("<shape>")`; a missing shape raises rather than
16
+ silently inventing one. Requires biffo-plugin-sdk >= 1.8.
17
+ """
18
+
19
+ from __future__ import annotations
20
+
21
+ import asyncio
22
+ import os
23
+ import sys
24
+ from pathlib import Path
25
+
26
+ from biffo_plugin_sdk import BiffoAPIClient, FixtureRecorder
27
+
28
+ CAPTURED_DIR = Path(__file__).parent / "captured"
29
+
30
+
31
+ async def _main(shape: str, path: str) -> None:
32
+ async with BiffoAPIClient(
33
+ base_url=os.environ["BIFFO_CORE_URL"], token=os.environ["BIFFO_CORE_TOKEN"]
34
+ ) as client:
35
+ recorder = FixtureRecorder(CAPTURED_DIR, record=True)
36
+ payload = await client.get(path)
37
+ print(f"wrote {recorder.save(shape, payload)}")
38
+
39
+
40
+ if __name__ == "__main__":
41
+ if len(sys.argv) != 3:
42
+ sys.exit("usage: example_plugin_record_fixtures.py <shape> <core-path>")
43
+ asyncio.run(_main(sys.argv[1], sys.argv[2]))
@@ -117,3 +117,35 @@ class TestUserCreatedLogsEvent:
117
117
  payload={"cognito_sub": "user-123", "email": "new@example.com"},
118
118
  )
119
119
  await plugin.events.dispatch(event)
120
+
121
+
122
+ class TestFakeRejectsWhatProductionRejects:
123
+ """The fake's bounds are generated from the manifest, so widening a value
124
+ past the declared `String(100)` must be refused, not silently recorded."""
125
+
126
+ async def test_value_within_declared_bound_is_accepted(self) -> None:
127
+ _, fake = _make_plugin()
128
+ await fake.client().post("/api/v1/plugins/example-plugin/widgets", json={"name": "x" * 100})
129
+ assert len(fake.tables["widgets"]) == 1
130
+
131
+ async def test_value_past_declared_bound_is_rejected(self) -> None:
132
+ import pytest
133
+ from biffo_plugin_sdk import BiffoAPIError
134
+
135
+ _, fake = _make_plugin()
136
+ with pytest.raises(BiffoAPIError) as err:
137
+ await fake.client().post(
138
+ "/api/v1/plugins/example-plugin/widgets", json={"name": "x" * 101}
139
+ )
140
+ assert err.value.status_code == 422
141
+ assert fake.tables["widgets"] == []
142
+
143
+ async def test_missing_not_null_column_is_rejected(self) -> None:
144
+ import pytest
145
+ from biffo_plugin_sdk import BiffoAPIError
146
+
147
+ _, fake = _make_plugin()
148
+ with pytest.raises(BiffoAPIError):
149
+ await fake.client().post(
150
+ "/api/v1/plugins/example-plugin/widgets", json={"description": "no name"}
151
+ )
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@biffo/cli",
3
- "version": "0.335.0",
3
+ "version": "0.337.0",
4
4
  "description": "Biffo project scaffolding CLI",
5
5
  "license": "MIT",
6
6
  "type": "module",