Skip to content

Commit d6ac485

Browse files
committed
docs: refresh test metrics, coverage, and LoC; nest hook example under _example_hook
1 parent 50a646f commit d6ac485

6 files changed

Lines changed: 83 additions & 59 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
*.out
1515
coverage
1616
mergedcoverage
17+
cover_sdk
1718

1819
# HTML coverage report generate by Go tests
1920
coverage.html

CLIENT_HOOKS.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ Filter scripts on `message.type` / `event` as needed.
8080

8181
## Example: append-only logger
8282

83-
Build the bundled sample (from repo root):
83+
Build the bundled sample (from repo root). The directory is named **`_example_hook`** on purpose: Go omits paths whose first path element begins with **`_`** (or **`.`**) or is named **`testdata`** from **`./...`**, so this sample **`package main`** tree is not matched by **`go test ./...`** at the repository root. You still build or run it by passing that path explicitly, as below.
8484

8585
```bash
86-
go build -o /tmp/marchat-hook-log ./client/exthook/example_hook
86+
go build -o /tmp/marchat-hook-log ./client/exthook/_example_hook
8787
```
8888

8989
Run the client with hooks (paths must be absolute on your OS):

README.md

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -775,10 +775,11 @@ Foundational test suite covering core functionality, cryptography, and plugins.
775775

776776
### Running Tests
777777
```bash
778-
go test ./... # Run all tests
778+
go test ./... # Run all tests (main module only)
779779
go test -cover ./... # With coverage
780780
go test ./server -v # Specific package
781781
go test ./... -timeout 10s # With timeout (CI recommended)
782+
cd plugin/sdk && go test ./... # Nested SDK module (separate go.mod)
782783
```
783784

