Skip to content

Validate each test request against its own operation - #47

Merged
willnet merged 1 commit into
willnet:mainfrom
ralder:fix-request-object-memoization
Oct 2, 2026
Merged

willnet merged 1 commit into
willnet:mainfrom
ralder:fix-request-object-memoization

Conversation

@ralder

@ralder ralder commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

Problem

Committee::Rails::Test::Methods#request_object memoizes Committee::Rails::RequestObject.new(integration_session.request) in an ivar for the whole test example:

def request_object
  @request_object ||= Committee::Rails::RequestObject.new(integration_session.request)
end

The core committee gem already fixed the same mine in interagent/committee#485 (committee 5.6.4): schema_validator is now rebuilt from request_object on each assert_schema_conform, precisely so every request is validated against its own operation. But committee-rails pins request_object itself to the first request of the example, so the core fix only half-works here.

Symptom: in an example with 2+ HTTP requests, the second assert_schema_conform validates the request/response against the first request's operation, producing a misleading Committee::InvalidResponse ("response definition does not exist" / "expected object, but received Array"). Workaround in apps: manually resetting @request_object = nil between requests.

Fix

Mirror the core change: drop the ||= so request_object is rebuilt from the current integration_session.request on every call:

  def request_object
-   @request_object ||= Committee::Rails::RequestObject.new(integration_session.request)
+   Committee::Rails::RequestObject.new(integration_session.request)
  end

@default_schema memoization is intentionally untouched — the schema does not change between requests.

Compatibility

For single-request examples behavior is identical; only multi-request examples change (they now validate correctly). Added a spec covering the scenario: POST /users + assert, then GET /users + assert in one example (fails on main, passes with this change).

🤖 Generated with Claude Code

@willnet
willnet merged commit 1ebfa59 into willnet:main Oct 2, 2026
23 checks passed
@willnet

willnet commented Oct 2, 2026

Copy link
Copy Markdown
Owner

@ralder Thanks!

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.

2 participants