Run CRUD backed by SQLite.
JSON columns: tests, results, testQueue, generateInput, promptAudit, pipelineStats, feedbackLoop, videoSegments, qualityAnalytics.
Log lines are stored in the run_logs table (ENH-008) — not in a
logs JSON column. getById hydrates run.logs from
run_logs automatically so callers see no API change.
All read queries filter WHERE deletedAt IS NULL by default.
Hard deletes are replaced with soft-deletes: deletedAt = datetime('now').
Use getDeletedByProjectId / restore for recycle-bin operations.
Pagination
getByProjectIdPaged returns
{ data: Run[], meta: { total, page, pageSize, hasMore } }.
- Source:
Methods
(static) countByProjectIds(projectIds) → {number}
Count non-deleted runs for a set of project IDs.
Parameters:
| Name | Type | Description |
|---|---|---|
projectIds |
Array.<string> |
- Source:
Returns:
- Type
- number
(static) create(run)
Create a run.
Note: run.logs is intentionally not written to runs.logs — log lines
are persisted via runLogRepo.appendLog in runLogger.js (ENH-008).
Parameters:
| Name | Type | Description |
|---|---|---|
run |
Object |
- Source:
(static) deleteByProjectId(projectId) → {Array.<string>}
Soft-delete all runs for a project.
Parameters:
| Name | Type | Description |
|---|---|---|
projectId |
string |
- Source:
Returns:
IDs of newly soft-deleted runs.
- Type
- Array.<string>
(static) findActiveByProjectId(projectId, typesopt) → {Object|undefined}
Find an active (non-deleted, non-finished) run for a project.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
projectId |
string | ||
types |
Array.<string> |
<optional> |
— Run types to check (default: crawl, test_run, generate). |
- Source:
Returns:
- Type
- Object | undefined
(static) findLatestResultForTest(testId) → {Object|null}
Find the most recent non-deleted run result for a specific test ID.
Uses a LIKE pre-filter on the JSON results column to narrow down candidate rows, then parses and searches in JS. Only selects id, startedAt, results to avoid deserializing heavy columns.
Parameters:
| Name | Type | Description |
|---|---|---|
testId |
string | — e.g. "TC-1" |
- Source:
Returns:
The matching result object with runId, or null.
- Type
- Object | null
(static) getAllWithResults() → {Array.<Object>}
Get all non-deleted runs with results + feedbackLoop columns (for failure/analytics).
Prefer getWithResultsByProjectIds for workspace-scoped queries.
- Source:
Returns:
- Type
- Array.<Object>
(static) getById(id) → {Object|undefined}
Get a non-deleted run by ID.
Hydrates run.logs from the run_logs table (ENH-008).
Parameters:
| Name | Type | Description |
|---|---|---|
id |
string |
- Source:
Returns:
- Type
- Object | undefined
(static) getByIdIncludeDeleted(id) → {Object|undefined}
Get a run by ID including soft-deleted (for restore and abort operations).
Hydrates run.logs from the run_logs table (ENH-008).
Parameters:
| Name | Type | Description |
|---|---|---|
id |
string |
- Source:
Returns:
- Type
- Object | undefined
(static) getByProjectId(projectId) → {Array.<Object>}
Get non-deleted runs for a specific project, sorted by startedAt descending.
Parameters:
| Name | Type | Description |
|---|---|---|
projectId |
string |
- Source:
Returns:
- Type
- Array.<Object>
(static) getByProjectIdPaged(projectId, pageopt, pageSizeopt) → {Object}
Get non-deleted runs for a project with lean columns, paginated.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
projectId |
string | |||
page |
number | string |
<optional> |
1 | |
pageSize |
number | string |
<optional> |
DEFAULT_PAGE_SIZE |
- Source:
Returns:
- Type
- Object
(static) getDeletedAll() → {Array.<Object>}
Get all soft-deleted runs.
- Source:
Returns:
- Type
- Array.<Object>
(static) getDeletedByProjectId(projectId) → {Array.<Object>}
Get soft-deleted runs for a project.
Parameters:
| Name | Type | Description |
|---|---|---|
projectId |
string |
- Source:
Returns:
- Type
- Array.<Object>
(static) getRecentCompletedWithResults(projectId, limitopt) → {Array.<Object>}
Get recent completed test runs with only the columns needed for flaky score
computation. Returns at most limit rows, sorted newest-first, with only
id, type, status, startedAt, and results — avoiding the heavy
JSON blobs (testQueue, generateInput, promptAudit, qualityAnalytics).
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
projectId |
string | |||
limit |
number |
<optional> |
20 |
- Source:
Returns:
- Type
- Array.<Object>
(static) getWithResultsByProjectIds(projectIds) → {Array.<Object>}
Get non-deleted runs with results + feedbackLoop for a set of project IDs.
Workspace-scoped alternative to getAllWithResults — queries only the
rows belonging to the given projects instead of loading the entire table.
Parameters:
| Name | Type | Description |
|---|---|---|
projectIds |
Array.<string> |
- Source:
Returns:
- Type
- Array.<Object>
(static) hardDeleteById(id)
Hard-delete a run by ID (permanent — use only for purge operations).
Also purges all associated log rows from run_logs.
Parameters:
| Name | Type | Description |
|---|---|---|
id |
string |
- Source:
(static) hardDeleteByProjectId(projectId) → {Array.<string>}
Hard-delete all runs for a project (permanent — for project purge).
Also purges all associated log rows from run_logs.
Parameters:
| Name | Type | Description |
|---|---|---|
projectId |
string |
- Source:
Returns:
IDs of all deleted runs.
- Type
- Array.<string>
(static) markOrphansInterrupted() → {number}
Mark all "running" non-deleted runs as "interrupted" (orphan recovery on startup).
- Source:
Returns:
Number of runs marked.
- Type
- number
(static) restore(id) → {boolean}
Restore a soft-deleted run (clears deletedAt).
Parameters:
| Name | Type | Description |
|---|---|---|
id |
string |
- Source:
Returns:
Whether the run was found and restored.
- Type
- boolean
(static) restoreByProjectIdAfter(projectId, deletedAfter) → {number}
Restore soft-deleted runs for a project that were deleted at or after a given timestamp. Used by project cascade-restore to avoid restoring items that were individually deleted before the project.
Parameters:
| Name | Type | Description |
|---|---|---|
projectId |
string | |
deletedAfter |
string | — ISO timestamp (inclusive lower bound). |
- Source:
Returns:
Number of runs restored.
- Type
- number
(static) save(run)
Save the entire run object (upsert-style update of all known columns). Used by pipeline code that mutates the run in-memory and then flushes.
Pipeline code accumulates non-column properties on the run object (e.g. snapshots, pages, testsGenerated). These are filtered out so the generated SQL only references actual table columns.
Parameters:
| Name | Type | Description |
|---|---|---|
run |
Object | — Full run object with |
- Source:
(static) update(id, fields)
Update specific fields on a run (full replacement of provided fields). Unknown properties (not in the runs table) are silently skipped.
Parameters:
| Name | Type | Description |
|---|---|---|
id |
string | |
fields |
Object |
- Source:
(inner) parseLeanJson(row) → {Object}
Parse the lightweight JSON columns (feedbackLoop, pipelineStats) on a lean row in-place. Both are small objects — safe to include in listing queries.
Parameters:
| Name | Type | Description |
|---|---|---|
row |
Object |
- Source:
Returns:
The same row with JSON columns deserialized.
- Type
- Object
(inner) parseResultsAndLean(row) → {Object}
Parse results JSON + lean JSON columns on a row.
Shared by getAllWithResults and getWithResultsByProjectIds.
Parameters:
| Name | Type | Description |
|---|---|---|
row |
Object |
- Source:
Returns:
- Type
- Object