|
1 | 1 | import { describe, expect, it } from "@effect/vitest"; |
2 | 2 | import type { AuthTemplateEditorValue } from "@executor-js/react/components/auth-template-editor"; |
3 | 3 |
|
| 4 | +import { parseMcpIntegrationConfig } from "../sdk/types"; |
4 | 5 | import { |
5 | 6 | authMethodsFromConfig, |
6 | 7 | editorValueFromMcpAuthMethod, |
@@ -86,6 +87,35 @@ describe("mcpAuthMethodInputFromEditorValue", () => { |
86 | 87 | }); |
87 | 88 | }); |
88 | 89 |
|
| 90 | +describe("a stored oauth2 row's scope list", () => { |
| 91 | + const storedConfig = (method: Record<string, unknown>) => ({ |
| 92 | + transport: "remote", |
| 93 | + endpoint: "https://mcp.example.com/mcp", |
| 94 | + authenticationTemplate: [method], |
| 95 | + }); |
| 96 | + |
| 97 | + it("decodes whether the key is declared or absent", () => { |
| 98 | + expect( |
| 99 | + parseMcpIntegrationConfig(storedConfig({ slug: "oauth2", kind: "oauth2" })), |
| 100 | + ).not.toBeNull(); |
| 101 | + expect( |
| 102 | + parseMcpIntegrationConfig(storedConfig({ slug: "oauth2", kind: "oauth2", scopes: ["mcp"] })), |
| 103 | + ).not.toBeNull(); |
| 104 | + }); |
| 105 | + |
| 106 | + it("fails the WHOLE config when the row stores an empty list", () => { |
| 107 | + // `scopes` is a NonEmptyArray, so `[]` is not "declares no scopes" — it is |
| 108 | + // an invalid row. Decoding is all-or-nothing: one such row does not |
| 109 | + // degrade to a scope-less oauth method, it makes the entire integration |
| 110 | + // config undecodable, and the integration then presents no auth method at |
| 111 | + // all. That is the whole reason the editor codec omits the key rather than |
| 112 | + // writing `[]`; this test is here so the constraint is not invisible. |
| 113 | + expect( |
| 114 | + parseMcpIntegrationConfig(storedConfig({ slug: "oauth2", kind: "oauth2", scopes: [] })), |
| 115 | + ).toBeNull(); |
| 116 | + }); |
| 117 | +}); |
| 118 | + |
89 | 119 | describe("editorValueFromMcpAuthMethod", () => { |
90 | 120 | it("round-trips an apikey method, making the shared token variable explicit", () => { |
91 | 121 | expect( |
|
0 commit comments