The manga match result containing Kenmei and AniList data.
Object with generated command, description, and all metadata.
export function generateConfidenceTestCommand(
match: MangaMatchResult,
): ConfidenceTestCommand {
const searchTitle = match.kenmeiManga.title;
// Get the first match's candidate (what the algorithm suggested)
const firstMatch = match.anilistMatches?.[0];
const candidate = firstMatch?.manga;
if (!candidate) {
throw new Error("No candidate match found");
}
// Build candidate title (prefer English, fall back to Romaji)
const candidateTitle =
candidate.title.english || candidate.title.romaji || "";
const candidateRomaji = candidate.title.romaji || null;
const candidateNative = candidate.title.native || null;
// Collect synonyms from the candidate
const synonyms = candidate.synonyms || [];
// Build the command using npx tsx directly to avoid npm argument parsing issues
// (npm filters out unrecognized flags like --synonyms)
const commandParts: string[] = [
`npx tsx scripts/test-confidence.mts`,
quoteCommandArgument(searchTitle),
quoteCommandArgument(candidateTitle),
];
// Add romaji if different from English title
if (candidateRomaji && candidateRomaji !== candidateTitle) {
commandParts.push(quoteCommandArgument(candidateRomaji));
// Add native title if present and different
if (candidateNative && candidateNative !== candidateTitle) {
commandParts.push(quoteCommandArgument(candidateNative));
}
} else if (candidateNative && candidateNative !== candidateTitle) {
// If no romaji but we have native, add empty string placeholder then native
commandParts.push(
quoteCommandArgument(""),
quoteCommandArgument(candidateNative),
);
}
// Add synonyms if present
if (synonyms.length > 0) {
commandParts.push(
`--synonyms=${quoteCommandArgument(JSON.stringify(synonyms))}`,
);
}
const command = commandParts.join(" ");
const description =
`Test command to replicate this match's confidence calculation. ` +
`Search term: "${searchTitle}" vs ` +
`Candidate: "${candidateTitle}" (confidence: ${Math.round(firstMatch?.confidence || 0)}%)`;
return {
command,
description,
searchTitle,
candidateTitle,
candidateRomaji,
candidateNative,
synonyms,
};
}
Generates npm test:confidence command from match result for local testing; includes metadata.