feat: review text hits and release false-positive mappings
This commit is contained in:
@@ -2,6 +2,7 @@ import { promises as fs } from "node:fs";
|
||||
import { basename, dirname, join } from "node:path";
|
||||
import type { PlaceholderMapping } from "../types";
|
||||
import { canonicalPerson } from "./project-review";
|
||||
import { mappingForRestoration, mappingRoot } from "./mapping-groups";
|
||||
import {
|
||||
createRun, digest, isMarkdownFile, isRestorableDocument, listRuns, loadProjectWhitelist, publishProjectCopies,
|
||||
replaceProjectFilesInPlace, resolveWithin, restorePath, restoreText,
|
||||
@@ -18,17 +19,7 @@ export type RevisionPlan = {
|
||||
};
|
||||
|
||||
function existingRoot(key: string, mapping: PlaceholderMapping): string {
|
||||
const seen = new Set<string>();
|
||||
let current = key;
|
||||
while (mapping[current]?.merged_into) {
|
||||
if (seen.has(current)) throw new Error("Zyklische Personen-Zuordnung.");
|
||||
seen.add(current);
|
||||
current = mapping[current].merged_into!;
|
||||
if (!mapping[current] || mapping[current].type !== "PERSON") {
|
||||
throw new Error("Personen-Zuordnung verweist auf ein ungültiges Ziel.");
|
||||
}
|
||||
}
|
||||
return current;
|
||||
return mappingRoot(key, mapping);
|
||||
}
|
||||
|
||||
/** Build a single direct substitution for each changed placeholder; no replacement chains. */
|
||||
@@ -61,16 +52,17 @@ export function planProjectRevision(
|
||||
}
|
||||
const mapping: PlaceholderMapping = {};
|
||||
const replacements: PlaceholderMapping = {};
|
||||
const restoration = mappingForRestoration(previous);
|
||||
const merged: string[] = [];
|
||||
for (const [key, entry] of Object.entries(previous)) {
|
||||
const oldRoot = entry.type === "PERSON" ? existingRoot(key, previous) : key;
|
||||
const oldRoot = existingRoot(key, previous);
|
||||
if (releaseSet.has(key)) {
|
||||
// A canonical placeholder can stand for several spelling variants. Its
|
||||
// visible text restores to the canonical original; every variant is excluded.
|
||||
replacements[key] = { original: entry.original, type: entry.type };
|
||||
replacements[key] = { original: restoration[key].original, type: entry.type };
|
||||
continue;
|
||||
}
|
||||
const finalRoot = entry.type === "PERSON" ? canonicalPerson(oldRoot, merges) : key;
|
||||
const finalRoot = entry.type === "PERSON" ? canonicalPerson(oldRoot, merges) : oldRoot;
|
||||
mapping[key] = { ...entry };
|
||||
if (entry.type === "PERSON") {
|
||||
if (finalRoot === key) delete mapping[key].merged_into;
|
||||
@@ -173,8 +165,10 @@ export async function reviseProjectRun(args: {
|
||||
replacementAttempted = true;
|
||||
await replaceProjectFilesInPlace(previous.projectPath, directory, run.files);
|
||||
} else {
|
||||
publishedCopyPath = await publishProjectCopies(run, directory);
|
||||
run.copyPath = publishedCopyPath;
|
||||
if (run.files.length) {
|
||||
publishedCopyPath = await publishProjectCopies(run, directory);
|
||||
run.copyPath = publishedCopyPath;
|
||||
}
|
||||
await saveRun(directory, run);
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user