@mytechtoday/augment-extensions 1.4.0 → 1.5.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.
Files changed (307) hide show
  1. package/augment-extensions/coding-standards/c/CHANGELOG.md +55 -0
  2. package/augment-extensions/coding-standards/c/LICENSE +22 -0
  3. package/augment-extensions/coding-standards/c/README.md +167 -0
  4. package/augment-extensions/coding-standards/c/config/defaults.json +26 -0
  5. package/augment-extensions/coding-standards/c/config/examples/embedded.yaml +25 -0
  6. package/augment-extensions/coding-standards/c/config/examples/systems.json +31 -0
  7. package/augment-extensions/coding-standards/c/config/schema.json +244 -0
  8. package/augment-extensions/coding-standards/c/docs/API.md +613 -0
  9. package/augment-extensions/coding-standards/c/docs/CONFIGURATION.md +259 -0
  10. package/augment-extensions/coding-standards/c/docs/USER_GUIDE.md +567 -0
  11. package/augment-extensions/coding-standards/c/examples/drivers/Makefile +33 -0
  12. package/augment-extensions/coding-standards/c/examples/drivers/README.md +192 -0
  13. package/augment-extensions/coding-standards/c/examples/drivers/dma-example.c +224 -0
  14. package/augment-extensions/coding-standards/c/examples/drivers/example.dts +64 -0
  15. package/augment-extensions/coding-standards/c/examples/drivers/platform-driver.c +174 -0
  16. package/augment-extensions/coding-standards/c/examples/embedded/README.md +167 -0
  17. package/augment-extensions/coding-standards/c/examples/embedded/gpio-control.c +172 -0
  18. package/augment-extensions/coding-standards/c/examples/embedded/timer-isr.c +198 -0
  19. package/augment-extensions/coding-standards/c/examples/embedded/uart-communication.c +212 -0
  20. package/augment-extensions/coding-standards/c/examples/kernel/Makefile +82 -0
  21. package/augment-extensions/coding-standards/c/examples/kernel/README.md +168 -0
  22. package/augment-extensions/coding-standards/c/examples/kernel/char-device.c +198 -0
  23. package/augment-extensions/coding-standards/c/examples/kernel/proc-file.c +131 -0
  24. package/augment-extensions/coding-standards/c/examples/kernel/simple-module.c +111 -0
  25. package/augment-extensions/coding-standards/c/examples/legacy/Makefile +62 -0
  26. package/augment-extensions/coding-standards/c/examples/legacy/README.md +255 -0
  27. package/augment-extensions/coding-standards/c/examples/legacy/c89-to-c11-migration.c +268 -0
  28. package/augment-extensions/coding-standards/c/examples/legacy/compatibility-layer.c +239 -0
  29. package/augment-extensions/coding-standards/c/examples/networking/Makefile +35 -0
  30. package/augment-extensions/coding-standards/c/examples/networking/README.md +207 -0
  31. package/augment-extensions/coding-standards/c/examples/networking/protocol-parser.c +270 -0
  32. package/augment-extensions/coding-standards/c/examples/networking/tcp-server.c +197 -0
  33. package/augment-extensions/coding-standards/c/examples/networking/udp-multicast.c +220 -0
  34. package/augment-extensions/coding-standards/c/examples/realtime/Makefile +53 -0
  35. package/augment-extensions/coding-standards/c/examples/realtime/README.md +199 -0
  36. package/augment-extensions/coding-standards/c/examples/realtime/deadline-monitoring.c +260 -0
  37. package/augment-extensions/coding-standards/c/examples/realtime/priority-scheduling.c +258 -0
  38. package/augment-extensions/coding-standards/c/examples/systems/Makefile +34 -0
  39. package/augment-extensions/coding-standards/c/examples/systems/README.md +123 -0
  40. package/augment-extensions/coding-standards/c/examples/systems/ipc-pipes.c +181 -0
  41. package/augment-extensions/coding-standards/c/examples/systems/process-management.c +153 -0
  42. package/augment-extensions/coding-standards/c/examples/systems/signal-handling.c +162 -0
  43. package/augment-extensions/coding-standards/c/module.json +149 -0
  44. package/augment-extensions/coding-standards/c/rules/categories/drivers.md +635 -0
  45. package/augment-extensions/coding-standards/c/rules/categories/embedded.md +510 -0
  46. package/augment-extensions/coding-standards/c/rules/categories/kernel.md +653 -0
  47. package/augment-extensions/coding-standards/c/rules/categories/legacy.md +526 -0
  48. package/augment-extensions/coding-standards/c/rules/categories/networking.md +735 -0
  49. package/augment-extensions/coding-standards/c/rules/categories/realtime.md +631 -0
  50. package/augment-extensions/coding-standards/c/rules/categories/systems.md +586 -0
  51. package/augment-extensions/coding-standards/c/rules/universal/const-correctness.md +275 -0
  52. package/augment-extensions/coding-standards/c/rules/universal/documentation.md +251 -0
  53. package/augment-extensions/coding-standards/c/rules/universal/error-handling.md +250 -0
  54. package/augment-extensions/coding-standards/c/rules/universal/header-guards.md +254 -0
  55. package/augment-extensions/coding-standards/c/rules/universal/memory-safety.md +233 -0
  56. package/augment-extensions/coding-standards/c/rules/universal/naming.md +146 -0
  57. package/augment-extensions/coding-standards/c/src/conflict-detector.ts +461 -0
  58. package/augment-extensions/coding-standards/c/src/prompt-generator.ts +307 -0
  59. package/augment-extensions/coding-standards/c/src/rule-evaluator.ts +307 -0
  60. package/augment-extensions/coding-standards/c/src/rule-override.ts +427 -0
  61. package/augment-extensions/coding-standards/c/src/template-engine.ts +217 -0
  62. package/augment-extensions/coding-standards/c/templates/prompts/drivers.txt +191 -0
  63. package/augment-extensions/coding-standards/c/templates/prompts/embedded.txt +164 -0
  64. package/augment-extensions/coding-standards/c/templates/prompts/kernel.txt +175 -0
  65. package/augment-extensions/coding-standards/c/templates/prompts/legacy.txt +280 -0
  66. package/augment-extensions/coding-standards/c/templates/prompts/networking.txt +259 -0
  67. package/augment-extensions/coding-standards/c/templates/prompts/realtime.txt +219 -0
  68. package/augment-extensions/coding-standards/c/templates/prompts/systems.txt +147 -0
  69. package/augment-extensions/coding-standards/c/tests/integration/category-specific.test.ts +356 -0
  70. package/augment-extensions/coding-standards/c/tests/integration/end-to-end-workflow.test.ts +377 -0
  71. package/augment-extensions/coding-standards/c/tests/performance/benchmarks.test.ts +407 -0
  72. package/augment-extensions/coding-standards/c/tests/unit/config-manager.test.ts +345 -0
  73. package/augment-extensions/coding-standards/c/tests/unit/conflict-detector.test.ts +294 -0
  74. package/augment-extensions/coding-standards/c/tests/unit/prompt-generator.test.ts +174 -0
  75. package/augment-extensions/coding-standards/c/tests/unit/registry.test.ts +313 -0
  76. package/augment-extensions/coding-standards/c/tests/unit/rule-evaluator.test.ts +318 -0
  77. package/augment-extensions/coding-standards/c/tests/unit/rule-override.test.ts +326 -0
  78. package/augment-extensions/coding-standards/c/tests/unit/template-engine.test.ts +314 -0
  79. package/augment-extensions/coding-standards/go/CHARACTER-COUNT-REPORT.md +135 -0
  80. package/augment-extensions/coding-standards/go/PHASE1-COMPLETION.md +146 -0
  81. package/augment-extensions/coding-standards/go/PHASE4-COMPLETION.md +184 -0
  82. package/augment-extensions/coding-standards/go/README.md +200 -0
  83. package/augment-extensions/coding-standards/go/VALIDATION-CHECKLIST.md +154 -0
  84. package/augment-extensions/coding-standards/go/config/examples/example-cli.json +15 -0
  85. package/augment-extensions/coding-standards/go/config/examples/example-microservices.json +21 -0
  86. package/augment-extensions/coding-standards/go/config/examples/example-multi-category.yaml +24 -0
  87. package/augment-extensions/coding-standards/go/config/examples/example-web.json +15 -0
  88. package/augment-extensions/coding-standards/go/config/schema.json +110 -0
  89. package/augment-extensions/coding-standards/go/docs/CATEGORIES.md +221 -0
  90. package/augment-extensions/coding-standards/go/docs/CONFIGURATION.md +198 -0
  91. package/augment-extensions/coding-standards/go/docs/TROUBLESHOOTING.md +285 -0
  92. package/augment-extensions/coding-standards/go/examples/cli/cobra-app.go +287 -0
  93. package/augment-extensions/coding-standards/go/examples/cloud-native-app.go +217 -0
  94. package/augment-extensions/coding-standards/go/examples/devops-tool.go +250 -0
  95. package/augment-extensions/coding-standards/go/examples/distributed-system.go +247 -0
  96. package/augment-extensions/coding-standards/go/examples/microservices/grpc-service.go +253 -0
  97. package/augment-extensions/coding-standards/go/examples/rest-api.go +270 -0
  98. package/augment-extensions/coding-standards/go/examples/web/http-server.go +224 -0
  99. package/augment-extensions/coding-standards/go/module.json +139 -0
  100. package/augment-extensions/coding-standards/go/rules/categories/api-development/api-versioning.md +149 -0
  101. package/augment-extensions/coding-standards/go/rules/categories/api-development/rate-limiting.md +209 -0
  102. package/augment-extensions/coding-standards/go/rules/categories/api-development/rest-api-design.md +183 -0
  103. package/augment-extensions/coding-standards/go/rules/categories/cloud-native/cloud-config.md +193 -0
  104. package/augment-extensions/coding-standards/go/rules/categories/cloud-native/health-checks.md +231 -0
  105. package/augment-extensions/coding-standards/go/rules/categories/cloud-native/kubernetes.md +180 -0
  106. package/augment-extensions/coding-standards/go/rules/categories/devops-tooling/automation.md +179 -0
  107. package/augment-extensions/coding-standards/go/rules/categories/devops-tooling/ci-cd-integration.md +147 -0
  108. package/augment-extensions/coding-standards/go/rules/categories/devops-tooling/infrastructure-as-code.md +231 -0
  109. package/augment-extensions/coding-standards/go/rules/categories/distributed-systems/caching.md +150 -0
  110. package/augment-extensions/coding-standards/go/rules/categories/distributed-systems/consensus.md +187 -0
  111. package/augment-extensions/coding-standards/go/rules/categories/distributed-systems/event-sourcing.md +246 -0
  112. package/augment-extensions/coding-standards/go/rules/cli/command-parsing.md +264 -0
  113. package/augment-extensions/coding-standards/go/rules/cli/configuration.md +268 -0
  114. package/augment-extensions/coding-standards/go/rules/cli/cross-platform.md +324 -0
  115. package/augment-extensions/coding-standards/go/rules/microservices/distributed-tracing.md +253 -0
  116. package/augment-extensions/coding-standards/go/rules/microservices/grpc.md +257 -0
  117. package/augment-extensions/coding-standards/go/rules/microservices/metrics.md +278 -0
  118. package/augment-extensions/coding-standards/go/rules/microservices/service-discovery.md +249 -0
  119. package/augment-extensions/coding-standards/go/rules/universal/code-organization.md +221 -0
  120. package/augment-extensions/coding-standards/go/rules/universal/documentation.md +269 -0
  121. package/augment-extensions/coding-standards/go/rules/universal/performance.md +323 -0
  122. package/augment-extensions/coding-standards/go/rules/universal/testing.md +162 -0
  123. package/augment-extensions/coding-standards/go/rules/web/graceful-shutdown.md +249 -0
  124. package/augment-extensions/coding-standards/go/rules/web/http-handlers.md +164 -0
  125. package/augment-extensions/coding-standards/go/rules/web/middleware.md +234 -0
  126. package/augment-extensions/coding-standards/go/rules/web/routing.md +251 -0
  127. package/augment-extensions/coding-standards/go/templates/prompts/api.md +160 -0
  128. package/augment-extensions/coding-standards/go/templates/prompts/cli.md +225 -0
  129. package/augment-extensions/coding-standards/go/templates/prompts/cloud-native.md +121 -0
  130. package/augment-extensions/coding-standards/go/templates/prompts/devops.md +146 -0
  131. package/augment-extensions/coding-standards/go/templates/prompts/distributed.md +133 -0
  132. package/augment-extensions/coding-standards/go/templates/prompts/microservices.md +225 -0
  133. package/augment-extensions/coding-standards/go/templates/prompts/web.md +181 -0
  134. package/augment-extensions/coding-standards/go/tests/integration/module-integration.test.ts +164 -0
  135. package/augment-extensions/coding-standards/go/tests/unit/category-selection.test.ts +147 -0
  136. package/augment-extensions/coding-standards/go/tests/unit/module-structure.test.ts +154 -0
  137. package/augment-extensions/coding-standards/go/tests/validate-character-count.ps1 +13 -0
  138. package/augment-extensions/coding-standards/go/tests/validate-examples.ps1 +148 -0
  139. package/augment-extensions/coding-standards/go/tests/validate-examples.sh +135 -0
  140. package/cli/dist/analysis/ast-parser.d.ts +47 -0
  141. package/cli/dist/analysis/ast-parser.d.ts.map +1 -0
  142. package/cli/dist/analysis/ast-parser.js +161 -0
  143. package/cli/dist/analysis/ast-parser.js.map +1 -0
  144. package/cli/dist/analysis/complexity-analyzer.d.ts +27 -0
  145. package/cli/dist/analysis/complexity-analyzer.d.ts.map +1 -0
  146. package/cli/dist/analysis/complexity-analyzer.js +189 -0
  147. package/cli/dist/analysis/complexity-analyzer.js.map +1 -0
  148. package/cli/dist/analysis/dependency-analyzer.d.ts +23 -0
  149. package/cli/dist/analysis/dependency-analyzer.d.ts.map +1 -0
  150. package/cli/dist/analysis/dependency-analyzer.js +237 -0
  151. package/cli/dist/analysis/dependency-analyzer.js.map +1 -0
  152. package/cli/dist/analysis/index.d.ts +9 -0
  153. package/cli/dist/analysis/index.d.ts.map +1 -0
  154. package/cli/dist/analysis/index.js +25 -0
  155. package/cli/dist/analysis/index.js.map +1 -0
  156. package/cli/dist/analysis/security-scanner.d.ts +11 -0
  157. package/cli/dist/analysis/security-scanner.d.ts.map +1 -0
  158. package/cli/dist/analysis/security-scanner.js +294 -0
  159. package/cli/dist/analysis/security-scanner.js.map +1 -0
  160. package/cli/dist/analysis/types.d.ts +151 -0
  161. package/cli/dist/analysis/types.d.ts.map +1 -0
  162. package/cli/dist/analysis/types.js +6 -0
  163. package/cli/dist/analysis/types.js.map +1 -0
  164. package/cli/dist/cli.js +24 -0
  165. package/cli/dist/cli.js.map +1 -1
  166. package/cli/dist/commands/code-analysis.d.ts +11 -0
  167. package/cli/dist/commands/code-analysis.d.ts.map +1 -0
  168. package/cli/dist/commands/code-analysis.js +412 -0
  169. package/cli/dist/commands/code-analysis.js.map +1 -0
  170. package/modules.md +99 -3
  171. package/package.json +14 -2
  172. package/cli/dist/commands/agent.d.ts +0 -37
  173. package/cli/dist/commands/agent.d.ts.map +0 -1
  174. package/cli/dist/commands/agent.js +0 -222
  175. package/cli/dist/commands/agent.js.map +0 -1
  176. package/cli/dist/commands/beads.d.ts +0 -64
  177. package/cli/dist/commands/beads.d.ts.map +0 -1
  178. package/cli/dist/commands/beads.js +0 -377
  179. package/cli/dist/commands/beads.js.map +0 -1
  180. package/cli/dist/commands/change.d.ts +0 -54
  181. package/cli/dist/commands/change.d.ts.map +0 -1
  182. package/cli/dist/commands/change.js +0 -243
  183. package/cli/dist/commands/change.js.map +0 -1
  184. package/cli/dist/commands/clean.d.ts +0 -15
  185. package/cli/dist/commands/clean.d.ts.map +0 -1
  186. package/cli/dist/commands/clean.js +0 -63
  187. package/cli/dist/commands/clean.js.map +0 -1
  188. package/cli/dist/commands/clone.d.ts +0 -15
  189. package/cli/dist/commands/clone.d.ts.map +0 -1
  190. package/cli/dist/commands/clone.js +0 -49
  191. package/cli/dist/commands/clone.js.map +0 -1
  192. package/cli/dist/commands/config.d.ts +0 -33
  193. package/cli/dist/commands/config.d.ts.map +0 -1
  194. package/cli/dist/commands/config.js +0 -166
  195. package/cli/dist/commands/config.js.map +0 -1
  196. package/cli/dist/commands/context.d.ts +0 -38
  197. package/cli/dist/commands/context.d.ts.map +0 -1
  198. package/cli/dist/commands/context.js +0 -205
  199. package/cli/dist/commands/context.js.map +0 -1
  200. package/cli/dist/commands/create.d.ts +0 -18
  201. package/cli/dist/commands/create.d.ts.map +0 -1
  202. package/cli/dist/commands/create.js +0 -178
  203. package/cli/dist/commands/create.js.map +0 -1
  204. package/cli/dist/commands/diff.d.ts +0 -19
  205. package/cli/dist/commands/diff.d.ts.map +0 -1
  206. package/cli/dist/commands/diff.js +0 -104
  207. package/cli/dist/commands/diff.js.map +0 -1
  208. package/cli/dist/commands/doctor.d.ts +0 -14
  209. package/cli/dist/commands/doctor.d.ts.map +0 -1
  210. package/cli/dist/commands/doctor.js +0 -62
  211. package/cli/dist/commands/doctor.js.map +0 -1
  212. package/cli/dist/commands/export.d.ts +0 -28
  213. package/cli/dist/commands/export.d.ts.map +0 -1
  214. package/cli/dist/commands/export.js +0 -135
  215. package/cli/dist/commands/export.js.map +0 -1
  216. package/cli/dist/commands/import.d.ts +0 -23
  217. package/cli/dist/commands/import.d.ts.map +0 -1
  218. package/cli/dist/commands/import.js +0 -118
  219. package/cli/dist/commands/import.js.map +0 -1
  220. package/cli/dist/commands/prompt.d.ts +0 -45
  221. package/cli/dist/commands/prompt.d.ts.map +0 -1
  222. package/cli/dist/commands/prompt.js +0 -223
  223. package/cli/dist/commands/prompt.js.map +0 -1
  224. package/cli/dist/commands/spec.d.ts +0 -57
  225. package/cli/dist/commands/spec.d.ts.map +0 -1
  226. package/cli/dist/commands/spec.js +0 -279
  227. package/cli/dist/commands/spec.js.map +0 -1
  228. package/cli/dist/commands/stats.d.ts +0 -18
  229. package/cli/dist/commands/stats.d.ts.map +0 -1
  230. package/cli/dist/commands/stats.js +0 -85
  231. package/cli/dist/commands/stats.js.map +0 -1
  232. package/cli/dist/commands/task.d.ts +0 -65
  233. package/cli/dist/commands/task.d.ts.map +0 -1
  234. package/cli/dist/commands/task.js +0 -282
  235. package/cli/dist/commands/task.js.map +0 -1
  236. package/cli/dist/commands/template.d.ts +0 -17
  237. package/cli/dist/commands/template.d.ts.map +0 -1
  238. package/cli/dist/commands/template.js +0 -55
  239. package/cli/dist/commands/template.js.map +0 -1
  240. package/cli/dist/utils/agent-config.d.ts +0 -129
  241. package/cli/dist/utils/agent-config.d.ts.map +0 -1
  242. package/cli/dist/utils/agent-config.js +0 -297
  243. package/cli/dist/utils/agent-config.js.map +0 -1
  244. package/cli/dist/utils/beads-graph.d.ts +0 -17
  245. package/cli/dist/utils/beads-graph.d.ts.map +0 -1
  246. package/cli/dist/utils/beads-graph.js +0 -150
  247. package/cli/dist/utils/beads-graph.js.map +0 -1
  248. package/cli/dist/utils/beads-integration.d.ts +0 -112
  249. package/cli/dist/utils/beads-integration.d.ts.map +0 -1
  250. package/cli/dist/utils/beads-integration.js +0 -312
  251. package/cli/dist/utils/beads-integration.js.map +0 -1
  252. package/cli/dist/utils/beads-reporter.d.ts +0 -17
  253. package/cli/dist/utils/beads-reporter.d.ts.map +0 -1
  254. package/cli/dist/utils/beads-reporter.js +0 -160
  255. package/cli/dist/utils/beads-reporter.js.map +0 -1
  256. package/cli/dist/utils/cache-manager.d.ts +0 -55
  257. package/cli/dist/utils/cache-manager.d.ts.map +0 -1
  258. package/cli/dist/utils/cache-manager.js +0 -150
  259. package/cli/dist/utils/cache-manager.js.map +0 -1
  260. package/cli/dist/utils/change-manager.d.ts +0 -70
  261. package/cli/dist/utils/change-manager.d.ts.map +0 -1
  262. package/cli/dist/utils/change-manager.js +0 -412
  263. package/cli/dist/utils/change-manager.js.map +0 -1
  264. package/cli/dist/utils/config-manager-enhanced.d.ts +0 -66
  265. package/cli/dist/utils/config-manager-enhanced.d.ts.map +0 -1
  266. package/cli/dist/utils/config-manager-enhanced.js +0 -77
  267. package/cli/dist/utils/config-manager-enhanced.js.map +0 -1
  268. package/cli/dist/utils/context-manager.d.ts +0 -96
  269. package/cli/dist/utils/context-manager.d.ts.map +0 -1
  270. package/cli/dist/utils/context-manager.js +0 -258
  271. package/cli/dist/utils/context-manager.js.map +0 -1
  272. package/cli/dist/utils/diff-engine.d.ts +0 -78
  273. package/cli/dist/utils/diff-engine.d.ts.map +0 -1
  274. package/cli/dist/utils/diff-engine.js +0 -233
  275. package/cli/dist/utils/diff-engine.js.map +0 -1
  276. package/cli/dist/utils/export-system.d.ts +0 -101
  277. package/cli/dist/utils/export-system.d.ts.map +0 -1
  278. package/cli/dist/utils/export-system.js +0 -289
  279. package/cli/dist/utils/export-system.js.map +0 -1
  280. package/cli/dist/utils/health-checker.d.ts +0 -66
  281. package/cli/dist/utils/health-checker.d.ts.map +0 -1
  282. package/cli/dist/utils/health-checker.js +0 -285
  283. package/cli/dist/utils/health-checker.js.map +0 -1
  284. package/cli/dist/utils/import-system.d.ts +0 -74
  285. package/cli/dist/utils/import-system.d.ts.map +0 -1
  286. package/cli/dist/utils/import-system.js +0 -317
  287. package/cli/dist/utils/import-system.js.map +0 -1
  288. package/cli/dist/utils/module-cloner.d.ts +0 -40
  289. package/cli/dist/utils/module-cloner.d.ts.map +0 -1
  290. package/cli/dist/utils/module-cloner.js +0 -136
  291. package/cli/dist/utils/module-cloner.js.map +0 -1
  292. package/cli/dist/utils/prompt-manager.d.ts +0 -90
  293. package/cli/dist/utils/prompt-manager.d.ts.map +0 -1
  294. package/cli/dist/utils/prompt-manager.js +0 -302
  295. package/cli/dist/utils/prompt-manager.js.map +0 -1
  296. package/cli/dist/utils/spec-manager.d.ts +0 -65
  297. package/cli/dist/utils/spec-manager.d.ts.map +0 -1
  298. package/cli/dist/utils/spec-manager.js +0 -329
  299. package/cli/dist/utils/spec-manager.js.map +0 -1
  300. package/cli/dist/utils/stats-collector.d.ts +0 -74
  301. package/cli/dist/utils/stats-collector.d.ts.map +0 -1
  302. package/cli/dist/utils/stats-collector.js +0 -164
  303. package/cli/dist/utils/stats-collector.js.map +0 -1
  304. package/cli/dist/utils/template-engine.d.ts +0 -47
  305. package/cli/dist/utils/template-engine.d.ts.map +0 -1
  306. package/cli/dist/utils/template-engine.js +0 -204
  307. package/cli/dist/utils/template-engine.js.map +0 -1
