cdk-cost-analyzer 0.1.1

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 (228) hide show
  1. package/.cdk-cost-analyzer-cache/metadata.json +12 -0
  2. package/.gitlab-ci.yml +214 -0
  3. package/.husky/pre-commit +12 -0
  4. package/.kiro/hooks/accessibility-audit.kiro.hook +18 -0
  5. package/.kiro/hooks/api-schema-validation.kiro.hook +21 -0
  6. package/.kiro/hooks/auto-test-on-save.kiro.hook +19 -0
  7. package/.kiro/hooks/cdk-synth-on-change.kiro.hook +20 -0
  8. package/.kiro/hooks/code-coverage-check.kiro.hook +14 -0
  9. package/.kiro/hooks/commit-message-helper.kiro.hook +14 -0
  10. package/.kiro/hooks/dependency-update-check.kiro.hook +14 -0
  11. package/.kiro/hooks/env-file-validation.kiro.hook +18 -0
  12. package/.kiro/hooks/lint-and-format-on-save.kiro.hook +21 -0
  13. package/.kiro/hooks/mcp-config-validation.kiro.hook +17 -0
  14. package/.kiro/hooks/mcp-server-test.kiro.hook +14 -0
  15. package/.kiro/hooks/performance-analysis.kiro.hook +14 -0
  16. package/.kiro/hooks/readme-spell-check.kiro.hook +14 -0
  17. package/.kiro/hooks/security-scan-on-dependency-change.kiro.hook +21 -0
  18. package/.kiro/hooks/translation-update.kiro.hook +18 -0
  19. package/.kiro/hooks/update-documentation.kiro.hook +18 -0
  20. package/.kiro/settings/mcp.json +20 -0
  21. package/.kiro/specs/cdk-cost-analyzer/design.md +620 -0
  22. package/.kiro/specs/cdk-cost-analyzer/requirements.md +183 -0
  23. package/.kiro/specs/cdk-cost-analyzer/tasks.md +357 -0
  24. package/.kiro/specs/github-actions-ci/design.md +281 -0
  25. package/.kiro/specs/github-actions-ci/requirements.md +86 -0
  26. package/.kiro/specs/github-actions-ci/tasks.md +115 -0
  27. package/.kiro/specs/nlb-calculator-test-coverage/design.md +190 -0
  28. package/.kiro/specs/nlb-calculator-test-coverage/requirements.md +84 -0
  29. package/.kiro/specs/nlb-calculator-test-coverage/tasks.md +150 -0
  30. package/.kiro/specs/production-readiness/design.md +1213 -0
  31. package/.kiro/specs/production-readiness/requirements.md +312 -0
  32. package/.kiro/specs/production-readiness/tasks.md +269 -0
  33. package/.kiro/specs/repository-cleanup/design.md +283 -0
  34. package/.kiro/specs/repository-cleanup/requirements.md +74 -0
  35. package/.kiro/specs/repository-cleanup/tasks.md +64 -0
  36. package/.kiro/steering/aws-cli-best-practices.md +41 -0
  37. package/.kiro/steering/cdk-best-practices.md +49 -0
  38. package/.kiro/steering/development-standards.md +54 -0
  39. package/.kiro/steering/docker-best-practices.md +34 -0
  40. package/.kiro/steering/documentation-style.md +151 -0
  41. package/.kiro/steering/git-best-practices.md +37 -0
  42. package/.kiro/steering/mcp-best-practices.md +95 -0
  43. package/.kiro/steering/python-best-practices.md +48 -0
  44. package/.kiro/steering/react-best-practices.md +44 -0
  45. package/.kiro/steering/security-best-practices.md +41 -0
  46. package/.kiro/steering/testing-best-practices.md +59 -0
  47. package/.kiro/steering/typescript-best-practices.md +40 -0
  48. package/CHANGELOG.md +49 -0
  49. package/CONTRIBUTING.md +258 -0
  50. package/LICENSE +19 -0
  51. package/README.md +480 -0
  52. package/SECURITY.md +117 -0
  53. package/dist/api/index.d.ts +11 -0
  54. package/dist/api/index.js +65 -0
  55. package/dist/api/types.d.ts +15 -0
  56. package/dist/api/types.js +3 -0
  57. package/dist/cli/index.d.ts +2 -0
  58. package/dist/cli/index.js +262 -0
  59. package/dist/config/ConfigManager.d.ts +40 -0
  60. package/dist/config/ConfigManager.js +238 -0
  61. package/dist/config/index.d.ts +2 -0
  62. package/dist/config/index.js +19 -0
  63. package/dist/config/types.d.ts +72 -0
  64. package/dist/config/types.js +15 -0
  65. package/dist/diff/DiffEngine.d.ts +7 -0
  66. package/dist/diff/DiffEngine.js +73 -0
  67. package/dist/diff/index.d.ts +2 -0
  68. package/dist/diff/index.js +21 -0
  69. package/dist/diff/types.d.ts +20 -0
  70. package/dist/diff/types.js +3 -0
  71. package/dist/integrations/GitLabIntegration.d.ts +7 -0
  72. package/dist/integrations/GitLabIntegration.js +45 -0
  73. package/dist/integrations/index.d.ts +2 -0
  74. package/dist/integrations/index.js +21 -0
  75. package/dist/integrations/types.d.ts +11 -0
  76. package/dist/integrations/types.js +13 -0
  77. package/dist/parser/TemplateParser.d.ts +8 -0
  78. package/dist/parser/TemplateParser.js +75 -0
  79. package/dist/parser/index.d.ts +2 -0
  80. package/dist/parser/index.js +22 -0
  81. package/dist/parser/types.d.ts +30 -0
  82. package/dist/parser/types.js +3 -0
  83. package/dist/pipeline/PipelineOrchestrator.d.ts +23 -0
  84. package/dist/pipeline/PipelineOrchestrator.js +191 -0
  85. package/dist/pipeline/index.d.ts +2 -0
  86. package/dist/pipeline/index.js +19 -0
  87. package/dist/pipeline/types.d.ts +41 -0
  88. package/dist/pipeline/types.js +13 -0
  89. package/dist/pricing/CacheManager.d.ts +75 -0
  90. package/dist/pricing/CacheManager.js +195 -0
  91. package/dist/pricing/PricingClient.d.ts +17 -0
  92. package/dist/pricing/PricingClient.js +122 -0
  93. package/dist/pricing/PricingService.d.ts +16 -0
  94. package/dist/pricing/PricingService.js +149 -0
  95. package/dist/pricing/calculators/ALBCalculator.d.ts +16 -0
  96. package/dist/pricing/calculators/ALBCalculator.js +163 -0
  97. package/dist/pricing/calculators/APIGatewayCalculator.d.ts +10 -0
  98. package/dist/pricing/calculators/APIGatewayCalculator.js +177 -0
  99. package/dist/pricing/calculators/CloudFrontCalculator.d.ts +59 -0
  100. package/dist/pricing/calculators/CloudFrontCalculator.js +151 -0
  101. package/dist/pricing/calculators/DynamoDBCalculator.d.ts +9 -0
  102. package/dist/pricing/calculators/DynamoDBCalculator.js +146 -0
  103. package/dist/pricing/calculators/EC2Calculator.d.ts +7 -0
  104. package/dist/pricing/calculators/EC2Calculator.js +80 -0
  105. package/dist/pricing/calculators/ECSCalculator.d.ts +9 -0
  106. package/dist/pricing/calculators/ECSCalculator.js +116 -0
  107. package/dist/pricing/calculators/ElastiCacheCalculator.d.ts +8 -0
  108. package/dist/pricing/calculators/ElastiCacheCalculator.js +106 -0
  109. package/dist/pricing/calculators/LambdaCalculator.d.ts +13 -0
  110. package/dist/pricing/calculators/LambdaCalculator.js +111 -0
  111. package/dist/pricing/calculators/NLBCalculator.d.ts +16 -0
  112. package/dist/pricing/calculators/NLBCalculator.js +138 -0
  113. package/dist/pricing/calculators/NatGatewayCalculator.d.ts +12 -0
  114. package/dist/pricing/calculators/NatGatewayCalculator.js +116 -0
  115. package/dist/pricing/calculators/RDSCalculator.d.ts +9 -0
  116. package/dist/pricing/calculators/RDSCalculator.js +103 -0
  117. package/dist/pricing/calculators/S3Calculator.d.ts +8 -0
  118. package/dist/pricing/calculators/S3Calculator.js +68 -0
  119. package/dist/pricing/calculators/VPCEndpointCalculator.d.ts +12 -0
  120. package/dist/pricing/calculators/VPCEndpointCalculator.js +129 -0
  121. package/dist/pricing/index.d.ts +10 -0
  122. package/dist/pricing/index.js +37 -0
  123. package/dist/pricing/types.d.ts +53 -0
  124. package/dist/pricing/types.js +22 -0
  125. package/dist/releasetag.txt +1 -0
  126. package/dist/reporter/Reporter.d.ts +18 -0
  127. package/dist/reporter/Reporter.js +412 -0
  128. package/dist/reporter/index.d.ts +2 -0
  129. package/dist/reporter/index.js +21 -0
  130. package/dist/reporter/types.d.ts +72 -0
  131. package/dist/reporter/types.js +3 -0
  132. package/dist/synthesis/SynthesisOrchestrator.d.ts +26 -0
  133. package/dist/synthesis/SynthesisOrchestrator.js +243 -0
  134. package/dist/synthesis/index.d.ts +2 -0
  135. package/dist/synthesis/index.js +19 -0
  136. package/dist/synthesis/types.d.ts +17 -0
  137. package/dist/synthesis/types.js +13 -0
  138. package/dist/threshold/ThresholdEnforcer.d.ts +29 -0
  139. package/dist/threshold/ThresholdEnforcer.js +143 -0
  140. package/dist/threshold/index.d.ts +2 -0
  141. package/dist/threshold/index.js +19 -0
  142. package/dist/threshold/types.d.ts +15 -0
  143. package/dist/threshold/types.js +17 -0
  144. package/docs/CALCULATORS.md +820 -0
  145. package/docs/CI_CD.md +608 -0
  146. package/docs/CONFIGURATION.md +407 -0
  147. package/docs/DEVELOPMENT.md +387 -0
  148. package/docs/RELEASE.md +223 -0
  149. package/docs/TROUBLESHOOTING.md +847 -0
  150. package/examples/.cdk-cost-analyzer.yml +85 -0
  151. package/examples/.gitlab-ci.yml +125 -0
  152. package/examples/api-usage.js +26 -0
  153. package/examples/complex/base.json +16 -0
  154. package/examples/complex/target.json +29 -0
  155. package/examples/monorepo/.gitlab-ci.yml +251 -0
  156. package/examples/monorepo/README.md +341 -0
  157. package/examples/monorepo/package.json +27 -0
  158. package/examples/monorepo/packages/backend-infra/.cdk-cost-analyzer.yml +34 -0
  159. package/examples/monorepo/packages/backend-infra/bin/app.ts +16 -0
  160. package/examples/monorepo/packages/backend-infra/cdk.json +7 -0
  161. package/examples/monorepo/packages/backend-infra/lib/backend-stack.ts +128 -0
  162. package/examples/monorepo/packages/backend-infra/package.json +30 -0
  163. package/examples/monorepo/packages/backend-infra/tsconfig.json +11 -0
  164. package/examples/monorepo/packages/data-infra/.cdk-cost-analyzer.yml +38 -0
  165. package/examples/monorepo/packages/data-infra/bin/app.ts +16 -0
  166. package/examples/monorepo/packages/data-infra/cdk.json +7 -0
  167. package/examples/monorepo/packages/data-infra/lib/data-stack.ts +121 -0
  168. package/examples/monorepo/packages/data-infra/package.json +30 -0
  169. package/examples/monorepo/packages/data-infra/tsconfig.json +11 -0
  170. package/examples/monorepo/packages/frontend-infra/.cdk-cost-analyzer.yml +31 -0
  171. package/examples/monorepo/packages/frontend-infra/bin/app.ts +16 -0
  172. package/examples/monorepo/packages/frontend-infra/cdk.json +7 -0
  173. package/examples/monorepo/packages/frontend-infra/lib/frontend-stack.ts +60 -0
  174. package/examples/monorepo/packages/frontend-infra/package.json +30 -0
  175. package/examples/monorepo/packages/frontend-infra/tsconfig.json +11 -0
  176. package/examples/monorepo/tsconfig.json +35 -0
  177. package/examples/multi-stack/.cdk-cost-analyzer.yml +72 -0
  178. package/examples/multi-stack/.gitlab-ci.yml +184 -0
  179. package/examples/multi-stack/README.md +279 -0
  180. package/examples/multi-stack/bin/app.ts +36 -0
  181. package/examples/multi-stack/cdk.json +72 -0
  182. package/examples/multi-stack/lib/compute-stack.ts +128 -0
  183. package/examples/multi-stack/lib/networking-stack.ts +69 -0
  184. package/examples/multi-stack/lib/storage-stack.ts +141 -0
  185. package/examples/multi-stack/package-lock.json +4437 -0
  186. package/examples/multi-stack/package.json +42 -0
  187. package/examples/multi-stack/tsconfig.json +34 -0
  188. package/examples/simple/base.json +8 -0
  189. package/examples/simple/target.json +14 -0
  190. package/examples/single-stack/.NVP +0 -0
  191. package/examples/single-stack/.cdk-cost-analyzer.yml +52 -0
  192. package/examples/single-stack/.gitlab-ci.yml +126 -0
  193. package/examples/single-stack/README.md +184 -0
  194. package/examples/single-stack/UeK +0 -0
  195. package/examples/single-stack/bin/app.ts +16 -0
  196. package/examples/single-stack/cdk.json +72 -0
  197. package/examples/single-stack/lib/infrastructure-stack.ts +119 -0
  198. package/examples/single-stack/package-lock.json +4443 -0
  199. package/examples/single-stack/package.json +38 -0
  200. package/examples/single-stack/tsconfig.json +34 -0
  201. package/package.json +139 -0
  202. package/test-cdk-project/README-COMPUTE.md +141 -0
  203. package/test-cdk-project/README.md +95 -0
  204. package/test-cdk-project/app-with-compute.js +102 -0
  205. package/test-cdk-project/app.js +81 -0
  206. package/test-cdk-project/cdk-compute.json +3 -0
  207. package/test-cdk-project/cdk.context.json +7 -0
  208. package/test-cdk-project/cdk.json +3 -0
  209. package/test-cdk-project/cdk.out/TestStack.assets.json +21 -0
  210. package/test-cdk-project/cdk.out/TestStack.template.json +115 -0
  211. package/test-cdk-project/cdk.out/cdk.out +1 -0
  212. package/test-cdk-project/cdk.out/manifest.json +503 -0
  213. package/test-cdk-project/cdk.out/tree.json +1 -0
  214. package/test-cdk-project/cdk.out.base/TestStack.assets.json +21 -0
  215. package/test-cdk-project/cdk.out.base/TestStack.template.json +115 -0
  216. package/test-cdk-project/cdk.out.base/cdk.out +1 -0
  217. package/test-cdk-project/cdk.out.base/manifest.json +503 -0
  218. package/test-cdk-project/cdk.out.base/tree.json +1 -0
  219. package/test-cdk-project/cdk.out.target/TestStack.assets.json +21 -0
  220. package/test-cdk-project/cdk.out.target/TestStack.template.json +183 -0
  221. package/test-cdk-project/cdk.out.target/cdk.out +1 -0
  222. package/test-cdk-project/cdk.out.target/manifest.json +521 -0
  223. package/test-cdk-project/cdk.out.target/tree.json +1 -0
  224. package/test-cdk-project/package-lock.json +422 -0
  225. package/test-cdk-project/package.json +17 -0
  226. package/tools/workflows/README.md +102 -0
  227. package/tools/workflows/validate-workflows.js +109 -0
  228. package/tools/workflows/workflow-utils.ts +181 -0
