Skip to content
Open
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
72 changes: 69 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,21 @@ cortex role set <slug>
| `cortex --version` | Show version information |
| `cortex --help` | Display help message |

#### Daemon Commands

| Command | Description |
|---------|-------------|
| `cortex daemon install --execute` | Install and enable the cortexd daemon |
| `cortex daemon uninstall --execute` | Stop and remove the daemon |
| `cortex daemon ping` | Test daemon connectivity |
| `cortex daemon version` | Show daemon version |
| `cortex daemon config` | Show daemon configuration |
| `cortex daemon reload-config` | Reload daemon configuration |
| `cortex daemon run-tests` | Run daemon test suite |
| `cortex daemon run-tests --unit` | Run only unit tests |
| `cortex daemon run-tests --integration` | Run only integration tests |
| `cortex daemon run-tests -t <name>` | Run a specific test |

### Configuration

Cortex stores configuration in `~/.cortex/`:
Expand Down Expand Up @@ -256,20 +271,45 @@ Cortex stores configuration in `~/.cortex/`:

```
cortex/
├── cortex/ # Main package
├── cortex/ # Main Python package
│ ├── cli.py # Command-line interface
│ ├── coordinator.py # Installation orchestration
│ ├── llm_router.py # Multi-LLM routing
│ ├── daemon_client.py # IPC client for cortexd
│ ├── packages.py # Package manager wrapper
│ ├── hardware_detection.py
│ ├── installation_history.py
│ └── utils/ # Utility modules
├── tests/ # Test suite
├── daemon/ # C++ background daemon (cortexd)
│ ├── src/ # Daemon source code
│ ├── include/ # Header files
│ ├── tests/ # Unit & integration tests
│ ├── scripts/ # Build and setup scripts
│ └── README.md # Daemon documentation
├── tests/ # Python test suite
├── docs/ # Documentation
├── examples/ # Example scripts
└── scripts/ # Utility scripts
```

### Background Daemon (cortexd)

Cortex includes an optional C++ background daemon for system-level operations:

```bash
# Install the daemon
cortex daemon install --execute

# Check daemon status
cortex daemon ping
cortex daemon version

# Run daemon tests (no installation required)
cortex daemon run-tests
```

See [daemon/README.md](daemon/README.md) for full documentation.

---

## Safety & Security
Expand Down Expand Up @@ -433,11 +473,37 @@ pip install -e ".[dev]"

# Install pre-commit hooks
pre-commit install
```

### Running Tests

**Python Tests:**

# Run tests
```bash
# Run all Python tests
pytest tests/ -v

# Run with coverage
pytest tests/ -v --cov=cortex
```

**Daemon Tests (C++):**

```bash
# Build daemon with tests
cd daemon && ./scripts/build.sh Release --with-tests

# Run all daemon tests (no daemon installation required)
cortex daemon run-tests

# Run specific test types
cortex daemon run-tests --unit # Unit tests only
cortex daemon run-tests --integration # Integration tests only
cortex daemon run-tests -t config # Specific test
```

> **Note:** Daemon tests run against a static library and don't require the daemon to be installed as a systemd service. They test the code directly.

See [CONTRIBUTING.md](CONTRIBUTING.md) for detailed guidelines.

---
Expand Down
58 changes: 58 additions & 0 deletions TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,64 @@ python -m src.sandbox_executor "echo hello" --dry-run
- [ ] Works in fish (if installed)
- [ ] Works in tmux/screen

## Daemon Tests (C++)

The daemon has its own test suite that tests the C++ code directly.

### Prerequisites

```bash
# Build daemon with tests
cd daemon
./scripts/build.sh Release --with-tests
```

### Running Daemon Tests

**Via Cortex CLI:**

- [ ] `cortex daemon run-tests` - Runs all daemon tests
- [ ] `cortex daemon run-tests --unit` - Runs unit tests only
- [ ] `cortex daemon run-tests --integration` - Runs integration tests only
- [ ] `cortex daemon run-tests -t config` - Runs specific test
- [ ] `cortex daemon run-tests -v` - Verbose output

**Via ctest:**

```bash
cd daemon/build
ctest --output-on-failure
```

### Test Structure

| Test | Type | What It Tests |
|------|------|---------------|
| `test_config` | Unit | Configuration loading/validation |
| `test_protocol` | Unit | IPC message serialization |
| `test_rate_limiter` | Unit | Request rate limiting |
| `test_logger` | Unit | Logging subsystem |
| `test_common` | Unit | Common constants/types |
| `test_ipc_server` | Integration | IPC server lifecycle |
| `test_handlers` | Integration | IPC request handlers |
| `test_daemon` | Integration | Daemon lifecycle/services |

### Important Notes

> **Tests don't require daemon installation!**
>
> The tests link against a static library (`cortexd_lib`) containing all daemon code.
> They instantiate classes directly in memory and test their behavior without needing
> systemd or an installed binary.

### Daemon Test Checklist

- [ ] All unit tests pass
- [ ] All integration tests pass
- [ ] Tests complete in < 30 seconds
- [ ] No memory leaks (run with valgrind if available)
- [ ] Tests pass without root/sudo

## Notes

Record any issues found:
Expand Down
Loading
Loading