Skip to content
Open
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
7 changes: 4 additions & 3 deletions loopx/control_plane/effect_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
STARTUP_READY_TIMEOUT_SECONDS = 15.0
STARTUP_POLL_SECONDS = 0.025
_NODE_VERSION_RE = re.compile(r"^v?(\d+)\.(\d+)\.(\d+)(?:[-+].*)?$")
_IDLE_MS_RE = re.compile(r"[ \t\r\n\f\v]*([0-9]+)[ \t\r\n\f\v]*")
_RUNTIME_SOURCE_SUFFIXES = frozenset({".json", ".ts"})
_RuntimeSourceSnapshot = tuple[tuple[str, int, int, int], ...]

Expand All @@ -40,13 +41,13 @@ def _validate_effect_runtime_idle_ms(environment: Mapping[str, str]) -> int:
raw = environment.get("LOOPX_EFFECT_RUNTIME_IDLE_MS")
if raw is None:
return DEFAULT_EFFECT_RUNTIME_IDLE_MS
normalized = raw.strip()
if not re.fullmatch(r"[0-9]+", normalized):
match = _IDLE_MS_RE.fullmatch(raw)
if match is None:
raise EffectRuntimeStartupError(
"LOOPX_EFFECT_RUNTIME_IDLE_MS must be a positive base-10 integer",
diagnostic_code="invalid_runtime_idle_ms",
)
parsed = int(normalized)
parsed = int(match.group(1))
if not 1 <= parsed <= MAX_EFFECT_RUNTIME_IDLE_MS:
raise EffectRuntimeStartupError(
"LOOPX_EFFECT_RUNTIME_IDLE_MS must be between "
Expand Down
6 changes: 3 additions & 3 deletions loopx/control_plane/effect_runtime_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ export const MAX_EFFECT_RUNTIME_IDLE_MS = 2_147_483_647;

export function effectRuntimeIdleMs(value: string | undefined): number {
if (value === undefined) return DEFAULT_EFFECT_RUNTIME_IDLE_MS;
const normalized = value.trim();
if (!/^\d+$/u.test(normalized)) {
const match = /^[\t\n\v\f\r ]*(\d+)[\t\n\v\f\r ]*$/u.exec(value);
if (match === null) {
throw new Error(
"LOOPX_EFFECT_RUNTIME_IDLE_MS must be a positive base-10 integer",
);
}
const parsed = Number(normalized);
const parsed = Number(match[1]);
if (
!Number.isSafeInteger(parsed) || parsed < 1 ||
parsed > MAX_EFFECT_RUNTIME_IDLE_MS
Expand Down
15 changes: 14 additions & 1 deletion tests/fixtures/effect_runtime_idle_ms.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,20 @@
"valid": [
{ "raw": null, "value": 300000 },
{ "raw": " 250 ", "value": 250 },
{ "raw": "\t250\n", "value": 250 },
{ "raw": "\u000b250\u000c", "value": 250 },
{ "raw": "2147483647", "value": 2147483647 }
],
"invalid": ["", "not-a-number", "0", "-1", "1.5", "1e3", "2147483648"]
"invalid": [
"",
"not-a-number",
"0",
"-1",
"1.5",
"1e3",
"2147483648",
"\u0085250\u0085",
"\u001c250\u001c",
"\ufeff250\ufeff"
]
}