Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
roots: ['<rootDir>/src'],
transform: {
'^.+\\.tsx?$': 'ts-jest',
},
testRegex: '(/__tests__/.*|(\\.|/)(test|spec))\\.tsx?$',
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
collectCoverage: true,
coverageReporters: ['text', 'lcov', 'json-summary'],
coverageThreshold: {
global: {
branches: 80,
functions: 80,
lines: 80,
statements: 80
}
},
collectCoverageFrom: [
'src/**/*.{ts,tsx}',
'!src/**/*.d.ts',
'!src/**/*.interface.ts',
'!src/**/*.test.ts'
]
};
15 changes: 15 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "multi-agent-chat-platform",
"version": "0.1.0",
"description": "Multi-agent interactive chat platform",
"scripts": {
"test": "jest",
"test:coverage": "jest --coverage"
},
"devDependencies": {
"@types/jest": "^27.5.0",
"jest": "^27.5.1",
"ts-jest": "^27.1.4",
"typescript": "^4.6.4"
}
}
123 changes: 123 additions & 0 deletions src/docs/component-interface-spec.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# Multi-Agent Chat Platform: Component Interface Specification

## Overview
This document provides a comprehensive specification for component interfaces, public methods, and testing strategies.

## 1. Personality Data Manager Interface

### Public Methods
- `loadProfile(id: string)`: Retrieve a personality profile
- `saveProfile(profile: PersonalityProfile)`: Save or update a profile
- `validateProfile(profile: PersonalityProfile)`: Validate profile schema
- `listProfiles()`: Retrieve all available profiles
- `deleteProfile(id: string)`: Remove a profile

### Input/Output JSON Schemas

#### Profile Load Request Schema
```json
{
"type": "object",
"properties": {
"id": {
"type": "string",
"description": "Unique identifier for the personality profile"
}
},
"required": ["id"]
}
```

#### Profile Load Response Schema
```json
{
"type": "object",
"properties": {
"id": {"type": "string"},
"name": {"type": "string"},
"tone": {"type": "string"},
"samplePrompts": {
"type": "array",
"items": {"type": "string"}
},
"metadata": {"type": "object"}
},
"required": ["id", "name", "tone"]
}
```

### Error Handling Scenarios
1. Profile Not Found
- Return `null` or throw `ProfileNotFoundException`
2. Invalid Profile Schema
- Return detailed validation errors
3. Duplicate Profile Creation
- Prevent duplicate entries, return error

### Unit Test Scenarios
1. Profile Loading
- Successfully load existing profile
- Handle non-existent profile
- Verify returned profile matches schema

2. Profile Validation
- Validate complete profile
- Reject profiles with missing required fields
- Check metadata optional field handling

3. Profile Saving
- Save new profile successfully
- Update existing profile
- Prevent duplicate profile creation

4. Error Scenarios
- Handle invalid input types
- Test boundary conditions
- Validate error message specificity

## 2. Chatbot Engine Adapter Interface

### Public Methods
- `generateResponse(profile: PersonalityProfile, context: ConversationContext)`: Generate agent response
- `estimateTokenUsage(prompt: string)`: Calculate token consumption
- `validatePrompt(prompt: string)`: Ensure prompt meets requirements

### Test Coverage Goals
- Happy path: 100% coverage
- Error paths: Comprehensive scenarios
- Edge cases: Unexpected inputs

## 3. Conversation Orchestrator Interface

### Public Methods
- `initializeConversation(agents: string[])`: Start multi-agent dialogue
- `processUserMessage(message: string)`: Route and generate responses
- `getConversationHistory(sessionId: string)`: Retrieve dialogue context

### Key Testing Focus Areas
- Message routing logic
- Agent interaction sequences
- State management
- Error resilience

## Testing Coverage Recommendations

### Quantitative Coverage Goals
- Unit Tests: ≥80% code coverage
- Integration Tests: Key interaction paths
- Error Handling: 90% scenario coverage

### Coverage Measurement
- Line Coverage: ≥80%
- Branch Coverage: ≥75%
- Function Coverage: ≥80%

### Measurement Tools
- Jest for JavaScript/TypeScript
- Istanbul for code coverage reporting
- Continuous Integration hooks

### Reporting Requirements
- Detailed coverage reports
- Visualization of untested code paths
- Recommendations for additional test scenarios
109 changes: 109 additions & 0 deletions src/interfaces/personality-data-manager.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/**
* Custom error classes for more specific error handling
*/
export class ProfileNotFoundException extends Error {
constructor(message: string) {
super(message);
this.name = 'ProfileNotFoundException';
}
}

export class InvalidProfileException extends Error {
public validationErrors: ValidationError[];

constructor(message: string, errors: ValidationError[]) {
super(message);
this.name = 'InvalidProfileException';
this.validationErrors = errors;
}
}

/**
* Comprehensive interface for Personality Data Manager
*/
export interface PersonalityDataManagerInterface {
/**
* Load a personality profile by its unique identifier
* @param id - Unique identifier for the personality profile
* @throws {ProfileNotFoundException} If profile with given ID does not exist
*/
loadProfile(id: string): Promise<PersonalityProfile>;

/**
* List all available personality profiles
* @returns Array of profile metadata
*/
listProfiles(): Promise<PersonalityProfileMetadata[]>;

/**
* Validate a personality profile's schema
* @param profile - Personality profile to validate
* @throws {InvalidProfileException} If profile fails validation
*/
validateProfile(profile: PersonalityProfile): void;

/**
* Save a new or update an existing personality profile
* @param profile - Personality profile to save
* @returns Unique identifier of the saved profile
* @throws {InvalidProfileException} If profile is invalid
*/
saveProfile(profile: PersonalityProfile): Promise<string>;

/**
* Delete a personality profile
* @param id - Unique identifier of profile to delete
* @throws {ProfileNotFoundException} If profile does not exist
*/
deleteProfile(id: string): Promise<void>;
}

/**
* Comprehensive Personality Profile definition
*/
export interface PersonalityProfile {
id?: string;
name: string;
tone: string;
samplePrompts: string[];
description?: string;
traits?: Record<string, string>;
metadata?: Record<string, unknown>;
}

/**
* Metadata for profile listing and management
*/
export interface PersonalityProfileMetadata {
id: string;
name: string;
createdAt: Date;
updatedAt: Date;
}

/**
* Detailed validation error structure
*/
export interface ValidationError {
field: string;
code: string;
message: string;
}

/**
* Validation rules and constraints
*/
export const PersonalityProfileValidationRules = {
name: {
minLength: 2,
maxLength: 100
},
tone: {
allowedValues: ['Philosophical', 'Humorous', 'Serious', 'Empathetic']
},
samplePrompts: {
minPrompts: 1,
maxPrompts: 10,
maxPromptLength: 200
}
};
Loading