diff --git a/src/features/housekeeping/foundation/commands/audit-envelope.test.ts b/src/features/housekeeping/foundation/commands/audit-envelope.test.ts index b217773a..38ddad61 100644 --- a/src/features/housekeeping/foundation/commands/audit-envelope.test.ts +++ b/src/features/housekeeping/foundation/commands/audit-envelope.test.ts @@ -141,4 +141,24 @@ describe("audit command envelope", () => { runWithAuditIntent(writer, auditEntry, () => Promise.reject(original)), ).rejects.toBe(original); }); + it("preserves a pathological rejection when failure evidence rejects", async () => { + const { proxy, revoke } = Proxy.revocable( + new Error("operation failed"), + {}, + ); + revoke(); + const writer: HousekeepingAuditWriter = { + write: vi + .fn() + .mockResolvedValueOnce(undefined) + .mockRejectedValueOnce(new Error("audit failure")), + }; + let rejected: unknown; + try { + await runWithAuditIntent(writer, auditEntry, () => Promise.reject(proxy)); + } catch (error) { + rejected = error; + } + expect(rejected === proxy).toBe(true); + }); }); diff --git a/src/features/housekeeping/foundation/commands/audit-envelope.ts b/src/features/housekeeping/foundation/commands/audit-envelope.ts index 4a66db80..4de99baa 100644 --- a/src/features/housekeeping/foundation/commands/audit-envelope.ts +++ b/src/features/housekeeping/foundation/commands/audit-envelope.ts @@ -49,15 +49,15 @@ export async function runWithAuditIntent( try { await writeOutcome(writer, entry, "failure", transaction); } catch (auditOutcomeError) { - if (error instanceof Error) { - try { + try { + if (error instanceof Error) { Object.defineProperty(error, "auditOutcomeError", { value: auditOutcomeError, configurable: true, }); - } catch { - // Frozen or non-extensible errors still preserve their original identity. } + } catch { + // Enrichment is best-effort; always preserve the original rejection. } } throw error;