import { OpenAPIHono } from "@hono/zod-openapi"; import { createPluginContext } from "@suaveplan/api-plugin"; import { EventBus } from "@suaveplan/events"; import type { SurrealAdapter } from "@suaveplan/surrealdb"; import { describe, expect, it } from "@suaveplan/testing/runner"; import { CONTACTS_API_CODES } from "../error-codes/error-codes.js"; import { createContactsPlugin, runOnInit } from "./plugin.js"; const noopLogger = { debug: () => undefined, info: () => undefined, warn: () => undefined, error: () => undefined, }; describe("plugin onInit error propagation", () => { it("onInit raises SCHEMA_APPLY_FAILED when execute throws", { timeout: 5000, }, async () => { const db = { async execute() { throw new Error("db disconnected"); }, async query() { return [[]]; }, } as unknown as SurrealAdapter; const app = new OpenAPIHono(); const services = new Map(); services.set("app", app); services.set("db", db); const ctx = createPluginContext({ logger: noopLogger, eventBus: new EventBus(), signal: new AbortController().signal, config: {} as never, services, }); const desc = createContactsPlugin({ applySchemaOnInit: true }); await expect( runOnInit(ctx as never, desc.defaults) ).rejects.toMatchObject({ code: CONTACTS_API_CODES.SCHEMA_APPLY_FAILED, }); }); });