Open History to see the last commit
1import { assert, it } from "@effect/vitest";
2import { classifyCodexManagedError } from "./CodexManagedErrors.ts";
3it("maps streamed failures to safe actionable messages and reconnect decisions", () => {
4 assert.deepEqual(
5 classifyCodexManagedError({
6 error: {
7 code: "subscription_sharing_v2_invalid_user",
8 message: "opaque token dummy-sensitive",
9 },
10 }),
11 {
12 message:
13 "ChatGPT could not validate this connection. Check the selected account and sharing permissions.",
14 code: "subscription_sharing_v2_invalid_user",
15 },
16 );
17 assert.include(
18 classifyCodexManagedError("subscription_sharing_usage_limit_exceeded")!.message,
19 "Usage settings",
20 );
21 assert.equal(
22 classifyCodexManagedError("subscription_sharing_usage_limit_exceeded")!.code,
23 "subscription_sharing_usage_limit_exceeded",
24 );
25 assert.include(
26 classifyCodexManagedError("subscription_sharing_unsupported_capability")!.message,
27 "feature",
28 );
29 assert.isUndefined(classifyCodexManagedError(undefined));
30 assert.isUndefined(classifyCodexManagedError({ error: "unknown" }));
31});
32
33it("distinguishes unsupported tools from input items without exposing the raw response", () => {
34 const code = "subscription_sharing_unsupported_capability";
35 for (const [detail, expected] of [
36 ["tool 'namespace' is not supported", "tool namespace"],
37 ["input item 'additional_tools' is not supported", "input item"],
38 ]) {
39 const response = { error: { code, message: `${detail}; dummy-sensitive` } };
40 for (const value of [response, JSON.stringify(response)]) {
41 const failure = classifyCodexManagedError(value);
42 assert.isDefined(failure);
43 assert.include(failure!.message, expected!);
44 assert.notInclude(failure!.message, "dummy-sensitive");
45 }
46 }
47});
48
49it("preserves credentials for the current subscriber and permission error codes", () => {
50 for (const code of [
51 "subscription_sharing_invalid_user",
52 "subscription_sharing_user_not_eligible",
53 "subscription_sharing_route_not_supported",
54 "subscription_sharing_user_unavailable",
55 "chatpass_v2_scope_not_authorized",
56 "chatpass_v2_invalid_authorization_context",
57 ]) {
58 assert.strictEqual(classifyCodexManagedError({ error: { code } })?.code, code);
59 }
60});