-
-
Notifications
You must be signed in to change notification settings - Fork 386
fix(keys): preserve last-enabled-key error code #1393
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 all commits
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 |
|---|---|---|
|
|
@@ -505,7 +505,7 @@ export async function editKey( | |
| return { | ||
| ok: false, | ||
| error: tError("CANNOT_DISABLE_LAST_KEY"), | ||
| errorCode: ERROR_CODES.OPERATION_FAILED, | ||
| errorCode: ERROR_CODES.CANNOT_DISABLE_LAST_KEY, | ||
| }; | ||
| } | ||
| } | ||
|
|
@@ -1263,7 +1263,7 @@ export async function toggleKeyEnabled(keyId: number, enabled: boolean): Promise | |
| return { | ||
| ok: false, | ||
| error: tError("CANNOT_DISABLE_LAST_KEY"), | ||
| errorCode: ERROR_CODES.OPERATION_FAILED, | ||
| errorCode: ERROR_CODES.CANNOT_DISABLE_LAST_KEY, | ||
|
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.
When a dashboard user tries to disable their last enabled key, the REST handler replaces the translated action message with the generic Useful? React with 👍 / 👎. |
||
| }; | ||
| } | ||
| } | ||
|
|
@@ -1418,7 +1418,7 @@ export async function batchUpdateKeys( | |
| if (currentEnabledCount - disableCount < 1) { | ||
| throw new BatchUpdateError( | ||
| tError("CANNOT_DISABLE_LAST_KEY"), | ||
| ERROR_CODES.OPERATION_FAILED | ||
| ERROR_CODES.CANNOT_DISABLE_LAST_KEY | ||
|
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.
The two changed batch-disable guards now return Knowledge Base Used: Management API (/api/v1) Prompt To Fix With AIThis is a comment left during a code review.
Path: src/actions/keys.ts
Line: 1421
Comment:
**Cover batch error-code branches**
The two changed batch-disable guards now return `CANNOT_DISABLE_LAST_KEY`, but the added regressions exercise only `toggleKeyEnabled`. Add coverage for both batch guards so a future change cannot collapse their codes back to `OPERATION_FAILED` while the suite continues to pass.
**Knowledge Base Used:** [Management API (/api/v1)](https://app.greptile.com/ygxz/-/custom-context/knowledge-base/ding113/claude-code-hub/-/docs/management-api.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Contributor
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. [High] [TEST-MISSING-CRITICAL] The batch-disable error-code changes are still untested Why this is a problem: Both batch guards in this PR were switched from Suggested fix: const result = await batchUpdateKeys({
keyIds: [42],
updates: { isEnabled: false },
});
expect(result).toMatchObject({
ok: false,
errorCode: "CANNOT_DISABLE_LAST_KEY",
});Add one test that makes |
||
| ); | ||
| } | ||
| } | ||
|
|
@@ -1478,7 +1478,7 @@ export async function batchUpdateKeys( | |
| if (Number(remainingEnabled?.count ?? 0) < 1) { | ||
| throw new BatchUpdateError( | ||
| tError("CANNOT_DISABLE_LAST_KEY"), | ||
| ERROR_CODES.OPERATION_FAILED | ||
| ERROR_CODES.CANNOT_DISABLE_LAST_KEY | ||
| ); | ||
| } | ||
| } | ||
|
|
||
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.
[High] [TEST-MISSING-CRITICAL] The PATCH disable path still has no regression asserting the new machine-readable code
Why this is a problem: This line changed from
ERROR_CODES.OPERATION_FAILEDtoERROR_CODES.CANNOT_DISABLE_LAST_KEY, but the existing PATCH coverage still only checksexpect(result.error).toBe("CANNOT_DISABLE_LAST_KEY");. IferrorCoderegresses toOPERATION_FAILED, the suite stays green while the client falls back to the generic toast again. That misses the CLAUDE.md rule:All new features must have unit test coverage of at least 80%.Suggested fix: