Files
sub-store/AGENTS.md
T
rogee cec95ff4e8 test: add comprehensive unit tests — coverage 20.2% → 91.8%
Add 12 test files covering all internal packages:

- internal/util/util_test.go (97.2%)
- internal/model/model_test.go (100.0%)
- internal/config/config_test.go (88.1%)
- internal/template/builtin_test.go (98.8%)
- internal/middleware/middleware_test.go (98.7%)
- internal/database/repo_extra_test.go (85.5%)
- internal/rules/converter_test.go (99.1%)
- internal/service/subscription_test.go (75.7%)
- internal/handler/handler_test.go (90.6%)
- internal/filter/filter_extra_test.go (91.9%)
- internal/proxy/client_parser_test.go (96.1%)
- internal/render/render_extra_test.go (99.2%)

Overall: 91.8% (4033/4400 statements) — exceeds 85% acceptance threshold.
All tests pass, go vet clean, go build clean.
2026-07-27 16:12:28 +08:00

63 lines
3.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
SUB STORE 项目重构
`ref/sub-store-cloudflare` 是一个使用cloudflare部署的机场订阅转换助手,我们需要参考原项目,完成GO语言、SQLITE数据库的重构。
## 项目约束
- **全新项目,无历史数据包袱**:不存在存量用户、存量配置、存量过滤器需要迁移。所有"向后兼容"、"存量 script 过滤器迁移"、"process→FilterRule 转换"等问题均不需要考虑——直接按 Go 版自身的设计实现即可,不必复刻原项目的兼容逻辑。
- **ProxyNode 类型自由选择**:不强制与原项目 `Record<string, unknown>` 保持一致,按 Go 最佳实践选择 struct 或 map。
- **前端适配后端**:前端尚未实现,后端 API 设计可自由定义,不需要兼容原前端格式。
## 开发决议
开发前必读 [`docs/review-resolutions.md`](docs/review-resolutions.md) — 45 条 review 问题的逐条决议(ProxyNode 类型、token 双哈希、SQLite PRAGMA、sing-box 完整结构等)。开发中不得偏离已定决议;如需变更,先改本文档再改代码。
**关键决议摘要**
- ProxyNode = `map[string]any`,深拷贝用 json.Marshal/Unmarshal
- token 校验先 SHA-256 再 ConstantTimeCompare(防长度泄露时序攻击)
- SQLite: WAL + busy_timeout=5000 + foreign_keys=ON + MaxOpenConns=1
- CSP 收紧为 `script-src 'self'`(无 unsafe-eval
- custom 规则链上限 32 条,替代 JS script 过滤器
- modernc.org/sqlite(纯 Go),接受写性能 tradeoff
## 验收标准
- 单元测试覆盖率 ≥ 85%
<!-- CODEGRAPH_START -->
## CodeGraph
This project has a CodeGraph MCP server (`codegraph_*` tools) configured. CodeGraph is a tree-sitter-parsed knowledge graph of every symbol, edge, and file. Reads are sub-millisecond and return structural information grep cannot.
### When to prefer codegraph over native search
Use codegraph for **structural** questions — what calls what, what would break, where is X defined, what is X's signature. Use native grep/read only for **literal text** queries (string contents, comments, log messages) or after you already have a specific file open.
| Question | Tool |
| --------------------------------------------- | ------------------- |
| "Where is X defined?" / "Find symbol named X" | `codegraph_search` |
| "What calls function Y?" | `codegraph_callers` |
| "What does Y call?" | `codegraph_callees` |
| "What would break if I changed Z?" | `codegraph_impact` |
| "Show me Y's signature / source / docstring" | `codegraph_node` |
| "Give me focused context for a task/area" | `codegraph_context` |
| "Survey an unfamiliar module/topic" | `codegraph_explore` |
| "What files exist under path/" | `codegraph_files` |
| "Is the index healthy?" | `codegraph_status` |
### Rules of thumb
- **Trust codegraph results.** They come from a full AST parse. Do NOT re-verify them with grep — that's slower, less accurate, and wastes context.
- **Don't grep first** when looking up a symbol by name. `codegraph_search` is faster and returns kind + location + signature in one call.
- **Don't chain `codegraph_search` + `codegraph_node`** when you just want context — `codegraph_context` is one call.
- **`codegraph_explore` is the heavy hitter** for unfamiliar areas — it returns full source from all relevant files in one call, but is token-heavy. If your harness supports parallel subagents (e.g., Claude Code's Task tool), spawn one for explore-class questions to keep main session context clean.
- **Index lag**: the file watcher debounces ~500ms behind writes; don't re-query immediately after editing a file in the same turn.
### If `.codegraph/` doesn't exist
The MCP server returns "not initialized." Ask the user: _"I notice this project doesn't have CodeGraph initialized. Want me to run `codegraph init -i` to build the index?"_
<!-- CODEGRAPH_END -->