testdata/fixture is the acceptance fixture: one block, one template, one admin page, plus the two-line reactor boilerplate main. wasmhost_test.go compiles it with GOOS=wasip1 GOARCH=wasm -buildmode=c-shared (15.7 MiB, the WO-WZ-012 memory-budget baseline) and drives it through wazero exactly per wasm-abi.md: _initialize as the start function, request bytes through bn_alloc, DESCRIBE returning a decodable manifest, same-instance block+template renders, a panicking BlockFunc surfacing as ABI_ERROR_CODE_INTERNAL with the instance still callable, and a non-bn_alloc request pointer rejected as DECODE. wazero v1.12.0 joins go.mod as a test-only dependency (approved). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
55 lines
1.6 KiB
Go
55 lines
1.6 KiB
Go
// Package main is the WO-WZ-002 acceptance fixture: a minimal plugin with
|
|
// one block, one template, and one admin page, compiled to wasm with only
|
|
// the wasmguest boilerplate (main.go).
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"io"
|
|
|
|
"git.dev.alexdunmow.com/block/core/blocks"
|
|
"git.dev.alexdunmow.com/block/core/plugin"
|
|
"git.dev.alexdunmow.com/block/core/templates"
|
|
)
|
|
|
|
// Registration is the fixture's plugin registration — the same shape a .so
|
|
// plugin exports, untouched by the wasm migration.
|
|
var Registration = plugin.PluginRegistration{
|
|
Name: "wasmfixture",
|
|
Version: "0.0.1",
|
|
Register: func(tr templates.TemplateRegistry, br blocks.BlockRegistry) error {
|
|
br.Register(blocks.BlockMeta{
|
|
Key: "greeting",
|
|
Title: "Greeting",
|
|
Description: "Renders a greeting",
|
|
Category: blocks.CategoryContent,
|
|
}, func(ctx context.Context, content map[string]any) string {
|
|
if boom, _ := content["boom"].(bool); boom {
|
|
panic("fixture kaboom")
|
|
}
|
|
name, _ := content["name"].(string)
|
|
if name == "" {
|
|
name = "world"
|
|
}
|
|
return fmt.Sprintf("<p>hello %s</p>", name)
|
|
})
|
|
return tr.Register("wasmfixture-page", func(ctx context.Context, doc map[string]any) templates.HTMLComponent {
|
|
title, _ := doc["title"].(string)
|
|
return htmlString("<!doctype html><title>" + title + "</title>")
|
|
})
|
|
},
|
|
AdminPages: func() []plugin.AdminPage {
|
|
return []plugin.AdminPage{{
|
|
Key: "wasmfixture", Title: "Wasm Fixture", Icon: "flask", Route: "/admin/wasmfixture",
|
|
}}
|
|
},
|
|
}
|
|
|
|
type htmlString string
|
|
|
|
func (s htmlString) Render(_ context.Context, w io.Writer) error {
|
|
_, err := io.WriteString(w, string(s))
|
|
return err
|
|
}
|