Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Feb 10, 2026

Summary

Fixed three error handling issues in password policy tests identified by code review that could mask test failures or hide broken production paths.

Changes:

  • Removed unused import: PostgrestError type no longer referenced after refactoring
  • Fixed finally block error masking: Test errors now preserved during cleanup operations
    let testError: Error | null = null
    try {
      // test assertions
    }
    catch (error) {
      testError = error as Error
    }
    finally {
      // cleanup, then re-throw original error if any
    }
  • Added RPC validation: get_password_policy_hash errors now fail tests instead of silently falling back to dummy hash

Test plan

  • Verify tests pass in CI
  • Verify test failures in try block are not masked by cleanup errors
  • Verify broken RPC calls fail tests instead of using fallback values

Screenshots

N/A - backend test changes only

Checklist

  • My code follows the code style of this project and passes
    bun run lint:backend && bun run lint.
  • My change requires a change to the documentation.
  • I have updated the documentation
    accordingly.
  • My change has adequate E2E test coverage.
  • I have tested my code manually, and I have provided steps how to reproduce
    my tests

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

- Remove unused PostgrestError import
- Fix finally block to preserve test errors
- Add proper error validation for RPC call

Co-authored-by: riderx <4084527+riderx@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix code quality findings from AI suggestions fix: address test error handling in password policy tests Feb 10, 2026
Copilot AI requested a review from riderx February 10, 2026 14:17
@riderx riderx marked this pull request as ready for review February 11, 2026 03:48
Copilot AI review requested due to automatic review settings February 11, 2026 03:48
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the password policy test suite to avoid masking failures during cleanup and to validate production RPC paths more strictly, improving reliability of backend integration tests.

Changes:

  • Removed an unused PostgrestError type import.
  • Refactored a test to preserve assertion failures while still performing cleanup in finally.
  • Added explicit validation of get_password_policy_hash RPC results (fail fast on RPC errors / null results).

Comment on lines 299 to +309
finally {
const { error } = await getSupabaseClient()
const { error: restoreError } = await getSupabaseClient()
.from('orgs')
.update({ password_policy_config: policyConfig })
.eq('id', ORG_ID)
if (error)
throw error

// If restore failed, throw it (but preserve test failure if there was one)
if (restoreError) {
if (testError)
throw new Error(`Test failed AND restore failed: ${testError.message} | Restore error: ${restoreError.message}`)
throw restoreError
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The finally block can still mask the original test failure if the restore update(...) call rejects/throws (network/client exception) before restoreError is checked. Consider wrapping the restore operation in its own try/catch and, when both the test and restore fail, throw an AggregateError (or use Error with cause) so the original assertion stack trace is preserved instead of replacing it with a new Error built from messages.

Copilot uses AI. Check for mistakes.
Comment on lines +567 to +577
expect(orgError).toBeNull()
expect(org?.password_policy_config).not.toBeNull()

// Use the same RPC that production uses to compute the password policy hash
const { data: rpcResult } = await getSupabaseClient().rpc('get_password_policy_hash', {
const { data: rpcResult, error: rpcError } = await getSupabaseClient().rpc('get_password_policy_hash', {
policy_config: org?.password_policy_config,
})

const policyHash = (rpcResult as string | null) ?? 'test_hash'
expect(rpcError).toBeNull()
expect(rpcResult).not.toBeNull()
expect(typeof rpcResult).toBe('string')
Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expect(org?.password_policy_config).not.toBeNull() and expect(rpcResult).not.toBeNull() will still pass when the value is undefined (because undefined !== null). Use an assertion that also rejects undefined (e.g., assert org is truthy and then access org.password_policy_config, and assert rpcResult is defined/string) so the test fails at the right place with a clear signal.

Copilot uses AI. Check for mistakes.
Comment on lines +304 to +311

// If restore failed, throw it (but preserve test failure if there was one)
if (restoreError) {
if (testError)
throw new Error(`Test failed AND restore failed: ${testError.message} | Restore error: ${restoreError.message}`)
throw restoreError
}

Copy link

Copilot AI Feb 11, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are blank lines containing trailing whitespace (e.g., around the restore block). Please remove the trailing spaces to avoid formatter/lint churn in future diffs.

Suggested change
// If restore failed, throw it (but preserve test failure if there was one)
if (restoreError) {
if (testError)
throw new Error(`Test failed AND restore failed: ${testError.message} | Restore error: ${restoreError.message}`)
throw restoreError
}
// If restore failed, throw it (but preserve test failure if there was one)
if (restoreError) {
if (testError)
throw new Error(`Test failed AND restore failed: ${testError.message} | Restore error: ${restoreError.message}`)
throw restoreError
}

Copilot uses AI. Check for mistakes.
@sonarqubecloud
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants