@@ -1228,12 +1228,14 @@ TEST(config_yaml_edit_hermes_accepts_interior_brackets_in_plain_scalar_issue1924
12281228
12291229TEST (config_yaml_edit_hermes_hook_still_refuses_block_scalar_value_issue1924 ) {
12301230 /* A `>` or `|` that BEGINS a value is a real block scalar whose
1231- * indentation contract this editor does not model: the fail-closed
1232- * refusal stays, and the file stays byte-identical. */
1231+ * indentation contract this editor does not model: inside the `hooks`
1232+ * subtree the edit descends into, the fail-closed refusal stays and the
1233+ * file stays byte-identical. The same construct in an untouched section
1234+ * is opaque user content (#2209). */
12331235 static const char * const initials [] = {
1234- "agent :\n personalities:\n probe: >\n folded face\n" ,
1235- "agent :\n personalities:\n probe: |\n literal face\n" ,
1236- "agent :\n personalities:\n probe: >-\n chomped face\n" ,
1236+ "hooks :\n probe: >\n folded face\n" ,
1237+ "hooks :\n probe: |\n literal face\n" ,
1238+ "hooks :\n probe: >-\n chomped face\n" ,
12371239 };
12381240 for (size_t i = 0U ; i < sizeof (initials ) / sizeof (initials [0 ]); i ++ ) {
12391241 yaml_fixture_t fixture ;
@@ -1250,10 +1252,10 @@ TEST(config_yaml_edit_hermes_hook_still_refuses_block_scalar_value_issue1924) {
12501252
12511253TEST (config_yaml_edit_hermes_hook_still_refuses_nonempty_flow_sequence_value_issue1924 ) {
12521254 /* Pins the #1631 line: exact `[]` is accepted, a non-empty flow sequence
1253- * value is still unsupported in the sequence-document scan. */
1254- const char * initial = "agent:\n"
1255- " personalities :\n"
1256- " probe: [a, b]\n" ;
1255+ * value inside the edited `hooks` subtree is still unsupported. Outside
1256+ * it, the value is opaque user content (#2209). */
1257+ const char * initial = "hooks :\n"
1258+ " probe: [a, b]\n" ;
12571259 yaml_fixture_t fixture ;
12581260 ASSERT_EQ (yaml_fixture_init (& fixture , initial ), 0 );
12591261 ASSERT_EQ (yaml_hermes_hook_upsert (& fixture ), CBM_YAML_IDENTITY_EDIT_ERROR );
@@ -2027,6 +2029,57 @@ TEST(config_yaml_edit_remove_on_absent_config_is_a_no_op) {
20272029 PASS ();
20282030}
20292031
2032+ /* #2209: the stock Hermes config carries flow sequences and block scalars in
2033+ * sections the hook edit never touches (`platform_toolsets:` -> `cli:
2034+ * [hermes-cli]`, `plugins:` -> `enabled: [...]`, `|` prompts). They are opaque
2035+ * user content, exactly as for the mapping-entry editor that writes
2036+ * `mcp_servers` into the same file; only the `hooks` subtree is validated. */
2037+ TEST (config_yaml_edit_nested_sequence_ignores_foreign_flow_and_block_scalars_issue2209 ) {
2038+ const char * initial = "plugins:\n"
2039+ " enabled: [disk-cleanup]\n"
2040+ "platform_toolsets:\n"
2041+ " cli: [hermes-cli]\n"
2042+ " telegram: [hermes-telegram]\n"
2043+ "toolsets: [all]\n"
2044+ "agent:\n"
2045+ " system_prompt: |\n"
2046+ " You are helpful.\n"
2047+ " - keep: [this, text]\n"
2048+ " note: >\n"
2049+ " folded\n"
2050+ "model:\n"
2051+ " default: \"anthropic/claude-opus-4.6\"\n" ;
2052+ yaml_fixture_t fixture ;
2053+ ASSERT_EQ (yaml_fixture_init (& fixture , initial ), 0 );
2054+ ASSERT_EQ (cbm_yaml_upsert_mapping_sequence_item (fixture .path , yaml_hook_sequence_path , 2U , "id" ,
2055+ yaml_hook_identity , yaml_hook_canonical_item ),
2056+ CBM_YAML_IDENTITY_EDIT_OK );
2057+ char * installed = yaml_read_alloc (fixture .path );
2058+ ASSERT_NOT_NULL (installed );
2059+ ASSERT_EQ (strncmp (installed , initial , strlen (initial )), 0 );
2060+ ASSERT_NOT_NULL (strstr (installed , "hooks:\n"
2061+ " pre_llm_call:\n"
2062+ " - id: \"codebase-memory-mcp\"\n" ));
2063+ ASSERT_EQ (cbm_yaml_upsert_mapping_sequence_item (fixture .path , yaml_hook_sequence_path , 2U , "id" ,
2064+ yaml_hook_identity , yaml_hook_canonical_item ),
2065+ CBM_YAML_IDENTITY_EDIT_OK );
2066+ char * second = yaml_read_alloc (fixture .path );
2067+ ASSERT_NOT_NULL (second );
2068+ ASSERT_STR_EQ (second , installed );
2069+ free (second );
2070+ free (installed );
2071+ ASSERT_EQ (cbm_yaml_remove_mapping_sequence_item (fixture .path , yaml_hook_sequence_path , 2U , "id" ,
2072+ yaml_hook_identity , yaml_hook_canonical_item ),
2073+ CBM_YAML_IDENTITY_EDIT_OK );
2074+ char * removed = yaml_read_alloc (fixture .path );
2075+ ASSERT_NOT_NULL (removed );
2076+ ASSERT_NULL (strstr (removed , "codebase-memory-mcp" ));
2077+ ASSERT_EQ (strncmp (removed , initial , strlen (initial )), 0 );
2078+ free (removed );
2079+ th_cleanup (fixture .dir );
2080+ PASS ();
2081+ }
2082+
20302083TEST (config_yaml_edit_nested_sequence_ambiguity_fails_byte_identically ) {
20312084 const char * cases [] = {
20322085 "hooks:\n pre_llm_call:\n - id: \"bad-indent\"\n" ,
@@ -2192,6 +2245,7 @@ SUITE(config_yaml_edit) {
21922245 RUN_TEST (config_yaml_edit_nested_sequence_preserves_crlf );
21932246 RUN_TEST (config_yaml_edit_nested_sequence_foreign_identity_is_preserved );
21942247 RUN_TEST (config_yaml_edit_nested_sequence_removes_only_exact_canonical_item );
2248+ RUN_TEST (config_yaml_edit_nested_sequence_ignores_foreign_flow_and_block_scalars_issue2209 );
21952249 RUN_TEST (config_yaml_edit_nested_sequence_ambiguity_fails_byte_identically );
21962250 RUN_TEST (config_yaml_edit_remove_on_absent_config_is_a_no_op );
21972251#ifndef _WIN32
0 commit comments