mirror of
https://github.com/J3vb/OwnCord.git
synced 2026-09-03 03:50:00 +03:00
Phase B Step 6 — Solid.js incremental migration
- vite-plugin-solid + solid-js + @solidjs/testing-library in package.json
- vite.config.ts compiles src/components/solid/** as Solid TSX
- tsconfig.json gains jsx: preserve / jsxImportSource: solid-js
- lib/solidAdapter.ts wraps existing custom Stores as Solid signals
- lib/solidMount.ts adapts Solid render to {mount,destroy} contract
- components/solid/Badge.tsx (proof-of-concept leaf)
- components/solid/ChannelListItem.tsx (store-subscribed leaf)
- components/solid/Badge.test.tsx pipeline smoke test
- components/solid/README.md documents the migration recipe
Phase B Step 7 — Event persistence layer
- SQLite + Postgres migrations for the events table
- sqlc query files for both engines
- EventStore interface + SQLite raw-SQL impl + MemStore impl + pg stubs
- ws.EventPersister: async batched writer (queue / flush / drain / drop)
- ws.StartEventPruner: background retention pruner
- hub persists every replay-buffer push and exposes reconnect-tier counters
- serve.handleReconnect: tiered replay (buffer -> DB -> full re-sync)
- EventPersistenceConfig + main.go wiring
- event_persister_test.go covers batching / drops / drain
Phase B Step 8 — OpenTelemetry skeleton
- Server/telemetry package with public Provider/Tracer/Meter/Counter API
- telemetry_default.go (no-op build) + telemetry_otel.go (build tag otel)
- telemetry/metrics.go declares the AppMetrics bundle
- HTTPMiddleware mounted in Chi router (pass-through in default build)
- PrometheusHandler optionally mounted at /metrics
- Spans on MessageService.SendMessage, PermissionService.HasChannelPerm,
ChannelService.ListVisibleChannels
- Reconnect-tier counter wired into the global meter
- TelemetryConfig defaults
Phase C Step 9 — Wazero plugin runtime skeleton
- Server/plugin package: manifest parser, loader, registry, host APIs
(commands, storage, events, http, ui), errors
- sandbox_default.go (no-op) + sandbox_wazero.go (build tag wazero)
- SQLite + Postgres migrations for plugins + plugin_kv tables
- PluginStore interface + impls + pg stubs
- plugin/examples/hello manifest + README
- plugin_test.go covers manifest, loader, capability gating
- api/plugins_handler.go admin REST surface, mounted under admin group
- PluginsConfig + main.go wiring (disabled by default)
- Client: lib/pluginBridge.ts iframe + postMessage host
- Client: components/solid/PluginContainer.tsx Solid host component
Verification
- Default build (no -tags) is intended to compile cleanly with no new
third-party dependencies. The sandbox lacked Go 1.25.0 so go build
could not run; PHASE_BC_LOCAL_TODO.md enumerates the local follow-up
work (npm install, go mod tidy, sqlc-generate, real otel/wazero
wiring, remaining service spans, full Solid migration).
68 lines
1.9 KiB
Go
68 lines
1.9 KiB
Go
// Phase B Step 8 — telemetry default-build smoke test.
|
|
//
|
|
// In the default build (no -tags otel) the package installs a no-op provider
|
|
// that satisfies every API surface. The test confirms Init returns a non-nil
|
|
// shutdown closer, the Global() helper returns a usable provider, and that a
|
|
// pass-through HTTP middleware leaves the wrapped handler intact.
|
|
package telemetry
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
"net/http/httptest"
|
|
"testing"
|
|
|
|
"github.com/owncord/server/config"
|
|
)
|
|
|
|
func TestInitNoOpReturnsShutdown(t *testing.T) {
|
|
shutdown, err := Init(context.Background(), config.TelemetryConfig{Enabled: false})
|
|
if err != nil {
|
|
t.Fatalf("Init: %v", err)
|
|
}
|
|
if shutdown == nil {
|
|
t.Fatal("expected non-nil shutdown")
|
|
}
|
|
if err := shutdown(context.Background()); err != nil {
|
|
t.Fatalf("shutdown: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestGlobalReturnsUsableProvider(t *testing.T) {
|
|
p := Global()
|
|
if p == nil {
|
|
t.Fatal("Global returned nil")
|
|
}
|
|
tracer := p.Tracer("test")
|
|
_, span := tracer.Start(context.Background(), "noop")
|
|
span.SetAttributes(String("k", "v"))
|
|
span.End()
|
|
meter := p.Meter("test")
|
|
meter.Counter("c", "").Add(context.Background(), 1)
|
|
meter.Histogram("h", "", "s").Record(context.Background(), 1.0)
|
|
meter.Gauge("g", "").Set(context.Background(), 0.5)
|
|
}
|
|
|
|
func TestHTTPMiddlewareIsPassThrough(t *testing.T) {
|
|
called := false
|
|
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
called = true
|
|
w.WriteHeader(http.StatusTeapot)
|
|
})
|
|
wrapped := HTTPMiddleware()(handler)
|
|
rec := httptest.NewRecorder()
|
|
wrapped.ServeHTTP(rec, httptest.NewRequest("GET", "/", nil))
|
|
if !called {
|
|
t.Fatal("inner handler not called")
|
|
}
|
|
if rec.Code != http.StatusTeapot {
|
|
t.Fatalf("status: got %d want %d", rec.Code, http.StatusTeapot)
|
|
}
|
|
}
|
|
|
|
func TestPrometheusHandlerNilByDefault(t *testing.T) {
|
|
if PrometheusHandler() != nil {
|
|
t.Fatal("expected nil Prometheus handler in no-op build")
|
|
}
|
|
}
|