Skip to content

Potential fixes for 5 code quality findings#1614

Open
riderx wants to merge 7 commits intomainfrom
ai-findings-autofix/tests-password-policy.test.ts
Open

Potential fixes for 5 code quality findings#1614
riderx wants to merge 7 commits intomainfrom
ai-findings-autofix/tests-password-policy.test.ts

Conversation

@riderx
Copy link
Member

@riderx riderx commented Feb 10, 2026

This PR applies 5/5 suggestions from code quality AI findings.

Summary by CodeRabbit

  • Tests
    • Enhanced password policy test coverage with improved hash validation and error handling verification.

riderx and others added 5 commits February 10, 2026 13:47
…ofix

Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
…ofix

Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
…ofix

Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
…ofix

Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
…ofix

Co-authored-by: Copilot Autofix powered by AI <223894421+github-code-quality[bot]@users.noreply.github.com>
@riderx riderx marked this pull request as ready for review February 10, 2026 13:47
Copilot AI review requested due to automatic review settings February 10, 2026 13:47
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 10, 2026

📝 Walkthrough

Walkthrough

Refactors password policy test suite to compute policy hashes via RPC call get_password_policy_hash() instead of inline Base64 encoding. Adjusts error handling patterns, tightens HTTP status assertions from >= 400 to exact 400, and updates test titles.

Changes

Cohort / File(s) Summary
Password Policy Tests
tests/password-policy.test.ts
Replaces inline policy hash generation with RPC-based get_password_policy_hash(policy_config) calls across multiple tests. Streamlines error handling by removing intermediate error variables and throwing directly in finally blocks. Tightens HTTP status assertion in invalid JSON test case from >= 400 to 400. Updates test and describe block capitalization for consistency.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 Our tests hop with cleaner grace,
RPC calls now set the pace,
Hash by function, errors bright,
Status codes checked just right!
Policy tested, strong and true,

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Description check ⚠️ Warning The description is incomplete and largely missing required sections from the template. It only provides a brief reference to AI findings without covering Summary, Test plan, Screenshots, or Checklist sections. Complete the description by adding a Summary section explaining the changes, a Test plan with reproduction steps, and addressing all Checklist items as required by the template.
Title check ❓ Inconclusive The title is vague and generic, using a non-descriptive phrase 'Potential fixes for 5 code quality findings' that doesn't convey what changes are made or which aspects of the code are affected. Replace with a more specific title that describes the actual changes, e.g., 'Replace inline password policy hash generation with RPC calls' or 'Fix password policy test hash computation and error handling'.
✅ Passed checks (1 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ai-findings-autofix/tests-password-policy.test.ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
tests/password-policy.test.ts (2)

1-1: ⚠️ Potential issue | 🔴 Critical

Remove unused PostgrestError import — pipeline failure.

The CI pipeline reports TS6133: 'PostgrestError' is declared but its value is never read. This will block the build.

Proposed fix
-import type { PostgrestError } from '@supabase/supabase-js'

296-303: ⚠️ Potential issue | 🟠 Major

throw inside finally overwrites any exception from the try block.

If the test assertion in the try block fails and the restore also fails, the original test failure is silently swallowed. Both ESLint (no-unsafe-finally) and Biome flag this.

Consider logging or combining errors instead of a bare throw:

Proposed fix
    finally {
      const { error } = await getSupabaseClient()
        .from('orgs')
        .update({ password_policy_config: policyConfig })
        .eq('id', ORG_ID)
-     if (error)
-       throw error
+     if (error)
+       console.error('Failed to restore password policy after test:', error)
    }
🤖 Fix all issues with AI agents
In `@tests/password-policy.test.ts`:
- Around line 555-560: The type error comes from passing
org?.password_policy_config (which can be undefined) to
getSupabaseClient().rpc('get_password_policy_hash', { policy_config }) where
policy_config expects Json; fix by ensuring a Json is passed — e.g. replace
policy_config: org?.password_policy_config with policy_config:
(org?.password_policy_config ?? null) as unknown as Json (or import and use the
Json type and cast appropriately) so the rpc call receives a Json value.
- Line 54: The describe block titles start with an uppercase letter and violate
the test/prefer-lowercase-title rule; update the string arguments passed to the
describe calls (the one currently "Password Policy Configuration via SDK" and
the other at the later describe) so they start with a lowercase letter (e.g.,
"password policy configuration via SDK" and the similar lowercase variant for
the second describe) to satisfy the linter.

})

