37 lines
1.3 KiB
TypeScript
37 lines
1.3 KiB
TypeScript
import { describe, expect, test } from "vitest";
|
|
import { createPluginCapabilityUseRecorder } from "./audit.js";
|
|
|
|
/**
|
|
* Coverage for the recorder's error-logging branch when the sink rejects
|
|
* with a non-Error value — the logger receives the raw thrown value
|
|
* rather than a {name, message} projection.
|
|
*/
|
|
|
|
describe("createPluginCapabilityUseRecorder — non-Error sink failure", () => {
|
|
test("logs the raw thrown value when the sink rejects with a non-Error", async () => {
|
|
const errors: Record<string, unknown>[] = [];
|
|
const recorder = createPluginCapabilityUseRecorder({
|
|
tenantId: "t1",
|
|
pluginId: "p1",
|
|
sink: {
|
|
async emit() {
|
|
// eslint-disable-next-line @typescript-eslint/only-throw-error
|
|
throw { code: "OUTBOX_DOWN", transient: true };
|
|
},
|
|
},
|
|
logger: {
|
|
error: (record) => {
|
|
errors.push(record);
|
|
},
|
|
},
|
|
});
|
|
recorder.record({ capability: "log", outcome: "success" });
|
|
|
|
// Soft-fail (default): flush resolves, the error is only logged.
|
|
await expect(recorder.flush()).resolves.toBeUndefined();
|
|
expect(errors).toHaveLength(1);
|
|
expect(errors[0]?.err).toEqual({ code: "OUTBOX_DOWN", transient: true });
|
|
expect(errors[0]?.entryCount).toBe(1);
|
|
});
|
|
});
|