@@ -7349,6 +7349,40 @@ TEST(cli_opencode_honors_custom_config) {
73497349 PASS();
73507350}
73517351
7352+ /* Discussion #1560: OpenCode reads either opencode.json or opencode.jsonc, but
7353+ * we always wrote the .json name. A user whose real config is .jsonc got a
7354+ * SECOND file that OpenCode ignores — the MCP server silently never appeared
7355+ * while the install reported success. Prefer an existing .jsonc; with neither
7356+ * present, .json is still created, so fresh installs are unchanged. */
7357+ TEST(cli_opencode_prefers_existing_jsonc_config_discussion1560) {
7358+ char tmpdir[256];
7359+ snprintf(tmpdir, sizeof(tmpdir), "/tmp/cli-opencode-jsonc-XXXXXX");
7360+ if (!cbm_mkdtemp(tmpdir))
7361+ FAIL("cbm_mkdtemp failed");
7362+ char config_dir[512];
7363+ snprintf(config_dir, sizeof(config_dir), "%s/.config/opencode", tmpdir);
7364+ test_mkdirp(config_dir);
7365+ char jsonc_path[640];
7366+ snprintf(jsonc_path, sizeof(jsonc_path), "%s/opencode.jsonc", config_dir);
7367+ write_test_file(jsonc_path, "{\n // user's hand-written config\n \"theme\": \"dark\"\n}\n");
7368+
7369+ char *saved_path = save_test_env("PATH");
7370+ char *saved_file = save_test_env("OPENCODE_CONFIG");
7371+ cbm_setenv("PATH", tmpdir, 1);
7372+ cbm_unsetenv("OPENCODE_CONFIG");
7373+
7374+ char *json = cbm_build_install_plan_json(tmpdir, "/usr/local/bin/codebase-memory-mcp");
7375+ bool targets_jsonc = json && strstr(json, "/.config/opencode/opencode.jsonc") != NULL;
7376+
7377+ free(json);
7378+ restore_test_env("PATH", saved_path);
7379+ restore_test_env("OPENCODE_CONFIG", saved_file);
7380+ test_rmdir_r(tmpdir);
7381+ if (!targets_jsonc)
7382+ FAIL("an existing opencode.jsonc must be the install target, not a new opencode.json");
7383+ PASS();
7384+ }
7385+
73527386TEST(cli_opencode_config_dir_detects_without_retargeting_global_json) {
73537387 char tmpdir[256];
73547388 snprintf(tmpdir, sizeof(tmpdir), "/tmp/cli-opencode-dir-XXXXXX");
@@ -12416,6 +12450,7 @@ SUITE(cli) {
1241612450 RUN_TEST(cli_antigravity_does_not_imply_gemini);
1241712451 RUN_TEST(cli_antigravity_plan_uses_documented_global_files);
1241812452 RUN_TEST(cli_opencode_honors_custom_config);
12453+ RUN_TEST(cli_opencode_prefers_existing_jsonc_config_discussion1560);
1241912454 RUN_TEST(cli_opencode_config_dir_detects_without_retargeting_global_json);
1242012455 RUN_TEST(cli_kiro_and_hermes_homes_are_honored);
1242112456 RUN_TEST(cli_detect_agents_finds_official_kiro_cli_executable);
0 commit comments