describe('password Policy Configuration via SDK', () => {
describe('Password Policy Configuration via SDK', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

describe title must begin with a lowercase letter.

ESLint rule test/prefer-lowercase-title flags this. Same issue on line 463.

Proposed fix
-describe('Password Policy Configuration via SDK', () => {
+describe('password Policy Configuration via SDK', () => {

Line 463:

-describe('Password Policy Enforcement Integration', () => {
+describe('password Policy Enforcement Integration', () => {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
describe('Password Policy Configuration via SDK', () => {
describe('password Policy Configuration via SDK', () => {
🧰 Tools
🪛 ESLint

[error] 54-54: describes should begin with lowercase

(test/prefer-lowercase-title)

🤖 Prompt for AI Agents
In `@tests/password-policy.test.ts` at line 54, The describe block titles start
with an uppercase letter and violate the test/prefer-lowercase-title rule;
update the string arguments passed to the describe calls (the one currently
"Password Policy Configuration via SDK" and the other at the later describe) so
they start with a lowercase letter (e.g., "password policy configuration via
SDK" and the similar lowercase variant for the second describe) to satisfy the
linter.

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

const policyHash = (rpcResult as string | null) ?? 'test_hash'
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Pipeline type error: Json | undefined is not assignable to Json.

org?.password_policy_config can be undefined when org is null, but the RPC parameter policy_config expects Json. The CI reports TS2322 on this line.

Proposed fix
-    const { data: rpcResult } = await getSupabaseClient().rpc('get_password_policy_hash', {
-      policy_config: org?.password_policy_config,
-    })
+    const policyConfig = org?.password_policy_config
+    if (!policyConfig) {
+      throw new Error('Expected org to have password_policy_config')
+    }
+    const { data: rpcResult } = await getSupabaseClient().rpc('get_password_policy_hash', {
+      policy_config: policyConfig,
+    })
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// Use the same RPC that production uses to compute the password policy hash
const { data: rpcResult } = await getSupabaseClient().rpc('get_password_policy_hash', {
policy_config: org?.password_policy_config,
})
const policyHash = (rpcResult as string | null) ?? 'test_hash'
// Use the same RPC that production uses to compute the password policy hash
const policyConfig = org?.password_policy_config
if (!policyConfig) {
throw new Error('Expected org to have password_policy_config')
}
const { data: rpcResult } = await getSupabaseClient().rpc('get_password_policy_hash', {
policy_config: policyConfig,
})
const policyHash = (rpcResult as string | null) ?? 'test_hash'
🧰 Tools
🪛 GitHub Actions: Run tests

[error] 557-557: vue-tsc --noEmit: TS2322: Type 'Json | undefined' is not assignable to type 'Json'.

🤖 Prompt for AI Agents
In `@tests/password-policy.test.ts` around lines 555 - 560, The type error comes
from passing org?.password_policy_config (which can be undefined) to
getSupabaseClient().rpc('get_password_policy_hash', { policy_config }) where
policy_config expects Json; fix by ensuring a Json is passed — e.g. replace
policy_config: org?.password_policy_config with policy_config:
(org?.password_policy_config ?? null) as unknown as Json (or import and use the
Json type and cast appropriately) so the rpc call receives a Json value.

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

This PR addresses code-quality findings by tightening and simplifying the password-policy test suite to better match production behavior and improve assertion strictness.

Changes:

  • Normalizes describe(...) titles capitalization for consistency.
  • Simplifies the “temporarily disable policy / restore policy” logic during /private/validate_password_compliance testing.
  • Makes tests use the production RPC (get_password_policy_hash) for computing the password policy hash and tightens an invalid-JSON status assertion.

Comment on lines 281 to 282
try {
const response = await fetch(`${BASE_URL}/private/validate_password_compliance`, {
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

PostgrestError is no longer referenced in this test after removing restoreError, so the type import at the top of the file is now unused and may fail lint/TS checks. Remove the unused import (or reintroduce a typed variable if still needed).

Copilot uses AI. Check for mistakes.
Comment on lines 296 to 303
finally {
const { error } = await getSupabaseClient()
.from('orgs')
.update({ password_policy_config: policyConfig })
.eq('id', ORG_ID)
restoreError = error ?? null
if (error)
throw error
}
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

Throwing inside this finally will override any failure thrown in the try block (e.g., assertion failures), which can mask the real test failure and make debugging harder. Consider capturing/propagating the original error and only failing the test due to restore failure when the main body succeeded (or log restore failure without replacing the original exception).

Copilot uses AI. Check for mistakes.
Comment on lines +555 to +560
// Use the same RPC that production uses to compute the password policy hash
const { data: rpcResult } = await getSupabaseClient().rpc('get_password_policy_hash', {
policy_config: org?.password_policy_config,
})

const policyHash = (rpcResult as string | null) ?? 'test_hash'
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

This RPC call ignores the returned error and falls back to 'test_hash' when rpcResult is null, which can make the test pass even if get_password_policy_hash is broken/permissioned incorrectly or org.password_policy_config is unexpectedly null. To ensure the test is actually validating the production hash path, assert error is null and that the RPC returns a non-null string (and consider failing if the org has no policy config rather than using a dummy hash).

Copilot uses AI. Check for mistakes.
@riderx
Copy link
Member Author

riderx commented Feb 10, 2026

@copilot test are filing fix them

Copy link
Contributor

Copilot AI commented Feb 10, 2026

@riderx I've opened a new pull request, #1616, to work on those changes. Once the pull request is ready, I'll request review from you.

@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