Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

test(agenc): drive the lifecycle enrichment directly so the suite actually runs

nirholasf0e2ae46b9f3
diff --git a/api/agenc/[action].js b/api/agenc/[action].js
index c11ef6124..39dcfe60a 100644
--- a/api/agenc/[action].js
+++ b/api/agenc/[action].js
@@ -245,7 +245,7 @@ const LIFECYCLE_EVENT_KINDS = [
{ match: /^(task)?(complete|prove|submit)/i, kinds: ['completed_task', 'settled'] },
];
-async function enrichLifecycleFromProjection(lifecycle, taskPda) {
+export async function enrichLifecycleFromProjection(lifecycle, taskPda) {
if (!lifecycle?.timeline?.length) return;
let rows;
try {
diff --git a/tests/agenc-lifecycle-tx.test.js b/tests/agenc-lifecycle-tx.test.js
index eadb240c0..31383063f 100644
--- a/tests/agenc-lifecycle-tx.test.js
+++ b/tests/agenc-lifecycle-tx.test.js
@@ -18,8 +18,12 @@
* claim can't inherit the first claim's signature;
* • a DB outage degrades to the chain's own timeline: never a fabricated link.
*
- * We drive the REAL wrapped handler and mock only the I/O boundary (DB, rate
- * limiter, on-chain SDK), so the handler's own shaping runs unchanged.
+ * The enrichment is exercised directly rather than through the wrapped handler.
+ * `clientFor()` lazily imports @three-ws/solana-agent, which vitest.config.js
+ * marks external precisely so a suite can load this module without the SDK's
+ * dist/ built, and an external module cannot be mocked. Driving the exported
+ * function keeps the suite pure (DB boundary only, no RPC, no SDK build) and
+ * still runs the real merge rules, which are the whole of the behaviour here.
*/
import { describe, it, expect, vi, beforeEach } from 'vitest';
@@ -34,7 +38,6 @@ const DELIVERABLE = `https://pub-2534e921bf9c4314addcd4d8a6e98b7b.r2.dev/agora/d
const H = vi.hoisted(() => ({
activity: [],
dbThrows: false,
- timeline: [],
}));
vi.mock('../api/_lib/db.js', () => {
@@ -52,65 +55,30 @@ vi.mock('../api/_lib/rate-limit.js', () => ({
}));
vi.mock('@tetsuo-ai/sdk', () => ({
- getTask: async () => ({
- taskId: new Uint8Array(32),
- state: 2,
- creator: CREATOR,
- rewardAmount: '2000000',
- rewardMint: null,
- deadline: 1785990416,
- currentWorkers: 1,
- maxWorkers: 1,
- completedAt: 1785986919,
- constraintHash: null,
- }),
- getTaskLifecycleSummary: async () => ({
- currentState: 2,
- createdAt: 1785986816,
- currentWorkers: 1,
- maxWorkers: 1,
- timeline: H.timeline,
- }),
+ getTask: async () => null,
+ getTaskLifecycleSummary: async () => null,
getTasksByCreator: async () => [],
getAgent: async () => null,
deriveTaskPda: () => ({ toBase58: () => TASK_PDA }),
deriveAgentPda: () => ({ toBase58: () => TASK_PDA }),
}));
-const handler = (await import('../api/agenc/[action].js')).default;
-
-function makeRes() {
- return {
- statusCode: 200,
- headers: {},
- body: undefined,
- ended: false,
- setHeader(k, v) { this.headers[String(k).toLowerCase()] = v; },
- getHeader(k) { return this.headers[String(k).toLowerCase()]; },
- removeHeader(k) { delete this.headers[String(k).toLowerCase()]; },
- end(b) { this.body = b; this.ended = true; },
- get headersSent() { return this.ended; },
- get writableEnded() { return this.ended; },
- };
+const { enrichLifecycleFromProjection } = await import('../api/agenc/[action].js');
+
+/** The shape assembleTask hands the enrichment: the chain's own timeline. */
+function chainLifecycle(timeline) {
+ return { currentState: 2, createdAt: 1785986816, currentWorkers: 1, maxWorkers: 1, timeline };
}
-async function getTask(query = {}) {
- const res = makeRes();
- await handler({
- method: 'GET',
- url: '/api/agenc/get-task',
- headers: { host: 'three.ws' },
- query: { action: 'get-task', taskPda: TASK_PDA, cluster: 'devnet', lifecycle: '1', ...query },
- }, res);
- return { res, json: JSON.parse(res.body) };
+function defaultTimeline() {
+ return [
+ { eventName: 'taskCreated', timestamp: 1785986816, txSignature: null, actor: CREATOR },
+ { eventName: 'taskCompleted', timestamp: 1785986919, txSignature: null, actor: null },
+ ];
}
beforeEach(() => {
H.dbThrows = false;
- H.timeline = [
- { eventName: 'taskCreated', timestamp: 1785986816, txSignature: null, actor: { toBase58: () => CREATOR } },
- { eventName: 'taskCompleted', timestamp: 1785986919, txSignature: null, actor: null },
- ];
H.activity = [
{ kind: 'posted_task', tx_signature: SIG_CREATE, proof_hash: null, deliverable_url: null, created_at: '2026-08-06T03:26:58Z' },
{ kind: 'completed_task', tx_signature: SIG_DONE, proof_hash: PROOF, deliverable_url: DELIVERABLE, created_at: '2026-08-06T03:28:39Z' },
@@ -119,57 +87,62 @@ beforeEach(() => {
describe('get-task lifecycle enrichment', () => {
it('fills the chain\'s null signatures from the journal, matched by event', async () => {
- const { json } = await getTask();
- expect(json.ok).toBe(true);
- const [created, completed] = json.lifecycle.timeline;
+ const lifecycle = chainLifecycle(defaultTimeline());
+ await enrichLifecycleFromProjection(lifecycle, TASK_PDA);
+ const [created, completed] = lifecycle.timeline;
expect(created.txSignature).toBe(SIG_CREATE);
expect(completed.txSignature).toBe(SIG_DONE);
});
it('carries the completion\'s deliverable proof and hoists it for deep links', async () => {
- const { json } = await getTask();
- const completed = json.lifecycle.timeline[1];
+ const lifecycle = chainLifecycle(defaultTimeline());
+ await enrichLifecycleFromProjection(lifecycle, TASK_PDA);
+ const completed = lifecycle.timeline[1];
expect(completed.proofHash).toBe(PROOF);
expect(completed.deliverableUrl).toBe(DELIVERABLE);
// Hoisted: a client holding only the PDA can verify without walking events.
- expect(json.lifecycle.proofHash).toBe(PROOF);
- expect(json.lifecycle.deliverableUrl).toBe(DELIVERABLE);
+ expect(lifecycle.proofHash).toBe(PROOF);
+ expect(lifecycle.deliverableUrl).toBe(DELIVERABLE);
});
it('never overwrites a signature the chain itself reported', async () => {
const onChainSig = '5'.repeat(64);
- H.timeline[0].txSignature = onChainSig;
- const { json } = await getTask();
- expect(json.lifecycle.timeline[0].txSignature).toBe(onChainSig);
+ const timeline = defaultTimeline();
+ timeline[0].txSignature = onChainSig;
+ const lifecycle = chainLifecycle(timeline);
+ await enrichLifecycleFromProjection(lifecycle, TASK_PDA);
+ expect(lifecycle.timeline[0].txSignature).toBe(onChainSig);
});
it('consumes each journal row once so a second claim can\'t reuse the first\'s tx', async () => {
const claimA = 'A'.repeat(64);
const claimB = 'B'.repeat(64);
- H.timeline = [
- { eventName: 'taskClaimed', timestamp: 1, txSignature: null, actor: null },
- { eventName: 'taskClaimed', timestamp: 2, txSignature: null, actor: null },
- ];
H.activity = [
{ kind: 'claimed_task', tx_signature: claimA, proof_hash: null, deliverable_url: null, created_at: '2026-08-06T03:27:00Z' },
{ kind: 'claimed_task', tx_signature: claimB, proof_hash: null, deliverable_url: null, created_at: '2026-08-06T03:27:30Z' },
];
- const { json } = await getTask();
- expect(json.lifecycle.timeline.map((e) => e.txSignature)).toEqual([claimA, claimB]);
+ const lifecycle = chainLifecycle([
+ { eventName: 'taskClaimed', timestamp: 1, txSignature: null, actor: null },
+ { eventName: 'taskClaimed', timestamp: 2, txSignature: null, actor: null },
+ ]);
+ await enrichLifecycleFromProjection(lifecycle, TASK_PDA);
+ expect(lifecycle.timeline.map((e) => e.txSignature)).toEqual([claimA, claimB]);
});
it('invents nothing when the journal has no row for an event', async () => {
H.activity = [];
- const { json } = await getTask();
- expect(json.lifecycle.timeline.every((e) => e.txSignature === null)).toBe(true);
- expect(json.lifecycle.proofHash).toBeUndefined();
+ const lifecycle = chainLifecycle(defaultTimeline());
+ await enrichLifecycleFromProjection(lifecycle, TASK_PDA);
+ expect(lifecycle.timeline.every((e) => e.txSignature === null)).toBe(true);
+ expect(lifecycle.proofHash).toBeUndefined();
});
it('degrades to the chain\'s own timeline when the DB is unreachable', async () => {
H.dbThrows = true;
- const { res, json } = await getTask();
- expect(res.statusCode).toBe(200);
- expect(json.lifecycle.timeline).toHaveLength(2);
- expect(json.lifecycle.timeline.every((e) => e.txSignature === null)).toBe(true);
+ const lifecycle = chainLifecycle(defaultTimeline());
+ await expect(enrichLifecycleFromProjection(lifecycle, TASK_PDA)).resolves.toBeUndefined();
+ expect(lifecycle.timeline).toHaveLength(2);
+ expect(lifecycle.timeline.every((e) => e.txSignature === null)).toBe(true);
+ expect(lifecycle.proofHash).toBeUndefined();
});
});