Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

test(audit-log-stream): drop unit tests that only restate mocks or the e2e spec

Calvin7d7829965828
diff --git a/backend/src/ee/services/audit-log-stream-outbox/audit-log-stream-outbox-service.test.ts b/backend/src/ee/services/audit-log-stream-outbox/audit-log-stream-outbox-service.test.ts
index f985a7f7d1..a4871ab8ff 100644
--- a/backend/src/ee/services/audit-log-stream-outbox/audit-log-stream-outbox-service.test.ts
+++ b/backend/src/ee/services/audit-log-stream-outbox/audit-log-stream-outbox-service.test.ts
@@ -619,132 +619,3 @@ describe("audit-log-stream-outbox-service sweepStaleClaims", () => {
expect(exhaustedCounterAdd).not.toHaveBeenCalled();
});
});
-
-const containing = (fields: Record<string, unknown>): unknown => expect.objectContaining(fields);
-
-describe("audit-log-stream-outbox-service delivery failure alerting", () => {
- const FAILING_SINCE = new Date("2026-10-07T10:00:00.000Z");
-
- const failingStream = {
- id: STREAM_ID,
- provider: PROVIDER,
- orgId: ORG_ID,
- encryptedCredentials: Buffer.from("x"),
- streamMode: StreamMode.Batch,
- failingSince: FAILING_SINCE
- };
-
- beforeEach(() => {
- vi.clearAllMocks();
- getProviderBatchLimit.mockReturnValue({ maxLogs: 1_000, maxBytes: 4 * 1024 * 1024 });
- decryptLogStreamCredentials.mockResolvedValue({});
- });
-
- test("emits one event with the drop when a healthy stream exhausts a row", async () => {
- const { service, auditLogStreamOutboxDAL, eventEmitter } = createService();
- auditLogStreamOutboxDAL.claimBatchForStream
- .mockResolvedValueOnce([buildRow({ attempts: 4 }), buildRow({ id: 2, attempts: 4 })])
- .mockResolvedValueOnce([]);
- auditLogStreamOutboxDAL.markStreamFailing.mockResolvedValueOnce(FAILING_SINCE);
- batchStreamLog.mockRejectedValueOnce(new Error(FAILURE_MESSAGE));
-
- await service.drainStream({ streamId: STREAM_ID, orgId: ORG_ID, provider: PROVIDER });
-
- expect(auditLogStreamOutboxDAL.commitDeliveryResult).toHaveBeenCalledWith(expect.anything(), TX);
- expect(auditLogStreamOutboxDAL.markStreamFailing).toHaveBeenCalledWith(
- { streamId: STREAM_ID, errorMessage: FAILURE_MESSAGE },
- TX
- );
- expect(eventEmitter.emit).toHaveBeenCalledTimes(1);
- expect(eventEmitter.emit).toHaveBeenCalledWith(
- {
- eventType: "audit-log.stream.delivery-failed",
- payload: containing({
- orgId: ORG_ID,
- resourceType: "audit-log.stream",
- resourceId: STREAM_ID,
- targetIds: [STREAM_ID],
- provider: PROVIDER,
- errorMessage: FAILURE_MESSAGE,
- droppedCount: 2,
- failingSince: FAILING_SINCE.toISOString()
- })
- },
- TX
- );
- });
-
- test("does not emit when another worker already flipped the stream to failing", async () => {
- const { service, auditLogStreamOutboxDAL, eventEmitter } = createService();
- auditLogStreamOutboxDAL.claimBatchForStream
- .mockResolvedValueOnce([buildRow({ attempts: 4 })])
- .mockResolvedValueOnce([]);
- auditLogStreamOutboxDAL.markStreamFailing.mockResolvedValueOnce(null);
- batchStreamLog.mockRejectedValueOnce(new Error(FAILURE_MESSAGE));
-
- await service.drainStream({ streamId: STREAM_ID, orgId: ORG_ID, provider: PROVIDER });
-
- expect(eventEmitter.emit).not.toHaveBeenCalled();
- });
-
- test("does not touch stream health for a retriable failure", async () => {
- const { service, auditLogStreamOutboxDAL } = createService();
- auditLogStreamOutboxDAL.claimBatchForStream.mockResolvedValueOnce([buildRow()]).mockResolvedValueOnce([]);
- batchStreamLog.mockRejectedValueOnce(new Error(FAILURE_MESSAGE));
-
- await service.drainStream({ streamId: STREAM_ID, orgId: ORG_ID, provider: PROVIDER });
-
- expect(auditLogStreamOutboxDAL.markStreamFailing).not.toHaveBeenCalled();
- expect(auditLogStreamOutboxDAL.clearStreamFailing).not.toHaveBeenCalled();
- });
-
- test("does not touch stream health for a healthy stream that delivers", async () => {
- const { service, auditLogStreamOutboxDAL } = createService();
- auditLogStreamOutboxDAL.claimBatchForStream.mockResolvedValueOnce([buildRow()]).mockResolvedValueOnce([]);
- batchStreamLog.mockResolvedValueOnce(undefined);
-
- await service.drainStream({ streamId: STREAM_ID, orgId: ORG_ID, provider: PROVIDER });
-
- expect(auditLogStreamOutboxDAL.markStreamFailing).not.toHaveBeenCalled();
- expect(auditLogStreamOutboxDAL.clearStreamFailing).not.toHaveBeenCalled();
- });
-
- test("stays quiet when a stream that is already failing exhausts more rows", async () => {
- const { service, auditLogStreamOutboxDAL, eventEmitter } = createService();
- auditLogStreamOutboxDAL.markStreamFailing.mockResolvedValueOnce(null);
- auditLogStreamOutboxDAL.claimBatchForStream
- .mockResolvedValueOnce([buildRow({ attempts: 4 })])
- .mockResolvedValueOnce([]);
- batchStreamLog.mockRejectedValueOnce(new Error(FAILURE_MESSAGE));
-
- await service.drainStream({ streamId: STREAM_ID, orgId: ORG_ID, provider: PROVIDER });
-
- expect(eventEmitter.emit).not.toHaveBeenCalled();
- });
-
- test("clears the failing state when a failing stream delivers again", async () => {
- const { service, auditLogStreamOutboxDAL, auditLogStreamDAL, eventEmitter } = createService();
- auditLogStreamDAL.findById.mockResolvedValueOnce(failingStream);
- auditLogStreamOutboxDAL.claimBatchForStream.mockResolvedValueOnce([buildRow()]).mockResolvedValueOnce([]);
- batchStreamLog.mockResolvedValueOnce(undefined);
-
- await service.drainStream({ streamId: STREAM_ID, orgId: ORG_ID, provider: PROVIDER });
-
- expect(auditLogStreamOutboxDAL.clearStreamFailing).toHaveBeenCalledWith(STREAM_ID, TX);
- expect(eventEmitter.emit).not.toHaveBeenCalled();
- });
-
- test("a credential decrypt failure claims the rows and fails them instead of throwing", async () => {
- const { service, auditLogStreamOutboxDAL } = createService();
- decryptLogStreamCredentials.mockRejectedValueOnce(new Error("kms unreachable"));
- auditLogStreamOutboxDAL.claimBatchForStream.mockResolvedValueOnce([buildRow()]).mockResolvedValueOnce([]);
-
- await service.drainStream({ streamId: STREAM_ID, orgId: ORG_ID, provider: PROVIDER });
-
- expect(batchStreamLog).not.toHaveBeenCalled();
- const call = auditLogStreamOutboxDAL.commitDeliveryResult.mock.calls[0][0] as {
- retriable: { groups: { ids: number[] }[] } | null;
- };
- expect(call.retriable?.groups.flatMap((g) => g.ids)).toEqual([1]);
- });
-});
diff --git a/backend/src/services/alert/providers/audit-log-stream-alert-provider.test.ts b/backend/src/services/alert/providers/audit-log-stream-alert-provider.test.ts
index a58856d7e0..d4b51c3df3 100644
--- a/backend/src/services/alert/providers/audit-log-stream-alert-provider.test.ts
+++ b/backend/src/services/alert/providers/audit-log-stream-alert-provider.test.ts
@@ -3,35 +3,19 @@ import { describe, expect, test, vi } from "vitest";
import {
AUDIT_LOG_STREAM_DELIVERY_FAILED_EVENT,
- AUDIT_LOG_STREAM_RESOURCE_TYPE,
AuditLogStreamDeliveryFailedPayloadSchema,
emitAuditLogStreamDeliveryFailed
} from "@app/ee/services/audit-log-stream/audit-log-stream-events";
import { OrgPermissionActions, OrgPermissionSubjects } from "@app/ee/services/permission/org-permission";
import { ActorType } from "@app/services/auth/auth-type";
-import { AlertPermissionAction, AlertTriggerType, TAlertContext } from "../alert-types";
+import { AlertPermissionAction } from "../alert-types";
import { auditLogStreamAlertProviderFactory } from "./audit-log-stream-alert-provider";
-vi.mock("@app/lib/config/env", () => ({
- getConfig: () => ({ SITE_URL: "https://app.infisical.com" })
-}));
-
const ORG_ID = "org-1";
const STREAM_ID = "stream-1";
const FAILING_SINCE = new Date("2026-10-07T10:00:00.000Z");
-const alertContext = (overrides: Partial<TAlertContext> = {}): TAlertContext => ({
- id: "alert-1",
- name: "stream-down",
- orgId: ORG_ID,
- resourceType: AUDIT_LOG_STREAM_RESOURCE_TYPE,
- resourceId: null,
- eventType: AUDIT_LOG_STREAM_DELIVERY_FAILED_EVENT,
- condition: null,
- ...overrides
-});
-
const buildProvider = (abilityRules: Parameters<typeof createMongoAbility>[0] = []) => {
const auditLogStreamAlertDAL = {
findStreamInOrg: vi.fn<(id: string, orgId: string) => Promise<{ id: string; provider: string } | undefined>>(
@@ -54,14 +38,6 @@ const buildProvider = (abilityRules: Parameters<typeof createMongoAbility>[0] =
const actor = { actor: ActorType.USER, actorId: "user-1", actorAuthMethod: null, actorOrgId: ORG_ID };
describe("audit-log-stream alert provider", () => {
- test("declares one event-triggered event", () => {
- const { provider } = buildProvider();
- expect(provider.resourceType).toBe("audit-log.stream");
- expect(provider.events).toHaveLength(1);
- expect(provider.events[0].key).toBe(AUDIT_LOG_STREAM_DELIVERY_FAILED_EVENT);
- expect(provider.events[0].triggerType).toBe(AlertTriggerType.Event);
- });
-
test("findEventTargets reads what the emit helper writes", async () => {
const { provider, auditLogStreamAlertDAL } = buildProvider();
const emit = vi.fn(async () => undefined);
@@ -101,79 +77,6 @@ describe("audit-log-stream alert provider", () => {
]);
});
- test("findEventTargets drops a stream deleted before delivery", async () => {
- const { provider, auditLogStreamAlertDAL } = buildProvider();
- auditLogStreamAlertDAL.findStreamsByIds.mockResolvedValueOnce([]);
-
- const targets = await provider.findEventTargets({
- orgId: ORG_ID,
- eventType: AUDIT_LOG_STREAM_DELIVERY_FAILED_EVENT,
- condition: null,
- targetIds: [STREAM_ID],
- payload: {
- provider: "datadog",
- errorMessage: "boom",
- droppedCount: 1,
- failingSince: FAILING_SINCE.toISOString()
- }
- });
-
- expect(targets).toEqual([]);
- });
-
- test("findEventTargets throws on an unreadable payload", async () => {
- const { provider } = buildProvider();
- await expect(
- provider.findEventTargets({
- orgId: ORG_ID,
- eventType: AUDIT_LOG_STREAM_DELIVERY_FAILED_EVENT,
- condition: null,
- targetIds: [STREAM_ID],
- payload: {}
- })
- ).rejects.toThrow(/Unreadable/);
- });
-
- test("buildPayload names the stream, error and drop count and links to the streams tab", async () => {
- const { provider } = buildProvider();
- const viewUrl = await provider.buildViewUrl(alertContext());
- expect(viewUrl).toBe("https://app.infisical.com/organizations/org-1/audit-logs?selectedTab=streams");
-
- const payload = provider.buildPayload(
- alertContext(),
- [
- {
- streamId: STREAM_ID,
- provider: "sumo-logic",
- errorMessage: "timeout of 5000ms exceeded",
- droppedCount: 12,
- failingSince: FAILING_SINCE
- }
- ],
- viewUrl
- );
-
- expect(payload.severity).toBe("critical");
- expect(payload.summary).toContain("Sumo Logic");
- expect(payload.items[0].id).toBe(provider.targetId({ streamId: STREAM_ID } as never));
- expect(payload.items[0].fields).toEqual(
- expect.arrayContaining([
- { label: "Error", value: "timeout of 5000ms exceeded" },
- { label: "Dropped Events", value: "12" }
- ])
- );
- });
-
- test("assertResourceInScope rejects a stream from another org", async () => {
- const { provider, auditLogStreamAlertDAL } = buildProvider();
- auditLogStreamAlertDAL.findStreamInOrg.mockResolvedValueOnce(undefined);
-
- await expect(provider.assertResourceInScope({ orgId: ORG_ID, resourceId: STREAM_ID })).rejects.toThrow(
- /not found in this organization/
- );
- await expect(provider.assertResourceInScope({ orgId: ORG_ID, resourceId: null })).resolves.toBeUndefined();
- });
-
test("assertPermission needs settings read to read and settings edit to write", async () => {
const reader = buildProvider([{ action: OrgPermissionActions.Read, subject: OrgPermissionSubjects.Settings }]);
await expect(