@@ -0,0 +1,281 @@
1
+ # Design Document: GitHub Actions CI/CD Integration
2
+
3
+ ## Overview
4
+
5
+ This design implements a GitHub Actions workflow that automatically runs tests, linting, and type checking whenever code is pushed to the repository or a pull request is created. The workflow ensures code quality by validating all changes before they are merged.
6
+
7
+ The system uses GitHub Actions' native YAML-based workflow configuration to define a CI pipeline that mirrors the local development environment. The workflow leverages caching mechanisms to optimize execution time and runs tests in parallel where possible.
8
+
9
+ ## Architecture
10
+
11
+ ### Workflow Structure
12
+
13
+ ```
14
+ GitHub Event (push/PR)
15
+
16
+ Workflow Trigger
17
+
18
+ Setup Environment
19
+ ├── Checkout Code
20
+ ├── Setup Node.js
21
+ └── Restore Cache
22
+
23
+ Install Dependencies
24
+
25
+ Quality Checks (parallel)
26
+ ├── Linting (ESLint)
27
+ ├── Type Checking (TypeScript)
28
+ └── Build Verification
29
+
30
+ Test Execution
31
+ ├── Unit Tests
32
+ └── Property-Based Tests
33
+
34
+ Report Results
35
+ ```
36
+
37
+ ### Workflow File Location
38
+
39
+ The workflow will be defined in `.github/workflows/ci.yml` following GitHub Actions conventions.
40
+
41
+ ### Runner Environment
42
+
43
+ - **Platform**: Ubuntu latest (ubuntu-latest)
44
+ - **Node.js Version**: 18.x (matching project minimum requirement)
45
+ - **Package Manager**: npm (default for the project)
46
+
47
+ ## Components and Interfaces
48
+
49
+ ### 1. Workflow Configuration
50
+
51
+ **File**: `.github/workflows/ci.yml`
52
+
53
+ **Triggers**:
54
+ - `push`: All branches
55
+ - `pull_request`: All branches targeting any base branch
56
+
57
+ **Jobs**:
58
+ - `test`: Main job that runs all quality checks and tests
59
+
60
+ **Steps**:
61
+ 1. Checkout repository code
62
+ 2. Setup Node.js environment
63
+ 3. Cache node_modules
64
+ 4. Install dependencies
65
+ 5. Run linting
66
+ 6. Run type checking
67
+ 7. Build project
68
+ 8. Run test suite
69
+
70
+ ### 2. Caching Strategy
71
+
72
+ **Cache Key**: Based on `package-lock.json` hash
73
+ **Cache Path**: `node_modules`
74
+ **Restore Keys**: Fallback to most recent cache if exact match not found
75
+
76
+ ### 3. Test Execution
77
+
78
+ **Command**: `npm run test:silent`
79
+ **Framework**: Vitest
80
+ **Test Types**:
81
+ - Unit tests (`.test.ts` files)
82
+ - Property-based tests (`.property.test.ts` files)
83
+
84
+ ### 4. Quality Checks
85
+
86
+ **Linting**: `npm run eslint`
87
+ **Type Checking**: `npm run lint` (runs `tsc --noEmit`)
88
+ **Build**: `npm run build`
89
+
90
+ ## Data Models
91
+
92
+ ### Workflow Configuration Schema
93
+
94
+ ```yaml
95
+ name: string # Workflow name
96
+ on: object # Trigger events
97
+ push: object
98
+ branches: string[]
99
+ pull_request: object
100
+ branches: string[]
101
+ jobs: object
102
+ [jobName]: object
103
+ runs-on: string # Runner platform
104
+ strategy: object # Matrix strategy (optional)
105
+ matrix: object
106
+ node-version: number[]
107
+ steps: array
108
+ - name: string
109
+ uses: string # Action to use
110
+ with: object # Action inputs
111
+ ```
112
+
113
+ ### Cache Configuration
114
+
115
+ ```typescript
116
+ interface CacheConfig {
117
+ path: string; // Path to cache
118
+ key: string; # Cache key with hash
119
+ restore-keys: string; # Fallback keys
120
+ }
121
+ ```
122
+
123
+ ## Correctness Properties
124
+
125
+ *A property is a characteristic or behavior that should hold true across all valid executions of a system-essentially, a formal statement about what the system should do. Properties serve as the bridge between human-readable specifications and machine-verifiable correctness guarantees.*
126
+
127
+ ### Property Reflection
128
+
129
+ Analyzing the acceptance criteria for redundancy:
130
+
131
+ **1.1-1.5**: Workflow execution basics - 1.1 and 1.5 are testable, 1.2 overlaps with step ordering, 1.3 is command verification, 1.4 is GitHub's built-in behavior
132
+ **2.1-2.4**: PR behavior - only 2.1 is testable (trigger config), rest is GitHub's built-in behavior
133
+ **3.1-3.4**: Environment consistency - 3.1 and 3.3 are properties about matching configurations, 3.2 and 3.4 are examples
134
+ **4.1-4.4**: Performance - 4.1 is example (cache exists), 4.2 is property (step ordering), 4.3-4.4 are runtime behavior
135
+ **5.1-5.4**: Quality checks - 5.1 is property (step ordering), 5.2 is example (step exists), 5.3-5.4 are tool/GitHub behavior
136
+ **6.1-6.4**: Multi-version - 6.1 is property (matrix config), rest is GitHub's built-in matrix behavior
137
+
138
+ After reflection, we consolidate into focused properties that avoid redundancy and focus on what we can actually test in the workflow configuration.
139
+
140
+ ### Property 1: Dependencies install before tests
141
+ *For any* workflow configuration, dependency installation steps should appear before test execution steps in the step sequence
142
+ **Validates: Requirements 1.2**
143
+
144
+ ### Property 2: Test failures are not suppressed
145
+ *For any* test step in the workflow, it should not have continue-on-error enabled, ensuring failures propagate correctly
146
+ **Validates: Requirements 1.5**
147
+
148
+ ### Property 3: Node.js version matches project requirements
149
+ *For any* workflow configuration, the Node.js version specified should be compatible with the minimum version in package.json
150
+ **Validates: Requirements 3.1**
151
+
152
+ ### Property 4: Test command matches package.json
153
+ *For any* workflow configuration, the test command used should match the test script defined in package.json
154
+ **Validates: Requirements 3.3**
155
+
156
+ ### Property 5: Cache restores before dependency installation
157
+ *For any* workflow configuration with caching enabled, the cache restore step should appear before the dependency installation step
158
+ **Validates: Requirements 4.2**
159
+
160
+ ### Property 6: Quality checks precede tests
161
+ *For any* workflow configuration, linting and type checking steps should appear before test execution steps in the step sequence
162
+ **Validates: Requirements 5.1**
163
+
164
+ ### Property 7: Matrix versions are valid
165
+ *For any* workflow configuration with matrix strategy, all specified Node.js versions should be valid and supported versions
166
+ **Validates: Requirements 6.1**
167
+
168
+ ## Error Handling
169
+
170
+ ### Workflow Failures
171
+
172
+ **Dependency Installation Failure**:
173
+ - Cause: Network issues, invalid package-lock.json
174
+ - Handling: Workflow fails immediately, no subsequent steps run
175
+ - User Action: Check package-lock.json integrity, retry workflow
176
+
177
+ **Linting Failures**:
178
+ - Cause: Code style violations
179
+ - Handling: Workflow fails, reports specific violations
180
+ - User Action: Fix linting errors locally, push fixes
181
+
182
+ **Type Checking Failures**:
183
+ - Cause: TypeScript compilation errors
184
+ - Handling: Workflow fails, reports type errors
185
+ - User Action: Fix type errors locally, push fixes
186
+
187
+ **Build Failures**:
188
+ - Cause: Compilation errors, missing dependencies
189
+ - Handling: Workflow fails, reports build errors
190
+ - User Action: Fix build errors locally, verify with `npm run build`
191
+
192
+ **Test Failures**:
193
+ - Cause: Failing unit or property-based tests
194
+ - Handling: Workflow fails, reports test failures with details
195
+ - User Action: Fix failing tests locally, verify with `npm test`
196
+
197
+ ### Cache Failures
198
+
199
+ **Cache Miss**:
200
+ - Cause: First run or cache expired
201
+ - Handling: Install dependencies from scratch
202
+ - Impact: Slower workflow execution
203
+
204
+ **Cache Corruption**:
205
+ - Cause: Interrupted previous workflow
206
+ - Handling: Fallback to fresh installation
207
+ - Impact: Slower workflow execution
208
+
209
+ ## Testing Strategy
210
+
211
+ ### Unit Tests
212
+
213
+ Unit tests will verify the workflow configuration structure:
214
+
215
+ 1. **Workflow file exists**: Verify `.github/workflows/ci.yml` exists
216
+ 2. **Trigger configuration**: Verify push and pull_request triggers are configured
217
+ 3. **Node.js version**: Verify correct Node.js version is specified
218
+ 4. **Required steps**: Verify all required steps are present in correct order
219
+ 5. **Cache configuration**: Verify cache paths and keys are correctly configured
220
+
221
+ ### Property-Based Tests
222
+
223
+ Property-based tests will verify universal properties of the workflow configuration:
224
+
225
+ 1. **Property 1 Test**: Generate various GitHub event payloads, verify workflow triggers
226
+ 2. **Property 2 Test**: Parse workflow file, verify environment matches package.json requirements
227
+ 3. **Property 3 Test**: Verify cache configuration includes restore-keys for fallback
228
+ 4. **Property 4 Test**: Verify quality check steps appear before test steps in workflow
229
+ 5. **Property 5 Test**: Verify test step includes failure detection
230
+ 6. **Property 6 Test**: Verify all required quality check steps are present
231
+
232
+ ### Integration Testing
233
+
234
+ The workflow itself serves as an integration test:
235
+ - Each push/PR will validate the workflow works end-to-end
236
+ - GitHub Actions UI provides detailed logs for debugging
237
+ - Failed workflows prevent merging (when branch protection is enabled)
238
+
239
+ ### Testing Framework
240
+
241
+ - **Framework**: Vitest (already configured in project)
242
+ - **Property Testing Library**: fast-check (already in devDependencies)
243
+ - **Test Location**: `test/github-actions/` directory
244
+ - **Minimum Iterations**: 100 per property test
245
+
246
+ ## Implementation Notes
247
+
248
+ ### Projen Integration
249
+
250
+ The project uses Projen for configuration management. However, since Projen has `github: false` configured, we will manually create the GitHub Actions workflow file. This is intentional as the project primarily uses GitLab CI but wants to add GitHub Actions support.
251
+
252
+ ### Multi-Version Testing (Optional)
253
+
254
+ The design supports testing on multiple Node.js versions using GitHub Actions matrix strategy:
255
+
256
+ ```yaml
257
+ strategy:
258
+ matrix:
259
+ node-version: [18.x, 20.x, 22.x]
260
+ ```
261
+
262
+ This is optional and can be enabled based on project requirements.
263
+
264
+ ### Branch Protection
265
+
266
+ While not part of this implementation, teams should consider enabling GitHub branch protection rules to:
267
+ - Require status checks to pass before merging
268
+ - Require pull request reviews
269
+ - Prevent force pushes to protected branches
270
+
271
+ ### Performance Considerations
272
+
273
+ - **Caching**: Reduces dependency installation time from ~2-3 minutes to ~30 seconds
274
+ - **Parallel Execution**: Quality checks can run in parallel with proper job configuration
275
+ - **Silent Test Mode**: Using `test:silent` reduces log output and speeds up execution
276
+
277
+ ### Security Considerations
278
+
279
+ - **Dependency Scanning**: Consider adding `npm audit` step
280
+ - **Secret Management**: Use GitHub Secrets for any required credentials
281
+ - **Permissions**: Workflow runs with default GITHUB_TOKEN permissions
@@ -0,0 +1,86 @@
1
+ # Requirements Document
2
+
3
+ ## Introduction
4
+
5
+ This feature implements automated testing through GitHub Actions CI/CD pipeline. When code is pushed to the GitHub repository, the system will automatically run all tests to ensure code quality and catch issues early in the development cycle.
6
+
7
+ ## Glossary
8
+
9
+ - **GitHub Actions**: GitHub's built-in CI/CD platform that automates workflows
10
+ - **Workflow**: An automated process defined in YAML that runs on specific GitHub events
11
+ - **CI/CD**: Continuous Integration/Continuous Deployment - automated testing and deployment practices
12
+ - **Test Suite**: The collection of all unit tests, property-based tests, and integration tests
13
+ - **Push Event**: A Git push operation that triggers the workflow
14
+ - **Pull Request**: A proposed code change that can trigger validation workflows
15
+ - **Runner**: The virtual machine environment where GitHub Actions workflows execute
16
+ - **Job**: A set of steps that execute on the same runner
17
+ - **Node.js Environment**: The runtime environment required to execute TypeScript tests
18
+
19
+ ## Requirements
20
+
21
+ ### Requirement 1
22
+
23
+ **User Story:** As a developer, I want tests to run automatically on every push to GitHub, so that I can catch bugs early and maintain code quality.
24
+
25
+ #### Acceptance Criteria
26
+
27
+ 1. WHEN a developer pushes code to any branch THEN the system SHALL trigger the test workflow automatically
28
+ 2. WHEN the workflow executes THEN the system SHALL install all project dependencies before running tests
29
+ 3. WHEN the workflow runs tests THEN the system SHALL execute the complete test suite including unit tests and property-based tests
30
+ 4. WHEN tests complete THEN the system SHALL report the test results in the GitHub Actions interface
31
+ 5. WHEN tests fail THEN the system SHALL mark the workflow run as failed with exit code non-zero
32
+
33
+ ### Requirement 2
34
+
35
+ **User Story:** As a developer, I want to see test results for pull requests, so that I can verify changes before merging.
36
+
37
+ #### Acceptance Criteria
38
+
39
+ 1. WHEN a pull request is created THEN the system SHALL trigger the test workflow automatically
40
+ 2. WHEN a pull request is updated with new commits THEN the system SHALL re-run the test workflow
41
+ 3. WHEN tests complete on a pull request THEN the system SHALL display the test status on the pull request page
42
+ 4. WHEN tests fail on a pull request THEN the system SHALL prevent merging until tests pass or checks are overridden
43
+
44
+ ### Requirement 3
45
+
46
+ **User Story:** As a developer, I want the CI environment to match my local development environment, so that tests behave consistently.
47
+
48
+ #### Acceptance Criteria
49
+
50
+ 1. WHEN the workflow initializes THEN the system SHALL use the Node.js version specified in the project configuration
51
+ 2. WHEN the workflow installs dependencies THEN the system SHALL use the same package manager as local development
52
+ 3. WHEN the workflow runs tests THEN the system SHALL use the same test commands as documented in package.json
53
+ 4. WHEN the workflow executes THEN the system SHALL set environment variables consistent with test requirements
54
+
55
+ ### Requirement 4
56
+
57
+ **User Story:** As a developer, I want fast feedback from CI tests, so that I can iterate quickly on my code.
58
+
59
+ #### Acceptance Criteria
60
+
61
+ 1. WHEN the workflow runs THEN the system SHALL cache Node.js dependencies between runs
62
+ 2. WHEN dependencies are cached THEN the system SHALL restore the cache before installing new dependencies
63
+ 3. WHEN the workflow completes THEN the system SHALL finish within a reasonable time limit for the test suite size
64
+ 4. WHEN tests run THEN the system SHALL execute tests in parallel where possible
65
+
66
+ ### Requirement 5
67
+
68
+ **User Story:** As a team lead, I want to enforce code quality standards, so that all merged code meets our quality bar.
69
+
70
+ #### Acceptance Criteria
71
+
72
+ 1. WHEN a workflow is defined THEN the system SHALL include linting checks before running tests
73
+ 2. WHEN a workflow is defined THEN the system SHALL include type checking for TypeScript code
74
+ 3. WHEN quality checks fail THEN the system SHALL report specific failures with actionable error messages
75
+ 4. WHEN all checks pass THEN the system SHALL mark the workflow as successful
76
+
77
+ ### Requirement 6
78
+
79
+ **User Story:** As a developer, I want to test on multiple Node.js versions, so that I can ensure compatibility across environments.
80
+
81
+ #### Acceptance Criteria
82
+
83
+ 1. WHERE multiple Node.js versions are specified THEN the system SHALL run tests on each version in parallel
84
+ 2. WHEN testing on multiple versions THEN the system SHALL report results separately for each version
85
+ 3. WHEN any version fails THEN the system SHALL mark the overall workflow as failed
86
+ 4. WHEN all versions pass THEN the system SHALL mark the overall workflow as successful
@@ -0,0 +1,115 @@
1
+ # Implementation Plan
2
+
3
+ - [x] 1. Create GitHub Actions workflow directory structure
4
+ - Create `.github/workflows/` directory
5
+ - _Requirements: 1.1, 2.1_
6
+
7
+ - [x] 2. Implement basic CI workflow configuration
8
+ - [x] 2.1 Create workflow file with triggers for push and pull_request events
9
+ - Define workflow name and trigger events
10
+ - Configure to run on all branches
11
+ - _Requirements: 1.1, 2.1_
12
+
13
+ - [x] 2.2 Configure job with Ubuntu runner
14
+ - Set up job to run on ubuntu-latest
15
+ - _Requirements: 3.1_
16
+
17
+ - [x] 2.3 Add checkout step
18
+ - Use actions/checkout@v4 to clone repository
19
+ - _Requirements: 1.2_
20
+
21
+ - [x] 2.4 Add Node.js setup step
22
+ - Use actions/setup-node@v4
23
+ - Configure Node.js version 18.x
24
+ - _Requirements: 3.1_
25
+
26
+ - [x] 2.5 Write property test for Node.js version matching
27
+ - **Property 3: Node.js version matches project requirements**
28
+ - **Validates: Requirements 3.1**
29
+
30
+ - [x] 3. Implement dependency caching
31
+ - [x] 3.1 Add cache configuration step
32
+ - Use actions/cache@v4 or setup-node caching
33
+ - Configure cache key based on package-lock.json
34
+ - Set cache path to node_modules
35
+ - _Requirements: 4.1, 4.2_
36
+
37
+ - [x] 3.2 Write property test for cache step ordering
38
+ - **Property 5: Cache restores before dependency installation**
39
+ - **Validates: Requirements 4.2**
40
+
41
+ - [x] 4. Add dependency installation step
42
+ - [x] 4.1 Add npm ci command
43
+ - Use npm ci for clean installation
44
+ - _Requirements: 1.2, 3.2_
45
+
46
+ - [x] 4.2 Write property test for dependency installation ordering
47
+ - **Property 1: Dependencies install before tests**
48
+ - **Validates: Requirements 1.2**
49
+
50
+ - [x] 5. Implement quality check steps
51
+ - [x] 5.1 Add linting step
52
+ - Run npm run eslint
53
+ - _Requirements: 5.1_
54
+
55
+ - [x] 5.2 Add type checking step
56
+ - Run npm run lint (tsc --noEmit)
57
+ - _Requirements: 5.2_
58
+
59
+ - [x] 5.3 Add build verification step
60
+ - Run npm run build
61
+ - _Requirements: 5.1_
62
+
63
+ - [x] 5.4 Write property test for quality checks ordering
64
+ - **Property 6: Quality checks precede tests**
65
+ - **Validates: Requirements 5.1**
66
+
67
+ - [x] 6. Implement test execution step
68
+ - [x] 6.1 Add test step with silent mode
69
+ - Run npm run test:silent
70
+ - _Requirements: 1.3, 3.3_
71
+
72
+ - [x] 6.2 Write property test for test command matching
73
+ - **Property 4: Test command matches package.json**
74
+ - **Validates: Requirements 3.3**
75
+
76
+ - [x] 6.3 Write property test for test failure propagation
77
+ - **Property 2: Test failures are not suppressed**
78
+ - **Validates: Requirements 1.5**
79
+
80
+ - [x] 7. Add optional matrix strategy for multi-version testing
81
+ - [x] 7.1 Add matrix configuration (optional)
82
+ - Configure matrix with Node.js versions [18.x, 20.x, 22.x]
83
+ - Update setup-node step to use matrix.node-version
84
+ - _Requirements: 6.1_
85
+
86
+ - [x] 7.2 Write property test for matrix version validity
87
+ - **Property 7: Matrix versions are valid**
88
+ - **Validates: Requirements 6.1**
89
+
90
+ - [x] 8. Create workflow validation tests
91
+ - [x] 8.1 Write unit test for workflow file existence
92
+ - Verify .github/workflows/ci.yml exists
93
+ - _Requirements: 1.1_
94
+
95
+ - [x] 8.2 Write unit test for trigger configuration
96
+ - Verify push and pull_request triggers are configured
97
+ - _Requirements: 1.1, 2.1_
98
+
99
+ - [x] 8.3 Write unit test for required steps presence
100
+ - Verify all required steps are present
101
+ - _Requirements: 5.2_
102
+
103
+ - [x] 9. Documentation and finalization
104
+ - [x] 9.1 Update README with CI badge and information
105
+ - Add GitHub Actions status badge
106
+ - Document CI workflow behavior
107
+ - _Requirements: 1.4_
108
+
109
+ - [x] 9.2 Add workflow documentation
110
+ - Create docs/GITHUB_ACTIONS.md explaining the CI setup
111
+ - Document how to run checks locally
112
+ - _Requirements: 3.3_
113
+
114
+ - [x] 10. Checkpoint - Ensure all tests pass
115
+ - Ensure all tests pass, ask the user if questions arise.
@@ -0,0 +1,190 @@
1
+ # Design Document: NLBCalculator Test Coverage Enhancement
2
+
3
+ ## Overview
4
+
5
+ This design outlines a comprehensive testing strategy for the NLBCalculator class to improve test coverage from 15.82% to over 90%. The approach focuses on unit testing all public methods, private method behavior through public interfaces, and property-based testing for mathematical calculations.
6
+
7
+ ## Architecture
8
+
9
+ ### Testing Framework Stack
10
+ - **Jest**: Primary testing framework (already configured in project)
11
+ - **fast-check**: Property-based testing library for mathematical property validation
12
+ - **TypeScript**: Maintain type safety in test code
13
+
14
+ ### Test Organization
15
+ ```
16
+ test/pricing/calculators/
17
+ ├── NLBCalculator.test.ts # Main unit tests
18
+ └── NLBCalculator.property.test.ts # Property-based tests
19
+ ```
20
+
21
+ ## Components and Interfaces
22
+
23
+ ### Test Doubles and Mocks
24
+
25
+ #### MockPricingClient
26
+ ```typescript
27
+ interface MockPricingClient extends PricingClient {
28
+ getPrice(params: PriceQuery): Promise<number | null>;
29
+ // Configure responses for different scenarios
30
+ setHourlyRate(rate: number | null): void;
31
+ setNLCURate(rate: number | null): void;
32
+ setError(error: Error): void;
33
+ }
34
+ ```
35
+
36
+ #### Test Resource Factory
37
+ ```typescript
38
+ interface TestResourceFactory {
39
+ createNetworkLoadBalancer(properties?: Partial<any>): ResourceWithId;
40
+ createApplicationLoadBalancer(): ResourceWithId;
41
+ createGenericResource(type: string): ResourceWithId;
42
+ }
43
+ ```
44
+
45
+ ### Test Categories
46
+
47
+ #### 1. Method Coverage Tests
48
+ - `supports()` method with various resource types
49
+ - `calculateCost()` with different load balancer configurations
50
+ - Region normalization and prefix generation methods
51
+
52
+ #### 2. Calculation Logic Tests
53
+ - NLCU calculation from different usage metrics
54
+ - Cost combination logic (hourly + NLCU costs)
55
+ - Default parameter application
56
+
57
+ #### 3. Error Scenario Tests
58
+ - Null pricing responses
59
+ - Network/API errors
60
+ - Invalid resource configurations
61
+
62
+ #### 4. Integration Tests
63
+ - End-to-end cost calculation with realistic scenarios
64
+ - Multiple region testing
65
+ - Custom parameter combinations
66
+
67
+ ## Data Models
68
+
69
+ ### Test Data Structures
70
+
71
+ #### PricingScenario
72
+ ```typescript
73
+ interface PricingScenario {
74
+ name: string;
75
+ region: string;
76
+ hourlyRate: number | null;
77
+ nlcuRate: number | null;
78
+ expectedResult: Partial<MonthlyCost>;
79
+ shouldThrow?: boolean;
80
+ }
81
+ ```
82
+
83
+ #### UsageParameters
84
+ ```typescript
85
+ interface UsageParameters {
86
+ newConnectionsPerSecond?: number;
87
+ activeConnectionsPerMinute?: number;
88
+ processedBytesGB?: number;
89
+ }
90
+ ```
91
+
92
+ #### RegionTestCase
93
+ ```typescript
94
+ interface RegionTestCase {
95
+ regionCode: string;
96
+ expectedNormalizedName: string;
97
+ expectedPrefix: string;
98
+ }
99
+ ```
100
+
101
+ ## Testing Strategy
102
+
103
+ ### Unit Testing Approach
104
+ - **Isolated Testing**: Mock PricingClient to control responses
105
+ - **Boundary Testing**: Test edge cases for NLCU calculations
106
+ - **Error Path Testing**: Verify graceful error handling
107
+ - **State Testing**: Verify constructor parameter handling
108
+
109
+ ### Property-Based Testing Configuration
110
+ - **Library**: fast-check for generating test inputs
111
+ - **Iterations**: Minimum 100 iterations per property test
112
+ - **Generators**: Custom generators for realistic AWS usage patterns
113
+
114
+ ## Error Handling
115
+
116
+ ### Test Error Scenarios
117
+ 1. **Pricing API Failures**: Network timeouts, service errors
118
+ 2. **Invalid Responses**: Null rates, malformed data
119
+ 3. **Resource Validation**: Non-NLB resources, missing properties
120
+ 4. **Region Handling**: Unsupported regions, invalid region codes
121
+
122
+ ### Expected Behaviors
123
+ - Zero cost returned for error scenarios
124
+ - Descriptive error messages in assumptions
125
+ - No exceptions thrown from public methods
126
+ - Graceful degradation with confidence level "unknown"
127
+
128
+ ## Correctness Properties
129
+
130
+ *A property is a characteristic or behavior that should hold true across all valid executions of a system—essentially, a formal statement about what the system should do. Properties serve as the bridge between human-readable specifications and machine-verifiable correctness guarantees.*
131
+
132
+ ### Property 1: Resource Type Rejection
133
+ *For any* resource type string that is not "AWS::ElasticLoadBalancingV2::LoadBalancer", the supports method should return false
134
+ **Validates: Requirements 1.2**
135
+
136
+ ### Property 2: Valid MonthlyCost Structure
137
+ *For any* network load balancer resource with valid pricing data, calculateCost should return a MonthlyCost object with non-negative amount, "USD" currency, and non-empty assumptions array
138
+ **Validates: Requirements 1.3**
139
+
140
+ ### Property 3: Non-NLB Resource Zero Cost
141
+ *For any* resource with Type property that is not "network" or undefined, calculateCost should return zero cost with appropriate assumptions
142
+ **Validates: Requirements 1.4**
143
+
144
+ ### Property 4: New Connections NLCU Calculation
145
+ *For any* positive number of new connections per second, the NLCU calculation should equal the connections divided by 800
146
+ **Validates: Requirements 2.1**
147
+
148
+ ### Property 5: Active Connections NLCU Calculation
149
+ *For any* positive number of active connections per minute, the NLCU calculation should equal the connections divided by 100,000
150
+ **Validates: Requirements 2.2**
151
+
152
+ ### Property 6: Processed Bytes NLCU Calculation
153
+ *For any* positive number of processed GB per month, the NLCU calculation should equal the GB divided by 730 (converting to hourly)
154
+ **Validates: Requirements 2.3**
155
+
156
+ ### Property 7: Maximum NLCU Selection
157
+ *For any* set of NLCU values calculated from different metrics, the billing NLCU should equal the maximum value from the set
158
+ **Validates: Requirements 2.4**
159
+
160
+ ### Property 8: Custom Parameter Override
161
+ *For any* valid custom usage parameters provided to the constructor, those parameters should be used instead of the corresponding default values in calculations
162
+ **Validates: Requirements 2.5, 5.4**
163
+
164
+ ### Property 9: Unsupported Region Passthrough
165
+ *For any* region string not in the supported regions map, normalizeRegion should return the original string unchanged
166
+ **Validates: Requirements 3.2**
167
+
168
+ ### Property 10: Unsupported Region Empty Prefix
169
+ *For any* region string not in the supported regions map, getRegionPrefix should return an empty string
170
+ **Validates: Requirements 3.4**
171
+
172
+ ### Property 11: Exception Handling
173
+ *For any* exception thrown by the pricing client, calculateCost should return zero cost with the error message included in assumptions
174
+ **Validates: Requirements 4.3**
175
+
176
+ ### Property 12: Successful Calculation Structure
177
+ *For any* valid pricing data (non-null hourly and NLCU rates), calculateCost should return a cost with detailed breakdown in assumptions and "medium" confidence
178
+ **Validates: Requirements 4.4, 6.4**
179
+
180
+ ### Property 13: Cost Addition
181
+ *For any* valid hourly cost and NLCU cost, the total cost should equal their sum
182
+ **Validates: Requirements 6.1**
183
+
184
+ ### Property 14: Hourly Cost Calculation
185
+ *For any* positive hourly rate, the monthly hourly cost should equal the rate multiplied by 730
186
+ **Validates: Requirements 6.2**
187
+
188
+ ### Property 15: NLCU Cost Calculation
189
+ *For any* positive NLCU rate and NLCU per hour, the monthly NLCU cost should equal rate × NLCU per hour × 730
190
+ **Validates: Requirements 6.3**