kimun-notes 0.11.0

A terminal-based notes application
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
# Kimun CLI Testing Documentation

This document provides comprehensive guidance for testing the Kimun CLI functionality, including both automated integration tests and manual testing procedures.

## Overview

Kimun provides two CLI commands for interacting with your notes from the command line:
- `search` - Search notes by query
- `notes` - List all notes with optional path filtering

Both commands support text output format and require a configured workspace.

### Current Limitations

- **Database Initialization:** CLI commands require the workspace database to be initialized first via the TUI
- **Output Format:** Only text format is currently supported (JSON planned for future)
- **Read-Only:** CLI commands are read-only; note creation/editing requires TUI
- **No Streaming:** Large result sets are loaded entirely into memory

## Running Integration Tests

### Prerequisites

- Rust toolchain installed
- All dependencies resolved (`cargo build`)

### Test Execution

Run all CLI integration tests:
```bash
cd tui
cargo test cli_integration_test
```

Run specific integration tests:
```bash
# Test search command functionality
cargo test test_cli_search_command

# Test notes command functionality
cargo test test_cli_notes_command

# Test error handling when no workspace configured
cargo test test_cli_no_workspace_error

# Test custom config file support
cargo test test_cli_custom_config
```

### Test Coverage

The integration tests cover four main scenarios:

1. **Search Command (`test_cli_search_command`)**
   - Creates temporary vault with indexed test notes
   - Executes search command with query "hello"
   - Verifies command succeeds and returns results

2. **Notes Command (`test_cli_notes_command`)**
   - Tests listing all notes without path filter
   - Tests listing notes with path prefix filter ("sub/")
   - Verifies both scenarios succeed

3. **No Workspace Error (`test_cli_no_workspace_error`)**
   - Tests behavior when config has no workspace_dir set
   - Verifies settings layer correctly returns None
   - Ensures CLI would hit error branch for missing workspace

4. **Custom Config (`test_cli_custom_config`)**
   - Tests loading settings from custom config file path
   - Verifies end-to-end CLI execution with custom config
   - Ensures --config flag works correctly

## Manual Testing Procedures

### Setup Test Environment

1. **Create Test Workspace**
   ```bash
   mkdir -p /tmp/kimun-test-workspace
   cd /tmp/kimun-test-workspace
   ```

2. **Create Test Notes**
   ```bash
   mkdir -p sub
   echo "# Hello World\n\nThis is a hello note." > hello.md
   echo "# Nested Note\n\nThis note lives in a subdirectory." > sub/nested.md
   echo "# Another Note\n\nSome other content." > another.md
   ```

3. **Create Test Config**
   ```bash
   mkdir -p ~/.config/kimun
   cat > ~/.config/kimun/config.toml << EOF
   workspace_dir = "/tmp/kimun-test-workspace"
   EOF
   ```

4. **Initialize Workspace Database**

   **Important:** The CLI commands require the workspace database to be initialized. This happens automatically when the TUI starts, but must be done manually for CLI-only usage.

   **Option A - Use TUI to initialize (Recommended):**
   ```bash
   # Run TUI once to initialize database and create index
   kimun --config ~/.config/kimun/config.toml
   # Exit after startup completes (Ctrl+Q)
   ```

   **Option B - Manual database setup (Advanced):**
   ```bash
   # The database file will be created at workspace/.kimun.db
   # Currently there's no CLI command to initialize without TUI
   # This is a limitation of the current implementation
   ```

### Testing Search Command

#### Basic Search
```bash
# Search for notes containing "hello"
kimun search hello

# Expected output format:
# hello.md	"Hello World"	<size>	<timestamp>
```

#### Search with Different Queries
```bash
# Search for "nested"
kimun search nested

# Search for "note"
kimun search note

# Search for non-existent term
kimun search nonexistent
```

#### Expected Output Format
Each result line contains tab-separated fields:
- File path relative to workspace
- Note title in quotes
- File size in bytes
- Modified timestamp (Unix seconds)
- Journal date (if applicable): `journal:YYYY-MM-DD`

### Testing Notes Command

#### List All Notes
```bash
# List all notes in workspace
kimun notes

# Expected output: all notes with same format as search
```

#### Path Filtering
```bash
# List notes in subdirectory
kimun notes --path sub/

# List notes with specific prefix
kimun notes --path hello
```

#### Output Format Options
```bash
# Explicit text format (default)
kimun notes --format text
kimun search hello --format text
```

#### Exclusion Operator Testing

Test exclusion operators with various combinations:

```bash
# Basic content exclusion
kimun search "meeting -cancelled"

# Title exclusion
kimun search ">project >-draft"

# Filename exclusion
kimun search "@2024 @-temp"

# Path exclusion
kimun search "/docs /-private"

# Exclusion-only queries
kimun search "-cancelled"
kimun search ">-draft"

# Complex combinations
kimun search "meeting @2024 -cancelled >-draft /docs"
```

**Expected Behavior:**
- Content exclusions filter out notes containing excluded terms
- Title exclusions work on note titles/breadcrumbs only
- Filename exclusions work on note filenames only
- Path exclusions work on note path prefixes
- Exclusion-only queries return all notes except those matching excluded terms

### Testing Configuration

#### Custom Config File
```bash
# Create custom config
cat > /tmp/custom-config.toml << EOF
workspace_dir = "/tmp/kimun-test-workspace"
EOF

# Test with custom config
kimun --config /tmp/custom-config.toml notes
kimun --config /tmp/custom-config.toml search hello
```

#### No Workspace Configuration
```bash
# Create config without workspace
cat > /tmp/no-workspace.toml << EOF
# empty config
EOF

# Test error handling
kimun --config /tmp/no-workspace.toml notes
# Expected: Error message and exit code 1
```

