refactor(core): compile the mock provider only with a testing feature

Phase 3a of docs/DESIGN.md. MockProvider moves to api/mock.rs, and it,
the embedded MSN fixture bodies, and the IDX_MOCK_* hooks compile only
with idx-core's new `testing` feature. idx-cli enables it as a
dev-dependency, so `cargo test` keeps the fixture-backed provider while
release binaries no longer embed fixture data or honor
IDX_USE_MOCK_PROVIDER. Parser helpers used only by the mock are gated
the same way.

The packaged-cli flake check no longer relies on the mock; it checks
an offline cache miss (JSON CACHEMISS, exit 3) instead.

Goldens unchanged; clippy is clean with and without `testing`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
hermes 2026-10-14 09:31:12 +00:00
commit e78d9fcecd
13 changed files with 214 additions and 161 deletions

View file

@ -34,6 +34,17 @@ impl MsnClient {
Self { agent }
}
#[cfg(not(feature = "testing"))]
fn mock_error() -> Option<IdxError> {
None
}
#[cfg(not(feature = "testing"))]
fn mock_body(_endpoint: &str) -> Option<&'static str> {
None
}
#[cfg(feature = "testing")]
fn mock_error() -> Option<IdxError> {
if std::env::var("IDX_USE_MOCK_PROVIDER").is_ok() && std::env::var("IDX_MOCK_ERROR").is_ok()
{
@ -43,6 +54,7 @@ impl MsnClient {
}
}
#[cfg(feature = "testing")]
fn mock_body(endpoint: &str) -> Option<&'static str> {
if std::env::var("IDX_USE_MOCK_PROVIDER").is_err() {
return None;
@ -271,6 +283,7 @@ impl MsnClient {
url: &str,
request: &ScreenerRequest,
) -> Result<RawScreenerResponse, IdxError> {
#[cfg(feature = "testing")]
if std::env::var("IDX_USE_MOCK_PROVIDER").is_ok() {
if let Some(err) = Self::mock_error() {
return Err(err);

View file

@ -23,6 +23,7 @@ use map::{
parse_news, parse_profile, parse_quote, parse_screener_results, parse_sentiment,
};
#[cfg(feature = "testing")]
pub(crate) use parse::{parse_fundamentals_from_str, parse_history_from_str, parse_quote_from_str};
pub struct MsnProvider {