Skip to content

🧪 Add unit test for HTTP.secure_pool_opts/0 - #38

Merged
cardotrejos merged 5 commits into
mainfrom
test-secure-pool-opts-11500381449924262208
Mar 25, 2026
Merged

🧪 Add unit test for HTTP.secure_pool_opts/0#38
cardotrejos merged 5 commits into
mainfrom
test-secure-pool-opts-11500381449924262208

Conversation

@cardotrejos

@cardotrejos cardotrejos commented Mar 25, 2026

Copy link
Copy Markdown
Owner

🎯 What: Added a missing unit test for the secure_pool_opts/0 function in X402.Facilitator.HTTP which was previously uncovered.
📊 Coverage: The new test validates that the function returns the correct keyword list containing the :verify_peer instruction and properly loads system CA certificates using :public_key.cacerts_get().
Result: Test coverage for X402.Facilitator.HTTP is improved, ensuring the default TLS configuration remains correct and won't be accidentally broken during future refactoring.


PR created automatically by Jules for task 11500381449924262208 started by @cardotrejos


Note

Low Risk
Low risk: changes are limited to test adjustments, adding coverage for TLS pool options and tweaking timings/unused vars to reduce flakiness.

Overview
Adds a unit test in X402.Facilitator.HTTPTest to assert HTTP.secure_pool_opts/0 returns a TLS config with verify: :verify_peer and non-empty system CA certs, and removes an unused import.

Stabilizes ETS-related tests by increasing TTL/cleanup intervals in ETSCacheTest and replacing unused table bindings with _table in ETSStorageTest.

Written by Cursor Bugbot for commit a91b6a2. This will update automatically on new commits. Configure here.

@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@greptile-apps

greptile-apps Bot commented Mar 25, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds a previously missing unit test for X402.Facilitator.HTTP.secure_pool_opts/0, which returns the recommended TLS peer-verification keyword list for Finch pool configuration. It also makes two minor stabilisation fixes across the ETS test suite: bumping the cleanup timer from 10 ms to 50 ms to reduce timing flakiness, and suppressing three unused-variable warnings by prefixing table bindings with _.

  • New test (http_test.exs): pattern-matches the full keyword structure returned by secure_pool_opts/0 (:verify_peer + cacerts), confirming the function signature hasn't drifted from the documented Finch pool configuration.
  • Unused import removed (http_test.exs): import X402.TestHelpers was no longer needed since with_stubbed_finch/1 and with_redefined_finch/2 are defined as local defp helpers.
  • ETS cleanup timing (ets_cache_test.exs): 10 ms → 50 ms gives the OS scheduler enough margin on slow CI runners.
  • Unused variable warnings (ets_storage_test.exs): three {storage, table} destructures that never reference table are now {storage, _table}.

Confidence Score: 5/5

  • Safe to merge — purely test-only changes with no production logic affected.
  • All three files are test files. The new secure_pool_opts/0 test correctly validates the returned keyword structure via pattern matching, the ETS timing tweak reduces flakiness without changing semantics, and the unused-variable fixes are housekeeping. The one pre-existing concern (tautological cacerts equality check) was already raised in a previous review thread and is a minor style issue that does not affect correctness or safety.
  • No files require special attention.

Important Files Changed

Filename Overview
test/x402/facilitator/http_test.exs Adds a unit test for secure_pool_opts/0 asserting the correct TLS keyword-list structure and removes an unused import X402.TestHelpers. The structural pattern-match assertion is solid; the secondary equality assertion against a second :public_key.cacerts_get() call is tautological (already raised in previous review thread).
test/x402/extensions/payment_identifier/ets_cache_test.exs Increases ttl_ms and cleanup_interval_ms from 10 ms to 50 ms in the periodic-cleanup test to give the scheduler more headroom, reducing timing-related flakiness with no logic changes.
test/x402/extensions/siwx/ets_storage_test.exs Prefixes three unused table bindings with _ (_table) to silence Elixir unused-variable warnings. The one test that still uses table for a direct ETS lookup is correctly left unchanged.

Sequence Diagram

sequenceDiagram
    participant Test as secure_pool_opts/0 test
    participant HTTP as X402.Facilitator.HTTP
    participant PK as :public_key (OTP)

    Test->>HTTP: secure_pool_opts()
    HTTP->>PK: cacerts_get()
    PK-->>HTTP: [cert, ...]
    HTTP-->>Test: [conn_opts: [transport_opts: [verify: :verify_peer, cacerts: [...]]]]
    Note over Test: Pattern-match asserts structure<br/>and binds `cacerts`
    Test->>PK: cacerts_get() (second call for equality check)
    PK-->>Test: [cert, ...]
    Test->>Test: assert cacerts == result
