fix(anki): harden AnkiConnect requests and yomitan runtime fallback

- add request timeout and HTTP status check to verify-known-word-highlights AnkiConnect client
- let yomitan-script-runtime search on its own when the resolved manifest path isn't usable
- dedupe repeated tier-query setup in known-word-cache-maturity tests via setTierQueries helper
This commit is contained in:
2026-07-27 00:26:40 -07:00
parent 48c36aa195
commit a0fec40a13
3 changed files with 28 additions and 33 deletions
+6
View File
@@ -224,13 +224,19 @@ function readPersistedCacheScope(cachePath: string): string | null {
}
}
const ANKI_REQUEST_TIMEOUT_MS = 30_000;
function createAnkiClient(url: string) {
const request = async (action: string, params: unknown): Promise<unknown> => {
const response = await fetch(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ action, version: 6, params }),
signal: AbortSignal.timeout(ANKI_REQUEST_TIMEOUT_MS),
});
if (!response.ok) {
throw new Error(`AnkiConnect ${action}: HTTP ${response.status} ${response.statusText}`);
}
const payload = (await response.json()) as { result: unknown; error: string | null };
if (payload.error) {
throw new Error(`AnkiConnect ${action}: ${payload.error}`);
+2 -1
View File
@@ -152,5 +152,6 @@ export async function createYomitanRuntimeStateWithSearch(
}
}
return createYomitanRuntimeState(userDataPath, resolvedExtensionPath ?? undefined);
// No usable manifest at the resolved path, so let the loader search on its own.
return createYomitanRuntimeState(userDataPath);
}