Skip to content

Commit f8baf39

Browse files
committed
feat: 允许关闭 VFS 与 PCBID hook
- 将 VFS 和 PCBID 改为默认启用的公开配置 section - 为两个 section 自动生成 Enable 配置项 - 添加配置解析与模块初始化门控回归测试
1 parent 398ae5a commit f8baf39

5 files changed

Lines changed: 42 additions & 14 deletions

File tree

packages/applechu/src/config/tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::system_config::SystemConfig;
44

55
mod amdaemon;
66
mod loading;
7+
mod platform;
78

89
crate::config_section! {
910
pub struct TestSectionConfig => TEST_SECTION {

packages/applechu/src/config/tests/amdaemon.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,4 @@ fn required_internal_sections_are_not_emitted() {
7676
assert!(output.contains("[PCBID]"));
7777
assert!(output.contains("[VFS]"));
7878
assert!(output.contains("[SliderDevice]"));
79-
assert!(!output
80-
.split("[PCBID]")
81-
.nth(1)
82-
.unwrap()
83-
.starts_with("\nEnable"));
84-
assert!(!output
85-
.split("[VFS]")
86-
.nth(1)
87-
.unwrap()
88-
.starts_with("\nEnable"));
8979
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
use super::Config;
2+
3+
#[test]
4+
fn platform_hook_sections_are_public_and_enabled_by_default() {
5+
// Given: 用户没有覆盖平台 hook 的默认状态。
6+
let config = Config::parse(".", "ConfigVersion = 1\n").expect("测试配置必须有效");
7+
8+
// When: 配置被规范化保存。
9+
let output = config.to_toml();
10+
11+
// Then: VFS 与 PCBID 都公开默认启用开关。
12+
assert!(output.contains("[PCBID]\nEnable = true\n"));
13+
assert!(output.contains("[VFS]\nEnable = true\n"));
14+
}
15+
16+
#[test]
17+
fn platform_hook_modules_follow_explicit_enable_state() {
18+
// Given: 用户明确关闭 VFS 与 PCBID hook。
19+
let config = Config::parse(
20+
".",
21+
"ConfigVersion = 1\n[PCBID]\nEnable = false\n[VFS]\nEnable = false\n",
22+
)
23+
.expect("测试配置必须有效");
24+
25+
// When: 模块注册表计算两个 init 的启用状态。
26+
let modules = crate::module_registry::registered_modules();
27+
let pcbid = modules
28+
.iter()
29+
.find(|module| module.name.ends_with("platform::pcbid::init"))
30+
.expect("PCBID 模块必须完成注册");
31+
let vfs = modules
32+
.iter()
33+
.find(|module| module.name.ends_with("platform::vfs::init"))
34+
.expect("VFS 模块必须完成注册");
35+
36+
// Then: 两个 hook 初始化入口都被配置门控阻止。
37+
assert!(!(pcbid.enabled)(&config));
38+
assert!(!(vfs.enabled)(&config));
39+
}

packages/applechu/src/platform/pcbid.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ crate::config_section! {
1919
order: 960,
2020
default_on: true,
2121
always_enabled: false,
22-
hidden: true,
23-
export: true,
22+
hidden: false,
2423
comment: "机台序列号模拟",
2524
fields: {
2625
pub serial_no: String = String::from("ACAE01A99999999"),

packages/applechu/src/platform/vfs.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ crate::config_section! {
3535
order: 970,
3636
default_on: true,
3737
always_enabled: false,
38-
hidden: true,
39-
export: true,
38+
hidden: false,
4039
comment: "虚拟文件系统",
4140
fields: {
4241
pub amfs: String = String::from("amfs"),

0 commit comments

Comments
 (0)