package main import ( "net/http" "testing" "git.dev.alexdunmow.com/block/pluginsdk/plugin" "github.com/go-chi/chi/v5" ) // TestRouterMatchesAbsolutePluginPaths pins the wasm routing contract: the // host forwards the FULL request path (/api/plugins/calcomblock/...) to the // guest with no prefix strip, so every route must be registered absolute. // Relative registrations 404 the plugin's entire HTTP surface at runtime — // exactly the regression that shipped in 2.0.0–2.0.2. func TestRouterMatchesAbsolutePluginPaths(t *testing.T) { router, ok := NewCalcomRouter(plugin.CoreServices{}).(chi.Routes) if !ok { t.Fatal("NewCalcomRouter no longer returns a chi router") } for _, tc := range []struct{ method, path string }{ {http.MethodGet, "/api/plugins/calcomblock/reset"}, {http.MethodGet, "/api/plugins/calcomblock/slots"}, {http.MethodGet, "/api/plugins/calcomblock/date-grid"}, {http.MethodPost, "/api/plugins/calcomblock/book"}, {http.MethodPost, "/api/plugins/calcomblock/cancel"}, {http.MethodGet, "/api/plugins/calcomblock/event-types"}, } { rctx := chi.NewRouteContext() if !router.Match(rctx, tc.method, tc.path) { t.Errorf("%s %s does not match any route — must be registered at the absolute plugin path", tc.method, tc.path) } } }