-
Notifications
You must be signed in to change notification settings - Fork 30
feat(cloud-agent): add createSignedCommit for GitHub-signed commits #2282
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
Merged
Merged
Changes from all commits
Commits
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,23 @@ | ||
| /** Maps `items` through `mapper` with at most `concurrency` in flight, preserving | ||
| * input order. Stops early if `options.signal` aborts. */ | ||
| export async function mapWithConcurrency<T, R>( | ||
| items: readonly T[], | ||
| concurrency: number, | ||
| mapper: (item: T) => Promise<R>, | ||
| options?: { signal?: AbortSignal }, | ||
| ): Promise<R[]> { | ||
| if (items.length === 0) return []; | ||
| const results = new Array<R>(items.length); | ||
| let index = 0; | ||
| const worker = async () => { | ||
| while (index < items.length) { | ||
| if (options?.signal?.aborted) return; | ||
| const i = index++; | ||
| results[i] = await mapper(items[i]); | ||
| } | ||
| }; | ||
| await Promise.all( | ||
| Array.from({ length: Math.min(concurrency, items.length) }, () => worker()), | ||
| ); | ||
| return results; | ||
| } |
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,79 @@ | ||
| import { describe, expect, it, vi } from "vitest"; | ||
| import { execGhWithRetry, type GhExecResult, isTransientGhFailure } from "./gh"; | ||
|
|
||
| function result(partial: Partial<GhExecResult>): GhExecResult { | ||
| return { stdout: "", stderr: "", exitCode: 1, ...partial }; | ||
| } | ||
|
|
||
| describe("isTransientGhFailure", () => { | ||
| it.each([ | ||
| { | ||
| name: "HTTP 499", | ||
| res: result({ stderr: "gh: HTTP 499" }), | ||
| expected: true, | ||
| }, | ||
| { | ||
| name: "HTTP 502", | ||
| res: result({ stderr: "gh: HTTP 502" }), | ||
| expected: true, | ||
| }, | ||
| { | ||
| name: "timeout", | ||
| res: result({ error: "gh timed out after 30000ms" }), | ||
| expected: true, | ||
| }, | ||
| { | ||
| name: "ECONNRESET", | ||
| res: result({ error: "read ECONNRESET" }), | ||
| expected: true, | ||
| }, | ||
| { | ||
| name: "success", | ||
| res: result({ exitCode: 0, stderr: "gh: HTTP 499" }), | ||
| expected: false, | ||
| }, | ||
| { | ||
| name: "HTTP 404", | ||
| res: result({ stderr: "gh: HTTP 404" }), | ||
| expected: false, | ||
| }, | ||
| { | ||
| name: "HTTP 422 validation", | ||
| res: result({ stderr: "gh: HTTP 422" }), | ||
| expected: false, | ||
| }, | ||
| ])("$name -> $expected", ({ res, expected }) => { | ||
| expect(isTransientGhFailure(res)).toBe(expected); | ||
| }); | ||
| }); | ||
|
|
||
| describe("execGhWithRetry", () => { | ||
| it("retries transient failures then succeeds", async () => { | ||
| const exec = vi | ||
| .fn() | ||
| .mockResolvedValueOnce(result({ stderr: "gh: HTTP 499" })) | ||
| .mockResolvedValueOnce(result({ stdout: "ok", exitCode: 0 })); | ||
| const res = await execGhWithRetry(["api"], {}, { backoffMs: 0 }, exec); | ||
| expect(res.exitCode).toBe(0); | ||
| expect(exec).toHaveBeenCalledTimes(2); | ||
| }); | ||
|
|
||
| it("stops after maxAttempts on persistent transient failure", async () => { | ||
| const exec = vi.fn().mockResolvedValue(result({ stderr: "gh: HTTP 503" })); | ||
| const res = await execGhWithRetry( | ||
| ["api"], | ||
| {}, | ||
| { maxAttempts: 3, backoffMs: 0 }, | ||
| exec, | ||
| ); | ||
| expect(res.exitCode).toBe(1); | ||
| expect(exec).toHaveBeenCalledTimes(3); | ||
| }); | ||
|
|
||
| it("does not retry deterministic failures", async () => { | ||
| const exec = vi.fn().mockResolvedValue(result({ stderr: "gh: HTTP 404" })); | ||
| const res = await execGhWithRetry(["api"], {}, { backoffMs: 0 }, exec); | ||
| expect(res.exitCode).toBe(1); | ||
| expect(exec).toHaveBeenCalledTimes(1); | ||
| }); | ||
| }); |
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
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,58 @@ | ||
| import { describe, expect, it } from "vitest"; | ||
| import { chunkFileChanges, OversizedFileError } from "./signed-commit"; | ||
|
|
||
| function addition(path: string, sizeBytes: number) { | ||
| // base64 string of roughly `sizeBytes` length stands in for file contents. | ||
| return { path, contents: "a".repeat(sizeBytes) }; | ||
| } | ||
|
|
||
| describe("chunkFileChanges", () => { | ||
| it.each([ | ||
| { | ||
| name: "carries deletions in a single chunk when there are no additions", | ||
| changes: { additions: [], deletions: [{ path: "gone.txt" }] }, | ||
| limit: 1000, | ||
| expected: [{ additions: [], deletions: ["gone.txt"] }], | ||
| }, | ||
| { | ||
| name: "packs additions under the threshold into one chunk", | ||
| changes: { | ||
| additions: [addition("a", 100), addition("b", 100), addition("c", 100)], | ||
| deletions: [], | ||
| }, | ||
| limit: 10_000, | ||
| expected: [{ additions: ["a", "b", "c"], deletions: [] }], | ||
| }, | ||
| { | ||
| name: "splits additions across chunks, with deletions in the first only", | ||
| changes: { | ||
| additions: [addition("a", 400), addition("b", 400), addition("c", 400)], | ||
| deletions: [{ path: "d" }], | ||
| }, | ||
| limit: 500, | ||
| // Each ~400-byte addition needs its own chunk at a 500-byte budget. | ||
| expected: [ | ||
| { additions: ["a"], deletions: ["d"] }, | ||
| { additions: ["b"], deletions: [] }, | ||
| { additions: ["c"], deletions: [] }, | ||
| ], | ||
| }, | ||
| ])("$name", ({ changes, limit, expected }) => { | ||
| const chunks = chunkFileChanges(changes, limit); | ||
| expect( | ||
| chunks.map((c) => ({ | ||
| additions: c.additions.map((a) => a.path), | ||
| deletions: c.deletions.map((d) => d.path), | ||
| })), | ||
| ).toEqual(expected); | ||
| }); | ||
|
|
||
| it("throws OversizedFileError for a single file larger than the limit", () => { | ||
| expect(() => | ||
| chunkFileChanges( | ||
| { additions: [addition("huge", 5000)], deletions: [] }, | ||
| 1000, | ||
| ), | ||
| ).toThrow(OversizedFileError); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.