-
Notifications
You must be signed in to change notification settings - Fork 3.8k
fix(okta): describe each user param the way its endpoint accepts it #7307
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
Merged
Merged
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
Large diffs are not rendered by default.
Oops, something went wrong.
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
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
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
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,112 @@ | ||
| /** | ||
| * @vitest-environment node | ||
| */ | ||
| import { describe, expect, it, vi } from 'vitest' | ||
| import { tools as toolRegistry } from '@/tools/registry' | ||
| import type { ToolConfig } from '@/tools/types' | ||
|
|
||
| /** | ||
| * Uses the real tool registry: these assertions are about registered Okta tool | ||
| * params, which the global `@/tools/registry` mock in vitest.setup.ts empties. | ||
| */ | ||
| vi.unmock('@/tools/registry') | ||
|
|
||
| /** | ||
| * Okta's Management API spec (`okta/okta-management-openapi-spec`, | ||
| * `dist/2026.08.1/management-oneOfInheritance-noExamples.yaml`) distinguishes | ||
| * two user path parameters: | ||
| * | ||
| * - `pathId` — "An ID, login, or login shortname (as long as the shortname is | ||
| * unambiguous) of an existing Okta user". Used by `/api/v1/users/{id}` and | ||
| * every `/api/v1/users/{id}/lifecycle/*` operation. | ||
| * - `pathUserId` / `pathAppUserId` — "ID of an existing Okta user". Used by | ||
| * `/api/v1/users/{userId}/factors`, `/roles`, `/sessions`, and by the | ||
| * group- and app-membership paths. | ||
| * | ||
| * The `userId` param on every Okta tool is `user-or-llm`, so its description is | ||
| * the only thing a model reads before choosing what to pass. Advertising a | ||
| * login on a `pathUserId` endpoint produces a 404; withholding it on a `pathId` | ||
| * endpoint makes the model resolve an ID it never needed. | ||
| */ | ||
| const USER_SENTINEL = 'SIM-USER-SENTINEL' | ||
|
|
||
| /** The `{id}` positions Okta documents as ID-, login-, or shortname-addressable. */ | ||
| const LOGIN_CAPABLE_PATH = new RegExp(`^/api/v1/users/${USER_SENTINEL}(?:/lifecycle/[^/]+)?/?$`) | ||
|
|
||
| const AUTH_PARAMS: Record<string, unknown> = { | ||
| apiKey: 'token', | ||
| domain: 'dev-123456.okta.com', | ||
| } | ||
|
|
||
| interface OktaUserTool { | ||
| id: string | ||
| description: string | ||
| pathname: string | ||
| } | ||
|
|
||
| /** Fills every declared param so a declarative `url` builder can run. */ | ||
| function sentinelParams(tool: ToolConfig): Record<string, unknown> { | ||
| const params: Record<string, unknown> = { ...AUTH_PARAMS } | ||
| for (const [name, schema] of Object.entries(tool.params ?? {})) { | ||
| if (name in params) continue | ||
| if (name === 'userId') { | ||
| params[name] = USER_SENTINEL | ||
| continue | ||
| } | ||
| params[name] = schema.type === 'number' ? 1 : schema.type === 'boolean' ? false : `sim-${name}` | ||
| } | ||
| return params | ||
| } | ||
|
|
||
| /** | ||
| * Calls a declarative `url` builder with the untyped shape a tool really | ||
| * receives — the typed params interface is erased at the call boundary. | ||
| */ | ||
| function builtUrl(tool: ToolConfig): string { | ||
| const build = tool.request?.url | ||
| if (typeof build !== 'function') throw new Error(`${tool.id} has no url builder`) | ||
| return build(sentinelParams(tool) as never) | ||
| } | ||
|
|
||
| const oktaUserTools: OktaUserTool[] = Object.values(toolRegistry) | ||
| .filter((tool): tool is ToolConfig => Boolean(tool?.id?.startsWith('okta_'))) | ||
| .filter((tool) => Boolean(tool.params?.userId)) | ||
| .map((tool) => ({ | ||
| id: tool.id, | ||
| description: tool.params.userId.description ?? '', | ||
| pathname: new URL(builtUrl(tool)).pathname, | ||
| })) | ||
|
|
||
| /** | ||
| * A description advertises a login when it offers a login or an email as an | ||
| * accepted value. A negated clause ("not a login or email") withholds one, so | ||
| * it is stripped before the check — otherwise the warning an ID-only tool | ||
| * carries would read as the promise it exists to deny. | ||
| */ | ||
| function advertisesLogin(description: string): boolean { | ||
| const affirmative = description.replace(/\bnot an? [^.)]*/gi, '') | ||
| return /\blogins?\b|\bemail\b/i.test(affirmative) | ||
| } | ||
|
|
||
| describe('okta user path param descriptions', () => { | ||
| it('finds Okta tools carrying a userId param', () => { | ||
| expect(oktaUserTools.length).toBeGreaterThan(15) | ||
| }) | ||
|
|
||
| it('covers both Okta path-parameter kinds', () => { | ||
| const loginCapable = oktaUserTools.filter((tool) => LOGIN_CAPABLE_PATH.test(tool.pathname)) | ||
| expect(loginCapable.length).toBeGreaterThan(0) | ||
| expect(oktaUserTools.length - loginCapable.length).toBeGreaterThan(0) | ||
| }) | ||
|
|
||
| it.each(oktaUserTools.map((tool) => [tool.id, tool] as const))( | ||
| '%s describes userId the way its endpoint accepts it', | ||
| (_id, tool) => { | ||
| const loginCapable = LOGIN_CAPABLE_PATH.test(tool.pathname) | ||
| expect({ | ||
| pathname: tool.pathname, | ||
| advertisesLogin: advertisesLogin(tool.description), | ||
| }).toEqual({ pathname: tool.pathname, advertisesLogin: loginCapable }) | ||
| } | ||
| ) | ||
| }) |
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.
Uh oh!
There was an error while loading. Please reload this page.