Skip to content

test(auth): add unit tests for JwtValidator#10

Draft
Psyborgs-git wants to merge 8 commits intomainfrom
add-jwt-validator-tests-12249440911468361910
Draft

test(auth): add unit tests for JwtValidator#10
Psyborgs-git wants to merge 8 commits intomainfrom
add-jwt-validator-tests-12249440911468361910

Conversation

@Psyborgs-git
Copy link
Owner

This PR adds unit tests for JwtValidator in packages/auth.

It includes:

  • A new test file packages/auth/src/jwt.test.ts.
  • Tests for happy path validation, caching, and error handling (missing issuer, unknown provider, missing sub, expired token).
  • Mocks for jose library and JwtProviderManager.
  • Fix for root package.json to include vitest in devDependencies, enabling pnpm test to run.

This addresses the "Missing Tests for JWT Validator" task and improves overall testability.


PR created automatically by Jules for task 12249440911468361910 started by @Psyborgs-git

- Added comprehensive tests for `JwtValidator` in `packages/auth/src/jwt.test.ts`.
- Mocked `jose` and `JwtProviderManager` to isolate tests.
- Added `vitest` to root `devDependencies` to fix test execution.
- Verified tests pass and catch regressions.

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@google-labs-jules
Copy link
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

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 adds comprehensive unit tests for the JwtValidator class in the @orch/auth package, improving testability and ensuring the JWT validation logic works correctly across various scenarios.

Changes:

  • Added packages/auth/src/jwt.test.ts with 9 test cases covering happy path, error handling, caching, and edge cases
  • Added vitest ^3.2.4 to root package.json devDependencies to enable running tests from the workspace root
  • Updated pnpm-lock.yaml to reflect the new vitest dependency and its transitive dependencies

Reviewed changes

Copilot reviewed 3 out of 4 changed files in this pull request and generated 5 comments.

File Description
packages/auth/src/jwt.test.ts New test file with comprehensive unit tests for JwtValidator including mocking of jose library and JwtProviderManager
package.json Added vitest ^3.2.4 to root devDependencies for workspace-level test execution
pnpm-lock.yaml Lockfile updates reflecting vitest addition and dependency resolution changes
packages/shared/tsconfig.tsbuildinfo Build artifact update from TypeScript compilation with updated dependencies
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +95 to +107
it('should throw AUTH_FAILED if provider is not found', async () => {
vi.mocked(jose.decodeJwt).mockReturnValue({ iss: 'unknown-issuer' });
vi.mocked(mockProviderManager.findByIssuer).mockReturnValue(undefined);

await expect(validator.validate(validToken)).rejects.toThrow(OrchestratorError);
await expect(validator.validate(validToken)).rejects.toThrow('is not a registered provider');

try {
await validator.validate(validToken);
} catch (err: any) {
expect(err.code).toBe(ErrorCode.AUTH_FAILED);
}
});
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

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

This test calls validator.validate(validToken) three times (lines 99, 100, and 103), which is inefficient and could potentially mask issues. Consider restructuring the test to call the validation method only once and make all assertions on the caught error, similar to the pattern used in other error tests in this file (e.g., lines 172-179).

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,209 @@
import { describe, it, expect, beforeEach, vi, type Mock } from 'vitest';
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

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

This test file is missing a header comment describing its purpose. Other test files in this package include a header comment following the pattern: /** * Tests for @orch/auth/[module] — [description] */. Consider adding a similar header comment at the top of this file for consistency.

Copilot uses AI. Check for mistakes.
@Psyborgs-git
Copy link
Owner Author

@copilot open a new pull request to apply changes based on the comments in this thread

Copy link
Contributor

Copilot AI commented Feb 26, 2026

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

Copilot AI and others added 6 commits February 26, 2026 04:17
Co-authored-by: Psyborgs-git <49641518+Psyborgs-git@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
test(auth): address review comments on JwtValidator unit tests
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.

3 participants