Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
remove unused stuff from merge conflict
Thiago Araujo da Silvaa32dc7696e8d
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.tsindex 09e3dba44d..f79e188501 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@@ -64,8 +64,6 @@ const buildRow = (overrides: Partial<TAuditLogStreamOutboxRow> = {}): TAuditLogS});const createService = () => {- const onStreamFailure = vi.fn(async () => undefined);-const auditLogStreamOutboxDAL = {batchInsert: vi.fn(async () => undefined),claimBatchForStream: vi.fn<(...args: unknown[]) => Promise<TAuditLogStreamOutboxRow[]>>(async () => []),@@ -92,36 +90,27 @@ const createService = () => {auditLogStreamDAL: auditLogStreamDAL as never,kmsService: {} as never,keyStore: {} as never,- queueService: {} as never,- onStreamFailure+ queueService: {} as never});- return { service, onStreamFailure, auditLogStreamOutboxDAL, auditLogStreamDAL };+ return { service, auditLogStreamOutboxDAL, auditLogStreamDAL };};-describe("audit-log-stream-outbox-service drainStream failure wiring", () => {+describe("audit-log-stream-outbox-service drainStream failure handling", () => {beforeEach(() => {vi.clearAllMocks();// Reset to the generous default; tests that need chunking override per-call.getProviderBatchLimit.mockReturnValue({ maxLogs: 1_000, maxBytes: 4 * 1024 * 1024 });});- test("invokes onStreamFailure with the truncated error message when the provider rejects", async () => {- const { service, onStreamFailure, auditLogStreamOutboxDAL } = createService();+ test("retries the failed row when the provider rejects the batch", 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(onStreamFailure).toHaveBeenCalledTimes(1);- expect(onStreamFailure).toHaveBeenCalledWith({- orgId: ORG_ID,- streamId: STREAM_ID,- provider: PROVIDER,- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment -- asymmetric matcher is typed `any`- errorMessage: expect.stringContaining(FAILURE_MESSAGE)- });expect(auditLogStreamOutboxDAL.commitDeliveryResult).toHaveBeenCalledTimes(1);const call = auditLogStreamOutboxDAL.commitDeliveryResult.mock.calls[0][0] as {successIds: number[];@@ -134,7 +123,7 @@ describe("audit-log-stream-outbox-service drainStream failure wiring", () => {});test("routes rows that hit MAX_ATTEMPTS to DLQ instead of retry", async () => {- const { service, onStreamFailure, auditLogStreamOutboxDAL } = createService();+ const { service, auditLogStreamOutboxDAL } = createService();// attempts=4 → attempts+1=5 hits MAX_ATTEMPTS so the row must go to DLQ.auditLogStreamOutboxDAL.claimBatchForStream@@ -144,7 +133,6 @@ describe("audit-log-stream-outbox-service drainStream failure wiring", () => {await service.drainStream({ streamId: STREAM_ID, orgId: ORG_ID, provider: PROVIDER });- expect(onStreamFailure).toHaveBeenCalledTimes(1);expect(auditLogStreamOutboxDAL.commitDeliveryResult).toHaveBeenCalledTimes(1);const call = auditLogStreamOutboxDAL.commitDeliveryResult.mock.calls[0][0] as {successIds: number[];@@ -157,15 +145,14 @@ describe("audit-log-stream-outbox-service drainStream failure wiring", () => {expect(call.exhausted[0].errorMessage).toEqual(expect.stringContaining(FAILURE_MESSAGE));});- test("does not invoke onStreamFailure on the success path", async () => {- const { service, onStreamFailure, auditLogStreamOutboxDAL } = createService();+ test("commits delivered rows on the success path", 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(onStreamFailure).not.toHaveBeenCalled();expect(auditLogStreamOutboxDAL.commitDeliveryResult).toHaveBeenCalledTimes(1);const call = auditLogStreamOutboxDAL.commitDeliveryResult.mock.calls[0][0] as {successIds: number[];@@ -289,7 +276,7 @@ describe("audit-log-stream-outbox-service drainStream single mode", () => {});test("retries only the row whose single-event send failed", async () => {- const { service, onStreamFailure, auditLogStreamOutboxDAL, auditLogStreamDAL } = createService();+ const { service, auditLogStreamOutboxDAL, auditLogStreamDAL } = createService();auditLogStreamDAL.findById.mockResolvedValue({id: STREAM_ID,@@ -307,7 +294,6 @@ describe("audit-log-stream-outbox-service drainStream single mode", () => {await service.drainStream({ streamId: STREAM_ID, orgId: ORG_ID, provider: LogProvider.Custom });- expect(onStreamFailure).toHaveBeenCalledTimes(1);const call = auditLogStreamOutboxDAL.commitDeliveryResult.mock.calls[0][0] as {successIds: number[];retriable: { groups: { ids: number[]; nextRetryDelayMs: number }[] } | null;diff --git a/backend/src/ee/services/audit-log-stream-outbox/audit-log-stream-outbox-service.ts b/backend/src/ee/services/audit-log-stream-outbox/audit-log-stream-outbox-service.tsindex a109ac06f7..36a3cbc489 100644--- a/backend/src/ee/services/audit-log-stream-outbox/audit-log-stream-outbox-service.ts+++ b/backend/src/ee/services/audit-log-stream-outbox/audit-log-stream-outbox-service.ts@@ -1,5 +1,3 @@-import { isAxiosError } from "axios";-import { TAuditLogs } from "@app/db/schemas";import { KeyStorePrefixes, TKeyStoreFactory } from "@app/keystore/keystore";import { logger } from "@app/lib/logger";@@ -56,8 +54,6 @@ const PROVIDER_QUEUE_MAP: Record<LogProvider, QueueName> = {[LogProvider.Splunk]: QueueName.AuditLogStreamSplunk};-const LAST_ERROR_MAX_LENGTH = 1_000;-const computeBackoffMs = (attemptsAfterIncrement: number): number => {const exponent = Math.min(attemptsAfterIncrement - 1, 10);const base = Math.min(BACKOFF_BASE_MS * 2 ** exponent, BACKOFF_MAX_MS);@@ -65,30 +61,12 @@ const computeBackoffMs = (attemptsAfterIncrement: number): number => {return base + jitter;};-const formatErrorMessage = (error: unknown): string => {- if (isAxiosError(error)) {- return `${error.message ?? "Request failed"} — ${JSON.stringify(error.response?.data ?? null)}`;- }- return (error as Error)?.message ?? "Unknown error";-};--const truncateError = (error: unknown): string => {- const message = formatErrorMessage(error);- return message.length > LAST_ERROR_MAX_LENGTH ? `${message.slice(0, LAST_ERROR_MAX_LENGTH)}...` : message;-};-export type TAuditLogStreamOutboxServiceFactoryDep = {auditLogStreamOutboxDAL: TAuditLogStreamOutboxDALFactory;auditLogStreamDAL: Pick<TAuditLogStreamDALFactory, "find" | "findById">;kmsService: Pick<TKmsServiceFactory, "createCipherPairWithDataKey">;keyStore: Pick<TKeyStoreFactory, "setItemWithExpiryNX">;queueService: TQueueServiceFactory;- onStreamFailure?: (input: {- orgId: string;- streamId: string;- provider: LogProvider;- errorMessage: string;- }) => Promise<void> | void;};export type TAuditLogStreamOutboxServiceFactory = {@@ -104,8 +82,7 @@ export const auditLogStreamOutboxServiceFactory = ({auditLogStreamDAL,kmsService,keyStore,- queueService,- onStreamFailure+ queueService}: TAuditLogStreamOutboxServiceFactoryDep): TAuditLogStreamOutboxServiceFactory => {// Try to win the 5s SETNX debounce for a stream and, on win, enqueue a delayed// flush job on the matching per-provider queue. Returning false means another@@ -247,7 +224,7 @@ export const auditLogStreamOutboxServiceFactory = ({}streamSuccess.push(...chunk);} catch (error) {- const errorMessage = truncateError(error);+ const errorMessage = (error as Error)?.message ?? "Unknown error";logger.error(error,`audit-log-stream-outbox: batch delivery failed [streamId=${streamId}] [orgId=${orgId}] [provider=${provider}] [chunkSize=${chunk.length}]: ${errorMessage}`@@ -289,13 +266,9 @@ export const auditLogStreamOutboxServiceFactory = ({});if (streamFail.length > 0) {- if (onStreamFailure) {- const representativeError = streamFail.at(-1)?.errorMessage ?? "Unknown error";- // eslint-disable-next-line no-await-in-loop- await Promise.resolve(onStreamFailure({ orgId, streamId, provider, errorMessage: representativeError }));- }-- // Bail when this claim saw any failure. The inner loop already attempted+ // Each failed chunk is already logged with its error above; the rows are+ // committed to 'retry'/DLQ by commitDeliveryResult. Bail when this claim+ // saw any failure. The inner loop already attempted// every chunk independently (so partial-success rows are committed// above), but hopping straight to the next claim risks compounding load// on a degraded endpoint — let backoff on the retriable rows govern