mirror of
https://github.com/farion1231/cc-switch.git
synced 2026-07-26 23:56:02 +08:00
fix(codex): move common-config TOML merge off smol-toml to backend toml_edit
updateTomlCommonConfigSnippet re-serialized the whole document through
smol-toml (parse -> deepMerge -> stringify): comments dropped, keys
reordered, and empty parent table headers synthesized -- the
long-standing "config.toml keeps getting reordered" symptom (audit C5,
introduced in 083e48bf).
Replace it with a backend command backed by the same
merge_toml_table_like / remove_toml_table_like used when writing live
configs, so the form preview and the live write share one merge
semantic and user formatting survives edit-time merges. The frontend
sync helper is deleted outright to keep the pattern from coming back.
Making the form operations async exposes them to interleaving, so a
result is discarded unless it is still current when it lands:
- a per-hook sequence number (last operation wins) covers rapid
toggle/save races where an earlier merge resolves after a later
removal and would flip the switch back;
- a config-baseline check covers the user hand-editing the TOML while
a merge is in flight -- the stale result must not clobber their edit.
The checkbox state self-heals via the existing inference effect.
Regression tests pin both by resolving a suspended merge after a newer
operation / an external edit, plus backend tests locking comment and
key-order preservation, scalar override, and value-matched removal.
This commit is contained in:
@@ -48,6 +48,29 @@ export async function setCommonConfigSnippet(
|
||||
return invoke("set_common_config_snippet", { appType, snippet });
|
||||
}
|
||||
|
||||
/**
|
||||
* 对编辑器里的 config.toml 文本做通用配置片段的合并/剥离
|
||||
*
|
||||
* 合并/剥离在后端用 toml_edit 完成(保注释、保键序);前端 smol-toml
|
||||
* 的整文档重序列化会破坏用户手写格式,禁止在前端做这类结构化改写。
|
||||
*
|
||||
* @param configToml - 编辑器当前的 config.toml 文本
|
||||
* @param snippetToml - 通用配置片段(TOML 字符串)
|
||||
* @param enabled - true 合并片段,false 按值匹配剥离片段
|
||||
* @returns 更新后的 config.toml 文本
|
||||
*/
|
||||
export async function updateTomlCommonConfigSnippet(
|
||||
configToml: string,
|
||||
snippetToml: string,
|
||||
enabled: boolean,
|
||||
): Promise<string> {
|
||||
return invoke<string>("update_toml_common_config_snippet", {
|
||||
configToml,
|
||||
snippetToml,
|
||||
enabled,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 提取通用配置片段
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user