Sign in

Search issue titles and bodies, change requests and comments. Private repositories you cannot read are not included.

vole
Site
Clone

Read only, no credentials:

https://rodent.software/vole.git

Write over SSH with a registered key:

git clone ssh://git@rodent.software/vole.git

Self-hosted forge that lives in your Git repo.

Make run pages step-aware and easier to scan

e653853a52ede660a589caeddd1bf46d5101f853 · Keenan Nemetz · 17d ago · parent fdd0b3e8

Make run pages step-aware and easier to scan

Stream structured step events from the runner so a running attempt can show per-step tabs and tail the selected step's log. Keep one log pane for finished runs, label run timings, let queued and running durations tick client-side, and fix long branch names. Polish the runs list with filter totals, a real subtitle, and clearer stop/cancel labels.

server/web/static/app.js +162−29

@@ -575,27 +575,58 @@ const fitTextarea = (area) => {
575 575 });
576 576 })();
577 577
578 // Live CI job output. The server serves the attempt's file from a byte offset and
579 // says when the log is final; the page asks again only while the job is running.
580 // Chunks are decoded with a streaming TextDecoder because a multi-byte character
581 // can straddle two byte offsets.
578 // Live step output. A running attempt reports each step's log range as a
579 // structured event, so the step tabs can change while the job is still going.
580 // The selected step is fetched from its own byte range; the running step is
581 // tailed, and a completed step stops at X-Step-Final. The step tab bar itself is
582 // refreshed by htmx, which is also how this learns that the next step started.
582 583 (() => {
583 const follow = (pre) => {
584 if (pre.dataset.logStreaming) return;
585 pre.dataset.logStreaming = '1';
586 const url = pre.dataset.logUrl;
587 if (!url) return;
584 const pane = document.querySelector('pre[data-live-step-log]');
585 if (!pane) return;
586
587 let current = '';
588 let follow = true;
589 let generation = 0;
590
591 const list = () => document.getElementById('run-live-steps');
592 const buttons = () => Array.from(document.querySelectorAll('#run-live-steps [data-step-number]'));
593 const streamed = () => buttons().filter((button) => button.dataset.logUrl);
594 const running = () => buttons().find((button) => button.dataset.stepStatus === 'running');
595 const byNumber = (number) => buttons().find((button) => button.dataset.stepNumber === number);
596
597 const mark = (number) => {
598 buttons().forEach((button) => {
599 const active = button.dataset.stepNumber === number;
600 button.classList.toggle('active', active);
601 button.setAttribute('aria-selected', active ? 'true' : 'false');
602 });
603 };
604
605 const select = (button) => {
606 if (!button || !button.dataset.logUrl) return;
607 const number = button.dataset.stepNumber || '';
608 const changed = number !== current;
609 current = number;
610 mark(number);
611 if (changed) stream(button);
612 };
613
614 const stream = (button) => {
615 const url = button.dataset.logUrl;
616 let offset = Number(button.dataset.logOffset || 0);
617 const id = ++generation;
588 618 const decoder = new TextDecoder();
589 let offset = 0;
590 let stopped = false;
591 const finalOn404 = pre.dataset.logFinal === '1';
619 pane.textContent = '';
620
592 621 const schedule = () => {
593 if (!stopped) setTimeout(tick, 1000);
622 if (id === generation) setTimeout(tick, 1000);
594 623 };
624
595 625 const tick = async () => {
626 if (id !== generation) return;
596 627 let res;
597 628 try {
598 res = await fetch(url + (url.includes('?') ? '&' : '?') + 'after=' + offset, {
629 res = await fetch(url + '&after=' + offset, {
599 630 cache: 'no-store',
600 631 credentials: 'same-origin',
601 632 });
@@ -603,8 +634,8 @@ const fitTextarea = (area) => {
603 634 schedule();
604 635 return;
605 636 }
637 if (id !== generation) return;
606 638 if (res.status === 404) {
607 if (finalOn404 || res.headers.get('X-Log-Final') === '1') return;
608 639 schedule();
609 640 return;
610 641 }
@@ -619,32 +650,134 @@ const fitTextarea = (area) => {
619 650 schedule();
620 651 return;
621 652 }
653 if (id !== generation) return;
622 654 if (buf.byteLength) {
623 const stick = pre.scrollTop + pre.clientHeight >= pre.scrollHeight - 12;
624 pre.appendChild(document.createTextNode(decoder.decode(buf, { stream: true })));
655 const stick = pane.scrollTop + pane.clientHeight >= pane.scrollHeight - 12;
656 pane.appendChild(document.createTextNode(decoder.decode(buf, { stream: true })));
625 657 offset += buf.byteLength;
626 if (stick) pre.scrollTop = pre.scrollHeight;
658 if (stick) pane.scrollTop = pane.scrollHeight;
627 659 }
628 if (res.headers.get('X-Log-Final') === '1') {
629 pre.appendChild(document.createTextNode(decoder.decode()));
630 pre.dataset.logStreaming = 'done';
631 const state = pre.closest('details')?.querySelector('.run-log-state');
632 if (state) state.textContent = 'complete';
660 if (res.headers.get('X-Step-Final') === '1') {
661 pane.appendChild(document.createTextNode(decoder.decode()));
633 662 return;
634 663 }
635 664 schedule();
636 665 };
666
637 667 tick();
638 668 };
639 669
640 document.querySelectorAll('details').forEach((details) => {
641 const pre = details.querySelector('pre[data-log-stream]');
642 if (!pre) return;
643 if (details.open) follow(pre);
644 details.addEventListener('toggle', () => {
645 if (details.open) follow(pre);
670 // A poll that brings a new running step should move the pane with it, unless
671 // the reader deliberately opened an earlier step.
672 const sync = () => {
673 if (!list()) return;
674 const active = running();
675 if (follow) {
676 if (active) {
677 if (active.dataset.stepNumber !== current) select(active);
678 else mark(current);
679 } else if (current) {
680 mark(current);
681 } else {
682 const started = streamed();
683 if (started.length) select(started[started.length - 1]);
684 }
685 return;
686 }
687 if (current) mark(current);
688 };
689
690 document.addEventListener('click', (event) => {
691 const button = event.target.closest('#run-live-steps [data-log-url]');
692 if (!button) return;
693 follow = button.dataset.stepStatus === 'running';
694 select(button);
695 });
696
697 document.body.addEventListener('htmx:afterSwap', () => {
698 if (list()) sync();
699 });
700
701 sync();
702 })();
703
704 // A finished run's output is one pane with the steps as tabs. HTMX replaces the
705 // pane's text; this only moves the selected marker so the reader can see which
706 // step is on screen.
707 (() => {
708 document.addEventListener('click', (event) => {
709 const step = event.target.closest('[data-log-step]');
710 if (!step) return;
711 const list = step.closest('.run-log-steps');
712 if (!list) return;
713 list.querySelectorAll('[data-log-step]').forEach((button) => {
714 const active = button === step;
715 button.classList.toggle('active', active);
716 button.setAttribute('aria-selected', active ? 'true' : 'false');
717 });
718 });
719 })();
720
721 // Relative times and live durations. The server renders the same words, so a page
722 // without scripts still reads; this keeps the values moving between the polls
723 // that refresh the surrounding row. A run that is waiting or running would
724 // otherwise show a frozen duration until the next page load, and asking the
725 // server every second for a clock would be wasteful. The formatting matches
726 // internal/format.Duration and humanSince in server/web/ui.go.
727 (() => {
728 const duration = (ms) => {
729 if (!(ms > 0)) return '0s';
730 if (ms < 1000) return `${Math.floor(ms)}ms`;
731 let seconds = Math.round(ms / 1000);
732 const hours = Math.floor(seconds / 3600);
733 seconds -= hours * 3600;
734 const minutes = Math.floor(seconds / 60);
735 seconds -= minutes * 60;
736 if (hours > 0 && minutes === 0 && seconds === 0) return `${hours}h`;
737 if (hours > 0 && seconds === 0) return `${hours}h ${minutes}m`;
738 if (hours > 0) return `${hours}h ${minutes}m ${seconds}s`;
739 if (minutes > 0 && seconds === 0) return `${minutes}m`;
740 if (minutes > 0) return `${minutes}m ${seconds}s`;
741 return `${seconds}s`;
742 };
743
744 const since = (unix, now) => {
745 if (!unix) return '';
746 const age = now - unix * 1000;
747 if (age < 60000) return 'just now';
748 if (age < 3600000) return `${Math.floor(age / 60000)}m ago`;
749 if (age < 86400000) return `${Math.floor(age / 3600000)}h ago`;
750 return `${Math.floor(age / 86400000)}d ago`;
751 };
752
753 const set = (element, value) => {
754 if (element.textContent !== value) element.textContent = value;
755 };
756
757 const tick = () => {
758 const now = Date.now();
759 document.querySelectorAll('[data-clock-from]').forEach((element) => {
760 const from = Number(element.getAttribute('data-clock-from')) * 1000;
761 if (!Number.isFinite(from) || from <= 0) return;
762 set(element, duration(now - from));
763 });
764 document.querySelectorAll('[data-since]').forEach((element) => {
765 const unix = Number(element.getAttribute('data-since'));
766 if (!Number.isFinite(unix) || unix <= 0) return;
767 set(element, since(unix, now));
646 768 });
769 };
770
771 tick();
772 setInterval(() => {
773 if (document.visibilityState === 'visible') tick();
774 }, 1000);
775 document.addEventListener('visibilitychange', () => {
776 if (document.visibilityState === 'visible') tick();
647 777 });
778 // HTMX replaces whole sections of a change's sidebar. The next tick adopts
779 // whatever times arrived with the new markup.
780 document.body.addEventListener('htmx:afterSwap', tick);
648 781 })();
649 782
650 783 // The palette's shortcut hint names the reader's own modifier key. The markup