Normalize mistaken user owners across extraction and cognition

This commit is contained in:
Youzini-afk
2026-04-09 23:38:14 +08:00
parent d1b07d8cbb
commit 5c9a8a9df1
7 changed files with 512 additions and 98 deletions

View File

@@ -209,4 +209,78 @@ globalThis.__stBmeTestContext = {
}
}
{
const graph = createEmptyGraph();
globalThis.__stBmeTestContext.name1 = "邱谁";
globalThis.__stBmeTestContext.name2 = "群像卡";
const restore = setTestOverrides({
llm: {
async callLLMForJSON() {
return {
operations: [
{
action: "create",
type: "pov_memory",
scope: {
layer: "pov",
ownerType: "character",
ownerName: "邱 谁",
ownerId: "邱 谁",
},
fields: { summary: "她感觉对方在试探自己的底线" },
},
],
cognitionUpdates: [
{
ownerType: "character",
ownerName: "【邱谁】",
knownRefs: [],
},
],
regionUpdates: {},
};
},
},
});
try {
const result = await extractMemories({
graph,
messages: [{ seq: 7, role: "assistant", content: "用户名误标测试" }],
startSeq: 7,
endSeq: 7,
schema: DEFAULT_NODE_SCHEMA,
embeddingConfig: null,
settings: {},
});
assert.equal(result.success, true);
const povNode = graph.nodes.find(
(node) => !node.archived && node.type === "pov_memory",
);
assert.ok(povNode);
assert.equal(povNode.scope?.ownerType, "user");
assert.equal(povNode.scope?.ownerName, "邱谁");
const knowledgeOwners = Object.values(graph.knowledgeState?.owners || {});
assert.equal(
knowledgeOwners.some(
(entry) =>
String(entry?.ownerType || "") === "character" &&
String(entry?.ownerName || "") === "邱谁",
),
false,
);
assert.equal(
knowledgeOwners.some(
(entry) =>
String(entry?.ownerType || "") === "user" &&
String(entry?.ownerName || "") === "邱谁",
),
true,
);
} finally {
restore();
}
}
console.log("extractor-owner-scope tests passed");