Skip to content

refactor(examples): simplify auth examples and fix response buffering#4

Merged
appleboy merged 3 commits intomainfrom
claude/determined-hopper
Mar 27, 2026
Merged

refactor(examples): simplify auth examples and fix response buffering#4
appleboy merged 3 commits intomainfrom
claude/determined-hopper

Conversation

@appleboy
Copy link
Copy Markdown
Member

Summary

  • Add upfront env var validation in go-cli with a clear fatal message before calling the SDK
  • Eliminate duplicate userinfo network call in python-cli by threading the already-fetched result into print_token_info (one request instead of two on the happy path)
  • Move credstore import to top level in python-cli (was deferred inside exception handler)
  • Fix python-m2m response body read: use streaming iter_bytes() capped at MAX_BODY_SIZE+1 bytes instead of buffering the full response via resp.content
  • Align scope order to [profile, email] consistently across all examples
  • Fix grammar in go-m2m env var error message

Test plan

  • go-cli: run with missing env vars — expect clear fatal message and exit
  • go-cli: run with valid env vars — authenticate and print token info as before
  • python-cli: verify single userinfo network call on happy path (no duplicate on cache hit)
  • python-m2m: verify large response is capped at 1 MB and memory is bounded

🤖 Generated with Claude Code

- Add env var validation in go-cli before calling the SDK
- Eliminate duplicate userinfo network call in python-cli by threading result into print_token_info
- Move credstore import to top level in python-cli
- Stream and cap response body at source in python-m2m instead of buffering full response
- Align scope order to profile/email consistently across all examples
- Fix grammar in go-m2m env var error message

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings March 27, 2026 09:18
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the language examples to reduce redundant network calls, improve upfront configuration validation, and bound HTTP response buffering when printing userinfo output.

Changes:

  • Add early environment-variable validation in go-cli and improve the env-var error grammar in go-m2m.
  • Eliminate a duplicate userinfo request in python-cli by passing the already-fetched userinfo into print_token_info, and move the credstore import to the module level.
  • Update python-m2m to stream the userinfo response body and cap output to 1 MB, and align scope ordering to ["profile", "email"].

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
python-m2m/main.py Switches from resp.content buffering to streamed body reading with a size cap; aligns scope order.
python-cli/main.py Avoids duplicate userinfo call by threading userinfo through print_token_info; moves credstore import to top-level; aligns scope order.
go-m2m/main.go Fixes env-var error message grammar.
go-cli/main.go Adds upfront env-var validation and uses the validated values when initializing the SDK client.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Replace bytes concatenation with bytearray.extend() to accumulate streamed chunks in O(n) instead of O(n²)
- Skip empty chunks early and check remaining capacity before each extend to cap at MAX_BODY_SIZE+1 without a post-loop slice

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

- Change WithScopes("email", "profile") to WithScopes("profile", "email") for consistency with all other examples in this repo

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@appleboy appleboy merged commit b152794 into main Mar 27, 2026
4 checks passed
@appleboy appleboy deleted the claude/determined-hopper branch March 27, 2026 09:38
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