mirror of
https://github.com/0xrsydn/idx-cli.git
synced 2026-11-07 09:45:36 +00:00
fix: address release review (WAL-aware sync hash, empty MCP inputs)
- Sync hashed only the main database file, but local edits can sit in the -wal sidecar, so an edited database could match an earlier build and be replaced. Checkpoint the WAL before hashing; if changes remain, never take the rebuilt-snapshot path. - MCP tools rejected nothing for empty symbols/sections/kinds and returned an empty success; they now fail with INVALIDINPUT, as the CLI requires input. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
eef118961d
commit
58d421028f
4 changed files with 126 additions and 23 deletions
|
|
@ -99,6 +99,9 @@ for one or more IDX tickers."
|
|||
)]
|
||||
async fn get_quotes(&self, params: Parameters<SymbolsParams>) -> ToolResult {
|
||||
let SymbolsParams { symbols } = params.0;
|
||||
if let Some(err) = empty_input("symbols", &symbols) {
|
||||
return err;
|
||||
}
|
||||
self.live(move |idx| {
|
||||
let quotes = idx.market().quotes(&symbols, CachePolicy::Default)?;
|
||||
Ok(json!({ "quotes": quotes }))
|
||||
|
|
@ -155,6 +158,9 @@ earnings, analyst sentiment, insights, and news. Sections that fail are listed u
|
|||
async fn get_company(&self, params: Parameters<CompanyParams>) -> ToolResult {
|
||||
let CompanyParams { symbol, sections } = params.0;
|
||||
let sections = sections.unwrap_or_else(|| CompanySection::ALL.to_vec());
|
||||
if let Some(err) = empty_input("sections", §ions) {
|
||||
return err;
|
||||
}
|
||||
self.live(move |idx| {
|
||||
let financial = idx.financial();
|
||||
let policy = CachePolicy::Default;
|
||||
|
|
@ -195,6 +201,9 @@ are listed under `errors`; the call fails only if every analysis fails."
|
|||
async fn analyze_stock(&self, params: Parameters<AnalyzeParams>) -> ToolResult {
|
||||
let AnalyzeParams { symbol, kinds } = params.0;
|
||||
let kinds = kinds.unwrap_or_else(|| AnalysisKind::ALL.to_vec());
|
||||
if let Some(err) = empty_input("kinds", &kinds) {
|
||||
return err;
|
||||
}
|
||||
self.live(move |idx| {
|
||||
let analysis = idx.analysis();
|
||||
let policy = CachePolicy::Default;
|
||||
|
|
@ -224,6 +233,9 @@ tickers. Tickers that fail are listed under `failures`."
|
|||
)]
|
||||
async fn compare_stocks(&self, params: Parameters<SymbolsParams>) -> ToolResult {
|
||||
let SymbolsParams { symbols } = params.0;
|
||||
if let Some(err) = empty_input("symbols", &symbols) {
|
||||
return err;
|
||||
}
|
||||
self.live(move |idx| {
|
||||
let comparison = idx.analysis().compare(&symbols, CachePolicy::Default)?;
|
||||
let failures: Vec<Value> = comparison
|
||||
|
|
@ -377,6 +389,17 @@ where
|
|||
})
|
||||
}
|
||||
|
||||
/// An explicitly empty list is an input error, as in the CLI, rather than an
|
||||
/// empty success an agent could mistake for data.
|
||||
fn empty_input<T>(field: &str, values: &[T]) -> Option<ToolResult> {
|
||||
values.is_empty().then(|| {
|
||||
let err = IdxError::InvalidInput(format!("{field} must not be empty"));
|
||||
Ok(CallToolResult::structured_error(Value::Object(error_body(
|
||||
&err,
|
||||
))))
|
||||
})
|
||||
}
|
||||
|
||||
fn to_json<T: Serialize>(value: T) -> Result<Value, IdxError> {
|
||||
serde_json::to_value(value).map_err(|err| IdxError::ParseError(err.to_string()))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -243,6 +243,17 @@ fn errors_carry_cli_codes() {
|
|||
assert!(is_error);
|
||||
assert_eq!(body["code"], "INVALIDINPUT");
|
||||
|
||||
for (tool, arguments) in [
|
||||
("get_quotes", json!({"symbols": []})),
|
||||
("compare_stocks", json!({"symbols": []})),
|
||||
("get_company", json!({"symbol": "BBCA", "sections": []})),
|
||||
("analyze_stock", json!({"symbol": "BBCA", "kinds": []})),
|
||||
] {
|
||||
let (is_error, body) = client.call(tool, arguments);
|
||||
assert!(is_error, "{tool}: {body}");
|
||||
assert_eq!(body["code"], "INVALIDINPUT", "{tool}");
|
||||
}
|
||||
|
||||
// Empty ownership database: investor tools point at the sync path.
|
||||
let status = client.ok("ownership_status", json!({}));
|
||||
assert_eq!(status["populated"], false);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue