Skip to content

Commit 3dfbcb9

Browse files
committed
add more to the agents.md
1 parent d932144 commit 3dfbcb9

1 file changed

Lines changed: 46 additions & 4 deletions

File tree

‎AGENTS.md‎

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# Repository Guidelines
22

3+
## Agent Change Discipline
4+
5+
- Make surgical changes: touch only files required by the task.
6+
- Do not refactor adjacent code, rename symbols, or reformat unrelated files unless the task requires it.
7+
- Prefer the simplest solution that solves the problem; do not add speculative abstractions, features, or configurability.
8+
- Match existing style and patterns. Remove only unused imports, variables, functions, or files introduced by your change.
9+
- If requirements are ambiguous, state the assumption or ask before coding.
10+
311
## Project Structure & Module Organization
412

513
- `cmd/`: buildable binaries (e.g. `cmd/cdc`, `cmd/kafka-consumer`).
@@ -17,21 +25,55 @@
1725
- `make check`: pre-submit checks (fmt, tidy, codegen, dashboards, Makefile formatting).
1826
- `make unit_test`: unit tests with race + failpoints enabled (uses `--tags=intest`).
1927
- `make unit_test_pkg PKG=./pkg/sink/...`: narrow unit test scope.
28+
- `make generate_mock`: regenerate gomock-based mocks via `scripts/generate-mock.sh`.
2029
- `make integration_test_kafka CASE=<name>` (and `*_mysql|*_storage|*_pulsar`): run integration suites; requires binaries in `bin/` (`make check_third_party_binary`).
2130

22-
## Coding Style & Naming Conventions
31+
## Go Coding Rules
2332

24-
- Go: keep `gofmt` clean; use `make fmt` before pushing.
33+
- Formatting: keep `gofmt` clean; use `make fmt` before pushing.
2534
- Naming:
2635
- Functions: use camel case and **do not** include `_` (e.g. `getPartitionNum`, not `get_partition_num`).
2736
- Variables: use lowerCamelCase (e.g. `flushInterval`, not `flush_interval`).
28-
- Logging: structured logs via `github.com/pingcap/log` + `zap` fields; message strings should **not** include function names and should avoid `-` (use spaces instead).
29-
- Errors: when an error comes from a third party/library call, wrap it immediately with `errors.Trace(err)` or `errors.WrapError(...)` to attach a stack trace; upstream callers should propagate wrapped errors without wrapping again. Avoid using `errors.New` to create error objects; instead, utilize the predefined objects available in the `cerrors` package.
37+
- Imports: do not rename imports unless required to resolve a package name conflict or to follow an existing local convention.
38+
39+
## Errors
40+
41+
- Use predefined errors from the repository error package; keep the local import name consistent with surrounding code.
42+
- When an error comes from a third-party or library call, wrap it immediately at the boundary with `errors.WrapError(predefinedError, err, args...)`.
43+
- After an error has been wrapped with `errors.WrapError`, propagate it directly; do not call `errors.Trace` again on later paths.
44+
- When creating a TiCDC error, use `GenWithStack...` or `GenWithStackByArgs...` on a predefined error and pass concrete details through arguments when needed.
45+
- Decide whether a newly generated error needs stack information. If a stack is unnecessary, especially on hot paths, use `FastGen...` or `FastGenByArgs...`.
46+
- Avoid other error creation or wrapping styles, including `errors.New`, bare `fmt.Errorf`, and adding stack information multiple times.
47+
48+
## Logging
49+
50+
- Use structured logs via `github.com/pingcap/log` with `zap` fields.
51+
- Treat logs as operational signals, not control-flow comments. Keep normal paths quiet.
52+
- Default `INFO`/`WARN` logs should record high-value lifecycle events, state changes, external dependency abnormalities, or invariant violations.
53+
- Choose log levels by required action:
54+
- `ERROR`: correctness, availability, or key progress is affected and needs attention.
55+
- `WARN`: the system is abnormal but can continue through recovery, retry, fallback, or degraded behavior.
56+
- `INFO`: key lifecycle events, important state changes, important configuration, or summary information.
57+
- `DEBUG`: bounded, low-frequency diagnostics with clear troubleshooting value.
58+
- Do not add `DEBUG` logs by default. Delete low-value logs instead of moving them to `DEBUG`.
59+
- Keep `message` stable and concise: summarize what happened, why it happened, and what the system will do next.
60+
- Put object details in stable camelCase `zap` fields such as `changefeedID`, `nodeID`, `dispatcherID`, `regionID`, `subscriptionID`, and `requestID`.
61+
- Message strings should not include function names and should avoid `-` (use spaces instead).
62+
- Avoid per-object or per-iteration logs, duplicated logs on the same error path, large objects, raw payloads, and long error dumps in default logs.
63+
- Use metrics for counts, scale, frequency, and trends; use windowed summaries or representative samples for high-cardinality events.
64+
- Before adding, keeping, or rewriting a log, verify that it answers a real diagnostic question, identifies the object, reason, action, and impact, and will not grow linearly with object count or retry/loop frequency.
3065

3166
## Testing Guidelines
3267

3368
- Unit tests: `*_test.go`, favor deterministic tests; use `testify/require`.
69+
- Unit tests should cover meaningful behavior only; avoid redundant or low-value cases.
70+
- Do not test across feature boundaries. Keep each test focused on the behavior owned by the package or component under test.
71+
- Reuse existing tests when possible. Add a new test only when reuse would make the existing test unclear or incomplete.
72+
- If several test functions are highly related, merge them into one concise table-driven or scenario-based test.
73+
- When a test needs mocked components, prefer existing gomock-generated mocks over handwritten mocks. If the required mock does not exist, add it to the mock generation flow and run `make generate_mock`.
74+
- Keep tests efficient, simple, focused, and easy to update.
3475
- Failpoints: `make unit_test` enables/disables automatically. If you enable manually, disable before committing to avoid a dirty tree.
76+
- For documentation-only changes, unit tests are usually unnecessary. If tests are skipped, state in the final response that only documentation was changed.
3577

3678
## Commit & Pull Request Guidelines
3779

0 commit comments

Comments
 (0)