Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
57 changes: 48 additions & 9 deletions test/helpers/probe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export type ProbeResult = {
invoiceFetched: boolean;
success: boolean;
durationMs: number;
routeFeeMsat?: number;
bolt11?: string;
nodeId?: string;
rawProviderResult?: string;
Expand All @@ -49,6 +50,12 @@ type LnurlInvoiceResponse = {
reason?: string;
};

export type ProbeCommandResult = {
success: boolean;
durationMs?: number;
routeFeeMsat?: number;
};

const DEFAULT_PROBE_TIMEOUT_SECONDS = 90;
const DEFAULT_PROBE_FETCH_RETRIES = 2;
const DEFAULT_PROBE_FETCH_RETRY_DELAY_MS = 1_000;
Expand Down Expand Up @@ -234,24 +241,48 @@ export function runProbeNodeCommand(target: ProbeTarget, amountMsat: number): st
return runDevToolsCommand(method, payload, timeoutSeconds);
}

export function parseProbeCommandSuccess(raw: string): boolean {
export function parseProbeCommandResult(raw: string): ProbeCommandResult | null {
const result = extractContentCallResult(raw);
if (!result) return false;
if (!result) return null;

let parsed: unknown;
try {
parsed = JSON.parse(result);
} catch {
return false;
return null;
}
if (typeof parsed !== 'object' || parsed === null) return false;
if (typeof parsed !== 'object' || parsed === null) return null;

if ('success' in parsed) return parsed.success === true;
const payload = parsed as Record<string, unknown>;
if ('type' in parsed && typeof parsed.type === 'string') {
return parsed.type === 'Success' || parsed.type.endsWith('.ProbeSuccess');
return {
success: parsed.type === 'Success' || parsed.type.endsWith('.ProbeSuccess'),
durationMs: parseOptionalNumber(payload.durationMs),
Comment thread
piotr-iohk marked this conversation as resolved.
Outdated
routeFeeMsat: parseOptionalNumber(payload.routeFeeMsat),
};
}

return {
success: payload.success === true,
durationMs: parseOptionalNumber(payload.durationMs),
routeFeeMsat: parseOptionalNumber(payload.routeFeeMsat),
};
}

export function parseProbeCommandSuccess(raw: string): boolean {
return parseProbeCommandResult(raw)?.success ?? false;
}

function parseOptionalNumber(value: unknown): number | undefined {
if (typeof value === 'number' && Number.isFinite(value)) {
return value;
}
if (typeof value === 'string') {
const parsedValue = Number.parseInt(value, 10);
return Number.isFinite(parsedValue) ? parsedValue : undefined;
}

return false;
return undefined;
}

export function summarizeProbeCommandFailure(raw: string): string {
Expand Down Expand Up @@ -557,8 +588,8 @@ export function renderProbeReport(
`Scores reset: ${scoresResetForReport()}`,
`Readiness at probe start: ${readiness ? summarizeProbeReadiness(readiness) : 'not captured'}`,
'',
'| Target | Type | Amount sats | Required | Fetch | Probe | Retries | Duration ms | Failure |',
'| --- | --- | ---: | --- | --- | --- | ---: | ---: | --- |',
'| Target | Type | Amount sats | Required | Fetch | Probe | Retries | Duration ms | Route fee msat | Failure |',
'| --- | --- | ---: | --- | --- | --- | ---: | ---: | ---: | --- |',
];

for (const result of results) {
Expand All @@ -572,6 +603,7 @@ export function renderProbeReport(
result.success ? '✅' : '❌',
result.retries.toString(),
result.durationMs.toString(),
formatRouteFeeCell(result),
result.success ? '' : formatFailureCell(result.error ?? ''),
].join(' | ')} |`
);
Expand Down Expand Up @@ -684,6 +716,9 @@ async function fetchJsonOnce<T>(url: string): Promise<T> {
if (!response.ok) {
throw new Error(`HTTP ${response.status} for ${url}${formatResponseBody(text)}`);
}
if (text.trim().length === 0) {
throw new Error(`HTTP ${response.status} for ${url} returned an empty response body`);
}

return JSON.parse(text) as T;
}
Expand Down Expand Up @@ -759,6 +794,10 @@ function formatFetchCell(result: ProbeResult): string {
return result.invoiceFetched ? 'ok' : 'failed';
}

function formatRouteFeeCell(result: ProbeResult): string {
return result.routeFeeMsat === undefined ? '' : result.routeFeeMsat.toString();
}

function runDevToolsCommand(
method: string,
payload: Record<string, unknown>,
Expand Down
24 changes: 15 additions & 9 deletions test/specs/mainnet/probe.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
buildProbeQueue,
fetchBolt11ForProbe,
parseNonNegativeIntEnv,
parseProbeCommandSuccess,
parseProbeCommandResult,
probeModeForTargetType,
resolveProbeAmountProfile,
resetPathfindingScores,
Expand Down Expand Up @@ -88,15 +88,16 @@ async function runInvoiceProbe(target: ProbeTarget, amountMsat: number): Promise
);
const rawProviderResult = runProbeInvoiceCommand(target, amountMsat, bolt11);
lastRawProviderResult = rawProviderResult;
const success = parseProbeCommandSuccess(rawProviderResult);
const providerResult = parseProbeCommandResult(rawProviderResult);

if (success) {
if (providerResult?.success) {
Comment thread
piotr-iohk marked this conversation as resolved.
return {
...baseResult,
retries: retry,
invoiceFetched: true,
success: true,
durationMs: Date.now() - startedAt,
durationMs: providerResult.durationMs ?? Date.now() - startedAt,
routeFeeMsat: providerResult.routeFeeMsat,
bolt11,
rawProviderResult,
};
Expand All @@ -113,12 +114,14 @@ async function runInvoiceProbe(target: ProbeTarget, amountMsat: number): Promise
}
}

const providerResult = parseProbeCommandResult(lastRawProviderResult);
return {
...baseResult,
retries: maxRetries,
invoiceFetched: true,
success: false,
durationMs: Date.now() - startedAt,
durationMs: providerResult?.durationMs ?? Date.now() - startedAt,
routeFeeMsat: providerResult?.routeFeeMsat,
bolt11,
rawProviderResult: lastRawProviderResult,
error: lastError,
Expand Down Expand Up @@ -159,14 +162,15 @@ async function runNodeProbe(target: ProbeTarget, amountMsat: number): Promise<Pr
);
const rawProviderResult = runProbeNodeCommand(target, amountMsat);
lastRawProviderResult = rawProviderResult;
const success = parseProbeCommandSuccess(rawProviderResult);
const providerResult = parseProbeCommandResult(rawProviderResult);

if (success) {
if (providerResult?.success) {
Comment thread
piotr-iohk marked this conversation as resolved.
return {
...baseResult,
retries: retry,
success: true,
durationMs: Date.now() - startedAt,
durationMs: providerResult.durationMs ?? Date.now() - startedAt,
routeFeeMsat: providerResult.routeFeeMsat,
rawProviderResult,
};
}
Expand All @@ -182,11 +186,13 @@ async function runNodeProbe(target: ProbeTarget, amountMsat: number): Promise<Pr
}
}

const providerResult = parseProbeCommandResult(lastRawProviderResult);
return {
...baseResult,
retries: maxRetries,
success: false,
durationMs: Date.now() - startedAt,
durationMs: providerResult?.durationMs ?? Date.now() - startedAt,
routeFeeMsat: providerResult?.routeFeeMsat,
rawProviderResult: lastRawProviderResult,
error: lastError,
};
Expand Down