Skip to content

feat: return requestId#2923

Merged
chronark merged 2 commits intomainfrom
return-request-id
Feb 27, 2025
Merged

feat: return requestId#2923
chronark merged 2 commits intomainfrom
return-request-id

Conversation

@chronark
Copy link
Collaborator

@chronark chronark commented Feb 27, 2025

Summary by CodeRabbit

  • New Features
    • The key verification service now returns a unique tracking identifier with each response, enhancing traceability and debugging.
  • Tests
    • A new test case has been added to confirm that key verification requests correctly return the tracking identifier.
    • Updated test cases to improve error reporting and utilize dynamic values for requests.

@changeset-bot
Copy link

changeset-bot bot commented Feb 27, 2025

⚠️ No Changeset found

Latest commit: c251d33

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercel
Copy link

vercel bot commented Feb 27, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
engineering ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 27, 2025 5:11pm
play ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 27, 2025 5:11pm
www ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 27, 2025 5:11pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
dashboard ⬜️ Ignored (Inspect) Visit Preview Feb 27, 2025 5:11pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 27, 2025

📝 Walkthrough

Walkthrough

The changes add a new test case to the key verification API, ensuring that a valid request returns a defined requestId. The API route has been updated to include requestId in both the request and response schemas, and the context now logs this identifier during analytics insertion. Additionally, a minor change was made in the Careers page file with non-functional text modifications.

Changes

File(s) Change Summary
apps/api/src/routes/v1_keys_verifyKey.test.ts
apps/api/src/routes/v1_keys_verifyKey.ts
Added new requestId field to the request and response schemas of the key verification endpoint and updated the integration test to validate its presence.
apps/www/app/careers/page.tsx Minor text content modification in the Careers component; no actual changes to logic or declarations.
apps/api/src/routes/v1_keys_updateKey.error.test.ts Updated timestamp representation in the test object for deleted keys and improved error reporting in assertions.
apps/api/src/routes/v1_migrations_createKey.happy.test.ts Introduced a dynamic plaintext variable for UUID generation in the request body to enhance test variability.

Possibly related PRs

Suggested labels

Feature

Suggested reviewers

  • mcstepp
  • MichaelUnkey
  • perkinsjr
  • ogzhanolguncu
✨ Finishing Touches
  • 📝 Generate Docstrings

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions
Copy link
Contributor

github-actions bot commented Feb 27, 2025

Thank you for following the naming conventions for pull request titles! 🙏

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🔭 Outside diff range comments (1)
apps/api/src/routes/v1_migrations_createKey.happy.test.ts (1)

578-591: 💡 Verification agent

🧩 Analysis chain

Consider adding a test for the new requestId feature

According to the PR summary, you're adding requestId to the verify key API. While this test verifies the basic functionality works, consider adding an explicit assertion that checks if the response contains a defined requestId.

  expect(verifyRes.status).toBe(200);
  expect(verifyRes.body.valid).toEqual(true);
+ expect(verifyRes.body.requestId).toBeDefined();

Let's check what's in the response schema:


🏁 Script executed:

#!/bin/bash
# Search for the V1KeysVerifyKeyResponse type definition
rg -A 15 "V1KeysVerifyKeyResponse" --type=typescript

Length of output: 87


I'll re-run the code search using the correct file extension. This should help us verify whether the V1KeysVerifyKeyResponse type includes the new requestId member.


🏁 Script executed:

#!/bin/bash
rg -A 15 "V1KeysVerifyKeyResponse" --type ts

Length of output: 76041


Action: Add an explicit assertion for requestId in the migration key test

The test in apps/api/src/routes/v1_migrations_createKey.happy.test.ts currently verifies that the key is valid, but it does not check for the new requestId field added to the verify key API. We already see that other tests (e.g., in apps/api/src/routes/v1_keys_verifyKey.test.ts) assert that requestId is defined. To ensure consistency across tests and to validate the new feature, please add an assertion such as:

  expect(verifyRes.status).toBe(200);
  expect(verifyRes.body.valid).toEqual(true);
+ expect(verifyRes.body.requestId).toBeDefined();

This additional check will confirm that the requestId is correctly returned as part of the response.

🧹 Nitpick comments (1)
apps/api/src/routes/v1_migrations_createKey.happy.test.ts (1)

295-296: Consider using the imported randomUUID function

You're importing randomUUID from 'node:crypto' on line 3 but using crypto.randomUUID() here. For consistency, consider using the imported function instead.

-const plaintext = crypto.randomUUID();
+const plaintext = randomUUID();
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fe23731 and c251d33.

📒 Files selected for processing (2)
  • apps/api/src/routes/v1_keys_updateKey.error.test.ts (2 hunks)
  • apps/api/src/routes/v1_migrations_createKey.happy.test.ts (2 hunks)
🧰 Additional context used
🧠 Learnings (1)
apps/api/src/routes/v1_keys_updateKey.error.test.ts (1)
Learnt from: MichaelUnkey
PR: unkeyed/unkey#2114
File: apps/api/src/routes/v1_keys_updateKey.error.test.ts:0-0
Timestamp: 2024-11-10T16:45:16.994Z
Learning: In the `v1/keys.updateKey` endpoint, the server validates the refill configuration before checking if the key exists. Therefore, tests can assert validation errors without needing to create the key first.
⏰ Context from checks skipped due to timeout of 90000ms (18)
  • GitHub Check: Test Packages / Test ./packages/rbac
  • GitHub Check: Test Packages / Test ./packages/nextjs
  • GitHub Check: Test Packages / Test ./packages/hono
  • GitHub Check: Test Packages / Test ./packages/cache
  • GitHub Check: Test Packages / Test ./packages/api
  • GitHub Check: Test Packages / Test ./internal/clickhouse
  • GitHub Check: Test Packages / Test ./internal/resend
  • GitHub Check: Test Packages / Test ./internal/keys
  • GitHub Check: Test Packages / Test ./internal/id
  • GitHub Check: Test Packages / Test ./internal/hash
  • GitHub Check: Test Packages / Test ./internal/encryption
  • GitHub Check: Test Go API Local / test_agent_local
  • GitHub Check: Test Packages / Test ./internal/billing
  • GitHub Check: Build / Build
  • GitHub Check: Test API / API Test Local
  • GitHub Check: autofix
  • GitHub Check: Test Agent Local / test_agent_local
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (3)
apps/api/src/routes/v1_keys_updateKey.error.test.ts (2)

91-92: Schema update to use millisecond timestamps

The key object now uses createdAtM and deletedAtM with millisecond timestamps (via Date.now()) instead of what appears to be previous datetime fields. This change aligns with the schema updates needed to support the new requestId feature.


109-109: Improved error assertion with context

Great enhancement to the test assertion! Including the full response in the error message makes debugging failed tests much easier.

apps/api/src/routes/v1_migrations_createKey.happy.test.ts (1)

306-306: LGTM: Using dynamic plaintext value improves test quality

Good change from a hardcoded plaintext to a dynamic UUID. This makes the test more robust by verifying functionality with random values rather than static ones.

@chronark chronark merged commit d2a73c3 into main Feb 27, 2025
29 of 30 checks passed
@chronark chronark deleted the return-request-id branch February 27, 2025 17:24
@coderabbitai coderabbitai bot mentioned this pull request Feb 27, 2025
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