Hmbown/CodeWhale · error

Expected Ok when cwd anchors relative path, got

Error message

Expected Ok when cwd anchors relative path, got {other:?}

What it means

Test panic asserting that when an MCP server command is a relative path (e.g. server/mcp_server.py), providing a cwd (server.cwd = Some("/tmp/codewhale-project")) makes doctor_check_mcp_server classify it as Ok (stdio) rather than warning about an unanchored relative path. The panic fires when any non-Ok variant is returned.

Solutions

  1. Read the {other:?} payload in the panic message to see the actual Warning/Error detail.
  2. Verify doctor_check_mcp_server consults server.cwd before flagging relative command paths.
  3. If relative-path-with-cwd should now warn by policy, update the test to the new expectation.

Example fix

// before
server.cwd = Some(PathBuf::from("/tmp/codewhale-project"));
// after (if the doctor needs the cwd to exist)
// ensure the anchor directory exists in the test environment:
std::fs::create_dir_all("/tmp/codewhale-project").ok();
Defensive patterns

Strategy: validation

Validate before calling

if Path::new(cmd).is_relative() && server.cwd.is_none() { // expect a warning, not Ok }

Type guard

fn is_ok_status(s: &McpServerDoctorStatus) -> bool { matches!(s, McpServerDoctorStatus::Ok(_)) }

Try / catch

match doctor_check_mcp_server(&server) { Ok(d) => assert!(d.contains("stdio")), other => panic!("cwd-anchored relative path misclassified: {other:?}") }

Prevention

When it happens

Trigger: Calling doctor_check_mcp_server on an McpServerConfig whose command is a relative path and whose cwd is set; the doctor returns Warning/Error instead of resolving the relative path against cwd and returning Ok.

Common situations: Regression in the doctor's relative-path-vs-cwd resolution logic; cwd field dropped or ignored during a config refactor; test executable path handling changed.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@433685b202 (2026-09-15). Data as JSON: /api/errors/4fda9daaab3d1993. Report an issue: GitHub.

Appendix: source

Thrown at crates/tui/src/lib.rs:19456

            assert!(
                matches!(
                    doctor_check_mcp_server(&server),
                    McpServerDoctorStatus::Warning(_)
                ),
                "Expected a relative-path warning for {command} {argument}"
            );
        }
    }

    #[test]
    fn test_relative_stdio_path_arg_with_cwd_is_ok() {
        let executable = std::env::current_exe().expect("current test executable");
        let executable = executable.to_string_lossy();
        let mut server = make_server(Some(&executable), &["server/mcp_server.py"], None);
        server.cwd = Some(PathBuf::from("/tmp/codewhale-project"));
        match doctor_check_mcp_server(&server) {
            McpServerDoctorStatus::Ok(detail) => assert!(detail.contains("stdio")),
            other => panic!("Expected Ok when cwd anchors relative path, got {other:?}"),
        }
    }

    #[test]
    fn test_self_hosted_absolute_is_ok() {
        let executable = std::env::current_exe().expect("current test executable");
        let executable = executable.to_string_lossy();
        let server = make_server(Some(&executable), &["serve", "--mcp"], None);
        match doctor_check_mcp_server(&server) {
            McpServerDoctorStatus::Ok(detail) => assert!(detail.contains("stdio server")),
            McpServerDoctorStatus::Warning(detail) => {
                panic!("Absolute path should not warn: {detail}")
            }
            McpServerDoctorStatus::Error(detail) => panic!("unexpected error: {detail}"),
        }
    }

    #[cfg(test)]

View on GitHub (pinned to 433685b202)