Skip to content

Commit 0899dc1

Browse files
authored
fix: Improve plugin logging and add test/coverage CI (#11)
* Add debug logging mode for plugin * Add log level support for plugin logging * Add tests and CI checks * Expand behavioral test coverage * Add coverage reporting and Codecov upload * Add repo guidance and Given/When/Then test comments * Fix Codecov workflow guard * Make Given/When/Then comments descriptive * Fix session-context test typecheck
1 parent d80c284 commit 0899dc1

22 files changed

Lines changed: 2560 additions & 828 deletions

.github/workflows/lint.yml

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Lint
1+
name: CI
22

33
on:
44
push:
@@ -15,7 +15,7 @@ concurrency:
1515
cancel-in-progress: true
1616

1717
jobs:
18-
lint:
18+
checks:
1919
runs-on: ubuntu-latest
2020
steps:
2121
- name: Check out repository
@@ -25,9 +25,35 @@ jobs:
2525
uses: actions/setup-node@v4
2626
with:
2727
node-version: "24"
28+
cache: npm
2829

2930
- name: Install dependencies
3031
run: npm ci
3132

3233
- name: Run lint
3334
run: npm run lint
35+
36+
- name: Run typecheck
37+
run: npm run typecheck
38+
39+
- name: Run coverage
40+
run: npm run coverage
41+
42+
- name: Upload coverage artifact
43+
uses: actions/upload-artifact@v4
44+
with:
45+
name: coverage-report
46+
path: coverage
47+
48+
- name: Upload coverage to Codecov
49+
if: ${{ env.CODECOV_TOKEN != '' }}
50+
env:
51+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
52+
uses: codecov/codecov-action@v5
53+
with:
54+
files: ./coverage/lcov.info
55+
flags: unit
56+
name: vitest-coverage
57+
token: ${{ env.CODECOV_TOKEN }}
58+
fail_ci_if_error: false
59+
verbose: true

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
node_modules/
2+
coverage/

AGENTS.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# AGENTS.md
2+
3+
## Repo Scope
4+
5+
This repository contains the Agent Control plugin for OpenClaw. It is a TypeScript ESM project that ships source files directly; there is no separate build step in normal development.
6+
7+
## Local Verification
8+
9+
Run the full local verification stack before finishing non-trivial changes:
10+
11+
```bash
12+
npm run lint
13+
npm run typecheck
14+
npm test
15+
```
16+
17+
When the change affects tests, coverage, or CI behavior, also run:
18+
19+
```bash
20+
npm run coverage
21+
```
22+
23+
Coverage output is written to `coverage/`, including `coverage/lcov.info` for Codecov-compatible uploads.
24+
25+
## Testing Conventions
26+
27+
- Prefer behavioral tests over implementation-detail tests.
28+
- Write test names as concise behavioral summaries.
29+
- Express Given/When/Then structure as code comments inside the test body.
30+
- Make each Given/When/Then comment descriptive. Do not use placeholder comments like `// Given`, `// When`, or `// Then` by themselves.
31+
- Use Vitest for unit and integration-style tests.
32+
- Assert externally visible outcomes first: return values, registered hooks, emitted logs, blocked tool calls, resolved context, and client calls.
33+
- Mock boundary dependencies such as `agent-control`, session/context helpers, and runtime-loading edges when needed, but keep the assertions focused on plugin behavior.
34+
- When adding a new branch in plugin logic, add or update tests in the corresponding `test/*.test.ts` file.
35+
36+
Examples of the preferred naming style:
37+
38+
- `it("defaults to warn", () => { ... })`
39+
- `it("blocks the tool call when fail-closed sync fails", async () => { ... })`
40+
41+
Examples of the preferred comment style:
42+
43+
- `// Given no logging configuration is provided`
44+
- `// When the effective log level is resolved`
45+
- `// Then warn mode is selected by default`
46+
47+
## Project Conventions
48+
49+
- Keep imports ESM-compatible and include the `.ts` suffix for local TypeScript imports, matching the current codebase style.
50+
- This repo uses `oxlint` for linting and `tsc --noEmit` for semantic typechecking. `npm run lint` is not a substitute for `npm run typecheck`.
51+
- Preserve the plugin's quiet default behavior. New logs should fit the existing `logLevel` model:
52+
- `warn`: warnings, errors, and block events
53+
- `info`: important lifecycle events
54+
- `debug`: verbose diagnostics
55+
56+
## When Changing Config or User-Facing Behavior
57+
58+
Keep these files aligned when config shape or documented behavior changes:
59+
60+
- `src/types.ts`
61+
- `openclaw.plugin.json`
62+
- `README.md`
63+
- relevant tests under `test/`
64+
65+
If a change affects CI expectations or coverage behavior, also update:
66+
67+
- `.github/workflows/lint.yml`
68+
- `package.json`
69+
- `vitest.config.ts`
70+
71+
## CI Expectations
72+
73+
The main GitHub Actions workflow is `.github/workflows/lint.yml`. Changes to scripts or coverage generation should keep local commands and CI steps in sync.

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,14 @@ Then restart the gateway.
3535

3636
```bash
3737
npm install
38+
npm run lint
39+
npm run typecheck
40+
npm test
41+
npm run coverage
3842
```
3943

44+
Coverage reports are written to `coverage/`, including `coverage/lcov.info` for Codecov-compatible uploads. The GitHub Actions workflow will upload that report to Codecov automatically when a `CODECOV_TOKEN` secret is configured for the repository.
45+
4046
3. Link it into your OpenClaw config from your OpenClaw checkout:
4147

4248
```bash
@@ -66,16 +72,29 @@ openclaw config set plugins.entries.agent-control-openclaw-plugin.config.timeout
6672
openclaw config set plugins.entries.agent-control-openclaw-plugin.config.failClosed false --strict-json
6773

6874
# Optional settings
75+
openclaw config set plugins.entries.agent-control-openclaw-plugin.config.logLevel "info"
76+
openclaw config set plugins.entries.agent-control-openclaw-plugin.config.logLevel "debug"
6977
openclaw config set plugins.entries.agent-control-openclaw-plugin.config.agentId "00000000-0000-4000-8000-000000000000"
7078
openclaw config set plugins.entries.agent-control-openclaw-plugin.config.agentVersion "2026.3.3"
7179
openclaw config set plugins.entries.agent-control-openclaw-plugin.config.userAgent "agent-control-plugin/0.1"
7280

7381
# Remove optional keys
7482
openclaw config unset plugins.entries.agent-control-openclaw-plugin.config.apiKey
83+
openclaw config unset plugins.entries.agent-control-openclaw-plugin.config.logLevel
84+
openclaw config unset plugins.entries.agent-control-openclaw-plugin.config.debug
7585
openclaw config unset plugins.entries.agent-control-openclaw-plugin.config.agentId
7686
openclaw config unset plugins.entries.agent-control-openclaw-plugin.config.agentVersion
7787
openclaw config unset plugins.entries.agent-control-openclaw-plugin.config.userAgent
7888

7989
# Uninstall plugin link/install record from OpenClaw config
8090
openclaw plugins uninstall agent-control-openclaw-plugin --force
8191
```
92+
93+
By default the plugin stays quiet and only emits warnings, errors, and tool block events.
94+
95+
Set `config.logLevel` to:
96+
97+
- `info` for one-line lifecycle logs such as client init, warmup, and agent syncs
98+
- `debug` for verbose startup, sync, and evaluation diagnostics
99+
100+
The older `config.debug` flag is still accepted as a deprecated alias for `logLevel=debug`.

openclaw.plugin.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@
3333
},
3434
"failClosed": {
3535
"type": "boolean"
36+
},
37+
"logLevel": {
38+
"type": "string",
39+
"enum": ["warn", "info", "debug"]
40+
},
41+
"debug": {
42+
"type": "boolean"
3643
}
3744
}
3845
},
@@ -56,6 +63,14 @@
5663
"failClosed": {
5764
"label": "Fail Closed",
5865
"help": "If true, block tool invocations when Agent Control is unavailable."
66+
},
67+
"logLevel": {
68+
"label": "Log Level",
69+
"help": "Controls plugin verbosity: warn logs only warnings, errors, and block events; info adds high-level lifecycle logs; debug adds verbose diagnostics."
70+
},
71+
"debug": {
72+
"label": "Debug Logging",
73+
"help": "Deprecated alias for logLevel=debug."
5974
}
6075
}
6176
}

0 commit comments

Comments
 (0)