* Validate a single task. * @param {object} task - Hub-provided validation task * @returns {Promise<{ status: string, report?: object, response?: object, reason?: string }>}
(task)
| 107 | * @returns {Promise<{ status: string, report?: object, response?: object, reason?: string }>} |
| 108 | */ |
| 109 | async function validateOneTask(task) { |
| 110 | if (!task || !task.task_id || !task.nonce) { |
| 111 | return { status: 'skipped', reason: 'invalid_task_shape' }; |
| 112 | } |
| 113 | const commands = Array.isArray(task.validation_commands) ? task.validation_commands : []; |
| 114 | if (commands.length === 0) { |
| 115 | // Nothing to run -- report overall_ok=false so the Hub records a fail and moves on. |
| 116 | const payload = buildReportPayload(task, { results: [], overallOk: false, durationMs: 0 }); |
| 117 | const r = await submitReport(payload); |
| 118 | return { status: 'reported_empty', report: payload, response: r }; |
| 119 | } |
| 120 | |
| 121 | let execution; |
| 122 | try { |
| 123 | execution = await runInSandbox(commands, {}); |
| 124 | } catch (err) { |
| 125 | execution = { |
| 126 | results: [{ |
| 127 | cmd: commands[0], |
| 128 | ok: false, |
| 129 | stdout: '', |
| 130 | stderr: 'sandbox_error: ' + (err && err.message ? err.message : String(err)), |
| 131 | exitCode: -1, |
| 132 | durationMs: 0, |
| 133 | timedOut: false, |
| 134 | }], |
| 135 | overallOk: false, |
| 136 | durationMs: 0, |
| 137 | stoppedEarly: true, |
| 138 | }; |
| 139 | } |
| 140 | |
| 141 | const payload = buildReportPayload(task, execution); |
| 142 | const response = await submitReport(payload); |
| 143 | return { |
| 144 | status: response && response.ok ? 'reported' : 'report_failed', |
| 145 | report: payload, |
| 146 | response, |
| 147 | }; |
| 148 | } |
| 149 | |
| 150 | // Lazy single-shot preflight cache. Runs once per process, reused by both the |
| 151 | // daemon and the inline runValidatorCycle() called from the main evolve loop. |
no test coverage detected