Replace the design-note docs (p1–p7) with the implemented "make it real" phase docs (p8–p10) and wire production-grade, env-gated real integrations: - p8 Casper Testnet: byte-exact deploys + WASM install via casper-js-sdk; live node reads (node.testnet.casper.network); CRED402_CHAIN=sim|testnet transport. - p9 x402 + data + MCP: real EIP-712 typed-data digests (@casper-ecosystem/ casper-eip-712); casper-x402 facilitator client (x402 V2); live Open-Meteo GHI; official @modelcontextprotocol/sdk server; casper-sidecar SSE event feed. - p10 RealFi + cross-chain: real Stripe test-mode webhooks (HMAC-verified) and Plaid sandbox → privacy-preserving on-chain envelopes; Base Sepolia EVM deploy (Foundry); reachable via /api/realfi/* and /api/x402/facilitator routes. - Sign-in with Casper Wallet: real extension provider + challenge/ed25519/session flow (/v1/auth/wallet/*), console connect + sign-in button. - Branding: Cred402 logo mark, favicon, OG image; Vercel config for the console. All env-gated with sim/free-API fallbacks; full suite green, all toolchains (TS/Rust/Go/Solidity) build. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
46 lines
1.7 KiB
TypeScript
46 lines
1.7 KiB
TypeScript
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
import { Ledger } from "../lib/ledger/index.js";
|
|
import { buildAgentHealthBadge } from "../lib/services/agent_health.js";
|
|
|
|
function reg(l: Ledger, id: string, rep: number) {
|
|
l.agents.register_agent({ agent_id: id, owner_public_key: "01", agent_public_key: "01", service_type: "monitoring" });
|
|
l.agents.seed_profile(id, { reputation_score: rep });
|
|
}
|
|
|
|
test("health: a clean high-reputation agent is green", () => {
|
|
const l = new Ledger();
|
|
reg(l, "Healthy", 90);
|
|
const b = buildAgentHealthBadge(l, "Healthy");
|
|
assert.ok(!("error" in b));
|
|
if ("error" in b) return;
|
|
assert.equal(b.status, "green");
|
|
assert.ok(b.score >= 80);
|
|
assert.ok(b.factors.every((f) => f.status === "green"));
|
|
});
|
|
|
|
test("health: an open dispute forces red (worst-of)", () => {
|
|
const l = new Ledger();
|
|
reg(l, "Disputed", 90);
|
|
l.disputes.open({ dispute_type: "bad_evidence", complainant: "W", respondent_agent: "Disputed", note: "x", evidence_hash: "0x1" });
|
|
const b = buildAgentHealthBadge(l, "Disputed");
|
|
if ("error" in b) return assert.fail("expected a badge");
|
|
assert.equal(b.status, "red"); // even with high reputation, an open dispute is red
|
|
const disputes = b.factors.find((f) => f.label === "disputes")!;
|
|
assert.equal(disputes.status, "red");
|
|
});
|
|
|
|
test("health: a mid-reputation agent is amber", () => {
|
|
const l = new Ledger();
|
|
reg(l, "Mid", 55);
|
|
const b = buildAgentHealthBadge(l, "Mid");
|
|
if ("error" in b) return assert.fail("expected a badge");
|
|
assert.equal(b.status, "amber");
|
|
});
|
|
|
|
test("health: unknown agent → error", () => {
|
|
const l = new Ledger();
|
|
assert.ok("error" in buildAgentHealthBadge(l, "Ghost"));
|
|
});
|