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)
112 lines
3.7 KiB
TypeScript
112 lines
3.7 KiB
TypeScript
// @vitest-environment happy-dom
|
|
/**
|
|
* tests/unit/indexer-ui-capabilities-panel.test.tsx — GREEN (M1-F-5)
|
|
*
|
|
* Category D: CapabilitiesPanel component (~5 tests)
|
|
*
|
|
* Mock strategy: vi.mock at module level; per-test control via usePollingMock.mockReturnValue().
|
|
*/
|
|
|
|
import { describe, it, expect, vi, afterEach } from "vitest";
|
|
import { render, screen, cleanup, waitFor } from "@testing-library/react";
|
|
|
|
// Module-level mock — must be hoisted above imports.
|
|
vi.mock("../../indexer-ui/src/hooks/usePolling.js", () => ({
|
|
usePolling: vi.fn(() => ({ data: null, error: null, loading: true })),
|
|
}));
|
|
|
|
import CapabilitiesPanel from "../../indexer-ui/src/components/CapabilitiesPanel.js";
|
|
|
|
const { usePolling: usePollingMock } = await import("../../indexer-ui/src/hooks/usePolling.js");
|
|
|
|
afterEach(() => {
|
|
cleanup();
|
|
vi.clearAllMocks();
|
|
(usePollingMock as ReturnType<typeof vi.fn>).mockReturnValue({
|
|
data: null,
|
|
error: null,
|
|
loading: true,
|
|
});
|
|
});
|
|
|
|
const SAMPLE_CAPABILITIES = [
|
|
{ capability_id: "llm.text.generate.v1", supplier_count: 3 },
|
|
{ capability_id: "speech.transcribe.v1", supplier_count: 1 },
|
|
];
|
|
|
|
// ─── Render contract ─────────────────────────────────────────────────────────
|
|
|
|
describe("CapabilitiesPanel — render", () => {
|
|
it("renders one capability-card per capability entry", async () => {
|
|
(usePollingMock as ReturnType<typeof vi.fn>).mockReturnValue({
|
|
data: SAMPLE_CAPABILITIES,
|
|
error: null,
|
|
loading: false,
|
|
});
|
|
render(<CapabilitiesPanel />);
|
|
await waitFor(() => {
|
|
const cards = document.querySelectorAll("[data-testid='capability-card']");
|
|
expect(cards.length).toBe(SAMPLE_CAPABILITIES.length);
|
|
});
|
|
});
|
|
|
|
it("renders zero cards when capabilities list is empty", async () => {
|
|
(usePollingMock as ReturnType<typeof vi.fn>).mockReturnValue({
|
|
data: [],
|
|
error: null,
|
|
loading: false,
|
|
});
|
|
render(<CapabilitiesPanel />);
|
|
await waitFor(() => {
|
|
const cards = document.querySelectorAll("[data-testid='capability-card']");
|
|
expect(cards.length).toBe(0);
|
|
});
|
|
});
|
|
|
|
it("each card shows capability_id text", async () => {
|
|
(usePollingMock as ReturnType<typeof vi.fn>).mockReturnValue({
|
|
data: SAMPLE_CAPABILITIES,
|
|
error: null,
|
|
loading: false,
|
|
});
|
|
render(<CapabilitiesPanel />);
|
|
await waitFor(() => {
|
|
expect(screen.getByText(/llm\.text\.generate\.v1/)).toBeTruthy();
|
|
expect(screen.getByText(/speech\.transcribe\.v1/)).toBeTruthy();
|
|
});
|
|
});
|
|
|
|
it("each card shows supplier_count", async () => {
|
|
(usePollingMock as ReturnType<typeof vi.fn>).mockReturnValue({
|
|
data: SAMPLE_CAPABILITIES,
|
|
error: null,
|
|
loading: false,
|
|
});
|
|
render(<CapabilitiesPanel />);
|
|
await waitFor(() => {
|
|
// supplier_count: 3 for llm, 1 for speech
|
|
expect(screen.getByText("3")).toBeTruthy();
|
|
expect(screen.getByText("1")).toBeTruthy();
|
|
});
|
|
});
|
|
});
|
|
|
|
// ─── Polling interval ────────────────────────────────────────────────────────
|
|
|
|
describe("CapabilitiesPanel — polling", () => {
|
|
it("passes intervalMs=30000 to usePolling", async () => {
|
|
(usePollingMock as ReturnType<typeof vi.fn>).mockReturnValue({
|
|
data: [],
|
|
error: null,
|
|
loading: false,
|
|
});
|
|
render(<CapabilitiesPanel />);
|
|
await waitFor(() => {
|
|
expect(usePollingMock).toHaveBeenCalled();
|
|
const callArgs = (usePollingMock as ReturnType<typeof vi.fn>).mock.calls[0];
|
|
// second argument must be 30000
|
|
expect(callArgs[1]).toBe(30_000);
|
|
});
|
|
});
|
|
});
|