Skip to main content

majordomus_cli/bench/
system.rs

1//! The transports' own operations, benchmarked beside the capabilities: the MCP protocol
2//! methods a client calls before any tool, and the HTTP projection's infrastructure
3//! routes. Declared once, here, as data; the projection turns them into targets and the
4//! coverage into requirements.
5
6use schemars::JsonSchema;
7use serde::{Deserialize, Serialize};
8
9/// One system target.
10#[derive(
11    Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize, JsonSchema,
12)]
13#[serde(rename_all = "snake_case")]
14pub enum SystemTarget {
15    /// A fresh `majordomus mcp` process: spawn, `initialize`, first `tools/list`.
16    McpProcessCold,
17    /// `initialize` on a running process.
18    McpInitialize,
19    /// `ping`.
20    McpPing,
21    /// `tools/list`.
22    McpToolsList,
23    /// `resources/list`.
24    McpResourcesList,
25    /// `resources/read` of the first declarative resource.
26    McpResourcesRead,
27    /// `GET /`: the topology as JSON, what a client that asks for no page receives.
28    HttpIndex,
29    /// `GET /` with `Accept: text/html`: the home page, rendered from the topology.
30    HttpHome,
31    /// `GET /openapi.json`.
32    HttpOpenApi,
33    /// `GET /swagger`.
34    HttpSwagger,
35    /// `GET /cockpit`: the Cockpit's landing page, rendered.
36    HttpCockpitOverview,
37    /// `GET /cockpit/capabilities`: the whole registry as a table, the widest page there is.
38    HttpCockpitCapabilities,
39    /// `GET /cockpit/graphs/registry`: a page whose content is a derived graph.
40    HttpCockpitGraph,
41    /// `GET /` over the live view a served process follows the repository with: the
42    /// per-request generation check (a stamp of the watched git control files, compared
43    /// with the generation held) and the surface resolution, on the cheapest route there
44    /// is. Its difference from `system.http.index` is what following git costs a request.
45    HttpIndexLive,
46}
47
48impl SystemTarget {
49    /// Every system target, in a stable order.
50    pub const ALL: [SystemTarget; 14] = [
51        SystemTarget::McpProcessCold,
52        SystemTarget::McpInitialize,
53        SystemTarget::McpPing,
54        SystemTarget::McpToolsList,
55        SystemTarget::McpResourcesList,
56        SystemTarget::McpResourcesRead,
57        SystemTarget::HttpIndex,
58        SystemTarget::HttpHome,
59        SystemTarget::HttpOpenApi,
60        SystemTarget::HttpSwagger,
61        SystemTarget::HttpCockpitOverview,
62        SystemTarget::HttpCockpitCapabilities,
63        SystemTarget::HttpCockpitGraph,
64        SystemTarget::HttpIndexLive,
65    ];
66
67    /// The stable key results and baselines use.
68    pub fn key(self) -> &'static str {
69        match self {
70            SystemTarget::McpProcessCold => "system.mcp.process_cold",
71            SystemTarget::McpInitialize => "system.mcp.initialize",
72            SystemTarget::McpPing => "system.mcp.ping",
73            SystemTarget::McpToolsList => "system.mcp.tools_list",
74            SystemTarget::McpResourcesList => "system.mcp.resources_list",
75            SystemTarget::McpResourcesRead => "system.mcp.resources_read",
76            SystemTarget::HttpIndex => "system.http.index",
77            SystemTarget::HttpHome => "system.http.home",
78            SystemTarget::HttpOpenApi => "system.http.openapi",
79            SystemTarget::HttpSwagger => "system.http.swagger",
80            SystemTarget::HttpCockpitOverview => "system.http.cockpit_overview",
81            SystemTarget::HttpCockpitCapabilities => "system.http.cockpit_capabilities",
82            SystemTarget::HttpCockpitGraph => "system.http.cockpit_graph",
83            SystemTarget::HttpIndexLive => "system.http.live.index",
84        }
85    }
86
87    /// The transport the target belongs to.
88    pub fn transport(self) -> super::Transport {
89        match self {
90            SystemTarget::McpProcessCold
91            | SystemTarget::McpInitialize
92            | SystemTarget::McpPing
93            | SystemTarget::McpToolsList
94            | SystemTarget::McpResourcesList
95            | SystemTarget::McpResourcesRead => super::Transport::Mcp,
96            SystemTarget::HttpIndex
97            | SystemTarget::HttpHome
98            | SystemTarget::HttpOpenApi
99            | SystemTarget::HttpSwagger
100            | SystemTarget::HttpCockpitOverview
101            | SystemTarget::HttpCockpitCapabilities
102            | SystemTarget::HttpCockpitGraph
103            | SystemTarget::HttpIndexLive => super::Transport::Http,
104        }
105    }
106
107    /// One line of what is measured.
108    pub fn description(self) -> &'static str {
109        match self {
110            SystemTarget::McpProcessCold => {
111                "spawn a majordomus mcp process, initialize, first tools/list"
112            }
113            SystemTarget::McpInitialize => "initialize on a running process",
114            SystemTarget::McpPing => "ping: the protocol round trip with nothing behind it",
115            SystemTarget::McpToolsList => "tools/list",
116            SystemTarget::McpResourcesList => "resources/list",
117            SystemTarget::McpResourcesRead => "resources/read of the first declarative resource",
118            SystemTarget::HttpIndex => "GET / (the topology as JSON)",
119            SystemTarget::HttpHome => {
120                "GET / with Accept: text/html (the home page, rendered from the topology)"
121            }
122            SystemTarget::HttpOpenApi => "GET /openapi.json",
123            SystemTarget::HttpSwagger => "GET /swagger (the Swagger UI shell)",
124            SystemTarget::HttpCockpitOverview => {
125                "GET /cockpit (the Cockpit's landing page, server-rendered)"
126            }
127            SystemTarget::HttpCockpitCapabilities => {
128                "GET /cockpit/capabilities (every capability as a table: the widest page)"
129            }
130            SystemTarget::HttpCockpitGraph => {
131                "GET /cockpit/graphs/registry (a page whose content is a derived graph)"
132            }
133            SystemTarget::HttpIndexLive => {
134                "GET / over the live view a served process uses (the per-request git stamp and surface resolution)"
135            }
136        }
137    }
138}