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
196 lines
7.1 KiB
TypeScript
196 lines
7.1 KiB
TypeScript
// Exercises workflow engine unit behavior and credential handling.
|
|
import { describe, expect, mock, test } from 'bun:test';
|
|
import type { EventPayload, IAgentRuntime } from '@elizaos/core';
|
|
import { WorkflowCredentialStore } from '../../src/services/workflow-credential-store';
|
|
import {
|
|
CONNECTOR_DISCONNECTED_EVENT,
|
|
type ConnectorDisconnectedPayload,
|
|
} from '../../src/types/index';
|
|
|
|
/**
|
|
* Verifies the event-driven cache eviction wired up in
|
|
* `WorkflowCredentialStore.start()`:
|
|
*
|
|
* - Subscribes to `connector_disconnected` on start.
|
|
* - Calls `delete(userId, credType)` for every credType in the payload.
|
|
* - Unsubscribes on stop, so subsequent emits are no-ops.
|
|
*
|
|
* Uses a fake event bus + a spy on `WorkflowCredentialStore.prototype.delete`
|
|
* so the test exercises the real subscribe/unsubscribe path without standing
|
|
* up Postgres / pglite.
|
|
*/
|
|
|
|
type EventHandler = (payload: EventPayload) => Promise<void>;
|
|
type CredentialStoreRuntime = Pick<
|
|
IAgentRuntime,
|
|
'agentId' | 'db' | 'getService' | 'getSetting' | 'registerEvent' | 'unregisterEvent'
|
|
>;
|
|
type DeleteMethod = typeof WorkflowCredentialStore.prototype.delete;
|
|
|
|
interface EventBusRuntime {
|
|
agentId: string;
|
|
/** Map of event name → handler list. */
|
|
events: Map<string, EventHandler[]>;
|
|
emit: (
|
|
eventName: string,
|
|
payload: Omit<ConnectorDisconnectedPayload, 'runtime'>
|
|
) => Promise<void>;
|
|
/** Number of currently-registered handlers for an event (for assertions). */
|
|
handlerCount: (eventName: string) => number;
|
|
}
|
|
|
|
function createEventBusRuntime(agentId = 'agent-001'): {
|
|
runtime: IAgentRuntime;
|
|
bus: EventBusRuntime;
|
|
} {
|
|
const events = new Map<string, EventHandler[]>();
|
|
|
|
const bus: EventBusRuntime = {
|
|
agentId,
|
|
events,
|
|
handlerCount: (eventName) => events.get(eventName)?.length ?? 0,
|
|
emit: async (eventName, payload) => {
|
|
const handlers = events.get(eventName) ?? [];
|
|
// Mirror the real runtime's auto-injection of `runtime` + `source`.
|
|
const fullPayload: ConnectorDisconnectedPayload = {
|
|
...payload,
|
|
runtime,
|
|
source: 'test',
|
|
};
|
|
await Promise.all(handlers.map((handler) => handler(fullPayload)));
|
|
},
|
|
};
|
|
|
|
const runtimeDouble: CredentialStoreRuntime = {
|
|
agentId,
|
|
// The credential store reads `runtime.db` only inside DB methods we don't
|
|
// call here (delete is spied on). A throwing getter would still satisfy
|
|
// the type while making accidental DB access loud.
|
|
get db() {
|
|
throw new Error('runtime.db should not be touched in this test');
|
|
},
|
|
getService: () => null,
|
|
getSetting: () => null,
|
|
registerEvent: ((eventName: string, handler: EventHandler) => {
|
|
const list = events.get(eventName) ?? [];
|
|
list.push(handler);
|
|
events.set(eventName, list);
|
|
}) as IAgentRuntime['registerEvent'],
|
|
unregisterEvent: ((eventName: string, handler: EventHandler) => {
|
|
const list = events.get(eventName);
|
|
if (!list) return;
|
|
const idx = list.indexOf(handler);
|
|
if (idx >= 0) list.splice(idx, 1);
|
|
if (list.length === 0) events.delete(eventName);
|
|
}) as IAgentRuntime['unregisterEvent'],
|
|
};
|
|
const runtime = runtimeDouble as IAgentRuntime;
|
|
|
|
return { runtime, bus };
|
|
}
|
|
|
|
describe('WorkflowCredentialStore event-driven eviction', () => {
|
|
test('start() subscribes and emit invokes delete() for every credType', async () => {
|
|
const { runtime, bus } = createEventBusRuntime('agent-evict-1');
|
|
const deleteSpy = mock<DeleteMethod>(() => Promise.resolve());
|
|
// Spy on the prototype so the subscriber's `this.delete(...)` call routes
|
|
// to the mock without touching the real DB-backed implementation.
|
|
const originalDelete = WorkflowCredentialStore.prototype.delete;
|
|
WorkflowCredentialStore.prototype.delete = deleteSpy;
|
|
|
|
try {
|
|
const store = await WorkflowCredentialStore.start(runtime);
|
|
expect(bus.handlerCount(CONNECTOR_DISCONNECTED_EVENT)).toBe(1);
|
|
|
|
await bus.emit(CONNECTOR_DISCONNECTED_EVENT, {
|
|
userId: 'agent-evict-1',
|
|
credTypes: ['gmailOAuth2', 'gmailOAuth2Api'],
|
|
connectorName: 'gmail',
|
|
});
|
|
|
|
expect(deleteSpy).toHaveBeenCalledTimes(2);
|
|
expect(deleteSpy).toHaveBeenCalledWith('agent-evict-1', 'gmailOAuth2');
|
|
expect(deleteSpy).toHaveBeenCalledWith('agent-evict-1', 'gmailOAuth2Api');
|
|
|
|
await store.stop();
|
|
} finally {
|
|
WorkflowCredentialStore.prototype.delete = originalDelete;
|
|
}
|
|
});
|
|
|
|
test('empty credTypes payload skips deletion', async () => {
|
|
const { runtime, bus } = createEventBusRuntime('agent-evict-2');
|
|
const deleteSpy = mock<DeleteMethod>(() => Promise.resolve());
|
|
const originalDelete = WorkflowCredentialStore.prototype.delete;
|
|
WorkflowCredentialStore.prototype.delete = deleteSpy;
|
|
|
|
try {
|
|
const store = await WorkflowCredentialStore.start(runtime);
|
|
await bus.emit(CONNECTOR_DISCONNECTED_EVENT, {
|
|
userId: 'agent-evict-2',
|
|
credTypes: [],
|
|
connectorName: 'unmapped-connector',
|
|
});
|
|
expect(deleteSpy).not.toHaveBeenCalled();
|
|
await store.stop();
|
|
} finally {
|
|
WorkflowCredentialStore.prototype.delete = originalDelete;
|
|
}
|
|
});
|
|
|
|
test('stop() unsubscribes — subsequent emits do not invoke delete', async () => {
|
|
const { runtime, bus } = createEventBusRuntime('agent-evict-3');
|
|
const deleteSpy = mock<DeleteMethod>(() => Promise.resolve());
|
|
const originalDelete = WorkflowCredentialStore.prototype.delete;
|
|
WorkflowCredentialStore.prototype.delete = deleteSpy;
|
|
|
|
try {
|
|
const store = await WorkflowCredentialStore.start(runtime);
|
|
expect(bus.handlerCount(CONNECTOR_DISCONNECTED_EVENT)).toBe(1);
|
|
|
|
await store.stop();
|
|
expect(bus.handlerCount(CONNECTOR_DISCONNECTED_EVENT)).toBe(0);
|
|
|
|
await bus.emit(CONNECTOR_DISCONNECTED_EVENT, {
|
|
userId: 'agent-evict-3',
|
|
credTypes: ['slackApi'],
|
|
connectorName: 'slack',
|
|
});
|
|
expect(deleteSpy).not.toHaveBeenCalled();
|
|
} finally {
|
|
WorkflowCredentialStore.prototype.delete = originalDelete;
|
|
}
|
|
});
|
|
|
|
test('a delete failure for one credType does not block sibling deletes', async () => {
|
|
const { runtime, bus } = createEventBusRuntime('agent-evict-4');
|
|
const calls: Array<[string, string]> = [];
|
|
const deleteSpy = mock<DeleteMethod>(async (userId: string, credType: string) => {
|
|
calls.push([userId, credType]);
|
|
if (credType === 'discordApi') {
|
|
throw new Error('boom');
|
|
}
|
|
});
|
|
const originalDelete = WorkflowCredentialStore.prototype.delete;
|
|
WorkflowCredentialStore.prototype.delete = deleteSpy;
|
|
|
|
try {
|
|
const store = await WorkflowCredentialStore.start(runtime);
|
|
await bus.emit(CONNECTOR_DISCONNECTED_EVENT, {
|
|
userId: 'agent-evict-4',
|
|
credTypes: ['discordApi', 'discordBotApi', 'discordWebhookApi'],
|
|
connectorName: 'discord',
|
|
});
|
|
|
|
const seen = new Set(calls.map(([, credType]) => credType));
|
|
expect(seen.has('discordApi')).toBe(true);
|
|
expect(seen.has('discordBotApi')).toBe(true);
|
|
expect(seen.has('discordWebhookApi')).toBe(true);
|
|
|
|
await store.stop();
|
|
} finally {
|
|
WorkflowCredentialStore.prototype.delete = originalDelete;
|
|
}
|
|
});
|
|
});
|