@@ -0,0 +1,323 @@
1
+ # Go Performance Rules
2
+
3
+ ## Overview
4
+
5
+ This document defines universal performance optimization best practices for Go projects. These rules apply to all Go code regardless of project category.
6
+
7
+ ## Core Principles
8
+
9
+ 1. **Allocation Minimization**: Reduce heap allocations in hot paths
10
+ 2. **Object Reuse**: Use `sync.Pool` for frequently allocated objects
11
+ 3. **Profiling**: Use pprof to identify bottlenecks before optimizing
12
+ 4. **Benchmarking**: Write benchmarks to measure performance improvements
13
+ 5. **Escape Analysis**: Understand and leverage escape analysis
14
+
15
+ ## Rules
16
+
17
+ ### GOL.2.7.1: Allocation Minimization Techniques
18
+
19
+ **Rule**: Minimize heap allocations in performance-critical code paths.
20
+
21
+ **Rationale**: Heap allocations are expensive and increase GC pressure. Stack allocations are much faster.
22
+
23
+ **Techniques**:
24
+
25
+ **1. Preallocate Slices**:
26
+ ```go
27
+ // Bad: Multiple allocations as slice grows
28
+ func processItems(n int) []Item {
29
+ var items []Item
30
+ for i := 0; i < n; i++ {
31
+ items = append(items, Item{ID: i})
32
+ }
33
+ return items
34
+ }
35
+
36
+ // Good: Single allocation with known capacity
37
+ func processItems(n int) []Item {
38
+ items := make([]Item, 0, n)
39
+ for i := 0; i < n; i++ {
40
+ items = append(items, Item{ID: i})
41
+ }
42
+ return items
43
+ }
44
+ ```
45
+
46
+ **2. Reuse Buffers**:
47
+ ```go
48
+ // Bad: New buffer for each call
49
+ func formatMessage(msg string) string {
50
+ var buf bytes.Buffer
51
+ buf.WriteString("[INFO] ")
52
+ buf.WriteString(msg)
53
+ return buf.String()
54
+ }
55
+
56
+ // Good: Reuse buffer with Reset()
57
+ var bufPool = sync.Pool{
58
+ New: func() interface{} {
59
+ return new(bytes.Buffer)
60
+ },
61
+ }
62
+
63
+ func formatMessage(msg string) string {
64
+ buf := bufPool.Get().(*bytes.Buffer)
65
+ defer bufPool.Put(buf)
66
+ buf.Reset()
67
+ buf.WriteString("[INFO] ")
68
+ buf.WriteString(msg)
69
+ return buf.String()
70
+ }
71
+ ```
72
+
73
+ **3. Avoid String Concatenation in Loops**:
74
+ ```go
75
+ // Bad: Creates new string on each iteration
76
+ func joinStrings(items []string) string {
77
+ result := ""
78
+ for _, item := range items {
79
+ result += item + ","
80
+ }
81
+ return result
82
+ }
83
+
84
+ // Good: Use strings.Builder
85
+ func joinStrings(items []string) string {
86
+ var sb strings.Builder
87
+ sb.Grow(len(items) * 10) // Preallocate approximate size
88
+ for i, item := range items {
89
+ if i > 0 {
90
+ sb.WriteString(",")
91
+ }
92
+ sb.WriteString(item)
93
+ }
94
+ return sb.String()
95
+ }
96
+ ```
97
+
98
+ ### GOL.2.7.2: sync.Pool for Object Reuse
99
+
100
+ **Rule**: Use `sync.Pool` to reuse frequently allocated objects and reduce GC pressure.
101
+
102
+ **Rationale**: `sync.Pool` provides a cache of reusable objects, reducing allocation overhead.
103
+
104
+ **Example**:
105
+ ```go
106
+ // Define a pool for buffers
107
+ var bufferPool = sync.Pool{
108
+ New: func() interface{} {
109
+ return new(bytes.Buffer)
110
+ },
111
+ }
112
+
113
+ // Use the pool
114
+ func processData(data []byte) (string, error) {
115
+ // Get buffer from pool
116
+ buf := bufferPool.Get().(*bytes.Buffer)
117
+ defer func() {
118
+ buf.Reset() // Clear buffer
119
+ bufferPool.Put(buf) // Return to pool
120
+ }()
121
+
122
+ // Use buffer
123
+ buf.Write(data)
124
+ return buf.String(), nil
125
+ }
126
+ ```
127
+
128
+ **Best Practices**:
129
+ - Always call `Reset()` before returning objects to the pool
130
+ - Use `defer` to ensure objects are returned even on error
131
+ - Don't store references to pooled objects after returning them
132
+ - Pool objects should be safe to reuse after `Reset()`
133
+
134
+ ### GOL.2.7.3: Profiling with pprof
135
+
136
+ **Rule**: Use pprof to profile CPU, memory, and goroutine usage before optimizing.
137
+
138
+ **Rationale**: Profile-guided optimization is more effective than guessing. Measure first, optimize second.
139
+
140
+ **CPU Profiling**:
141
+ ```go
142
+ import (
143
+ "os"
144
+ "runtime/pprof"
145
+ )
146
+
147
+ func main() {
148
+ // Start CPU profiling
149
+ f, err := os.Create("cpu.prof")
150
+ if err != nil {
151
+ log.Fatal(err)
152
+ }
153
+ defer f.Close()
154
+
155
+ if err := pprof.StartCPUProfile(f); err != nil {
156
+ log.Fatal(err)
157
+ }
158
+ defer pprof.StopCPUProfile()
159
+
160
+ // Run your code
161
+ doWork()
162
+ }
163
+ ```
164
+
165
+ **Memory Profiling**:
166
+ ```go
167
+ import (
168
+ "os"
169
+ "runtime"
170
+ "runtime/pprof"
171
+ )
172
+
173
+ func main() {
174
+ // Run your code
175
+ doWork()
176
+
177
+ // Write memory profile
178
+ f, err := os.Create("mem.prof")
179
+ if err != nil {
180
+ log.Fatal(err)
181
+ }
182
+ defer f.Close()
183
+
184
+ runtime.GC() // Get up-to-date statistics
185
+ if err := pprof.WriteHeapProfile(f); err != nil {
186
+ log.Fatal(err)
187
+ }
188
+ }
189
+ ```
190
+
191
+ **Analyzing Profiles**:
192
+ ```bash
193
+ # CPU profile
194
+ go tool pprof cpu.prof
195
+ # Commands: top, list, web
196
+
197
+ # Memory profile
198
+ go tool pprof mem.prof
199
+ # Commands: top, list, web
200
+
201
+ # HTTP server profiling (import _ "net/http/pprof")
202
+ go tool pprof http://localhost:6060/debug/pprof/profile
203
+ go tool pprof http://localhost:6060/debug/pprof/heap
204
+ ```
205
+
206
+ ### GOL.2.7.4: Benchmark Writing and Interpretation
207
+
208
+ **Rule**: Write benchmarks to measure performance and track regressions.
209
+
210
+ **Rationale**: Benchmarks provide objective measurements and catch performance regressions.
211
+
212
+ **Example**:
213
+ ```go
214
+ func BenchmarkStringConcatenation(b *testing.B) {
215
+ for i := 0; i < b.N; i++ {
216
+ _ = "hello" + " " + "world"
217
+ }
218
+ }
219
+
220
+ func BenchmarkStringBuilder(b *testing.B) {
221
+ for i := 0; i < b.N; i++ {
222
+ var sb strings.Builder
223
+ sb.WriteString("hello")
224
+ sb.WriteString(" ")
225
+ sb.WriteString("world")
226
+ _ = sb.String()
227
+ }
228
+ }
229
+
230
+ // Benchmark with setup
231
+ func BenchmarkMapLookup(b *testing.B) {
232
+ m := make(map[string]int)
233
+ for i := 0; i < 1000; i++ {
234
+ m[fmt.Sprintf("key%d", i)] = i
235
+ }
236
+
237
+ b.ResetTimer() // Don't count setup time
238
+
239
+ for i := 0; i < b.N; i++ {
240
+ _ = m["key500"]
241
+ }
242
+ }
243
+ ```
244
+
245
+ **Running Benchmarks**:
246
+ ```bash
247
+ # Run all benchmarks
248
+ go test -bench=.
249
+
250
+ # Run specific benchmark
251
+ go test -bench=BenchmarkStringBuilder
252
+
253
+ # With memory statistics
254
+ go test -bench=. -benchmem
255
+
256
+ # Compare benchmarks
257
+ go test -bench=. -benchmem > old.txt
258
+ # Make changes
259
+ go test -bench=. -benchmem > new.txt
260
+ benchstat old.txt new.txt
261
+ ```
262
+
263
+ ### GOL.2.7.5: Escape Analysis and Optimization
264
+
265
+ **Rule**: Understand escape analysis to keep allocations on the stack when possible.
266
+
267
+ **Rationale**: Stack allocations are much faster than heap allocations and don't require GC.
268
+
269
+ **Check Escape Analysis**:
270
+ ```bash
271
+ go build -gcflags='-m' main.go
272
+ ```
273
+
274
+ **Example**:
275
+ ```go
276
+ // Escapes to heap (returned pointer)
277
+ func createUser() *User {
278
+ u := User{Name: "Alice"}
279
+ return &u // Escapes: returned to caller
280
+ }
281
+
282
+ // Stays on stack (value returned)
283
+ func createUser() User {
284
+ return User{Name: "Alice"}
285
+ }
286
+
287
+ // Escapes to heap (stored in interface)
288
+ func processUser(u *User) {
289
+ var i interface{} = u // Escapes: stored in interface
290
+ fmt.Println(i)
291
+ }
292
+
293
+ // Stays on stack (no escape)
294
+ func processUser(u *User) {
295
+ fmt.Println(u.Name) // No escape: direct field access
296
+ }
297
+ ```
298
+
299
+ **Optimization Tips**:
300
+ - Return values instead of pointers when possible
301
+ - Avoid storing pointers in interfaces in hot paths
302
+ - Use value receivers for small structs
303
+ - Preallocate slices with known capacity
304
+ - Avoid closures that capture large variables
305
+
306
+ ## Performance Checklist
307
+
308
+ - [ ] Profile before optimizing (CPU, memory, goroutines)
309
+ - [ ] Write benchmarks for critical paths
310
+ - [ ] Preallocate slices with known capacity
311
+ - [ ] Use `sync.Pool` for frequently allocated objects
312
+ - [ ] Use `strings.Builder` for string concatenation
313
+ - [ ] Check escape analysis for hot paths
314
+ - [ ] Minimize allocations in loops
315
+ - [ ] Reuse buffers and objects
316
+ - [ ] Use `benchstat` to compare performance changes
317
+
318
+ ## References
319
+
320
+ - [Go Performance Tips](https://github.com/dgryski/go-perfbook)
321
+ - [Profiling Go Programs](https://go.dev/blog/pprof)
322
+ - [Escape Analysis](https://www.ardanlabs.com/blog/2017/05/language-mechanics-on-escape-analysis.html)
323
+
@@ -0,0 +1,162 @@
1
+ # Go Testing Rules
2
+
3
+ ## Overview
4
+
5
+ This document defines universal testing best practices for Go projects. These rules apply to all Go code regardless of project category.
6
+
7
+ ## Core Principles
8
+
9
+ 1. **Table-Driven Tests**: Use table-driven tests for comprehensive coverage
10
+ 2. **Subtests**: Organize tests with `t.Run()` for clarity and isolation
11
+ 3. **Benchmarks**: Write benchmarks to measure and track performance
12
+ 4. **Test Helpers**: Use `t.Helper()` to improve error reporting
13
+ 5. **Test Coverage**: Aim for >80% code coverage with meaningful tests
14
+
15
+ ## Rules
16
+
17
+ ### GOL.2.4.1: Table-Driven Test Pattern
18
+
19
+ **Rule**: Use table-driven tests to test multiple scenarios with the same logic.
20
+
21
+ **Rationale**: Reduces code duplication, improves readability, and makes it easy to add new test cases.
22
+
23
+ **Example**:
24
+ ```go
25
+ func TestAdd(t *testing.T) {
26
+ tests := []struct {
27
+ name string
28
+ a, b int
29
+ expected int
30
+ }{
31
+ {"positive numbers", 2, 3, 5},
32
+ {"negative numbers", -2, -3, -5},
33
+ {"mixed signs", -2, 3, 1},
34
+ {"zero values", 0, 0, 0},
35
+ }
36
+
37
+ for _, tt := range tests {
38
+ t.Run(tt.name, func(t *testing.T) {
39
+ result := Add(tt.a, tt.b)
40
+ if result != tt.expected {
41
+ t.Errorf("Add(%d, %d) = %d; want %d", tt.a, tt.b, result, tt.expected)
42
+ }
43
+ })
44
+ }
45
+ }
46
+ ```
47
+
48
+ ### GOL.2.4.2: Subtest Usage with t.Run()
49
+
50
+ **Rule**: Use `t.Run()` to create subtests for better organization and parallel execution.
51
+
52
+ **Rationale**: Subtests provide clear test names, allow running specific tests, and enable parallel execution.
53
+
54
+ **Example**:
55
+ ```go
56
+ func TestUserValidation(t *testing.T) {
57
+ t.Run("valid email", func(t *testing.T) {
58
+ t.Parallel()
59
+ user := User{Email: "test@example.com"}
60
+ if err := user.Validate(); err != nil {
61
+ t.Errorf("expected valid email, got error: %v", err)
62
+ }
63
+ })
64
+
65
+ t.Run("invalid email", func(t *testing.T) {
66
+ t.Parallel()
67
+ user := User{Email: "invalid"}
68
+ if err := user.Validate(); err == nil {
69
+ t.Error("expected error for invalid email")
70
+ }
71
+ })
72
+ }
73
+ ```
74
+
75
+ ### GOL.2.4.3: Benchmark Writing
76
+
77
+ **Rule**: Write benchmarks for performance-critical code using the `testing.B` type.
78
+
79
+ **Rationale**: Benchmarks help identify performance regressions and optimization opportunities.
80
+
81
+ **Example**:
82
+ ```go
83
+ func BenchmarkStringConcatenation(b *testing.B) {
84
+ for i := 0; i < b.N; i++ {
85
+ _ = "hello" + "world"
86
+ }
87
+ }
88
+
89
+ func BenchmarkStringBuilder(b *testing.B) {
90
+ for i := 0; i < b.N; i++ {
91
+ var sb strings.Builder
92
+ sb.WriteString("hello")
93
+ sb.WriteString("world")
94
+ _ = sb.String()
95
+ }
96
+ }
97
+ ```
98
+
99
+ ### GOL.2.4.4: Test Helper Functions with t.Helper()
100
+
101
+ **Rule**: Mark test helper functions with `t.Helper()` to improve error reporting.
102
+
103
+ **Rationale**: `t.Helper()` ensures error messages point to the calling test, not the helper function.
104
+
105
+ **Example**:
106
+ ```go
107
+ func assertNoError(t *testing.T, err error) {
108
+ t.Helper()
109
+ if err != nil {
110
+ t.Fatalf("unexpected error: %v", err)
111
+ }
112
+ }
113
+
114
+ func assertEqual(t *testing.T, got, want interface{}) {
115
+ t.Helper()
116
+ if got != want {
117
+ t.Errorf("got %v; want %v", got, want)
118
+ }
119
+ }
120
+
121
+ func TestUserCreation(t *testing.T) {
122
+ user, err := NewUser("test@example.com")
123
+ assertNoError(t, err)
124
+ assertEqual(t, user.Email, "test@example.com")
125
+ }
126
+ ```
127
+
128
+ ### GOL.2.4.5: Test Organization and Best Practices
129
+
130
+ **Rule**: Follow Go testing conventions for file naming, test naming, and test organization.
131
+
132
+ **Best Practices**:
133
+ - Test files end with `_test.go`
134
+ - Test functions start with `Test` prefix
135
+ - Benchmark functions start with `Benchmark` prefix
136
+ - Example functions start with `Example` prefix
137
+ - Use `testdata/` directory for test fixtures
138
+ - Use `testing.Short()` to skip long-running tests
139
+ - Clean up resources with `t.Cleanup()`
140
+
141
+ **Example**:
142
+ ```go
143
+ func TestDatabaseOperations(t *testing.T) {
144
+ if testing.Short() {
145
+ t.Skip("skipping database test in short mode")
146
+ }
147
+
148
+ db := setupTestDB(t)
149
+ t.Cleanup(func() {
150
+ db.Close()
151
+ })
152
+
153
+ // Test logic here
154
+ }
155
+ ```
156
+
157
+ ## References
158
+
159
+ - [Go Testing Package](https://pkg.go.dev/testing)
160
+ - [Table Driven Tests](https://github.com/golang/go/wiki/TableDrivenTests)
161
+ - [Go Testing Best Practices](https://go.dev/doc/effective_go#testing)
162
+