Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows
fix: parse JSON in is_plugin_installed() (#1850)
Maximilian Roosca2a61751741
diff --git a/src/commands/config/show.rs b/src/commands/config/show.rsindex 6de48a6d6..dc199da55 100644--- a/src/commands/config/show.rs+++ b/src/commands/config/show.rs@@ -110,8 +110,13 @@ pub(super) fn is_plugin_installed() -> bool {return false;};- // Look for "worktrunk@worktrunk" in the plugins object- content.contains("\"worktrunk@worktrunk\"")+ let Ok(json) = serde_json::from_str::<serde_json::Value>(&content) else {+ return false;+ };++ json.get("plugins")+ .and_then(|p| p.get("worktrunk@worktrunk"))+ .is_some()}/// Check if the statusline is configured in Claude Code settingsdiff --git a/tests/integration_tests/config_show.rs b/tests/integration_tests/config_show.rsindex 3e533161e..8b6b1b2ff 100644--- a/tests/integration_tests/config_show.rs+++ b/tests/integration_tests/config_show.rs@@ -2738,6 +2738,30 @@ fn test_plugins_claude_install(mut repo: TestRepo, temp_home: TempDir) {});}+#[rstest]+fn test_plugins_claude_install_invalid_plugins_json(mut repo: TestRepo, temp_home: TempDir) {+ repo.setup_mock_ci_tools_unauthenticated();+ repo.setup_mock_claude_with_plugins();++ // Write invalid JSON to the plugins file — is_plugin_installed() should+ // treat this as "not installed" and the install command should proceed+ let plugins_dir = temp_home.path().join(".claude/plugins");+ fs::create_dir_all(&plugins_dir).unwrap();+ fs::write(plugins_dir.join("installed_plugins.json"), "not valid json").unwrap();++ let settings = setup_snapshot_settings_with_home(&repo, &temp_home);+ settings.bind(|| {+ let mut cmd = wt_command();+ repo.configure_wt_cmd(&mut cmd);+ repo.configure_mock_commands(&mut cmd);+ cmd.args(["config", "plugins", "claude", "install", "--yes"])+ .current_dir(repo.root_path());+ set_temp_home_env(&mut cmd, temp_home.path());++ assert_cmd_snapshot!(cmd);+ });+}+#[rstest]fn test_plugins_claude_install_already_installed(mut repo: TestRepo, temp_home: TempDir) {repo.setup_mock_ci_tools_unauthenticated();diff --git a/tests/snapshots/integration__integration_tests__config_show__plugins_claude_install_invalid_plugins_json.snap b/tests/snapshots/integration__integration_tests__config_show__plugins_claude_install_invalid_plugins_json.snapnew file mode 100644index 000000000..203cc5f48--- /dev/null+++ b/tests/snapshots/integration__integration_tests__config_show__plugins_claude_install_invalid_plugins_json.snap@@ -0,0 +1,50 @@+---+source: tests/integration_tests/config_show.rs+info:+ program: wt+ args:+ - config+ - plugins+ - claude+ - install+ - "--yes"+ env:+ APPDATA: "[TEST_CONFIG_HOME]"+ CLICOLOR_FORCE: "1"+ COLUMNS: "500"+ GIT_AUTHOR_DATE: "2025-01-01T00:00:00Z"+ GIT_COMMITTER_DATE: "2025-01-01T00:00:00Z"+ GIT_CONFIG_GLOBAL: "[TEST_GIT_CONFIG]"+ GIT_CONFIG_SYSTEM: /dev/null+ GIT_EDITOR: ""+ GIT_TERMINAL_PROMPT: "0"+ HOME: "[TEST_HOME]"+ LANG: C+ LC_ALL: C+ MOCK_CONFIG_DIR: "[MOCK_CONFIG_DIR]"+ NO_COLOR: ""+ PATH: "[PATH]"+ PSModulePath: ""+ RUST_LOG: warn+ SHELL: ""+ TERM: alacritty+ USERPROFILE: "[TEST_HOME]"+ WORKTRUNK_APPROVALS_PATH: "[TEST_APPROVALS]"+ WORKTRUNK_CONFIG_PATH: "[TEST_CONFIG]"+ WORKTRUNK_SYSTEM_CONFIG_PATH: "[TEST_SYSTEM_CONFIG]"+ WORKTRUNK_TEST_CLAUDE_INSTALLED: "1"+ WORKTRUNK_TEST_DELAYED_STREAM_MS: "-1"+ WORKTRUNK_TEST_EPOCH: "1735776000"+ WORKTRUNK_TEST_NUSHELL_ENV: "0"+ WORKTRUNK_TEST_POWERSHELL_ENV: "0"+ WORKTRUNK_TEST_SKIP_URL_HEALTH_CHECK: "1"+ XDG_CONFIG_HOME: "[TEST_CONFIG_HOME]"+---+success: true+exit_code: 0+----- stdout -----++----- stderr -----+[36m◎[39m [36mAdding plugin from marketplace...[39m+[36m◎[39m [36mInstalling plugin...[39m+[32m✓[39m [32mPlugin installed[39m