Bonded-escrow marketplace for prompt → response between buyers and
local-LLM suppliers, settling on Vector (UTxO) via Aiken Plutus V3
validators. Lifecycle PostEscrow → Claim → Submit → Accept proven on
Vector testnet 2026-05-06; AcceptEscrow tx 125e3cfe…7dc100d distributes
payment + bonds per the validator's distribution rule.
Workspace layout (pnpm + TypeScript):
contracts/marketplace/ Aiken validators (advert + escrow) + plutus.json
packages/shared/ Tx-builders (lucid-evolution), CBOR codecs,
chain providers (mock / read-only / live Ogmios)
supplier/ OpenAI-compatible HTTP node (Ollama by default;
vLLM / llama.cpp / OpenRouter / OpenClaw all
swap-in via OLLAMA_URL); 202+poll chat handler
buyer/ Express + React SPA; server-side runs the full
chain lifecycle via /v1/submit-prompt and
/v1/accept; SPA never holds the buyer key
indexer/ Chain-follower (extends apex-dashboard pattern),
SSE event stream + REST queries
indexer-ui/ Operator dashboard (events + suppliers + escrow
lookup)
tests/ 1098 vitest unit + integration tests (10 skipped
under M1-F-D-defer for UPLC test plumbing)
deploy/testnet/ Per-service docker-compose for the Hetzner stack
docs/EXECUTIVE_SUMMARY.* Marp deck (PDF + PPTX) — 11 slides, mermaid
diagrams pre-rendered for portable export
docs/CLOUDFLARE_WAF_BYPASS.md CF Skip-rule runbook for /v1/* paths
docs/ARCHITECTURE.md canonical spec
Live demo (testnet, 2026-05-06):
https://mp-buyers.vector.testnet.apexfusion.org (buyer SPA)
https://mp-suppliers.vector.testnet.apexfusion.org (supplier API)
https://mp-indexer.vector.testnet.apexfusion.org (indexer + UI)
88 lines
3.3 KiB
TypeScript
88 lines
3.3 KiB
TypeScript
/**
|
|
* buyer-server-config.test.ts — RED phase (M1-E)
|
|
*
|
|
* Category H: Server / config (~5 tests)
|
|
*
|
|
* All tests FAIL until M1-E-green.
|
|
*/
|
|
|
|
import { describe, it, expect } from "vitest";
|
|
import { join } from "path";
|
|
import { loadConfig } from "../../buyer/src/config.js";
|
|
import { createApp } from "../../buyer/src/server.js";
|
|
|
|
// ─── loadConfig tests ─────────────────────────────────────────────────────────
|
|
|
|
describe("loadConfig(env)", () => {
|
|
const VALID_ENV = {
|
|
BUYER_PRIV_KEY_HEX: "9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae3942",
|
|
INDEXER_URL: "http://localhost:3001",
|
|
BUYER_PORT: "3002",
|
|
NETWORK_ID: "0",
|
|
};
|
|
|
|
it("returns a BuyerConfig when all required env vars are present", () => {
|
|
const config = loadConfig(VALID_ENV);
|
|
expect(config.privKeyHex).toBe(VALID_ENV.BUYER_PRIV_KEY_HEX);
|
|
expect(config.indexerUrl).toBe(VALID_ENV.INDEXER_URL);
|
|
expect(config.port).toBe(3002);
|
|
expect(config.networkId).toBe(0);
|
|
});
|
|
|
|
it("throws when BUYER_PRIV_KEY_HEX is missing", () => {
|
|
const env = { ...VALID_ENV };
|
|
delete (env as Record<string, string | undefined>).BUYER_PRIV_KEY_HEX;
|
|
expect(() => loadConfig(env)).toThrow();
|
|
});
|
|
|
|
it("throws when INDEXER_URL is missing", () => {
|
|
const env = { ...VALID_ENV };
|
|
delete (env as Record<string, string | undefined>).INDEXER_URL;
|
|
expect(() => loadConfig(env)).toThrow();
|
|
});
|
|
|
|
it("defaults BUYER_PORT to 3002 when not provided", () => {
|
|
const env = { ...VALID_ENV };
|
|
delete (env as Record<string, string | undefined>).BUYER_PORT;
|
|
const config = loadConfig(env);
|
|
expect(config.port).toBe(3002);
|
|
});
|
|
|
|
it("defaults NETWORK_ID to 0 (testnet) when not provided", () => {
|
|
const env = { ...VALID_ENV };
|
|
delete (env as Record<string, string | undefined>).NETWORK_ID;
|
|
const config = loadConfig(env);
|
|
expect(config.networkId).toBe(0);
|
|
});
|
|
});
|
|
|
|
// ─── createApp tests ──────────────────────────────────────────────────────────
|
|
|
|
describe("createApp(deps)", () => {
|
|
it("GET /healthz returns { ok: true } with status 200", async () => {
|
|
const app = createApp({});
|
|
// Use supertest-style in-process request
|
|
const { default: request } = await import("supertest");
|
|
const res = await request(app).get("/healthz");
|
|
expect(res.status).toBe(200);
|
|
expect(res.body).toMatchObject({ ok: true });
|
|
});
|
|
|
|
it("serves static dist/ directory when distPath exists", async () => {
|
|
// The dist path doesn't exist yet; createApp should mount it without crashing.
|
|
// We test that the app at least starts up with the distPath option.
|
|
const app = createApp({ distPath: "/tmp/nonexistent-dist" });
|
|
const { default: request } = await import("supertest");
|
|
// /healthz still works regardless of distPath
|
|
const res = await request(app).get("/healthz");
|
|
expect(res.status).toBe(200);
|
|
});
|
|
|
|
it("returns 404 for unknown routes when dist/ is not set", async () => {
|
|
const app = createApp({});
|
|
const { default: request } = await import("supertest");
|
|
const res = await request(app).get("/this-page-does-not-exist");
|
|
expect(res.status).toBe(404);
|
|
});
|
|
});
|