import { describe, expectTypeOf, it } from "vitest"; import type { OpenClawPluginServiceContext as CoreServiceContext } from "./core.js"; import type { DiagnosticEventPayload, DiagnosticEventPrivateData } from "./diagnostic-runtime.js"; import type { OpenClawPluginServiceContext as PluginEntryServiceContext } from "./plugin-entry.js"; type ListenerArgs = NonNullable extends { onEvent: infer TOnEvent } ? TOnEvent extends (listener: infer TListener) => unknown ? TListener extends (...args: infer TArgs) => unknown ? TArgs : never : never : never; type ListenerPrivateData = ListenerArgs[2]; type InternalDiagnostics = NonNullable< T["internalDiagnostics"] >; type TelemetryExporterEvent = Extract; describe("plugin service diagnostics contract", () => { it("keeps host attribution out of public SDK listener declarations", () => { expectTypeOf< ListenerPrivateData >().toEqualTypeOf(); expectTypeOf< ListenerPrivateData >().toEqualTypeOf(); expectTypeOf["length"]>().toEqualTypeOf<3>(); expectTypeOf["length"]>().toEqualTypeOf<3>(); expectTypeOf< "hostPluginId" extends keyof ListenerPrivateData ? true : false >().toEqualTypeOf(); expectTypeOf< "reportExporterHealth" extends keyof InternalDiagnostics ? true : false >().toEqualTypeOf(); expectTypeOf< "reportExporterHealth" extends keyof InternalDiagnostics ? true : false >().toEqualTypeOf(); }); it("keeps the shipped telemetry exporter event union unchanged", () => { expectTypeOf().toEqualTypeOf< "started" | "failure" | "dropped" >(); expectTypeOf>().toEqualTypeOf< | "configured" | "emit_failed" | "handler_failed" | "queue_full" | "shutdown_failed" | "start_failed" | "unsupported_protocol" >(); expectTypeOf< "transport" extends keyof TelemetryExporterEvent ? true : false >().toEqualTypeOf(); expectTypeOf< "endpointMode" extends keyof TelemetryExporterEvent ? true : false >().toEqualTypeOf(); }); });