Anki maturity-based known-word highlighting (#172)

This commit is contained in:
2026-07-27 23:58:02 -07:00
committed by GitHub
parent 08c6807cb1
commit 987b325edb
54 changed files with 3046 additions and 381 deletions
+51
View File
@@ -328,3 +328,54 @@ test('warns and falls back for invalid proxy settings', () => {
assert.ok(warnings.some((warning) => warning.path === 'ankiConnect.proxy.port'));
assert.ok(warnings.some((warning) => warning.path === 'ankiConnect.proxy.upstreamUrl'));
});
test('resolves knownWords maturity settings from config', () => {
const { context, warnings } = makeContext({
knownWords: { highlightEnabled: true, maturityEnabled: true, matureThresholdDays: 30 },
});
applyAnkiConnectResolution(context);
assert.equal(context.resolved.ankiConnect.knownWords.maturityEnabled, true);
assert.equal(context.resolved.ankiConnect.knownWords.matureThresholdDays, 30);
assert.deepEqual(warnings, []);
});
test('warns and falls back for invalid knownWords maturity settings', () => {
const { context, warnings } = makeContext({
knownWords: { maturityEnabled: 'yes', matureThresholdDays: 0 },
});
applyAnkiConnectResolution(context);
assert.equal(
context.resolved.ankiConnect.knownWords.maturityEnabled,
DEFAULT_CONFIG.ankiConnect.knownWords.maturityEnabled,
);
assert.equal(
context.resolved.ankiConnect.knownWords.matureThresholdDays,
DEFAULT_CONFIG.ankiConnect.knownWords.matureThresholdDays,
);
assert.ok(warnings.some((warning) => warning.path === 'ankiConnect.knownWords.maturityEnabled'));
assert.ok(
warnings.some((warning) => warning.path === 'ankiConnect.knownWords.matureThresholdDays'),
);
});
test('omitted knownWords maturity settings fall back to defaults', () => {
const { context, warnings } = makeContext({
knownWords: { highlightEnabled: true },
});
applyAnkiConnectResolution(context);
assert.equal(
context.resolved.ankiConnect.knownWords.maturityEnabled,
DEFAULT_CONFIG.ankiConnect.knownWords.maturityEnabled,
);
assert.equal(
context.resolved.ankiConnect.knownWords.matureThresholdDays,
DEFAULT_CONFIG.ankiConnect.knownWords.matureThresholdDays,
);
assert.deepEqual(warnings, []);
});
@@ -49,6 +49,46 @@ export function applyAnkiKnownWordsResolution(
}
}
const knownWordsMaturityEnabled = asBoolean(knownWordsConfig.maturityEnabled);
if (knownWordsMaturityEnabled !== undefined) {
context.resolved.ankiConnect.knownWords.maturityEnabled = knownWordsMaturityEnabled;
} else if (hasOwn(knownWordsConfig, 'maturityEnabled')) {
context.warn(
'ankiConnect.knownWords.maturityEnabled',
knownWordsConfig.maturityEnabled,
context.resolved.ankiConnect.knownWords.maturityEnabled,
'Expected boolean.',
);
context.resolved.ankiConnect.knownWords.maturityEnabled =
DEFAULT_CONFIG.ankiConnect.knownWords.maturityEnabled;
} else {
context.resolved.ankiConnect.knownWords.maturityEnabled =
DEFAULT_CONFIG.ankiConnect.knownWords.maturityEnabled;
}
const knownWordsMatureThresholdDays = asNumber(knownWordsConfig.matureThresholdDays);
const hasValidMatureThresholdDays =
knownWordsMatureThresholdDays !== undefined &&
Number.isInteger(knownWordsMatureThresholdDays) &&
knownWordsMatureThresholdDays >= 1;
if (hasOwn(knownWordsConfig, 'matureThresholdDays')) {
if (hasValidMatureThresholdDays) {
context.resolved.ankiConnect.knownWords.matureThresholdDays = knownWordsMatureThresholdDays;
} else {
context.warn(
'ankiConnect.knownWords.matureThresholdDays',
knownWordsConfig.matureThresholdDays,
DEFAULT_CONFIG.ankiConnect.knownWords.matureThresholdDays,
'Expected an integer of at least 1.',
);
context.resolved.ankiConnect.knownWords.matureThresholdDays =
DEFAULT_CONFIG.ankiConnect.knownWords.matureThresholdDays;
}
} else {
context.resolved.ankiConnect.knownWords.matureThresholdDays =
DEFAULT_CONFIG.ankiConnect.knownWords.matureThresholdDays;
}
const knownWordsRefreshMinutes = asNumber(knownWordsConfig.refreshMinutes);
const hasValidKnownWordsRefreshMinutes =
knownWordsRefreshMinutes !== undefined &&