Files
wehub-resource-sync 426e9eeabd
Voice Workbench / headless workbench (mocked backends) (push) Has been cancelled
Voice Workbench / real acoustic lane (nightly, provisioned only) (push) Has been cancelled
ci / test (push) Has been cancelled
ci / lint-and-format (push) Has been cancelled
ci / build (push) Has been cancelled
ci / dev-startup (push) Has been cancelled
gitleaks / gitleaks (push) Has been cancelled
Markdown Links / Relative Markdown Links (push) Has been cancelled
Quality (Extended) / Homepage Build (PR smoke) (push) Has been cancelled
Quality (Extended) / Comment-only diff guard (push) Has been cancelled
Quality (Extended) / Format + Type Safety Ratchet (push) Has been cancelled
Quality (Extended) / Develop Gate (secret scan + UI determinism) (push) Has been cancelled
Quality (Extended) / Develop Gate (lint) (push) Has been cancelled
Chat shell gestures / Chat shell gesture + parity e2e (push) Has been cancelled
Cloud Gateway Discord / Test (push) Has been cancelled
Benchmark Bridge Tests / benchmark (bunx @biomejs/biome check packages/lifeops-bench/src, benchmark-lint) (push) Has been cancelled
Benchmark Bridge Tests / benchmark (bunx vitest run --config packages/lifeops-bench/vitest.config.ts --root packages/lifeops-bench --passWithNoTests, benchmark-tests) (push) Has been cancelled
Build Agent Image / build-and-push (push) Has been cancelled
Dev Smoke / bun run dev onboarding chat (push) Has been cancelled
Dev Smoke / Vite HMR dependency-level smoke (push) Has been cancelled
Electrobun Submodule Guard / electrobun gitlink is fetchable (push) Has been cancelled
Publish @elizaos/example-code / check_npm (push) Has been cancelled
Publish @elizaos/example-code / publish_npm (push) Has been cancelled
Publish @elizaos/plugin-elizacloud / verify_version (push) Has been cancelled
Publish @elizaos/plugin-elizacloud / publish_npm (push) Has been cancelled
Sandbox Live Smoke / Sandbox live smoke (push) Has been cancelled
Snap Build & Test / Build Snap (amd64) (push) Has been cancelled
Snap Build & Test / Build Snap (arm64) (push) Has been cancelled
Test Packaging / elizaos CLI global-install smoke (node + bun) (push) Has been cancelled
Cloud Gateway Webhook / Test (push) Has been cancelled
Cloud Tests / lint-and-types (push) Has been cancelled
Cloud Tests / unit-tests (push) Has been cancelled
Cloud Tests / integration-tests (push) Has been cancelled
Cloud Tests / e2e-tests (push) Has been cancelled
CodeQL Advanced / Analyze (javascript-typescript) (push) Has been cancelled
Deploy Apps Worker (Product 2) / Determine environment (push) Has been cancelled
Deploy Apps Worker (Product 2) / Deploy apps worker to apps-control host (${{ needs.determine-env.outputs.environment }}) (push) Has been cancelled
Deploy Eliza Provisioning Worker / Determine environment (push) Has been cancelled
Deploy Eliza Provisioning Worker / Deploy worker to Hetzner host (${{ needs.determine-env.outputs.environment }} @ ${{ needs.determine-env.outputs.deployment_sha }}) (push) Has been cancelled
Dev Smoke / Classify changed paths (push) Has been cancelled
supply-chain / sbom (push) Has been cancelled
supply-chain / vulnerability-scan (push) Has been cancelled
Build, Push & Deploy to Phala Cloud / build-and-push (push) Has been cancelled
Test Packaging / Validate Packaging Configs (push) Has been cancelled
Test Packaging / Build & Test PyPI Package (push) Has been cancelled
Test Packaging / PyPI on Python ${{ matrix.python }} (push) Has been cancelled
Test Packaging / Pack & Test JS Tarballs (push) Has been cancelled
UI Fixture E2E / ui-fixture-e2e (push) Has been cancelled
UI Fixture E2E / fixture-e2e (push) Has been cancelled
UI Story Gate / story-gate (push) Has been cancelled
vault-ci / test (macos-latest) (push) Has been cancelled
vault-ci / test (ubuntu-latest) (push) Has been cancelled
vault-ci / test (windows-latest) (push) Has been cancelled
vault-ci / app-core wiring tests (push) Has been cancelled
verify-patches / verify patches/CHECKSUMS.sha256 (push) Has been cancelled
Voice Benchmark Smoke / voice-emotion fixture smoke (push) Has been cancelled
Voice Benchmark Smoke / voiceagentbench fixture smoke (push) Has been cancelled
Voice Benchmark Smoke / voicebench-quality unit smoke (push) Has been cancelled
Voice Benchmark Smoke / voicebench TypeScript unit (no audio) (push) Has been cancelled
Voice Benchmark Smoke / voice bench smoke summary (push) Has been cancelled
Windows CI / windows ([bun run --cwd packages/app-core test bun run --cwd packages/elizaos test bun run --cwd packages/cloud/shared test], app-and-cli) (push) Has been cancelled
Windows CI / windows ([bun run --cwd packages/scenario-runner test bun run --cwd packages/vault test bun run --cwd packages/security test bun run --cwd plugins/plugin-coding-tools test], framework-packages) (push) Has been cancelled
Windows CI / windows ([bun run --cwd plugins/plugin-elizacloud test bun run --cwd plugins/plugin-discord test bun run --cwd plugins/plugin-anthropic test bun run --cwd plugins/plugin-openai test bun run --cwd plugins/plugin-app-control test bun run --cwd plugins/pl… (push) Has been cancelled
Windows CI / windows ([node packages/scripts/run-turbo.mjs run build --filter=@elizaos/core --filter=@elizaos/shared --filter=@elizaos/agent --concurrency=4 node packages/scripts/run-bash-linux-only.mjs scripts/verify-riscv64-buildpaths.sh node packages/scripts/run… (push) Has been cancelled
Windows CI / windows ([node packages/scripts/run-turbo.mjs run typecheck --filter=@elizaos/core --filter=@elizaos/shared --filter=@elizaos/cloud-shared --concurrency=4 bun run --cwd packages/core test bun run --cwd packages/shared test], core-runtime, 75) (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:43:05 +08:00

288 lines
8.6 KiB
TypeScript

/**
* Tests for the EntityStore — multi-identity upsert, observeIdentity merge
* with provenance, resolve with multiple candidates, recordInteraction,
* and explicit merge.
*
* Runs against a real PGLite-backed runtime via createRealTestRuntime.
*/
import type { AgentRuntime } from "@elizaos/core";
import { afterAll, beforeAll, describe, expect, it } from "vitest";
import {
createRealTestRuntime,
type RealTestRuntimeResult,
} from "../../../packages/test/helpers/real-runtime.ts";
import { EntityStore } from "../src/lifeops/entities/store";
import type { EntityIdentity } from "../src/lifeops/entities/types";
import { SELF_ENTITY_ID } from "../src/lifeops/entities/types";
import { LifeOpsRepository } from "../src/lifeops/repository";
describe("EntityStore — real PGLite", () => {
let runtime: AgentRuntime;
let testResult: RealTestRuntimeResult;
let store: EntityStore;
const agentId = "entitystore-tests";
beforeAll(async () => {
testResult = await createRealTestRuntime({ characterName: agentId });
runtime = testResult.runtime;
await LifeOpsRepository.bootstrapSchema(runtime);
store = new EntityStore(runtime, agentId);
await store.ensureSelf();
}, 180_000);
afterAll(async () => {
await testResult?.cleanup();
});
it("ensureSelf bootstraps and is idempotent", async () => {
const a = await store.ensureSelf();
const b = await store.ensureSelf();
expect(a.entityId).toBe(SELF_ENTITY_ID);
expect(b.entityId).toBe(SELF_ENTITY_ID);
expect(b.createdAt).toBe(a.createdAt);
});
it("upsert creates an entity with multiple identities", async () => {
const identities: EntityIdentity[] = [
{
platform: "telegram",
handle: "@alice",
verified: true,
confidence: 1,
addedAt: new Date().toISOString(),
addedVia: "user_chat",
evidence: ["obs-1"],
},
{
platform: "gmail",
handle: "alice@example.com",
verified: true,
confidence: 1,
addedAt: new Date().toISOString(),
addedVia: "user_chat",
evidence: ["obs-1"],
},
];
const entity = await store.upsert({
type: "person",
preferredName: "Alice",
identities,
tags: ["friend"],
visibility: "owner_agent_admin",
state: {},
});
expect(entity.identities).toHaveLength(2);
const fetched = await store.get(entity.entityId);
expect(fetched?.identities).toHaveLength(2);
expect(fetched?.tags).toEqual(["friend"]);
});
it("observeIdentity collapses entities by (platform, handle) with provenance", async () => {
// Seed an entity with a Discord handle.
const seeded = await store.upsert({
type: "person",
preferredName: "Pat",
identities: [
{
platform: "discord",
handle: "patsmith",
verified: true,
confidence: 0.95,
addedAt: new Date().toISOString(),
addedVia: "user_chat",
evidence: ["seed-1"],
},
],
tags: [],
visibility: "owner_agent_admin",
state: {},
});
const result = await store.observeIdentity({
platform: "discord",
handle: "patsmith",
displayName: "Pat S.",
evidence: ["obs-2"],
confidence: 0.95,
});
expect(result.entity.entityId).toBe(seeded.entityId);
expect(result.mergedFrom).toEqual([seeded.entityId]);
const fetched = await store.get(seeded.entityId);
const identity = fetched?.identities.find(
(id) => id.platform === "discord" && id.handle === "patsmith",
);
expect(identity?.evidence).toContain("seed-1");
expect(identity?.evidence).toContain("obs-2");
});
it("observeIdentity creates a new entity when no candidate matches", async () => {
const result = await store.observeIdentity({
platform: "x",
handle: "@brandnew",
evidence: ["obs-x"],
confidence: 0.9,
});
expect(result.entity.entityId).not.toBe(SELF_ENTITY_ID);
expect(result.entity.identities).toHaveLength(1);
expect(result.entity.identities[0]?.platform).toBe("x");
});
it("observeIdentity surfaces conflict when multiple candidates match", async () => {
// Two pre-existing entities both claiming the same email handle.
const a = await store.upsert({
type: "person",
preferredName: "Conflict A",
identities: [
{
platform: "email",
handle: "shared@conflict.com",
verified: false,
confidence: 0.6,
addedAt: new Date().toISOString(),
addedVia: "platform_observation",
evidence: ["a"],
},
],
tags: [],
visibility: "owner_agent_admin",
state: {},
});
const b = await store.upsert({
type: "person",
preferredName: "Conflict B",
identities: [
{
platform: "email",
handle: "shared@conflict.com",
verified: false,
confidence: 0.6,
addedAt: new Date().toISOString(),
addedVia: "platform_observation",
evidence: ["b"],
},
],
tags: [],
visibility: "owner_agent_admin",
state: {},
});
const result = await store.observeIdentity({
platform: "email",
handle: "shared@conflict.com",
evidence: ["obs-conflict"],
confidence: 0.7,
});
expect(result.conflict).toBe(true);
expect(result.mergedFrom?.sort()).toEqual([a.entityId, b.entityId].sort());
});
it("resolve returns ranked candidates by name", async () => {
await store.upsert({
type: "person",
preferredName: "ResolveTest",
identities: [],
tags: [],
visibility: "owner_agent_admin",
state: {},
});
const candidates = await store.resolve({
name: "ResolveTest",
type: "person",
});
expect(candidates.length).toBeGreaterThan(0);
expect(candidates[0]?.entity.preferredName).toBe("ResolveTest");
});
it("resolve with identity narrows to exact (platform, handle)", async () => {
await store.upsert({
type: "person",
preferredName: "IdentityResolve",
identities: [
{
platform: "telegram",
handle: "identity_resolve",
verified: true,
confidence: 1,
addedAt: new Date().toISOString(),
addedVia: "user_chat",
evidence: ["ir"],
},
],
tags: [],
visibility: "owner_agent_admin",
state: {},
});
const result = await store.resolve({
identity: { platform: "telegram", handle: "identity_resolve" },
});
expect(result.length).toBe(1);
expect(result[0]?.safeToSend).toBe(true);
});
it("recordInteraction updates state.lastInboundAt and lastInteractionPlatform", async () => {
const entity = await store.upsert({
type: "person",
preferredName: "Interactor",
identities: [],
tags: [],
visibility: "owner_agent_admin",
state: {},
});
const occurredAt = new Date("2026-05-01T10:00:00Z").toISOString();
await store.recordInteraction(entity.entityId, {
platform: "telegram",
direction: "inbound",
summary: "ping",
occurredAt,
});
const fetched = await store.get(entity.entityId);
expect(fetched?.state.lastInboundAt).toBe(occurredAt);
expect(fetched?.state.lastInteractionPlatform).toBe("telegram");
});
it("merge folds source identities into target and removes the source row", async () => {
const target = await store.upsert({
type: "person",
preferredName: "MergeTarget",
identities: [
{
platform: "email",
handle: "target@example.com",
verified: true,
confidence: 1,
addedAt: new Date().toISOString(),
addedVia: "user_chat",
evidence: ["t"],
},
],
tags: ["original"],
visibility: "owner_agent_admin",
state: {},
});
const source = await store.upsert({
type: "person",
preferredName: "MergeSource",
identities: [
{
platform: "telegram",
handle: "@mergesource",
verified: true,
confidence: 1,
addedAt: new Date().toISOString(),
addedVia: "platform_observation",
evidence: ["s"],
},
],
tags: ["folded"],
visibility: "owner_agent_admin",
state: {},
});
const merged = await store.merge(target.entityId, [source.entityId]);
expect(merged.identities.length).toBe(2);
expect(merged.tags).toContain("original");
expect(merged.tags).toContain("folded");
expect(await store.get(source.entityId)).toBeNull();
});
});