-- 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 == "opencode-go" 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_opencode_go_extension = false }, string_marker = { panto_opencode_go_extension = "true" }, }, auth = { absent = {}, disabled = { panto_opencode_go_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_opencode_go_extension = true }, second = { panto_opencode_go_extension = true } }, providers = { first = { panto_opencode_go_extension = true, auth = "second" }, second = { panto_opencode_go_extension = true, auth = "first" }, }, } entry.configure(config) contains(config.auth.first, { type = "api_key", key = "${env:OPENCODE_API_KEY}", }) contains(config.providers.first, { style = "openai_chat", model_catalog_name = "opencode-go", extra_headers = { ["User-Agent"] = "panto", ["x-opencode-session"] = "${session:id}", }, endpoints = { openai_chat = { base_url = "https://opencode.ai/zen/go/v1" }, openai_responses = { base_url = "https://opencode.ai/zen/go/v1" }, anthropic_messages = { base_url = "https://opencode.ai/zen/go" }, }, }) 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_opencode_go_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_opencode_go_extension = true, client_id = "custom-client", key = "${env:CUSTOM_KEY}" } }, providers = { custom = { panto_opencode_go_extension = true, auth = "login", model_catalog_name = "custom-catalog", extra_headers = { ["user-agent"] = "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["user-agent"] == "custom-header") assert(custom.extra_headers["User-Agent"] == nil, "case-insensitive header override") assert(custom.extra_headers.custom == "${session:id}", "raw session reference preserved") local flat = { providers = { custom = { panto_opencode_go_extension = true, auth = "login", style = "openai_chat", 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 == "openai_chat") assert(flat.providers.custom.base_url == "https://gateway.example/v1") local invalid = { providers = { marked = { panto_opencode_go_extension = true, extra_headers = false } } } entry.configure(invalid) assert(invalid.providers.marked.extra_headers == false, "explicit false remains untouched") print("panto-opencode-go: ok")