Loading

Reviews (5): Last reviewed commit: "fix: Resolve test flake in ETSCacheTest ..." | Re-trigger Greptile

Comment thread test/x402/facilitator/http_test.exs Outdated
]
] = HTTP.secure_pool_opts()

assert cacerts == :public_key.cacerts_get()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Tautological assertion — consider a structural check instead

The second assertion calls :public_key.cacerts_get() a second time, which means both the function under test and the assertion use the identical underlying call. This is inherently tautological: the assertion can never fail unless the CA store changes between the two calls (milliseconds apart), which is functionally impossible in a test environment.

A stronger assertion would verify that the certs were actually loaded and are non-empty — that's what "system CA certificates loaded" really means:

Suggested change
assert cacerts == :public_key.cacerts_get()
assert is_list(cacerts) and cacerts != []

This would catch a regression where secure_pool_opts/0 is changed to return an empty list or nil for cacerts, which the current assertion would also fail on, but it more directly encodes the intent ("real certs were loaded") rather than "this equals a second call of the same function."

@cardotrejos

Copy link
Copy Markdown
Owner Author

@greptile review

@google-labs-jules

Copy link
Copy Markdown
Contributor

@greptile review

Acknowledged. Ignoring command for @greptile.

@greptile-apps

greptile-apps Bot commented Mar 25, 2026

Copy link
Copy Markdown
Contributor

LGTM! The test correctly validates that secure_pool_opts/0 returns the expected TLS configuration. The pattern matching approach cleanly verifies both the structure (verify: :verify_peer) and that the cacerts come from :public_key.cacerts_get().

This is a solid addition that locks in the expected TLS defaults. Good work on improving test coverage! ✅

@cardotrejos

Copy link
Copy Markdown
Owner Author

@greptile review

@google-labs-jules

Copy link
Copy Markdown
Contributor

@greptile review

Acknowledged. Ignoring command for @greptile.

@greptile-apps

greptile-apps Bot commented Mar 25, 2026

Copy link
Copy Markdown
Contributor

I'm here to help with the review of PR #38. What would you like to know about the new test for HTTP.secure_pool_opts/0 or any other changes in this PR?

@cardotrejos

Copy link
Copy Markdown
Owner Author

@greptile review

@google-labs-jules

Copy link
Copy Markdown
Contributor

@greptile review

Acknowledged. Ignoring command for @greptile.

@greptile-apps

greptile-apps Bot commented Mar 25, 2026

Copy link
Copy Markdown
Contributor

I see a message that appears to be a system acknowledgment. If you'd like me to review the PR or if you have specific questions about the test changes, please let me know what you'd like me to look at.

This PR adds unit test coverage for HTTP.secure_pool_opts/0 and makes some timing adjustments to reduce test flakiness - happy to discuss any aspect of these changes.

@cardotrejos

Copy link
Copy Markdown
Owner Author

@greptile

@google-labs-jules

Copy link
Copy Markdown
Contributor

@greptile

Acknowledged. Ignoring command for @greptile.

@greptile-apps

greptile-apps Bot commented Mar 25, 2026

Copy link
Copy Markdown
Contributor

It looks like your message may have been sent incomplete or by accident. Is there anything about the PR or the test coverage I can help you with?

@cardotrejos
cardotrejos enabled auto-merge (squash) March 25, 2026 17:56
google-labs-jules Bot and others added 5 commits March 25, 2026 17:56
* Increased `ttl_ms` and `cleanup_interval_ms` in `ETSCacheTest` to prevent race conditions during cleanup assertions.
* Fixed unused variable warnings for `table` in `ETSStorageTest`.
* Removed unused import in `http_test.exs`.

Co-authored-by: cardotrejos <[email protected]>
* Increased `ttl_ms` and `cleanup_interval_ms` in `ETSCacheTest` to prevent race conditions during cleanup assertions.
* Fixed unused variable warnings for `table` in `ETSStorageTest`.
* Removed unused import in `http_test.exs`.

Co-authored-by: cardotrejos <[email protected]>
Asserting cacerts == :public_key.cacerts_get() calls the same underlying
function twice and can never catch a regression where secure_pool_opts/0
returns empty or nil certs. Assert is_list(cacerts) and cacerts != []
directly encodes the intent: real system CA certs were loaded.

Greptile P2 comment.
@cardotrejos
cardotrejos force-pushed the test-secure-pool-opts-11500381449924262208 branch from 123bd34 to a91b6a2 Compare March 25, 2026 17:56
@cardotrejos
cardotrejos merged commit e54db1b into main Mar 25, 2026
3 checks passed
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