mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-15 21:05:51 +00:00
Four inline + one outside-diff actionable comment from the second CodeRabbit review on claude-code-best/claude-code#386: - tests/mocks/auth.ts: align mock return contracts with src/utils/auth.ts. checkAndRefreshOAuthTokenIfNeeded resolves to a Promise<boolean> and getClaudeAIOAuthTokens returns the full token shape (refreshToken, expiresAt, scopes, subscriptionType, rateLimitTier) so tests that branch on these values can not silently drift away from production. - src/utils/handlePromptSubmit.ts (461-468): clear the freshly-published abortController before the early return when every claimed autonomy command was skipped as non-consumable, so this turn's stale controller does not leak into the next turn. - src/utils/handlePromptSubmit.ts (621-649): separate execution failure from finalizer failure. The turn body now writes to a `turnError` slot; a single pass after the inner try decides whether to finalize claimed commands as `completed` or `failed`, with each finalize call wrapped in its own try/catch so a failure inside finalize does not flip a successful turn into `failed` and double-finalize the same commands. The outer catch only rethrows the original turn error. - src/utils/processUserInput/processSlashCommand.tsx (228-276): wrap the post-success `finalizeDeferredAutonomyRunCompleted()` call in its own try/catch so a finalize failure no longer falls into the worker-failure catch path and emits a contradictory `<scheduled-task-result status="failed">` for a slash command that actually succeeded. Outside scope (not changed) — the CodeRabbit suggestion to add a `.ts` extension to the shared `tests/mocks/auth` import contradicts the project's existing convention: every other test imports the shared mocks without the extension (e.g. `tests/mocks/log`, `tests/mocks/debug`, `tests/mocks/file-system`), and the project's tsconfig does not enable `allowImportingTsExtensions`, so adding the extension fails typecheck. The import is kept extension-less to match the rest of the suite. Validation: - bun run typecheck (clean). - bun test → 3996 pass / 0 fail across 305 test files.
32 lines
1.2 KiB
TypeScript
32 lines
1.2 KiB
TypeScript
/**
|
|
* Shared mock for `src/utils/auth.js`. Use it via:
|
|
*
|
|
* import { authMock } from '../../tests/mocks/auth'
|
|
* mock.module('src/utils/auth.js', authMock)
|
|
*
|
|
* Tests that need different return values can override the helper used by
|
|
* the suite (e.g. by extending this object and re-registering with mock.module).
|
|
* Always extend here rather than inlining a different shape per test, so the
|
|
* surface stays consistent when `auth.ts` exports change.
|
|
*/
|
|
export const authMock = () => ({
|
|
// Mirrors the production contract: src/utils/auth.ts returns
|
|
// Promise<boolean> ("did the access token change") and a token object that
|
|
// carries scopes, subscriptionType, expiresAt, etc. Tests that branch on
|
|
// these values must see the full shape so they can not silently drift away
|
|
// from production.
|
|
checkAndRefreshOAuthTokenIfNeeded: async () => false,
|
|
getClaudeAIOAuthTokens: () => ({
|
|
accessToken: 'token',
|
|
refreshToken: null,
|
|
expiresAt: null,
|
|
scopes: ['user:inference'],
|
|
subscriptionType: null,
|
|
rateLimitTier: null,
|
|
}),
|
|
isClaudeAISubscriber: () => true,
|
|
isProSubscriber: () => false,
|
|
isMaxSubscriber: () => false,
|
|
isTeamSubscriber: () => false,
|
|
})
|