M0: compilable skeleton — Kigi 0.1.0 fork surgery
Hard fork of xai-org/grok-build (Apache-2.0) re-targeted as Kigi, an
unofficial Kimi Code CLI community build.
Rename & identity
- 72 xai-*/xai-grok-* crates -> kigi-* (explicit: xai-grok-pager-bin ->
kigi-bin [binary `kigi`], xai-grok-pager -> kigi-tui; rest mechanical);
ptyctl, ptyctl-cli, third_party/ unchanged; proto package
xai.grok.tools.v1 -> kigi.tools.v1
- Config home ~/.kigi (KIGI_SHARE_DIR override), env prefix GROK_* ->
KIGI_*, `kigi --version` carries the unofficial-community-build notice
- clap identity, help text, startup banner, prompt templates rebranded
(templates re-encrypted)
Deletions (PRD removal list #5/#6/#7/#9/#10)
- voice input (xai-grok-voice) and all TUI wiring
- telemetry: Mixpanel client, external OTel stream, Sentry, OTLP layers,
trace/GCS/S3 upload queues (kigi-file-utils halved), workspace upload
module & dc_log, heap-profile uploader, auth-diagnostics uploader,
session-analytics halves of feedback; local zero-egress observability
preserved in new kigi-log crate (unified log, --debug firehose,
subsystem file logs, opt-in instrumentation)
- announcements (crate, remote-settings fields, TUI surfaces)
- plugin marketplace (crate, sources/browse/CTA/extensions-modal tab);
direct plugin install/uninstall/update via kigi-agent git_install kept
- relay/gateway/assets endpoints and features (agent relay, headless
relay transport, gateway bridge, LeaderEnvUrls); leader IPC socket now
~/.kigi/leader.sock + KIGI_LEADER_SOCKET, no ws-url derivation
- functional types rehomed instead of deleted: PermissionMode ->
kigi-config-types, McpInitStrategy -> kigi-mcp, PrCreationSource ->
session signals, TerminalDiagnostics -> kigi-pager-render, agent_id ->
shell util
Endpoints
- kigi-env rewritten: single production KigiEndpoints {coding_api_base_url
https://api.kimi.com/coding/v1 (KIGI_CODE_BASE_URL), oauth_host
https://auth.kimi.com (KIGI_OAUTH_HOST), update_base_url (GitHub
Releases API), upgrade_page_url}; GrokBuildEnvironment enum deleted
Toolchain & workspace hygiene
- Rust 1.97.0 pinned; edition 2024; full cargo update; git2 hoisted to
workspace at 0.21 (Option->Result API migration), quick-xml 0.41
- Root Cargo.toml hand-maintained (PRD §8.1): version 0.1.0 inherited by
all members, members sorted, unused deps pruned
- cargo-deny advisories gate (deny.toml with documented transitive
exceptions); CI workflow (check/clippy/fmt/deny/test, macOS+Linux)
- cross-crate test seams re-gated behind `test-support` cargo feature;
insta snapshot baselines renamed to the kigi_tui prefix
- clippy --workspace --all-targets: zero warnings; fmt clean
Fixes surfaced by the port
- updater probe/installer divergence (bin/kigi vs bin/grok symlink set)
- idle model-metadata refresh dead under KIGI_CODE_BASE_URL override
(new is_effective_coding_endpoint_url, loopback+override aware)
- macOS symlinked-TMPDIR fixture canonicalization (foreign_sessions,
fast-worktree); RSS measurement tests serialized via serial_test
Docs & legal (Apache §4)
- NOTICE added (upstream attribution + change statement); THIRD-PARTY
notices sustained; kigi-tools ported-code notices extended; README,
CONTRIBUTING, SECURITY, AGENTS.md rewritten
Out of scope for M0 (tracked): Kimi auth/inference (M1), search/fetch,
command parity, config import (M2), Computer Hub excision & final
brand-token sweep (M2), distribution & self-update rewrite (M3).
This commit is contained in:
@@ -0,0 +1,258 @@
|
||||
//! Integration test: MockInferenceServer `/v1/settings` endpoint and
|
||||
//! remote settings settings refresh infrastructure.
|
||||
//!
|
||||
//! Tests the mock endpoint directly (no binary needed) and verifies
|
||||
//! the `fetch_settings_blocking` client round-trips correctly with
|
||||
//! runtime-mutated mock settings.
|
||||
//!
|
||||
//! Run locally:
|
||||
//! ```bash
|
||||
//! cargo test -p kigi-shell --test test_settings_refresh
|
||||
//! ```
|
||||
|
||||
use std::future::Future;
|
||||
|
||||
use kigi_shell::util::config::RemoteSettings;
|
||||
use kigi_test_support::*;
|
||||
|
||||
async fn with_local_set<F, Fut>(f: F)
|
||||
where
|
||||
F: FnOnce() -> Fut,
|
||||
Fut: Future<Output = ()>,
|
||||
{
|
||||
tokio::task::LocalSet::new().run_until(f()).await;
|
||||
}
|
||||
|
||||
/// Verify the mock `/v1/settings` endpoint returns 404 when no settings
|
||||
/// are configured (the default). This preserves backward compatibility:
|
||||
/// existing tests that never call `set_settings` see a 404, and
|
||||
/// `fetch_settings_blocking` returns `None`.
|
||||
#[tokio::test]
|
||||
async fn test_settings_endpoint_returns_404_when_unconfigured() {
|
||||
with_local_set(|| async {
|
||||
let server = MockInferenceServer::start()
|
||||
.await
|
||||
.expect("start mock server");
|
||||
|
||||
let resp = reqwest::get(format!("{}/settings", server.url()))
|
||||
.await
|
||||
.expect("request failed");
|
||||
assert_eq!(resp.status(), 404);
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
||||
/// Verify the mock `/v1/settings` endpoint returns configured settings
|
||||
/// and that `set_settings` runtime mutation is reflected immediately.
|
||||
#[tokio::test]
|
||||
async fn test_settings_endpoint_returns_configured_settings() {
|
||||
with_local_set(|| async {
|
||||
let server = MockInferenceServer::start()
|
||||
.await
|
||||
.expect("start mock server");
|
||||
|
||||
// Configure initial settings
|
||||
server.set_settings(RemoteSettings {
|
||||
tips: Some(vec!["tip_v1".into()]),
|
||||
leader_mode: Some(false),
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
// Fetch and verify
|
||||
let resp = reqwest::get(format!("{}/settings", server.url()))
|
||||
.await
|
||||
.expect("request failed");
|
||||
assert_eq!(resp.status(), 200);
|
||||
let settings: RemoteSettings = resp.json().await.expect("parse failed");
|
||||
assert_eq!(settings.tips, Some(vec!["tip_v1".into()]));
|
||||
assert_eq!(settings.leader_mode, Some(false));
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
||||
/// Verify that `set_settings` updates are visible to subsequent requests
|
||||
/// (runtime mutation for multi-session test scenarios).
|
||||
#[tokio::test]
|
||||
async fn test_settings_endpoint_reflects_runtime_mutations() {
|
||||
with_local_set(|| async {
|
||||
let server = MockInferenceServer::start()
|
||||
.await
|
||||
.expect("start mock server");
|
||||
|
||||
// Initial settings
|
||||
server.set_settings(RemoteSettings {
|
||||
tips: Some(vec!["tip_v1".into()]),
|
||||
..Default::default()
|
||||
});
|
||||
let settings: RemoteSettings = reqwest::get(format!("{}/settings", server.url()))
|
||||
.await
|
||||
.unwrap()
|
||||
.json()
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(settings.tips, Some(vec!["tip_v1".into()]));
|
||||
|
||||
// Mutate settings (simulating a remote feature flag change)
|
||||
server.set_settings(RemoteSettings {
|
||||
tips: Some(vec!["tip_v2".into()]),
|
||||
leader_mode: Some(true),
|
||||
..Default::default()
|
||||
});
|
||||
|
||||
// Subsequent request sees the updated values
|
||||
let settings: RemoteSettings = reqwest::get(format!("{}/settings", server.url()))
|
||||
.await
|
||||
.unwrap()
|
||||
.json()
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(settings.tips, Some(vec!["tip_v2".into()]));
|
||||
assert_eq!(settings.leader_mode, Some(true));
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
||||
/// Verify `fetch_settings_blocking` round-trips through the mock server.
|
||||
/// This is the actual client function used by `refresh_remote_settings`.
|
||||
#[tokio::test]
|
||||
async fn test_fetch_settings_blocking_round_trip() {
|
||||
with_local_set(|| async {
|
||||
let server = MockInferenceServer::start()
|
||||
.await
|
||||
.expect("start mock server");
|
||||
|
||||
// Without settings configured: returns None (404 from mock)
|
||||
let auth = kigi_shell::auth::GrokAuth {
|
||||
key: "test-key".into(),
|
||||
..Default::default()
|
||||
};
|
||||
let result = tokio::task::spawn_blocking({
|
||||
let url = server.url().to_string();
|
||||
let auth = auth.clone();
|
||||
move || kigi_shell::remote::fetch_settings_blocking(&url, &auth, None)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
assert!(
|
||||
result.is_none(),
|
||||
"Expected None when settings not configured"
|
||||
);
|
||||
|
||||
// With settings configured: returns Some(settings)
|
||||
server.set_settings(RemoteSettings {
|
||||
tips: Some(vec!["fetched_tip".into()]),
|
||||
..Default::default()
|
||||
});
|
||||
let result = tokio::task::spawn_blocking({
|
||||
let url = server.url().to_string();
|
||||
let auth = auth.clone();
|
||||
move || kigi_shell::remote::fetch_settings_blocking(&url, &auth, None)
|
||||
})
|
||||
.await
|
||||
.unwrap();
|
||||
let settings = result.expect("Expected Some when settings are configured");
|
||||
assert_eq!(settings.tips, Some(vec!["fetched_tip".into()]));
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
||||
/// Verify the `doom_loop_recovery` settings object survives the
|
||||
/// `/v1/settings` round-trip, that its absence deserializes to `None` (old
|
||||
/// servers), and that a partial object keeps its unset fields `None`.
|
||||
#[tokio::test]
|
||||
async fn test_doom_loop_recovery_settings_round_trip() {
|
||||
use kigi_shell::util::config::DoomLoopRecoverySettings;
|
||||
|
||||
with_local_set(|| async {
|
||||
let server = MockInferenceServer::start()
|
||||
.await
|
||||
.expect("start mock server");
|
||||
|
||||
// Absent from the payload ⇒ None on the client.
|
||||
server.set_settings(RemoteSettings::default());
|
||||
let settings: RemoteSettings = reqwest::get(format!("{}/settings", server.url()))
|
||||
.await
|
||||
.unwrap()
|
||||
.json()
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(settings.doom_loop_recovery, None);
|
||||
|
||||
server.set_settings(RemoteSettings {
|
||||
doom_loop_recovery: Some(DoomLoopRecoverySettings {
|
||||
enabled: Some(true),
|
||||
max_threshold: Some(16),
|
||||
max_retries: Some(1),
|
||||
}),
|
||||
..Default::default()
|
||||
});
|
||||
let settings: RemoteSettings = reqwest::get(format!("{}/settings", server.url()))
|
||||
.await
|
||||
.unwrap()
|
||||
.json()
|
||||
.await
|
||||
.unwrap();
|
||||
let recovery = settings.doom_loop_recovery.expect("object round-trips");
|
||||
assert_eq!(recovery.enabled, Some(true));
|
||||
assert_eq!(recovery.max_threshold, Some(16));
|
||||
assert_eq!(recovery.max_retries, Some(1));
|
||||
|
||||
// Partial object: only the set field comes through; the rest stay
|
||||
// None so the resolver falls through per-field.
|
||||
server.set_settings(RemoteSettings {
|
||||
doom_loop_recovery: Some(DoomLoopRecoverySettings {
|
||||
max_threshold: Some(32),
|
||||
..Default::default()
|
||||
}),
|
||||
..Default::default()
|
||||
});
|
||||
let settings: RemoteSettings = reqwest::get(format!("{}/settings", server.url()))
|
||||
.await
|
||||
.unwrap()
|
||||
.json()
|
||||
.await
|
||||
.unwrap();
|
||||
let recovery = settings.doom_loop_recovery.expect("object round-trips");
|
||||
assert_eq!(recovery.enabled, None);
|
||||
assert_eq!(recovery.max_threshold, Some(32));
|
||||
assert_eq!(recovery.max_retries, None);
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
||||
/// Verify that the mock server's request log correctly tracks
|
||||
/// GET /v1/settings requests for assertion in multi-session tests.
|
||||
#[tokio::test]
|
||||
async fn test_settings_requests_appear_in_request_log() {
|
||||
with_local_set(|| async {
|
||||
let server = MockInferenceServer::start()
|
||||
.await
|
||||
.expect("start mock server");
|
||||
server.set_settings(RemoteSettings::default());
|
||||
|
||||
assert_eq!(server.request_count(), 0);
|
||||
|
||||
// First request
|
||||
let _ = reqwest::get(format!("{}/settings", server.url()))
|
||||
.await
|
||||
.unwrap();
|
||||
let settings_reqs: Vec<_> = server
|
||||
.requests()
|
||||
.into_iter()
|
||||
.filter(|r| r.method == "GET" && r.path.contains("/settings"))
|
||||
.collect();
|
||||
assert_eq!(settings_reqs.len(), 1, "Expected 1 settings request");
|
||||
|
||||
// Second request (simulating /new refresh)
|
||||
let _ = reqwest::get(format!("{}/settings", server.url()))
|
||||
.await
|
||||
.unwrap();
|
||||
let settings_reqs: Vec<_> = server
|
||||
.requests()
|
||||
.into_iter()
|
||||
.filter(|r| r.method == "GET" && r.path.contains("/settings"))
|
||||
.collect();
|
||||
assert_eq!(settings_reqs.len(), 2, "Expected 2 settings requests");
|
||||
})
|
||||
.await;
|
||||
}
|
||||
Reference in New Issue
Block a user