# Remix MCP Server Tests

**IMPORTANT: Tests are currently disabled** due to the migration from SQLite to PostgreSQL in v0.3.0.

## Current Status

The existing test files (`*.test.js.disabled`) contain SQLite-specific code and have been disabled until they can be updated for PostgreSQL compatibility. Running `npm test` will show no tests to run, which is expected.

## What Needs to Be Done

The tests require the following updates to work with PostgreSQL:

1. **PostgreSQL Test Database Setup**: Tests need a running PostgreSQL instance with appropriate test database configuration
2. **Async/Await Conversion**: All test code must be updated from synchronous SQLite calls to async PostgreSQL operations
3. **Connection Pooling**: Tests must properly manage PostgreSQL connection pools (setup/teardown)
4. **Full-Text Search Updates**: FTS tests need to use PostgreSQL's `plainto_tsquery` instead of SQLite FTS5 syntax
5. **CI/CD Integration**: GitHub Actions workflows need PostgreSQL service containers

## Test Coverage (to be updated)

### Database Module (`database.test.js.disabled`)
- Database initialization and setup
- Table creation (conversations, messages)
- Index creation (including GIN indexes for full-text search)
- Foreign key constraints
- CHECK constraints
- Database pool management

### Tools Module (`tools.test.js`)
- **remixConversation**
  - Creating conversations with messages
  - Parent-child conversation linking
  - Message linked list (prev/next IDs)
  - Created timestamp preservation on updates
  - Input validation
  - FTS synchronization
  
- **continueConversation**
  - Message retrieval
  - Non-existent conversation handling
  - Message metadata completeness

- **readConversationTree**
  - Single conversation trees
  - Multi-level parent-child trees
  - Subtree retrieval
  - Deep nesting (10+ levels)
  - Non-existent conversation handling

- **searchParents**
  - Searching from child to parent conversations
  - Multiple keyword searches
  - Message metadata in results
  - FTS special character escaping
  - Cycle detection
  - Invalid input handling

- **searchChildren**
  - Searching from parent to all children recursively
  - Multiple keyword searches
  - Message metadata in results
  - Deep tree handling (150+ levels with depth limit)
  - Cycle detection
  - Invalid input handling

- **FTS Escaping**
  - Double quote escaping
  - Special FTS character handling

### CLI Module (`cli.test.js`)
- CLI argument parsing
  - `--connection-string /path/to/db` format
  - `--connection-string=/path/to/db` format
  - Default path behavior
  - Absolute path handling
  - Relative path handling
- Server startup verification

## Running Tests

Run all tests:
```bash
npm test
```

Build only:
```bash
npm run build
```

Watch mode (rebuild on changes):
```bash
npm run watch
```

## Test Statistics

- **Total Tests**: 48
- **Test Suites**: 12
- **Coverage**: All major functions and edge cases
- **Runtime**: ~12 seconds (includes CLI tests with 2s timeouts)

## Test Database Files

Test files create temporary database files (e.g., `test-*.db`). These are:
- Automatically cleaned up after tests complete
- Excluded from git via `.gitignore`
- Created in the project root or `/tmp` directory

## Writing New Tests

Use Node.js built-in test runner:

```javascript
import { describe, it, before, after } from 'node:test';
import assert from 'node:assert';

describe('Feature Name', () => {
  before(() => {
    // Setup
  });

  after(() => {
    // Cleanup
  });

  it('should do something', () => {
    // Test code
    assert.strictEqual(actual, expected);
  });
});
```

## Continuous Integration

Tests run automatically via GitHub Actions on:
- All branch pushes
- Pull requests to main
- Multiple Node.js versions (18.x, 20.x, 22.x)
