trae-coding-engine 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +91 -0
- package/bin/coding-engine.js +16 -0
- package/lib/cli.js +86 -0
- package/lib/index.js +6 -0
- package/lib/setup.js +290 -0
- package/package.json +32 -0
- package/templates/.agents/skills/coding-architecture/SKILL.md +347 -0
- package/templates/.agents/skills/coding-code-review/SKILL.md +95 -0
- package/templates/.agents/skills/coding-cve-remediation/SKILL.md +163 -0
- package/templates/.agents/skills/coding-db-schema/SKILL.md +273 -0
- package/templates/.agents/skills/coding-deploy-config/SKILL.md +129 -0
- package/templates/.agents/skills/coding-docs-audit/SKILL.md +285 -0
- package/templates/.agents/skills/coding-docs-audit-autofix/SKILL.md +33 -0
- package/templates/.agents/skills/coding-http-api/SKILL.md +269 -0
- package/templates/.agents/skills/coding-issue-autodev/SKILL.md +172 -0
- package/templates/.agents/skills/coding-merge-request/SKILL.md +199 -0
- package/templates/.agents/skills/coding-observability/SKILL.md +193 -0
- package/templates/.agents/skills/coding-refactor-insight/SKILL.md +89 -0
- package/templates/.agents/skills/coding-release-merge/SKILL.md +224 -0
- package/templates/.agents/skills/coding-runtime-adapter/SKILL.md +115 -0
- package/templates/.agents/skills/coding-testing/SKILL.md +169 -0
- package/templates/AGENTS.md +179 -0
- package/templates/MR-Template-Default.md +33 -0
- package/templates/Makefile +370 -0
- package/templates/REGISTRY.md +53 -0
- package/templates/scripts/check-adr.sh +283 -0
- package/templates/scripts/check-comment-i18n.py +209 -0
- package/templates/scripts/check-comment-i18n.sh +38 -0
- package/templates/scripts/check-doc-refs.sh +40 -0
- package/templates/scripts/check-docs.sh +103 -0
- package/templates/scripts/check-go-names.sh +59 -0
- package/templates/scripts/check-iam-actions.py +126 -0
- package/templates/scripts/check-migration-sql-immutability.sh +232 -0
- package/templates/scripts/check-mr-desc.sh +165 -0
- package/templates/scripts/check-mr-size.sh +128 -0
- package/templates/scripts/check-mr-title.sh +123 -0
- package/templates/scripts/check-openapi.py +221 -0
- package/templates/scripts/check-rdb-structured-queries.sh +98 -0
- package/templates/scripts/check-repository-transactions.sh +100 -0
- package/templates/scripts/check-runbooks.sh +229 -0
- package/templates/scripts/check-skill-router-sync.py +331 -0
- package/templates/scripts/check-skills.sh +243 -0
- package/templates/scripts/docs-audit-to-issues.py +373 -0
- package/templates/scripts/docs-verification-reminder.sh +63 -0
- package/templates/scripts/find-ci-failures.sh +133 -0
- package/templates/scripts/find-stale-mrs.sh +72 -0
- package/templates/scripts/gen-adr-index.sh +122 -0
- package/templates/scripts/open-mr.sh +536 -0
- package/templates/scripts/regen-agent-md.sh +149 -0
- package/templates/scripts/run-mr-hygiene.sh +140 -0
- package/templates/scripts/runbook.sh +91 -0
- package/templates/scripts/self-maintenance-digest.py +125 -0
- package/templates/scripts/send-self-maintenance-lark-card.py +116 -0
- package/templates/scripts/skill-graph.sh +114 -0
- package/templates/scripts/skill-impact.sh +134 -0
- package/templates/scripts/skill-propose.sh +302 -0
- package/templates/scripts/skill-router-hook.sh +152 -0
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: coding-release-merge
|
|
3
|
+
description: Use when merging the latest release branch into the current coding_engine feature branch, resolving conflicts, and reconciling newly introduced shared conventions such as API contracts, error handling rules, common helpers, config patterns, or cross-cutting refactors across both sides of the merge.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# coding-release-merge: Merge Latest Release Safely
|
|
7
|
+
|
|
8
|
+
用于把最新 release 分支合入当前工作分支。重点不是只解决文本冲突,而是识别 release 新增的通用逻辑变化,并把当前分支和 release 侧代码都拉到同一套规范上。
|
|
9
|
+
|
|
10
|
+
## Trigger
|
|
11
|
+
|
|
12
|
+
用户要求“合并 release / 拉最新 release / merge 最新发布分支 / 同步 release 代码 / rebase release 分支代码”时加载。
|
|
13
|
+
|
|
14
|
+
如果 merge 涉及测试、HTTP API、部署配置、DB schema、runtime adapter 等路径,继续加载 `AGENTS.md` Skill Router 中对应的领域 skill。任何代码修改仍触发 `coding-testing`。
|
|
15
|
+
|
|
16
|
+
## Non-Negotiables
|
|
17
|
+
|
|
18
|
+
- 不要在未确认干净工作区前开始 merge;已有用户改动必须保护。
|
|
19
|
+
- 默认使用 `git merge --no-ff --no-commit`,即使没有文本冲突,也先执行通用逻辑巡检和测试,再决定提交。
|
|
20
|
+
- 不要用 `git reset --hard`、`git checkout -- <file>`、`git restore <file>` 丢弃用户改动,除非用户明确要求。
|
|
21
|
+
- 冲突解决不能只选择 ours/theirs;必须读双方意图,保留 release 的通用规范变更和当前分支的业务增量。
|
|
22
|
+
- 每个通用逻辑变化都要做“双向巡检”:release 新规范是否被当前分支违背;当前分支若本身在改通用规范,release 新代码是否违背。
|
|
23
|
+
|
|
24
|
+
## Workflow
|
|
25
|
+
|
|
26
|
+
### 1. Preflight
|
|
27
|
+
|
|
28
|
+
确认仓库状态和当前分支:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
git status --short
|
|
32
|
+
git branch --show-current
|
|
33
|
+
git rev-parse --show-toplevel
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
如果工作区不干净:
|
|
37
|
+
|
|
38
|
+
- 用户改动与 merge 无关:建议用户先 stash/commit;不要替用户丢弃。
|
|
39
|
+
- 用户改动正是本任务的一部分:继续前记录哪些文件已有改动,后续不要误判为 merge 产物。
|
|
40
|
+
|
|
41
|
+
### 2. Fetch and Select Release Ref
|
|
42
|
+
|
|
43
|
+
拉取远端 release 分支:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
git fetch --prune origin
|
|
47
|
+
git for-each-ref --sort=-committerdate --format='%(refname:short) %(committerdate:iso8601)' 'refs/remotes/origin/release*'
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
选择规则:
|
|
51
|
+
|
|
52
|
+
- 用户指定了 release ref:使用用户指定值。
|
|
53
|
+
- 存在单一集成分支 `origin/release`:默认使用它。
|
|
54
|
+
- 存在多个 `origin/release/*` 或 `origin/release-*`:选择 fetch 后 committerdate 最新的 release ref,并在回复中说明具体 ref。
|
|
55
|
+
- 无 release ref:停止并要求用户指定。
|
|
56
|
+
|
|
57
|
+
记录 merge 前锚点:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
BASE_HEAD=$(git rev-parse HEAD)
|
|
61
|
+
RELEASE_REF=<selected-release-ref>
|
|
62
|
+
RELEASE_TIP=$(git rev-parse "$RELEASE_REF")
|
|
63
|
+
MERGE_BASE=$(git merge-base HEAD "$RELEASE_REF")
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### 3. Inspect Incoming Release Changes
|
|
67
|
+
|
|
68
|
+
先看新拉下来的 commit message 和真实 diff,不要只依赖标题:
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
git log --oneline --decorate --no-merges "$MERGE_BASE..$RELEASE_REF"
|
|
72
|
+
git diff --stat "$MERGE_BASE..$RELEASE_REF"
|
|
73
|
+
git diff --name-only "$MERGE_BASE..$RELEASE_REF"
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
对可疑提交继续看细节:
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
git show --stat <commit>
|
|
80
|
+
git show --name-only <commit>
|
|
81
|
+
git show <commit> -- <path>
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
重点识别这些后端“通用逻辑变化”信号:
|
|
85
|
+
|
|
86
|
+
- API/IDL/handler contract:字段必选性、错误码、Action/Version、鉴权、TOP response envelope、`base.Error` 映射。
|
|
87
|
+
- 指针处理:`ptr.Of` / `ptr.To`、optional field、nil vs zero value、clone pointer、`optionalString` / `stringValue` / `cloneUUIDPtr` 等局部 helper。
|
|
88
|
+
- 分页处理:`PageInput` / `PageOutput`、`shared.PageRequest` / `shared.PageResult`、`NormalizePage`、`paginateCount`、`normalizedLimit`、offset/limit 默认值。
|
|
89
|
+
- request context:`requestctx.*FromContext`、`requestctx.With*`、rdb repository `rdb.DB(ctx, ...)` / `conn(ctx)`、`AgentIdentityFromContext`、tenant/workspace/user/action/version 解析规则。
|
|
90
|
+
- 错误处理规范:`errno.Ensure`、`errno.Wrap`、`errno.NewWithMessage`、dependency 分类 helper、状态码映射、handler 的 `toHTTPError`。
|
|
91
|
+
- 参数校验:`validate.Struct` / `validate.Required`、handler/application 局部 `invalid`、`requiredUUID`、`validateScope`、K8s quantity / JSON config validation。
|
|
92
|
+
- UUID / ID:`pkg/platform/uuid` 的 `New` / `Parse` / `MustParse` / `IsZero` / `Unique`,以及 UUID 字符串转换 helper。
|
|
93
|
+
- logger / observability context:`logger.WithContextFields`、`logger.ContextFields`、`logger.String` / `logger.Err` 等 field helper,metrics/log 语义变化。
|
|
94
|
+
- retry/backoff:`retry.Do`、`retry.Permanent`、attempts/ctx deadline、transient vs permanent error 分类。
|
|
95
|
+
- config / DB normalize:`config.LoadYAML` strict decode、`gormdb.NormalizeConfig`、`NormalizeType`、`Endpoint`、DSN/parameter/default port 规则。
|
|
96
|
+
- mapper / clone / conversion:RDB mapper、`MapSlice`、DTO/domain/PO conversion、`rawJSON` / `rawJSONPtr`、slice/map/json/time clone 与 formatting helper。
|
|
97
|
+
- 命名/资源名规范:`shared.NormalizeName`、Hermes/K8s `SanitizeName` / `InstanceName` / `SecretName` / `LabelValue`、label/resource length 限制。
|
|
98
|
+
- 架构边界:port/interface 变化、ServiceDeps、fx wiring、adapter contract。
|
|
99
|
+
- 配置/部署规范:Secret vs ConfigMap、DSN、probe/service port、默认值、镜像字段。
|
|
100
|
+
- 数据/持久化规范:GORM PO、AutoMigrate owner、soft delete、repository parity、transaction context。
|
|
101
|
+
- 测试规范:mock 生成、table-driven pattern、race/miniredis/testcontainers 约束。
|
|
102
|
+
|
|
103
|
+
产出一个短清单:
|
|
104
|
+
|
|
105
|
+
```markdown
|
|
106
|
+
Incoming shared changes:
|
|
107
|
+
- <commit/path>: <inferred rule> -> <affected local search terms>
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
常用搜索入口:
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
rg 'ptr\.Of|ptr\.To|optionalString|stringValue|clone.*Ptr|nil \|\| .*IsZero' internal pkg --glob '*.go'
|
|
114
|
+
rg 'PageInput|PageOutput|PageRequest|PageResult|NormalizePage|paginateCount|normalizedLimit|Offset\(|Limit\(' internal pkg --glob '*.go'
|
|
115
|
+
rg 'FromContext|With.*Context|rdb\.DB\(ctx|conn\(ctx\)|AgentIdentityFromContext|TenantID|WorkspaceID|UserFromContext' internal pkg --glob '*.go'
|
|
116
|
+
rg 'errno\.Ensure|errno\.Wrap|errno\.NewWithMessage|toHTTPError|ErrInvalidArgument|ErrPersistenceError' internal pkg --glob '*.go'
|
|
117
|
+
rg 'validate\.Struct|validate\.Required|requiredUUID|validateScope|invalid\(' internal pkg --glob '*.go'
|
|
118
|
+
rg 'uuid\.New|uuid\.Parse|uuid\.MustParse|uuid\.IsZero|uuid\.Unique' internal pkg --glob '*.go'
|
|
119
|
+
rg 'logger\.WithContextFields|logger\.ContextFields|logger\.(String|Err|Int|Bool|Any)' internal pkg --glob '*.go'
|
|
120
|
+
rg 'retry\.Do|retry\.Permanent|NormalizeConfig|LoadYAML|MapSlice|rawJSON|cloneString|SanitizeName|InstanceName|SecretName|LabelValue' internal pkg --glob '*.go'
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### 4. Merge Without Committing
|
|
124
|
+
|
|
125
|
+
```bash
|
|
126
|
+
git merge --no-ff --no-commit "$RELEASE_REF"
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
如果出现冲突:
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
git status --short
|
|
133
|
+
git diff --name-only --diff-filter=U
|
|
134
|
+
git diff --cc -- <conflicted-path>
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
解决顺序:
|
|
138
|
+
|
|
139
|
+
1. 先解决接口、domain/application contract、config/schema 这类上游约束。
|
|
140
|
+
2. 再解决 adapters/bootstrap/web 这类下游适配。
|
|
141
|
+
3. 最后解决测试、文档、生成物。
|
|
142
|
+
|
|
143
|
+
每个冲突文件都要回答:
|
|
144
|
+
|
|
145
|
+
- release 侧是否引入了新规范?
|
|
146
|
+
- 当前分支的业务改动是否还成立?
|
|
147
|
+
- 合并结果是否同时满足新规范和当前分支目标?
|
|
148
|
+
|
|
149
|
+
### 5. Shared Logic Reconciliation
|
|
150
|
+
|
|
151
|
+
这是本 skill 的核心检查。
|
|
152
|
+
|
|
153
|
+
#### A. Release introduced shared rule
|
|
154
|
+
|
|
155
|
+
如果 `MERGE_BASE..RELEASE_REF` 中包含通用逻辑变化,对当前分支新增/修改代码做 targeted grep:
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
git diff --name-only "$MERGE_BASE..HEAD"
|
|
159
|
+
rg '<old-helper|old-error-pattern|old-field|old-action|old-config-key>' <candidate-paths>
|
|
160
|
+
rg '<new-helper|new-error-pattern|new-field|new-action|new-config-key>' <candidate-paths>
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
修复所有当前分支仍违背 release 新规范的地方。不要只修冲突文件;非冲突文件也可能违背。
|
|
164
|
+
|
|
165
|
+
#### B. Current branch changes shared rule
|
|
166
|
+
|
|
167
|
+
如果当前分支本来就在改通用逻辑,对 release 新引入代码做反向检查:
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
git diff --name-only "$MERGE_BASE..$RELEASE_REF"
|
|
171
|
+
rg '<current-branch-new-rule-or-helper>' <release-touched-paths>
|
|
172
|
+
rg '<deprecated-rule-or-helper>' <release-touched-paths>
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
修复 release 新代码中仍使用旧规范的地方,确保 merge 后整个工作树一致。
|
|
176
|
+
|
|
177
|
+
#### C. Cross-layer consistency
|
|
178
|
+
|
|
179
|
+
按变更面加载对应 skill 并执行其 gate:
|
|
180
|
+
|
|
181
|
+
- API/handler/IDL:`coding-http-api`
|
|
182
|
+
- tests:`coding-testing`
|
|
183
|
+
- deploy/config/runtime config:`coding-deploy-config`
|
|
184
|
+
- DB schema/GORM PO:`coding-db-schema`
|
|
185
|
+
- runtime provider:`coding-runtime-adapter`
|
|
186
|
+
- observability:`coding-observability`
|
|
187
|
+
- domain/application/ports:`coding-architecture`
|
|
188
|
+
|
|
189
|
+
若通用规则影响文档、API、配置或重要生命周期,执行 `AGENTS.md` Docs Verification Gate。
|
|
190
|
+
|
|
191
|
+
### 6. Validation
|
|
192
|
+
|
|
193
|
+
最少执行:
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
make test
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
按触发面追加:
|
|
200
|
+
|
|
201
|
+
- IDL changed:`make gen-thrift`,再跑相关测试。
|
|
202
|
+
- generated mocks changed:`make generate`,再跑相关测试。
|
|
203
|
+
- skill changed:`make check-skills` 和 `make check-agent-md`。
|
|
204
|
+
- deploy/config changed:按 `coding-deploy-config` 的渲染/grep gate。
|
|
205
|
+
|
|
206
|
+
如果测试失败,先判断是否由 merge 结果或通用规范迁移造成;不要把失败简单归咎于 release。
|
|
207
|
+
|
|
208
|
+
### 7. Final Report
|
|
209
|
+
|
|
210
|
+
最终回复必须包含:
|
|
211
|
+
|
|
212
|
+
- 使用的 release ref 和 tip commit。
|
|
213
|
+
- 冲突文件列表,或说明无文本冲突。
|
|
214
|
+
- 识别到的通用逻辑变化及采取的双向修复。
|
|
215
|
+
- 运行过的验证命令和结果。
|
|
216
|
+
- 是否已提交;默认未提交时说明 merge 处于待提交状态。
|
|
217
|
+
|
|
218
|
+
如果需要提交,commit title 使用 repo whitelist scope,例如:
|
|
219
|
+
|
|
220
|
+
```text
|
|
221
|
+
merge: release into <branch>
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
或在发生实质修复时使用更具体的 conventional commit scope,例如 `fix:http-api`、`fix:config`、`refactor:runtime`。
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: coding-runtime-adapter
|
|
3
|
+
description: Use when adding a new runtime provider to coding_engine, modifying runtime adapter code under `internal/adapters/outbound/{hermes,workspacejob}/**`, or changing worker provider registry wiring.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# coding-runtime-adapter: Runtime Adapter Pattern
|
|
7
|
+
|
|
8
|
+
## The Quad
|
|
9
|
+
|
|
10
|
+
Every runtime provider is exactly four files in `internal/adapters/outbound/<name>/`:
|
|
11
|
+
|
|
12
|
+
| File | Interface | Responsibility |
|
|
13
|
+
|------|-----------|----------------|
|
|
14
|
+
| `executor.go` | `runtime.AgentExecutor` | Prepare + Run + Cancel + Health |
|
|
15
|
+
| `controller.go` | `runtime.RuntimeController` | K8s lifecycle (upsert/stop/delete/refresh/view) |
|
|
16
|
+
| `apikey.go` / `token.go` | — | Credential cache backed by K8s Secret |
|
|
17
|
+
| `discovery.go` | — | Derive HTTP/WS endpoint from tenantID+agentID (stateless) |
|
|
18
|
+
|
|
19
|
+
Supporting files: `helpers.go`, `errors.go`, `statefulset_builder.go` or `crd.go`, `api_client.go` or `pool.go`.
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
## Pattern Files (read when implementing each component)
|
|
23
|
+
|
|
24
|
+
| Component | Pattern file |
|
|
25
|
+
|-----------|-------------|
|
|
26
|
+
| Executor | `.agents/skills/coding-runtime-adapter/patterns/p1-executor.md` |
|
|
27
|
+
| Controller | `.agents/skills/coding-runtime-adapter/patterns/p2-controller.md` |
|
|
28
|
+
| Credential Manager | `.agents/skills/coding-runtime-adapter/patterns/p3-credential-manager.md` |
|
|
29
|
+
| Discovery | `.agents/skills/coding-runtime-adapter/patterns/p4-discovery.md` |
|
|
30
|
+
|
|
31
|
+
## Templates (copy and adapt)
|
|
32
|
+
|
|
33
|
+
| Need | Template |
|
|
34
|
+
|------|----------|
|
|
35
|
+
| Naming helpers (InstanceName, SecretName, SanitizeName) | `.agents/skills/coding-runtime-adapter/templates/helpers.go` |
|
|
36
|
+
| CredentialManager with singleflight + RWMutex | `.agents/skills/coding-runtime-adapter/templates/credential_manager.go` |
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
## Naming Helpers (quick ref)
|
|
40
|
+
|
|
41
|
+
```go
|
|
42
|
+
InstanceName(tenantID, agentID) → "xxx-<tenant>-<agent>" // DNS-1123 safe
|
|
43
|
+
SecretName(tenantID, agentID) → "xxx-cred-<tenant>-<agent>"
|
|
44
|
+
LabelValue(s) → truncated to 63 chars
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Each adapter package is standalone — copy `helpers.go` into your package, don't import from hermes.
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
## Deployment Config Sync Projection
|
|
51
|
+
|
|
52
|
+
If a runtime adapter config struct or `RegistryConfig` mirror changes, load
|
|
53
|
+
`coding-deploy-config` and reconcile the worker runtime surfaces there. Keep
|
|
54
|
+
this skill focused on runtime mechanics, not Helm/YAML/Secret policy.
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
## RegistryConfig Extension
|
|
58
|
+
|
|
59
|
+
`internal/bootstrap/worker/registry.go`:
|
|
60
|
+
```go
|
|
61
|
+
type RegistryConfig struct {
|
|
62
|
+
Namespace string
|
|
63
|
+
Hermes hermes.Config // image + storage class + storage size
|
|
64
|
+
WorkspaceSync runtime.WorkspaceSyncConfig
|
|
65
|
+
PlatformMCPTokenIssuer hermes.TokenIssuerConfig
|
|
66
|
+
// Xxx xxx.Config // add per-provider config struct here
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Add `XxxImage` only when the provider needs a pinned image. Guard in `ProvideProviderRegistry`:
|
|
71
|
+
```go
|
|
72
|
+
if cfg.XxxImage == "" { return nil, fmt.Errorf("XxxImage is required") }
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
## Wiring Checklist (`bootstrap/worker/registry.go`)
|
|
77
|
+
|
|
78
|
+
- [ ] Add `EngineKindXxx EngineKind = "xxx"` to `internal/domain/shared/enums.go`
|
|
79
|
+
- [ ] Add `XxxImage string` to `RegistryConfig` if needed; add guard
|
|
80
|
+
- [ ] Instantiate: `credMgr → discovery → client/pool → executor → controller`
|
|
81
|
+
- [ ] `reg.Register(shared.EngineKindXxx, executor, controller)`
|
|
82
|
+
|
|
83
|
+
```go
|
|
84
|
+
xxxCredMgr := xxx.NewCredManager(k8sClient, cfg.Namespace)
|
|
85
|
+
xxxDiscovery := xxx.NewDiscovery(cfg.Namespace)
|
|
86
|
+
xxxClient := xxx.NewAPIClient()
|
|
87
|
+
xxxExecutor := xxx.NewExecutor(xxxCredMgr, xxxDiscovery, xxxClient)
|
|
88
|
+
xxxCtrl := xxx.NewController(dynClient, k8sClient, cfg.Namespace, xxxCredMgr, xxxDiscovery, cfg.XxxImage)
|
|
89
|
+
reg.Register(shared.EngineKindXxx, xxxExecutor, xxxCtrl)
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
## Existing Providers Quick Reference
|
|
94
|
+
|
|
95
|
+
| | Hermes |
|
|
96
|
+
|--|--------|
|
|
97
|
+
| `EngineKind` | `"hermes"` |
|
|
98
|
+
| Transport | HTTP SSE (`api_client.go` / `sse.go`) |
|
|
99
|
+
| Workload | `StatefulSet` + `ClusterIP Service` |
|
|
100
|
+
| Credential | `hermes-apikey-*` Secret |
|
|
101
|
+
| `OnAgentStop` | scale replicas to 0 |
|
|
102
|
+
| Port | 8642 (http) |
|
|
103
|
+
| Image / storage in RegistryConfig | `Hermes hermes.Config` |
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
## Common Mistakes
|
|
107
|
+
|
|
108
|
+
| Mistake | Fix |
|
|
109
|
+
|---------|-----|
|
|
110
|
+
| `Kind()` returns wrong string | Must equal `EngineKind` constant value exactly |
|
|
111
|
+
| `Run()` skips type-assert on `p.Conn()` | Always assert; return `runtime.ErrInvalidPreparedRun` on failure |
|
|
112
|
+
| Cache key uses only `agentID` | Must include `tenantID` — multiple tenants share one namespace |
|
|
113
|
+
| Deleting K8s resources in wrong order | workload → Service → PVC → Secret |
|
|
114
|
+
| `"latest"` as image tag in RegistryConfig | Guard with explicit empty-string check |
|
|
115
|
+
| Forgetting `Evict` in `OnAgentDelete` | Causes credential leak across agent lifecycle |
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: coding-testing
|
|
3
|
+
description: Use when writing, reviewing, fixing, or running any test in coding_engine, including unit tests, integration tests, external-service manual checks, and deployed-environment coverage (E2E P0/P1/P2 smoke & regression, DFX stability/load, Eval quality). There is no QA team — Claude owns test correctness. Covers which strategy applies to each layer, required tooling, mandatory test run commands, and what "done" means before marking work complete.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# coding-testing: Testing Strategy (No QA — Claude Owns This)
|
|
7
|
+
|
|
8
|
+
## THE RULE
|
|
9
|
+
|
|
10
|
+
**There is no QA team. Every feature, fix, and refactor ships with tests. Work is not done until tests pass.**
|
|
11
|
+
|
|
12
|
+
No exceptions. No "I'll add tests later." No "this is simple, it doesn't need tests."
|
|
13
|
+
|
|
14
|
+
> **Deployed-system coverage:** Black-box TOP/HTTP coverage against a deployed
|
|
15
|
+
> cluster lives under Strategy 6: `tests/e2e/` (P0/P1/P2 smoke & regression),
|
|
16
|
+
> `tests/dfx/` (stability/load/QPS), and `tests/eval/` (chat quality). Shell
|
|
17
|
+
> scenario suites have been retired — do not create new curl-based scenario
|
|
18
|
+
> scripts for routine smoke or regression.
|
|
19
|
+
>
|
|
20
|
+
> **Repository gate fixtures:** `scripts/test/*.test.sh` files test CI /
|
|
21
|
+
> repository-governance scripts, not product Go behavior. Run them with
|
|
22
|
+
> `make test-scripts`; `make check` is the umbrella CI gate that includes them.
|
|
23
|
+
> Do not wire `make test-scripts` into `make test`; keep `make test` focused on
|
|
24
|
+
> `go test -race ./...`.
|
|
25
|
+
>
|
|
26
|
+
> **External service tests:** tests that call real third-party SaaS / OpenTOP / cloud services use `//go:build external` and files named `*_external_test.go`. They are manual developer checks only: run the specific package or test with `go test -tags=external ...` when credentials are available. Do not add a shared Make target, and do not wire them into CI, `make test`, or `make check`.
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
## Step 1 — Identify your strategy
|
|
30
|
+
|
|
31
|
+
First decide whether the test calls a real third-party service. If yes, use the
|
|
32
|
+
`external` convention above (`//go:build external`, `*_external_test.go`, manual
|
|
33
|
+
`go test -tags=external ...`). If the test calls a deployed coding cluster over
|
|
34
|
+
TOP/HTTP (including E2E smoke/regression, DFX load/stability, or Eval quality),
|
|
35
|
+
use Strategy 6 with the corresponding build tag (`e2e`, `dfx`, or `eval`). The
|
|
36
|
+
numbered strategies below cover normal unit/integration tests; choose the
|
|
37
|
+
narrowest one that proves the behavior.
|
|
38
|
+
|
|
39
|
+
```
|
|
40
|
+
New code in... → Strategy
|
|
41
|
+
application/<domain>/service.go → 1
|
|
42
|
+
application/<domain>/ → 1
|
|
43
|
+
adapters/inbound/http/handlers/ → 4
|
|
44
|
+
adapters/outbound/openclaw/ → 2
|
|
45
|
+
adapters/outbound/llm/ → 2
|
|
46
|
+
application/evolution/acl/ → 1 (in-process cross-context ACL adapters, ADR 0058)
|
|
47
|
+
adapters/outbound/runtimeregistry/ → 1
|
|
48
|
+
adapters/outbound/speccatalog/ → 1 (config-backed in-memory spec catalog)
|
|
49
|
+
adapters/outbound/up/ → 2
|
|
50
|
+
adapters/outbound/artifact/ → 2 (ArtifactServer SDK adapter tests with fake / httptest)
|
|
51
|
+
adapters/outbound/arkskillhub/ → 2 (Ark Skill Hub HTTP adapter tests with fake / httptest)
|
|
52
|
+
adapters/outbound/aigw/ → 2 (AIGW SDK HTTP adapter tests with fake / httptest)
|
|
53
|
+
adapters/outbound/clawsentry/ → 2 (ClawSentry adapter tests with fake / httptest; real service checks use external)
|
|
54
|
+
adapters/outbound/hiagent/ → 2 (HiAgent HTTP TOP adapter tests with fake / httptest)
|
|
55
|
+
adapters/outbound/mcp/ → 2 (MCP client transports)
|
|
56
|
+
adapters/outbound/<other-runtime>/ → 2
|
|
57
|
+
adapters/outbound/hermes/ → 2
|
|
58
|
+
adapters/outbound/secretcodec/ → 2 (crypto-backed secret adapter)
|
|
59
|
+
adapters/outbound/volcid/ → 2 (Volcengine ID SDK adapter tests with fake / httptest)
|
|
60
|
+
adapters/outbound/iam/ → 2 (IAM SDK adapter tests with fake / httptest)
|
|
61
|
+
adapters/outbound/workspacejob/ → 2 (Kubernetes Job helper)
|
|
62
|
+
adapters/outbound/channels/ → 2 (HTTP integrations — feishu, wecom)
|
|
63
|
+
adapters/outbound/media/ → 2 (shared media utils — STT HTTP client, MIME/tag, inbound file processor)
|
|
64
|
+
adapters/outbound/diagnostics/ → 2 (coding doctor checkers — rdb via injected openDB fake, redis via miniredis)
|
|
65
|
+
adapters/outbound/metricquery/ → 2 (Prometheus-compatible HTTP query adapters with httptest)
|
|
66
|
+
adapters/outbound/metrics/ → 2 (OTel/metrics outbound adapters with fake reader or httptest)
|
|
67
|
+
adapters/outbound/echo/ → 1 (in-process placeholder runtime)
|
|
68
|
+
adapters/outbound/queue/ → 3 (redisstreams — miniredis)
|
|
69
|
+
adapters/outbound/eventbus/rediseventbus/ → 3
|
|
70
|
+
adapters/outbound/messagebus/redismessagebus/ → 3
|
|
71
|
+
adapters/outbound/presence/ → 3 (miniredis — Redis-backed presence registry, ADR 0018)
|
|
72
|
+
adapters/outbound/gatewaypresence/ → 3 (miniredis — Redis ZSET live-instance set for the gateway multi-replica guard, ADR 0086)
|
|
73
|
+
adapters/outbound/ownership/ → 3 (miniredis — Redis SSE-ownership registry + pub/sub backplane for the gateway ownership fabric, ADR 0086)
|
|
74
|
+
adapters/outbound/sessionlease/ → 3 (miniredis — Redis-backed session lease + Lua scripts, ADR 0025)
|
|
75
|
+
adapters/outbound/sessionkeylock/ → 3 (Redis-backed session key uniqueness lock, ADR 0069)
|
|
76
|
+
adapters/outbound/lane/redislane/ → 3 (miniredis)
|
|
77
|
+
adapters/outbound/redismsgbus/ → 3 (miniredis)
|
|
78
|
+
adapters/outbound/lane/locallane/ → 1 (in-process channel)
|
|
79
|
+
adapters/outbound/messagebus/localmsgbus/ → 1 (in-process channel)
|
|
80
|
+
adapters/outbound/eventbus/localeventbus/ → 1 (in-process channel)
|
|
81
|
+
adapters/outbound/messagebus/middleware/ → 1 (message bus middleware — debug log decorator)
|
|
82
|
+
adapters/outbound/metering/ → 2 (HTTP push adapter)
|
|
83
|
+
adapters/outbound/persistence/postgres/ → 5
|
|
84
|
+
domain/<aggregate>/ → 1
|
|
85
|
+
pkg/platform/<util>/ → 1
|
|
86
|
+
pkg/platform/<util>/ → 1
|
|
87
|
+
bootstrap/ → 1
|
|
88
|
+
tests/e2e/ → 6 (deployed-environment E2E; P0 owns smoke)
|
|
89
|
+
tests/dfx/ → 6 (deployed-environment DFX: stability/load/QPS)
|
|
90
|
+
tests/eval/ → 6 (deployed-environment Eval: chat quality)
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
## Step 2 — Copy the template (if scaffolding a new file)
|
|
94
|
+
|
|
95
|
+
Do not write boilerplate from memory. Read and adapt the relevant template:
|
|
96
|
+
|
|
97
|
+
| Need | Template |
|
|
98
|
+
|------|----------|
|
|
99
|
+
| New repository dependency mock | Add `//go:generate go run go.uber.org/mock/mockgen ...` on the domain repository interface and run `make generate` |
|
|
100
|
+
| New `tests/integration/*_test.go` | `.agents/skills/coding-testing/templates/integration_test_setup.go` |
|
|
101
|
+
| New `export_test.go` for white-box access | `.agents/skills/coding-testing/templates/export_test.go` |
|
|
102
|
+
|
|
103
|
+
For integration tests, do not copy local DB / Redis container setup into the
|
|
104
|
+
test file. The integration suite owns shared fixtures in
|
|
105
|
+
`tests/integration/testutil/`; strategy 5 documents the required entry points.
|
|
106
|
+
|
|
107
|
+
## Step 3 — Read the detail file
|
|
108
|
+
|
|
109
|
+
After identifying your strategy, read the corresponding file:
|
|
110
|
+
|
|
111
|
+
| Strategy | File |
|
|
112
|
+
|----------|------|
|
|
113
|
+
| 1 — App service unit tests | `.agents/skills/coding-testing/strategies/s1-app-services.md` |
|
|
114
|
+
| 2 — K8s / HTTP adapter unit tests | `.agents/skills/coding-testing/strategies/s2-k8s-adapters.md` |
|
|
115
|
+
| 3 — Redis adapter tests | `.agents/skills/coding-testing/strategies/s3-redis.md` |
|
|
116
|
+
| 4 — HTTP handler tests | `.agents/skills/coding-testing/strategies/s4-http-handlers.md` |
|
|
117
|
+
| 5 — Integration / persistence tests | `.agents/skills/coding-testing/strategies/s5-integration.md` |
|
|
118
|
+
| 6 — Deployed-environment black-box (E2E/DFX/Eval) | `.agents/skills/coding-testing/strategies/s6-deployed-blackbox.md` |
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
## Commands
|
|
122
|
+
|
|
123
|
+
| Command | When |
|
|
124
|
+
|---------|------|
|
|
125
|
+
| `make test` | Always — `go test -race ./...` |
|
|
126
|
+
| `make test-scripts` | When `scripts/**` or `scripts/test/**` changes — offline fixture/workflow regression tests for CI and repository gate scripts; also covered by `make check` |
|
|
127
|
+
| `go test -tags=external ./<package> -run '<test regex>' -count=1` | Manual only, when intentionally validating one adapter against a real third-party service with local credentials |
|
|
128
|
+
| `go test -tags=integration ./tests/integration/... -run '^$'` | Any `persistence/rdb` repository, GORM PO, repository constructor/mapper, or Redis-backed code change — proves integration tests still compile |
|
|
129
|
+
| `go test -tags=integration ./tests/integration/<affected_file>_test.go -run '^$'` | Any integration test file changed — proves the file can be run directly without relying on sibling `_test.go` helpers |
|
|
130
|
+
| `go test -tags=integration ./tests/integration/... -run '<affected test regex>' -count=1 -parallel=2` | Any database repository or Redis-backed behavior change — run the corresponding integration tests against real DB/Redis testcontainers |
|
|
131
|
+
| `make test-e2e` | When validating deployed-environment TOP/HTTP behavior with `CODING_E2E_*` env configured |
|
|
132
|
+
| `CODING_E2E_REQUIRE=1 CODING_E2E_PRIORITY=P0 go test -tags=e2e ./tests/e2e -count=1 -v` | Post-deploy smoke sweep and golden-path HTTP regression coverage |
|
|
133
|
+
| `go test -tags=e2e ./tests/e2e -run '<affected test regex>' -count=1 -v` | Any changed or newly added E2E case |
|
|
134
|
+
| `go test -tags=dfx ./tests/dfx -run '<test regex>' -count=1 -v` | Manual DFX stability/load/QPS run against a deployed environment |
|
|
135
|
+
| `go test -tags=eval ./tests/eval -run '<test regex>' -count=1 -v` | Manual chat quality evaluation against a deployed environment |
|
|
136
|
+
| `make generate` | When generated code or mocks need refresh |
|
|
137
|
+
| `make gen-thrift` | When IDL changed |
|
|
138
|
+
| `make check-skills` | When new `adapters/outbound/` package added |
|
|
139
|
+
|
|
140
|
+
Generated mocks go next to their interfaces: domain repositories in `internal/domain/<agg>/mocks/`, application ports in `internal/application/port/mocks/`. Service tests should use generated mocks for repository dependencies.
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
## Done Checklist
|
|
144
|
+
|
|
145
|
+
- [ ] New code has tests (correct strategy applied)
|
|
146
|
+
- [ ] `make test` passes, zero races
|
|
147
|
+
- [ ] If `scripts/**` or `scripts/test/**` changed: `make test-scripts` passes; for CI gate scripts, `make check` remains the final umbrella gate
|
|
148
|
+
- [ ] If a real third-party service contract changed: note whether the affected `*_external_test.go` was manually run with local credentials
|
|
149
|
+
- [ ] If any rdb repository / PO / mapper / constructor / transaction helper changed: `make check-repository-transactions` passes
|
|
150
|
+
- [ ] If database repository or Redis-backed code changed: integration tests compile and the affected integration tests pass; if Docker/testcontainers is unavailable, report that blocker explicitly
|
|
151
|
+
- [ ] If an integration test file changed: the file compiles by itself with `go test -tags=integration ./tests/integration/<file>_test.go -run '^$'`
|
|
152
|
+
- [ ] If deployed TOP/HTTP behavior, post-deploy smoke, HTTP regression, DFX, or Eval coverage changed: the corresponding Strategy 6 suite case(s) pass; P0 smoke uses `CODING_E2E_REQUIRE=1 CODING_E2E_PRIORITY=P0`; DFX/Eval runs use `-count=1`
|
|
153
|
+
- [ ] If generated code changed: `make generate` and/or `make gen-thrift` run
|
|
154
|
+
- [ ] Error paths tested, not just happy path
|
|
155
|
+
- [ ] `t.Parallel()` on every unit test function
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
## Common Mistakes
|
|
159
|
+
|
|
160
|
+
| Mistake | Correct |
|
|
161
|
+
|---------|---------|
|
|
162
|
+
| Hand-written `fakeXXXRepository` in service tests | Use generated GoMock repository mocks |
|
|
163
|
+
| testcontainers outside `tests/integration/` | Integration tests only, with `//go:build integration` |
|
|
164
|
+
| `time.Now()` in tests | Inject `func() time.Time` via `ServiceDeps.Now` |
|
|
165
|
+
| Missing `t.Parallel()` | Every test that doesn't mutate global state must call it |
|
|
166
|
+
| Only happy path tested | Every public method needs error path too |
|
|
167
|
+
| `make test` broken by unrelated code | Fix it — broken tests anywhere block everything |
|
|
168
|
+
| Real third-party service calls hidden in `integration` / `e2e` | Use `//go:build external` and `*_external_test.go`; run the exact package/test manually |
|
|
169
|
+
| Shell curl regression added as a scenario script | Add or update a Strategy 6 case in `tests/e2e/`, `tests/dfx/`, or `tests/eval/`; P0 owns routine smoke |
|