fix(library): proper picker-loop isolation with real regression test

Supersedes 4249952's half-fix: try now wraps pickCandidate too; restores
the 19 controller tests that commit deleted; replaces its source-grep
pseudo-tests with a behavioral two-entry isolation test.
This commit is contained in:
afiqzudinhadi 2026-08-05 15:37:19 +08:00
parent 4249952f0a
commit 2686c3fa64
3 changed files with 40 additions and 36 deletions

View file

@ -227,20 +227,19 @@ export class LibraryController {
let skipped = 0;
if (!dryRun) {
for (const entry of report.needsChoice) {
const idx = await this.pickCandidate(entry.filename, entry.candidates);
const candidate = idx != null ? entry.candidates[idx] : undefined;
if (!candidate) {
skipped++;
continue;
}
try {
const idx = await this.pickCandidate(entry.filename, entry.candidates);
const candidate = idx != null ? entry.candidates[idx] : undefined;
if (!candidate) {
skipped++;
continue;
}
const content = await deps.readNote(entry.path);
await deps.writeNote(entry.path, patchFrontmatter(content, candidate.patches, { defaultType: spec.itemType }));
report.resolved.push(entry.path);
picked++;
} catch (e) {
const msg = e instanceof Error ? e.message : String(e);
console.log(`[media-db-library] picker failed for ${entry.filename}: ${msg}`);
deps.log(`picker failed for ${entry.filename}: ${e instanceof Error ? e.message : String(e)}`);
skipped++;
}
}