You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CLIENT_HOOKS.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -80,10 +80,10 @@ Filter scripts on `message.type` / `event` as needed.
80
80
81
81
## Example: append-only logger
82
82
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.
84
84
85
85
```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
87
87
```
88
88
89
89
Run the client with hooks (paths must be absolute on your OS):
Copy file name to clipboardExpand all lines: TESTING.md
+50-40Lines changed: 50 additions & 40 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,7 +12,7 @@ The Marchat test suite provides foundational coverage of the application's core
12
12
-**Database Tests**: Testing database operations and schema management
13
13
-**Server Tests**: Testing WebSocket handling, message routing, and user management
14
14
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.
16
16
17
17
**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).
18
18
@@ -36,6 +36,7 @@ The Marchat test suite provides foundational coverage of the application's core
|`internal/doctor/db_checks_test.go`| Doctor DB probes | SQLite connectivity and version checks used by `-doctor`|
40
41
|`cmd/server/main_test.go`| Server main function and startup | Flag parsing, configuration validation, TLS setup, admin normalization, `validateStartupConfig`, deprecated flags |
41
42
|`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
80
81
-**Client Code Snippet**: Text editing, selection, clipboard operations, syntax highlighting, state management
81
82
-**Client Main**: Message rendering, user lists, URL handling, encryption functions, flag validation
82
83
-**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`)
# Nested modules (separate go.mod; not run by root `go test ./...`)
127
129
cd plugin/sdk
128
130
go test ./...
131
+
cd ../examples/echo
132
+
go test ./... # optional sample plugin (may report [no test files])
129
133
```
130
134
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
+
131
137
### Optional hub load benchmarks (server)
132
138
133
139
`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 ./...
197
203
198
204
| Package | Coverage | Status | Lines of Code¹ | Weighted Impact |
|`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)
217
224
218
225
### High Coverage (70%+)
219
226
-**Shared Package**: Cryptographic operations, data types, message handling, version utilities (88.1%)
@@ -223,15 +230,16 @@ go test -cover ./...
223
230
224
231
### Medium Coverage (40-70%)
225
232
-**Plugin Host Package**: Load/start/stop lifecycle, JSON IPC with a minimal test plugin, `ExecuteCommand` (62.5%)
-**Client Package**: Message rendering, user lists, encryption functions, flag validation, TUI entrypoints (23.1%)
235
243
-**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`
236
244
237
245
### Detailed File Coverage
@@ -243,10 +251,10 @@ Statement percentages below are from the merged profile (`go tool cover -func=co
243
251
|`internal/doctor/db_checks.go`| 100.0% | internal/doctor | SQLite checks for `-doctor`|
-**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)
282
292
283
293
## Test Data and Fixtures
284
294
@@ -412,12 +422,12 @@ When adding new functionality to Marchat:
412
422
413
423
## Test Metrics
414
424
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`.
-**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).
-**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:
421
431
`python -c "import os; ..."` walking the tree and skipping `*_test.go`, or equivalent `find` + `wc -l`.
422
432
-**Execution Time**: on the order of a few seconds for `go test ./...` on a typical dev machine
423
433
-**Reliability**: deterministic; use `go test -race ./...` where supported (see CI)
0 commit comments