Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions ui/src/features/info/InfoPanel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import Card from '../../lib/components/Card.svelte';
import EngineStats from '../status/EngineStats.svelte';
import { collectBrowserFacts, type BrowserFacts } from './browserFacts';
import { formatDiagnostics, type DiagReport } from './diagnostics';
import { abridgedDiagnostics, formatDiagnostics, type DiagReport } from './diagnostics';
import { buildBugReportUrl, buildIdeaUrl } from './issueReport';
import {
describeUpdateInstallError,
Expand Down Expand Up @@ -107,15 +107,20 @@
];

// The bug form's Diagnostics field is required, so on the rare report too long
// to ride along in the URL the user has to paste it by hand. Put it on their
// clipboard and say so — they are about to leave this panel for the browser,
// and telling them afterwards to come back and find Copy is no help.
// to ride along in the URL even abridged, the user has to paste it by hand.
// Put it on their clipboard and say so — they are about to leave this panel
// for the browser, and telling them afterwards to come back and find Copy is
// no help.
let reportNote = $state('');
let reportNoteTimer: ReturnType<typeof setTimeout> | undefined;

async function reportBug() {
const diagnostics = formatDiagnostics(report);
const { url, overflowed } = buildBugReportUrl(diagnostics);
// Fullest version that fits the URL: a large plugin library is cut down to
// vendor counts before the report is given up on.
const { url, overflowed } = buildBugReportUrl(
abridgedDiagnostics(report).map(formatDiagnostics),
);
if (overflowed) {
clearTimeout(reportNoteTimer);
try {
Expand Down
82 changes: 81 additions & 1 deletion ui/src/features/info/diagnostics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@ import { DEFAULT_APP_SETTINGS } from '../../lib/engine/appSettings';
import { DEFAULT_APP_INFO, DEFAULT_STATUS_STATE } from '../../lib/engine/types';
import type { AppInfo, RackModule, RoutingState, StatusState } from '../../lib/engine/types';
import type { BrowserFacts } from './browserFacts';
import { buildDiagnostics, formatDiagnostics, type DiagnosticsInput } from './diagnostics';
import { buildBugReportUrl } from './issueReport';
import {
abridgedDiagnostics,
buildDiagnostics,
formatDiagnostics,
type DiagnosticsInput,
} from './diagnostics';

const info: AppInfo = {
version: '0.1.0',
Expand Down Expand Up @@ -380,3 +386,77 @@ describe('formatDiagnostics', () => {
);
});
});

describe('abridgedDiagnostics', () => {
/** A library shaped like a Linux machine with the LSP bundle installed: one
vendor, a couple of hundred long names. */
const bigLibrary = [
...Array.from({ length: 198 }, (_, index) => ({
id: `lsp${index}`,
name: `LSP Parametric Equalizer x${index} Mid-Side`,
manufacturer: 'LSP VST3',
})),
{ id: 'n1', name: 'NeuralAmpModeler', manufacturer: 'Plectrify' },
{ id: 'n2', name: 'PlectrifyNam', manufacturer: 'Plectrify' },
{ id: 'n3', name: 'Nameless Verb' },
];

const levelRow = (level: ReturnType<typeof buildDiagnostics>, label: string) =>
row(level, 'Plugins', label);

it('cuts the plugin names to vendor counts first, then to a total', () => {
const levels = abridgedDiagnostics(buildDiagnostics(input({ plugins: bigLibrary })));

expect(levels).toHaveLength(3);
expect(levelRow(levels[0], 'Installed')).toContain('LSP Parametric Equalizer x0 Mid-Side');
// Largest vendor first; the vendorless plugin is counted, not named.
expect(levelRow(levels[1], 'Installed')).toBe(
'LSP VST3: 198 · Plectrify: 2 · 1 with no vendor (names left out to fit the issue form)',
);
expect(levelRow(levels[2], 'Installed')).toBe(
'201 plugins (names left out to fit the issue form)',
);
});

it('keeps the skipped files named until the last level', () => {
const levels = abridgedDiagnostics(buildDiagnostics(input({ plugins: bigLibrary })));

expect(levelRow(levels[1], 'Skipped')).toBe('Crasher');
expect(levelRow(levels[2], 'Skipped')).toBe('1 file (names left out to fit the issue form)');
});

it('leaves every other row alone', () => {
const [full, ...shorter] = abridgedDiagnostics(
buildDiagnostics(input({ plugins: bigLibrary })),
);
const others = (level: typeof full) =>
level.sections.flatMap((section) =>
section.rows
.filter((r) => r.label !== 'Installed' && r.label !== 'Skipped')
.map((r) => r.value),
);
for (const level of shorter) expect(others(level)).toEqual(others(full));
});

it('has nothing to cut when no plugins are installed or skipped', () => {
expect(
abridgedDiagnostics(buildDiagnostics(input({ plugins: [], blacklisted: [] }))),
).toHaveLength(1);
});

it('gets a large library into the bug form instead of dropping the report (#35)', () => {
const report = buildDiagnostics(input({ plugins: bigLibrary }));
// The full report alone is too long for the URL — the case that used to
// open the form with the Diagnostics field empty.
expect(buildBugReportUrl(formatDiagnostics(report)).overflowed).toBe(true);

const { url, abridged, overflowed } = buildBugReportUrl(
abridgedDiagnostics(report).map(formatDiagnostics),
);
expect(overflowed).toBe(false);
expect(abridged).toBe(true);
const prefilled = new URL(url).searchParams.get('diagnostics') ?? '';
expect(prefilled).toContain('LSP VST3: 198');
expect(prefilled).toContain('Ryzen 9 5900X');
});
});
93 changes: 86 additions & 7 deletions ui/src/features/info/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ import type { BrowserFacts } from './browserFacts';
export interface DiagRow {
label: string;
value: string;
/** Shorter stand-ins for `value`, one per abridging level and each shorter
than the last, for the one place the report has to fit a size limit: the
bug form's URL (see `abridgedDiagnostics`). Only the rows that can grow
with the size of someone's library carry them — everything else is a
handful of words at most and is never worth cutting. */
shorter?: string[];
}

export interface DiagSection {
Expand Down Expand Up @@ -364,6 +370,31 @@ function formatPluginLibrary(plugins: PluginInfo[]): string {
.join(' · ');
}

/** Said wherever names were dropped, so the report itself admits the cut and
nobody reads a vendor count as a library of one plugin per vendor. */
const NAMES_LEFT_OUT = '(names left out to fit the issue form)';

/** The library without its names: `LSP VST3: 198 · Plectrify: 3 · 2 more`.
One count per vendor, largest first, because that is what still identifies
the machine — 198 plugins from one vendor is a fact about the bug report;
their 198 names, which on Linux is what a plugin bundle like LSP installs,
are what pushed the report out of the form. */
function formatPluginVendors(plugins: PluginInfo[]): string {
const byVendor = new Map<string, number>();
for (const plugin of plugins) {
const vendor = (plugin.manufacturer ?? '').trim();
byVendor.set(vendor, (byVendor.get(vendor) ?? 0) + 1);
}
const unnamed = byVendor.get('') ?? 0;
byVendor.delete('');

const vendors = [...byVendor]
.sort(([a, an], [b, bn]) => bn - an || a.localeCompare(b))
.map(([vendor, n]) => `${vendor}: ${n}`);
if (unnamed > 0) vendors.push(`${unnamed} with no vendor`);
return `${vendors.join(' · ')} ${NAMES_LEFT_OUT}`;
}

/** What the host knows about, and what it will not load. Its own section
because the list is long enough to bury the rig rows it used to sit among —
and because "which plugins are installed" is the first question a crash
Expand All @@ -373,6 +404,13 @@ function pluginsSection(input: DiagnosticsInput): DiagSection {
// The list the section prints wins over the engine's count when it has
// entries, so the number can never contradict the names right below it.
const skipped = blacklisted.length > 0 ? blacklisted.length : (info.plugins?.blacklisted ?? 0);
const skippedNames =
blacklisted.length === 0
? 'none'
: blacklisted
.map((entry) => dash(entry.name))
.sort((a, b) => a.localeCompare(b))
.join(' · ');

return {
title: 'Plugins',
Expand All @@ -386,18 +424,30 @@ function pluginsSection(input: DiagnosticsInput): DiagSection {
`scan ${scan.status}`,
),
},
{ label: 'Installed', value: formatPluginLibrary(plugins) },
{
label: 'Installed',
value: formatPluginLibrary(plugins),
// Vendors first, then the bare total: the list is the one row that
// grows without bound, and hundreds of names do not fit a URL.
shorter:
plugins.length === 0
? undefined
: [
formatPluginVendors(plugins),
`${count(plugins.length, 'plugin')} ${NAMES_LEFT_OUT}`,
],
},
{
label: 'Skipped',
// File names, not the paths they came from: the path is under the
// user's account and this report is written for a public issue.
value:
value: skippedNames,
// Kept whole at the first level — a skipped file is a crash suspect
// and worth more than the names of the plugins that load fine.
shorter:
blacklisted.length === 0
? 'none'
: blacklisted
.map((entry) => dash(entry.name))
.sort((a, b) => a.localeCompare(b))
.join(' · '),
? undefined
: [skippedNames, `${count(blacklisted.length, 'file')} ${NAMES_LEFT_OUT}`],
},
],
};
Expand Down Expand Up @@ -507,3 +557,32 @@ export function formatDiagnostics(report: DiagReport): string {
)
.join('\n\n');
}

/** The report at every level of abridging, the full one first and each after
it shorter: level *n* swaps every row's value for its *n*th `shorter`
stand-in (or its last one, once it has run out). Stops at the deepest level
any row offers, so a report with nothing to shorten is a list of one.

For the bug form's URL, which takes the first that fits: dropping the plugin
names is a much smaller loss than dropping the whole report, which is what a
machine with a few hundred plugins used to get (issue #35). */
export function abridgedDiagnostics(report: DiagReport): DiagReport[] {
const depth = Math.max(
0,
...report.sections.flatMap((section) => section.rows.map((row) => row.shorter?.length ?? 0)),
);
const levels: DiagReport[] = [report];
for (let level = 1; level <= depth; level += 1) {
levels.push({
sections: report.sections.map((section) => ({
...section,
rows: section.rows.map((row) =>
row.shorter && row.shorter.length > 0
? { ...row, value: row.shorter[Math.min(level, row.shorter.length) - 1] }
: row,
),
})),
});
}
return levels;
}
22 changes: 22 additions & 0 deletions ui/src/features/info/issueReport.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,28 @@ describe('buildBugReportUrl', () => {
expect(url.length).toBe(MAX_ISSUE_URL_LENGTH);
});

it('takes the fullest version of the report that fits', () => {
const tooLong = 'x'.repeat(MAX_ISSUE_URL_LENGTH);
const { url, abridged, overflowed } = buildBugReportUrl([tooLong, 'shorter', 'short']);

expect(new URL(url).searchParams.get('diagnostics')).toBe('shorter');
expect(abridged).toBe(true);
expect(overflowed).toBe(false);
});

it('does not call the full report abridged', () => {
expect(buildBugReportUrl(['full', 'short']).abridged).toBe(false);
});

it('drops the report only when no version fits', () => {
const tooLong = 'x'.repeat(MAX_ISSUE_URL_LENGTH);
const { url, abridged, overflowed } = buildBugReportUrl([tooLong, tooLong]);

expect(overflowed).toBe(true);
expect(abridged).toBe(false);
expect(new URL(url).searchParams.get('diagnostics')).toBeNull();
});

it('carries a realistic report without overflowing', () => {
// A busy rig is ~1.6 KB raw and ~3.6 KB encoded — well inside the cap. This
// guards against someone lowering MAX_ISSUE_URL_LENGTH below the real range.
Expand Down
34 changes: 24 additions & 10 deletions ui/src/features/info/issueReport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,12 @@ export const MAX_ISSUE_URL_LENGTH = 6000;

export interface IssueUrl {
url: string;
/** True when the report did not fit and was left out — the caller has to put
it on the clipboard and say so, because the form field is required. */
/** True when a shorter version of the report went in because the full one
did not fit. The report says itself what it left out. */
abridged: boolean;
/** True when no version of the report fit and it was left out — the caller
has to put it on the clipboard and say so, because the form field is
required. */
overflowed: boolean;
}

Expand All @@ -40,17 +44,27 @@ function query(params: Record<string, string>): string {
.join('&');
}

/** The bug form, with the environment report prefilled where it fits. */
export function buildBugReportUrl(diagnostics: string): IssueUrl {
const withReport = `${NEW_ISSUE_BASE_URL}?${query({
template: BUG_TEMPLATE,
[DIAGNOSTICS_FIELD]: diagnostics,
})}`;
if (withReport.length <= MAX_ISSUE_URL_LENGTH) return { url: withReport, overflowed: false };
/** The bug form, with the environment report prefilled where it fits.

`diagnostics` is the report, or several versions of it from fullest to
shortest (`abridgedDiagnostics`): the first whose URL fits goes in. */
export function buildBugReportUrl(diagnostics: string | readonly string[]): IssueUrl {
const versions = typeof diagnostics === 'string' ? [diagnostics] : diagnostics;
for (const [index, report] of versions.entries()) {
const url = `${NEW_ISSUE_BASE_URL}?${query({
template: BUG_TEMPLATE,
[DIAGNOSTICS_FIELD]: report,
})}`;
if (url.length <= MAX_ISSUE_URL_LENGTH) return { url, abridged: index > 0, overflowed: false };
}

// Still open the form — an issue with the diagnostics pasted by hand beats no
// issue at all, and the caller tells the user where to find them.
return { url: `${NEW_ISSUE_BASE_URL}?${query({ template: BUG_TEMPLATE })}`, overflowed: true };
return {
url: `${NEW_ISSUE_BASE_URL}?${query({ template: BUG_TEMPLATE })}`,
abridged: false,
overflowed: true,
};
}

/** The idea form. No diagnostics, so nothing to overflow. */
Expand Down
Loading