Skip to content

Test coverage for text.js (35.95% → 100%) #52

@anabelle

Description

@anabelle

Overview

The text.js module handles text generation, formatting, sanitization, and prompt construction. With 35.95% coverage, significant text processing functionality is untested.

Current Coverage

  • Statements: 35.95%
  • Branches: 26.84%
  • Functions: 55.55%
  • Lines: 35.95%
  • Target: 100% coverage

Uncovered Areas

Major untested sections:

  • Text generation with various contexts
  • Sanitization and whitelist enforcement
  • Prompt construction for different scenarios
  • Text formatting and cleanup
  • Character style application
  • Post example selection
  • Length constraints
  • Special character handling

Key Functionality to Test

1. Text Generation

  • Generating posts with LLM
  • Generating replies with context
  • Fallback to examples
  • Style adherence
  • Length management

2. Sanitization

  • Whitelist enforcement
  • Removing disallowed content
  • Preserving allowed patterns
  • URL handling
  • Handle/mention preservation

3. Prompt Construction

  • Building prompts for posts
  • Building prompts for replies
  • Including character context
  • Adding conversation history
  • Style instruction formatting

4. Text Formatting

  • Cleaning up generated text
  • Removing artifacts
  • Fixing formatting issues
  • Line break handling
  • Emoji processing

Testing Strategy

describe('Text Module', () => {
  describe('Text Generation', () => {
    test('generates post with LLM');
    test('generates reply with context');
    test('falls back to examples on error');
    test('applies character style');
    test('respects length limits');
  });

  describe('Sanitization', () => {
    test('enforces whitelist rules');
    test('removes disallowed content');
    test('preserves allowed patterns');
    test('handles URLs correctly');
    test('preserves mentions and handles');
  });

  describe('Prompt Construction', () => {
    test('builds post generation prompt');
    test('builds reply generation prompt');
    test('includes character bio');
    test('adds conversation context');
    test('formats style instructions');
  });

  describe('Text Formatting', () => {
    test('cleans generated text');
    test('removes LLM artifacts');
    test('fixes formatting issues');
    test('handles line breaks');
    test('processes emoji correctly');
  });

  describe('Post Examples', () => {
    test('selects random example');
    test('filters by criteria');
    test('handles missing examples');
  });

  describe('Integration', () => {
    test('integrates with service posting');
    test('integrates with reply generation');
    test('uses character configuration');
  });
});

Test Fixtures Needed

  • Character configurations
  • Post examples
  • Conversation contexts
  • Mock LLM responses
  • Sanitization test cases
  • Whitelist patterns

Acceptance Criteria

  • Text generation fully tested
  • Sanitization verified
  • Prompt construction covered
  • Text formatting tested
  • Example selection verified
  • Integration points tested
  • Overall coverage 100%

Related

  • Parent: Increase plugin-nostr test coverage to 100% #39 - Increase plugin-nostr test coverage to 100%
  • Related: lib/service.js - Main consumer
  • Related: lib/generation.js - Generation utilities
  • See: test/generation.test.js, test/service.replyText.test.js

Priority

🟡 MEDIUM - Core feature for agent text generation and responses.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions