fix: rescan project files when category coverage changes

This commit is contained in:
muena
2026-10-19 12:34:07 +02:00
parent f71e46f735
commit 731c449c33
5 changed files with 33 additions and 3 deletions

View File

@@ -113,6 +113,7 @@ export async function reviseProjectRun(args: {
const { directory, run } = created;
run.origin = previous.origin;
run.revisedFrom = previous.id;
run.entityTypes = previous.entityTypes ? [...previous.entityTypes] : undefined;
run.commentAuthorCoverage = previous.commentAuthorCoverage;
run.reviewAuthorCoverage = previous.reviewAuthorCoverage;
run.mapping = plan.mapping;

View File

@@ -23,6 +23,8 @@ export type ProjectRun = {
projectName: string;
createdAt: string;
mapping: PlaceholderMapping;
/** Categories actually used to analyze the files in this snapshot. */
entityTypes?: EntityType[];
/** Hash of each live project file and its immutable output in this run. */
sourceState?: Record<string, { hash: string; output: string }>;
/** Generic replacement mode for placeholders embedded in code identifiers. */
@@ -472,6 +474,7 @@ export async function updateProjectMapping(projectPath: string,
run.origin = latest.run.origin;
run.revisedFrom = latest.run.id;
run.mapping = mapping;
run.entityTypes = latest.run.entityTypes ? [...latest.run.entityTypes] : undefined;
run.matchModes = { ...latest.run.matchModes };
run.files = latest.run.files.map((file) => ({ ...file }));
run.sourceState = latest.run.sourceState ? { ...latest.run.sourceState } : undefined;
@@ -614,6 +617,13 @@ export async function reusableProjectOutput(run: ProjectRun, directory: string,
return await matchesPreviousOutput(directory, relPath, currentHash) ? relPath : undefined;
}
/** Unknown or changed category coverage requires a new review of unchanged files. */
export function sameEntityTypeCoverage(run: ProjectRun, selected: readonly EntityType[]): boolean {
if (!Array.isArray(run.entityTypes)) return false;
const covered = new Set(run.entityTypes);
return covered.size === new Set(selected).size && selected.every((type) => covered.has(type));
}
/** Only an identical saved file can disambiguate a placeholder reused across runs. */
export async function mappingForMatchingSnapshots(relPath: string, currentHash: string,
earlier: Array<{ run: ProjectRun; directory: string }>): Promise<PlaceholderMapping> {

View File

@@ -10,7 +10,7 @@ import type { DocumentHit } from "./velum";
import {
createRun, digest, forceMasks, listRuns, loadProjectEntityTypes, loadProjectFileExclusions, loadProjectRules, parseProjectRules, publishProjectCopies, replaceSpans,
loadProjectWhitelist, reusableProjectOutput, replaceProjectFilesInPlace, resolveWithin, safeRelativePath, saveProjectFileExclusions, saveProjectRules,
saveProjectEntityTypes, saveProjectWhitelist, saveRun, scanProjectFiles, toUtf16Offsets, whitelistKey, withoutExcludedProjectFiles,
saveProjectEntityTypes, saveProjectWhitelist, saveRun, sameEntityTypeCoverage, scanProjectFiles, toUtf16Offsets, whitelistKey, withoutExcludedProjectFiles,
} from "./lib/velum-project";
import type { ProjectFile, ProjectRule, ProjectWhitelistEntry, RunFile, SkippedProjectFile } from "./lib/velum-project";
import {
@@ -109,6 +109,8 @@ async function prepare(root: string, files: ProjectFile[], rules: ProjectRule[],
const masks = forceMasks(withoutWhitelistedRules(rules, whitelist));
const latestEntry = (await listRuns(root))[0];
const latest = latestEntry?.run;
const categoryCoverageChanged = Boolean(latest && !sameEntityTypeCoverage(latest, entityTypes));
if (categoryCoverageChanged) onProgress("Kategorien geändert oder alter Stand: Dateien erneut analysieren");
const previousMapping: PlaceholderMapping = latest?.mapping ?? {};
const previousPlaceholders = Object.keys(previousMapping);
let mapping: PlaceholderMapping = previousMapping;
@@ -122,7 +124,7 @@ async function prepare(root: string, files: ProjectFile[], rules: ProjectRule[],
for (const file of files) {
const data = await fs.readFile(file.absPath);
const hash = digest(data);
const previousOutput = !reanalyzeUnchanged && latest && previousDirectory
const previousOutput = !reanalyzeUnchanged && !categoryCoverageChanged && latest && previousDirectory
? await reusableProjectOutput(latest, previousDirectory, file.relPath, hash) : undefined;
if (previousOutput && previousDirectory) {
retained.push({ file, hash, output: previousOutput, directory: previousDirectory });
@@ -320,6 +322,7 @@ function HitReview(props: { root: string; rules: ProjectRule[]; whitelist: Proje
selectedPeople.has(source) && availableTargets.has(canonicalPerson(target, personMerges))));
run.mapping = mappingForSelection(props.preview.mapping, props.preview.previousMapping,
acceptedHits, activeMerges);
run.entityTypes = [...props.preview.entityTypes];
run.sourceState = {};
run.commentAuthorCoverage = props.preview.entityTypes.includes("PERSON");
run.reviewAuthorCoverage = props.preview.entityTypes.includes("PERSON");
@@ -778,7 +781,7 @@ export default function Command() {
<Form.Checkbox id="reanalyzeUnchanged" title="Erneute Analyse"
label="Auch unveränderte Dateien erneut analysieren" value={reanalyzeUnchanged}
onChange={setReanalyzeUnchanged}
info="Standardmäßig werden nur neue oder geänderte Dateien an Velum gesendet. Für neue Regeln, Kategorien oder Word-Erkennung auch bestehende Dateien ausdrücklich erneut prüfen." />
info="Unveränderte Dateien werden nur bei geänderten Kategorien oder unbekanntem altem Prüfstand automatisch neu analysiert. Für neue Projektregeln oder Word-Erkennung diese Option aktivieren." />
<Form.Description title="Projekt-Whitelist" text={`${whitelist.length} Begriffe werden bei diesem Ordner nicht mehr vorgeschlagen. Über die Aktionen kannst du sie wieder freigeben.`} />
<Form.Description title="Ablauf" text="Dateien und Kategorien wählen, Zuordnungen prüfen und Personen bei Bedarf zusammenfassen. Abgewählte Dateien bleiben für diesen Projektordner ausgeschlossen. Standardmäßig werden die Originaldateien nach Bestätigung ersetzt; Kopien sind als Alternative verfügbar." />
</Form>;