@biffo/cli 0.324.7 → 0.324.9

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.
@@ -202,6 +202,46 @@ def _external_base_name(raw: str) -> str | None:
202
202
  return name if name in EXTERNAL_BASE_IDENTIFIERS else None
203
203
 
204
204
 
205
+ #: The dashboard's plugin registry — the one file `biffo plugin install` writes
206
+ #: a `user_frontend` plugin's `frontendUrl` into (`plugin-frontend-registry.ts`
207
+ #: in biffo-template, ADR-0021 section 2).
208
+ PLUGIN_REGISTRY_FILE = "apps/frontend/src/lib/plugins.ts"
209
+
210
+ #: The shared plugin host's `user_frontend` mount: `/api/v1/plugins/<slug>/ui`,
211
+ #: served same-origin by the plugin host behind the `/api/v1/plugins/*` route
212
+ #: family and NEVER by this BFF (biffo-template#2114). Every install of a
213
+ #: `user_frontend` plugin writes exactly one such literal into
214
+ #: `PLUGIN_REGISTRY_FILE`, so without this exemption the required check went
215
+ #: red on the first install, in every split dashboard.
216
+ #:
217
+ #: Like `EXTERNAL_BASE_IDENTIFIERS` this is an explicit ALLOWLIST, and it is
218
+ #: scoped on two axes at once -- the FILE (only `PLUGIN_REGISTRY_FILE`) and the
219
+ #: SHAPE (exactly `/api/v1/plugins/<one segment>/ui`, nothing before, after or
220
+ #: between). Any other `/api/v1/plugins/...` path, the same path from any other
221
+ #: file, or any other `/api/v1/...` path in the registry still has to match a
222
+ #: route this BFF registers.
223
+ #:
224
+ #: The shape is STRUCTURAL and deliberately defines no slug grammar of its own.
225
+ #: An earlier draft spelled the slug as kebab-case (`[a-z0-9]+(-[a-z0-9]+)*`),
226
+ #: which was narrower than what the installer accepts (its manifest grammar is
227
+ #: `^[a-z][a-z0-9-]*$`, admitting `widgets-` and `a--b`), so those installs went
228
+ #: red again. Two hand-kept grammars will always drift; one segment of anything
229
+ #: that cannot be a path separator, a template hole (`{`), a query/fragment
230
+ #: delimiter or a dot-segment cannot. The slug is whatever the installer wrote.
231
+ #: biffo-template pins the writer (`frontendUrlForSlug`) against this constant by
232
+ #: running THIS test over a `plugins.ts` the writer produced, for boundary slugs.
233
+ PLUGIN_HOST_UI_PATH = re.compile(r"^/api/v1/plugins/[^/{}?#.\s]+/ui$")
234
+
235
+
236
+ def is_plugin_host_ui_path(file: Path, normalized: str | None) -> bool:
237
+ """True for a `user_frontend` mount literal in the plugin registry file."""
238
+ return (
239
+ normalized is not None
240
+ and _relative(file) == PLUGIN_REGISTRY_FILE
241
+ and PLUGIN_HOST_UI_PATH.match(normalized) is not None
242
+ )
243
+
244
+
205
245
  def _template_literals(text: str):
