Repository navigation
Assert on silenced console output instead of blanket-suppressing it #722
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,12 +16,17 @@ import { createPasswordHash } from '@kody-internal/shared/password-hash.ts' | |
|
|
||
| // The handlers fire `void logAuditEvent(...)` without awaiting it; those | ||
| // promises can resolve after the test ends and leak `audit-event` lines into | ||
| // the runner output once the console spies are restored. Stub the audit sink. | ||
| // the runner output once the console spies are restored. Route the sink to a | ||
| // spy so the expected audit events are asserted instead of silently dropped. | ||
| const auditSpy = vi.hoisted(() => ({ | ||
| logAuditEvent: vi.fn(async () => undefined), | ||
| })) | ||
|
|
||
| vi.mock('#app/audit-log.ts', async (importOriginal) => { | ||
| const actual = await importOriginal<typeof import('#app/audit-log.ts')>() | ||
| return { | ||
| ...actual, | ||
| logAuditEvent: async () => undefined, | ||
| logAuditEvent: (...args: Array<unknown>) => auditSpy.logAuditEvent(...args), | ||
| } | ||
| }) | ||
|
|
||
|
|
@@ -312,6 +317,14 @@ test('github sign-in creates a verified account, then signs it back in', async ( | |
| ) | ||
| .get() as Record<string, unknown> | ||
| expect(connection.user_id).toBe(user.id) | ||
| expect(auditSpy.logAuditEvent).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| category: 'auth', | ||
| action: 'oauth_signup', | ||
| result: 'success', | ||
| reason: 'provider=github', | ||
| }), | ||
| ) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟠 Major | ⚡ Quick win Add Same gap as 🔧 Proposed additions // Lines 320-327 — oauth_signup
+expect(auditSpy.logAuditEvent).toHaveBeenCalledTimes(1)
expect(auditSpy.logAuditEvent).toHaveBeenCalledWith(
expect.objectContaining({
category: 'auth',
action: 'oauth_signup',
result: 'success',
reason: 'provider=github',
}),
)
// Lines 354-361 — oauth_login
+expect(auditSpy.logAuditEvent).toHaveBeenCalledTimes(1)
expect(auditSpy.logAuditEvent).toHaveBeenCalledWith(
expect.objectContaining({
category: 'auth',
action: 'oauth_login',
result: 'success',
reason: 'provider=github',
}),
)Also applies to: 354-361 🤖 Prompt for AI Agents |
||
|
|
||
| // A second sign-in with the same provider identity reuses the account. | ||
| const secondStart = await startProviderFlow( | ||
|
|
@@ -338,6 +351,14 @@ test('github sign-in creates a verified account, then signs it back in', async ( | |
| .prepare(`SELECT COUNT(*) AS count FROM users`) | ||
| .get() as { count: number } | ||
| expect(userCount.count).toBe(1) | ||
| expect(auditSpy.logAuditEvent).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| category: 'auth', | ||
| action: 'oauth_login', | ||
| result: 'success', | ||
| reason: 'provider=github', | ||
| }), | ||
| ) | ||
| }) | ||
|
|
||
| test('google sign-in links a matching verified email to the existing account', async () => { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Add
toHaveBeenCalledTimesassertions to match the pattern in other handler tests.All four assertion blocks use only
toHaveBeenCalledWithwithouttoHaveBeenCalledTimes. This means extra unexpected audit events would pass silently — the exact regression class this PR aims to prevent. Theaccount-profileandaccount-resend-verificationtests correctly pair both assertions; this file should follow suit.For the signup-success case (lines 416-430), the expected count is 2 (signup + invite_use). For the login-failure (378-385), login-success (535-542), and signup-failure (582-588) cases, the expected count is 1 each.
🔧 Proposed additions
Also applies to: 416-430, 535-542, 582-588
🤖 Prompt for AI Agents