# 贡献指南

> codeweb 的开发流程、测试纪律与提交前门禁。

---

LLMS 索引： [llms.txt](/codeweb/zh/llms.txt)

---

## 仓库结构 {#repository-layout}

codeweb 是单一 Rust crate，按 feature 划分使用面(`cli`、`tui`、`serve`、`mcp`、`jsp`、`java`、`analyze`、`search-sql-v2`;`full` 为全开)。没有 workspace:动手前先确认改动落在哪个模块、哪个 feature 下。SQL 解析位于独立的 [ogsql-parser](https://github.com/c2j/ogsql-parser) crate。

## 测试纪律 {#test-discipline}

本仓库采用测试驱动开发，一次循环只锁定一个行为:

1. **Red** —— 先写会失败的行为测试。因 API 尚不存在导致的编译失败也算合法 red。
2. **Green** —— 只写让测试通过的最少实现;禁止放宽断言换绿。
3. **Refactor** —— 相关测试全绿后再重构，范围限于当前改动路径。

review 会强制执行的规则:

- 不删除、跳过、弱化已有测试来让改动通过。
- 测试名描述行为(`should_reject_negative_amount`)。
- 改遗留路径前先写特征测试锁定当前行为。
- 你的改动弄坏了已有测试时修实现;除非写测试的人明确要求，否则不改测试。

## 提交前门禁 {#pre-commit-gates}

与 CI 完全一致:

```bash
cargo fmt --all -- --check
cargo clippy --features full -- -D warnings
cargo test --features full -- --skip test_path_mapping_applied --skip test_serve_
```

- 只要改动可能影响 feature 门控代码(例如新增被其他 feature match 的枚举变体),`cargo build --features full` 就必须编译通过。
- 被跳过的测试是 CI 有意的环境相关跳过;本地裸跑 `cargo test --features full` 时 `test_serve_*` 失败属于已知限制，确认你的改动没有让它更糟即可。

## 提交变更 {#submitting-changes}

1. 从 `main` 创建 feature 分支。
2. 在门禁全绿的状态下提交。
3. Push 并创建 pull request。
4. 由维护者 review 并合并;贡献者不自行合并自己的 PR。
