Skip to content

test(ai-proxy): verify the Anthropic Messages upstream request - #14278

Open
Zi-Yi-Ming wants to merge 1 commit into
apache:masterfrom
Zi-Yi-Ming:test/anthropic-messages-request-contract
Open

Zi-Yi-Ming wants to merge 1 commit into
apache:masterfrom
Zi-Yi-Ming:test/anthropic-messages-request-contract

Conversation

@Zi-Yi-Ming

Copy link
Copy Markdown

Description

The Anthropic fixture tests match the recorded response, which the mock selects from X-AI-Fixture. That response alone gives no evidence about the method, configured credentials, or JSON sent upstream.

Use the native Messages path for the existing JSON and SSE fixture cases. The JSON case adds a block-local /v1/messages handler that checks POST, the configured x-api-key, and the decoded model, token limit, and message. A log assertion confirms that the checked handler served the request. The handler still uses the existing fixture loader and recorded response.

Related issue

Refs #13340.

Validation

Run from the APISIX checkout with a dedicated test etcd and the CI-pinned Test::Nginx checkout.

export TEST_NGINX_BINARY="$(command -v openresty)"
export FLUSH_ETCD=1
prove --timer -v -I/opt/test-nginx/lib -I. t/plugin/ai-proxy-fixture.t
prove --timer -v -I/opt/test-nginx/lib -I. t/plugin/ai-proxy-protocol-conversion.t
make utils
./utils/check-test-code-style.sh
git diff --check
  • ai-proxy-fixture.t passed all 51 TAP assertions. ai-proxy-protocol-conversion.t passed all 89.
  • The test style check passed in a temporary checkout containing the patch. git diff --check passed in the working branch.
  • In the temporary checkout, removing the checked handler failed only the verification log assertion. Three separate mutations changed the outbound method to PUT, removed x-api-key, or sent an empty messages array. Each failed the corresponding check.

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)

Assert the method, configured API key, and decoded request body at the test upstream before serving the existing Anthropic fixture response.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant