fix: stabilize authoring graph selection

This commit is contained in:
lda
2026-08-09 06:30:27 +07:00 Verified
parent c037e73bee
commit d4c28850d8
14 changed files with 303 additions and 156 deletions
@@ -0,0 +1,33 @@
import type { DraftDiagnostic } from "../domain/draft-workspace-models.js";
export type DiagnosticEntry = {
readonly diagnostic: DraftDiagnostic;
readonly key: string;
};
const diagnosticIdentity = (diagnostic: DraftDiagnostic): string =>
JSON.stringify([
diagnostic.code,
diagnostic.path,
diagnostic.message,
diagnostic.stepId,
diagnostic.repairHint,
diagnostic.details,
]);
export const withDiagnosticKeys = (
diagnostics: ReadonlyArray<DraftDiagnostic>,
): ReadonlyArray<DiagnosticEntry> => {
const occurrenceByIdentity = new Map<string, number>();
const entries: DiagnosticEntry[] = [];
for (const diagnostic of diagnostics) {
const identity = diagnosticIdentity(diagnostic);
const occurrence = occurrenceByIdentity.get(identity) ?? 0;
occurrenceByIdentity.set(identity, occurrence + 1);
entries.push({
diagnostic,
key: `diagnostic-${identity}-${occurrence}`,
});
}
return entries;
};