784785
### Test Scripts
@@ -790,21 +791,22 @@ Percentages are **statement coverage** from a merged profile (`go test -coverpro
790791

791792
| Package | Coverage | Size | Status |
792793
|---------|----------|------|--------|
793-
| `shared` | 88.1% | 212 LOC | High |
794-
| `plugin/license` | 87.1% | 203 LOC | High |
795-
| `client/crypto` | 80.3% | 320 LOC | High |
796-
| `config` | 73.2% | 285 LOC | High |
797-
| `plugin/host` | 62.5% | 539 LOC | Medium |
798-
| `client/config` | 57.3% | 1683 LOC | Medium |
799-
| `internal/doctor` | 49.8% | 661 LOC | Medium |
800-
| `plugin/store` | 47.0% | 490 LOC | Medium |
801-
| `cmd/license` | 42.2% | 140 LOC | Medium |
802-
| `server` | 36.1% | 6303 LOC | Low |
803-
| `plugin/manager` | 32.1% | 626 LOC | Low |
804-
| `client` | 23.0% | 4966 LOC | Low |
805-
| `cmd/server` | 13.7% | 424 LOC | Low |
806-
807-
**Overall: 37.7%** (main module packages only). See [TESTING.md](TESTING.md) for detailed information.
794+
| `shared` | 88.1% | 253 LOC | High |
795+
| `plugin/license` | 87.1% | 246 LOC | High |
796+
| `client/crypto` | 80.3% | 387 LOC | High |
797+
| `config` | 73.2% | 339 LOC | High |
798+
| `plugin/host` | 62.5% | 623 LOC | Medium |
799+
| `client/config` | 58.0% | 1993 LOC | Medium |
800+
| `internal/doctor` | 52.1% | 802 LOC | Medium |
801+
| `plugin/store` | 47.0% | 552 LOC | Medium |
802+
| `cmd/license` | 42.2% | 160 LOC | Medium |
803+
| `server` | 36.3% | 7215 LOC | Low |
804+
| `plugin/manager` | 32.1% | 747 LOC | Low |
805+
| `client/exthook` | 24.1% | 204 LOC | Low |
806+
| `client` | 23.1% | 5555 LOC | Low |
807+
| `cmd/server` | 13.7% | 484 LOC | Low |
808+
809+
**Overall: 37.8%** (main module packages only). See [TESTING.md](TESTING.md) for detailed information.
808810

809811
## Contributing
810812

TESTING.md

Lines changed: 50 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ The Marchat test suite provides foundational coverage of the application's core
1212
- **Database Tests**: Testing database operations and schema management
1313
- **Server Tests**: Testing WebSocket handling, message routing, and user management
1414

15-
**Note**: When **`main`** has moved past the latest Git tag, a narrative summary may appear in **README.md****Latest Updates**. This is a foundational test suite with good coverage for smaller utility packages and significantly improved coverage for client and server components. **Overall statement coverage is 37.7%** across all packages in the main module, computed from the merged profile at the repo root (for example the `coverage` file or another path passed to `go test -coverprofile=... ./...`). Regenerate summaries with `go tool cover -func=<same-path>`. On **Windows PowerShell**, prefer a profile filename **without** a `.out` suffix (e.g. `mergedcoverage` or `coverage`) so the argument is not misparsed.
15+
**Note**: When **`main`** has moved past the latest Git tag, a narrative summary may appear in **README.md****Latest Updates**. This is a foundational test suite with good coverage for smaller utility packages and significantly improved coverage for client and server components. **Overall statement coverage is 37.8%** across all packages in the main module, computed from the merged profile at the repo root (for example the `coverage` file or another path passed to `go test -coverprofile=... ./...`). Regenerate summaries with `go tool cover -func=<same-path>`. On **Windows PowerShell**, prefer a profile filename **without** a `.out` suffix (e.g. `mergedcoverage` or `coverage`) so the argument is not misparsed.
1616

1717
**Database backends:** Automated tests open **SQLite** (usually in-memory or a temp file). PostgreSQL and MySQL/MariaDB are supported at runtime via `MARCHAT_DB_PATH`. **GitHub Actions** runs an extra **`database-smoke`** job (see `.github/workflows/go.yml`) with Postgres 16 and MySQL 8 service containers: it sets `MARCHAT_CI_POSTGRES_URL` and `MARCHAT_CI_MYSQL_URL` and runs `TestPostgresInitDBAndSchemaSmoke` / `TestMySQLInitDBAndSchemaSmoke` in `server/db_ci_smoke_test.go` (`InitDB` + `CreateSchema` + table checks). Locally, those tests **skip** unless you export the same variables (for MySQL, use a `mysql:` or `mysql://` prefix on the DSN so it is not parsed as a SQLite path). Schema creation is dialect-aware (including MySQL/MariaDB rules for indexed text).
1818

@@ -36,6 +36,7 @@ The Marchat test suite provides foundational coverage of the application's core
3636
| `client/file_picker_test.go` | Client file picker functionality | File browsing, selection, size validation, directory navigation |
3737
| `client/main_test.go` | Client main functionality | Message rendering, user lists, URL handling, encryption functions, flag validation |
3838
| `client/websocket_sanitize_test.go` | WebSocket URL / TLS hints | Sanitization helpers for display and connection hints |
39+
| `client/exthook/exthook_test.go` | Client hook helpers | Executable validation, hook JSON shaping, path rules |
3940
| `internal/doctor/db_checks_test.go` | Doctor DB probes | SQLite connectivity and version checks used by `-doctor` |
4041
| `cmd/server/main_test.go` | Server main function and startup | Flag parsing, configuration validation, TLS setup, admin normalization, `validateStartupConfig`, deprecated flags |
4142
| `cmd/server/subprocess_doctor_test.go` | Server binary smoke | `go run ./cmd/server -doctor` / `-doctor-json` subprocess (covers `main` early exits) |
@@ -80,6 +81,7 @@ Per-file statement percentages for important paths are listed under [Test Covera
8081
- **Client Code Snippet**: Text editing, selection, clipboard operations, syntax highlighting, state management
8182
- **Client Main**: Message rendering, user lists, URL handling, encryption functions, flag validation
8283
- **Client WebSocket helpers**: URL / TLS hint sanitization (`websocket_sanitize_test.go`)
84+
- **Client Hooks (`client/exthook`)**: Executable path validation and hook-safe JSON for send/receive events (`exthook_test.go`)
8385
- **Client File Picker**: File browsing, directory navigation, file selection, size validation, error handling
8486
- **Doctor (`internal/doctor`)**: Server/client diagnostics, env masking, update checks, DB connectivity probes
8587
- **Server Main**: Flag parsing, multi-flag handling, banner display, startup config validation (`validateStartupConfig`), admin username normalization (`normalizeAndValidateAdmins`), subprocess `-doctor` / `-doctor-json` smoke (`subprocess_doctor_test.go`)
@@ -123,11 +125,15 @@ go test -v ./...
123125
# Run tests for a specific package
124126
go test ./server
125127
go test ./shared
126-
# Nested plugin SDK module (separate go.mod)
128+
# Nested modules (separate go.mod; not run by root `go test ./...`)
127129
cd plugin/sdk
128130
go test ./...
131+
cd ../examples/echo
132+
go test ./... # optional sample plugin (may report [no test files])
129133
```
130134

135+
**Client hook sample binary:** `client/exthook/_example_hook` is a small **`package main`** logger used with [CLIENT_HOOKS.md](CLIENT_HOOKS.md). The leading **`_`** on the directory name follows the Go **`./...`** omission rules so root **`go test ./...`** does not compile it as a second package under `client/exthook` (build it only with an explicit path, for example **`go build ./client/exthook/_example_hook`**).
136+
131137
### Optional hub load benchmarks (server)
132138

133139
`server/loadverify_bench_test.go` defines `BenchmarkLoadverify_*` helpers for profiling hub broadcast paths. **`go test ./...` does not run benchmarks** unless you pass `-bench` (and usually `-run=^$` so only benchmarks execute).
@@ -197,23 +203,24 @@ go test -cover ./...
197203

198204
| Package | Coverage | Status | Lines of Code¹ | Weighted Impact |
199205
|---------|----------|--------|----------------|-----------------|
200-
| `shared` | 88.1% | High | 212 | Small |
201-
| `plugin/license` | 87.1% | High | 203 | Small |
202-
| `client/crypto` | 80.3% | High | 320 | Small |
203-
| `config` | 73.2% | High | 285 | Small |
204-
| `plugin/host` | 62.5% | Medium | 539 | Medium |
205-
| `client/config` | 57.3% | Medium | 1683 | Medium |
206-
| `internal/doctor` | 49.8% | Medium | 661 | Medium |
207-
| `plugin/store` | 47.0% | Medium | 490 | Medium |
208-
| `cmd/license` | 42.2% | Medium | 140 | Small |
209-
| `server` | 36.1% | Low | 6303 | Large |
210-
| `plugin/manager` | 32.1% | Low | 626 | Medium |
211-
| `client` | 23.0% | Low | 4966 | Large |
212-
| `cmd/server` | 13.7% | Low | 424 | Medium |
213-
214-
¹Non-test `.go` files only, physical line count (`wc -l` style), per package directory (regenerate with the Python snippet in **Test Metrics** or `find` + `wc`).
215-
216-
**Overall coverage: 37.7%** (all packages in the main module; merged profile `coverage` or another `-coverprofile` path)
206+
| `shared` | 88.1% | High | 253 | Small |
207+
| `plugin/license` | 87.1% | High | 246 | Small |
208+
| `client/crypto` | 80.3% | High | 387 | Small |
209+
| `config` | 73.2% | High | 339 | Small |
210+
| `plugin/host` | 62.5% | Medium | 623 | Medium |
211+
| `client/config` | 58.0% | Medium | 1993 | Medium |
212+
| `internal/doctor` | 52.1% | Medium | 802 | Medium |
213+
| `plugin/store` | 47.0% | Medium | 552 | Medium |
214+
| `cmd/license` | 42.2% | Medium | 160 | Small |
215+
| `server` | 36.3% | Low | 7215 | Large |
216+
| `plugin/manager` | 32.1% | Low | 747 | Medium |
217+
| `client/exthook` | 24.1% | Low | 204 | Small |
218+
| `client` | 23.1% | Low | 5555 | Large |
219+
| `cmd/server` | 13.7% | Low | 484 | Medium |
220+
221+
¹Non-test `.go` files only, physical line count (`wc -l` style), **only `.go` files in that package directory** (not subpackages such as `client/config` inside `client/`). Regenerate with the Python snippet in **Test Metrics** or `find` + `wc`.
222+
223+
**Overall coverage: 37.8%** (all packages in the main module; merged profile `coverage` or another `-coverprofile` path)
217224

218225
### High Coverage (70%+)
219226
- **Shared Package**: Cryptographic operations, data types, message handling, version utilities (88.1%)
@@ -223,15 +230,16 @@ go test -cover ./...
223230

224231
### Medium Coverage (40-70%)
225232
- **Plugin Host Package**: Load/start/stop lifecycle, JSON IPC with a minimal test plugin, `ExecuteCommand` (62.5%)
226-
- **Client Config Package**: Configuration management, path utilities, keystore migration, interactive UI (57.3%)
227-
- **Doctor Package**: Server/client diagnostics, env checks, update metadata, DB probes (49.8%)
233+
- **Client Config Package**: Configuration management, path utilities, keystore migration, interactive UI (58.0%)
234+
- **Doctor Package**: Server/client diagnostics, env checks, update metadata, DB probes (52.1%)
228235
- **Plugin Store**: Registry management, platform resolution, filtering, caching (47.0%)
229236
- **Command License**: CLI functions for license management (42.2%)
230237

231238
### Low Coverage (<40%)
232-
- **Server Package**: WebSocket handling, admin panel, database operations, message edit/delete/pin/search, channels, DMs (36.1%)
239+
- **Server Package**: WebSocket handling, admin panel, database operations, message edit/delete/pin/search, channels, DMs (36.3%)
233240
- **Plugin Manager**: Installation, store download paths, enable/disable with persisted state (32.1%)
234-
- **Client Package**: Message rendering, user lists, encryption functions, flag validation, TUI entrypoints (23.0%)
241+
- **Client Hooks (`client/exthook`)**: Hook path validation and hook-safe message JSON (24.1%)
242+
- **Client Package**: Message rendering, user lists, encryption functions, flag validation, TUI entrypoints (23.1%)
235243
- **Server Main (`cmd/server`)**: Full `main` startup, HTTP/TLS serving, admin panel wiring (13.7% for `cmd/server`); helpers such as `normalizeAndValidateAdmins` and `validateStartupConfig` plus `-doctor` / `-doctor-json` subprocess smoke tests cover parts of `main`
236244

237245
### Detailed File Coverage
@@ -243,10 +251,10 @@ Statement percentages below are from the merged profile (`go tool cover -func=co
243251
| `internal/doctor/db_checks.go` | 100.0% | internal/doctor | SQLite checks for `-doctor` |
244252
| `client/file_picker.go` | 98.2% | client | File selection TUI component |
245253
| `server/health.go` | 89.3% | server | Health monitoring and status |
246-
| `plugin/license/validator.go` | 85.4% | plugin/license | License validation and verification |
254+
| `plugin/license/validator.go` | 87.1% | plugin/license | License validation and verification |
247255
| `client/render.go` | 80.0% | client | TUI rendering helpers |
248256
| `client/crypto/keystore.go` | 80.3% | client/crypto | Keystore management, raw encrypt/decrypt |
249-
| `shared/crypto.go` | 79.4% | shared | Cryptographic operations |
257+
| `shared/crypto.go` | 82.5% | shared | Cryptographic operations |
250258
| `server/db.go` | 75.8% | server | Database operations |
251259
| `config/config.go` | 73.2% | config | Configuration management |
252260
| `client/notification_manager.go` | 67.5% | client | Desktop / notification integration |
@@ -255,30 +263,32 @@ Statement percentages below are from the merged profile (`go tool cover -func=co
255263
| `server/logger.go` | 61.4% | server | Logging functionality |
256264
| `server/message_state.go` | 59.2% | server | Reactions, read receipts, channel prefs |
257265
| `server/db_dialect.go` | 58.5% | server | SQL dialect helpers |
258-
| `server/hub.go` | 55.2% | server | WebSocket hub management, channels, DMs |
266+
| `server/hub.go` | 58.4% | server | WebSocket hub management, channels, DMs |
259267
| `client/code_snippet.go` | 53.4% | client | Code snippet TUI component |
260-
| `server/handlers.go` | 47.6% | server | HTTP/WebSocket handlers, edit/delete/pin/search |
268+
| `server/handlers.go` | 50.5% | server | HTTP/WebSocket handlers, edit/delete/pin/search |
261269
| `plugin/store/store.go` | 47.0% | plugin/store | Plugin store operations |
262270
| `cmd/license/main.go` | 42.2% | cmd/license | License CLI tool |
263-
| `client/config/config.go` | 40.6% | client/config | Client configuration |
264-
| `internal/doctor/doctor.go` | 37.4% | internal/doctor | Doctor orchestration and reporting |
271+
| `client/config/config.go` | 43.2% | client/config | Client configuration |
272+
| `internal/doctor/doctor.go` | 37.3% | internal/doctor | Doctor orchestration and reporting |
265273
| `server/config_ui.go` | 36.0% | server | Server configuration UI |
266-
| `server/admin_web.go` | 33.3% | server | Admin web interface |
274+
| `server/admin_web.go` | 33.4% | server | Admin web interface |
267275
| `plugin/manager/manager.go` | 32.1% | plugin/manager | Plugin management |
268276
| `server/admin_panel.go` | 15.9% | server | Admin panel functionality |
269277
| `server/client.go` | 14.4% | server | Client management, message type routing |
270278
| `cmd/server/main.go` | 13.7% | cmd/server | Server main application |
271279
| `server/plugin_commands.go` | 11.9% | server | Plugin command handling |
272-
| `client/main.go` | 6.7% | client | Client main application |
280+
| `client/exthook/exthook.go` | 24.1% | client/exthook | Client hook path checks and hook JSON |
281+
| `client/main.go` | 6.6% | client | Client main application |
273282

274283
### Areas for Future Testing
275-
- **Server Package**: Advanced WebSocket handling, complex message routing scenarios (current: 36.1%)
276-
- **Client Package**: WebSocket communication, full TUI integration (current: 23.0%)
284+
- **Server Package**: Advanced WebSocket handling, complex message routing scenarios (current: 36.3%)
285+
- **Client Package**: WebSocket communication, full TUI integration (current: 23.1%)
277286
- **Plugin Host**: Broader command/response paths and failure modes beyond the minimal IPC test plugin (current: 62.5%)
278287
- **Plugin Manager**: Store download, checksum, and install edge cases (current: 32.1%)
279288
- **Server Main**: Full `main` execution, HTTP/TLS serving, admin panel integration (current: 13.7% statement coverage for `cmd/server/main.go`)
280289
- **File Transfer**: File upload/download functionality
281-
- **Plugin License**: License validation and enforcement (current: 85.4%)
290+
- **Client Hooks**: Broader hook execution paths and failure modes (current: 24.1% for `client/exthook`)
291+
- **Plugin License**: License validation and enforcement (package: 87.1%; `validator.go` file line in the table above)
282292

283293
## Test Data and Fixtures
284294

@@ -412,12 +422,12 @@ When adding new functionality to Marchat:
412422

413423
## Test Metrics
414424

415-
- **Top-level tests**: 334 `Test*` entrypoints from `go test -list . ./...` on the main module; the nested **`plugin/sdk`** module adds 10 more (`cd plugin/sdk && go test -list . ./...`).
416-
- **Test files**: 38 `_test.go` files in the repo tree (including `plugin/sdk/plugin_test.go`).
417-
- **Packages (`go list ./...`)**: 14 in the main module; `plugin/sdk` is a nested module with its own `go.mod`.
418-
- **Coverage by Package** (statement %, merged profile): 88.1% (`shared`), 87.1% (`plugin/license`), 80.3% (`client/crypto`), 73.2% (`config`), 62.5% (`plugin/host`), 57.3% (`client/config`), 49.8% (`internal/doctor`), 47.0% (`plugin/store`), 42.2% (`cmd/license`), 36.1% (`server`), 32.1% (`plugin/manager`), 23.0% (`client`), 13.7% (`cmd/server`)
419-
- **Overall Coverage**: **37.7%** across main-module packages (regenerate with `go test -coverprofile=mergedcoverage ./...` then `go tool cover -func=mergedcoverage`; on PowerShell avoid `-coverprofile=*.out`--see note above)
420-
- **Lines of code (approx.)**: non-test `.go` lines per package directory, same totals as the **Current Coverage Status** table (e.g. `server` 6298, `client` 4966); re-count with:
425+
- **Top-level tests**: 348 `Test*` entrypoints from `go test -list . ./...` on the main module; the nested **`plugin/sdk`** module adds 10 more (`cd plugin/sdk && go test -list . ./...`).
426+
- **Test files**: 42 tracked `_test.go` files (`git ls-files '*_test.go'`), including `plugin/sdk/plugin_test.go` in the nested SDK module.
427+
- **Packages (`go list ./...`)**: 15 in the main module; `plugin/sdk` and `plugin/examples/echo` are nested modules with their own `go.mod` files (root `go test ./...` does not run their tests).
428+
- **Coverage by Package** (statement %, merged profile): 88.1% (`shared`), 87.1% (`plugin/license`), 80.3% (`client/crypto`), 73.2% (`config`), 62.5% (`plugin/host`), 58.0% (`client/config`), 52.1% (`internal/doctor`), 47.0% (`plugin/store`), 42.2% (`cmd/license`), 36.3% (`server`), 32.1% (`plugin/manager`), 24.1% (`client/exthook`), 23.1% (`client`), 13.7% (`cmd/server`)
429+
- **Overall Coverage**: **37.8%** across main-module packages (regenerate with `go test -coverprofile=mergedcoverage ./...` then `go tool cover -func=mergedcoverage`; on PowerShell avoid `-coverprofile=*.out`--see note above)
430+
- **Lines of code (approx.)**: non-test `.go` lines per package directory, same totals as the **Current Coverage Status** table (e.g. `server` 7215, `client` 5555); re-count with:
421431
`python -c "import os; ..."` walking the tree and skipping `*_test.go`, or equivalent `find` + `wc -l`.
422432
- **Execution Time**: on the order of a few seconds for `go test ./...` on a typical dev machine
423433
- **Reliability**: deterministic; use `go test -race ./...` where supported (see CI)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Example stdin hook: append each JSON line to a log file for spike testing.
22
//
3-
// Build: go build -o marchat-hook-log ./client/exthook/example_hook
3+
// Build: go build -o marchat-hook-log ./client/exthook/_example_hook
44
// Run client from repo root: go run ./client (not go run .)
55
// Env: MARCHAT_CLIENT_HOOK_RECEIVE=C:\full\path\marchat-hook-log.exe (and/or MARCHAT_CLIENT_HOOK_SEND)
66
//

0 commit comments

Comments
 (0)