@biffo/cli 0.336.0 → 0.338.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.
- package/_skeletons/plugin-template/.github/workflows/ci.yml +7 -0
- package/_skeletons/plugin-template/README.md +10 -2
- package/_skeletons/plugin-template/biffo.plugin.json +17 -3
- package/_skeletons/plugin-template/tests/captured/.gitkeep +0 -0
- package/_skeletons/plugin-template/tests/example_plugin_fakes.py +19 -2
- package/_skeletons/plugin-template/tests/example_plugin_record_fixtures.py +43 -0
- package/_skeletons/plugin-template/tests/test_example_plugin.py +32 -0
- package/_skeletons/plugin-template/tests/test_example_plugin_ingress_surfaces.py +21 -3
- package/dist/index.js +21 -0
- package/package.json +1 -1
|
@@ -176,6 +176,13 @@ jobs:
|
|
|
176
176
|
# invokes `uv run --no-sync`, i.e. it expects a synced .venv, not a
|
|
177
177
|
# fresh one) and because biffo.plugin.json's own tables/permissions
|
|
178
178
|
# are exactly what the harness conforms against.
|
|
179
|
+
# The manifest's ingress `required_group`s are `setting:` references
|
|
180
|
+
# (biffo-template#1517): verify fails closed unless the instance-
|
|
181
|
+
# supplied values exist, exactly as `biffo plugin install` does, so
|
|
182
|
+
# supply stand-ins here (placeholders — never a real instance's groups).
|
|
183
|
+
env:
|
|
184
|
+
BIFFO_PLUGIN_EXAMPLE_PLUGIN_FOUNDER_GROUP: founder
|
|
185
|
+
BIFFO_PLUGIN_EXAMPLE_PLUGIN_ADMIN_GROUP: admin
|
|
179
186
|
run: sh scripts/biffo.sh plugin verify
|
|
180
187
|
- uses: codecov/codecov-action@v5
|
|
181
188
|
if: always()
|
|
@@ -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
|
|
|
@@ -137,10 +138,17 @@ in `biffo.plugin.json`:
|
|
|
137
138
|
```json
|
|
138
139
|
"user_frontend": {
|
|
139
140
|
"dir": "web/dist",
|
|
140
|
-
"required_group": "
|
|
141
|
+
"required_group": "setting:founder_group"
|
|
141
142
|
}
|
|
142
143
|
```
|
|
143
144
|
|
|
145
|
+
`required_group` is a **reference**, not a group name: `setting:<name>` names a
|
|
146
|
+
`kind: "setting"` entry in the manifest's `config:` list, which the instance
|
|
147
|
+
supplies at install time (`biffo plugin install --config founder_group=<group>`)
|
|
148
|
+
and the shared host resolves per plugin. The same form applies to
|
|
149
|
+
`user_ingress` and `admin_ingress`. A literal group name still validates but is
|
|
150
|
+
deprecated (the SDK emits a `LegacyRequiredGroupWarning`).
|
|
151
|
+
|
|
144
152
|
and ships **`web/` and nothing else** — a built static bundle (`index.html`
|
|
145
153
|
plus hashed `assets/*`, the ordinary Vite build-output shape) at the
|
|
146
154
|
repo-relative path `dir` names. That is the entire contract. In particular a
|
|
@@ -90,16 +90,30 @@
|
|
|
90
90
|
"dependencies": {
|
|
91
91
|
"biffo-plugin-sdk": "^1.0"
|
|
92
92
|
},
|
|
93
|
+
"config": [
|
|
94
|
+
{
|
|
95
|
+
"name": "founder_group",
|
|
96
|
+
"kind": "setting",
|
|
97
|
+
"required": true,
|
|
98
|
+
"description": "Cognito group allowed on the user ingress and the user frontend. Supplied by the instance at install time (e.g. --config founder_group=<group>)."
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
"name": "admin_group",
|
|
102
|
+
"kind": "setting",
|
|
103
|
+
"required": true,
|
|
104
|
+
"description": "Cognito group allowed on the admin ingress. Supplied by the instance at install time (e.g. --config admin_group=<group>)."
|
|
105
|
+
}
|
|
106
|
+
],
|
|
93
107
|
"user_ingress": {
|
|
94
|
-
"required_group": "
|
|
108
|
+
"required_group": "setting:founder_group",
|
|
95
109
|
"app": "example_plugin.user_app:app"
|
|
96
110
|
},
|
|
97
111
|
"admin_ingress": {
|
|
98
|
-
"required_group": "
|
|
112
|
+
"required_group": "setting:admin_group",
|
|
99
113
|
"app": "example_plugin.admin_app:app"
|
|
100
114
|
},
|
|
101
115
|
"user_frontend": {
|
|
102
116
|
"dir": "web/dist",
|
|
103
|
-
"required_group": "
|
|
117
|
+
"required_group": "setting:founder_group"
|
|
104
118
|
}
|
|
105
119
|
}
|
|
File without changes
|
|
@@ -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
|
+
)
|
|
@@ -38,24 +38,42 @@ def _resolve_app(app_ref: str) -> FastAPI:
|
|
|
38
38
|
return getattr(module, attr)
|
|
39
39
|
|
|
40
40
|
|
|
41
|
+
class TestRequiredGroupsAreSettingReferences:
|
|
42
|
+
"""Every surface's `required_group` names a declared `kind: setting` config
|
|
43
|
+
entry (biffo-template#1517) — never a literal Cognito group baked into the
|
|
44
|
+
manifest. `PluginManifest` already rejects a dangling/non-setting reference
|
|
45
|
+
(and warns on a literal); this pins that the skeleton uses the setting form.
|
|
46
|
+
"""
|
|
47
|
+
|
|
48
|
+
def test_no_surface_carries_a_literal_group(self) -> None:
|
|
49
|
+
manifest = load_manifest(MANIFEST_PATH)
|
|
50
|
+
settings = {c.name for c in manifest.config if c.kind == "setting"}
|
|
51
|
+
for surface in (manifest.user_ingress, manifest.admin_ingress, manifest.user_frontend):
|
|
52
|
+
assert surface is not None
|
|
53
|
+
# Plain string handling, not an SDK helper: the skeleton's locked SDK
|
|
54
|
+
# may predate the helper (the pin is raised separately, #2168).
|
|
55
|
+
assert surface.required_group.startswith("setting:"), surface.required_group
|
|
56
|
+
assert surface.required_group.removeprefix("setting:") in settings
|
|
57
|
+
|
|
58
|
+
|
|
41
59
|
class TestManifestDeclaresAllThreeSurfaces:
|
|
42
60
|
def test_manifest_validates_and_declares_user_ingress(self) -> None:
|
|
43
61
|
manifest = load_manifest(MANIFEST_PATH)
|
|
44
62
|
assert manifest.user_ingress is not None
|
|
45
|
-
assert manifest.user_ingress.required_group == "
|
|
63
|
+
assert manifest.user_ingress.required_group == "setting:founder_group"
|
|
46
64
|
assert manifest.user_ingress.app == "example_plugin.user_app:app"
|
|
47
65
|
|
|
48
66
|
def test_manifest_declares_admin_ingress(self) -> None:
|
|
49
67
|
manifest = load_manifest(MANIFEST_PATH)
|
|
50
68
|
assert manifest.admin_ingress is not None
|
|
51
|
-
assert manifest.admin_ingress.required_group == "
|
|
69
|
+
assert manifest.admin_ingress.required_group == "setting:admin_group"
|
|
52
70
|
assert manifest.admin_ingress.app == "example_plugin.admin_app:app"
|
|
53
71
|
|
|
54
72
|
def test_manifest_declares_user_frontend(self) -> None:
|
|
55
73
|
manifest = load_manifest(MANIFEST_PATH)
|
|
56
74
|
assert manifest.user_frontend is not None
|
|
57
75
|
assert manifest.user_frontend.dir == "web/dist"
|
|
58
|
-
assert manifest.user_frontend.required_group == "
|
|
76
|
+
assert manifest.user_frontend.required_group == "setting:founder_group"
|
|
59
77
|
|
|
60
78
|
def test_ui_components_no_longer_point_at_a_dead_admin_path(self) -> None:
|
|
61
79
|
"""The old `/admin/example-plugin` paths matched none of the three real
|
package/dist/index.js
CHANGED
|
@@ -6800,6 +6800,10 @@ var RouteDefSchema = z6.object({
|
|
|
6800
6800
|
}
|
|
6801
6801
|
});
|
|
6802
6802
|
var REL_DIR = /^[\w][\w./-]*$/;
|
|
6803
|
+
var SETTING_REF_PREFIX = "setting:";
|
|
6804
|
+
function parseSettingRef(value) {
|
|
6805
|
+
return value.startsWith(SETTING_REF_PREFIX) ? value.slice(SETTING_REF_PREFIX.length).trim() : null;
|
|
6806
|
+
}
|
|
6803
6807
|
var NON_EMPTY_GROUP = "required_group must be a non-empty Cognito group name.";
|
|
6804
6808
|
var APP_REF = /^[a-zA-Z_]\w*(\.[a-zA-Z_]\w*)*:[a-zA-Z_]\w*$/;
|
|
6805
6809
|
var UserIngressSchema = z6.object({
|
|
@@ -6915,6 +6919,23 @@ var PluginManifestSchema = z6.object({
|
|
|
6915
6919
|
const settingNames = new Set(
|
|
6916
6920
|
manifest.config.filter((c) => c.kind === "setting").map((c) => c.name)
|
|
6917
6921
|
);
|
|
6922
|
+
const configKinds = new Map(manifest.config.map((c) => [c.name, c.kind]));
|
|
6923
|
+
const surfaces = [
|
|
6924
|
+
["user_ingress", manifest.user_ingress],
|
|
6925
|
+
["admin_ingress", manifest.admin_ingress],
|
|
6926
|
+
["user_frontend", manifest.user_frontend]
|
|
6927
|
+
];
|
|
6928
|
+
for (const [label, surface] of surfaces) {
|
|
6929
|
+
const ref = surface ? parseSettingRef(surface.required_group) : null;
|
|
6930
|
+
if (ref === null) continue;
|
|
6931
|
+
const kind = configKinds.get(ref);
|
|
6932
|
+
if (kind !== "setting") {
|
|
6933
|
+
ctx.addIssue({
|
|
6934
|
+
code: z6.ZodIssueCode.custom,
|
|
6935
|
+
message: `${label}.required_group '${surface.required_group}' references config entry '${ref}', which ${kind === void 0 ? "this manifest does not declare" : `is kind '${kind}', not "setting"`}. Declared setting config names: ${[...settingNames].sort().join(", ") || "none"}`
|
|
6936
|
+
});
|
|
6937
|
+
}
|
|
6938
|
+
}
|
|
6918
6939
|
for (const agent of manifest.chat_agents) {
|
|
6919
6940
|
if (!settingNames.has(agent.required_group)) {
|
|
6920
6941
|
ctx.addIssue({
|