Skip to content

bayological/pact-test

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pact Test Harness

A TypeScript test harness for Pact. Simulates multi-agent interaction with file-based messaging and storage.

Quick Start

npm install
npm run setup

Then open three terminals:

# Terminal 1
npm run client

# Terminal 2
npm run provider

# Terminal 3
npm run resolver

Architecture

┌─────────┐     file msgs     ┌──────────┐
│  Client  │◄────────────────►│ Provider  │
│  (CLI)   │                   │  (CLI)    │
└────┬─────┘                   └─────┬─────┘
     │                               │
     │        ┌──────────┐           │
     └───────►│ Resolver  │◄──────────┘
              │  (CLI)    │
              └─────┬─────┘
                    │
              ┌─────▼─────┐
              │  Shared    │
              │  Storage   │
              │ (pacts +   │
              │  evidence) │
              └────────────┘

Directory Structure

pact-test/
├── package.json
├── tsconfig.json
├── src/
│   ├── identity/
│   │   └── wallet.ts         # Keypair generation, signing
│   ├── messaging/
│   │   └── inbox.ts          # File-based message send/receive
│   ├── storage/
│   │   └── store.ts          # Save/load pacts and evidence
│   ├── pact/
│   │   ├── types.ts          # Pact TypeScript types
│   │   └── create.ts         # Create, sign, verify pacts
│   ├── resolver/
│   │   └── resolve.ts        # Resolver logic and prompt generation
│   ├── setup.ts              # Setup script (creates wallets + dirs)
│   └── cli.ts                # Interactive CLI for agents
├── agents/                   # Created by setup script
│   ├── client/
│   │   ├── wallet.json
│   │   └── inbox/
│   ├── provider/
│   │   ├── wallet.json
│   │   └── inbox/
│   └── resolver/
│       ├── wallet.json
│       └── inbox/
└── shared/                   # Created by setup script
    ├── pacts/
    └── evidence/

Components

Identity (wallet.ts)

Ethereum wallet-based identity using ethers.js v6. Generates keypairs, signs messages, and verifies signatures.

Messaging (inbox.ts)

File-based message passing between agents. Messages are JSON files stored in each agent's inbox directory with timestamp-based filenames.

Storage (store.ts)

Filesystem-based storage for pacts and evidence. Pacts are stored as JSON files; evidence as arbitrary files with SHA256 hashes.

Pact (create.ts + types.ts)

Pact lifecycle management: creation, signing, state transitions. A pact moves through states: proposed -> active -> disputed/resolved.

Resolver (resolve.ts)

Resolution logic including a simple automated resolver for testing and a prompt generator for AI-based resolution.

Test Flow Walkthrough

1. Client creates a pact

npm run client
> [3] Create new pact
> Provider address: 0x... (from provider's wallet)
> Description: Design a logo
> Acceptance criteria: Delivers 3 concepts, Includes source files
> Escrow amount: 500
Pact created: pact_abc123

2. Provider signs

npm run provider
> [2] View messages
(sees draft_pact notification with pact ID)
> [3] Sign a pact
> Pact ID: pact_abc123
Signed!

3. Client signs (pact becomes active)

npm run client
> [4] Sign a pact
> Pact ID: pact_abc123
Pact is now ACTIVE

4. Provider submits evidence

npm run provider
> [4] Submit evidence
> Pact ID: pact_abc123
> Filename: deliverable.md
> Content: Here are the 3 logo concepts with source files...
> END
Evidence saved

5. Resolver evaluates

npm run resolver
> [3] Resolve a pact
> Pact ID: pact_abc123
Outcome: fulfilled
> Apply this resolution? y
Pact resolved!

Pact States

  • proposed - Created but not yet signed by all parties
  • active - All parties have signed
  • disputed - A party has raised a dispute
  • resolved - Resolver has issued a resolution

CLI Commands

Option Client Provider Resolver
1 View my pacts View my pacts View my pacts
2 View messages View messages View messages
3 Create new pact Sign a pact Resolve a pact
4 Sign a pact Submit evidence Generate resolver prompt
5 View pact details View pact details View pact details
6 Send message Send message Send message
q Quit Quit Quit

Next Steps

  • XMTP Integration - Replace file-based messaging with XMTP for real p2p messaging
  • IPFS Storage - Store pacts and evidence on IPFS instead of local filesystem
  • Claude Skills - Use Claude as the AI resolver via skills/tools
  • On-chain Settlement - Smart contract for escrow and resolution enforcement

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published