docs(agents): 补充文档与注释规范
All checks were successful
CI/CD / Verify and Deploy (push) Successful in 1m31s
All checks were successful
CI/CD / Verify and Deploy (push) Successful in 1m31s
新增 `## Documentation`:文档描述代码,不是规范。冲突时先改文档。禁止用行号定位代码,改为文件路径加稳定符号。 新增 `## Code Comments`:注释只写代码说不出的原因。禁止复述代码、重复函数名、变更日志。一到两行是预算。
This commit is contained in:
26
AGENTS.md
26
AGENTS.md
@@ -249,6 +249,32 @@ The MySQL fixtures each `DropTable` + `AutoMigrate` the shared schema, so run mo
|
|||||||
- A new test that needs to reach into private fields, sleep for seconds, or start a container usually means the unit boundary is wrong — fix the design (inject the dependency) instead of adding scaffolding.
|
- A new test that needs to reach into private fields, sleep for seconds, or start a container usually means the unit boundary is wrong — fix the design (inject the dependency) instead of adding scaffolding.
|
||||||
- When a test starts failing "because the environment changed", check whether it was ever deterministic before editing it.
|
- When a test starts failing "because the environment changed", check whether it was ever deterministic before editing it.
|
||||||
|
|
||||||
|
## Documentation
|
||||||
|
|
||||||
|
Design docs live in `docs/design/` and are written in Chinese. They describe what the code does and why. They are not a spec the code must satisfy: when a doc and the code disagree, the doc is wrong until proven otherwise — fix the doc first, and change code only if the code is actually broken.
|
||||||
|
|
||||||
|
**Never locate code by line number.** Line numbers drift on every edit, so `service.go:496` is wrong within a week. Cite the file plus a stable symbol instead:
|
||||||
|
|
||||||
|
- good: `backend/internal/feed/service.go` 的 `listByHotWindowRedis`
|
||||||
|
- good: `backend/internal/feed/service.go` 的 `hotSnapshotTTL`
|
||||||
|
- good: test name `TestListByPopularity_StaleAsOfIsReplaced`
|
||||||
|
- good: an exact string, e.g. the log line `feed: expire hot snapshot %s failed, dropping it`
|
||||||
|
- bad: `backend/internal/feed/service.go:496-532`
|
||||||
|
|
||||||
|
Inside a code excerpt, the header comment names the file only — the block already shows which function it is. When a paragraph already names the symbol, do not add a path for it.
|
||||||
|
|
||||||
|
Keep each doc current in the same change that touches the behavior it describes. Prefer a table or a short excerpt over prose that repeats the code.
|
||||||
|
|
||||||
|
## Code Comments
|
||||||
|
|
||||||
|
Comments carry the *why* the code cannot say: an invariant, a non-obvious tradeoff, a failure mode, a deliberate omission. Everything else is noise, and noise is what makes real comments invisible.
|
||||||
|
|
||||||
|
- Do not restate the code. No `// 遍历 videos`, no comment that repeats the function name, no changelog (`// 新增于 X`), no attribution.
|
||||||
|
- One short paragraph is the budget, usually one or two lines. If a comment needs five lines to justify a two-line block, rename or restructure the code instead.
|
||||||
|
- Keep the ones that encode a reason: `// RENAMENX 把临时键的 1 分钟 TTL 带给了 dest` earns its line; `// 返回响应` does not.
|
||||||
|
- Write in the file's language — Chinese in `backend/`, matching the surrounding file.
|
||||||
|
- The same limit applies to test intent comments: one sentence saying why the invariant exists, not a recount of the bug.
|
||||||
|
|
||||||
## Commit Messages
|
## Commit Messages
|
||||||
|
|
||||||
Commit messages are Chinese, `type(scope): subject`, and written to the structural rules of ASD-STE100 — target roughly 80 %, which means the text reads simply. This is not a certified STE document; it is a readability standard with two hard parts: short sentences, and terms kept exactly as the code spells them.
|
Commit messages are Chinese, `type(scope): subject`, and written to the structural rules of ASD-STE100 — target roughly 80 %, which means the text reads simply. This is not a certified STE document; it is a readability standard with two hard parts: short sentences, and terms kept exactly as the code spells them.
|
||||||
|
|||||||
Reference in New Issue
Block a user