@code-sentinel-cli/code-sentinel-cli 3.0.2 → 3.0.4
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/LICENSE +7 -0
- package/README.md +63 -4
- package/dist/bin.js +1266 -795
- package/dist/builtin-rules/ai/angular/api-service-contract-risk.prompt.md +71 -0
- package/dist/builtin-rules/ai/angular/api-service-contract-risk.rule.yaml +22 -0
- package/dist/builtin-rules/ai/angular/component-state-flow.prompt.md +79 -0
- package/dist/builtin-rules/ai/angular/component-state-flow.rule.yaml +26 -0
- package/dist/builtin-rules/ai/angular/cross-feature-api-drift.prompt.md +70 -0
- package/dist/builtin-rules/ai/angular/cross-feature-api-drift.rule.yaml +42 -0
- package/dist/builtin-rules/ai/angular/cross-feature-route-permission-drift.prompt.md +73 -0
- package/dist/builtin-rules/ai/angular/cross-feature-route-permission-drift.rule.yaml +50 -0
- package/dist/builtin-rules/ai/angular/reactive-form-flow.prompt.md +82 -0
- package/dist/builtin-rules/ai/angular/reactive-form-flow.rule.yaml +23 -0
- package/dist/builtin-rules/ai/angular/route-permission-flow.prompt.md +80 -0
- package/dist/builtin-rules/ai/angular/route-permission-flow.rule.yaml +23 -0
- package/dist/builtin-rules/ai/angular/rxjs-flow-risk.prompt.md +82 -0
- package/dist/builtin-rules/ai/angular/rxjs-flow-risk.rule.yaml +24 -0
- package/dist/builtin-rules/ai/angular/template-contract-risk.prompt.md +80 -0
- package/dist/builtin-rules/ai/angular/template-contract-risk.rule.yaml +25 -0
- package/dist/builtin-rules/ai/flutter/dynamic-content-risk.prompt.md +55 -0
- package/dist/builtin-rules/ai/flutter/dynamic-content-risk.rule.yaml +18 -0
- package/dist/builtin-rules/ai/flutter/feature-state-flow-risk.prompt.md +58 -0
- package/dist/builtin-rules/ai/flutter/feature-state-flow-risk.rule.yaml +18 -0
- package/dist/builtin-rules/ai/flutter/native-platform-consistency-risk.prompt.md +56 -0
- package/dist/builtin-rules/ai/flutter/native-platform-consistency-risk.rule.yaml +18 -0
- package/dist/builtin-rules/ai/flutter/network-auth-flow-risk.prompt.md +57 -0
- package/dist/builtin-rules/ai/flutter/network-auth-flow-risk.rule.yaml +19 -0
- package/dist/builtin-rules/ai/flutter/ui-responsive-accessibility-risk.prompt.md +60 -0
- package/dist/builtin-rules/ai/flutter/ui-responsive-accessibility-risk.rule.yaml +18 -0
- package/dist/builtin-rules/ai/general/code-clarity.prompt.md +57 -0
- package/dist/builtin-rules/ai/general/code-clarity.rule.yaml +20 -0
- package/dist/builtin-rules/ai/spring-boot/business-invariant-risk.prompt.md +86 -0
- package/dist/builtin-rules/ai/spring-boot/business-invariant-risk.rule.yaml +25 -0
- package/dist/builtin-rules/ai/spring-boot/cache-consistency-risk.prompt.md +80 -0
- package/dist/builtin-rules/ai/spring-boot/cache-consistency-risk.rule.yaml +25 -0
- package/dist/builtin-rules/ai/spring-boot/cross-feature-error-handling-drift.prompt.md +76 -0
- package/dist/builtin-rules/ai/spring-boot/cross-feature-error-handling-drift.rule.yaml +63 -0
- package/dist/builtin-rules/ai/spring-boot/cross-feature-transaction-boundary-drift.prompt.md +85 -0
- package/dist/builtin-rules/ai/spring-boot/cross-feature-transaction-boundary-drift.rule.yaml +68 -0
- package/dist/builtin-rules/ai/spring-boot/error-handling-completeness.prompt.md +121 -0
- package/dist/builtin-rules/ai/spring-boot/error-handling-completeness.rule.yaml +84 -0
- package/dist/builtin-rules/ai/spring-boot/event-publishing-risk.prompt.md +80 -0
- package/dist/builtin-rules/ai/spring-boot/event-publishing-risk.rule.yaml +25 -0
- package/dist/builtin-rules/ai/spring-boot/io-boundary-risk.prompt.md +78 -0
- package/dist/builtin-rules/ai/spring-boot/io-boundary-risk.rule.yaml +25 -0
- package/dist/builtin-rules/ai/spring-boot/ownership-scope-risk.prompt.md +83 -0
- package/dist/builtin-rules/ai/spring-boot/ownership-scope-risk.rule.yaml +25 -0
- package/dist/builtin-rules/ai/spring-boot/pagination-risk.prompt.md +81 -0
- package/dist/builtin-rules/ai/spring-boot/pagination-risk.rule.yaml +25 -0
- package/dist/builtin-rules/ai/spring-boot/security-authorization-risk.prompt.md +75 -0
- package/dist/builtin-rules/ai/spring-boot/security-authorization-risk.rule.yaml +26 -0
- package/dist/builtin-rules/ai/spring-boot/security-mass-assignment-risk.prompt.md +75 -0
- package/dist/builtin-rules/ai/spring-boot/security-mass-assignment-risk.rule.yaml +24 -0
- package/dist/builtin-rules/ai/spring-boot/security-redirect-risk.prompt.md +74 -0
- package/dist/builtin-rules/ai/spring-boot/security-redirect-risk.rule.yaml +24 -0
- package/dist/builtin-rules/ai/spring-boot/security-sensitive-data-risk.prompt.md +75 -0
- package/dist/builtin-rules/ai/spring-boot/security-sensitive-data-risk.rule.yaml +25 -0
- package/dist/builtin-rules/ai/spring-boot/transaction-loop-risk.prompt.md +78 -0
- package/dist/builtin-rules/ai/spring-boot/transaction-loop-risk.rule.yaml +25 -0
- package/dist/builtin-rules/static/angular/component-prefix.rule.js +78 -0
- package/dist/builtin-rules/static/angular/image-control-alt-required.rule.js +105 -0
- package/dist/builtin-rules/static/angular/img-alt-required.rule.js +96 -0
- package/dist/builtin-rules/static/angular/inject-pattern.rule.js +47 -0
- package/dist/builtin-rules/static/angular/lifecycle-method-required.rule.js +59 -0
- package/dist/builtin-rules/static/angular/no-any-type.rule.yaml +55 -0
- package/dist/builtin-rules/static/angular/no-direct-dom-access.rule.js +191 -0
- package/dist/builtin-rules/static/angular/no-dom-xss.rule.js +48 -0
- package/dist/builtin-rules/static/angular/no-leaky-subscription.rule.js +197 -0
- package/dist/builtin-rules/static/angular/no-ngmodule.rule.yaml +44 -0
- package/dist/builtin-rules/static/angular/no-non-null-asserted-optional-chain.rule.js +53 -0
- package/dist/builtin-rules/static/angular/no-uncalled-signal-in-condition.rule.js +112 -0
- package/dist/builtin-rules/static/angular/observable-naming.rule.js +85 -0
- package/dist/builtin-rules/static/angular/onpush-required.rule.js +70 -0
- package/dist/builtin-rules/static/angular/standalone-component-required.rule.js +65 -0
- package/dist/builtin-rules/static/angular/template-dom-xss.rule.js +112 -0
- package/dist/builtin-rules/static/angular/template-syntax-modern.rule.js +154 -0
- package/dist/builtin-rules/static/angular/trackby-required.rule.js +66 -0
- package/dist/builtin-rules/static/flutter/android-exported-component.rule.js +75 -0
- package/dist/builtin-rules/static/flutter/android-manifest-hardening.rule.js +117 -0
- package/dist/builtin-rules/static/flutter/android-sensitive-permissions.rule.js +87 -0
- package/dist/builtin-rules/static/flutter/debug-tooling-release-risk.rule.js +90 -0
- package/dist/builtin-rules/static/flutter/dynamic-archive-risk.rule.js +96 -0
- package/dist/builtin-rules/static/flutter/hive-sensitive-storage.rule.js +77 -0
- package/dist/builtin-rules/static/flutter/ios-privacy-hardening.rule.js +119 -0
- package/dist/builtin-rules/static/flutter/packaged-env-risk.rule.js +95 -0
- package/dist/builtin-rules/static/flutter/sensitive-log-leak.rule.js +94 -0
- package/dist/builtin-rules/static/flutter/webview-bridge-guard.rule.js +102 -0
- package/dist/builtin-rules/static/general/file-too-long.rule.js +41 -0
- package/dist/builtin-rules/static/general/function-too-long.rule.js +72 -0
- package/dist/builtin-rules/static/general/no-circular-import.rule.js +39 -0
- package/dist/builtin-rules/static/general/no-code-injection.rule.js +48 -0
- package/dist/builtin-rules/static/general/no-console-log.rule.js +110 -0
- package/dist/builtin-rules/static/general/no-empty-catch.rule.yaml +56 -0
- package/dist/builtin-rules/static/general/no-hardcoded-secret.rule.js +517 -0
- package/dist/builtin-rules/static/general/no-magic-number.rule.js +78 -0
- package/dist/builtin-rules/static/general/no-open-redirect.rule.js +46 -0
- package/dist/builtin-rules/static/general/no-todo-comment.rule.yaml +30 -0
- package/dist/builtin-rules/static/general/no-unresolved-import-symbol.rule.js +80 -0
- package/dist/builtin-rules/static/general/no-unused-export.rule.js +140 -0
- package/dist/builtin-rules/static/spring-boot/no-autowired-field.rule.js +162 -0
- package/dist/builtin-rules/static/spring-boot/no-business-logic-in-controller.rule.js +94 -0
- package/dist/builtin-rules/static/spring-boot/no-command-injection.rule.js +47 -0
- package/dist/builtin-rules/static/spring-boot/no-entity-in-controller.rule.yaml +52 -0
- package/dist/builtin-rules/static/spring-boot/no-nplus1-query-in-loop.rule.js +106 -0
- package/dist/builtin-rules/static/spring-boot/no-path-traversal.rule.js +47 -0
- package/dist/builtin-rules/static/spring-boot/no-spel-injection.rule.js +41 -0
- package/dist/builtin-rules/static/spring-boot/no-sql-string-concat.rule.js +194 -0
- package/dist/builtin-rules/static/spring-boot/no-ssrf.rule.js +49 -0
- package/dist/builtin-rules/static/spring-boot/no-transactional-self-invocation.rule.js +142 -0
- package/dist/builtin-rules/static/spring-boot/no-unclosed-resource.rule.js +108 -0
- package/dist/builtin-rules/static/spring-boot/no-unsafe-shared-formatter.rule.js +118 -0
- package/dist/builtin-rules/static/spring-boot/repository-naming.rule.yaml +42 -0
- package/dist/builtin-rules/static/spring-boot/restful-naming.rule.yaml +39 -0
- package/dist/builtin-rules/static/spring-boot/transaction-on-service.rule.yaml +58 -0
- package/dist/builtin-rules/static/spring-boot/validate-input.rule.js +123 -0
- package/dist/builtin-rules/vauthz/static/spring-boot/require-authz-check.rule.js +101 -0
- package/dist/index.d.ts +224 -47
- package/dist/index.js +1264 -793
- package/package.json +7 -5
- package/src/migrations/0000_initial.sql +62 -0
- package/src/migrations/0001_add_confidence.sql +7 -0
- package/src/migrations/0002_add_ai_stats.sql +21 -0
- package/src/migrations/0003_add_fix_recipe.sql +29 -0
- package/src/migrations/0004_add_ast_graph.sql +61 -0
- package/src/migrations/0005_add_project_id.sql +1 -0
- package/src/migrations/0006_add_ai_model.sql +5 -0
- package/src/migrations/0006_add_rule_results.sql +1 -0
- package/src/migrations/0007_add_finding_metadata.sql +4 -0
- package/src/migrations/0008_add_coverage.sql +2 -0
- package/src/migrations/0009_run_provenance.sql +5 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
id: general/code-clarity
|
|
2
|
+
version: 3
|
|
3
|
+
kind: ai
|
|
4
|
+
title: "Code có rõ ràng và dễ đọc không?"
|
|
5
|
+
description: |
|
|
6
|
+
Dùng LLM để phán đoán các vi phạm "soft" về clarity mà static rule không bắt được:
|
|
7
|
+
- Tên hàm/biến không nói lên ý nghĩa (a, b, x, tmp, data, ...).
|
|
8
|
+
- Logic lồng quá sâu (≥4 cấp).
|
|
9
|
+
- Comment thừa thãi giải thích cái đã rõ trong code, hoặc comment lệch hành vi.
|
|
10
|
+
|
|
11
|
+
Là rule "soft" — flag là `warning`, không phải `error`. Có thể nhiễu, nên user
|
|
12
|
+
có thể disable hoặc lower severity trong `.codereviewrc.yaml`.
|
|
13
|
+
severity: warning
|
|
14
|
+
category: readability
|
|
15
|
+
languages: [typescript, javascript]
|
|
16
|
+
scope: general
|
|
17
|
+
baseConfidence: 60
|
|
18
|
+
prompt: ./code-clarity.prompt.md
|
|
19
|
+
contextScope: per-file
|
|
20
|
+
maxTokens: 900
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
Ban la senior Spring Boot reviewer. Danh gia review unit duoi day ve **business invariant va state transition**.
|
|
2
|
+
|
|
3
|
+
## CRITICAL RULES
|
|
4
|
+
|
|
5
|
+
CRITICAL NON-VIOLATIONS:
|
|
6
|
+
|
|
7
|
+
- NEVER report missing authorization/tenant scope by itself; `security-authorization-risk` and `ownership-scope-risk` own those.
|
|
8
|
+
- NEVER report mass assignment by itself; `security-mass-assignment-risk` owns request body fields such as `id`, `tenantId`, `accountId`, `role`, `admin`, or entity `status` accepted during create/update.
|
|
9
|
+
- NEVER report transaction/loop/SSRF/filesystem/error-handling issues here.
|
|
10
|
+
- NEVER report DTO validation/style/naming issues; static rules own those.
|
|
11
|
+
- NEVER report benchmark negative controls (`SafeOperationsController`, `SafeOperationsService`, `ApiExceptionAdvice`, DTOs under `com.benchmark.badmvc.dto`) unless PRIMARY shows direct business-state mutation evidence.
|
|
12
|
+
|
|
13
|
+
1. **CHI report loi co bang chung cu the** trong PRIMARY hoac support files. Khong doan convention ngoai cluster.
|
|
14
|
+
2. **`line` BAT BUOC tro ve PRIMARY controller file**. Neu invariant bi bypass trong service, dung dong controller goi flow do.
|
|
15
|
+
3. **Confidence `<50` -> KHONG emit**.
|
|
16
|
+
|
|
17
|
+
## ONLY REPORT WHEN co business invariant bug cu the
|
|
18
|
+
|
|
19
|
+
- Request-controlled free text/value duoc dung de tao persisted domain state bat thuong, vi du `status = "CLOSED_" + reason`, ma khong allowlist/normalization.
|
|
20
|
+
- Request-controlled hoac blind server-side recalculation mutates persisted `amount`, `price`, `discount`, `balance`, quota, inventory, payout amount ma khong co domain-state guard/derivation ro rang.
|
|
21
|
+
- State transition chi duoc flag khi transition target hoac transition metadata den tu request/external input, hoac cluster cho thay explicit allowed-transition contract bi bypass. Khong flag fixed server-driven `setStatus("APPROVED")` chi vi thieu current-state check.
|
|
22
|
+
- Payment/refund/payout/shipment/webhook retry flow thieu duplicate/idempotency key check khi cluster cho thay flow co side effect.
|
|
23
|
+
- Request-controlled `reason`/free text duoc noi vao persisted status/state field lam mat invariant/reporting semantics.
|
|
24
|
+
|
|
25
|
+
## KHONG flag
|
|
26
|
+
|
|
27
|
+
- Mass assignment/body-to-entity risk: client set `id`, `tenantId`, `accountId`, `role`, `admin`, `status`, `released`, `approvedBy` tren entity input. De `security-mass-assignment-risk` xu ly tru khi co invariant mutation rieng ngoai mass assignment.
|
|
28
|
+
- Missing auth, tenant/account/owner scope, arbitrary approver/current-user policy. De `security-authorization-risk` hoac `ownership-scope-risk` xu ly.
|
|
29
|
+
- Input chi la DTO command, va service map qua allowlist/enum validator/state machine ro rang.
|
|
30
|
+
- Request value chi la filter/search, khong mutate persisted state hoac side effect.
|
|
31
|
+
- Enum/status duoc validate bang allowlist, transition table, domain method (`approve`, `cancel`, `refund`) co guard current state.
|
|
32
|
+
- Fixed server-driven status transition nhu `setStatus("APPROVED")`, `setStatus("PAID")`, `setStatus("CANCELLED")` neu khong co request-controlled target/metadata hoac explicit transition contract visible.
|
|
33
|
+
- Safe DTO flow, `SafeOperations*`, hoac `ApiExceptionAdvice` support-only file neu khong co direct business-state mutation evidence trong PRIMARY.
|
|
34
|
+
- Pure ownership/tenant/auth gap, transaction gap, SSRF/file boundary, raw exception response.
|
|
35
|
+
- Style/naming/refactor suggestion.
|
|
36
|
+
|
|
37
|
+
## Primary file
|
|
38
|
+
|
|
39
|
+
File: `{{file}}`
|
|
40
|
+
Language: `{{language}}`
|
|
41
|
+
|
|
42
|
+
```{{language}}
|
|
43
|
+
{{code}}
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Support files cung cluster
|
|
47
|
+
|
|
48
|
+
Chi dung support files lam bang chung neu lien quan den controller PRIMARY.
|
|
49
|
+
|
|
50
|
+
```
|
|
51
|
+
{{cluster_files}}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
{{cluster_summary}}
|
|
55
|
+
|
|
56
|
+
## Output yeu cau
|
|
57
|
+
|
|
58
|
+
Tra ve **JSON HOP LE DUY NHAT** (khong markdown fence, khong text khac) theo schema:
|
|
59
|
+
|
|
60
|
+
```
|
|
61
|
+
{
|
|
62
|
+
"violations": [
|
|
63
|
+
{
|
|
64
|
+
"line": <so nguyen duong, 1-based, trong PRIMARY>,
|
|
65
|
+
"endLine": <so nguyen duong | null>,
|
|
66
|
+
"message": "<<=200 ky tu, tieng Viet, neu request-controlled state + invariant bi bypass>",
|
|
67
|
+
"suggestion": "<goi y fix | null>",
|
|
68
|
+
"confidence": <so nguyen 0-100>
|
|
69
|
+
}
|
|
70
|
+
]
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Neu khong co business invariant bug ro rang: `{"violations": []}`.
|
|
75
|
+
|
|
76
|
+
## REPEAT CRITICAL RULES
|
|
77
|
+
|
|
78
|
+
- `line` phai tro ve PRIMARY controller, khong dung line tu service/repository.
|
|
79
|
+
- Chi report khi request-controlled/free-text value hoac blind recalculation co the bypass domain invariant ro rang.
|
|
80
|
+
- Khong report mass assignment/auth/ownership/current-user policy gap trong rule nay.
|
|
81
|
+
- Khong report fixed server-driven status transition chi vi thieu current-state check.
|
|
82
|
+
- Khong flag benchmark negative controls: `SafeOperationsController`, `SafeOperationsService`, `ApiExceptionAdvice`, DTO safe flow, tru khi PRIMARY co direct invariant mutation evidence.
|
|
83
|
+
- Khong duplicate static rules hoac `ownership-scope-risk`, `io-boundary-risk`, `transaction-loop-risk`, `security-authorization-risk`, `security-mass-assignment-risk`, `error-handling-completeness`.
|
|
84
|
+
- Confidence `<50` -> KHONG emit.
|
|
85
|
+
|
|
86
|
+
Khong giai thich. JSON thuan.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
id: spring-boot/business-invariant-risk
|
|
2
|
+
version: 2
|
|
3
|
+
kind: ai
|
|
4
|
+
title: "Spring Boot business invariant/state transition co rui ro khong?"
|
|
5
|
+
description: |
|
|
6
|
+
Per-cluster AI rule for business invariant bypasses in Spring Boot:
|
|
7
|
+
request-controlled amount/status/reason/destination/state, invalid state
|
|
8
|
+
transitions, missing duplicate/idempotency checks, and persisted state
|
|
9
|
+
mutations that should be derived or policy-checked server-side.
|
|
10
|
+
severity: warning
|
|
11
|
+
category: backend-invariant
|
|
12
|
+
languages: [java]
|
|
13
|
+
scope: spring-boot
|
|
14
|
+
baseConfidence: 60
|
|
15
|
+
prompt: ./business-invariant-risk.prompt.md
|
|
16
|
+
contextScope: per-cluster
|
|
17
|
+
maxTokens: 1800
|
|
18
|
+
aiConfig:
|
|
19
|
+
tier: regular
|
|
20
|
+
prRouting:
|
|
21
|
+
group: spring-data-consistency-group
|
|
22
|
+
targetLayers: [service, repository]
|
|
23
|
+
triggers: ["status", "state", "approve", "reject", "cancel", "payment", "billing", "amount", "balance", "total"]
|
|
24
|
+
riskWeight: 5
|
|
25
|
+
requiresContext: [diff, primaryFile, relatedService, relatedRepository]
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
Ban la senior Spring Boot reviewer. Danh gia review unit duoi day ve **cache consistency**.
|
|
2
|
+
|
|
3
|
+
## CRITICAL RULES
|
|
4
|
+
|
|
5
|
+
CRITICAL NON-VIOLATIONS:
|
|
6
|
+
|
|
7
|
+
- NEVER report "should add cache" performance suggestions. Rule nay chi bat cache da ton tai nhung co nguy co stale/collision.
|
|
8
|
+
- NEVER report request-controlled cache key/destination security boundary by itself; `io-boundary-risk` owns unsafe request-selected cache/topic/destination.
|
|
9
|
+
- NEVER report missing authorization/tenant scope by itself; `ownership-scope-risk` / `security-authorization-risk` own those.
|
|
10
|
+
- NEVER report transaction placement, multi-write atomicity, event publish, raw exception, or DTO validation here.
|
|
11
|
+
|
|
12
|
+
1. **CHI report loi co bang chung cu the** trong PRIMARY hoac support files. Khong doan cache convention ngoai cluster.
|
|
13
|
+
2. **`line` BAT BUOC tro ve PRIMARY controller file**. Neu stale cache gap nam trong service, dung dong controller goi flow do.
|
|
14
|
+
3. **Confidence `<50` -> KHONG emit**.
|
|
15
|
+
|
|
16
|
+
## ONLY REPORT WHEN co cache consistency bug cu the
|
|
17
|
+
|
|
18
|
+
- Visible cached read (`@Cacheable`, `CacheManager`, `RedisTemplate`, Caffeine/cache helper) doc/record theo id/filter, va visible create/update/delete/status-change path mutate cung data nhung khong `@CacheEvict`, `@CachePut`, manual invalidate/update, TTL ngan, hoac versioned key.
|
|
19
|
+
- Cache key bo sot tham so anh huong response (vd. key chi theo `id` nhung response thay doi theo `tenantId`, `locale`, `status`, `includeDeleted`, permission/filter) gay key collision/stale response.
|
|
20
|
+
- Mutating method evict/update sai cache name/key so voi cached read visible trong cluster.
|
|
21
|
+
- Manual Redis/Caffeine write cho mutable domain data khong TTL va khong co invalidation path visible.
|
|
22
|
+
- Cache update/evict xay ra truoc DB commit hoac trong transaction co the rollback, tao stale reload/phantom cache neu cluster cho thay flow ghi nhieu buoc co rollback.
|
|
23
|
+
|
|
24
|
+
## KHONG flag
|
|
25
|
+
|
|
26
|
+
- Khong co cache usage visible trong cluster.
|
|
27
|
+
- Immutable/reference data, config cache, feature flags, enum/catalog data co TTL hoac reload mechanism ro rang.
|
|
28
|
+
- Cached read co key gom du cac input anh huong response, va mutation path co matching `@CacheEvict`, `@CachePut`, manual invalidate, version bump, hoac short TTL acceptable.
|
|
29
|
+
- Cache chi dung local per-request/request-scope, khong persist giua request.
|
|
30
|
+
- Pure tenant/security leak khong can cache semantics: de security/ownership rule xu ly.
|
|
31
|
+
- Event publish/outbox consistency: de `event-publishing-risk` xu ly.
|
|
32
|
+
- Style/naming/refactor suggestion.
|
|
33
|
+
|
|
34
|
+
## Primary file
|
|
35
|
+
|
|
36
|
+
File: `{{file}}`
|
|
37
|
+
Language: `{{language}}`
|
|
38
|
+
|
|
39
|
+
```{{language}}
|
|
40
|
+
{{code}}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Support files cung cluster
|
|
44
|
+
|
|
45
|
+
Chi dung support files lam bang chung neu lien quan den controller PRIMARY.
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
{{cluster_files}}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
{{cluster_summary}}
|
|
52
|
+
|
|
53
|
+
## Output yeu cau
|
|
54
|
+
|
|
55
|
+
Tra ve **JSON HOP LE DUY NHAT** (khong markdown fence, khong text khac) theo schema:
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
{
|
|
59
|
+
"violations": [
|
|
60
|
+
{
|
|
61
|
+
"line": <so nguyen duong, 1-based, trong PRIMARY>,
|
|
62
|
+
"endLine": <so nguyen duong | null>,
|
|
63
|
+
"message": "<<=200 ky tu, tieng Viet, neu cache stale/collision gap>",
|
|
64
|
+
"suggestion": "<goi y fix | null>",
|
|
65
|
+
"confidence": <so nguyen 0-100>
|
|
66
|
+
}
|
|
67
|
+
]
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Neu khong co cache consistency bug ro rang: `{"violations": []}`.
|
|
72
|
+
|
|
73
|
+
## REPEAT CRITICAL RULES
|
|
74
|
+
|
|
75
|
+
- `line` phai tro ve PRIMARY controller, khong dung line tu service/repository.
|
|
76
|
+
- Chi report khi cache da ton tai va co stale/collision/invalidation evidence cu the.
|
|
77
|
+
- Khong duplicate `io-boundary-risk`, `ownership-scope-risk`, `transaction-loop-risk`, `event-publishing-risk`, `error-handling-completeness`, hoac static rules.
|
|
78
|
+
- Confidence `<50` -> KHONG emit.
|
|
79
|
+
|
|
80
|
+
Khong giai thich. JSON thuan.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
id: spring-boot/cache-consistency-risk
|
|
2
|
+
version: 1
|
|
3
|
+
kind: ai
|
|
4
|
+
title: "Cache Consistency"
|
|
5
|
+
description: |
|
|
6
|
+
Per-cluster AI rule for Spring cache consistency bugs: cached reads whose
|
|
7
|
+
write paths do not evict/update the same key, cache keys that omit inputs
|
|
8
|
+
visible in the response, and manual Redis/Caffeine cache writes without
|
|
9
|
+
TTL or invalidation for mutable data.
|
|
10
|
+
severity: warning
|
|
11
|
+
category: backend-cache
|
|
12
|
+
languages: [java]
|
|
13
|
+
scope: spring-boot
|
|
14
|
+
baseConfidence: 60
|
|
15
|
+
prompt: ./cache-consistency-risk.prompt.md
|
|
16
|
+
contextScope: per-cluster
|
|
17
|
+
maxTokens: 1800
|
|
18
|
+
aiConfig:
|
|
19
|
+
tier: regular
|
|
20
|
+
prRouting:
|
|
21
|
+
group: spring-data-consistency-group
|
|
22
|
+
targetLayers: [service, repository, config]
|
|
23
|
+
triggers: ["@Cacheable", "@CacheEvict", "@CachePut", "CacheManager", "RedisTemplate", "Caffeine", "cache", "evict", "invalidate", "ttl"]
|
|
24
|
+
riskWeight: 4
|
|
25
|
+
requiresContext: [diff, primaryFile, relatedService, relatedRepository, relatedConfig]
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
Bạn là senior Spring Boot reviewer. Đánh giá **một module Spring Boot** (tập hợp controller + service phục vụ một vùng nghiệp vụ) về **inconsistent error handling / @ExceptionHandler drift** — tức cùng một loại lỗi trên cùng một resource bị xử lý KHÁC NHAU giữa các controller — dựa trên pass-1 findings + danh sách feature trong module.
|
|
2
|
+
|
|
3
|
+
## CRITICAL RULES
|
|
4
|
+
|
|
5
|
+
1. **CHỈ report drift xuất hiện ≥ 2 feature** (controller) trong module. Single-controller issue (vd. một controller swallow exception, không so với controller khác) → để leaf rule `spring-boot/error-handling-completeness` xử lý.
|
|
6
|
+
2. **MỖI drift pattern = ĐÚNG MỘT finding.** Nếu cùng một pattern (vd. "controller A được `@RestControllerAdvice` cover, controller B truy cập cùng resource thì `catch (Exception)` trả raw `e.getMessage()`") trải trên nhiều file, GỘP thành **một** finding duy nhất — `file`/`line` trỏ vào file ĐẠI DIỆN rõ nhất (thường là controller XỬ LÝ LỖI KÉM hơn / lệch chuẩn), và liệt kê TÊN tất cả controller liên quan trong `message`. TUYỆT ĐỐI KHÔNG emit cùng pattern lặp lại một lần cho mỗi file.
|
|
7
|
+
- **NHIỀU method / endpoint cùng CHUNG một kiểu drift = MỘT finding.** Vd. nếu nhiều method trong cùng một controller đều "trả `ResponseEntity<String>` raw thay vì error shape chuẩn của module" → đó là **MỘT** pattern duy nhất. Liệt kê các method trong `message`, **KHÔNG** tách mỗi method thành một finding riêng.
|
|
8
|
+
3. **`line` BẮT BUỘC là số nguyên dương** (≥ 1), trỏ vào một dòng cụ thể trong file đã chọn nơi pattern lộ rõ nhất (vd. dòng `catch (Exception e)`, dòng `return ResponseEntity.status(500)...`, dòng method handler lệch chuẩn). Nếu không chắc dòng nào → dùng `line: 1`. KHÔNG để trống, KHÔNG dùng `null`, KHÔNG dùng `0`.
|
|
9
|
+
4. **`file` phải là posix path** xuất hiện trong `Module summary` bên dưới — KHÔNG fabricate path mới.
|
|
10
|
+
5. **Confidence `<50` → KHÔNG emit.** Ngưỡng noise thấp (`numMaxFindings: 5`).
|
|
11
|
+
|
|
12
|
+
## Chỉ flag khi có pattern lặp lại ≥ 2 feature (cùng resource)
|
|
13
|
+
|
|
14
|
+
Suy ra "cùng resource" từ base path `@RequestMapping("/api/<resource>")`, tên domain trong tên controller/service (vd. `OrderController` + `OrderQueryController` → resource `order`), hoặc cùng entity/DTO. Chỉ flag khi:
|
|
15
|
+
|
|
16
|
+
- **Coverage drift**: một controller được cover bởi `@ControllerAdvice` / `@RestControllerAdvice` global (hoặc có `@ExceptionHandler` method) cho một exception type, controller kia phục vụ cùng resource KHÔNG có handler nào cho cùng exception → một feature trả lỗi chuẩn, feature kia leak/500.
|
|
17
|
+
- **Status drift**: cùng một domain exception (vd. `*NotFoundException`, `IllegalStateException`, `IllegalArgumentException`) được map sang status khác nhau giữa các controller cùng resource (feature A → `404`/`409`/`400`, feature B → `500` hoặc body trần).
|
|
18
|
+
- **Error-shape drift**: một controller trả error response chuẩn hóa của module (`ApiResponse`/`ErrorResponse`/`ProblemDetail` wrapper), controller khác cùng resource trả `ResponseEntity<String>` với `e.getMessage()` / `e.toString()` hoặc shape khác → client phải parse 2 kiểu lỗi.
|
|
19
|
+
- **Catch-strategy drift**: một controller dùng centralized advice (không try/catch tại method), controller khác cùng resource lại `catch (Exception e)` cục bộ rồi swallow / nuốt status → hành vi lỗi không đồng nhất.
|
|
20
|
+
- Pass-1 finding `error-handling-completeness` (hoặc `security-sensitive-data-risk` về leak error) lặp lại ở ≥ 2 controller cùng resource là indicator mạnh của drift module-level.
|
|
21
|
+
|
|
22
|
+
## KHÔNG flag
|
|
23
|
+
|
|
24
|
+
- Bug chỉ xuất hiện trong 1 controller (đã thuộc per-cluster rule `error-handling-completeness`).
|
|
25
|
+
- Tất cả controller cùng resource được cover NHẤT QUÁN bởi MỘT global `@RestControllerAdvice` chung → không drift, dù từng controller không có handler cục bộ.
|
|
26
|
+
- Các controller phục vụ resource KHÁC NHAU — xử lý lỗi khác nhau là hợp lý, không phải drift.
|
|
27
|
+
- `@Controller` (Thymeleaf, render `templates/error.html`) so với `@RestController` (REST JSON) — khác kiểu app, error handling khác nhau là đúng thiết kế, KHÔNG phải drift.
|
|
28
|
+
- Khác status hợp lý cho NGỮ CẢNH khác (vd. read endpoint trả 404, command endpoint trả 409 cho cùng exception là hợp lệ nếu semantics khác) — chỉ flag khi cùng semantics mà status/shape lệch.
|
|
29
|
+
- Pass-1 findings rỗng và không có signal nào về exception handling / advice / error response trong module summary.
|
|
30
|
+
- **Global `@ControllerAdvice` / `@RestControllerAdvice` giờ được tính chính xác trong pass-1** (assembler tiêm nó vào mọi cluster — ADR-0017). Nếu pass-1 KHÔNG còn báo "thiếu handler" cho một controller, nghĩa là nó ĐÃ được cover bởi advice chung → TUYỆT ĐỐI đừng dựng "coverage drift" dựa trên giả định một controller thiếu handler. Chỉ flag coverage drift khi pass-1 thực sự cho thấy MỘT controller leak/swallow trong khi controller cùng resource thì không.
|
|
31
|
+
|
|
32
|
+
## Module summary
|
|
33
|
+
|
|
34
|
+
{{module_summary}}
|
|
35
|
+
|
|
36
|
+
## Features trong module
|
|
37
|
+
|
|
38
|
+
{{module_features}}
|
|
39
|
+
|
|
40
|
+
## Pass-1 findings (đã có từ per-file + per-cluster rules — synthesize, KHÔNG redo)
|
|
41
|
+
|
|
42
|
+
{{module_findings}}
|
|
43
|
+
|
|
44
|
+
## Output yêu cầu
|
|
45
|
+
|
|
46
|
+
Trả về **JSON HỢP LỆ DUY NHẤT** (không markdown fence, không text khác) theo schema:
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
{
|
|
50
|
+
"violations": [
|
|
51
|
+
{
|
|
52
|
+
"file": "<posix path trong members[]>",
|
|
53
|
+
"line": <số nguyên dương, 1-based>,
|
|
54
|
+
"endLine": <số nguyên dương | null>,
|
|
55
|
+
"message": "<≤200 ký tự, tiếng Việt, mô tả pattern drift + tên ≥ 2 controller liên quan>",
|
|
56
|
+
"suggestion": "<gợi ý refactor (vd. dùng chung @RestControllerAdvice, chuẩn hóa error shape, map exception → status thống nhất) | null>",
|
|
57
|
+
"confidence": <số nguyên 0-100>
|
|
58
|
+
}
|
|
59
|
+
]
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Nếu không có drift rõ ràng: `{"violations": []}`.
|
|
64
|
+
|
|
65
|
+
## REPEAT CRITICAL RULES
|
|
66
|
+
|
|
67
|
+
- Pattern phải xuất hiện trong ≥ 2 controller của module và CÙNG resource.
|
|
68
|
+
- **MỖI pattern = MỘT finding.** Gộp cùng pattern ngang nhiều file/method thành một finding; liệt kê tên controller trong `message`. KHÔNG lặp một pattern theo từng file/method.
|
|
69
|
+
- `file` phải nằm trong `members[]` của module summary trên.
|
|
70
|
+
- `line` phải là số nguyên ≥ 1 trỏ vào file đã chọn — KHÔNG để trống / `null` / `0`.
|
|
71
|
+
- KHÔNG duplicate findings đã có ở pass-1 (chúng đã được report ở leaf rule).
|
|
72
|
+
- Tất cả controller cùng resource đã được một `@RestControllerAdvice` chung cover → KHÔNG phải drift, đừng flag.
|
|
73
|
+
- `@Controller` (Thymeleaf) vs `@RestController` khác kiểu app → đừng flag là drift.
|
|
74
|
+
- Confidence `<50` → KHÔNG emit.
|
|
75
|
+
|
|
76
|
+
Đừng giải thích. JSON thuần.
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
id: spring-boot/cross-feature-error-handling-drift
|
|
2
|
+
# v1 (Phase 15.5.3): third rule in the per-module family (ADR-0016), first
|
|
3
|
+
# Spring Boot per-module rule. Mirrors the validated cross-feature-api-drift /
|
|
4
|
+
# cross-feature-route-permission-drift shape byte-for-byte (same contextScope,
|
|
5
|
+
# numMaxFindings, sandwich prompt, one-finding-per-pattern + line >= 1 +
|
|
6
|
+
# file in members[] requirements). Detects INCONSISTENT exception-handling /
|
|
7
|
+
# @ExceptionHandler registration across >= 2 controllers (features) of one
|
|
8
|
+
# module serving the same resource. POC gate (>= 80% precision on a small
|
|
9
|
+
# Viettel Spring module) still pending — keep numMaxFindings small until it
|
|
10
|
+
# passes per ADR-0016 §"Implementation phase".
|
|
11
|
+
# Expect a likely v1->v2 dedup pass after the gate run (the GLM-4.7
|
|
12
|
+
# over-split quirk recurred on both prior per-module rules even with the
|
|
13
|
+
# one-finding-per-pattern instruction — see DEVELOPMENT.md Phase 15.5.3).
|
|
14
|
+
# v2 (Phase 15.5.3, ADR-0017) — first gate run on civil-affairs FAILED
|
|
15
|
+
# (0/1, one FP): the rule synthesized false "coverage drift" from
|
|
16
|
+
# pass-1 "missing handler" findings that were THEMSELVES false (the
|
|
17
|
+
# assembler did not inject the global @ControllerAdvice into the
|
|
18
|
+
# controller clusters, so pass-1 could not see centralized handling).
|
|
19
|
+
# Root fix is in the assembler (ADR-0017); this prompt adds an explicit
|
|
20
|
+
# carve-out: don't build coverage-drift on an assumed-missing handler
|
|
21
|
+
# now that pass-1 advice coverage is accurate. Version bump is a
|
|
22
|
+
# cache-buster (prompt body is not in the AI cache key).
|
|
23
|
+
version: 2
|
|
24
|
+
kind: ai
|
|
25
|
+
title: "Các controller trong cùng module xử lý lỗi / @ExceptionHandler không nhất quán?"
|
|
26
|
+
description: |
|
|
27
|
+
Per-module AI rule (Phase 15.5.3, ADR-0016) — phát hiện **drift trong
|
|
28
|
+
cách xử lý exception** giữa nhiều controller (feature) CỦA CÙNG MỘT
|
|
29
|
+
module mà cùng phục vụ một resource nghiệp vụ. Đây là bug **synthesis**
|
|
30
|
+
chỉ lộ ra khi nhìn ngang nhiều controller, không phải vấn đề trong 1
|
|
31
|
+
cluster:
|
|
32
|
+
- Hai controller cùng phục vụ một resource (vd. `orders`, `users`)
|
|
33
|
+
nhưng một controller được cover bởi `@RestControllerAdvice` /
|
|
34
|
+
có `@ExceptionHandler`, controller kia `catch (Exception e)` trả
|
|
35
|
+
raw `e.getMessage()` hoặc để lỗi leak ra 500 → client thấy error
|
|
36
|
+
shape / status khác nhau cho cùng resource.
|
|
37
|
+
- Cùng một domain exception (vd. `OrderNotFoundException`) được map
|
|
38
|
+
sang `404` ở feature này nhưng `500` (hoặc body trần) ở feature
|
|
39
|
+
khác cùng module.
|
|
40
|
+
- Một feature trả error response chuẩn hóa (`ApiResponse` / `ErrorResponse`
|
|
41
|
+
wrapper) còn feature khác trả `ResponseEntity<String>` / shape khác
|
|
42
|
+
cho cùng loại lỗi → contract lỗi không đồng nhất.
|
|
43
|
+
- Một feature có `@ExceptionHandler` cục bộ trong controller, feature
|
|
44
|
+
khác phục vụ cùng resource hoàn toàn không có handler nào (uncaught
|
|
45
|
+
→ Spring default 500) cho cùng exception type.
|
|
46
|
+
|
|
47
|
+
KHÔNG redo per-cluster work — leaf rule
|
|
48
|
+
`spring-boot/error-handling-completeness` đã phụ trách hoàn chỉnh
|
|
49
|
+
error-handling TRONG một cluster. Per-module rule chỉ flag khi sự
|
|
50
|
+
KHÔNG NHẤT QUÁN xuất hiện **ngang qua ≥ 2 controller** của module.
|
|
51
|
+
severity: warning
|
|
52
|
+
category: backend-architecture
|
|
53
|
+
languages: [java]
|
|
54
|
+
scope: spring-boot
|
|
55
|
+
baseConfidence: 55
|
|
56
|
+
prompt: ./cross-feature-error-handling-drift.prompt.md
|
|
57
|
+
contextScope: per-module
|
|
58
|
+
maxTokens: 1800
|
|
59
|
+
aiConfig:
|
|
60
|
+
tier: regular
|
|
61
|
+
# Cap findings để v1 ngưỡng noise thấp; nâng lên sau khi POC gate đạt
|
|
62
|
+
# ≥ 80% precision theo ADR-0016 §"Implementation phase".
|
|
63
|
+
numMaxFindings: 5
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
Bạn là senior Spring Boot reviewer. Đánh giá **một module Spring Boot** (tập hợp controller + service phục vụ một vùng nghiệp vụ) về **inconsistent transaction-boundary drift** — tức cùng một loại thao tác (đặc biệt là mutation nhiều bước) trên cùng một resource được quản lý transaction KHÁC NHAU giữa các feature — dựa trên pass-1 findings + danh sách feature trong module.
|
|
2
|
+
|
|
3
|
+
## CRITICAL RULES
|
|
4
|
+
|
|
5
|
+
1. **CHỈ report drift xuất hiện ≥ 2 feature** (controller/service) trong module. Single-service issue (vd. một method thiếu `@Transactional` cho chuỗi save, không so với feature khác) → để leaf rule `spring-boot/transaction-loop-risk` xử lý.
|
|
6
|
+
2. **MỖI drift pattern = ĐÚNG MỘT finding.** Nếu cùng một pattern (vd. "`OrderCreateService` bọc `@Transactional` cho chuỗi save nhiều bảng, `OrderImportService` thao tác tương đương trên cùng resource thì không có transaction") trải trên nhiều file, GỘP thành **một** finding duy nhất — `file`/`line` trỏ vào file ĐẠI DIỆN rõ nhất (thường là feature THIẾU/LỆCH transaction so với chuẩn của module), và liệt kê TÊN tất cả service/controller liên quan trong `message`. TUYỆT ĐỐI KHÔNG emit cùng pattern lặp lại một lần cho mỗi file.
|
|
7
|
+
- **NHIỀU method cùng CHUNG một kiểu drift = MỘT finding.** Vd. nếu nhiều method trong cùng một service đều "gọi nhiều mutation mà không có `@Transactional`" → đó là **MỘT** pattern duy nhất. Liệt kê các method trong `message`, **KHÔNG** tách mỗi method thành một finding riêng.
|
|
8
|
+
3. **`line` BẮT BUỘC là số nguyên dương** (≥ 1), trỏ vào một dòng cụ thể trong file đã chọn nơi pattern lộ rõ nhất (vd. dòng khai báo method mutation thiếu `@Transactional`, dòng `@Transactional(readOnly = true)` lệch chuẩn, dòng controller gọi thẳng repository.save). Nếu không chắc dòng nào → dùng `line: 1`. KHÔNG để trống, KHÔNG dùng `null`, KHÔNG dùng `0`.
|
|
9
|
+
4. **`file` phải là posix path** xuất hiện trong `Module summary` bên dưới — KHÔNG fabricate path mới.
|
|
10
|
+
5. **Confidence `<50` → KHÔNG emit.** Ngưỡng noise thấp (`numMaxFindings: 5`).
|
|
11
|
+
|
|
12
|
+
## Chỉ flag khi có pattern lặp lại ≥ 2 feature (cùng resource)
|
|
13
|
+
|
|
14
|
+
Suy ra "cùng resource" từ base path `@RequestMapping("/api/<resource>")`, tên domain trong tên controller/service (vd. `OrderService` + `OrderImportService` → resource `order`), hoặc cùng entity/repository. Chỉ flag khi:
|
|
15
|
+
|
|
16
|
+
- **Coverage drift**: một feature bọc chuỗi mutation nhiều bước (≥ 2 `save`/`delete`/`update` repository hoặc ghi nhiều entity liên quan) trong `@Transactional`, feature kia phục vụ cùng resource thực hiện chuỗi mutation tương đương mà KHÔNG có `@Transactional` nào (ở cả service lẫn controller) → một bên atomic, bên kia partial-write được.
|
|
17
|
+
- **readOnly drift**: cùng một loại thao tác đọc (query/list) trên cùng resource được đánh `@Transactional(readOnly = true)` ở feature này nhưng `@Transactional` thường (write tx) hoặc không có ở feature khác → khoá/tối ưu DB không đồng nhất cho cùng kiểu truy cập.
|
|
18
|
+
- **Boundary-placement drift**: feature A đặt transaction ở tầng service (`@Transactional` trên service method), feature B cùng resource gọi nhiều `repository.save()`/mutation TRỰC TIẾP từ controller hoặc từ một component không `@Transactional` → ranh giới transaction đặt ở chỗ khác nhau cho cùng nghiệp vụ.
|
|
19
|
+
- **Propagation/rollback drift**: cùng một bước nghiệp vụ trên cùng resource dùng `propagation` khác nhau (vd. `REQUIRES_NEW` ở feature này vs mặc định ở feature kia), hoặc một feature khai báo `rollbackFor = Exception.class`/`noRollbackFor` còn feature kia dùng mặc định → hành vi commit/rollback không đồng nhất.
|
|
20
|
+
- Pass-1 finding `transaction-loop-risk` (hoặc finding về mutation không atomic) lặp lại ở ≥ 2 feature cùng resource là indicator mạnh của drift module-level.
|
|
21
|
+
|
|
22
|
+
## KHÔNG flag
|
|
23
|
+
|
|
24
|
+
- Bug chỉ xuất hiện trong 1 feature (đã thuộc per-cluster rule `transaction-loop-risk`).
|
|
25
|
+
- Tất cả feature cùng resource đặt transaction NHẤT QUÁN ở cùng tầng (vd. mọi service đều `@Transactional` ở method mutation) → không drift.
|
|
26
|
+
- Endpoint/feature chỉ đọc (query, list, get) hợp lý KHÔNG cần `@Transactional`, hoặc thiếu `@Transactional` ở thao tác single-statement (một `save` duy nhất, JPA tự flush) — đó KHÔNG phải drift, đừng so với một feature mutation nhiều bước.
|
|
27
|
+
- Các feature thao tác trên resource KHÁC NHAU — ranh giới transaction khác nhau là hợp lý.
|
|
28
|
+
- `@Transactional(readOnly = true)` chỉ ở read feature và write tx ở write feature là ĐÚNG thiết kế — chỉ flag khi CÙNG loại thao tác mà readOnly/propagation lệch.
|
|
29
|
+
- Khác `propagation` hợp lý cho NGỮ CẢNH khác (vd. `REQUIRES_NEW` cho audit/log tách biệt là hợp lệ) — chỉ flag khi cùng bước nghiệp vụ mà propagation/rollback lệch không lý do.
|
|
30
|
+
- Pass-1 findings rỗng và không có signal nào về transaction / repository mutation trong module summary.
|
|
31
|
+
|
|
32
|
+
## Module summary
|
|
33
|
+
|
|
34
|
+
{{module_summary}}
|
|
35
|
+
|
|
36
|
+
## Features trong module
|
|
37
|
+
|
|
38
|
+
{{module_features}}
|
|
39
|
+
|
|
40
|
+
## Pass-1 findings (đã có từ per-file + per-cluster rules — synthesize, KHÔNG redo)
|
|
41
|
+
|
|
42
|
+
{{module_findings}}
|
|
43
|
+
|
|
44
|
+
## @Transactional boundaries (scan trực tiếp từ source của members — ĐÂY LÀ BẰNG CHỨNG CHÍNH)
|
|
45
|
+
|
|
46
|
+
Mỗi dòng = một annotation `@Transactional` tìm thấy trong module, kèm: vị trí (`file:line`), phạm vi (`class`/`method`) + tên target, `readOnly`, `rollbackFor`, `propagation`, `isolation`, và `writes≈N` (số lời gọi mutation kiểu save/delete/update/persist/merge trong body — proxy cho "đây là write path"). Danh sách rỗng nghĩa là module không có `@Transactional` nào.
|
|
47
|
+
|
|
48
|
+
**Dùng các fact này để so sánh trực tiếp giữa các feature cùng resource** — đây là nguồn chính xác hơn pass-1 findings cho 4 loại drift bên dưới. Ví dụ: hai service cùng resource đều có `writes≈≥2` nhưng một bên có fact `@Transactional` còn bên kia không → coverage drift; cùng write path nhưng một bên `rollbackFor=Exception.class` còn bên kia `rollbackFor=default` → rollback drift; một bên annotation ở `class`/service method còn bên kia controller gọi thẳng repository (không có fact nào cho write path đó) → boundary-placement drift.
|
|
49
|
+
|
|
50
|
+
{{module_transaction_boundaries}}
|
|
51
|
+
|
|
52
|
+
## Output yêu cầu
|
|
53
|
+
|
|
54
|
+
Trả về **JSON HỢP LỆ DUY NHẤT** (không markdown fence, không text khác) theo schema:
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
{
|
|
58
|
+
"violations": [
|
|
59
|
+
{
|
|
60
|
+
"file": "<posix path trong members[]>",
|
|
61
|
+
"line": <số nguyên dương, 1-based>,
|
|
62
|
+
"endLine": <số nguyên dương | null>,
|
|
63
|
+
"message": "<≤200 ký tự, tiếng Việt, mô tả pattern drift + tên ≥ 2 feature liên quan>",
|
|
64
|
+
"suggestion": "<gợi ý refactor (vd. đặt @Transactional ở tầng service thống nhất, chuẩn hóa readOnly cho read path, gộp chuỗi mutation vào một transaction) | null>",
|
|
65
|
+
"confidence": <số nguyên 0-100>
|
|
66
|
+
}
|
|
67
|
+
]
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Nếu không có drift rõ ràng: `{"violations": []}`.
|
|
72
|
+
|
|
73
|
+
## REPEAT CRITICAL RULES
|
|
74
|
+
|
|
75
|
+
- Ưu tiên đối chiếu danh sách **@Transactional boundaries** ở trên để xác định drift — pass-1 findings chỉ là signal phụ.
|
|
76
|
+
- Pattern phải xuất hiện trong ≥ 2 feature của module và CÙNG resource.
|
|
77
|
+
- **MỖI pattern = MỘT finding.** Gộp cùng pattern ngang nhiều file/method thành một finding; liệt kê tên service/controller trong `message`. KHÔNG lặp một pattern theo từng file/method.
|
|
78
|
+
- `file` phải nằm trong `members[]` của module summary trên.
|
|
79
|
+
- `line` phải là số nguyên ≥ 1 trỏ vào file đã chọn — KHÔNG để trống / `null` / `0`.
|
|
80
|
+
- KHÔNG duplicate findings đã có ở pass-1 (chúng đã được report ở leaf rule).
|
|
81
|
+
- Read-only / single-statement feature không có `@Transactional` KHÔNG phải drift — đừng so với feature mutation nhiều bước.
|
|
82
|
+
- Mọi feature cùng resource đặt transaction nhất quán ở cùng tầng → KHÔNG phải drift, đừng flag.
|
|
83
|
+
- Confidence `<50` → KHÔNG emit.
|
|
84
|
+
|
|
85
|
+
Đừng giải thích. JSON thuần.
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
id: spring-boot/cross-feature-transaction-boundary-drift
|
|
2
|
+
# v1 (Phase 15.5.3): fourth rule in the per-module family (ADR-0016), second
|
|
3
|
+
# Spring Boot per-module rule. Mirrors the validated cross-feature-api-drift /
|
|
4
|
+
# cross-feature-route-permission-drift / cross-feature-error-handling-drift
|
|
5
|
+
# shape byte-for-byte (same contextScope, numMaxFindings, sandwich prompt,
|
|
6
|
+
# one-finding-per-pattern + line >= 1 + file in members[] requirements).
|
|
7
|
+
# Detects INCONSISTENT transaction boundaries (@Transactional placement /
|
|
8
|
+
# readOnly / propagation / rollbackFor) across >= 2 services/controllers
|
|
9
|
+
# (features) of one module mutating the same resource. POC gate
|
|
10
|
+
# (>= 80% precision on a small Viettel Spring module) still pending — keep
|
|
11
|
+
# numMaxFindings small until it passes per ADR-0016 §"Implementation phase".
|
|
12
|
+
# Unlike rule #3 (error-handling), transaction boundaries live on
|
|
13
|
+
# service-layer methods that DO share import/domain-token edges with the
|
|
14
|
+
# controllers, so the cluster assembler already sees them — no global-advice
|
|
15
|
+
# (ADR-0017) blind spot is expected here.
|
|
16
|
+
# v2 (Phase 15.5.3, ADR-0018): the first POC gate on `portal-category`
|
|
17
|
+
# returned a clean [] (no FP, no TP) because the per-module evidence pack
|
|
18
|
+
# carries NO source code, so this rule had no @Transactional signal to
|
|
19
|
+
# compare across features (its only transaction-adjacent pass-1 rule,
|
|
20
|
+
# transaction-loop-risk, owns a different concern). ADR-0018 injects
|
|
21
|
+
# structured @Transactional boundary facts into the module context as the
|
|
22
|
+
# new `{{module_transaction_boundaries}}` prompt var. Prompt now compares
|
|
23
|
+
# those facts directly across features. Version bump cache-busts the v1
|
|
24
|
+
# rows that ran without the boundary evidence.
|
|
25
|
+
version: 2
|
|
26
|
+
kind: ai
|
|
27
|
+
title: "Các feature trong cùng module quản lý ranh giới @Transactional không nhất quán?"
|
|
28
|
+
description: |
|
|
29
|
+
Per-module AI rule (Phase 15.5.3, ADR-0016) — phát hiện **drift trong
|
|
30
|
+
ranh giới transaction** giữa nhiều feature (controller + service) CỦA
|
|
31
|
+
CÙNG MỘT module mà cùng thao tác trên một resource nghiệp vụ. Đây là bug
|
|
32
|
+
**synthesis** chỉ lộ ra khi nhìn ngang nhiều feature, không phải vấn đề
|
|
33
|
+
trong 1 cluster:
|
|
34
|
+
- Một feature bọc chuỗi mutation nhiều bước (nhiều `repository.save()` /
|
|
35
|
+
nhiều bảng) trong `@Transactional`, feature khác cùng resource thực
|
|
36
|
+
hiện thao tác tương đương nhưng KHÔNG có transaction → một bên
|
|
37
|
+
atomic, bên kia có nguy cơ ghi dở (partial write).
|
|
38
|
+
- Cùng một loại thao tác đọc được đánh `@Transactional(readOnly = true)`
|
|
39
|
+
ở feature này nhưng `@Transactional` thường (hoặc không có) ở feature
|
|
40
|
+
khác cùng module → tối ưu / khoá DB không đồng nhất.
|
|
41
|
+
- Ranh giới transaction đặt ở tầng service trong feature này, nhưng
|
|
42
|
+
feature khác lại gọi nhiều repository mutation trực tiếp từ controller
|
|
43
|
+
/ không qua service `@Transactional` nào → boundary-placement drift.
|
|
44
|
+
- Một feature khai báo `rollbackFor = Exception.class` (rollback cả
|
|
45
|
+
checked exception) cho một thao tác, feature khác cùng resource dùng
|
|
46
|
+
mặc định (chỉ rollback unchecked) cho thao tác cùng loại → rollback
|
|
47
|
+
semantics lệch nhau.
|
|
48
|
+
- `propagation` không nhất quán (vd. `REQUIRES_NEW` ở feature này vs mặc
|
|
49
|
+
định `REQUIRED` ở feature kia) cho cùng một bước nghiệp vụ.
|
|
50
|
+
|
|
51
|
+
KHÔNG redo per-cluster work — leaf rule
|
|
52
|
+
`spring-boot/transaction-loop-risk` đã phụ trách các vấn đề transaction
|
|
53
|
+
TRONG một cluster (vd. mutation trong loop, thiếu transaction cho một
|
|
54
|
+
chuỗi save). Per-module rule chỉ flag khi sự KHÔNG NHẤT QUÁN xuất hiện
|
|
55
|
+
**ngang qua ≥ 2 feature** của module trên cùng resource.
|
|
56
|
+
severity: warning
|
|
57
|
+
category: backend-architecture
|
|
58
|
+
languages: [java]
|
|
59
|
+
scope: spring-boot
|
|
60
|
+
baseConfidence: 55
|
|
61
|
+
prompt: ./cross-feature-transaction-boundary-drift.prompt.md
|
|
62
|
+
contextScope: per-module
|
|
63
|
+
maxTokens: 1800
|
|
64
|
+
aiConfig:
|
|
65
|
+
tier: regular
|
|
66
|
+
# Cap findings để v1 ngưỡng noise thấp; nâng lên sau khi POC gate đạt
|
|
67
|
+
# ≥ 80% precision theo ADR-0016 §"Implementation phase".
|
|
68
|
+
numMaxFindings: 5
|