206
246
  """Every template literal in `text`, as `(content, start_index)` — scanned
207
247
  with brace and backtick depth rather than matched with a regex.
@@ -728,7 +768,12 @@ def test_every_frontend_api_v1_path_is_registered_on_the_bff() -> None:
728
768
  extracted.extend(extract_api_paths(file.read_text(encoding="utf-8"), file))
729
769
 
730
770
  external = [p for p in extracted if p.external_base is not None]
731
- in_scope = [p for p in extracted if p.external_base is None]
771
+ plugin_host = [
772
+ p
773
+ for p in extracted
774
+ if p.external_base is None and is_plugin_host_ui_path(p.file, p.normalized)
775
+ ]
776
+ in_scope = [p for p in extracted if p.external_base is None and p not in plugin_host]
732
777
  resolved = [p for p in in_scope if p.normalized is not None]
733
778
  unresolved = [p for p in in_scope if p.normalized is None]
734
779
 
@@ -750,7 +795,8 @@ def test_every_frontend_api_v1_path_is_registered_on_the_bff() -> None:
750
795
  f"{matched_count} matched a route this BFF registers, "
751
796
  f"{len(unmatched)} did not, {len(unresolved)} could not be resolved "
752
797
  f"at all, {len(external)} target a declared external base and are out "
753
- "of this BFF's scope."
798
+ f"of this BFF's scope, {len(plugin_host)} are plugin-host `user_frontend` "
799
+ "mounts in the plugin registry (also out of this BFF's scope)."
754
800
  )
755
801
 
756
802
  lines = [summary]
@@ -775,6 +821,11 @@ def test_every_frontend_api_v1_path_is_registered_on_the_bff() -> None:
775
821
  f" EXTERNAL {_relative(p.file)}:{p.line} {p.raw!r} "
776
822
  f"-> prefixed with ${{{p.external_base}}}, declared external"
777
823
  )
824
+ for p in plugin_host:
825
+ lines.append(
826
+ f" PLUGIN-HOST {_relative(p.file)}:{p.line} {p.raw!r} "
827
+ "-> plugin-host user_frontend mount, declared plugin-host route family"
828
+ )
778
829
  if unmatched or unresolved:
779
830
  # Display only -- `path_is_registered` above is what actually decided
780
831
  # pass/fail; see its docstring for why this flattened set cannot be
@@ -1058,3 +1109,44 @@ class TestPathIsRegistered:
1058
1109
  assert path_is_registered(catchall_app, "/api/v1/analytics/pipeline/funnel") is True
1059
1110
  assert path_is_registered(catchall_app, "/api/v1/analytics/pipeline/funnel/{param}") is True
1060
1111
  assert path_is_registered(catchall_app, "/api/v1/other/path") is False
1112
+
1113
+
1114
+ class TestPluginHostRouteFamily:
1115
+ """The plugin-host exemption (biffo-template#2114) is an allowlist scoped by
1116
+ file AND shape — every row below is a way it must NOT widen."""
1117
+
1118
+ REGISTRY = REPO_ROOT / PLUGIN_REGISTRY_FILE
1119
+
1120
+ def test_user_frontend_mount_in_the_registry_is_exempt(self) -> None:
1121
+ assert is_plugin_host_ui_path(self.REGISTRY, "/api/v1/plugins/a5-throwaway/ui")
1122
+ assert is_plugin_host_ui_path(self.REGISTRY, "/api/v1/plugins/widgets/ui")
1123
+
1124
+ def test_every_slug_the_installer_accepts_is_exempt(self) -> None:
1125
+ # Manifest grammar is ^[a-z][a-z0-9-]*$ -- trailing and doubled hyphens
1126
+ # are legal, and so are the hand-authored shapes the registry reader
1127
+ # tolerates (underscore, uppercase). The guard defines no slug grammar.
1128
+ for slug in ("widgets-", "a--b", "a", "x9", "idea-scout", "a_b", "Widgets"):
1129
+ assert is_plugin_host_ui_path(self.REGISTRY, f"/api/v1/plugins/{slug}/ui"), slug
1130
+
1131
+ def test_same_path_in_any_other_file_is_not_exempt(self) -> None:
1132
+ other = FRONTEND_SRC / "lib" / "other.ts"
1133
+ assert not is_plugin_host_ui_path(other, "/api/v1/plugins/widgets/ui")
1134
+
1135
+ def test_other_shapes_in_the_registry_are_not_exempt(self) -> None:
1136
+ for path in (
1137
+ "/api/v1/plugins/widgets",
1138
+ "/api/v1/plugins/widgets/ui/extra",
1139
+ "/api/v1/plugins/widgets/api",
1140
+ "/api/v1/plugins/{param}/ui",
1141
+ "/api/v1/plugins/a/b/ui",
1142
+ "/api/v1/plugins//ui",
1143
+ "/api/v1/plugins/../ui",
1144
+ "/api/v1/plugins/./ui",
1145
+ "/api/v1/plugins/a?x=1/ui",
1146
+ "/api/v1/plugins/a#x/ui",
1147
+ "/api/v1/courses",
1148
+ "/api/v1/whoami",
1149
+ "/x/api/v1/plugins/widgets/ui",
1150
+ None,
1151
+ ):
1152
+ assert not is_plugin_host_ui_path(self.REGISTRY, path), path
package/dist/index.js CHANGED
@@ -10722,9 +10722,11 @@ function findManagedRegion(source) {
10722
10722
  const bodyStart = startIdx + REGISTRY_START_MARKER.length;
10723
10723
  const endIdx = source.indexOf(REGISTRY_END_MARKER, bodyStart);
10724
10724
  if (endIdx === -1) return null;
10725
+ const lineStart = source.lastIndexOf("\n", endIdx - 1) + 1;
10726
+ const seam = lineStart >= bodyStart && /^[ \t]*$/.test(source.slice(lineStart, endIdx)) ? lineStart : endIdx;
10725
10727
  return {
10726
- region: { before: source.slice(0, bodyStart), after: source.slice(endIdx) },
10727
- body: source.slice(bodyStart, endIdx)
10728
+ region: { before: source.slice(0, bodyStart), after: source.slice(seam) },
10729
+ body: source.slice(bodyStart, seam)
10728
10730
  };
10729
10731
  }
10730
10732
  var SLUG_FIELD_PATTERN = /\bslug\s*:\s*(['"])([a-zA-Z0-9_-]+)\1/;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@biffo/cli",
3
- "version": "0.324.7",
3
+ "version": "0.324.9",
4
4
  "description": "Biffo project scaffolding CLI",
5
5
  "license": "MIT",
6
6
  "type": "module",