Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(mcp-host): leave a note where a dashboard sparkline fails (SILENT-004)

marcotebecaa8a5f2623
diff --git a/mcp-host/src/workflow/__tests__/dashboardScript.test.ts b/mcp-host/src/workflow/__tests__/dashboardScript.test.ts
index 6ba691303..60233052d 100644
--- a/mcp-host/src/workflow/__tests__/dashboardScript.test.ts
+++ b/mcp-host/src/workflow/__tests__/dashboardScript.test.ts
@@ -27,6 +27,8 @@ interface Page {
charts: Map<string, FakeChart>
/** Text of each note that replaced a chart's container. */
notes: string[]
+ /** Class of each of those notes. */
+ noteClasses: string[]
/** Ids of the canvases whose container was removed. */
removed: string[]
setVars(vars: Record<string, string>): void
@@ -66,6 +68,7 @@ function runScript(
const charts = new Map<string, FakeChart>()
const byCanvas = new Map<string, FakeChart>()
const notes: string[] = []
+ const noteClasses: string[] = []
const removed: string[] = []
const listeners: Record<string, Array<() => void>> = {}
const listen = (name: string, fn: () => void) => (listeners[name] ??= []).push(fn)
@@ -73,7 +76,10 @@ function runScript(
id,
getAttribute: () => '[1,3,2]',
parentNode: {
- replaceWith: (note: { textContent: string }) => notes.push(note.textContent),
+ replaceWith: (note: { className: string; textContent: string }) => {
+ notes.push(note.textContent)
+ noteClasses.push(note.className)
+ },
remove: () => removed.push(id),
},
})
@@ -127,6 +133,7 @@ function runScript(
return {
charts,
notes,
+ noteClasses,
removed,
setVars: next => {
vars = next
@@ -196,7 +203,7 @@ describe('dashboardScript', () => {
expect(page.notes).toEqual([])
})
- it('replaces each chart with a note and drops the sparklines when Chart.js is missing', () => {
+ it('replaces each chart and each sparkline with a note when Chart.js is missing', () => {
const page = runScript([spec('c0'), spec('c1')], {
chartLibrary: false,
sparklines: ['sparkline-0'],
@@ -204,8 +211,9 @@ describe('dashboardScript', () => {
expect(page.notes).toEqual([
'This chart could not be drawn: the chart library did not load',
'This chart could not be drawn: the chart library did not load',
+ 'Trend could not be drawn',
])
- expect(page.removed).toEqual(['sparkline-0'])
+ expect(page.removed).toEqual([])
})
it('destroys a chart Chart.js registered before it threw, and draws the others', () => {
@@ -215,12 +223,28 @@ describe('dashboardScript', () => {
})
expect(page.notes).toEqual([
'This chart could not be drawn: "x" is not a registered controller.',
+ 'Trend could not be drawn',
])
expect(page.destroyed).toEqual(['c0', 'sparkline-0'])
- expect(page.removed).toEqual(['sparkline-0'])
+ expect(page.removed).toEqual([])
expect([...page.charts.keys()]).toEqual(['c1', 'sparkline-1'])
})
+ it('leaves a short fixed note where a sparkline failed, and draws a normal one as before', () => {
+ const page = runScript([], {
+ throwOn: ['sparkline-0'],
+ sparklines: ['sparkline-0', 'sparkline-1'],
+ })
+ // The note neither carries the error's text nor removes the KPI's trend area unseen.
+ expect(page.notes).toEqual(['Trend could not be drawn'])
+ expect(page.noteClasses).toEqual(['kpi-card__sparkline-note'])
+ expect(page.notes.join(' ')).not.toContain('registered controller')
+ expect(page.removed).toEqual([])
+ const drawn = page.charts.get('sparkline-1')!
+ expect(drawn.config.type).toBe('line')
+ expect(drawn.data.datasets[0]).toMatchObject({ data: [1, 3, 2], pointRadius: 0 })
+ })
+
it('draws a gauge as a half dial with its reading and maximum printed inside', () => {
const page = runScript([
spec('g', {
diff --git a/mcp-host/src/workflow/dashboardCss.ts b/mcp-host/src/workflow/dashboardCss.ts
index 3eb28fd44..6db7a64df 100644
--- a/mcp-host/src/workflow/dashboardCss.ts
+++ b/mcp-host/src/workflow/dashboardCss.ts
@@ -253,6 +253,12 @@ em, i { font-style: italic; }
overflow: hidden;
contain: size layout;
}
+.kpi-card__sparkline-note {
+ margin: 8px 0 0;
+ color: var(--text-muted);
+ font-size: 11px;
+ line-height: 1.4;
+}
.kpi-card__sparkline {
position: absolute !important;
inset: 0 !important;
diff --git a/mcp-host/src/workflow/dashboardScript.ts b/mcp-host/src/workflow/dashboardScript.ts
index 27aa17a6a..b86a197f7 100644
--- a/mcp-host/src/workflow/dashboardScript.ts
+++ b/mcp-host/src/workflow/dashboardScript.ts
@@ -2,8 +2,8 @@
* The script that draws a dashboard's charts in the browser.
*
* Each chart and each sparkline is drawn on its own: a chart Chart.js refuses
- * shows why in its card, a sparkline it refuses is removed, and neither blanks
- * the others. Colors are read
+ * shows why in its card, a sparkline it refuses leaves a short note in its
+ * place, and neither blanks the others. Colors are read
* from the page's CSS variables and read again when the color scheme or the
* print media changes, so the series stay legible in light, dark and print.
* Animation is off: headless HTML-to-PDF converters print a chart the moment it
@@ -222,7 +222,11 @@ const PAGE_SCRIPT = String.raw`
instances.push({ chart: chart });
} catch (err) {
discard(canvas);
- if (canvas.parentNode) canvas.parentNode.remove();
+ // A fixed text: the KPI says its trend is missing without the error's details.
+ var note = document.createElement('p');
+ note.className = 'kpi-card__sparkline-note';
+ note.textContent = 'Trend could not be drawn';
+ (canvas.parentNode || canvas).replaceWith(note);
}
}