Fix: don't create duplication errors
This commit is contained in:
@@ -277,6 +277,25 @@ test("co-mention pairs attribute targets in the same item", async () => {
|
||||
expect(pairs.has("Super Team->Angela")).toBe(true);
|
||||
});
|
||||
|
||||
test("co-mention emits unique refs when target appears multiple times in different scopes", async () => {
|
||||
const { space } = createMockSystem();
|
||||
await space.writePage("A", "");
|
||||
await space.writePage("B", "");
|
||||
// [[A]] shares a (nested) scope with both occurrences of [[B]]; without
|
||||
// ref-granularity dedupe, both j-iterations would emit the same ref
|
||||
// (A's position + B's name) but with different `via` scopes.
|
||||
const text =
|
||||
"* outer\n * [[A]]\n * [[B]]\n * also [[B]] here\n";
|
||||
const tree = parseMarkdown(text);
|
||||
const fm = extractFrontMatter(tree);
|
||||
const objects = await indexRelations(pageMeta("P"), fm, tree, text);
|
||||
const coms = objects.filter((o) =>
|
||||
o.tag === "relation" && o.kind === "co-mention"
|
||||
);
|
||||
const refs = coms.map((r) => r.ref);
|
||||
expect(new Set(refs).size).toEqual(refs.length);
|
||||
});
|
||||
|
||||
test("co-mention carries fromTag/toTag from target relations", async () => {
|
||||
const { space } = createMockSystem();
|
||||
await space.writePage("Jack", "");
|
||||
|
||||
@@ -523,7 +523,7 @@ function emitCoMentions(ctx: EmitCtx, tree: ParseTree): void {
|
||||
if (sharedPos === undefined) continue;
|
||||
|
||||
const via = `${ctx.pageMeta.name}@${sharedPos}`;
|
||||
const key = `${a.rec.to}->${b.rec.to}@${via}`;
|
||||
const key = `${a.rec.range![0]}->${b.rec.to}`;
|
||||
if (seenDirected.has(key)) continue;
|
||||
seenDirected.add(key);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user