Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9a24aff537 | ||
|
|
43769460fc | ||
|
|
2e62eb09f5 | ||
|
|
1ef3e291c2 | ||
|
|
3694f2501b | ||
|
|
c3d58d7111 | ||
|
|
da45cc36a3 |
No files matched your search
@@ -8,6 +8,7 @@ function createBatchFindWork({
|
||||
storage = typeof localStorage === 'undefined' ? null : localStorage,
|
||||
owner = () => '',
|
||||
journalName = 'find-work-batch',
|
||||
queueFailureReason = 'assigned but Today sync is unavailable',
|
||||
autoMount = true,
|
||||
}) {
|
||||
let request = null;
|
||||
@@ -58,7 +59,7 @@ function createBatchFindWork({
|
||||
entry.state = 'assigned';
|
||||
writeJournal(journal);
|
||||
}
|
||||
const queueResult = await queue(confirmed);
|
||||
const queueResult = await queue(confirmed, journal.context);
|
||||
if (queueResult === 'queued' || queueResult === 'exists') {
|
||||
queued.push(key(item));
|
||||
entry.state = 'queued';
|
||||
@@ -67,7 +68,7 @@ function createBatchFindWork({
|
||||
}
|
||||
writeJournal(journal);
|
||||
} else {
|
||||
failed.push({ key: key(item), reason: 'assigned but Today sync is unavailable', assigned: true });
|
||||
failed.push({ key: key(item), reason: queueFailureReason, assigned: true });
|
||||
}
|
||||
} catch (error) {
|
||||
failed.push({ key: key(item), reason: error?.message || 'assignment failed' });
|
||||
@@ -81,7 +82,7 @@ function createBatchFindWork({
|
||||
return outcome;
|
||||
}
|
||||
|
||||
function run(items, estimates = {}) {
|
||||
function run(items, estimates = {}, context = null) {
|
||||
if (request) return request;
|
||||
const selected = Array.isArray(items) ? items.slice() : [];
|
||||
const available = Math.max(0, Number(capacity()) || 0);
|
||||
@@ -112,7 +113,7 @@ function createBatchFindWork({
|
||||
}
|
||||
}
|
||||
const journal = {
|
||||
owner: String(owner() || ''), available,
|
||||
owner: String(owner() || ''), available, context,
|
||||
items: selected.map(item => ({ item, estimate: estimates[key(item)] || null, state: 'pending' })),
|
||||
};
|
||||
writeJournal(journal);
|
||||
|
||||
+17
-1
@@ -129,11 +129,27 @@ textarea { resize: vertical; min-height: 120px; }
|
||||
.cmd-select-result { min-height:44px; width:100%; display:grid; grid-template-columns:28px 1fr auto; gap:10px; align-items:center; text-align:left; }
|
||||
.cmd-select-result input { width:22px; height:22px; }
|
||||
.cmd-select-result[disabled] { cursor:not-allowed; opacity:.62; }
|
||||
.search-batch-actions { position:sticky; bottom:0; z-index:3; display:grid; grid-template-columns:1fr 1fr; gap:8px; padding:10px 0 calc(10px + env(safe-area-inset-bottom)); background:#0b1526; border-top:1px solid #2a496e; }
|
||||
.search-batch-actions { position:sticky; bottom:0; z-index:3; display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:8px; padding:10px 0 calc(10px + env(safe-area-inset-bottom)); background:#0b1526; border-top:1px solid #2a496e; }
|
||||
.search-batch-actions[hidden] { display:none; }
|
||||
.search-batch-actions span { grid-column:1 / -1; }
|
||||
.search-batch-actions button, .search-batch-recovery { min-height:44px; }
|
||||
.search-batch-recovery { width:100%; font-weight:700; }
|
||||
.search-batch-estimate-review { display:grid; gap:12px; padding:12px; border:1px solid #2a496e; border-radius:12px; background:#101f36; }
|
||||
.search-batch-estimate-review[hidden] { display:none; }
|
||||
.search-batch-estimate-review > div:first-child, #search-batch-estimate-list { display:grid; gap:8px; }
|
||||
.search-batch-estimate-row { display:grid; grid-template-columns:minmax(0,1fr) minmax(92px,auto); gap:10px; align-items:center; overflow-wrap:anywhere; }
|
||||
.search-batch-estimate-row label { display:flex; align-items:center; gap:6px; }
|
||||
.search-batch-estimate-review input { min-height:44px; width:76px; }
|
||||
.search-batch-estimate-actions { position:sticky; bottom:0; display:grid; grid-template-columns:1fr 1fr; gap:8px; padding-bottom:env(safe-area-inset-bottom); background:#101f36; }
|
||||
.search-batch-estimate-actions button { min-height:44px; }
|
||||
.search-release-review { display:grid; gap:12px; max-height:calc(100dvh - 48px); overflow:auto; padding:12px; border:1px solid #2a496e; border-radius:12px; background:#101f36; overflow-wrap:anywhere; }
|
||||
.search-release-review[hidden] { display:none; }
|
||||
.search-release-review > div:first-child, #search-release-list, .search-release-row { display:grid; gap:6px; }
|
||||
.search-release-review label { display:grid; gap:6px; }
|
||||
.search-release-review select, .search-release-review input { min-height:44px; width:100%; }
|
||||
.search-release-row { padding:8px 0; border-bottom:1px solid #2a496e; }
|
||||
.search-release-actions { position:sticky; bottom:0; display:grid; grid-template-columns:1fr 1fr; gap:8px; padding-bottom:env(safe-area-inset-bottom); background:#101f36; }
|
||||
.search-release-actions button { min-height:44px; }
|
||||
|
||||
.cmd-group { padding:8px 10px 3px; color:#60a5fa; font-size:11px; font-weight:700; letter-spacing:.08em; text-transform:uppercase; }
|
||||
#whiteboard-modal, #markdown-modal { position: fixed; inset: 0; background: rgba(5,12,21,.55); display: none; align-items: center; justify-content: center; z-index: 40; backdrop-filter: blur(6px); }
|
||||
|
||||
@@ -4424,8 +4424,8 @@
|
||||
});
|
||||
searchBatchPlanning = mountSearchBatchPlanning(
|
||||
document, createBatchFindWork, todayWork, ()=>planningOwnerLogin, fetchReviewJson,
|
||||
searchPreviewPath, queueToday, acceptClaimedIssue, index=>commandItems[index]?.result,
|
||||
()=>renderCommands(qs('#cmd-input').value), escapeHtml, escAttr
|
||||
searchPreviewPath, queueToday, todaySync, acceptClaimedIssue, i=>commandItems[i]?.result,
|
||||
()=>renderCommands(qs('#cmd-input').value), escapeHtml, escAttr, laterWork, laterPicker
|
||||
);
|
||||
searchDefer = createSearchDefer({
|
||||
claim: detail => searchPreview.claim(detail),
|
||||
|
||||
@@ -458,8 +458,33 @@
|
||||
<div class="search-batch-actions" id="search-batch-actions" hidden>
|
||||
<span id="search-selection-status" class="small" aria-live="polite">No issues selected.</span>
|
||||
<button id="cancel-search-selection" type="button">Cancel</button>
|
||||
<button id="defer-selected-search-results" type="button" disabled>Defer</button>
|
||||
<button id="plan-selected-search-results" type="button" disabled>Plan release</button>
|
||||
<button id="queue-selected-search-results" type="button" disabled>Assign & add to Today</button>
|
||||
</div>
|
||||
<section class="search-batch-estimate-review" id="search-batch-estimate-review"
|
||||
aria-labelledby="search-batch-estimate-heading" hidden>
|
||||
<div><strong id="search-batch-estimate-heading">Fit this work into Today</strong>
|
||||
<span class="small" id="search-batch-estimate-summary" aria-live="polite"></span></div>
|
||||
<div id="search-batch-estimate-list"></div>
|
||||
<div class="search-batch-estimate-actions">
|
||||
<button id="cancel-search-batch-estimates" type="button">Back</button>
|
||||
<button id="confirm-search-batch-estimates" type="button">Confirm & assign</button>
|
||||
</div>
|
||||
</section>
|
||||
<section class="search-release-review" id="search-release-review"
|
||||
aria-labelledby="search-release-heading" hidden>
|
||||
<div><strong id="search-release-heading">Plan selected issues into a release</strong>
|
||||
<span class="small" id="search-release-summary" aria-live="polite"></span></div>
|
||||
<label>Open milestone<select id="search-release-milestone" required></select></label>
|
||||
<label>Shared due date <span class="small">(optional)</span>
|
||||
<input id="search-release-due-date" type="date" /></label>
|
||||
<div id="search-release-list"></div>
|
||||
<div class="search-release-actions">
|
||||
<button id="cancel-search-release" type="button">Back</button>
|
||||
<button id="confirm-search-release" type="button">Assign & plan</button>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
|
||||
<div class="search-preview" id="search-preview" role="dialog" aria-modal="true" aria-labelledby="search-preview-title">
|
||||
|
||||
@@ -90,7 +90,8 @@ function createLaterPicker({
|
||||
onState({ open:true, message:result.message, value:String(input || '') });
|
||||
return false;
|
||||
}
|
||||
const confirmed = onConfirm(item, result.value, context);
|
||||
const confirmed = typeof item?.confirm === 'function' ? item.confirm(result.value) :
|
||||
onConfirm(item, result.value, context);
|
||||
if (confirmed !== true && typeof confirmed !== 'function') return false;
|
||||
committed = true;
|
||||
afterClose = typeof confirmed === 'function' ? confirmed : null;
|
||||
|
||||
@@ -57,15 +57,23 @@
|
||||
if (detail?.claimable) return claim(detail);
|
||||
throw new Error('This issue is no longer available to assign.');
|
||||
}
|
||||
return { identity, eligible, start, cancel, toggle, snapshot, prepare, limit:maximum };
|
||||
function releaseRepository() {
|
||||
const repositories = new Set(Array.from(selected.values()).map(item => item.repository));
|
||||
return repositories.size === 1 ? repositories.values().next().value : null;
|
||||
}
|
||||
return { identity, eligible, start, cancel, toggle, snapshot, prepare, releaseRepository, limit:maximum };
|
||||
}
|
||||
|
||||
createSearchBatchPlan.mount = function mountSearchBatchPlanning(
|
||||
document, batchFactory, todayWork, getOwner, fetchJson, previewPath, queueToday,
|
||||
acceptIssue, lookup, render, escapeHtml, escapeAttribute
|
||||
todaySync, acceptIssue, lookup, render, escapeHtml, escapeAttribute,
|
||||
laterWork = null, laterPicker = null
|
||||
) {
|
||||
const get = selector => document.querySelector(selector);
|
||||
let processor;
|
||||
let laterProcessor;
|
||||
let releaseProcessor;
|
||||
let releaseContext = null;
|
||||
const plan = createSearchBatchPlan({
|
||||
resolve:item => fetchJson(previewPath(item), {headers:{Accept:'application/json'}}),
|
||||
claim:detail => fetchJson(
|
||||
@@ -77,6 +85,8 @@
|
||||
get('#search-batch-actions').hidden = !state.active;
|
||||
get('#select-search-results').hidden = state.active;
|
||||
get('#queue-selected-search-results').disabled = state.count === 0;
|
||||
get('#defer-selected-search-results').disabled = state.count === 0;
|
||||
get('#plan-selected-search-results').disabled = state.count === 0;
|
||||
get('#search-selection-status').textContent = state.count ?
|
||||
state.count + ' issue' + (state.count === 1 ? '' : 's') + ' selected.' : 'No issues selected.';
|
||||
render();
|
||||
@@ -85,10 +95,24 @@
|
||||
processor = batchFactory({
|
||||
capacity:() => Math.max(0, todayWork.limit - todayWork.read().length),
|
||||
owner:getOwner,
|
||||
timeBudget:() => {
|
||||
const planning = todayWork.planning();
|
||||
return {
|
||||
capacity_minutes:planning.capacity_minutes,
|
||||
planned_minutes:Object.values(planning.estimates || {}).reduce((sum, minutes) => sum + minutes, 0),
|
||||
};
|
||||
},
|
||||
journalName:'search-today-batch',
|
||||
autoMount:false,
|
||||
claim:item => plan.prepare(item),
|
||||
queue:confirmed => queueToday(acceptIssue(confirmed)),
|
||||
persistEstimate:(confirmed, minutes) => {
|
||||
const planning = todayWork.planning();
|
||||
planning.estimates[todayWork.identity(confirmed)] = minutes;
|
||||
todayWork.replacePlanning(planning);
|
||||
todaySync.enqueueConfiguration(planning.capacity_minutes, planning.estimates);
|
||||
todaySync.flush();
|
||||
},
|
||||
onProgress:progress => {
|
||||
get('#queue-selected-search-results').disabled = progress.status === 'running';
|
||||
if (progress.status === 'running') {
|
||||
@@ -96,19 +120,193 @@
|
||||
} else if (progress.status === 'full') {
|
||||
get('#search-selection-status').textContent = 'Today has ' + progress.available + ' remaining slot' +
|
||||
(progress.available === 1 ? '.' : 's.');
|
||||
} else if (progress.status === 'estimates-required') {
|
||||
get('#search-batch-estimate-summary').textContent = 'Estimate every selected issue.';
|
||||
} else if (progress.status === 'over-budget') {
|
||||
get('#search-batch-estimate-summary').textContent = progress.requested_minutes +
|
||||
' min selected · ' + progress.remaining_minutes + ' min remain.';
|
||||
} else if (progress.status === 'complete') {
|
||||
get('#cmd-search-action-status').textContent = progress.failed.length ?
|
||||
progress.queued.length + ' queued · ' + progress.failed.length + ' need retry.' :
|
||||
progress.queued.length + ' added to Today.';
|
||||
get('#resume-search-batch').hidden = processor.pending() === 0;
|
||||
closeEstimateReview();
|
||||
if (!progress.failed.length) plan.cancel();
|
||||
}
|
||||
},
|
||||
});
|
||||
laterProcessor = batchFactory({
|
||||
capacity:() => plan.limit,
|
||||
owner:getOwner,
|
||||
journalName:'search-later-batch',
|
||||
queueFailureReason:'assigned but Later could not be saved',
|
||||
autoMount:false,
|
||||
claim:item => plan.prepare(item),
|
||||
queue:(confirmed, context) => {
|
||||
const outcome = laterWork?.defer(acceptIssue(confirmed), context?.until);
|
||||
return outcome === 'deferred' ? 'queued' : outcome;
|
||||
},
|
||||
onProgress:progress => {
|
||||
get('#defer-selected-search-results').disabled = progress.status === 'running';
|
||||
if (progress.status === 'running') {
|
||||
get('#search-selection-status').textContent = 'Deferring ' + progress.processed + ' of ' + progress.selected + '…';
|
||||
} else if (progress.status === 'complete') {
|
||||
get('#cmd-search-action-status').textContent = progress.failed.length ?
|
||||
progress.queued.length + ' deferred · ' + progress.failed.length + ' need retry.' :
|
||||
progress.queued.length + ' added to Later.';
|
||||
restore();
|
||||
if (!progress.failed.length) plan.cancel();
|
||||
}
|
||||
},
|
||||
});
|
||||
releaseProcessor = batchFactory({
|
||||
capacity:() => plan.limit,
|
||||
owner:getOwner,
|
||||
journalName:'search-release-batch',
|
||||
queueFailureReason:'assigned but release planning could not be confirmed',
|
||||
autoMount:false,
|
||||
claim:item => plan.prepare(item),
|
||||
queue:async (confirmed, context) => {
|
||||
const issuePath = 'api/v1/repos/' + confirmed.repository.split('/').map(encodeURIComponent).join('/') +
|
||||
'/issues/' + encodeURIComponent(confirmed.number);
|
||||
const milestone = await fetchJson(issuePath + '/milestone', {
|
||||
method:'PATCH', headers:{Accept:'application/json','Content-Type':'application/json'},
|
||||
body:JSON.stringify({milestone_id:context.milestone_id}),
|
||||
});
|
||||
if (milestone?.number !== confirmed.number || milestone?.milestone?.id !== context.milestone_id) {
|
||||
throw new Error('Issue milestone was not confirmed.');
|
||||
}
|
||||
if (context.due_date) {
|
||||
const deadline = await fetchJson(issuePath + '/due-date', {
|
||||
method:'PATCH', headers:{Accept:'application/json','Content-Type':'application/json'},
|
||||
body:JSON.stringify({due_date:context.due_date}),
|
||||
});
|
||||
if (deadline?.number !== confirmed.number || deadline?.due_date !== context.due_date) {
|
||||
throw new Error('Issue due date was not confirmed.');
|
||||
}
|
||||
}
|
||||
return 'queued';
|
||||
},
|
||||
onProgress:progress => {
|
||||
get('#confirm-search-release').disabled = progress.status === 'running';
|
||||
if (progress.status === 'running') {
|
||||
get('#search-release-summary').textContent = 'Planning ' + progress.processed + ' of ' + progress.selected + '…';
|
||||
} else if (progress.status === 'complete') {
|
||||
get('#cmd-search-action-status').textContent = progress.failed.length ?
|
||||
progress.queued.length + ' planned · ' + progress.failed.length + ' need retry.' :
|
||||
progress.queued.length + ' planned for ' + (releaseContext?.milestone_title || 'release') + '.';
|
||||
get('#resume-search-batch').hidden = releaseProcessor.pending() === 0;
|
||||
closeReleaseReview();
|
||||
if (!progress.failed.length) plan.cancel();
|
||||
}
|
||||
},
|
||||
});
|
||||
function estimateValues() {
|
||||
return Object.fromEntries(Array.from(document.querySelectorAll('[data-search-batch-estimate]')).map(input =>
|
||||
[input.dataset.searchBatchEstimate, Number(input.value)]
|
||||
));
|
||||
}
|
||||
function closeEstimateReview() {
|
||||
get('#search-batch-estimate-review').hidden = true;
|
||||
get('#search-batch-actions').hidden = !plan.snapshot().active;
|
||||
}
|
||||
function openEstimateReview(items) {
|
||||
const planning = todayWork.planning();
|
||||
const planned = Object.values(planning.estimates || {}).reduce((sum, minutes) => sum + minutes, 0);
|
||||
const remaining = Math.max(0, planning.capacity_minutes - planned);
|
||||
get('#search-batch-estimate-summary').textContent = remaining +
|
||||
' min remain. Estimate before assigning.';
|
||||
get('#search-batch-estimate-list').innerHTML = items.map(item => {
|
||||
const id = String(item.repository || '') + '#' + String(item.number || '');
|
||||
const estimate = planning.estimates?.[id] || '';
|
||||
return '<div class="search-batch-estimate-row"><div><span class="small">' + escapeHtml(id) +
|
||||
'</span><strong>' + escapeHtml(item.title || 'Untitled work') + '</strong></div><label class="small">' +
|
||||
'<input type="number" inputmode="numeric" min="5" max="1440" step="5" value="' +
|
||||
escapeAttribute(estimate) + '" data-search-batch-estimate="' + escapeAttribute(id) +
|
||||
'" aria-label="Estimate for ' + escapeAttribute(item.title || id) + ' in minutes" /> min</label></div>';
|
||||
}).join('');
|
||||
get('#search-batch-actions').hidden = true;
|
||||
get('#search-batch-estimate-review').hidden = false;
|
||||
document.querySelector('[data-search-batch-estimate]')?.focus();
|
||||
}
|
||||
function closeReleaseReview() {
|
||||
get('#search-release-review').hidden = true;
|
||||
get('#search-batch-actions').hidden = !plan.snapshot().active;
|
||||
}
|
||||
async function openReleaseReview() {
|
||||
const items = plan.snapshot().items;
|
||||
const repository = plan.releaseRepository();
|
||||
if (!items.length) return;
|
||||
if (!repository) {
|
||||
get('#search-selection-status').textContent = 'Select issues from one repository to plan a release.';
|
||||
return;
|
||||
}
|
||||
get('#plan-selected-search-results').disabled = true;
|
||||
get('#search-selection-status').textContent = 'Loading release milestones…';
|
||||
try {
|
||||
const milestones = await fetchJson(
|
||||
'api/v1/repos/' + repository.split('/').map(encodeURIComponent).join('/') + '/milestones',
|
||||
{headers:{Accept:'application/json'}}
|
||||
);
|
||||
const open = (Array.isArray(milestones) ? milestones : []).filter(item => item?.state !== 'closed');
|
||||
get('#search-release-milestone').innerHTML = '<option value="">Choose milestone</option>' + open.map(item =>
|
||||
'<option value="' + Number(item.id) + '">' + escapeHtml(item.title) + '</option>'
|
||||
).join('');
|
||||
get('#search-release-list').innerHTML = items.map(item => '<div class="search-release-row"><span>' +
|
||||
escapeHtml(item.repository + ' #' + item.number) + '</span><strong>' +
|
||||
escapeHtml(item.title || 'Untitled work') + '</strong></div>').join('');
|
||||
get('#search-release-summary').textContent = items.length + ' issues in ' + repository + '. Assignment starts only after confirmation.';
|
||||
get('#search-batch-actions').hidden = true;
|
||||
get('#search-release-review').hidden = false;
|
||||
get('#search-release-milestone').focus();
|
||||
} catch (error) {
|
||||
get('#search-selection-status').textContent = error?.message || 'Milestones could not be loaded. Try again.';
|
||||
} finally {
|
||||
get('#plan-selected-search-results').disabled = false;
|
||||
}
|
||||
}
|
||||
get('#select-search-results').addEventListener('click', () => plan.start());
|
||||
get('#cancel-search-selection').addEventListener('click', () => plan.cancel());
|
||||
get('#queue-selected-search-results').addEventListener('click', () => processor.run(plan.snapshot().items));
|
||||
get('#resume-search-batch').addEventListener('click', () => processor.resume());
|
||||
get('#queue-selected-search-results').addEventListener('click', () => {
|
||||
const items = plan.snapshot().items;
|
||||
const capacity = todayWork.planning().capacity_minutes;
|
||||
if (Number.isInteger(capacity) && capacity > 0) openEstimateReview(items);
|
||||
else processor.run(items);
|
||||
});
|
||||
get('#defer-selected-search-results').addEventListener('click', event => {
|
||||
const items = plan.snapshot().items;
|
||||
if (!items.length) return;
|
||||
laterPicker?.open({ items, confirm:until => () => laterProcessor.run(
|
||||
items, {}, { until:new Date(until).toISOString() }
|
||||
) }, event.currentTarget, 'search-batch');
|
||||
});
|
||||
get('#plan-selected-search-results').addEventListener('click', openReleaseReview);
|
||||
get('#cancel-search-release').addEventListener('click', closeReleaseReview);
|
||||
get('#confirm-search-release').addEventListener('click', () => {
|
||||
const milestoneSelect = get('#search-release-milestone');
|
||||
const milestoneId = Number(milestoneSelect.value);
|
||||
if (!Number.isInteger(milestoneId) || milestoneId < 1) {
|
||||
get('#search-release-summary').textContent = 'Choose an open milestone.';
|
||||
return;
|
||||
}
|
||||
const selectedOption = milestoneSelect.options?.[milestoneSelect.selectedIndex];
|
||||
const milestoneTitle = selectedOption?.textContent || selectedOption?.text || 'release';
|
||||
const dueDay = get('#search-release-due-date').value;
|
||||
releaseContext = {
|
||||
milestone_id:milestoneId, milestone_title:milestoneTitle,
|
||||
due_date:dueDay ? dueDay + 'T23:59:59Z' : null,
|
||||
};
|
||||
releaseProcessor.run(plan.snapshot().items, {}, releaseContext);
|
||||
});
|
||||
get('#cancel-search-batch-estimates').addEventListener('click', closeEstimateReview);
|
||||
get('#confirm-search-batch-estimates').addEventListener('click', () =>
|
||||
processor.run(plan.snapshot().items, estimateValues())
|
||||
);
|
||||
get('#resume-search-batch').addEventListener('click', () => {
|
||||
if (processor.pending()) return processor.resume();
|
||||
if (laterProcessor.pending()) return laterProcessor.resume();
|
||||
return releaseProcessor.resume();
|
||||
});
|
||||
get('#open-palette').addEventListener('click', () => restore());
|
||||
get('#cmd-results').addEventListener('change', event => {
|
||||
const index = event.target?.dataset?.searchSelect;
|
||||
@@ -117,7 +315,7 @@
|
||||
if (result) plan.toggle(result);
|
||||
});
|
||||
function restore() {
|
||||
const pending = processor.pending();
|
||||
const pending = processor.pending() + laterProcessor.pending() + releaseProcessor.pending();
|
||||
get('#resume-search-batch').hidden = pending === 0;
|
||||
get('#resume-search-batch').textContent = 'Resume ' + pending + ' interrupted';
|
||||
}
|
||||
@@ -131,7 +329,7 @@
|
||||
escapeHtml(result.repository) + ' #' + escapeHtml(result.number) + ' · ' +
|
||||
(allowed ? 'Open issue' : 'Not eligible') + '</span></label>';
|
||||
}
|
||||
return { plan, processor, restore, resultHtml };
|
||||
return { plan, processor, laterProcessor, releaseProcessor, restore, resultHtml };
|
||||
};
|
||||
|
||||
return createSearchBatchPlan;
|
||||
|
||||
@@ -155,6 +155,55 @@ first.run([item]).then(firstResult=>{{
|
||||
}
|
||||
|
||||
|
||||
def test_interrupted_batch_restores_operation_context_for_idempotent_recovery():
|
||||
script = f"""
|
||||
const createBatchFindWork=require({json.dumps(str(BATCH_FIND_WORK))});
|
||||
const values={{}};
|
||||
const storage={{
|
||||
getItem:key=>values[key] || null,
|
||||
setItem:(key,value)=>{{values[key]=value;}},
|
||||
removeItem:key=>{{delete values[key];}},
|
||||
}};
|
||||
const calls=[];
|
||||
const options={{
|
||||
capacity:()=>2, storage, owner:()=> 'timmy', journalName:'search-later-batch',
|
||||
queueFailureReason:'assigned but Later could not be saved',
|
||||
claim:item=>Promise.resolve({{...item,assigned_to_me:true}}),
|
||||
}};
|
||||
const first=createBatchFindWork({{...options, queue:(item,context)=>{{
|
||||
calls.push(['first',item.number,context?.until]);
|
||||
return item.number===813 ? 'queued' : 'unavailable';
|
||||
}}}});
|
||||
const items=[813,814].map(number=>({{repository:'stackchain/dashboard',number}}));
|
||||
first.run(items, {{}}, {{until:'2026-08-15T09:00:00.000Z'}}).then(firstResult=>{{
|
||||
const second=createBatchFindWork({{...options, queue:(item,context)=>{{
|
||||
calls.push(['resume',item.number,context?.until]);
|
||||
return 'queued';
|
||||
}}}});
|
||||
return second.resume().then(resumed=>process.stdout.write(JSON.stringify({{
|
||||
firstResult,resumed,calls,keys:Object.keys(values),
|
||||
}})));
|
||||
}});
|
||||
"""
|
||||
|
||||
result = run_node(script)
|
||||
assert result["firstResult"]["queued"] == ["stackchain/dashboard#813"]
|
||||
assert result["firstResult"]["failed"] == [{
|
||||
"key": "stackchain/dashboard#814",
|
||||
"reason": "assigned but Later could not be saved",
|
||||
"assigned": True,
|
||||
}]
|
||||
assert result["resumed"]["queued"] == [
|
||||
"stackchain/dashboard#813", "stackchain/dashboard#814",
|
||||
]
|
||||
assert result["calls"] == [
|
||||
["first", 813, "2026-08-15T09:00:00.000Z"],
|
||||
["first", 814, "2026-08-15T09:00:00.000Z"],
|
||||
["resume", 814, "2026-08-15T09:00:00.000Z"],
|
||||
]
|
||||
assert result["keys"] == []
|
||||
|
||||
|
||||
def test_resumed_batch_skips_queued_items_and_continues_in_original_order():
|
||||
script = f"""
|
||||
const createBatchFindWork=require({json.dumps(str(BATCH_FIND_WORK))});
|
||||
|
||||
@@ -132,3 +132,22 @@ process.stdout.write(JSON.stringify({{first, second, confirmations}}));
|
||||
output = run_node(script)
|
||||
|
||||
assert output == {"first": True, "second": False, "confirmations": 1}
|
||||
|
||||
|
||||
def test_picker_item_can_own_batch_confirmation_and_run_after_close():
|
||||
script = f"""
|
||||
const createLaterPicker = require({json.dumps(str(LATER_PICKER))});
|
||||
const order=[];
|
||||
const picker=createLaterPicker({{
|
||||
now:() => new Date(2026,7,14,8,0),
|
||||
onConfirm:()=>{{order.push('global');return true;}},
|
||||
}});
|
||||
picker.open({{confirm:until=>() => order.push(until.toISOString())}},null,'search-batch');
|
||||
const saved=picker.submit('2026-08-15T09:00');
|
||||
process.stdout.write(JSON.stringify({{saved,order}}));
|
||||
"""
|
||||
|
||||
assert run_node(script) == {
|
||||
"saved": True,
|
||||
"order": ["2026-08-15T09:00:00.000Z"],
|
||||
}
|
||||
@@ -69,6 +69,20 @@ Promise.all([
|
||||
assert result["results"][2] == "This issue is no longer available to assign."
|
||||
|
||||
|
||||
def test_release_planning_requires_selected_issues_from_one_repository():
|
||||
script = f"""
|
||||
const createSearchBatchPlan=require({json.dumps(str(SEARCH_BATCH_PLAN))});
|
||||
const flow=createSearchBatchPlan();
|
||||
flow.start();
|
||||
flow.toggle({{kind:'issue',state:'open',repository:'stackchain/dashboard',number:815}});
|
||||
const one=flow.releaseRepository();
|
||||
flow.toggle({{kind:'issue',state:'open',repository:'stackchain/api',number:17}});
|
||||
process.stdout.write(JSON.stringify({{one,mixed:flow.releaseRepository()}}));
|
||||
"""
|
||||
|
||||
assert run_node(script) == {"one": "stackchain/dashboard", "mixed": None}
|
||||
|
||||
|
||||
def test_mobile_search_exposes_touch_safe_durable_batch_planning_controls():
|
||||
html = HTML.read_text()
|
||||
dashboard = DASHBOARD.read_text()
|
||||
@@ -79,13 +93,25 @@ def test_mobile_search_exposes_touch_safe_durable_batch_planning_controls():
|
||||
assert 'id="select-search-results"' in html
|
||||
assert 'id="search-batch-actions"' in html
|
||||
assert 'id="queue-selected-search-results"' in html
|
||||
assert 'id="defer-selected-search-results"' in html
|
||||
assert 'id="plan-selected-search-results"' in html
|
||||
assert 'id="search-release-review"' in html
|
||||
assert 'id="search-release-milestone"' in html
|
||||
assert 'id="search-release-due-date"' in html
|
||||
assert 'id="resume-search-batch"' in html
|
||||
assert 'src="static/search-batch-plan.js"' in html
|
||||
assert "mountSearchBatchPlanning(" in dashboard
|
||||
assert "escapeHtml, escAttr, laterWork, laterPicker" in dashboard
|
||||
assert "journalName:'search-today-batch'" in controller
|
||||
assert "journalName:'search-later-batch'" in controller
|
||||
assert "journalName:'search-release-batch'" in controller
|
||||
assert "autoMount:false" in controller
|
||||
assert "plan.toggle(result)" in controller
|
||||
assert "processor.run(plan.snapshot().items)" in controller
|
||||
assert "processor.run(plan.snapshot().items, estimateValues())" in controller
|
||||
assert "timeBudget:()" in controller
|
||||
assert "persistEstimate" in controller
|
||||
assert 'id="search-batch-estimate-review"' in html
|
||||
assert 'data-search-batch-estimate' in controller
|
||||
assert "processor.resume()" in controller
|
||||
assert 'aria-label="Select ' in controller
|
||||
assert "result.kind === 'issue' && result.state === 'open'" in controller
|
||||
@@ -93,4 +119,244 @@ def test_mobile_search_exposes_touch_safe_durable_batch_planning_controls():
|
||||
assert "position:sticky" in css
|
||||
assert "env(safe-area-inset-bottom)" in css
|
||||
assert ".cmd-select-result" in css and "min-height:44px" in css
|
||||
assert ".search-release-review" in css and "100dvh" in css
|
||||
assert ".search-release-actions" in css and "env(safe-area-inset-bottom)" in css
|
||||
assert "BASE + 'static/search-batch-plan.js'" in worker
|
||||
|
||||
|
||||
def test_selected_search_issues_choose_one_future_time_before_durable_batch_defer():
|
||||
script = f"""
|
||||
const createSearchBatchPlan=require({json.dumps(str(SEARCH_BATCH_PLAN))});
|
||||
const listeners={{}};
|
||||
const elements={{}};
|
||||
for (const id of [
|
||||
'search-batch-actions','select-search-results','queue-selected-search-results',
|
||||
'defer-selected-search-results','plan-selected-search-results','search-selection-status','cmd-search-action-status',
|
||||
'resume-search-batch','open-palette','cmd-results','cancel-search-selection',
|
||||
'search-batch-estimate-review','search-batch-estimate-summary','search-batch-estimate-list',
|
||||
'cancel-search-batch-estimates','confirm-search-batch-estimates','search-release-review',
|
||||
'search-release-summary','search-release-milestone','search-release-due-date','search-release-list',
|
||||
'cancel-search-release','confirm-search-release'
|
||||
]) elements['#'+id]={{hidden:false,disabled:false,textContent:'',innerHTML:'',
|
||||
addEventListener:(name,fn)=>listeners[id+':'+name]=fn,focus:()=>{{}}}};
|
||||
const document={{querySelector:selector=>elements[selector] || null,querySelectorAll:()=>[]}};
|
||||
const processorOptions=[];
|
||||
const runs=[];
|
||||
const processors=[];
|
||||
const batchFactory=options=>{{
|
||||
processorOptions.push(options);
|
||||
const processor={{
|
||||
run:(items,estimates,context)=>{{runs.push({{items,estimates,context}});return Promise.resolve();}},
|
||||
resume:()=>Promise.resolve(),pending:()=>0,
|
||||
}};
|
||||
processors.push(processor);
|
||||
return processor;
|
||||
}};
|
||||
const planning={{capacity_minutes:null,estimates:{{}}}};
|
||||
const todayWork={{limit:8,read:()=>[],planning:()=>planning,identity:item=>item.repository+'#'+item.number,
|
||||
replacePlanning:()=>{{}}}};
|
||||
const laterCalls=[];
|
||||
const laterWork={{defer:(item,until)=>{{laterCalls.push([item.number,until]);return 'deferred';}}}};
|
||||
let pickerRequest=null;
|
||||
const laterPicker={{open:(payload,trigger,context)=>{{pickerRequest={{payload,trigger,context}};return true;}}}};
|
||||
const item={{kind:'issue',state:'open',repository:'stackchain/dashboard',number:813,title:'Batch defer'}};
|
||||
const mounted=createSearchBatchPlan.mount(
|
||||
document,batchFactory,todayWork,()=> 'timmy',()=>Promise.resolve(),()=>'',()=>Promise.resolve('queued'),
|
||||
{{enqueueConfiguration:()=>{{}},flush:()=>{{}}}},value=>({{...value,accepted:true}}),()=>item,()=>{{}},
|
||||
value=>value,value=>value,laterWork,laterPicker
|
||||
);
|
||||
mounted.plan.start();
|
||||
mounted.plan.toggle(item);
|
||||
listeners['defer-selected-search-results:click']({{currentTarget:elements['#defer-selected-search-results']}});
|
||||
const before={{runs:runs.slice(),count:pickerRequest.payload.items.length,context:pickerRequest.context,journals:processorOptions.map(value=>value.journalName)}};
|
||||
pickerRequest.payload.confirm(new Date('2026-08-15T09:00:00.000Z'))();
|
||||
const laterResult=processorOptions[1].queue({{...item,assigned_to_me:true}},{{until:'2026-08-15T09:00:00.000Z'}});
|
||||
process.stdout.write(JSON.stringify({{before,runs,laterResult,laterCalls}}));
|
||||
"""
|
||||
|
||||
result = run_node(script)
|
||||
assert result["before"] == {
|
||||
"runs": [],
|
||||
"count": 1,
|
||||
"context": "search-batch",
|
||||
"journals": ["search-today-batch", "search-later-batch", "search-release-batch"],
|
||||
}
|
||||
assert result["runs"] == [{
|
||||
"items": [{
|
||||
"kind": "issue", "state": "open", "repository": "stackchain/dashboard",
|
||||
"number": 813, "title": "Batch defer",
|
||||
}],
|
||||
"estimates": {},
|
||||
"context": {"until": "2026-08-15T09:00:00.000Z"},
|
||||
}]
|
||||
assert result["laterResult"] == "queued"
|
||||
assert result["laterCalls"] == [[813, "2026-08-15T09:00:00.000Z"]]
|
||||
|
||||
|
||||
def test_search_batch_reviews_time_estimates_before_any_assignment_and_persists_queued_estimates():
|
||||
script = f"""
|
||||
const createSearchBatchPlan=require({json.dumps(str(SEARCH_BATCH_PLAN))});
|
||||
const listeners={{}};
|
||||
const elements={{}};
|
||||
for (const id of [
|
||||
'search-batch-actions','select-search-results','queue-selected-search-results',
|
||||
'defer-selected-search-results','plan-selected-search-results',
|
||||
'search-selection-status','cmd-search-action-status','resume-search-batch',
|
||||
'open-palette','cmd-results','cancel-search-selection','search-batch-estimate-review',
|
||||
'search-batch-estimate-summary','search-batch-estimate-list',
|
||||
'cancel-search-batch-estimates','confirm-search-batch-estimates','search-release-review',
|
||||
'search-release-summary','search-release-milestone','search-release-due-date','search-release-list',
|
||||
'cancel-search-release','confirm-search-release'
|
||||
]) elements['#'+id]={{hidden:false,disabled:false,textContent:'',innerHTML:'',
|
||||
addEventListener:(name,fn)=>listeners[id+':'+name]=fn,focus:()=>{{}}}};
|
||||
const estimateInputs=[
|
||||
{{dataset:{{searchBatchEstimate:'stackchain/dashboard#811'}},value:'25'}},
|
||||
{{dataset:{{searchBatchEstimate:'stackchain/api#12'}},value:'30'}},
|
||||
];
|
||||
const document={{
|
||||
querySelector:selector=>elements[selector] || null,
|
||||
querySelectorAll:selector=>selector==='[data-search-batch-estimate]' ? estimateInputs : [],
|
||||
}};
|
||||
const calls=[];
|
||||
const processorOptions=[];
|
||||
const processor={{
|
||||
run:(items,estimates)=>{{calls.push({{type:'run',items,estimates}});return Promise.resolve();}},
|
||||
resume:()=>Promise.resolve(),pending:()=>0,
|
||||
}};
|
||||
const batchFactory=options=>{{processorOptions.push(options);return processor;}};
|
||||
const planning={{capacity_minutes:90,estimates:{{'stackchain/existing#1':20}}}};
|
||||
const todayWork={{limit:8,read:()=>[],planning:()=>planning,identity:item=>item.repository+'#'+item.number,
|
||||
replacePlanning:value=>Object.assign(planning,value)}};
|
||||
const todaySync={{enqueueConfiguration:()=>{{}},flush:()=>{{}}}};
|
||||
const items=[
|
||||
{{kind:'issue',state:'open',repository:'stackchain/dashboard',number:811,title:'Capacity'}},
|
||||
{{kind:'issue',state:'open',repository:'stackchain/api',number:12,title:'API'}},
|
||||
];
|
||||
let selected=items;
|
||||
const mounted=createSearchBatchPlan.mount(
|
||||
document,batchFactory,todayWork,()=> 'timmy',()=>Promise.resolve(),()=>'',()=>Promise.resolve('queued'),
|
||||
todaySync,item=>item,index=>selected[index],()=>{{}},value=>value,value=>value
|
||||
);
|
||||
mounted.plan.start();
|
||||
items.forEach(item=>mounted.plan.toggle(item));
|
||||
listeners['queue-selected-search-results:click']();
|
||||
const before={{
|
||||
calls:calls.slice(),
|
||||
reviewHidden:elements['#search-batch-estimate-review'].hidden,
|
||||
actionsHidden:elements['#search-batch-actions'].hidden,
|
||||
markup:elements['#search-batch-estimate-list'].innerHTML,
|
||||
budget:processorOptions[0].timeBudget(),
|
||||
}};
|
||||
listeners['confirm-search-batch-estimates:click']();
|
||||
processorOptions[0].persistEstimate(items[0],25);
|
||||
processorOptions[0].onProgress({{status:'complete',queued:['stackchain/dashboard#811','stackchain/api#12'],failed:[]}});
|
||||
const afterCompleteHidden=elements['#search-batch-estimate-review'].hidden;
|
||||
process.stdout.write(JSON.stringify({{before,calls,afterCompleteHidden}}));
|
||||
"""
|
||||
|
||||
result = run_node(script)
|
||||
assert result["before"]["calls"] == []
|
||||
assert result["before"]["reviewHidden"] is False
|
||||
assert result["before"]["actionsHidden"] is True
|
||||
assert "Capacity" in result["before"]["markup"]
|
||||
assert "data-search-batch-estimate" in result["before"]["markup"]
|
||||
assert result["before"]["budget"] == {"capacity_minutes": 90, "planned_minutes": 20}
|
||||
assert result["calls"] == [{
|
||||
"type": "run",
|
||||
"items": [
|
||||
{"kind": "issue", "state": "open", "repository": "stackchain/dashboard", "number": 811, "title": "Capacity"},
|
||||
{"kind": "issue", "state": "open", "repository": "stackchain/api", "number": 12, "title": "API"},
|
||||
],
|
||||
"estimates": {"stackchain/dashboard#811": 25, "stackchain/api#12": 30},
|
||||
}]
|
||||
assert result["afterCompleteHidden"] is True
|
||||
|
||||
|
||||
def test_search_batch_reviews_and_applies_one_repository_release_plan_before_assignment():
|
||||
script = f"""
|
||||
const createSearchBatchPlan=require({json.dumps(str(SEARCH_BATCH_PLAN))});
|
||||
const listeners={{}};
|
||||
const elements={{}};
|
||||
for (const id of [
|
||||
'search-batch-actions','select-search-results','queue-selected-search-results',
|
||||
'defer-selected-search-results','plan-selected-search-results','search-selection-status',
|
||||
'cmd-search-action-status','resume-search-batch','open-palette','cmd-results',
|
||||
'cancel-search-selection','search-batch-estimate-review','search-batch-estimate-summary',
|
||||
'search-batch-estimate-list','cancel-search-batch-estimates','confirm-search-batch-estimates',
|
||||
'search-release-review','search-release-summary','search-release-milestone',
|
||||
'search-release-due-date','search-release-list','cancel-search-release','confirm-search-release'
|
||||
]) elements['#'+id]={{hidden:false,disabled:false,textContent:'',innerHTML:'',value:'',
|
||||
addEventListener:(name,fn)=>listeners[id+':'+name]=fn,focus:()=>{{}}}};
|
||||
const document={{querySelector:selector=>elements[selector] || null,querySelectorAll:()=>[]}};
|
||||
const calls=[];
|
||||
const fetchJson=(url,options={{}})=>{{
|
||||
calls.push({{url,method:options.method || 'GET',body:options.body ? JSON.parse(options.body) : null}});
|
||||
if (url.endsWith('/milestones')) return Promise.resolve([{{id:9,title:'August RC'}},{{id:7,title:'Old',state:'closed'}}]);
|
||||
const number=Number(url.split('/issues/')[1].split('/')[0]);
|
||||
if (url.endsWith('/milestone')) return Promise.resolve({{number,milestone:{{id:9,title:'August RC'}}}});
|
||||
if (url.endsWith('/due-date')) return Promise.resolve({{number,due_date:'2026-08-31T23:59:59Z'}});
|
||||
return Promise.resolve();
|
||||
}};
|
||||
const processorOptions=[];
|
||||
const processors=[];
|
||||
const batchFactory=options=>{{processorOptions.push(options);const processor={{
|
||||
run:(items,estimates,context)=>{{calls.push({{run:items.map(item=>item.number),context}});return Promise.resolve();}},
|
||||
resume:()=>Promise.resolve(),pending:()=>0,
|
||||
}};processors.push(processor);return processor;}};
|
||||
const planning={{capacity_minutes:null,estimates:{{}}}};
|
||||
const todayWork={{limit:8,read:()=>[],planning:()=>planning,identity:item=>item.repository+'#'+item.number,replacePlanning:()=>{{}}}};
|
||||
const items=[
|
||||
{{kind:'issue',state:'open',repository:'stackchain/dashboard',number:815,title:'Release plan'}},
|
||||
{{kind:'issue',state:'open',repository:'stackchain/dashboard',number:816,title:'Second issue'}},
|
||||
];
|
||||
const mounted=createSearchBatchPlan.mount(
|
||||
document,batchFactory,todayWork,()=> 'timmy',fetchJson,()=>'',()=>Promise.resolve('queued'),
|
||||
{{enqueueConfiguration:()=>{{}},flush:()=>{{}}}},item=>item,index=>items[index],()=>{{}},
|
||||
value=>value,value=>value,null,null
|
||||
);
|
||||
mounted.plan.start();items.forEach(item=>mounted.plan.toggle(item));
|
||||
listeners['plan-selected-search-results:click']().then(async()=>{{
|
||||
const before={{calls:calls.slice(),reviewHidden:elements['#search-release-review'].hidden,
|
||||
actionsHidden:elements['#search-batch-actions'].hidden,options:elements['#search-release-milestone'].innerHTML,
|
||||
list:elements['#search-release-list'].innerHTML}};
|
||||
elements['#search-release-milestone'].value='9';
|
||||
elements['#search-release-milestone'].selectedIndex=0;
|
||||
elements['#search-release-milestone'].options=[{{textContent:'August RC'}}];
|
||||
elements['#search-release-due-date'].value='2026-08-31';
|
||||
listeners['confirm-search-release:click']();
|
||||
const queued=await processorOptions[2].queue({{...items[0],assigned_to_me:true}},
|
||||
{{milestone_id:9,milestone_title:'August RC',due_date:'2026-08-31T23:59:59Z'}});
|
||||
process.stdout.write(JSON.stringify({{before,calls,queued,journals:processorOptions.map(option=>option.journalName)}}));
|
||||
}});
|
||||
"""
|
||||
|
||||
result = run_node(script)
|
||||
assert result["before"]["calls"] == [{
|
||||
"url": "api/v1/repos/stackchain/dashboard/milestones", "method": "GET", "body": None,
|
||||
}]
|
||||
assert result["before"]["reviewHidden"] is False
|
||||
assert result["before"]["actionsHidden"] is True
|
||||
assert "August RC" in result["before"]["options"]
|
||||
assert "Old" not in result["before"]["options"]
|
||||
assert "Release plan" in result["before"]["list"]
|
||||
assert result["calls"][1] == {
|
||||
"run": [815, 816],
|
||||
"context": {
|
||||
"milestone_id": 9, "milestone_title": "August RC",
|
||||
"due_date": "2026-08-31T23:59:59Z",
|
||||
},
|
||||
}
|
||||
assert result["calls"][2:] == [
|
||||
{
|
||||
"url": "api/v1/repos/stackchain/dashboard/issues/815/milestone",
|
||||
"method": "PATCH", "body": {"milestone_id": 9},
|
||||
},
|
||||
{
|
||||
"url": "api/v1/repos/stackchain/dashboard/issues/815/due-date",
|
||||
"method": "PATCH", "body": {"due_date": "2026-08-31T23:59:59Z"},
|
||||
},
|
||||
]
|
||||
assert result["queued"] == "queued"
|
||||
assert result["journals"] == [
|
||||
"search-today-batch", "search-later-batch", "search-release-batch",
|
||||
]
|
||||
Reference in new issue
Block a user