-
Notifications
You must be signed in to change notification settings - Fork 11
fix(install): configure and verify AuthKit application URLs #244
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
Open
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| import { beforeEach, describe, expect, it, vi } from 'vitest'; | ||
| import type { FrameworkConfig } from './framework-config.js'; | ||
| import type { InstallerOptions } from '../utils/types.js'; | ||
|
|
||
| vi.mock('./skills-assets.js', () => ({ getReference: vi.fn() })); | ||
| vi.mock('./agent-interface.js', () => ({ initializeAgent: vi.fn(), runAgent: vi.fn() })); | ||
| vi.mock('./validation/index.js', () => ({ validateInstallation: vi.fn(), quickCheckValidateAndFormat: vi.fn() })); | ||
| vi.mock('./validation/security-checks.js', () => ({ | ||
| runInstallSecurityChecks: vi.fn(async () => ({ findings: [], blocking: [] })), | ||
| securityFindingsToIssues: vi.fn(() => []), | ||
| formatSecurityFindingsForAgent: vi.fn(() => ''), | ||
| })); | ||
| vi.mock('../steps/index.js', () => ({})); | ||
| vi.mock('./workos-management.js', () => ({})); | ||
| vi.mock('./env-writer.js', () => ({})); | ||
| vi.mock('../utils/ui-utils.js', () => ({ | ||
| ensurePackageIsInstalled: vi.fn(), | ||
| getOrAskForWorkOSCredentials: vi.fn(async () => ({ apiKey: 'test-key', clientId: 'client_test' })), | ||
| getPackageDotJson: vi.fn(async () => ({ dependencies: { next: '16.3.5' } })), | ||
| isUsingTypeScript: vi.fn(() => true), | ||
| })); | ||
| vi.mock('../utils/analytics.js', () => ({ | ||
| analytics: { setTag: vi.fn(), capture: vi.fn(), shutdown: vi.fn() }, | ||
| })); | ||
|
|
||
| import { getReference } from './skills-assets.js'; | ||
| import { initializeAgent, runAgent } from './agent-interface.js'; | ||
| import { runAgentInstaller } from './agent-runner.js'; | ||
| import { validateInstallation, quickCheckValidateAndFormat } from './validation/index.js'; | ||
|
|
||
| const options: InstallerOptions = { | ||
| debug: false, | ||
| forceInstall: false, | ||
| installDir: '/tmp/test-authkit-app', | ||
| local: false, | ||
| ci: true, | ||
| skipAuth: true, | ||
| clientId: 'client_test', | ||
| noValidate: true, | ||
| }; | ||
|
|
||
| const config: FrameworkConfig = { | ||
| metadata: { | ||
| name: 'Next.js', | ||
| integration: 'nextjs', | ||
| skillName: 'workos-authkit-nextjs', | ||
| language: 'javascript', | ||
| docsUrl: 'https://workos.com/docs/authkit/nextjs', | ||
| stability: 'stable', | ||
| priority: 100, | ||
| }, | ||
| detection: { packageName: 'next', packageDisplayName: 'Next.js', getVersion: () => '16.3.5' }, | ||
| environment: { requiresApiKey: true, uploadToHosting: false, getEnvVars: () => ({}) }, | ||
| analytics: { getTags: () => ({}) }, | ||
| prompts: { getAdditionalContextLines: () => ['Router: app'] }, | ||
| ui: { successMessage: 'Installed', getOutroChanges: () => [], getOutroNextSteps: () => [] }, | ||
| }; | ||
|
|
||
| const setupContent = 'Configure and read back Sign-out URI and Initiate login URI. Report unverified flows.'; | ||
|
|
||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| vi.mocked(getReference).mockImplementation(async (name) => { | ||
| if (name === 'workos-authkit-setup') return setupContent; | ||
| return `Instructions from ${name}`; | ||
| }); | ||
| vi.mocked(runAgent).mockResolvedValue({}); | ||
| vi.mocked(quickCheckValidateAndFormat).mockResolvedValue(null); | ||
| vi.mocked(validateInstallation).mockResolvedValue({ passed: true, framework: 'nextjs', issues: [], durationMs: 0 }); | ||
| }); | ||
|
|
||
| describe('installer prompt', () => { | ||
| it.each(['javascript', 'php'] as const)('injects shared application setup for %s integrations', async (language) => { | ||
| const framework = { | ||
| ...config, | ||
| metadata: { | ||
| ...config.metadata, | ||
| language, | ||
| integration: language === 'javascript' ? 'nextjs' : 'php', | ||
| skillName: language === 'javascript' ? 'workos-authkit-nextjs' : 'workos-php', | ||
| }, | ||
| }; | ||
| await runAgentInstaller(framework, options); | ||
|
|
||
| const prompt = vi.mocked(runAgent).mock.calls[0][1]; | ||
| expect(getReference).toHaveBeenCalledWith('workos-authkit-setup'); | ||
| expect(prompt).toContain(setupContent); | ||
| expect(prompt).toContain(`Instructions from ${framework.metadata.skillName}`); | ||
| expect(prompt).toContain('Router: app'); | ||
| expect(prompt).not.toContain('test-key'); | ||
| if (language === 'javascript') { | ||
| expect(prompt).toContain('NEXT_PUBLIC_WORKOS_REDIRECT_URI'); | ||
| expect(prompt).toContain('Instructions from workos-authkit-base'); | ||
| } else { | ||
| expect(prompt).toContain('WORKOS_REDIRECT_URI'); | ||
| expect(prompt).not.toContain('NEXT_PUBLIC_WORKOS_REDIRECT_URI'); | ||
| expect(getReference).not.toHaveBeenCalledWith('workos-authkit-base'); | ||
| } | ||
| }); | ||
|
|
||
| it('blocks success when an application route is still missing after retries', async () => { | ||
| vi.mocked(validateInstallation).mockResolvedValue({ | ||
| passed: false, | ||
| framework: 'nextjs', | ||
| durationMs: 0, | ||
| issues: [{ type: 'file', severity: 'error', message: 'Missing sign-in route', hint: 'Create /sign-in' }], | ||
| }); | ||
| await expect(runAgentInstaller(config, { ...options, noValidate: false })).rejects.toThrow('Missing sign-in route'); | ||
| const retry = vi.mocked(runAgent).mock.calls[0][5]; | ||
| expect(await retry!.validateAndFormat(options.installDir)).toContain('Create /sign-in'); | ||
| }); | ||
|
|
||
| it('does not start the agent when the bundled setup reference is missing', async () => { | ||
| vi.mocked(getReference).mockImplementation(async (name) => { | ||
| if (name === 'workos-authkit-setup') throw new Error('Missing bundled setup reference'); | ||
| return `Instructions from ${name}`; | ||
| }); | ||
|
|
||
| await expect(runAgentInstaller(config, options)).rejects.toThrow('Missing bundled setup reference'); | ||
| expect(initializeAgent).not.toHaveBeenCalled(); | ||
| expect(runAgent).not.toHaveBeenCalled(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Pages Router is a supported and detected Next.js mode, but this instruction always tells the agent to create an App Router
/sign-inroute. The new validation rule also accepts only{,src/}app/sign-in/route.*, so a correct Pages Router implementation is rejected and the installation fails, or the agent must add an unwanted App Router tree. Please make the prompt and validation depend on the detected router and support the equivalent Pages Router route.Knowledge Base Used:
Prompt To Fix With AI