-
Notifications
You must be signed in to change notification settings - Fork 454
[jsweep] Clean harness_retry_config.cjs #45378
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
pelikhan
merged 3 commits into
main
from
signed/jsweep/harness-retry-config-c98f57685f1a4e05
Jul 14, 2026
+117
−0
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
4b3c4cf
jsweep: add @ts-check and tests to harness_retry_config.cjs
github-actions[bot] b968f43
Merge branch 'main' into signed/jsweep/harness-retry-config-c98f57685…
pelikhan ad1f386
fix: use require() for CJS module import in harness_retry_config.test…
Copilot 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
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,115 @@ | ||
| // @ts-check | ||
|
|
||
| import { describe, it, expect } from "vitest"; | ||
| const { resolveRetryConfig, parseRetryConfigNumber } = require("./harness_retry_config.cjs"); | ||
|
|
||
| describe("parseRetryConfigNumber", () => { | ||
| it("returns defaultValue when env var is not set", () => { | ||
| const result = parseRetryConfigNumber({}, { envVar: "MY_VAR", defaultValue: 42, minimum: 0 }); | ||
| expect(result).toBe(42); | ||
| }); | ||
|
|
||
| it("returns defaultValue when env var is empty string", () => { | ||
| const result = parseRetryConfigNumber({ MY_VAR: "" }, { envVar: "MY_VAR", defaultValue: 42, minimum: 0 }); | ||
| expect(result).toBe(42); | ||
| }); | ||
|
|
||
| it("parses a valid integer", () => { | ||
| const result = parseRetryConfigNumber({ MY_VAR: "10" }, { envVar: "MY_VAR", defaultValue: 5, minimum: 0 }); | ||
| expect(result).toBe(10); | ||
| }); | ||
|
|
||
| it("rejects exponential notation integers", () => { | ||
| const result = parseRetryConfigNumber({ MY_VAR: "1e3" }, { envVar: "MY_VAR", defaultValue: 5, minimum: 0 }); | ||
| expect(result).toBe(5); | ||
| }); | ||
|
|
||
| it("rejects hex notation", () => { | ||
| const result = parseRetryConfigNumber({ MY_VAR: "0x10" }, { envVar: "MY_VAR", defaultValue: 5, minimum: 0 }); | ||
| expect(result).toBe(5); | ||
| }); | ||
|
|
||
| it("returns defaultValue when value is below minimum", () => { | ||
| const result = parseRetryConfigNumber({ MY_VAR: "0" }, { envVar: "MY_VAR", defaultValue: 5, minimum: 1 }); | ||
| expect(result).toBe(5); | ||
| }); | ||
|
|
||
| it("accepts float when allowFloat is true", () => { | ||
| const result = parseRetryConfigNumber({ MY_VAR: "1.5" }, { envVar: "MY_VAR", defaultValue: 2, minimum: 1, allowFloat: true }); | ||
| expect(result).toBe(1.5); | ||
| }); | ||
|
|
||
| it("rejects float when allowFloat is false (default)", () => { | ||
| const result = parseRetryConfigNumber({ MY_VAR: "1.5" }, { envVar: "MY_VAR", defaultValue: 2, minimum: 1 }); | ||
| expect(result).toBe(2); | ||
| }); | ||
|
|
||
| it("calls logger on invalid value", () => { | ||
| /** @type {string[]} */ | ||
| const logs = []; | ||
| parseRetryConfigNumber({ MY_VAR: "bad" }, { envVar: "MY_VAR", defaultValue: 5, minimum: 0, logger: m => logs.push(m) }); | ||
| expect(logs.length).toBeGreaterThan(0); | ||
| expect(logs[0]).toContain("MY_VAR"); | ||
| }); | ||
|
|
||
| it("trims whitespace from value", () => { | ||
| const result = parseRetryConfigNumber({ MY_VAR: " 7 " }, { envVar: "MY_VAR", defaultValue: 5, minimum: 0 }); | ||
| expect(result).toBe(7); | ||
| }); | ||
| }); | ||
|
|
||
| describe("resolveRetryConfig", () => { | ||
| it("returns defaults when no env vars are set", () => { | ||
| const config = resolveRetryConfig({}); | ||
| expect(config).toEqual({ | ||
| maxRetries: 3, | ||
| initialDelayMs: 5000, | ||
| backoffMultiplier: 2, | ||
| maxDelayMs: 60000, | ||
| }); | ||
| }); | ||
|
|
||
| it("reads maxRetries from env", () => { | ||
| const config = resolveRetryConfig({ GH_AW_HARNESS_MAX_RETRIES: "5" }); | ||
| expect(config.maxRetries).toBe(5); | ||
| }); | ||
|
|
||
| it("clamps maxRetries to MAX_RETRIES_CAP (100)", () => { | ||
| /** @type {string[]} */ | ||
| const logs = []; | ||
| const config = resolveRetryConfig({ GH_AW_HARNESS_MAX_RETRIES: "200" }, m => logs.push(m)); | ||
| expect(config.maxRetries).toBe(100); | ||
| expect(logs.some(m => m.includes("clamping"))).toBe(true); | ||
| }); | ||
|
|
||
| it("reads initialDelayMs from env", () => { | ||
| const config = resolveRetryConfig({ GH_AW_HARNESS_INITIAL_DELAY_MS: "1000" }); | ||
| expect(config.initialDelayMs).toBe(1000); | ||
| }); | ||
|
|
||
| it("reads backoffMultiplier as float from env", () => { | ||
| const config = resolveRetryConfig({ GH_AW_HARNESS_BACKOFF_MULTIPLIER: "1.5" }); | ||
| expect(config.backoffMultiplier).toBe(1.5); | ||
| }); | ||
|
|
||
| it("clamps maxDelayMs to initialDelayMs when lower", () => { | ||
| /** @type {string[]} */ | ||
| const logs = []; | ||
| const config = resolveRetryConfig({ GH_AW_HARNESS_INITIAL_DELAY_MS: "5000", GH_AW_HARNESS_MAX_DELAY_MS: "1000" }, m => logs.push(m)); | ||
| expect(config.maxDelayMs).toBe(5000); | ||
| expect(logs.some(m => m.includes("clamping max delay"))).toBe(true); | ||
| }); | ||
|
|
||
| it("reads maxDelayMs from env", () => { | ||
| const config = resolveRetryConfig({ GH_AW_HARNESS_MAX_DELAY_MS: "30000" }); | ||
| expect(config.maxDelayMs).toBe(30000); | ||
| }); | ||
|
|
||
| it("uses process.env when no env argument provided", () => { | ||
| const config = resolveRetryConfig(); | ||
| expect(config).toHaveProperty("maxRetries"); | ||
| expect(config).toHaveProperty("initialDelayMs"); | ||
| expect(config).toHaveProperty("backoffMultiplier"); | ||
| expect(config).toHaveProperty("maxDelayMs"); | ||
| }); | ||
| }); | ||
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.
Bug: ES module
importin a.cjsfile.cjsfiles are treated as CommonJS by Node.js (and bundlers), which does not support staticimportdeclarations. This will throw aSyntaxErrorat runtime/test-time.Fix — replace the imports with
require:Or rename the file to
harness_retry_config.test.mjs/harness_retry_config.test.js(if the project allows ESM tests) and update the test runner config accordingly.@copilot please address this.