Update: 将子项目从 submodule 转为完整内容

- 移除 GovAI, nomifun-tauri, 算力盒子 的 submodule 引用
- 添加所有子项目的完整源代码
- 保留原始 .git 为 .git.bak 备份
This commit is contained in:
freedak
2026-07-04 19:20:46 +08:00
parent 54d6465fa7
commit f7a720204a
3360 changed files with 802660 additions and 3 deletions
@@ -0,0 +1,86 @@
//! Black-box integration tests for CompactConfig (TC-2.2-01 through TC-2.2-03, TC-2.2-07).
//!
//! These test the public API of CompactConfig from a config-file consumer's
//! perspective: default values, full TOML override, partial override, and
//! Config-level integration.
use nomi_config::compact::CompactConfig;
use nomi_config::config::ConfigFile;
/// TC-2.2-01: CompactConfig default values match spec.
#[test]
fn tc_2_2_01_compact_config_defaults() {
let cfg = CompactConfig::default();
assert_eq!(cfg.context_window, 200_000);
assert_eq!(cfg.output_reserve, 20_000);
assert_eq!(cfg.autocompact_buffer, 13_000);
assert_eq!(cfg.emergency_buffer, 3_000);
assert_eq!(cfg.max_failures, 3);
assert_eq!(cfg.micro_keep_recent, 5);
assert_eq!(cfg.micro_gap_seconds, 3600);
assert!(cfg.enabled);
}
/// TC-2.2-02: CompactConfig full TOML parsing.
#[test]
fn tc_2_2_02_compact_config_toml_full() {
let toml_str = r#"
[compact]
context_window = 128000
output_reserve = 15000
autocompact_buffer = 10000
emergency_buffer = 2000
max_failures = 5
micro_keep_recent = 3
micro_gap_seconds = 1800
compactable_tools = ["Read", "Bash"]
enabled = false
"#;
let config: ConfigFile = toml::from_str(toml_str).unwrap();
assert_eq!(config.compact.context_window, 128_000);
assert_eq!(config.compact.output_reserve, 15_000);
assert_eq!(config.compact.autocompact_buffer, 10_000);
assert_eq!(config.compact.emergency_buffer, 2_000);
assert_eq!(config.compact.max_failures, 5);
assert_eq!(config.compact.micro_keep_recent, 3);
assert_eq!(config.compact.micro_gap_seconds, 1800);
assert_eq!(config.compact.compactable_tools, vec!["Read", "Bash"]);
assert!(!config.compact.enabled);
}
/// TC-2.2-03: partial override — only context_window set, rest are defaults.
#[test]
fn tc_2_2_03_compact_config_partial_override() {
let toml_str = r#"
[compact]
context_window = 128000
"#;
let config: ConfigFile = toml::from_str(toml_str).unwrap();
assert_eq!(config.compact.context_window, 128_000);
// All other fields should be defaults
assert_eq!(config.compact.output_reserve, 20_000);
assert_eq!(config.compact.autocompact_buffer, 13_000);
assert_eq!(config.compact.emergency_buffer, 3_000);
assert_eq!(config.compact.max_failures, 3);
assert_eq!(config.compact.micro_keep_recent, 5);
assert_eq!(config.compact.micro_gap_seconds, 3600);
assert!(config.compact.enabled);
}
/// TC-2.2-07: Config TOML with [compact] section parses completely.
#[test]
fn tc_2_2_07_config_with_compact_section() {
let toml_str = r#"
[default]
provider = "anthropic"
[compact]
context_window = 100000
enabled = true
"#;
let config: ConfigFile = toml::from_str(toml_str).unwrap();
assert_eq!(config.compact.context_window, 100_000);
assert!(config.compact.enabled);
// Other config sections should still parse
assert_eq!(config.default.provider, "anthropic");
}
@@ -0,0 +1,51 @@
use nomi_config::logging::{ResolvedLogging, create_file_layer};
use tracing::info;
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;
#[test]
fn create_file_layer_writes_json_to_file() {
let tmp = tempfile::tempdir().unwrap();
let config = ResolvedLogging {
enabled: true,
level: "info".to_string(),
dir: tmp.path().to_path_buf(),
};
let (layer, _guard) = create_file_layer(&config).unwrap();
tracing_subscriber::registry().with(layer).init();
info!(target: "nomi_test", key = "value", "test message");
drop(_guard);
let entries: Vec<_> = std::fs::read_dir(tmp.path())
.unwrap()
.filter_map(|e| e.ok())
.filter(|e| e.path().extension().is_some_and(|ext| ext == "log"))
.collect();
assert!(!entries.is_empty(), "expected at least one .log file");
let content = std::fs::read_to_string(entries[0].path()).unwrap();
assert!(
content.contains("test message"),
"log should contain message"
);
assert!(content.contains("nomi_test"), "log should contain target");
}
#[test]
fn create_file_layer_creates_directory() {
let tmp = tempfile::tempdir().unwrap();
let nested = tmp.path().join("sub").join("dir");
let config = ResolvedLogging {
enabled: true,
level: "info".to_string(),
dir: nested.clone(),
};
let result = create_file_layer::<tracing_subscriber::Registry>(&config);
assert!(result.is_ok());
assert!(nested.exists());
}
@@ -0,0 +1,75 @@
//! Black-box integration tests for PlanConfig (TC-3.2-01 through TC-3.2-03).
//!
//! These test the public API of PlanConfig from a config-file consumer's
//! perspective: default values, full TOML override, and partial override.
use nomi_config::config::ConfigFile;
use nomi_config::plan::PlanConfig;
/// TC-3.2-01: PlanConfig default values.
/// Input: no `[plan]` section in config.
/// Expected: enabled = true, plan_directory = ".nomi/plans".
#[test]
fn tc_3_2_01_plan_config_defaults() {
let cfg = PlanConfig::default();
assert!(cfg.enabled);
assert_eq!(cfg.plan_directory, ".nomi/plans");
}
/// TC-3.2-01 (variant): absent [plan] section in ConfigFile yields defaults.
#[test]
fn tc_3_2_01_absent_plan_section_uses_defaults() {
let config: ConfigFile = toml::from_str("").unwrap();
assert!(config.plan.enabled);
assert_eq!(config.plan.plan_directory, ".nomi/plans");
}
/// TC-3.2-02: PlanConfig TOML deserialization with all fields.
/// Input: [plan] section with enabled = false and custom plan_directory.
/// Expected: correct parsing.
#[test]
fn tc_3_2_02_plan_config_toml_full() {
let toml_str = r#"
[plan]
enabled = false
plan_directory = "/custom/plans"
"#;
let config: ConfigFile = toml::from_str(toml_str).unwrap();
assert!(!config.plan.enabled);
assert_eq!(config.plan.plan_directory, "/custom/plans");
}
/// TC-3.2-03: PlanConfig partial field override.
/// Input: [plan] section with only enabled = false (no plan_directory).
/// Expected: enabled = false, plan_directory uses default.
#[test]
fn tc_3_2_03_plan_config_partial_override() {
let toml_str = r#"
[plan]
enabled = false
"#;
let config: ConfigFile = toml::from_str(toml_str).unwrap();
assert!(!config.plan.enabled);
assert_eq!(config.plan.plan_directory, ".nomi/plans");
}
/// ConfigFile with [plan] section alongside other sections parses completely.
#[test]
fn plan_config_coexists_with_other_sections() {
let toml_str = r#"
[default]
provider = "anthropic"
[compact]
context_window = 100000
[plan]
enabled = true
plan_directory = ".nomi/custom-plans"
"#;
let config: ConfigFile = toml::from_str(toml_str).unwrap();
assert!(config.plan.enabled);
assert_eq!(config.plan.plan_directory, ".nomi/custom-plans");
assert_eq!(config.default.provider, "anthropic");
assert_eq!(config.compact.context_window, 100_000);
}