mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-03 20:37:06 +01:00
* feat: connect project purpose, next actions and research in Memory * test: resolve superseding essays through the real dynamic route
197 lines
5.3 KiB
TypeScript
197 lines
5.3 KiB
TypeScript
import { APP_URL } from "../../src/config/brand";
|
|
import assert from "node:assert/strict";
|
|
import { buildKnowledgeMap, type MapInputs } from "../../src/lib/knowledge-map/build";
|
|
import { connections, projectHandoff } from "../../src/lib/knowledge-map/model";
|
|
import { mapConnectionFacts } from "../../src/lib/knowledge-map/facts";
|
|
import { planRetrieval } from "../../src/lib/agent/plan";
|
|
const at = new Date("2026-11-15T00:00:00Z");
|
|
const input: MapInputs = {
|
|
projects: [
|
|
{
|
|
id: "p",
|
|
userId: "alice",
|
|
entityProjectId: "e",
|
|
name: "alpha",
|
|
description: "A project",
|
|
gitUrl: "https://github.com/example/alpha?token=SECRET-TOKEN",
|
|
liveUrl: "https://user:SECRET-TOKEN@example.com",
|
|
updatedAt: at,
|
|
devLog: [
|
|
{
|
|
date: "2026-11-15",
|
|
done: "Earlier same-day report",
|
|
next: "Superseded next step",
|
|
tests: "Old report",
|
|
todos: "",
|
|
health: "",
|
|
},
|
|
{
|
|
date: "2026-11-15",
|
|
done: "Built",
|
|
next: "Verify",
|
|
tests: "Reported pass",
|
|
todos: "",
|
|
health: "",
|
|
},
|
|
],
|
|
},
|
|
{
|
|
id: "other",
|
|
userId: "bob",
|
|
entityProjectId: "foreign",
|
|
name: "Secret",
|
|
description: "PRIVATE",
|
|
updatedAt: at,
|
|
devLog: null,
|
|
},
|
|
],
|
|
things: [
|
|
{
|
|
id: "e",
|
|
userId: "alice",
|
|
name: "alpha",
|
|
title: "Alpha",
|
|
type: "project",
|
|
description: "Purpose",
|
|
updatedAt: at,
|
|
},
|
|
{
|
|
id: "person",
|
|
userId: "alice",
|
|
name: "Private contact",
|
|
title: null,
|
|
type: "person",
|
|
description: "Personal detail",
|
|
updatedAt: at,
|
|
},
|
|
{
|
|
id: "foreign",
|
|
userId: "bob",
|
|
name: "Secret",
|
|
title: null,
|
|
type: "project",
|
|
description: "PRIVATE",
|
|
updatedAt: at,
|
|
},
|
|
],
|
|
relations: [
|
|
{
|
|
id: "good",
|
|
userId: "alice",
|
|
fromEntityId: "e",
|
|
toEntityId: "person",
|
|
type: "knows",
|
|
updatedAt: at,
|
|
},
|
|
{
|
|
id: "bad",
|
|
userId: "alice",
|
|
fromEntityId: "e",
|
|
toEntityId: "foreign",
|
|
type: "leak",
|
|
updatedAt: at,
|
|
},
|
|
{
|
|
id: "wrong-owner",
|
|
userId: "bob",
|
|
fromEntityId: "e",
|
|
toEntityId: "person",
|
|
type: "private",
|
|
updatedAt: at,
|
|
},
|
|
],
|
|
goals: [
|
|
{
|
|
id: "g",
|
|
userId: "alice",
|
|
entityId: "e",
|
|
title: "Launch",
|
|
description: "Ship",
|
|
status: "active",
|
|
progress: 20,
|
|
updatedAt: at,
|
|
},
|
|
{
|
|
id: "bad-goal",
|
|
userId: "alice",
|
|
entityId: "foreign",
|
|
title: "Secret goal",
|
|
description: null,
|
|
status: "active",
|
|
progress: 0,
|
|
updatedAt: at,
|
|
},
|
|
],
|
|
packages: [
|
|
{
|
|
projectId: "p",
|
|
userId: "alice",
|
|
packageName: "@example/kit",
|
|
version: "1.0.0",
|
|
observedAt: at,
|
|
},
|
|
{
|
|
projectId: "other",
|
|
userId: "alice",
|
|
packageName: "secret-kit",
|
|
version: null,
|
|
observedAt: at,
|
|
},
|
|
],
|
|
};
|
|
// Extra database fields cannot escape an explicit projection.
|
|
Object.assign(input.projects[0], {
|
|
resources: [{ kind: "credential", notes: "SECRET-TOKEN" }],
|
|
notes: "secret operator notes",
|
|
});
|
|
const map = buildKnowledgeMap("alice", input, [], at);
|
|
assert.equal(
|
|
map.nodes.filter((n) => n.kind === "project").length,
|
|
1,
|
|
"deduplicates runtime project and entity",
|
|
);
|
|
assert.equal(
|
|
map.edges.length,
|
|
3,
|
|
"drops both cross-owner endpoints and foreign relationship owners",
|
|
);
|
|
assert(!JSON.stringify(map).includes("SECRET"));
|
|
assert(!JSON.stringify(map).includes("foreign"));
|
|
assert(!JSON.stringify(map).includes("secret operator"));
|
|
assert.equal(map.nodes.find((n) => n.kind === "project")?.href, `${APP_URL}/projects/e`);
|
|
const handoff = projectHandoff(map, "project:p");
|
|
assert(handoff.includes("Verify"));
|
|
assert(
|
|
!handoff.includes("Superseded next step"),
|
|
"equal-date reports use append order, never an older handoff",
|
|
);
|
|
assert(handoff.includes("Repository: https://github.com/example/alpha"));
|
|
assert(!handoff.includes("SECRET-TOKEN"));
|
|
assert(handoff.includes("not independently verified"));
|
|
assert(handoff.includes("@example/kit"));
|
|
assert(!handoff.includes("Private contact"));
|
|
assert(!handoff.includes("Personal detail"));
|
|
assert.throws(() => projectHandoff(map, "entity:person"));
|
|
const malformed = buildKnowledgeMap(
|
|
"alice",
|
|
{ ...input, projects: [{ ...input.projects[0], entityProjectId: "foreign" }] },
|
|
[],
|
|
at,
|
|
);
|
|
assert.equal(
|
|
malformed.nodes.find((node) => node.id === "project:p")?.href,
|
|
`${APP_URL}/projects`,
|
|
"a foreign entity FK never becomes an open-project link",
|
|
);
|
|
const facts = mapConnectionFacts(map, "Alpha connections");
|
|
assert.equal(facts.length, 4);
|
|
assert(!JSON.stringify(facts).includes("Private contact"));
|
|
assert(facts.slice(1, 3).every((fact) => fact.fields.excerpt?.includes("not a permission grant")));
|
|
assert(planRetrieval("Show my knowledge map connections").sources.includes("projects"));
|
|
assert.equal(connections(map, "package:@example/kit").length, 1);
|
|
const bounded = buildKnowledgeMap("alice", input, ["Older records omitted"], at);
|
|
assert(projectHandoff(bounded, "project:p").includes("Older records omitted"));
|
|
console.log(
|
|
"knowledge-map: ownership, canonical identity, narrow handoff, grounded agent context and bounds passed",
|
|
);
|