### Error Scenarios

#### Missing Workspace Directory
```bash
# Point to non-existent directory
cat > /tmp/bad-config.toml << EOF
workspace_dir = "/tmp/does-not-exist"
EOF

kimun --config /tmp/bad-config.toml notes
# Expected: Error about unable to access workspace
```

#### Invalid Config File
```bash
# Test with malformed TOML
echo "invalid toml content [[[" > /tmp/bad.toml
kimun --config /tmp/bad.toml notes
# Expected: Config parsing error
```

## Test Scenarios and Expected Outputs

### Scenario 1: Fresh Workspace with Notes

**Setup:**
- Empty workspace with 3 notes: hello.md, sub/nested.md, another.md
- All notes properly indexed

**Test Cases:**

| Command | Expected Output | Notes |
|---------|----------------|-------|
| `kimun search hello` | `hello.md	"Hello World"	<size>	<timestamp>` | Single match |
| `kimun search note` | Multiple entries for notes containing "note" | Multiple matches |
| `kimun notes` | All 3 notes listed | Full listing |
| `kimun notes --path sub/` | Only `sub/nested.md` | Path filtering |

### Scenario 2: Journal Notes

**Setup:**
- Workspace with journal entries following YYYY-MM-DD.md pattern

**Test Cases:**

| Command | Expected Output | Notes |
|---------|----------------|-------|
| `kimun notes` | Entries include `journal:YYYY-MM-DD` suffix | Journal date detection |
| `kimun search today` | Journal entries with "today" in content | Search in journal |

### Scenario 3: Empty Workspace

**Setup:**
- Valid workspace directory but no notes

**Test Cases:**

| Command | Expected Output | Notes |
|---------|----------------|-------|
| `kimun search anything` | No output | Empty results |
| `kimun notes` | No output | Empty listing |

## Troubleshooting Guide

### Test Failures

#### Integration Test Failures

**Symptom:** `test_cli_search_command` fails
- **Check:** Verify search indexing is working in test vault
- **Solution:** Ensure `vault.recreate_index()` completes successfully
- **Debug:** Add logging to see if notes are being created and indexed

**Symptom:** `test_cli_no_workspace_error` fails
- **Check:** Verify AppSettings correctly handles missing workspace_dir
- **Solution:** Ensure config parsing returns None for missing workspace
- **Debug:** Print settings.workspace_dir value in test

**Symptom:** Tests hang or timeout
- **Check:** Async test execution and vault operations
- **Solution:** Verify tokio runtime is properly configured
- **Debug:** Add timeouts and logging to async operations

#### Manual Test Issues

**Symptom:** "No workspace configured" error
- **Check:** Config file location and format
- **Solution:** Verify config.toml exists and has valid workspace_dir
- **Debug:** Use `--config` flag with absolute path to config file

**Symptom:** CLI exits with code 1
- **Check:** Workspace directory exists and is accessible
- **Solution:** Create workspace directory or fix permissions
- **Debug:** Run with verbose logging if available

**Symptom:** No search results when notes exist
- **Check:** Notes are properly indexed
- **Solution:** Run TUI once to ensure indexing, or check if vault.recreate_index() needed
- **Debug:** Verify note content matches search query

**Symptom:** "no such table: notes" error
- **Check:** Database has been initialized
- **Solution:** Run TUI once to initialize SQLite database and create tables
- **Debug:** Verify .kimun.db file exists in workspace directory

**Symptom:** Notes command shows no output
- **Check:** Notes exist in workspace directory
- **Solution:** Create test notes or verify workspace path
- **Debug:** List directory contents manually

### Environment Issues

#### Path Problems
- Ensure all paths in config use absolute paths
- Check workspace directory permissions
- Verify config file is readable

#### Index Problems
- Notes may need initial indexing through TUI
- Search index might be corrupt or missing
- Try recreating workspace or running TUI once

#### Config Issues
- TOML syntax must be valid
- workspace_dir must point to accessible directory
- Custom config paths must be absolute

### Debugging Commands

```bash
# Check config loading
kimun --config /path/to/config.toml notes 2>&1 | head

# Verify workspace access
ls -la "$(grep workspace_dir ~/.config/kimun/config.toml | cut -d'"' -f2)"

# Test with minimal config
echo 'workspace_dir = "/tmp/test"' | kimun --config - notes

# Check file permissions
stat ~/.config/kimun/config.toml
```

## Performance Considerations

### Large Workspaces
- Search performance depends on index size
- Notes listing loads all entries into memory
- Consider pagination for very large note collections

### Concurrent Access
- CLI and TUI can safely access same workspace simultaneously
- Index updates are atomic
- File system locking handles concurrent note access

## Integration with CI/CD

### Automated Testing
```bash
# Run in CI pipeline
cargo test --package kimun-notes cli_integration_test
```

### Test Coverage
```bash
# Generate coverage report including CLI tests
cargo tarpaulin --include-tests --out Html
```

### Performance Benchmarks
```bash
# Benchmark CLI performance with large datasets
hyperfine 'kimun search common-term' --warmup 3
```

## Future Test Considerations

### Current Limitation Improvements
- CLI-only database initialization command
- Streaming output for large result sets
- Write operations via CLI (create, edit, delete notes)
- Live indexing without requiring TUI startup

### Additional Test Scenarios
- Unicode/non-ASCII content in notes
- Very large notes (>1MB)
- Malformed note files
- Symlinks in workspace
- Network-mounted workspace directories
- Concurrent CLI operations

### Output Format Extensions
- JSON output format testing
- Machine-readable output validation
- CSV/TSV output formats
- Structured metadata output

### Configuration Extensions
- Multiple workspace support
- Environment variable configuration
- XDG base directory compliance
- Profile-based configurations