-
-
Notifications
You must be signed in to change notification settings - Fork 4.8k
fix(antigravity): align Client-Metadata platform/identity with Antigravity requests #1578
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
happycastle114
wants to merge
6
commits into
router-for-me:main
from
happycastle114:fix/antigravity-metadata-alignment
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
546e5f5
fix(antigravity): align Client-Metadata with Antigravity platform ide…
happycastle114 aa99421
refactor(antigravity): handle GOOS explicitly and reuse computed plat…
happycastle114 c4b6382
refactor(antigravity): mirror opencode metadata platform behavior
happycastle114 7975fb7
feat(antigravity): align runtime headers with opencode-antigravity-au…
happycastle114 d08767a
ci: add GHCR hotfix image workflow for fork branches
happycastle114 c6aa808
ci: build hotfix image for PR and push events
happycastle114 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| name: ghcr-hotfix | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - fix/antigravity-metadata-alignment | ||
| - hotfix/** | ||
| pull_request: | ||
| branches: | ||
| - main | ||
| - master | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read | ||
| packages: write | ||
|
|
||
| env: | ||
| IMAGE_NAME: ghcr.io/happycastle114/cliproxyapi | ||
|
|
||
| jobs: | ||
| build-and-push: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Set up QEMU | ||
| uses: docker/setup-qemu-action@v3 | ||
|
|
||
| - name: Set up Docker Buildx | ||
| uses: docker/setup-buildx-action@v3 | ||
|
|
||
| - name: Log in to GHCR | ||
| uses: docker/login-action@v3 | ||
| with: | ||
| registry: ghcr.io | ||
| username: ${{ github.actor }} | ||
| password: ${{ secrets.GITHUB_TOKEN }} | ||
|
|
||
| - name: Extract metadata | ||
| id: meta | ||
| uses: docker/metadata-action@v5 | ||
| with: | ||
| images: ${{ env.IMAGE_NAME }} | ||
| tags: | | ||
| type=raw,value=hotfix-latest,enable=${{ github.event_name == 'push' }} | ||
| type=sha,prefix=hotfix- | ||
|
|
||
| - name: Build and push image | ||
| uses: docker/build-push-action@v6 | ||
| with: | ||
| context: . | ||
| platforms: linux/amd64,linux/arm64 | ||
| push: true | ||
| tags: ${{ steps.meta.outputs.tags }} | ||
| labels: ${{ steps.meta.outputs.labels }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| package antigravity | ||
|
|
||
| import ( | ||
| "strings" | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestMetadataPlatformForGOOS(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| goos string | ||
| want string | ||
| }{ | ||
| {name: "windows", goos: "windows", want: "WINDOWS"}, | ||
| {name: "darwin", goos: "darwin", want: "MACOS"}, | ||
| {name: "linux", goos: "linux", want: "MACOS"}, | ||
| {name: "unknown", goos: "freebsd", want: "MACOS"}, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| got := metadataPlatformForGOOS(tt.goos) | ||
| if got != tt.want { | ||
| t.Fatalf("metadataPlatformForGOOS(%q) = %q, want %q", tt.goos, got, tt.want) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestAntigravityJSONClientMetadata(t *testing.T) { | ||
| m := antigravityJSONClientMetadata() | ||
| if m == "" { | ||
| t.Fatal("metadata should not be empty") | ||
| } | ||
| if !(strings.Contains(m, `"ideType":"ANTIGRAVITY"`) && strings.Contains(m, `"pluginType":"GEMINI"`)) { | ||
| t.Fatalf("unexpected metadata: %s", m) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
internal/runtime/executor/antigravity_executor_headers_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package executor | ||
|
|
||
| import ( | ||
| "net/http" | ||
| "strings" | ||
| "testing" | ||
| ) | ||
|
|
||
| func TestMetadataPlatformFromUserAgent(t *testing.T) { | ||
| tests := []struct { | ||
| name string | ||
| ua string | ||
| want string | ||
| }{ | ||
| {name: "windows ua", ua: "antigravity/1.104.0 windows/amd64", want: "WINDOWS"}, | ||
| {name: "darwin ua", ua: "antigravity/1.104.0 darwin/arm64", want: "MACOS"}, | ||
| {name: "unknown ua", ua: "antigravity/1.104.0 linux/amd64", want: "MACOS"}, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| got := metadataPlatformFromUserAgent(tt.ua) | ||
| if got != tt.want { | ||
| t.Fatalf("metadataPlatformFromUserAgent(%q)=%q want=%q", tt.ua, got, tt.want) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestApplyAntigravityHeaders(t *testing.T) { | ||
| h := make(http.Header) | ||
| applyAntigravityHeaders(h, nil) | ||
|
|
||
| ua := h.Get("User-Agent") | ||
| if ua == "" { | ||
| t.Fatal("User-Agent should be set") | ||
| } | ||
| if !strings.HasPrefix(ua, "antigravity/") { | ||
| t.Fatalf("unexpected User-Agent: %s", ua) | ||
| } | ||
| if h.Get("X-Goog-Api-Client") != antigravityAPIClient { | ||
| t.Fatalf("unexpected X-Goog-Api-Client: %s", h.Get("X-Goog-Api-Client")) | ||
| } | ||
| metadata := h.Get("Client-Metadata") | ||
| if !strings.Contains(metadata, `"ideType":"ANTIGRAVITY"`) { | ||
| t.Fatalf("unexpected Client-Metadata: %s", metadata) | ||
| } | ||
| if !(strings.Contains(metadata, `"platform":"WINDOWS"`) || strings.Contains(metadata, `"platform":"MACOS"`)) { | ||
| t.Fatalf("unexpected Client-Metadata platform: %s", metadata) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is some duplication between
antigravityJSONClientMetadataandantigravityRequestMetadata. Both functions construct similar metadata structures and callruntimeMetadataPlatform(). In functions likeFetchProjectID, both helpers are called, resulting inruntimeMetadataPlatform()being executed twice, which is slightly inefficient.To improve this, you could determine the platform once at package initialization and store it in a package-level variable. This variable can then be reused in both helper functions, making the code more efficient and adhering to the Don't Repeat Yourself (DRY) principle.