Pure functions for AUTO-001 risk-based ordering and budget truncation.
No DB access — callers pass in runHistory, changedPages, changedFiles, etc.
Returned arrays preserve the input test objects untouched; only a riskScore
(and skipReason from applyBudgetToQueue) is added. Callers that need the
original approved-test order for audit/persistence should keep their input
array around — these helpers do not mutate it.
- Source:
Members
(static, constant) MAX_BUDGET_MINUTES
Server-side cap on the budgetMinutes request param to bound worker pool exposure.
- Source:
Methods
(static) applyBudgetToQueue()
Truncate the queue to fit a wall-clock budget. Smoke tests are always kept
(pinned regardless of remaining budget). Returns { kept, skipped } so the
caller can persist "skipped (over budget)" status markers for observability
— silently dropping tests violates AGENT.md issue-handling rules.
- Source:
(static) normalizeBudgetMinutes()
Coerce a user-supplied budgetMinutes into a safe finite number ≤ MAX_BUDGET_MINUTES,
or null if absent / non-positive / non-finite. Prevents a malformed value
("abc", Infinity, 1e9) from being passed straight through to the runner.
- Source:
(static) scoreTestRisk()
runHistory contract: rows are ordered newest-first. Both callers
(routes/runs.js + routes/trigger.js) build history by flat-mapping the
results of runs returned by runRepo.getRecentCompletedWithResults(),
which queries ORDER BY startedAt DESC — so position 0 is the most recent
execution. The scorer takes the first 10 entries as the "recent" window
and reads index 0 for the most-recent-failure bonus. Reversing the array
at the callers (or sorting inside the scorer) would work too but costs an
O(n) per test; honouring the source order here is free.
- Source: