diff options
Diffstat (limited to '_selfcheck.lua')
| -rw-r--r-- | _selfcheck.lua | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/_selfcheck.lua b/_selfcheck.lua new file mode 100644 index 0000000..f3be748 --- /dev/null +++ b/_selfcheck.lua @@ -0,0 +1,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") |
