M1-F: end-to-end LLM marketplace lifecycle on Vector testnet
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)
This commit is contained in:
121
tests/unit/indexer-boot.test.ts
Normal file
121
tests/unit/indexer-boot.test.ts
Normal file
@@ -0,0 +1,121 @@
|
||||
/**
|
||||
* tests/unit/indexer-boot.test.ts — boot / integration smoke tests (Category G)
|
||||
*
|
||||
* Tests createApp wiring and worker/shutdown behaviour.
|
||||
* All tests RED — createApp throws "not implemented — M1-D-green".
|
||||
* Tests call createApp() directly; the stub throws, causing Vitest to mark them FAIL.
|
||||
*/
|
||||
|
||||
import { describe, it, expect, vi } from "vitest";
|
||||
import { EventEmitter } from "events";
|
||||
|
||||
import { createApp } from "../../indexer/src/server.js";
|
||||
import type { IndexerDeps } from "../../indexer/src/server.js";
|
||||
|
||||
function makeMockDeps(): IndexerDeps {
|
||||
const workerEmitter = new EventEmitter();
|
||||
const cache = {
|
||||
listActiveAdvertisements: vi.fn(() => []),
|
||||
getAdvertisementByRef: vi.fn(() => null),
|
||||
getEscrowByRef: vi.fn(() => null),
|
||||
listEscrowsByBuyer: vi.fn(() => []),
|
||||
listEscrowsBySupplier: vi.fn(() => []),
|
||||
getSupplierStatus: vi.fn(() => null),
|
||||
listEventsAfterSlot: vi.fn(() => []),
|
||||
dbSizeBytes: vi.fn(() => 4096),
|
||||
close: vi.fn(),
|
||||
} as unknown as IndexerDeps["cache"];
|
||||
|
||||
const worker = {
|
||||
getCurrentSlot: vi.fn(() => 0),
|
||||
getTipSlot: vi.fn(() => 0),
|
||||
start: vi.fn(),
|
||||
stop: vi.fn(),
|
||||
on: workerEmitter.on.bind(workerEmitter),
|
||||
emit: workerEmitter.emit.bind(workerEmitter),
|
||||
off: workerEmitter.off.bind(workerEmitter),
|
||||
listenerCount: workerEmitter.listenerCount.bind(workerEmitter),
|
||||
} as unknown as IndexerDeps["worker"];
|
||||
|
||||
return { cache, worker };
|
||||
}
|
||||
|
||||
// ─── Route wiring ─────────────────────────────────────────────────────────────
|
||||
|
||||
describe("createApp — route wiring", () => {
|
||||
it("createApp returns an Express Application instance (not undefined)", () => {
|
||||
const app = createApp(makeMockDeps());
|
||||
// An Express Application should be a function
|
||||
expect(typeof app).toBe("function");
|
||||
});
|
||||
|
||||
it("createApp does not throw when called with valid deps", () => {
|
||||
expect(() => createApp(makeMockDeps())).not.toThrow();
|
||||
});
|
||||
|
||||
it("createApp accepts a second call with fresh deps (no singleton state)", () => {
|
||||
const app1 = createApp(makeMockDeps());
|
||||
const app2 = createApp(makeMockDeps());
|
||||
expect(app1).not.toBe(app2);
|
||||
});
|
||||
|
||||
it("worker.on is called at least once during createApp (event wiring)", () => {
|
||||
const deps = makeMockDeps();
|
||||
const onSpy = vi.spyOn(deps.worker, "on");
|
||||
createApp(deps);
|
||||
expect(onSpy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("createApp wires chain-event listener on worker", () => {
|
||||
const deps = makeMockDeps();
|
||||
createApp(deps);
|
||||
// After wiring, the EventEmitter should have at least one listener for chain-event
|
||||
const emitter = deps.worker as unknown as EventEmitter;
|
||||
expect(emitter.listenerCount("chain-event")).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
|
||||
// ─── Worker event listener wiring ────────────────────────────────────────────
|
||||
|
||||
describe("Worker + SSE — event listener wiring", () => {
|
||||
it("worker.on('chain-event') has at least one listener after createApp", () => {
|
||||
const deps = makeMockDeps();
|
||||
createApp(deps);
|
||||
const emitter = deps.worker as unknown as EventEmitter;
|
||||
expect(emitter.listenerCount("chain-event")).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it("worker.on('sync-progress') listener is wired by createApp", () => {
|
||||
const deps = makeMockDeps();
|
||||
createApp(deps);
|
||||
const emitter = deps.worker as unknown as EventEmitter;
|
||||
expect(emitter.listenerCount("sync-progress")).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
|
||||
// ─── Graceful shutdown ────────────────────────────────────────────────────────
|
||||
|
||||
describe("Graceful shutdown", () => {
|
||||
it("worker.stop() method exists and is callable (interface contract)", () => {
|
||||
const deps = makeMockDeps();
|
||||
// This doesn't need createApp — just checks the interface contract
|
||||
expect(typeof deps.worker.stop).toBe("function");
|
||||
expect(() => deps.worker.stop()).not.toThrow();
|
||||
});
|
||||
|
||||
it("cache.close() method exists and is callable (interface contract)", () => {
|
||||
const deps = makeMockDeps();
|
||||
expect(typeof deps.cache.close).toBe("function");
|
||||
expect(() => deps.cache.close()).not.toThrow();
|
||||
});
|
||||
|
||||
it("createApp does not call worker.stop() or cache.close() on construction", () => {
|
||||
const deps = makeMockDeps();
|
||||
const stopSpy = vi.spyOn(deps.worker, "stop");
|
||||
const closeSpy = vi.spyOn(deps.cache, "close");
|
||||
createApp(deps);
|
||||
// Shutdown must NOT be triggered just by constructing the app
|
||||
expect(stopSpy).not.toHaveBeenCalled();
|
||||
expect(closeSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user