feat(logs): collapse large run log data and serve client manifest
CI / changes (pull_request) Successful in 6s
CI / version (pull_request) Skipped
CI / server (pull_request) Successful in 1m30s
CI / client (pull_request) Successful in 1m31s
CI / image (pull_request) Skipped

- collapse run log data blocks whose pretty-printed JSON exceeds a byte
  or line limit, with a per-block toggle and an expand/collapse-all
  button next to the Logs heading
- align data blocks and toggles with the context/message column
- add a "Copy logs" button that copies the filtered logs as plain text
  with every data block expanded
- add GET /manifest.json with the app name, version and run log data
  limits (RUN_LOG_DATA_COLLAPSE_BYTES / RUN_LOG_DATA_COLLAPSE_LINES)
- load the manifest in the client stale-while-revalidate: localStorage
  copy first, refetched per page load and on tab focus after a while
- show the server version in the sidebar footer, with a reload hint
  when it differs from the client build

Closes #3
This commit is contained in:
ars9 committed 2026-10-02 14:05:49 +03:00
1 parent 4e55d14599
commit 718a12c2f4
25 files changed
+623 -36

No files matched your search

+64 -10
View File
@@ -1,6 +1,7 @@
import { useEffect, useRef, useState, useCallback } from 'react';
import { useEffect, useMemo, useRef, useState, useCallback } from 'react';
import { useNavigate, useParams, Link } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
import { useManifest } from '../../hooks/useManifest';
import { usePageTitle } from '../../hooks/usePageTitle';
import { runs, runFiles } from '../../api';
import type {
@@ -25,6 +26,8 @@ import {
Card,
CodeBlock,
DescriptionList,
formatLogText,
hasLargeData,
LogOutput,
Search,
Table,
@@ -38,6 +41,7 @@ import {
ChevronDown,
ChevronRight,
ClipboardList,
Copy,
Activity,
Download,
Trash2,
@@ -81,6 +85,7 @@ function RunDetail() {
const { id, runId } = useParams<{ id: string; runId: string }>();
const navigate = useNavigate();
const toast = useToast();
const logDataLimits = useManifest().runLogs.dataLimits;
const [scenario, setScenario] = useState<Scenario | null>(null);
const [run, setRun] = useState<ScenarioRunDetail | null>(null);
@@ -102,6 +107,7 @@ function RunDetail() {
const [pendingDeleteFile, setPendingDeleteFile] = useState<FileMetadata | null>(null);
const [deletingFile, setDeletingFile] = useState(false);
const [repeating, setRepeating] = useState(false);
const [logDataExpanded, setLogDataExpanded] = useState(false);
const logSearchRef = useRef('');
const pollRef = useRef<ReturnType<typeof setInterval> | null>(null);
@@ -144,6 +150,33 @@ function RunDetail() {
}
};
const logEntries = useMemo(
() =>
(run?.logs ?? []).map((l) => ({
id: l.id,
level: l.level,
context: l.context,
message: l.message,
data: l.data,
createdAt: l.createdAt,
})),
[run?.logs],
);
const logsHaveLargeData = useMemo(
() => hasLargeData(logEntries, logDataLimits),
[logEntries, logDataLimits],
);
// Copies the (filtered) logs as plain text with every data block expanded
const handleCopyLogs = async () => {
try {
await navigator.clipboard.writeText(formatLogText(logEntries, run?.createdAt));
toast.success(t('runs.logs_copied'));
} catch {
toast.error(t('runs.logs_copy_failed'));
}
};
const handleRepeatRun = async () => {
if (!id || !run?.environmentId) return;
setRepeating(true);
@@ -516,7 +549,22 @@ function RunDetail() {
{run.logs.length > 0 && (
<div className={styles.stepsSection}>
<div className={styles.sectionHeadingRow}>
<h2 className={styles.sectionHeading}>{t('runs.logs_heading')}</h2>
<div style={{ display: 'flex', alignItems: 'center', gap: '8px' }}>
<h2 className={styles.sectionHeading} style={{ margin: 0 }}>
{t('runs.logs_heading')}
</h2>
{logsHaveLargeData && (
<Button
variant="ghost"
size="sm"
aria-expanded={logDataExpanded}
onClick={() => setLogDataExpanded((v) => !v)}
>
{logDataExpanded ? <ChevronDown size={14} /> : <ChevronRight size={14} />}
{logDataExpanded ? t('runs.logs_collapse_data') : t('runs.logs_expand_data')}
</Button>
)}
</div>
<div style={{ display: 'flex', alignItems: 'center', gap: '8px' }}>
<Search
value={logSearch}
@@ -527,19 +575,25 @@ function RunDetail() {
<Download size={14} />
{t('runs.action_download_logs')}
</Button>
<Button variant="secondary" size="sm" onClick={handleCopyLogs}>
<Copy size={14} />
{t('runs.action_copy_logs')}
</Button>
</div>
</div>
<LogOutput
startTime={run.createdAt}
maxHeight={480}
entries={run.logs.map((l) => ({
id: l.id,
level: l.level,
context: l.context,
message: l.message,
data: l.data,
createdAt: l.createdAt,
}))}
entries={logEntries}
dataLimits={logDataLimits}
dataExpanded={logDataExpanded}
showDataLabel={({ bytes, lines }) =>
t('runs.logs_show_data', {
size: bytes < 1024 ? `${bytes} B` : `${(bytes / 1024).toFixed(1)} KB`,
count: lines,
})
}
hideDataLabel={t('runs.logs_hide_data')}
emptyMessage=""
/>
</div>