mirror of
https://github.com/nimbold/Firelink.git
synced 2026-09-02 22:17:56 +00:00
fix(torrent): distinguish connected and listed peers
- label live connected peer telemetry separately from listed peer details - report count mismatches and keep connected values accented - synchronize bindings, locales, accessibility, and regression coverage
This commit is contained in:
@@ -4,12 +4,13 @@ import {
|
||||
formatPropertiesDiagnosticCount,
|
||||
getPropertiesAvailabilityDiagnosticState,
|
||||
getPropertiesPeerDiagnosticState,
|
||||
hasTorrentPeerCountDifference,
|
||||
hasLiveTorrentPeerWithoutDetails,
|
||||
} from './propertiesDiagnostics';
|
||||
|
||||
const emptyPeerDiagnostics = {
|
||||
totalPeers: 0,
|
||||
totalSeeders: 0,
|
||||
listedPeers: 0,
|
||||
listedSeeders: 0,
|
||||
peers: [],
|
||||
truncated: false,
|
||||
};
|
||||
@@ -29,6 +30,15 @@ describe('Properties peer diagnostics presentation state', () => {
|
||||
expect(formatPropertiesDiagnosticCount(Number.MAX_SAFE_INTEGER + 1, 'en-US')).toBe('—');
|
||||
});
|
||||
|
||||
it('identifies when the connected telemetry differs from the listed peer response', () => {
|
||||
expect(hasTorrentPeerCountDifference(38, 2, 5, 2)).toBe(true);
|
||||
expect(hasTorrentPeerCountDifference(5, 2, 5, 2)).toBe(false);
|
||||
expect(hasTorrentPeerCountDifference(undefined, 2, 5, 2)).toBe(false);
|
||||
expect(hasTorrentPeerCountDifference(38, 2, 5, 1)).toBe(true);
|
||||
expect(hasTorrentPeerCountDifference(Number.NaN, 2, 5, 2)).toBe(false);
|
||||
expect(hasTorrentPeerCountDifference(38, 2, Number.POSITIVE_INFINITY, 2)).toBe(false);
|
||||
});
|
||||
|
||||
it('keeps a genuine empty response live instead of treating it as unavailable', () => {
|
||||
expect(getPropertiesPeerDiagnosticState(emptyPeerDiagnostics, false, 'idle')).toBe('live');
|
||||
});
|
||||
|
||||
@@ -5,11 +5,29 @@ import type { PropertiesDiagnosticPhase } from '../propertiesBridge';
|
||||
|
||||
export type PropertiesDiagnosticValueState = 'live' | 'loading' | 'stale' | 'error' | 'unavailable';
|
||||
|
||||
const isValidDiagnosticCount = (value: number | undefined): value is number =>
|
||||
typeof value === 'number' && Number.isSafeInteger(value) && value >= 0;
|
||||
|
||||
export const formatPropertiesDiagnosticCount = (value: number, locale: string): string => {
|
||||
if (!Number.isSafeInteger(value) || value < 0) return '—';
|
||||
if (!isValidDiagnosticCount(value)) return '—';
|
||||
return new Intl.NumberFormat(resolveAppLocale(locale)).format(value);
|
||||
};
|
||||
|
||||
export const hasTorrentPeerCountDifference = (
|
||||
connectedPeers: number | undefined,
|
||||
connectedSeeders: number | undefined,
|
||||
listedPeers: number,
|
||||
listedSeeders: number,
|
||||
): boolean => (
|
||||
isValidDiagnosticCount(connectedPeers)
|
||||
&& isValidDiagnosticCount(listedPeers)
|
||||
&& connectedPeers !== listedPeers
|
||||
) || (
|
||||
isValidDiagnosticCount(connectedSeeders)
|
||||
&& isValidDiagnosticCount(listedSeeders)
|
||||
&& connectedSeeders !== listedSeeders
|
||||
);
|
||||
|
||||
export const hasLiveTorrentPeerWithoutDetails = (
|
||||
connectedPeers: number | undefined,
|
||||
detailedPeers: number,
|
||||
|
||||
Reference in New Issue
Block a user