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.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
test(platform): cover scheduler job-id sync and net staked conviction
nirholas3119e179129f
diff --git a/tests/cron-scheduler-sync.test.js b/tests/cron-scheduler-sync.test.jsnew file mode 100644index 000000000..0077ede1c--- /dev/null+++ b/tests/cron-scheduler-sync.test.js@@ -0,0 +1,79 @@+// Tests for the Cloud Scheduler sync script's pure decision logic+// (scripts/create-gcp-scheduler.mjs).+//+// Two things here can take the whole cron fleet down without leaving a trace in+// any config file, which is why they are pinned:+//+// 1. The run-state decision. A bare sync must NOT touch whether existing jobs+// are running. When it paused every job by default, following the+// `scripts/gcp-triage.mjs` remedy for one drifted cron stopped all of them+// (payouts, buybacks, treasury, changelog push, dead-man switch) while+// vercel.json still read as perfectly correct.+// 2. The job-id derivation, which is the only link between a declared cron and+// its live job. `scripts/check-cron-drift.mjs` imports this exact function;+// a second copy drifting by one character makes every job read as MISSING.++import { describe, it, expect } from 'vitest';+import { readFileSync } from 'node:fs';+import { jobId, runStateAction, cronSecretFromArgs } from '../scripts/create-gcp-scheduler.mjs';++describe('runStateAction', () => {+ it('leaves run state alone for a bare config sync', () => {+ expect(runStateAction([])).toBe(null);+ expect(runStateAction(['--env-file', '/tmp/prod.env'])).toBe(null);+ });++ it('pauses the fleet only when asked explicitly', () => {+ expect(runStateAction(['--pause'])).toBe('pause');+ });++ it('resumes the fleet only when asked explicitly', () => {+ expect(runStateAction(['--resume'])).toBe('resume');+ });++ it('refuses both levers at once rather than guessing an order', () => {+ expect(() => runStateAction(['--pause', '--resume'])).toThrow(/mutually exclusive/);+ });+});++describe('jobId', () => {+ it('matches the ids Cloud Scheduler already holds', () => {+ expect(jobId('/api/cron/economy-tick')).toBe('cron-api-cron-economy-tick');+ expect(jobId('/api/llm/health')).toBe('cron-api-llm-health');+ });++ it('collapses every run of non-alphanumerics to a single hyphen', () => {+ expect(jobId('/api/cron/a__b.c')).toBe('cron-api-cron-a-b-c');+ });++ it('produces one unique, id-legal job per declared cron', () => {+ const { crons } = JSON.parse(readFileSync(new URL('../vercel.json', import.meta.url), 'utf8'));+ expect(crons.length).toBeGreaterThan(0);+ const ids = crons.map((c) => jobId(c.path));+ expect(new Set(ids).size).toBe(ids.length);+ for (const id of ids) {+ expect(id).toMatch(/^[a-zA-Z0-9_-]+$/);+ expect(id.length).toBeLessThanOrEqual(500);+ }+ });+});++describe('cronSecretFromArgs', () => {+ it('reads CRON_SECRET out of the named env file', () => {+ const read = () => 'OTHER=1\nCRON_SECRET="s3cr3t"\nMORE=2\n';+ expect(cronSecretFromArgs(['--env-file', 'prod.env'], read)).toBe('s3cr3t');+ });++ it('accepts an unquoted value', () => {+ expect(cronSecretFromArgs(['--env-file', 'prod.env'], () => 'CRON_SECRET=plain\n')).toBe('plain');+ });++ it('returns null when no env file was passed, so process.env can win', () => {+ expect(cronSecretFromArgs([])).toBe(null);+ expect(cronSecretFromArgs(['--env-file'])).toBe(null);+ });++ it('returns null when the file holds no CRON_SECRET line', () => {+ expect(cronSecretFromArgs(['--env-file', 'prod.env'], () => 'DATABASE_URL=x\n')).toBe(null);+ });+});diff --git a/tests/reputation-net-conviction.test.js b/tests/reputation-net-conviction.test.jsnew file mode 100644index 000000000..2af221bff--- /dev/null+++ b/tests/reputation-net-conviction.test.js@@ -0,0 +1,128 @@+// Reputation Staking Market — net conviction (spec §3.3).+//+// `GET /api/agents/solana-reputation` reports what is STILL staked behind an+// agent, not what was ever staked. A settled position's conviction is retired the+// moment the escrow's threews.unstake.v1 memo lands, so these tests pin the one+// rule that keeps the reputation card honest: withdrawn conviction is not+// conviction.+//+// Invariants under test:+// 1. A stake with no settlement counts in full.+// 2. A settled stake stops counting, and stops counting for its staker.+// 3. Retirement is clamped per stake signature, so an over-stated settlement+// can never eat a different staker's conviction or drive the total negative.+// 4. Duplicate settlements naming one stake retire it once, never twice.+// 5. Gross is still reported alongside net, so the history is not erased.+// 6. Lamport values survive past Number.MAX_SAFE_INTEGER.++import { describe, it, expect } from 'vitest';++import { netConviction } from '../api/_lib/reputation-market.js';++const ALICE = 'THREEsyntheticStaker11111111111111111Alice';+const BOB = 'THREEsyntheticStaker11111111111111111111Bob';+const SIG_A = 'a'.repeat(88);+const SIG_B = 'b'.repeat(88);+const SIG_C = 'c'.repeat(88);++const stake = (signature, attester, lamports, score = 4) => ({ signature, attester, lamports, score });+const retire = (stake_signature, principal) => ({ stake_signature, principal });++describe('netConviction', () => {+ it('counts an unsettled stake in full', () => {+ const out = netConviction({ stakes: [stake(SIG_A, ALICE, '2000000')], retirements: [] });+ expect(out.total_lamports).toBe('2000000');+ expect(out.gross_lamports).toBe('2000000');+ expect(out.retired_lamports).toBe('0');+ expect(out.count).toBe(1);+ expect(out.unique_stakers).toBe(1);+ expect(out.top_stakers).toEqual([{ attester: ALICE, lamports: '2000000', score: 4 }]);+ });++ it('retires a settled stake from the total and from its staker', () => {+ const out = netConviction({+ stakes: [stake(SIG_A, ALICE, '2000000'), stake(SIG_B, BOB, '3000000')],+ retirements: [retire(SIG_A, '2000000')],+ });+ expect(out.total_lamports).toBe('3000000');+ expect(out.gross_lamports).toBe('5000000');+ expect(out.retired_lamports).toBe('2000000');+ expect(out.retired_count).toBe(1);+ expect(out.count).toBe(1);+ expect(out.top_stakers).toEqual([{ attester: BOB, lamports: '3000000', score: 4 }]);+ });++ it('reports zero once every position is settled, never a negative', () => {+ const out = netConviction({+ stakes: [stake(SIG_A, ALICE, '2000000')],+ retirements: [retire(SIG_A, '9000000')],+ });+ expect(out.total_lamports).toBe('0');+ expect(out.retired_lamports).toBe('2000000');+ expect(out.count).toBe(0);+ expect(out.unique_stakers).toBe(0);+ expect(out.top_stakers).toEqual([]);+ });++ it('clamps an over-stated settlement to its own stake, leaving others whole', () => {+ const out = netConviction({+ stakes: [stake(SIG_A, ALICE, '1000000'), stake(SIG_B, BOB, '4000000')],+ retirements: [retire(SIG_A, '99000000')],+ });+ expect(out.total_lamports).toBe('4000000');+ expect(out.top_stakers).toEqual([{ attester: BOB, lamports: '4000000', score: 4 }]);+ });++ it('retires a stake once even when two settlements name it', () => {+ const out = netConviction({+ stakes: [stake(SIG_A, ALICE, '5000000')],+ retirements: [retire(SIG_A, '2000000'), retire(SIG_A, '2000000')],+ });+ expect(out.total_lamports).toBe('3000000');+ expect(out.retired_lamports).toBe('2000000');+ expect(out.retired_count).toBe(1);+ });++ it('ignores a settlement naming a stake this agent never received', () => {+ const out = netConviction({+ stakes: [stake(SIG_A, ALICE, '2000000')],+ retirements: [retire(SIG_C, '2000000')],+ });+ expect(out.total_lamports).toBe('2000000');+ expect(out.retired_count).toBe(0);+ });++ it('sums a staker who holds several positions and drops only the settled one', () => {+ const out = netConviction({+ stakes: [stake(SIG_A, ALICE, '1000000', 5), stake(SIG_B, ALICE, '2000000', 3), stake(SIG_C, BOB, '1500000')],+ retirements: [retire(SIG_A, '1000000')],+ });+ expect(out.total_lamports).toBe('3500000');+ expect(out.unique_stakers).toBe(2);+ expect(out.top_stakers).toEqual([+ { attester: ALICE, lamports: '2000000', score: 3 },+ { attester: BOB, lamports: '1500000', score: 4 },+ ]);+ });++ it('carries lamport values past Number.MAX_SAFE_INTEGER without loss', () => {+ const out = netConviction({+ stakes: [stake(SIG_A, ALICE, '9007199254740993')],+ retirements: [retire(SIG_A, '1')],+ });+ expect(out.total_lamports).toBe('9007199254740992');+ });++ it('answers an empty market with zeroes rather than throwing', () => {+ const out = netConviction();+ expect(out).toEqual({+ total_lamports: '0',+ count: 0,+ unique_stakers: 0,+ gross_lamports: '0',+ retired_lamports: '0',+ retired_count: 0,+ top_stakers: [],+ });+ });+});