1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
-- Offline: panto lua _selfcheck.lua (or Lua 5.4).
local here = debug.getinfo(1, "S").source:match("^@(.*)/[^/]+$") or "."
local entry = assert(loadfile(here .. "/init.lua"))()
assert(entry.name == "codex" and type(entry.configure) == "function")
assert(entry.activate == nil, "configure-only extension")
local function contains(actual, expected)
for key, value in pairs(expected) do
if type(value) == "table" then
assert(type(actual[key]) == "table", key .. " must be a table")
contains(actual[key], value)
else
assert(actual[key] == value, key .. " default mismatch")
end
end
end
local empty = {}
entry.configure(empty)
assert(next(empty) == nil, "no implicit auth/providers")
local untouched = { providers = {
absent = {}, disabled = { panto_codex_extension = false },
string_marker = { panto_codex_extension = "true" },
}, auth = { absent = {}, disabled = { panto_codex_extension = false } } }
entry.configure(untouched)
assert(next(untouched.providers.absent) == nil)
assert(untouched.providers.disabled.style == nil and untouched.providers.string_marker.style == nil)
assert(next(untouched.auth.absent) == nil and untouched.auth.disabled.type == nil)
local config = {
auth = { first = { panto_codex_extension = true }, second = { panto_codex_extension = true } },
providers = {
first = { panto_codex_extension = true, auth = "second" },
second = { panto_codex_extension = true, auth = "first" },
},
}
entry.configure(config)
contains(config.auth.first, {
type = "oauth_device",
dialect = "codex",
client_id = "app_EMoamEEZ73f0CkXaXp7hrann",
device_code_url = "https://auth.openai.com/api/accounts/deviceauth/usercode",
device_poll_url = "https://auth.openai.com/api/accounts/deviceauth/token",
verification_url = "https://auth.openai.com/codex/device",
token_url = "https://auth.openai.com/oauth/token",
account_id_jwt_claim = "https://api.openai.com/auth",
})
contains(config.providers.first, {
style = "openai_responses",
model_catalog_name = "openai",
extra_headers = {
["OpenAI-Beta"] = "responses=experimental",
originator = "codex_cli_rs",
},
base_url = "https://chatgpt.com/backend-api/codex",
dialect = "codex",
})
assert(config.providers.first.auth == "second" and config.providers.second.auth == "first")
assert(config.providers.first.extra_headers ~= config.providers.second.extra_headers)
config.providers.first.extra_headers.custom = "first-only"
assert(config.providers.second.extra_headers.custom == nil, "instance defaults must not alias")
entry.configure(config)
assert(config.providers.first.extra_headers.custom == "first-only", "repeatable configuration")
local fresh = { providers = { third = { panto_codex_extension = true } } }
entry.configure(fresh)
assert(fresh.providers.third.auth == nil, "never invent auth linkage")
assert(fresh.providers.third.extra_headers.custom == nil, "no cross-load mutable defaults")
local override = {
auth = { login = { panto_codex_extension = true, client_id = "custom-client", key = "${env:CUSTOM_KEY}" } },
providers = { custom = {
panto_codex_extension = true,
auth = "login",
model_catalog_name = "custom-catalog",
extra_headers = { ["openai-beta"] = "custom-header", custom = "${session:id}" },
endpoints = { openai_responses = {
base_url = "https://gateway.example/v1",
extra_headers = { local_header = "kept" },
} },
} },
}
entry.configure(override)
local custom = override.providers.custom
assert(override.auth.login.client_id == "custom-client")
assert(override.auth.login.key == "${env:CUSTOM_KEY}", "raw key reference preserved")
assert(custom.auth == "login" and custom.model_catalog_name == "custom-catalog")
assert(custom.base_url == nil and custom.dialect == nil, "endpoint form stays valid")
assert(custom.endpoints.openai_responses.base_url == "https://gateway.example/v1")
assert(custom.endpoints.openai_responses.extra_headers.local_header == "kept")
assert(custom.extra_headers["openai-beta"] == "custom-header")
assert(custom.extra_headers["OpenAI-Beta"] == nil, "case-insensitive header override")
assert(custom.extra_headers.custom == "${session:id}", "raw session reference preserved")
assert(custom.endpoints.openai_responses.dialect == "codex")
for _, style in ipairs({ "openai_chat", "anthropic_messages" }) do
local flat = { providers = { custom = {
panto_codex_extension = true, auth = "login", style = style,
base_url = "https://gateway.example/v1",
} } }
entry.configure(flat)
assert(flat.providers.custom.endpoints == nil, "explicit flat provider stays flat")
assert(flat.providers.custom.style == style and flat.providers.custom.dialect == nil)
assert(flat.providers.custom.base_url == "https://gateway.example/v1")
end
local invalid = { providers = { marked = { panto_codex_extension = true, extra_headers = false } } }
entry.configure(invalid)
assert(invalid.providers.marked.extra_headers == false, "explicit false remains untouched")
print("panto-codex: ok")
|