Skip to content

Cover env binding detection with tests - #211

Open
ayaangazali wants to merge 3 commits into
pydantic:mainfrom
ayaangazali:env-binding-detection-tests
Open

Cover env binding detection with tests#211
ayaangazali wants to merge 3 commits into
pydantic:mainfrom
ayaangazali:env-binding-detection-tests

Conversation

@ayaangazali

Copy link
Copy Markdown
Contributor

instrumentEnv decides which instrumentation every Worker binding gets, and it had no tests. A regression in one of those shape checks would quietly route a binding to the wrong wrapper or leave it uninstrumented, and nothing would fail, so this adds coverage for each branch: values that are not proxyable pass through, version metadata is returned untouched so accesses stay untraced, and KV, queues, Durable Objects, Analytics Engine and D1 each get wrapped, plus an object matching no shape being left alone.

The cases are driven through instrumentEnv rather than the detector functions, since those are private, and they identify each binding by whether its methods came back wrapped. I sanity-checked that they actually bite by stubbing individual detectors to false: neutering the queue check fails the queue case and neutering the Analytics Engine check fails that one, so the assertions are pinned to the dispatch and not just to the mocks.

Ran the repo preflight and pnpm run check, both green, 65 passing in the package. Test only, so no changeset.

One thing I noticed while writing these and did not touch: isD1Database is the only detector that omits the !isJSRPC(item) guard its five siblings all have. It is unreachable today because isJSRPC is checked first in the dispatch chain, so a service binding never gets that far, but it would matter if that ordering ever changed. Happy to send it as a separate one-liner if you want the guard there for symmetry.

quick disclosure: put this together with Claude Code and read it over myself. Freshman still learning, so if these read as low value I would rather hear it than keep adding them :)

Copilot AI review requested due to automatic review settings August 4, 2026 07:25

Copilot AI left a comment

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds a test suite for instrumentEnv. The tests cover primitive values, version metadata, KV namespaces, queues, Durable Objects, Analytics Engine datasets, D1 databases, service bindings, and unrecognized objects. They verify binding detection, proxy behavior, method delegation, and service-binding span creation.

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the added tests for environment binding detection.
Description check ✅ Passed The description accurately explains the test coverage and validation for instrumentEnv binding detection.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/otel-cf-workers/test/instrumentation/env.test.ts`:
- Line 12: Extend the “instrumentEnv binding detection” suite to cover the
isJSRPC(item) path in instrumentEnv, using a service-binding fixture that
reaches instrumentServiceBinding. Assert the binding’s observable method
behavior, while preserving the existing coverage for other binding types.
- Around line 28-35: Update the instrumentation tests around the KV, Durable
Object, D1, and plain-object binding cases to invoke each returned method and
assert its expected result or mock invocation, rather than checking only typeof.
In the plain-object case, assert the returned result is exactly the original
plain object using identity equality, while preserving the KV method-wrapping
assertion.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 19788efd-b14d-4ce4-b0ea-0a4ae85cc5ae

📥 Commits

Reviewing files that changed from the base of the PR and between 28a13c0 and 473aa7c.

📒 Files selected for processing (1)
  • packages/otel-cf-workers/test/instrumentation/env.test.ts
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • pydantic/logfire (manual)
  • pydantic/pydantic-ai (manual)

Comment thread packages/otel-cf-workers/test/instrumentation/env.test.ts
Comment thread packages/otel-cf-workers/test/instrumentation/env.test.ts Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/otel-cf-workers/test/instrumentation/env.test.ts`:
- Around line 115-118: Update the span-name assertion following the single
service call to compare the complete finished-span name list exactly with
['Service Binding MY_SERVICE'] using toEqual, replacing toContain while
preserving the existing mapping and test setup.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 57b58216-67c2-494a-be7b-f8b87e393013

📥 Commits

Reviewing files that changed from the base of the PR and between 473aa7c and cb272cc.

📒 Files selected for processing (1)
  • packages/otel-cf-workers/test/instrumentation/env.test.ts
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • pydantic/logfire (manual)
  • pydantic/pydantic-ai (manual)

Comment thread packages/otel-cf-workers/test/instrumentation/env.test.ts Outdated

@petyosi petyosi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Reviewed the full diff and relevant surrounding code. No significant correctness, failure-mode, compatibility, or test-coverage issues found.

@ayaangazali
ayaangazali force-pushed the env-binding-detection-tests branch from 8b50a71 to bcad8fb Compare August 15, 2026 17:25
@ayaangazali

Copy link
Copy Markdown
Contributor Author

Rebased onto current main (79bcac0) and re-verified there. Approved and clean, no conflicts.

Recap: this is test-only coverage for instrumentEnv, which decides the instrumentation every Worker binding gets and had none. Eight cases, one per dispatch branch, mutation-verified twice: stubbing the queue detector to false fails the queue case, and the same for Analytics Engine.

Happy to close it if you would rather not take this one.

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.

3 participants