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

@ -217,14 +217,17 @@
packaged-cli = pkgs.runCommand "idx-packaged-cli"
{ nativeBuildInputs = with pkgs; [ bash jq ]; }
''
# The mock provider reads fixtures relative to the working dir.
mkdir -p tests
cp -r ${./crates/idx-core/tests/fixtures} tests/fixtures
export HOME="$TMPDIR"
export HOME="$TMPDIR" XDG_CACHE_HOME="$TMPDIR/cache" XDG_CONFIG_HOME="$TMPDIR/config"
${idxPackage}/bin/idx -o json version | jq -e '.version | type == "string"'
${idxPackage}/bin/idx completions bash | bash -n
IDX_USE_MOCK_PROVIDER=1 ${idxPackage}/bin/idx -o json stocks quote BBCA \
| jq -e '.[0].price | type == "number"'
# Release builds have no mock provider; an offline cache miss
# exercises the JSON error contract and exit-code classes.
set +e
${idxPackage}/bin/idx --offline -o json stocks quote BBCA 2>err.json
status=$?
set -e
test "$status" -eq 3
jq -e '.code == "CACHEMISS"' err.json
touch "$out"
'';
install-script-sh = installerCheck "sh";