28th platform `github-copilot` (uses_oauth, ChatCompletions wire). Two-stage auth: RFC-8628 GitHub device flow (client Iv1.b507a08c87ecfe98, scope read:user, errors in a 200 body) mints the DURABLE github token; a GET api.github.com/copilot_internal/ v2/token exchange re-mints the SHORT-LIVED copilot token. Persisted as key=copilot token, refresh_token=github token, expires_at=copilot expiry; the "refresh" is a copilot-token re-mint (not a refresh_token grant), dispatched via OAuthTokenBody::GithubCopilotExchange in the generic refresher. VS Code editor-identity headers on /models + /chat/completions, gated on SamplerConfig.github_copilot / PlatformId::sends_copilot_editor_headers() so every other ChatCompletions provider stays byte-identical. Live /models filtered (parse_github_copilot_listing) to the openai-completions-served models: keep iff model_picker_enabled && policy.state!="disabled" && tool_calls!=false AND not a claude-4.x/5.x (messages) or gpt-5/oswe/mai- (responses-only) id — those need per-model wire routing (documented debt), excluded rather than mis-routed. Inherits the leak-safe pooled routing (scope oauth/github-copilot); its bearer/ refresh/api_key never touch the Kimi token (regression test added). Fail-fast on an out-of-range copilot expires_at (would otherwise silently 401 mid-session). Adversarial security review: GO, no CRITICAL/HIGH. Known limitation: Pi's per-model policy-enablement POST is not ported (documented in AGENTS.md).
64 lines
2.3 KiB
Rust
64 lines
2.3 KiB
Rust
//! Shared helpers for kigi-shell integration tests.
|
|
|
|
use kigi_shell::sampling::{ApiBackend, Client, SamplerConfig};
|
|
|
|
/// Create a sampling client configured for a mock server. Shared by the
|
|
/// integration tests so the ~30-field `SamplerConfig` literal lives in one
|
|
/// place (`SamplerConfig` has no `Default`).
|
|
pub fn create_test_client(base_url: &str, api_backend: ApiBackend) -> Client {
|
|
create_test_client_with_extra_headers(base_url, api_backend, &[])
|
|
}
|
|
|
|
/// Like [`create_test_client`] but seeds `SamplerConfig::extra_headers`, so a
|
|
/// test can assert that session-injected headers reach the wire.
|
|
pub fn create_test_client_with_extra_headers(
|
|
base_url: &str,
|
|
api_backend: ApiBackend,
|
|
extra_headers: &[(&str, &str)],
|
|
) -> Client {
|
|
Client::new(test_sampler_config(base_url, api_backend, extra_headers)).unwrap()
|
|
}
|
|
|
|
/// The shared mock-server `SamplerConfig`; tests needing a non-default field
|
|
/// (e.g. `doom_loop_recovery`) mutate the returned value before building the
|
|
/// client themselves.
|
|
pub fn test_sampler_config(
|
|
base_url: &str,
|
|
api_backend: ApiBackend,
|
|
extra_headers: &[(&str, &str)],
|
|
) -> SamplerConfig {
|
|
// Shell `Client` is `kigi_sampler::SamplingClient`, which takes a
|
|
// `SamplerConfig` directly. Construct one inline here.
|
|
SamplerConfig {
|
|
api_key: Some("test-api-key".to_string()),
|
|
base_url: base_url.to_string(),
|
|
model: "test-model".to_string(),
|
|
max_completion_tokens: Some(1000),
|
|
temperature: Some(0.7),
|
|
top_p: None,
|
|
api_backend,
|
|
auth_scheme: Default::default(),
|
|
anthropic_oauth: false,
|
|
github_copilot: false,
|
|
chat_compat: Default::default(),
|
|
extra_headers: extra_headers
|
|
.iter()
|
|
.map(|(k, v)| (k.to_string(), v.to_string()))
|
|
.collect(),
|
|
context_window: 256_000,
|
|
force_http1: false,
|
|
max_retries: None,
|
|
stream_tool_calls: false,
|
|
idle_timeout_secs: None,
|
|
reasoning_effort: None,
|
|
origin_client: None,
|
|
attribution_callback: None,
|
|
bearer_resolver: None,
|
|
supports_backend_search: false,
|
|
compactions_remaining: None,
|
|
compaction_at_tokens: None,
|
|
doom_loop_recovery: None,
|
|
header_injector: None,
|
|
}
|
|
}
|