fix: verify and correct new operator behavior#43
Merged
Conversation
- Fix above_percent/below_percent value format: API requires [field_name, percent_float] order (e.g. ["SMA200", 10]), not [percent, field_name] as the naive reading suggested. Verified via live API: [10, "SMA200"] returns "type of percent must be float64" error while ["SMA200", 10.5] works correctly. - Clarify has/has_none_of operators: work on set/array-type fields (e.g. typespecs), not string fields (sector, exchange) — string fields return "Unsupported string operation". - Widen ScreenStocksInput.value type to include [string, number] tuple for percent operators and make value optional (empty/not_empty are already validated at runtime). - Add all 6 new operators to the MCP tool schema enums in index.ts for all 4 tools (screen_stocks, screen_forex, screen_crypto, screen_etf) with correct usage examples. - Add 10 new unit tests covering all 6 new operators: conversion correctness, no-value behavior for empty/not_empty, and value-required enforcement for other new operators. Test count: 84 → 94, all passing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR verifies each of the 6 new operators end-to-end against the live TradingView scanner API and fixes the issues found.
Findings
empty→"empty"right: undefinedcorrectly dropped byJSON.stringifynot_empty→"nempty"above_percent→"above%"[field_name, percent_float]— e.g.["SMA200", 10]— NOT[percent, field]. Sending[10, "SMA200"]returns"type of percent must be float64"errorbelow_percent→"below%"hastypespecs; returns"Unsupported string operation has"on string fields likesectorhas_none_ofhasChanges
src/api/types.tsScreenStocksInput.filter[].valuetype to include[string, number]tuple (forabove_percent/below_percent)valueoptional at the type level (runtime validation invalidateAndConvertFiltersalready handles theempty/not_emptyspecial case)src/index.tsenumin every tool schema (screen_stocks,screen_forex,screen_crypto,screen_etf) — they were missing, so AI assistants using these tools had no way to discover themvaluefield descriptions and examples to show the correct[field_name, percent]format forabove_percent/below_percentand the array format forhas/has_none_ofsrc/tests/screen.test.tsempty/not_empty, value-required enforcement for other operators)validOperatorslist to includeabove_percent,below_percent,has,has_none_of(4 of the 6 new ones —empty/not_emptytested separately since they don't require a value)Test plan
npm run buildpasses (TypeScript clean)npm test— 94 tests, 0 failuresempty/nemptyreturn correct results (3 stocks vs 2235 stocks with dividend filter)above%with["SMA200", 10.5]returns stocks withclose > SMA200 * 1.105below%with["SMA200", 10.5]returns 2078 large-caps below their SMA200 by 10.5%haswithtypespecs+["common"]returns 206 resultshas_none_ofwithtypespecs+["preferred"]returns 290 resultsin_range,greater,crosses_above) still work correctly