CI: refuse provider HTTP outside live tests

Merged
JO
11d ago
+134-1

Stacked on #4775 (its parent in the stack); targets refactor/ai-plumbing like the rest of the AI plumbing stack. The diff shows #4775's commit until that merges.

Problem

The suite already refuses unstubbed HTTP (VCR raises VCR::Errors::UnhandledHTTPRequestError), but nothing stops an edit from quietly re-enabling the network in a test file. WebMock.allow_net_connect! is a one-line addition that would leak real provider calls and real keys from the test process — the failure would look like an innocent live test that passes and bills someone.

What

Two halves of the same guard, referencing the RubyLLM Workbench comparison (R13):

  1. test/lib/ai_network_policy_test.rb — pins the existing unhandled-request refusal (an unstubbed request to api.openai.com raises VCR::Errors::UnhandledHTTPRequestError), and scans every test and test-support file for network-opening calls (allow_net_connect, WebMock.allow/disable/enable, VCR.turned_off, VCR.configuration.record=). test/support/ai_test_helper.rb's with_ai_live stays the only exception, scoped to a block and only live under AI_LIVE=1/RECORD_CASSETTES=1.
  2. script/ci/deny_provider_http.rb — a dependency-free CI step wired into both the unit and the system test jobs, before tests boot. Fails the build with the offending files listed.

Verification

  • Injecting a WebMock.allow_net_connect! line into a test file makes both halves fail, with the file and pattern named; removing it restores green.
  • bin/rails test test/lib/ai_network_policy_test.rb green.
  • No live provider calls; no environment variables touched.

Notes

Provider access in tests stays where it belongs: recorded cassettes under AI_LIVE=1/RECORD_CASSETTES=1 via with_ai_cassette/with_ai_live.


Summary by cubic

Prevents test files from quietly re-enabling live provider HTTP, which would leak real API calls and keys from the test process. VCR already refuses unstubbed requests, but a one-line WebMock.allow_net_connect! could bypass that and make a live test pass while billing someone.

  • script/ci/deny_provider_http.rb owns the list of network-opening patterns; test/lib/ai_network_policy_test.rb runs it against the repo and scratch test files and pins the unhandled-request refusal, so the two copies can't drift.
  • The dependency-free CI gate runs in the unit and system test jobs and fails the build with the offending files listed. It also catches less direct openers: disable_net_connect!(allow:), ignore_hosts, ignore_request (only test_helper's Selenium line is allowlisted), and cassettes recording with :all, :new_episodes, or :once; the default record: :none makes a missing cassette fail instead of recording live.
  • test/support/ai_test_helper.rb's with_ai_live stays the only exception, scoped to a block and active only under AI_LIVE=1 or RECORD_CASSETTES=1; it raises otherwise, so calling it directly can't open the network.

Note: the diff also carries the parent stack's generations refactor, squashed in as one commit.

Summary by CodeRabbit

  • New Features
    • Transaction categorization, merchant detection, merchant website enhancement, and bill setup suggestions run through a shared background workflow.
    • Added an API endpoint to view rule-run progress, including work awaiting AI processing and completion status.
    • AI prompt settings use one shared categorization prompt and one merchant-detection prompt.
  • Improvements
    • AI processing adapts batch sizes to model limits and retries smaller batches when responses exceed limits or cannot be used.
    • Merchant enhancement preserves existing websites and merges duplicate merchants when possible.
    • Settings display differing prompt text that may be lost until the changes are saved.