+36
![github-actions[bot]](/assets/img/avatar_default.png)








Julius Marminge
maria-rcks
Bilal Bakr
shivam
Vitalii Yehorov
Jake Leventhal
Claude Opus 5
Alex Southwell
github-actions[bot]
Nicholas Wasmiller
PB
Exotic
Yash Singh
Devin
Theo Browne
Gabriel De Andrade
Dara Adedeji
scratchyone
Dominic Roy
chukfinley
Primož Ajdišek
benthecarman
NaveDanan
aaditagrawal
Aditya Garud
Nick Anisimov
MacKinley Smith
Yordis Prieto
t3-code[bot]
AKolenda
Guillermo Casanova
Otavio Salvador
Shirish Pothi
Ishaan Kothari
Bob Fowler
Anton Bezdenezhnykh
ValeraZSD
Ephraim
Ryan Ilano
Alex
maco
Cursor
Tristan Knight
PR Batch Tester
oliver
kamkm
de34391427
Co-authored-by: maria-rcks <[email protected]> Co-authored-by: Bilal Bakr <[email protected]> Co-authored-by: shivam <[email protected]> Co-authored-by: Vitalii Yehorov <[email protected]> Co-authored-by: Jake Leventhal <[email protected]> Co-authored-by: Claude Opus 5 (1M context) <[email protected]> Co-authored-by: Alex Southwell <[email protected]> Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Nicholas Wasmiller <[email protected]> Co-authored-by: PB <[email protected]> Co-authored-by: Exotic <[email protected]> Co-authored-by: Yash Singh <[email protected]> Co-authored-by: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: Theo Browne <[email protected]> Co-authored-by: Gabriel De Andrade <[email protected]> Co-authored-by: Dara Adedeji <[email protected]> Co-authored-by: scratchyone <[email protected]> Co-authored-by: Dominic Roy <[email protected]> Co-authored-by: chukfinley <[email protected]> Co-authored-by: Primož Ajdišek <[email protected]> Co-authored-by: benthecarman <[email protected]> Co-authored-by: NaveDanan <[email protected]> Co-authored-by: aaditagrawal <[email protected]> Co-authored-by: Aditya Garud <[email protected]> Co-authored-by: Nick Anisimov <[email protected]> Co-authored-by: MacKinley Smith <[email protected]> Co-authored-by: Yordis Prieto <[email protected]> Co-authored-by: t3-code[bot] <269035359+t3-code[bot]@users.noreply.github.com> Co-authored-by: AKolenda <[email protected]> Co-authored-by: Guillermo Casanova <[email protected]> Co-authored-by: Otavio Salvador <[email protected]> Co-authored-by: Shirish Pothi <[email protected]> Co-authored-by: Ishaan Kothari <[email protected]> Co-authored-by: Bob Fowler <[email protected]> Co-authored-by: Anton Bezdenezhnykh <[email protected]> Co-authored-by: ValeraZSD <[email protected]> Co-authored-by: Ephraim <[email protected]> Co-authored-by: Ryan Ilano <[email protected]> Co-authored-by: Alex <[email protected]> Co-authored-by: maco <[email protected]> Co-authored-by: Cursor <[email protected]> Co-authored-by: Tristan Knight <[email protected]> Co-authored-by: PR Batch Tester <[email protected]> Co-authored-by: oliver <[email protected]> Co-authored-by: kamkm <[email protected]> Signed-off-by: Yordis Prieto <[email protected]>
209 lines
6.3 KiB
TypeScript
209 lines
6.3 KiB
TypeScript
import * as NodeAssert from "node:assert/strict";
|
|
|
|
import { describe, it } from "vite-plus/test";
|
|
import type * as EffectCodexSchema from "effect-codex-app-server/schema";
|
|
|
|
import { describeMcpElicitation, toMcpElicitationResponse } from "./CodexMcpElicitation.ts";
|
|
|
|
describe("Codex MCP elicitation approvals", () => {
|
|
const request = {
|
|
mode: "form",
|
|
message: "Allow ChatGPT to use Safari?",
|
|
serverName: "computer-use",
|
|
threadId: "provider-thread-1",
|
|
turnId: "turn-1",
|
|
_meta: {
|
|
app_name: "Safari",
|
|
persist: ["session", "always"],
|
|
},
|
|
requestedSchema: {
|
|
type: "object",
|
|
properties: {
|
|
approval: {
|
|
type: "string",
|
|
oneOf: [
|
|
{ const: "once", title: "Allow once" },
|
|
{ const: "session", title: "Allow for this session" },
|
|
{ const: "always", title: "Always allow Safari" },
|
|
],
|
|
},
|
|
},
|
|
required: ["approval"],
|
|
},
|
|
} satisfies EffectCodexSchema.McpServerElicitationRequestParams;
|
|
|
|
it("preserves the app name and advertised persistence choices", () => {
|
|
NodeAssert.deepStrictEqual(describeMcpElicitation(request), {
|
|
appName: "Safari",
|
|
options: [
|
|
{ decision: "cancel", label: "Cancel" },
|
|
{ decision: "decline", label: "Decline" },
|
|
{ decision: "acceptForSession", label: "Allow for this session" },
|
|
{ decision: "acceptAlways", label: "Always allow Safari" },
|
|
{ decision: "accept", label: "Approve" },
|
|
],
|
|
});
|
|
});
|
|
|
|
it("extracts the app name from a Computer Use request without metadata", () => {
|
|
const { _meta, ...requestWithoutMetadata } = request;
|
|
|
|
NodeAssert.equal(describeMcpElicitation(requestWithoutMetadata).appName, "Safari");
|
|
});
|
|
|
|
it("returns the accepted form option to Codex", () => {
|
|
NodeAssert.deepStrictEqual(toMcpElicitationResponse(request, "accept"), {
|
|
action: "accept",
|
|
content: { approval: "once" },
|
|
});
|
|
});
|
|
|
|
it("returns session-scoped approval in the MCP response", () => {
|
|
NodeAssert.deepStrictEqual(toMcpElicitationResponse(request, "acceptForSession"), {
|
|
action: "accept",
|
|
_meta: { persist: "session" },
|
|
content: { approval: "session" },
|
|
});
|
|
});
|
|
|
|
it("returns persistent approval in the MCP response", () => {
|
|
NodeAssert.deepStrictEqual(toMcpElicitationResponse(request, "acceptAlways"), {
|
|
action: "accept",
|
|
_meta: { persist: "always" },
|
|
content: { approval: "always" },
|
|
});
|
|
});
|
|
|
|
it("returns rejection without form content", () => {
|
|
NodeAssert.deepStrictEqual(toMcpElicitationResponse(request, "decline"), {
|
|
action: "decline",
|
|
});
|
|
});
|
|
|
|
it("returns cancellation without form content", () => {
|
|
NodeAssert.deepStrictEqual(toMcpElicitationResponse(request, "cancel"), {
|
|
action: "cancel",
|
|
});
|
|
});
|
|
|
|
it("supports boolean permanent-approval fields", () => {
|
|
const booleanRequest = {
|
|
...request,
|
|
_meta: { app_name: "Safari" },
|
|
requestedSchema: {
|
|
type: "object",
|
|
properties: {
|
|
always: { type: "boolean", title: "Always allow Safari" },
|
|
},
|
|
},
|
|
} satisfies EffectCodexSchema.McpServerElicitationRequestParams;
|
|
|
|
NodeAssert.ok(
|
|
describeMcpElicitation(booleanRequest).options.some(
|
|
(option) => option.decision === "acceptAlways",
|
|
),
|
|
);
|
|
NodeAssert.deepStrictEqual(toMcpElicitationResponse(booleanRequest, "acceptAlways"), {
|
|
action: "accept",
|
|
_meta: { persist: "always" },
|
|
content: { always: true },
|
|
});
|
|
});
|
|
|
|
it("preserves valid nullable MCP form fields and persistence choices", () => {
|
|
const nullableRequest = {
|
|
...request,
|
|
_meta: {
|
|
app_name: null,
|
|
appName: "Safari",
|
|
connector_name: null,
|
|
persist: null,
|
|
target: null,
|
|
tool_params: null,
|
|
},
|
|
requestedSchema: {
|
|
type: "object",
|
|
properties: {
|
|
approval: {
|
|
type: "string",
|
|
title: null,
|
|
description: null,
|
|
default: null,
|
|
enum: ["once", "always"],
|
|
enumNames: null,
|
|
},
|
|
},
|
|
required: ["approval"],
|
|
},
|
|
} satisfies EffectCodexSchema.McpServerElicitationRequestParams;
|
|
|
|
NodeAssert.equal(describeMcpElicitation(nullableRequest).appName, "Safari");
|
|
NodeAssert.ok(
|
|
describeMcpElicitation(nullableRequest).options.some(
|
|
(option) => option.decision === "acceptAlways",
|
|
),
|
|
);
|
|
NodeAssert.deepStrictEqual(toMcpElicitationResponse(nullableRequest, "acceptAlways"), {
|
|
action: "accept",
|
|
_meta: { persist: "always" },
|
|
content: { approval: "always" },
|
|
});
|
|
});
|
|
|
|
it("declines required form fields that an approval prompt cannot collect", () => {
|
|
const inputRequest = {
|
|
...request,
|
|
requestedSchema: {
|
|
type: "object",
|
|
properties: {
|
|
email: { type: "string", format: "email" },
|
|
},
|
|
required: ["email"],
|
|
},
|
|
} satisfies EffectCodexSchema.McpServerElicitationRequestParams;
|
|
|
|
NodeAssert.deepStrictEqual(toMcpElicitationResponse(inputRequest, "accept"), {
|
|
action: "decline",
|
|
});
|
|
});
|
|
|
|
it("does not approve URL elicitations without opening their requested URL", () => {
|
|
const urlRequest = {
|
|
mode: "url",
|
|
message: "Finish signing in to continue.",
|
|
serverName: "computer-use",
|
|
threadId: "provider-thread-1",
|
|
turnId: "turn-1",
|
|
elicitationId: "sign-in-1",
|
|
url: "https://example.com/authorize",
|
|
} satisfies EffectCodexSchema.McpServerElicitationRequestParams;
|
|
|
|
NodeAssert.deepStrictEqual(toMcpElicitationResponse(urlRequest, "accept"), {
|
|
action: "decline",
|
|
});
|
|
});
|
|
|
|
it("omits persistence choices that cannot satisfy required form fields", () => {
|
|
const onceOnlyRequest = {
|
|
...request,
|
|
_meta: { app_name: "Safari", persist: ["session", "always"] },
|
|
requestedSchema: {
|
|
type: "object",
|
|
properties: {
|
|
approval: {
|
|
type: "string",
|
|
enum: ["once"],
|
|
},
|
|
},
|
|
required: ["approval"],
|
|
},
|
|
} satisfies EffectCodexSchema.McpServerElicitationRequestParams;
|
|
|
|
NodeAssert.deepStrictEqual(describeMcpElicitation(onceOnlyRequest).options, [
|
|
{ decision: "cancel", label: "Cancel" },
|
|
{ decision: "decline", label: "Decline" },
|
|
{ decision: "accept", label: "Approve" },
|
|
]);
|
|
});
|
|
});
|