Bootstrap the plugin-facing SDK module so the fleet migration (P2) becomes a mechanical block/core/X -> block/pluginsdk/X import rewrite. - abi/proto/v1: the single source-of-truth ABI proto tree, copied from the cms authoring source (cms/backend/abi/proto/v1) with go_package retargeted to git.dev.alexdunmow.com/block/pluginsdk/abi/v1;abiv1. Kills the hand-kept cms/core proto duplication (audit gap 4). - abi/v1: generated Go bindings (buf generate); byte-identical to core's abi/v1 save the embedded go_package path. - plugin/ (registration + DI surface), plugin/wasmguest/** (transport shim, caps stubs, bnwasm db driver, testdata fixtures + golden .pb), and the guest-facing type packages: blocks (+builtin/shared/tags), templates (+pongo/bn), auth, settings, content, gating, crypto, rbac, video, ai, subscriptions, menus, datasources. Internal imports rewritten core -> pluginsdk; zero block/core references remain. - README/AGENTS(+CLAUDE symlink)/Makefile: proto is the contract, Go is one binding; no replace directives; templates/bn is a synced copy authored in cms. Spec: cms docs/superpowers/specs/2026-07-07-proto-first-plugin-sdk-design.md Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
60 lines
1.8 KiB
Go
60 lines
1.8 KiB
Go
package blocks
|
|
|
|
import "testing"
|
|
|
|
func TestPoweredBlockRoundTrip(t *testing.T) {
|
|
marker := PoweredBlock("<p>{{ x }}</p>", map[string]any{"x": "y"})
|
|
pr, ok := DecodePoweredBlock(marker)
|
|
if !ok {
|
|
t.Fatal("DecodePoweredBlock did not recognize its own marker")
|
|
}
|
|
if pr.Template != "<p>{{ x }}</p>" {
|
|
t.Errorf("template = %q", pr.Template)
|
|
}
|
|
if pr.Data["x"] != "y" {
|
|
t.Errorf("data = %v", pr.Data)
|
|
}
|
|
}
|
|
|
|
func TestDecodePoweredBlockRejectsPlainHTML(t *testing.T) {
|
|
if _, ok := DecodePoweredBlock("<p>hello</p>"); ok {
|
|
t.Error("plain HTML must not decode as a powered block")
|
|
}
|
|
if _, ok := DecodePoweredBlock(""); ok {
|
|
t.Error("empty string must not decode as a powered block")
|
|
}
|
|
}
|
|
|
|
func TestTagFilterRegistry(t *testing.T) {
|
|
ResetRegisteredTagsAndFilters()
|
|
t.Cleanup(ResetRegisteredTagsAndFilters)
|
|
|
|
RegisterTag("b", func(map[string]any, RenderContext) (string, error) { return "b", nil })
|
|
RegisterTag("a", func(map[string]any, RenderContext) (string, error) { return "a", nil })
|
|
RegisterFilter("f", func(string, map[string]any) (string, error) { return "f", nil })
|
|
// Empty name / nil fn are ignored.
|
|
RegisterTag("", nil)
|
|
RegisterFilter("g", nil)
|
|
|
|
if names := RegisteredTagNames(); len(names) != 2 || names[0] != "a" || names[1] != "b" {
|
|
t.Errorf("tag names = %v, want sorted [a b]", names)
|
|
}
|
|
if names := RegisteredFilterNames(); len(names) != 1 || names[0] != "f" {
|
|
t.Errorf("filter names = %v, want [f]", names)
|
|
}
|
|
if _, ok := LookupTag("a"); !ok {
|
|
t.Error("LookupTag(a) missing")
|
|
}
|
|
if _, ok := LookupFilter("f"); !ok {
|
|
t.Error("LookupFilter(f) missing")
|
|
}
|
|
if _, ok := LookupTag("missing"); ok {
|
|
t.Error("LookupTag(missing) should be absent")
|
|
}
|
|
|
|
ResetRegisteredTagsAndFilters()
|
|
if RegisteredTagNames() != nil || RegisteredFilterNames() != nil {
|
|
t.Error("reset did not clear registries")
|
|
}
|
|
}
|