Compare commits
13
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ecc1b447be | ||
|
|
64703482fd | ||
|
|
0412eeeb38 | ||
|
|
33a3f7c0b9 | ||
|
|
c01e3ead32 | ||
|
|
156c311217 | ||
|
|
9f6b34b55a | ||
|
|
e92fa42b4e | ||
|
|
5d1cdf9da0 | ||
|
|
09a9d69102 | ||
|
|
d1ef6297ec | ||
|
|
424309e3c3 | ||
|
|
e5d640dc1a |
No files matched your search
@@ -182,3 +182,41 @@ html[data-theme="light"] .pulse-dim { color: var(--text-muted); }
|
||||
html[data-theme="light"] .pulse-running {
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
/* The `hidden` attribute must win over component display rules such as
|
||||
.lt-form-group { display: flex }, or hidden sections still show (both
|
||||
Quick Command worker pickers were visible in either mode). */
|
||||
[hidden] { display: none !important; }
|
||||
|
||||
/* Command output blocks (#27): toolbar above a wrapping, collapsible <pre>. */
|
||||
.pl-out { margin-top: 0.4rem; min-width: 0; }
|
||||
.pl-out-bar {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
gap: 0.3rem;
|
||||
}
|
||||
.pl-out-label {
|
||||
margin-right: auto;
|
||||
font-size: 0.65rem;
|
||||
letter-spacing: 0.05em;
|
||||
text-transform: uppercase;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
.pl-out-btn { padding: 0.1rem 0.5rem; font-size: 0.62rem; }
|
||||
.pl-out-pre {
|
||||
margin: 0.3rem 0 0;
|
||||
white-space: pre-wrap;
|
||||
overflow-wrap: anywhere;
|
||||
overflow: auto;
|
||||
}
|
||||
.pl-out-pre.is-nowrap { white-space: pre; overflow-wrap: normal; }
|
||||
.pl-out-pre.is-tall { max-height: 24rem; }
|
||||
.pl-out-pre.is-tall.is-expanded { max-height: none; }
|
||||
.pl-out-err {
|
||||
color: var(--accent-red);
|
||||
border-left-color: var(--accent-red);
|
||||
text-shadow: none;
|
||||
}
|
||||
.pl-out-note { margin-top: 0.3rem; font-size: 0.7rem; color: var(--text-muted); }
|
||||
+84
-1
@@ -163,6 +163,87 @@
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------
|
||||
Command output blocks (#27): ANSI codes stripped, Copy / Wrap / Expand /
|
||||
.txt controls, and a notice when the display is cut short. Copy and the
|
||||
download always use the full text, which is kept here by block id.
|
||||
------------------------------------------------------------------- */
|
||||
const OUT_MAX = 100000; // characters drawn per block
|
||||
const OUT_TALL_LINES = 25; // taller than this starts collapsed
|
||||
const OUT_WRAP_KEY = 'pulse_output_wrap';
|
||||
// CSI (colours, cursor moves), OSC (titles, links), charset switches (ESC ( B)
|
||||
// and other two-byte escapes.
|
||||
// eslint-disable-next-line no-control-regex -- matching ESC/BEL is the point
|
||||
const ANSI_RE = /\u001b(?:\][^\u0007\u001b]*(?:\u0007|\u001b\\)|\[[0-?]*[ -/]*[@-~]|[()*+][0-9A-Za-z]|[@-Z\\-_])/g;
|
||||
const _outTexts = new Map();
|
||||
let _outSeq = 0;
|
||||
|
||||
function stripAnsi(text) {
|
||||
return String(text == null ? '' : text).replace(ANSI_RE, '');
|
||||
}
|
||||
|
||||
function outButton(action, id, label, title) {
|
||||
return '<button type="button" class="lt-btn lt-btn-ghost lt-btn-sm pl-out-btn" data-action="' + action +
|
||||
'" data-out="' + id + '" title="' + title + '">' + label + '</button>';
|
||||
}
|
||||
|
||||
/** HTML for one output block. opts: { err, label, name (download file name), cls } */
|
||||
function renderOutput(text, opts) {
|
||||
const o = opts || {};
|
||||
const clean = stripAnsi(text);
|
||||
const id = 'pl-out-' + (++_outSeq);
|
||||
_outTexts.set(id, { text: clean, name: String(o.name || 'output').replace(/[^\w.-]+/g, '-') });
|
||||
if (_outTexts.size > 500) _outTexts.delete(_outTexts.keys().next().value);
|
||||
const shown = clean.length > OUT_MAX ? clean.slice(0, OUT_MAX) : clean;
|
||||
const tall = shown.split('\n').length > OUT_TALL_LINES;
|
||||
const cls = ['lt-log-output', 'pl-out-pre'];
|
||||
if (o.err) cls.push('pl-out-err');
|
||||
if (o.cls) cls.push(o.cls);
|
||||
if (storage.get(OUT_WRAP_KEY, true) === false) cls.push('is-nowrap');
|
||||
if (tall) cls.push('is-tall');
|
||||
return '<div class="pl-out" id="' + id + '">' +
|
||||
'<div class="pl-out-bar">' +
|
||||
(o.label ? '<span class="pl-out-label">' + esc(o.label) + '</span>' : '') +
|
||||
outButton('out:copy', id, 'Copy', 'Copy the full output') +
|
||||
outButton('out:wrap', id, 'Wrap', 'Wrap long lines on or off') +
|
||||
(tall ? outButton('out:expand', id, 'Expand', 'Show every line') : '') +
|
||||
outButton('out:download', id, '.txt', 'Download as a text file') +
|
||||
'</div>' +
|
||||
'<pre class="' + cls.join(' ') + '">' + esc(shown) + '</pre>' +
|
||||
(clean.length > OUT_MAX
|
||||
? '<div class="pl-out-note">Showing the first ' + OUT_MAX.toLocaleString() + ' of ' +
|
||||
clean.length.toLocaleString() + ' characters. Copy and .txt include all of it.</div>'
|
||||
: '') +
|
||||
'</div>';
|
||||
}
|
||||
|
||||
function outEntry(el) {
|
||||
return _outTexts.get(el.getAttribute('data-out')) || { text: '', name: 'output' };
|
||||
}
|
||||
|
||||
const outputActions = {
|
||||
'out:copy': async (el) => {
|
||||
const ok = LT().clipboard ? await LT().clipboard.copy(outEntry(el).text) : false;
|
||||
toastSafe(ok ? 'success' : 'error', ok ? 'Output copied' : 'Copy failed');
|
||||
},
|
||||
'out:wrap': () => {
|
||||
const wrap = storage.get(OUT_WRAP_KEY, true) === false; // currently off: turn on
|
||||
storage.set(OUT_WRAP_KEY, wrap);
|
||||
document.querySelectorAll('.pl-out-pre').forEach(p => p.classList.toggle('is-nowrap', !wrap));
|
||||
},
|
||||
'out:expand': (el) => {
|
||||
const block = document.getElementById(el.getAttribute('data-out'));
|
||||
const pre = block && block.querySelector('.pl-out-pre');
|
||||
if (!pre) return;
|
||||
const open = pre.classList.toggle('is-expanded');
|
||||
el.textContent = open ? 'Collapse' : 'Expand';
|
||||
},
|
||||
'out:download': (el) => {
|
||||
const e = outEntry(el);
|
||||
download(e.name + '.txt', e.text);
|
||||
},
|
||||
};
|
||||
|
||||
/* Verbatim localStorage keys: `commandHistory` and `pulse_executionView`
|
||||
must keep working across the redesign, so NO prefix is applied. */
|
||||
const storage = {
|
||||
@@ -673,7 +754,8 @@
|
||||
get beep() { return LT().beep; },
|
||||
esc: esc,
|
||||
fmt: fmt,
|
||||
util: { download: download, storage: storage, throttle: throttle },
|
||||
util: { download: download, storage: storage, throttle: throttle, stripAnsi: stripAnsi },
|
||||
output: { render: renderOutput },
|
||||
|
||||
/** Escape hatch for pages that need to push a frame upstream. */
|
||||
ws: { send(d) { return _wsHandle && _wsHandle.send ? _wsHandle.send(d) : false; }, get handle() { return _wsHandle; } },
|
||||
@@ -691,6 +773,7 @@
|
||||
'open-cmdpalette': () => { if (LT().cmdPalette) LT().cmdPalette.open(); },
|
||||
'app:keys-help': openKeysHelp,
|
||||
});
|
||||
actions.registerAll(outputActions);
|
||||
|
||||
installDelegation();
|
||||
|
||||
|
||||
@@ -71,10 +71,13 @@
|
||||
/* ------------------------------------------------------------------
|
||||
Loading
|
||||
------------------------------------------------------------------ */
|
||||
async function loadView(view, append) {
|
||||
// keepLoaded: a live refresh fetches as many rows as are already shown, so
|
||||
// rows brought in with Load More don't vanish when an event arrives (#17).
|
||||
async function loadView(view, append, keepLoaded) {
|
||||
const st = state[view];
|
||||
const offset = append ? st.offset : 0;
|
||||
const params = new URLSearchParams({ limit: String(LIMIT), offset: String(offset) });
|
||||
const limit = keepLoaded ? Math.min(Math.max(LIMIT, st.rows.length), 1000) : LIMIT;
|
||||
const params = new URLSearchParams({ limit: String(limit), offset: String(offset) });
|
||||
if (view === 'manual') params.set('hide_internal', 'true');
|
||||
if (view === 'automated') params.set('only_internal', 'true'); // server-side (#4)
|
||||
const term = searchTerm();
|
||||
@@ -102,8 +105,12 @@
|
||||
await loadView(state.view, false);
|
||||
render();
|
||||
}
|
||||
// Live events trigger this; coalesce bursts into at most one reload per 2 s (#10).
|
||||
const reloadCurrent = Pulse.util.throttle(reloadNow, 2000);
|
||||
// Live events trigger this; coalesce bursts into at most one reload per 2 s (#10),
|
||||
// keeping however many rows are loaded (#17).
|
||||
const reloadCurrent = Pulse.util.throttle(async () => {
|
||||
await loadView(state.view, false, true);
|
||||
render();
|
||||
}, 2000);
|
||||
|
||||
// Typing in the search box: search on the server once typing pauses (#16).
|
||||
let searchTimer = null;
|
||||
@@ -275,8 +282,9 @@
|
||||
return '<div class="ex-log-field"><span class="ex-log-label">' + esc(label) + ':</span> ' + value + '</div>';
|
||||
}
|
||||
|
||||
function out(text, isErr) {
|
||||
return '<pre class="lt-log-output' + (isErr ? ' ex-log-output-err' : '') + '">' + esc(text) + '</pre>';
|
||||
// Shared output block: ANSI stripped, Copy / Wrap / Expand / .txt (#27).
|
||||
function out(text, isErr, name) {
|
||||
return Pulse.output.render(text, { err: isErr, name: (name || 'pulse-output') + (isErr ? '-stderr' : '') });
|
||||
}
|
||||
|
||||
function promptOptions(options, executionId) {
|
||||
@@ -307,8 +315,8 @@
|
||||
(ok ? '✓' : '✗') + ' Command Result',
|
||||
field('Status', ok ? 'Success' : 'Failed') +
|
||||
(log.duration ? field('Duration', esc(log.duration) + 'ms') : '') +
|
||||
(log.stdout ? field('Output', out(log.stdout, false)) : '') +
|
||||
(log.stderr ? field('Errors', out(log.stderr, true)) : '') +
|
||||
(log.stdout ? field('Output', out(log.stdout, false, 'pulse-' + String(log.command_id || '').slice(0, 8))) : '') +
|
||||
(log.stderr ? field('Errors', out(log.stderr, true, 'pulse-' + String(log.command_id || '').slice(0, 8))) : '') +
|
||||
(log.error ? field('Error', esc(log.error)) : ''));
|
||||
}
|
||||
|
||||
|
||||
@@ -83,3 +83,31 @@
|
||||
color: var(--text-muted);
|
||||
font-size: 0.85em;
|
||||
}
|
||||
|
||||
/* Results under the form, one card per worker (#5). */
|
||||
.qc-run-summary {
|
||||
font-size: 0.75rem;
|
||||
color: var(--text-secondary);
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
.qc-run {
|
||||
border: 1px solid var(--border-dim, var(--border-color));
|
||||
background: var(--bg-primary);
|
||||
padding: 0.6rem 0.75rem;
|
||||
margin-bottom: 0.6rem;
|
||||
min-width: 0;
|
||||
}
|
||||
.qc-run-head {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 0.4rem 0.75rem;
|
||||
}
|
||||
.qc-run-time { color: var(--text-muted); font-size: 0.75rem; }
|
||||
.qc-run-link { margin-left: auto; font-size: 0.75rem; }
|
||||
.qc-out-err {
|
||||
color: var(--accent-red);
|
||||
border-left-color: var(--accent-red);
|
||||
text-shadow: none;
|
||||
}
|
||||
.qc-out-note { color: var(--text-muted); font-size: 0.72rem; margin-top: 0.4rem; }
|
||||
+129
-60
@@ -48,6 +48,16 @@
|
||||
/* -------------------------------------------------------------------
|
||||
Worker select / checkbox list
|
||||
------------------------------------------------------------------- */
|
||||
/* Last mode and worker choice, kept across reloads (#31). */
|
||||
const PREFS_KEY = 'pulse_qc_prefs';
|
||||
function loadPrefs() {
|
||||
const p = Pulse.util.storage.get(PREFS_KEY, null);
|
||||
return p && typeof p === 'object' ? p : {};
|
||||
}
|
||||
function savePrefs(patch) {
|
||||
Pulse.util.storage.set(PREFS_KEY, Object.assign(loadPrefs(), patch));
|
||||
}
|
||||
|
||||
function currentMode() {
|
||||
const checked = document.querySelector('input[name="qc-exec-mode"]:checked');
|
||||
return checked ? checked.value : 'single';
|
||||
@@ -78,7 +88,8 @@
|
||||
const wrap = document.getElementById('qc-worker-list');
|
||||
if (!wrap) return;
|
||||
if (workers.length === 0) {
|
||||
wrap.innerHTML = '<div class="lt-empty-state lt-empty-state--sm"><div class="lt-empty-state-title">No workers available</div></div>';
|
||||
wrap.innerHTML = '<div class="lt-empty-state lt-empty-state--sm"><div class="lt-empty-state-title">No workers available</div>' +
|
||||
'<div class="lt-empty-state-body">Connect one first: see <a href="/workers">Workers</a>.</div></div>';
|
||||
return;
|
||||
}
|
||||
const keep = preserveIds || new Set();
|
||||
@@ -98,10 +109,18 @@
|
||||
return Array.from(document.querySelectorAll('input[name="qc-worker-cb"]:checked')).map(cb => cb.value);
|
||||
}
|
||||
|
||||
let _restored = false;
|
||||
async function loadWorkers() {
|
||||
const select = document.getElementById('qc-worker');
|
||||
const preserveSingle = select ? select.value : '';
|
||||
const preserveMulti = new Set(selectedWorkerCheckboxIds());
|
||||
let preserveSingle = select ? select.value : '';
|
||||
let preserveMulti = new Set(selectedWorkerCheckboxIds());
|
||||
if (!_restored) {
|
||||
// First load: start from the saved choice rather than the first worker.
|
||||
_restored = true;
|
||||
const prefs = loadPrefs();
|
||||
preserveSingle = prefs.worker || preserveSingle;
|
||||
if (Array.isArray(prefs.workers)) preserveMulti = new Set(prefs.workers);
|
||||
}
|
||||
try {
|
||||
_workers = await Pulse.api.get('/api/workers') || [];
|
||||
} catch (e) {
|
||||
@@ -147,65 +166,110 @@
|
||||
/* -------------------------------------------------------------------
|
||||
Result rendering
|
||||
------------------------------------------------------------------- */
|
||||
function renderSingleSuccess(executionId) {
|
||||
const wrap = document.getElementById('qc-result');
|
||||
if (!wrap) return;
|
||||
wrap.innerHTML =
|
||||
'<div class="lt-alert lt-alert--success">' +
|
||||
'<span class="lt-alert-icon">✓</span>' +
|
||||
'<div class="lt-alert-body">' +
|
||||
'<div class="lt-alert-title">Command sent successfully</div>' +
|
||||
'<div class="lt-alert-msg">Execution ID: <code>' + esc(executionId) + '</code> | ' +
|
||||
'<a href="/executions?open=' + encodeURIComponent(executionId) + '">view in Executions</a>' +
|
||||
'</div>' +
|
||||
'</div>' +
|
||||
'</div>';
|
||||
/* Results show here as they arrive, per worker, instead of only in Executions (#5).
|
||||
A card per run: "running" until its command_result comes in over the live
|
||||
connection, or a poll finds it finished if that event was missed. */
|
||||
const _runs = new Map(); // execution id -> { card, startedAt, timer }
|
||||
const _early = new Map(); // results that beat the POST response
|
||||
|
||||
function forgetRuns() {
|
||||
_runs.forEach(r => clearTimeout(r.timer));
|
||||
_runs.clear();
|
||||
}
|
||||
|
||||
function renderSingleFailure(message) {
|
||||
function renderRuns(entries, summary) {
|
||||
forgetRuns();
|
||||
const wrap = document.getElementById('qc-result');
|
||||
if (!wrap) return;
|
||||
wrap.innerHTML =
|
||||
'<div class="lt-alert lt-alert--error">' +
|
||||
'<span class="lt-alert-icon">✕</span>' +
|
||||
'<div class="lt-alert-body">' +
|
||||
'<div class="lt-alert-title">Command failed</div>' +
|
||||
'<div class="lt-alert-msg">' + esc(message) + '</div>' +
|
||||
'</div>' +
|
||||
'</div>';
|
||||
const head = summary ? '<div class="qc-run-summary">' + esc(summary) + '</div>' : '';
|
||||
wrap.innerHTML = head + entries.map(runCard).join('');
|
||||
entries.forEach((e, i) => {
|
||||
if (!e.executionId) return;
|
||||
const run = { card: document.getElementById('qc-run-' + i), startedAt: Date.now(), timer: null };
|
||||
_runs.set(e.executionId, run);
|
||||
if (_early.has(e.executionId)) { showResult(e.executionId, _early.get(e.executionId)); return; }
|
||||
run.timer = setTimeout(() => pollRun(e.executionId, 0), 5000);
|
||||
});
|
||||
}
|
||||
|
||||
function renderMultiResult(results, successCount, failCount) {
|
||||
const wrap = document.getElementById('qc-result');
|
||||
if (!wrap) return;
|
||||
const rows = results.map(r =>
|
||||
'<tr>' +
|
||||
'<td data-label="Worker">' + esc(r.worker) + '</td>' +
|
||||
'<td data-label="Result">' +
|
||||
(r.success
|
||||
? '<span class="lt-status lt-status-completed">✓ Sent (' + esc(String(r.executionId || '').slice(0, 8)) + '…)</span>'
|
||||
: '<span class="lt-status lt-status-failed">✕ ' + esc(r.error) + '</span>') +
|
||||
'</td>' +
|
||||
'</tr>'
|
||||
).join('');
|
||||
wrap.innerHTML =
|
||||
'<div class="lt-alert' + (failCount === 0 ? ' lt-alert--success' : (successCount === 0 ? ' lt-alert--error' : ' lt-alert--warning')) + '">' +
|
||||
'<div class="lt-alert-body">' +
|
||||
'<div class="lt-alert-title">Multi-worker execution complete</div>' +
|
||||
'<div class="lt-alert-msg">Success: ' + successCount + ' | Failed: ' + failCount + '</div>' +
|
||||
'</div>' +
|
||||
'</div>' +
|
||||
'<table class="lt-table lt-table-sm lt-table-responsive">' +
|
||||
'<thead><tr><th>Worker</th><th>Result</th></tr></thead>' +
|
||||
'<tbody>' + rows + '</tbody>' +
|
||||
'</table>';
|
||||
function runCard(e, i) {
|
||||
const id = e.executionId;
|
||||
const worker = esc(e.worker);
|
||||
if (!id) {
|
||||
return '<div class="qc-run" id="qc-run-' + i + '"><div class="qc-run-head">' +
|
||||
'<strong class="qc-run-worker">' + worker + '</strong>' +
|
||||
'<span class="lt-status lt-status-failed qc-run-status">✕ Not sent</span></div>' +
|
||||
'<div class="qc-run-body"><pre class="lt-log-output qc-out-err">' + esc(e.error || 'Failed to send') + '</pre></div></div>';
|
||||
}
|
||||
return '<div class="qc-run" id="qc-run-' + i + '"><div class="qc-run-head">' +
|
||||
'<strong class="qc-run-worker">' + worker + '</strong>' +
|
||||
'<span class="lt-status lt-status-running qc-run-status">Running…</span>' +
|
||||
'<span class="qc-run-time"></span>' +
|
||||
'<a class="qc-run-link" href="/executions?open=' + encodeURIComponent(id) + '">view in Executions</a></div>' +
|
||||
'<div class="qc-run-body"></div></div>';
|
||||
}
|
||||
|
||||
function failureLabel(r) {
|
||||
if (r.timed_out) return 'Timed out';
|
||||
if (r.signal) return 'Killed (' + r.signal + ')';
|
||||
if (typeof r.exit_code === 'number') return 'Failed (exit ' + r.exit_code + ')';
|
||||
return 'Failed';
|
||||
}
|
||||
|
||||
function showResult(executionId, r) {
|
||||
const run = _runs.get(executionId);
|
||||
if (!run || !run.card) return;
|
||||
clearTimeout(run.timer);
|
||||
_runs.delete(executionId);
|
||||
_early.delete(executionId);
|
||||
const status = run.card.querySelector('.qc-run-status');
|
||||
const ok = Boolean(r.success);
|
||||
const label = ok ? 'Completed' : failureLabel(r);
|
||||
status.className = 'lt-status qc-run-status ' + (ok ? 'lt-status-completed' : 'lt-status-failed');
|
||||
status.textContent = (ok ? '\u2713 ' : '\u2715 ') + label;
|
||||
const ms = typeof r.duration === 'number' ? r.duration : Date.now() - run.startedAt;
|
||||
run.card.querySelector('.qc-run-time').textContent = ms < 1000 ? ms + ' ms' : (ms / 1000).toFixed(1) + ' s';
|
||||
const parts = [];
|
||||
const name = 'pulse-' + String(executionId).slice(0, 8);
|
||||
if (r.stdout) parts.push(Pulse.output.render(r.stdout, { cls: 'qc-out', name: name }));
|
||||
if (r.stderr) parts.push(Pulse.output.render(r.stderr, { err: true, cls: 'qc-out-err', name: name + '-stderr' }));
|
||||
if (!r.success && r.error && !r.stderr) parts.push('<pre class="lt-log-output qc-out-err">' + esc(r.error) + '</pre>');
|
||||
if (!parts.length) parts.push('<div class="qc-out-note">No output</div>');
|
||||
const body = run.card.querySelector('.qc-run-body');
|
||||
body.innerHTML = parts.join('');
|
||||
}
|
||||
|
||||
// Fallback for a result event that never arrived (e.g. the live connection dropped).
|
||||
async function pollRun(executionId, tries) {
|
||||
const run = _runs.get(executionId);
|
||||
if (!run) return;
|
||||
try {
|
||||
const ex = await Pulse.api.get('/api/executions/' + encodeURIComponent(executionId));
|
||||
if (ex && ex.status !== 'running') {
|
||||
const logs = Array.isArray(ex.logs) ? ex.logs : [];
|
||||
const r = logs.filter(l => l.action === 'command_result').pop();
|
||||
showResult(executionId, r || { success: ex.status === 'completed', error: 'No result recorded (' + ex.status + ')' });
|
||||
return;
|
||||
}
|
||||
} catch (e) { /* try again */ }
|
||||
if (tries < 180 && _runs.has(executionId)) run.timer = setTimeout(() => pollRun(executionId, tries + 1), 5000);
|
||||
}
|
||||
|
||||
function onCommandResult(data) {
|
||||
if (!data || !data.execution_id) return false;
|
||||
if (_runs.has(data.execution_id)) { showResult(data.execution_id, data); return true; }
|
||||
// Can arrive before the POST that started it returns: keep it briefly.
|
||||
_early.set(data.execution_id, data);
|
||||
if (_early.size > 100) _early.delete(_early.keys().next().value);
|
||||
return false;
|
||||
}
|
||||
|
||||
function renderExecuting(count) {
|
||||
forgetRuns();
|
||||
const wrap = document.getElementById('qc-result');
|
||||
if (!wrap) return;
|
||||
wrap.innerHTML = '<div class="lt-empty-state lt-empty-state--sm"><div class="lt-empty-state-title">Executing' +
|
||||
(count > 1 ? ' on ' + count + ' worker(s)' : '') + '…</div></div>';
|
||||
wrap.innerHTML = '<div class="lt-empty-state lt-empty-state--sm"><div class="lt-empty-state-title">Sending' +
|
||||
(count > 1 ? ' to ' + count + ' workers' : '') + '…</div></div>';
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------
|
||||
@@ -229,14 +293,14 @@
|
||||
}
|
||||
const worker = _workers.find(w => w.id === workerId);
|
||||
const workerName = worker ? worker.name : 'Unknown';
|
||||
savePrefs({ mode: 'single', worker: workerId });
|
||||
renderExecuting(1);
|
||||
try {
|
||||
const data = await Pulse.api.post('/api/workers/' + encodeURIComponent(workerId) + '/command', { command });
|
||||
addToHistory(command, workerName);
|
||||
renderSingleSuccess(data && data.execution_id);
|
||||
Pulse.beep('success');
|
||||
renderRuns([{ worker: workerName, executionId: data && data.execution_id }]);
|
||||
} catch (e) {
|
||||
renderSingleFailure(e.message || 'Failed to execute command');
|
||||
renderRuns([{ worker: workerName, error: e.message || 'Failed to execute command' }]);
|
||||
Pulse.beep('error');
|
||||
}
|
||||
return;
|
||||
@@ -247,6 +311,7 @@
|
||||
Pulse.toast.error('Please select at least one worker');
|
||||
return;
|
||||
}
|
||||
savePrefs({ mode: 'multi', workers: workerIds });
|
||||
renderExecuting(workerIds.length);
|
||||
// Send to every selected worker at once (#26); results keep the selection order.
|
||||
const results = await Promise.all(workerIds.map(async (workerId) => {
|
||||
@@ -262,10 +327,10 @@
|
||||
const successCount = results.filter(r => r.success).length;
|
||||
const failCount = results.length - successCount;
|
||||
addToHistory(command, workerIds.length + ' workers');
|
||||
renderMultiResult(results, successCount, failCount);
|
||||
if (failCount === 0) Pulse.beep('success');
|
||||
else if (successCount > 0) Pulse.beep('info');
|
||||
else Pulse.beep('error');
|
||||
renderRuns(results, failCount === 0
|
||||
? 'Sent to ' + successCount + ' workers'
|
||||
: 'Sent to ' + successCount + ' of ' + results.length + ' workers; ' + failCount + ' could not be reached');
|
||||
if (failCount > 0) Pulse.beep(successCount > 0 ? 'info' : 'error');
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------
|
||||
@@ -309,7 +374,7 @@
|
||||
|
||||
function init() {
|
||||
Pulse.actions.registerAll({
|
||||
'qc:mode': applyMode,
|
||||
'qc:mode': () => { applyMode(); savePrefs({ mode: currentMode() }); },
|
||||
'qc:templates-open': () => { renderTemplates(); if (window.lt && lt.modal) lt.modal.open('qc-templates-modal'); },
|
||||
'qc:template-use': (el) => {
|
||||
const idx = Number(el.getAttribute('data-index'));
|
||||
@@ -347,15 +412,19 @@
|
||||
lt.keys.on('ctrl+enter', () => { execute(); });
|
||||
}
|
||||
|
||||
const saved = loadPrefs().mode;
|
||||
const savedRadio = saved && document.querySelector('input[name="qc-exec-mode"][value="' + (saved === 'multi' ? 'multi' : 'single') + '"]');
|
||||
if (savedRadio) savedRadio.checked = true;
|
||||
applyMode();
|
||||
return loadWorkers().then(() => { consumeRerun(); });
|
||||
}
|
||||
|
||||
function onEvent(type) {
|
||||
function onEvent(type, data) {
|
||||
if (type === 'worker_update') {
|
||||
loadWorkers();
|
||||
return true;
|
||||
}
|
||||
if (type === 'command_result') return onCommandResult(data);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -94,7 +94,13 @@
|
||||
const wrap = document.getElementById('sc-wrap');
|
||||
if (!wrap) return;
|
||||
if (_schedules.length === 0) {
|
||||
wrap.innerHTML = '<div class="lt-empty-state"><div class="lt-empty-state-title">No scheduled commands yet</div></div>';
|
||||
wrap.innerHTML =
|
||||
'<div class="lt-empty-state">' +
|
||||
'<div class="lt-empty-state-title">No scheduled commands yet</div>' +
|
||||
'<div class="lt-empty-state-body">A schedule runs a command on the workers you pick, repeatedly. ' +
|
||||
'Try the command in <a href="/quick">Quick Command</a> first, then schedule it here.</div>' +
|
||||
'<button type="button" class="lt-btn lt-btn-primary" data-action="sc:create-open">+ New Schedule</button>' +
|
||||
'</div>';
|
||||
return;
|
||||
}
|
||||
wrap.innerHTML =
|
||||
@@ -128,7 +134,8 @@
|
||||
const wrap = document.getElementById('sc-worker-list');
|
||||
if (!wrap) return;
|
||||
if (_workers.length === 0) {
|
||||
wrap.innerHTML = '<div class="lt-empty-state lt-empty-state--sm"><div class="lt-empty-state-title">No workers available</div></div>';
|
||||
wrap.innerHTML = '<div class="lt-empty-state lt-empty-state--sm"><div class="lt-empty-state-title">No workers available</div>' +
|
||||
'<div class="lt-empty-state-body">Connect one first: see <a href="/workers">Workers</a>.</div></div>';
|
||||
return;
|
||||
}
|
||||
wrap.innerHTML = _workers.map(w =>
|
||||
|
||||
@@ -178,7 +178,10 @@
|
||||
'<div class="lt-empty-state">' +
|
||||
'<div class="lt-empty-state-icon">⚙</div>' +
|
||||
'<div class="lt-empty-state-title">No workers connected</div>' +
|
||||
'<div class="lt-empty-state-body">Workers appear here once they connect and send a heartbeat.</div>' +
|
||||
'<div class="lt-empty-state-body">A worker is a small agent that runs commands on its host. Install it there, ' +
|
||||
'set <code>WORKER_NAME</code>, <code>PULSE_SERVER</code>, <code>PULSE_WS</code> and <code>WORKER_API_KEY</code> ' +
|
||||
'(the server\'s key), and start it: it shows up here within a few seconds.</div>' +
|
||||
'<a class="lt-btn lt-btn-secondary" href="https://code.lotusguild.org/LotusGuild/pulse#pulse-worker-setup" target="_blank" rel="noopener">Worker setup guide</a>' +
|
||||
'</div>';
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -49,6 +49,8 @@
|
||||
'<div class="lt-empty-state-title">No workflows yet</div>' +
|
||||
'<div class="lt-empty-state-body">Workflows let you run multi-step jobs across one or more workers.</div>' +
|
||||
'<button type="button" class="lt-btn lt-btn-primary" data-action="wf:create-open">Create your first workflow</button>' +
|
||||
'<div class="lt-empty-state-body"><a href="https://code.lotusguild.org/LotusGuild/pulse#workflows" target="_blank" rel="noopener">Step types and examples</a>' +
|
||||
' · or try a single command in <a href="/quick">Quick Command</a></div>' +
|
||||
'</div>'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -630,6 +630,7 @@ wss.on('connection', (ws, req) => {
|
||||
stdout: stdout,
|
||||
stderr: stderr,
|
||||
...failure,
|
||||
duration: duration,
|
||||
is_automated: isAutomated,
|
||||
});
|
||||
|
||||
@@ -795,6 +796,14 @@ function broadcast(data) {
|
||||
}
|
||||
|
||||
// Helper function to add log entry to execution (atomic: no read-modify-write race condition)
|
||||
// One readable message for the UI, which shows only `error` (#25):
|
||||
// "Invalid workflow definition: step check: no step with id "nope"".
|
||||
function definitionError(problems) {
|
||||
const parts = problems.slice(0, 5).map(p => `step ${p.step}: ${p.error}`);
|
||||
if (problems.length > 5) parts.push(`and ${problems.length - 5} more`);
|
||||
return 'Invalid workflow definition: ' + parts.join('; ');
|
||||
}
|
||||
|
||||
async function addExecutionLog(executionId, logEntry) {
|
||||
try {
|
||||
await pool.query(
|
||||
@@ -1519,7 +1528,7 @@ app.post('/api/workflows', authenticateSSO, requireJSON, async (req, res) => {
|
||||
const { name, description, definition, webhook_url } = req.body;
|
||||
if (!name || !definition) return res.status(400).json({ error: 'name and definition are required' });
|
||||
const problems = [...conditionErrors(definition), ...gotoErrors(definition)];
|
||||
if (problems.length) return res.status(400).json({ error: 'Invalid workflow definition', problems });
|
||||
if (problems.length) return res.status(400).json({ error: definitionError(problems), problems });
|
||||
|
||||
const webhookCheck = validateWebhookUrl(webhook_url);
|
||||
if (!webhookCheck.ok) return res.status(400).json({ error: webhookCheck.reason });
|
||||
@@ -1864,7 +1873,7 @@ app.put('/api/workflows/:id', authenticateSSO, requireJSON, async (req, res) =>
|
||||
return res.status(400).json({ error: 'Invalid JSON in definition' });
|
||||
}
|
||||
const problems = [...conditionErrors(defObj), ...gotoErrors(defObj)];
|
||||
if (problems.length) return res.status(400).json({ error: 'Invalid workflow definition', problems });
|
||||
if (problems.length) return res.status(400).json({ error: definitionError(problems), problems });
|
||||
|
||||
const [result] = await pool.query(
|
||||
'UPDATE workflows SET name=?, description=?, definition=?, webhook_url=?, updated_at=NOW() WHERE id=?',
|
||||
|
||||
@@ -256,3 +256,12 @@ test('a failure on one target fails the step, after every target has reported (#
|
||||
expect(outputs(ex).filter(o => o === 'ok')).toHaveLength(2);
|
||||
expect(outputs(ex)).not.toContain('should-not-run');
|
||||
});
|
||||
|
||||
test('a rejected definition says what is wrong in the error itself (#25)', async () => {
|
||||
const res = await sso('POST', '/api/workflows', { name: `bad-goto-${unique()}`, definition: { steps: [
|
||||
{ id: 'check', type: 'execute', command: 'true', goto: 'nope' },
|
||||
] } });
|
||||
expect(res.status).toBe(400);
|
||||
expect(res.json.error).toBe('Invalid workflow definition: step check: no step with id "nope"');
|
||||
expect(res.json.problems).toHaveLength(1);
|
||||
});
|
||||
@@ -74,3 +74,24 @@ test.describe('first visit in a session', () => {
|
||||
await expect(page.locator('#lt-boot-text')).toContainText('ALL SYSTEMS NOMINAL: PULSE', { timeout: 15_000 });
|
||||
});
|
||||
});
|
||||
|
||||
test('empty states say what to do next (#33)', async ({ page }) => {
|
||||
for (const path of ['/api/workers', '/api/scheduled-commands', '/api/workflows']) {
|
||||
await page.route(u => u.pathname === path, r => r.fulfill({ json: [] }));
|
||||
}
|
||||
await page.goto('/workers');
|
||||
await expect(page.locator('#wk-grid')).toContainText('WORKER_API_KEY');
|
||||
await expect(page.getByRole('link', { name: 'Worker setup guide' })).toHaveAttribute('href', /#pulse-worker-setup$/);
|
||||
|
||||
await page.goto('/scheduler');
|
||||
await page.locator('#sc-wrap').getByRole('button', { name: '+ New Schedule' }).click();
|
||||
await expect(page.locator('#sc-create-modal')).toBeVisible();
|
||||
await page.keyboard.press('Escape');
|
||||
|
||||
await page.goto('/quick');
|
||||
await page.locator('#qc-mode-multi').check(); // the checkbox list is the multi-worker picker
|
||||
await expect(page.locator('#qc-worker-list').getByRole('link', { name: 'Workers' })).toHaveAttribute('href', '/workers');
|
||||
|
||||
await page.goto('/workflows');
|
||||
await expect(page.getByRole('link', { name: 'Step types and examples' })).toHaveAttribute('href', /#workflows$/);
|
||||
});
|
||||
@@ -13,8 +13,11 @@ test('a quick command runs on a worker and its output shows in Executions', asyn
|
||||
await page.locator('#qc-command').fill(`echo ${marker}`);
|
||||
await page.locator('#qc-execute-btn').click();
|
||||
|
||||
// The output shows right under the form (#5), with a link to the full record.
|
||||
const result = page.locator('#qc-result');
|
||||
await expect(result).toContainText('Command sent successfully');
|
||||
await expect(result.locator('.qc-run-status')).toHaveText(/Completed/);
|
||||
await expect(result.locator('pre.qc-out')).toHaveText(marker);
|
||||
await expect(result).toContainText('node-02');
|
||||
await result.getByRole('link', { name: 'view in Executions' }).click();
|
||||
|
||||
await expect(page).toHaveURL(/\/executions/);
|
||||
@@ -34,7 +37,10 @@ test('a failing command is reported as failed with its stderr', async ({ page })
|
||||
await page.locator('#qc-command').fill(`echo ${marker} >&2; exit 3`);
|
||||
await page.locator('#qc-command').press('Control+Enter'); // the documented shortcut
|
||||
|
||||
await page.locator('#qc-result').getByRole('link', { name: 'view in Executions' }).click();
|
||||
const result = page.locator('#qc-result');
|
||||
await expect(result.locator('.qc-run-status')).toHaveText(/Failed \(exit 3\)/);
|
||||
await expect(result.locator('pre.qc-out-err')).toHaveText(marker);
|
||||
await result.getByRole('link', { name: 'view in Executions' }).click();
|
||||
const detail = page.locator('#ex-detail-body');
|
||||
await expect(detail).toContainText(marker);
|
||||
await expect(detail).toContainText(/failed/i);
|
||||
@@ -44,13 +50,19 @@ test('multi-worker mode sends the command to every selected worker', async ({ pa
|
||||
await page.goto('/quick');
|
||||
await page.locator('label[for="qc-mode-multi"], #qc-mode-multi').first().click();
|
||||
await page.getByRole('button', { name: /select all/i }).click();
|
||||
await page.locator('#qc-command').fill(`echo ${token()}`);
|
||||
await page.locator('#qc-command').fill('echo "$WORKER_NAME says hi"');
|
||||
await page.locator('#qc-execute-btn').click();
|
||||
|
||||
// One card per worker, each with its own output (#5).
|
||||
const result = page.locator('#qc-result');
|
||||
await expect(result).toContainText('Success: 3');
|
||||
await expect(result).toContainText('Failed: 0');
|
||||
await expect(result.locator('tbody tr')).toHaveCount(3);
|
||||
await expect(result).toContainText('Sent to 3 workers');
|
||||
const runs = result.locator('.qc-run');
|
||||
await expect(runs).toHaveCount(3);
|
||||
for (const n of ['node-01', 'node-02', 'node-03']) {
|
||||
const card = runs.filter({ hasText: n });
|
||||
await expect(card.locator('.qc-run-status')).toHaveText(/Completed/);
|
||||
await expect(card.locator('pre.qc-out')).toHaveText(`${n} says hi`);
|
||||
}
|
||||
});
|
||||
|
||||
test('Executions updates live when a command starts elsewhere', async ({ page, request }) => {
|
||||
@@ -80,3 +92,114 @@ test('searching Executions finds a run by its command (#16)', async ({ page, req
|
||||
await expect(rows).toHaveCount(1);
|
||||
await expect(rows.first()).toHaveAttribute('data-execution-id', id);
|
||||
});
|
||||
|
||||
test('Quick Command remembers the mode and workers after a reload (#31)', async ({ page }) => {
|
||||
await page.goto('/quick');
|
||||
await page.locator('#qc-mode-multi').check();
|
||||
const boxes = page.locator('#qc-worker-list label');
|
||||
await boxes.filter({ hasText: 'node-02' }).locator('input').check();
|
||||
await boxes.filter({ hasText: 'node-03' }).locator('input').check();
|
||||
await page.locator('#qc-command').fill('true');
|
||||
await page.locator('#qc-execute-btn').click();
|
||||
await expect(page.locator('#qc-result')).toContainText('Sent to 2 workers');
|
||||
|
||||
await page.reload();
|
||||
await expect(page.locator('#qc-mode-multi')).toBeChecked();
|
||||
await expect(boxes.filter({ hasText: 'node-02' }).locator('input')).toBeChecked();
|
||||
await expect(boxes.filter({ hasText: 'node-03' }).locator('input')).toBeChecked();
|
||||
await expect(boxes.filter({ hasText: 'node-01' }).locator('input')).not.toBeChecked();
|
||||
|
||||
// Single mode remembers its worker too.
|
||||
await page.locator('#qc-mode-single').check();
|
||||
const node3 = await page.locator('#qc-worker option', { hasText: 'node-03' }).getAttribute('value');
|
||||
await page.locator('#qc-worker').selectOption(node3);
|
||||
await page.locator('#qc-command').fill('true'); // the reload emptied it
|
||||
await page.locator('#qc-execute-btn').click();
|
||||
await expect(page.locator('#qc-result .qc-run-status')).toHaveText(/Completed/);
|
||||
await page.reload();
|
||||
await expect(page.locator('#qc-mode-single')).toBeChecked();
|
||||
await expect(page.locator('#qc-worker option:checked')).toContainText('node-03');
|
||||
});
|
||||
|
||||
test('a live update keeps the rows brought in with Load More (#17)', async ({ page, request }) => {
|
||||
const workers = await (await request.get('/api/workers')).json();
|
||||
const id = workers.find(w => w.name === 'node-01').id;
|
||||
const send = () => request.post(`/api/workers/${id}/command`, { data: { command: 'true' } });
|
||||
for (let i = 0; i < 60; i++) await send();
|
||||
|
||||
await page.goto('/executions');
|
||||
const rows = page.locator('#ex-list-manual .ex-row');
|
||||
await expect(rows).toHaveCount(50);
|
||||
await page.getByRole('button', { name: 'Load More Executions' }).click();
|
||||
await expect.poll(() => rows.count()).toBeGreaterThan(50);
|
||||
const shown = await rows.count();
|
||||
|
||||
// A live event: the list refreshes with the new run on top, and still shows
|
||||
// as many rows as before rather than dropping back to the first 50.
|
||||
const marker = `live-${Date.now().toString(36)}`;
|
||||
await request.post(`/api/workers/${id}/command`, { data: { command: `echo ${marker}` } });
|
||||
await expect(rows.first()).toContainText(marker, { timeout: 10_000 });
|
||||
await expect(rows).toHaveCount(shown);
|
||||
});
|
||||
|
||||
test('the result still shows when the live update is missed (#5)', async ({ page }) => {
|
||||
// No live connection at all: the page has to find the result by polling.
|
||||
await page.routeWebSocket(/.*/, () => { /* never connects to the server */ });
|
||||
const marker = token();
|
||||
await page.goto('/quick');
|
||||
await page.locator('#qc-worker').selectOption({ label: 'node-03 (online)' });
|
||||
await page.locator('#qc-command').fill(`echo ${marker}`);
|
||||
await page.locator('#qc-execute-btn').click();
|
||||
|
||||
const result = page.locator('#qc-result');
|
||||
await expect(result.locator('.qc-run-status')).toHaveText(/Running/);
|
||||
await expect(result.locator('pre.qc-out')).toHaveText(marker, { timeout: 15_000 });
|
||||
await expect(result.locator('.qc-run-status')).toHaveText(/Completed/);
|
||||
});
|
||||
|
||||
test('only the worker picker for the chosen mode is shown', async ({ page }) => {
|
||||
await page.goto('/quick');
|
||||
await page.locator('#qc-mode-single').check();
|
||||
await expect(page.locator('#qc-single-mode')).toBeVisible();
|
||||
await expect(page.locator('#qc-multi-mode')).toBeHidden();
|
||||
await page.locator('#qc-mode-multi').check();
|
||||
await expect(page.locator('#qc-multi-mode')).toBeVisible();
|
||||
await expect(page.locator('#qc-single-mode')).toBeHidden();
|
||||
});
|
||||
|
||||
test('output is readable: colours stripped, Copy / Wrap / Expand / .txt (#27)', async ({ page, context }) => {
|
||||
await context.grantPermissions(['clipboard-read', 'clipboard-write']);
|
||||
await page.goto('/quick');
|
||||
await page.locator('#qc-mode-single').check();
|
||||
await page.locator('#qc-worker').selectOption({ label: 'node-01 (online)' });
|
||||
await page.locator('#qc-command').fill(`printf '\\033[1;32mgreen\\033[0m plain\\n'; seq 1 40`);
|
||||
await page.locator('#qc-execute-btn').click();
|
||||
|
||||
const block = page.locator('#qc-result .pl-out').first();
|
||||
const pre = block.locator('pre');
|
||||
await expect(pre).toContainText('green plain');
|
||||
expect(await pre.textContent()).not.toContain('\u001b'); // no raw escape codes
|
||||
|
||||
// 41 lines: starts collapsed, Expand shows everything.
|
||||
await expect(pre).toHaveClass(/is-tall/);
|
||||
await block.getByRole('button', { name: 'Expand' }).click();
|
||||
await expect(pre).toHaveClass(/is-expanded/);
|
||||
await expect(block.getByRole('button', { name: 'Collapse' })).toBeVisible();
|
||||
|
||||
// Wrap toggles long-line wrapping, and the choice sticks.
|
||||
await block.getByRole('button', { name: 'Wrap' }).click();
|
||||
await expect(pre).toHaveClass(/is-nowrap/);
|
||||
await block.getByRole('button', { name: 'Wrap' }).click();
|
||||
await expect(pre).not.toHaveClass(/is-nowrap/);
|
||||
|
||||
// Copy gives the full, clean text.
|
||||
await block.getByRole('button', { name: 'Copy' }).click();
|
||||
const copied = await page.evaluate(() => navigator.clipboard.readText());
|
||||
expect(copied.startsWith('green plain\n1\n2\n')).toBe(true);
|
||||
expect(copied.trim().endsWith('40')).toBe(true);
|
||||
|
||||
// .txt downloads the same text.
|
||||
const [dl] = await Promise.all([page.waitForEvent('download'), block.getByRole('button', { name: '.txt' }).click()]);
|
||||
expect(dl.suggestedFilename()).toMatch(/^pulse-[0-9a-f]{8}\.txt$/);
|
||||
expect(require('fs').readFileSync(await dl.path(), 'utf8')).toBe(copied);
|
||||
});
|
||||
@@ -43,6 +43,30 @@ test('an invalid workflow definition is rejected with a message', async ({ page,
|
||||
expect(problems).toEqual([]); // rejected in the browser, so no failed request either
|
||||
});
|
||||
|
||||
test('a definition the server rejects shows the server\'s reason (#25)', async ({ page, problems }) => {
|
||||
await page.goto('/workflows');
|
||||
await page.getByRole('button', { name: '+ Create Workflow' }).click();
|
||||
await page.locator('#wf-create-name').fill(`Bad goto ${Date.now()}`);
|
||||
await page.locator('#wf-create-definition').fill(JSON.stringify({ steps: [
|
||||
{ id: 'check', type: 'execute', command: 'true', goto: 'nope' },
|
||||
] }));
|
||||
await page.locator('#wf-create-form').getByRole('button', { name: 'Create' }).click();
|
||||
await expect(page.locator('#wf-create-error')).toContainText('no step with id "nope"');
|
||||
// The 400 (and the browser's console line for it) is the point of this test.
|
||||
expect(problems.every(p => /400/.test(p))).toBe(true);
|
||||
problems.length = 0;
|
||||
});
|
||||
|
||||
test('Escape closes the Run dialog (#25)', async ({ page, request }) => {
|
||||
const name = `UI esc ${Date.now()}`;
|
||||
await request.post('/api/workflows', { data: { name, definition: { steps: [{ id: 'a', type: 'execute', command: 'true' }] } } });
|
||||
await page.goto('/workflows');
|
||||
await page.locator('#wf-list tr', { hasText: name }).getByRole('button', { name: 'Execute' }).click();
|
||||
await expect(page.locator('#wf-run-modal')).toBeVisible();
|
||||
await page.keyboard.press('Escape');
|
||||
await expect(page.locator('#wf-run-modal')).toBeHidden();
|
||||
});
|
||||
|
||||
test('a run waiting on a prompt shows as waiting, and the Waiting filter finds it (#3)', async ({ page, request }) => {
|
||||
const created = await request.post('/api/workflows', { data: { name: `UI wait ${Date.now()}`, definition: { steps: [
|
||||
{ id: 'ask', type: 'prompt', message: 'Proceed?', options: ['Yes'] },
|
||||
|
||||
@@ -126,7 +126,9 @@ describe('cancel_command (#8)', () => {
|
||||
test('cancelling stops the command and everything it started', async () => {
|
||||
const w = makeWorker();
|
||||
const pidFile = path.join(fs.mkdtempSync(path.join(os.tmpdir(), 'pulse-cancel-')), 'pid');
|
||||
const pending = w.executeCommand({ command: `sleep 30 & echo $! > ${pidFile}; wait`, execution_id: 'ex-c', command_id: 'cmd-c' });
|
||||
// Write then rename: the shell creates a redirect target before writing to it,
|
||||
// so reading ${pidFile} directly could see an empty file (pid 0).
|
||||
const pending = w.executeCommand({ command: `sleep 30 & echo $! > ${pidFile}.tmp && mv ${pidFile}.tmp ${pidFile}; wait`, execution_id: 'ex-c', command_id: 'cmd-c' });
|
||||
for (let i = 0; i < 50 && !fs.existsSync(pidFile); i++) await new Promise(r => setTimeout(r, 50));
|
||||
const childPid = Number(fs.readFileSync(pidFile, 'utf8'));
|
||||
expect(alive(childPid)).toBe(true);
|
||||
|
||||
Reference in new issue
Block a user