Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion webdriver/src/prj/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"scripts": {
"start": "node --loader ts-node/esm src/index.ts",
"dev": "ts-node src/index.ts",
"build": "tsc"
"build": "tsc",
"test": "node --loader ts-node/esm --test src/**/*.test.ts",
"typecheck": "tsc --noEmit"
},
"dependencies": {
"puppeteer-core": "24.16.0",
Expand Down
15 changes: 15 additions & 0 deletions webdriver/src/prj/src/duration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,21 @@ export function envInt(envName: string, defaultValue: number): number {
return result;
}

/**
* Like `envInt`, but for limits where a non-positive value is nonsense rather
* than merely unusual — a zero response cap, for instance, would reject every
* page. Fails at startup instead of silently disabling the feature.
*/
export function envPositiveInt(envName: string, defaultValue: number): number {
const value = envInt(envName, defaultValue);
if (!Number.isInteger(value) || value < 1) {
throw new Error(
`env ${envName} must be a positive integer, got "${process.env[envName]}"`,
);
Comment on lines +75 to +80

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf 'Tracked candidate file:\n'
git ls-files | grep -F 'webdriver/src/prj/src/duration.ts' || true

printf '\nRelevant duration.ts outline and target lines:\n'
if [ -f webdriver/src/prj/src/duration.ts ]; then
  ast-grep outline webdriver/src/prj/src/duration.ts || true
  printf '\nLines 1-130:\n'
  sed -n '1,130p' webdriver/src/prj/src/duration.ts | nl -ba
fi

printf '\nInspect parseInt behavior used by this envInt implementation:\n'
node - <<'JS'
for (const raw of ['4.5', '4invalid', '4invalid.5', '0.5', '3', '3.14159']) {
  console.log(`${JSON.stringify(raw)} -> parseInt 10=${parseInt(raw, 10)}, Number=${Number(raw)}, isInteger=${Number.isInteger(Number(raw))}, safe=${Number.isSafeInteger(Number(raw))}`);
}
JS

printf '\nSearch for envPositiveInt/envInt usages:\n'
rg -n "envPositiveInt|envInt" webdriver/src/prj/src -S || true

Repository: genlayerlabs/genvm-manager

Length of output: 1056


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf 'Lines 1-120 of webdriver/src/prj/src/duration.ts:\n'
sed -n '1,120p' webdriver/src/prj/src/duration.ts | awk '{printf "%6d\t%s\n", NR, $0}'

printf '\nInspect parseInt behavior used by this envInt implementation:\n'
node - <<'JS'
for (const raw of ['4.5', '4invalid', '4invalid.5', '0.5', '3', '3.14159']) {
  console.log(`${JSON.stringify(raw)} -> parseInt 10=${parseInt(raw, 10)}, Number=${Number(raw)}, isInteger=${Number.isInteger(Number(raw))}, safe=${Number.isSafeInteger(Number(raw))}`);
}
JS

printf '\nSearch for envPositiveInt/envInt usages:\n'
rg -n "envPositiveInt|envInt" webdriver/src/prj/src -S || true

Repository: genlayerlabs/genvm-manager

Length of output: 6437


🏁 Script executed:

#!/bin/bash
set -euo pipefail

node - <<'JS'
const cases = [
  '4.5',
  '4invalid',
  '4invalid.5',
  '0.5',
  '3',
  '3.14159',
  '4.5invalid',
  '9007199254740991',
  '9007199254740992',
];
for (const raw of cases) {
  const parseInt10 = parseInt(raw, 10);
  const numberVal = Number(raw);
  console.log(`${raw}: parseInt10=${parseInt10}, Number=${numberVal}, isInteger=${Number.isInteger(numberVal)}, safe=${Number.isSafeInteger(numberVal)}`);
}
JS

Repository: genlayerlabs/genvm-manager

Length of output: 795


Validate the raw environment value before integer conversion.

envInt delegates to parseInt, so inputs like 4.5, 4invalid, and 4.5invalid accept only the integer prefix and use 4. Since envPositiveInt checks the parsed value, fractional or trailing-character configs bypass the intended fail-fast behavior for response and concurrency limits. Parse raw input strictly with Number(raw) and fail unless the value is a safe positive integer.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@webdriver/src/prj/src/duration.ts` around lines 75 - 80, Update
envPositiveInt to validate the raw environment value before conversion, using
Number(raw) rather than envInt so fractional and trailing-character inputs are
rejected. Require the resulting value to be a safe positive integer, while
preserving default handling for an unset variable and the existing error
behavior.

}
return value;
}

export function envStr(envName: string, defaultValue: string): string {
const raw = process.env[envName];
const value = raw !== undefined && raw !== '' ? raw : defaultValue;
Expand Down
Loading
Loading