AI plumbing 3a-tests: a few comprehensive AI tests per layer

Merged
JO
4d ago
+185-2327

Part 3a-tests of the AI plumbing series (part of #4419). Top of a GitHub stack on refactor/ai-plumbing: 3a (#5501) ← 3a-tidy (#5502) ← 3a-tests (this PR). Test-only.

Why

The AI plumbing layers (2a–2f, 3a) added unit tests that restate the implementation one method at a time. Many of them break on any refactor without ever catching a regression. This PR keeps a few comprehensive tests per layer: the scenario and contract tests, every regression case, the guards, and the migration, live and e2e tests.

What stays, by layer

LayerKeepers
Transports, instrumentationai_transport_contract_test, ai_transport_generate_test, usage_subscriber_test, subscribers_test
Routing, config, consentai_agreement_test, ai_config_test, ai_routing_matrix_test
Generations, jobs, requestersgeneration_test, generation_job_test, auto_categorizer_test
PDF, documentspdf_reading_test, ai_documents_test, process_pdf_job_test
Jev, shadowshadow_job_test, ai_transport_judge_test, categorize_transaction_test
Health, capsuleprobe_job_test, system_health_controller_test, system/admin/system_health_test

Kept whole:

  • test/e2e/ai, test/models/ai/live and their cassettes;
  • test/migrations;
  • the guards: ai_routing_matrix_test, ai_feature_guard_test, ai_schemas_test, ai_prompts_test, ai_shadow_test, and the two RuboCop cop tests.

The routing matrix requires one test file per generation and per judgement, so each of those files keeps one or two cases.

Every case added in 2e and 2f's review rounds stays. Where its file was deleted, the case moved into its layer's keeper:

  • the base URL rule;
  • NO_PROXY CIDR, names-only and leading-dot matching;
  • the image-refusal and gateway-diagnostic error mapping;
  • an overload reported as a 400 staying retryable;
  • RubyLLM logging no request body or key at debug;
  • the OTLP + header.

These moved into ai_transport_contract_test and subscribers_test.

Size: in the 50 test files this PR touches, cases go from 685 to 491 and lines from 9,595 to 7,453. That includes the 38 cases restored after review: each was the only check on a behaviour (see the review thread).

Verification

2026-11-21:

  • full bin/rails test: 18,394 runs, 0 failures (the four moved NO_PROXY cases were fixed and rerun green: 83 runs in the two keeper files);
  • AI_E2E=1 bin/rails test test/e2e/ai: 12 runs, 67 assertions, 0 failures, against live free models and Cohere;
  • test/system/admin/system_health_test.rb: 5 runs, 0 failures;
  • bin/rubocop (3,629 files), erb_lint --lint-all, Biome and Brakeman: clean.

šŸ¤– Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Added coverage for reading large text documents in bounded chunks, including continuation through very large character offsets.
    • Added checks for compatible endpoint normalization, proxy matching, error classification, and protecting request details and credentials from debug logs.
    • Added validation that Jev endpoints reject a zero parallel-request limit.
    • Updated and reduced coverage across AI, document, PDF, assistant, and indexing workflows. These test changes do not indicate changes to runtime behavior.