@mrciphersmith/keryx 0.4.28 → 0.4.30

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 (132) hide show
  1. package/dist/cli.js +4916 -3655
  2. package/dist/core.js +91 -28
  3. package/dist/keryx-general-worker-entry.js +413 -240
  4. package/package.json +1 -1
  5. package/src/gdskills/bundled/install-manifest.json +3 -0
  6. package/src/gdskills/bundled/rules/core/api-contracts.mdc +21 -136
  7. package/src/gdskills/bundled/rules/core/async-patterns.mdc +18 -171
  8. package/src/gdskills/bundled/rules/core/clean-architecture.mdc +40 -150
  9. package/src/gdskills/bundled/rules/core/cli-interface-design.mdc +63 -194
  10. package/src/gdskills/bundled/rules/core/code-style-patterns.mdc +36 -48
  11. package/src/gdskills/bundled/rules/core/concurrency-patterns.mdc +32 -0
  12. package/src/gdskills/bundled/rules/core/database-patterns.mdc +26 -148
  13. package/src/gdskills/bundled/rules/core/error-handling.mdc +57 -109
  14. package/src/gdskills/bundled/rules/core/frontend-assistant.mdc +14 -29
  15. package/src/gdskills/bundled/rules/core/layout-rendering.mdc +51 -0
  16. package/src/gdskills/bundled/rules/core/mobx-store-template.mdc +69 -511
  17. package/src/gdskills/bundled/rules/core/nestjs-dto.mdc +18 -36
  18. package/src/gdskills/bundled/rules/core/playwright-testing.mdc +35 -308
  19. package/src/gdskills/bundled/rules/core/security-baseline.mdc +18 -140
  20. package/src/gdskills/bundled/rules/core/skill-authoring.mdc +190 -0
  21. package/src/gdskills/bundled/rules/core/skills-storage-workflow.mdc +5 -0
  22. package/src/gdskills/bundled/rules/core/solid-principles.mdc +70 -121
  23. package/src/gdskills/bundled/rules/core/storybook-guidelines.mdc +20 -22
  24. package/src/gdskills/bundled/rules/core/tdd-workflow.mdc +37 -74
  25. package/src/gdskills/bundled/rules/core/ui-anti-slop.mdc +48 -37
  26. package/src/gdskills/bundled/skills/orchestration/task-implementer/SKILL.md +2 -2
  27. package/src/gdskills/bundled/skills/quality/deprecation-path/SKILL.md +1 -1
  28. package/src/gdskills/bundled/skills/quality/tests-creator/SKILL.md +1 -1
  29. package/src/gdskills/bundled/skills/review/review-architecture/SKILL.md +25 -61
  30. package/src/gdskills/bundled/skills/review/review-backend/SKILL.md +15 -69
  31. package/src/gdskills/bundled/skills/review/review-clean-code/SKILL.md +84 -418
  32. package/src/gdskills/bundled/skills/review/review-core-boundaries/SKILL.md +2 -2
  33. package/src/gdskills/bundled/skills/review/review-degradation/SKILL.md +1 -1
  34. package/src/gdskills/bundled/skills/review/review-flow-graph/SKILL.md +1 -1
  35. package/src/gdskills/bundled/skills/review/review-frontend/SKILL.md +17 -311
  36. package/src/gdskills/bundled/skills/review/review-frontend-conventions/SKILL.md +8 -22
  37. package/src/gdskills/bundled/skills/review/review-highload/SKILL.md +84 -228
  38. package/src/gdskills/bundled/skills/review/review-layout/SKILL.md +22 -28
  39. package/src/gdskills/bundled/skills/review/review-logic/SKILL.md +9 -10
  40. package/src/gdskills/bundled/skills/review/review-performance/SKILL.md +16 -38
  41. package/src/gdskills/bundled/skills/review/review-premise/SKILL.md +1 -1
  42. package/src/gdskills/bundled/skills/review/review-regression/SKILL.md +1 -1
  43. package/src/gdskills/bundled/skills/review/review-security-code/SKILL.md +8 -8
  44. package/src/gdskills/bundled/skills/review/review-style/SKILL.md +49 -88
  45. package/src/gdskills/bundled/skills/review/review-testing-practices/SKILL.md +22 -40
  46. package/src/gdskills/bundled/skills/review/review-ui-ux/SKILL.md +42 -82
  47. package/src/gdskills/bundled/stacks/angular/rules/coding-style.mdc +15 -57
  48. package/src/gdskills/bundled/stacks/angular/rules/patterns.mdc +16 -60
  49. package/src/gdskills/bundled/stacks/angular/rules/security.mdc +11 -49
  50. package/src/gdskills/bundled/stacks/angular/rules/testing.mdc +13 -52
  51. package/src/gdskills/bundled/stacks/c-cpp/rules/coding-style.mdc +33 -57
  52. package/src/gdskills/bundled/stacks/c-cpp/rules/patterns.mdc +35 -62
  53. package/src/gdskills/bundled/stacks/c-cpp/rules/security.mdc +35 -62
  54. package/src/gdskills/bundled/stacks/c-cpp/rules/testing.mdc +34 -54
  55. package/src/gdskills/bundled/stacks/ci-github-gitlab/rules/patterns.mdc +27 -56
  56. package/src/gdskills/bundled/stacks/ci-github-gitlab/rules/security.mdc +51 -119
  57. package/src/gdskills/bundled/stacks/csharp-dotnet/rules/coding-style.mdc +42 -74
  58. package/src/gdskills/bundled/stacks/csharp-dotnet/rules/patterns.mdc +45 -83
  59. package/src/gdskills/bundled/stacks/csharp-dotnet/rules/security.mdc +34 -59
  60. package/src/gdskills/bundled/stacks/csharp-dotnet/rules/testing.mdc +33 -62
  61. package/src/gdskills/bundled/stacks/django/rules/coding-style.mdc +15 -56
  62. package/src/gdskills/bundled/stacks/django/rules/patterns.mdc +16 -68
  63. package/src/gdskills/bundled/stacks/django/rules/security.mdc +13 -71
  64. package/src/gdskills/bundled/stacks/django/rules/testing.mdc +16 -62
  65. package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/coding-style.mdc +30 -53
  66. package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/patterns.mdc +20 -56
  67. package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/security.mdc +52 -122
  68. package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/testing.mdc +23 -42
  69. package/src/gdskills/bundled/stacks/fastapi/rules/coding-style.mdc +13 -47
  70. package/src/gdskills/bundled/stacks/fastapi/rules/patterns.mdc +18 -81
  71. package/src/gdskills/bundled/stacks/fastapi/rules/security.mdc +13 -75
  72. package/src/gdskills/bundled/stacks/fastapi/rules/testing.mdc +14 -58
  73. package/src/gdskills/bundled/stacks/flutter-dart/rules/coding-style.mdc +36 -74
  74. package/src/gdskills/bundled/stacks/flutter-dart/rules/patterns.mdc +30 -66
  75. package/src/gdskills/bundled/stacks/flutter-dart/rules/security.mdc +33 -67
  76. package/src/gdskills/bundled/stacks/flutter-dart/rules/testing.mdc +41 -73
  77. package/src/gdskills/bundled/stacks/go/rules/coding-style.mdc +36 -57
  78. package/src/gdskills/bundled/stacks/go/rules/patterns.mdc +27 -42
  79. package/src/gdskills/bundled/stacks/go/rules/security.mdc +26 -43
  80. package/src/gdskills/bundled/stacks/go/rules/testing.mdc +23 -41
  81. package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/coding-style.mdc +21 -40
  82. package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/patterns.mdc +26 -43
  83. package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/security.mdc +25 -37
  84. package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/testing.mdc +34 -50
  85. package/src/gdskills/bundled/stacks/kotlin-android/rules/coding-style.mdc +28 -65
  86. package/src/gdskills/bundled/stacks/kotlin-android/rules/patterns.mdc +34 -78
  87. package/src/gdskills/bundled/stacks/kotlin-android/rules/security.mdc +35 -68
  88. package/src/gdskills/bundled/stacks/kotlin-android/rules/testing.mdc +34 -68
  89. package/src/gdskills/bundled/stacks/mobx/rules/coding-style.mdc +18 -64
  90. package/src/gdskills/bundled/stacks/mobx/rules/patterns.mdc +13 -66
  91. package/src/gdskills/bundled/stacks/mobx/rules/security.mdc +8 -35
  92. package/src/gdskills/bundled/stacks/mobx/rules/testing.mdc +10 -39
  93. package/src/gdskills/bundled/stacks/nestjs/rules/coding-style.mdc +32 -45
  94. package/src/gdskills/bundled/stacks/nestjs/rules/patterns.mdc +40 -60
  95. package/src/gdskills/bundled/stacks/nestjs/rules/security.mdc +30 -50
  96. package/src/gdskills/bundled/stacks/nestjs/rules/testing.mdc +27 -47
  97. package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/coding-style.mdc +14 -48
  98. package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/patterns.mdc +15 -67
  99. package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/security.mdc +12 -50
  100. package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/testing.mdc +11 -43
  101. package/src/gdskills/bundled/stacks/php-laravel/rules/coding-style.mdc +17 -58
  102. package/src/gdskills/bundled/stacks/php-laravel/rules/patterns.mdc +15 -56
  103. package/src/gdskills/bundled/stacks/php-laravel/rules/security.mdc +13 -50
  104. package/src/gdskills/bundled/stacks/php-laravel/rules/testing.mdc +14 -55
  105. package/src/gdskills/bundled/stacks/python/rules/coding-style.mdc +13 -41
  106. package/src/gdskills/bundled/stacks/python/rules/patterns.mdc +20 -61
  107. package/src/gdskills/bundled/stacks/python/rules/security.mdc +15 -57
  108. package/src/gdskills/bundled/stacks/python/rules/testing.mdc +16 -50
  109. package/src/gdskills/bundled/stacks/react/rules/coding-style.mdc +14 -40
  110. package/src/gdskills/bundled/stacks/react/rules/patterns.mdc +15 -55
  111. package/src/gdskills/bundled/stacks/react/rules/security.mdc +13 -49
  112. package/src/gdskills/bundled/stacks/react/rules/testing.mdc +10 -37
  113. package/src/gdskills/bundled/stacks/ruby-rails/rules/coding-style.mdc +15 -48
  114. package/src/gdskills/bundled/stacks/ruby-rails/rules/patterns.mdc +18 -67
  115. package/src/gdskills/bundled/stacks/ruby-rails/rules/security.mdc +11 -60
  116. package/src/gdskills/bundled/stacks/ruby-rails/rules/testing.mdc +14 -65
  117. package/src/gdskills/bundled/stacks/rust/rules/coding-style.mdc +39 -65
  118. package/src/gdskills/bundled/stacks/rust/rules/patterns.mdc +33 -60
  119. package/src/gdskills/bundled/stacks/rust/rules/security.mdc +35 -57
  120. package/src/gdskills/bundled/stacks/rust/rules/testing.mdc +29 -52
  121. package/src/gdskills/bundled/stacks/sql-db/rules/coding-style.mdc +12 -48
  122. package/src/gdskills/bundled/stacks/sql-db/rules/patterns.mdc +22 -113
  123. package/src/gdskills/bundled/stacks/sql-db/rules/security.mdc +11 -56
  124. package/src/gdskills/bundled/stacks/sql-db/rules/testing.mdc +14 -59
  125. package/src/gdskills/bundled/stacks/swift-ios/rules/coding-style.mdc +29 -65
  126. package/src/gdskills/bundled/stacks/swift-ios/rules/patterns.mdc +41 -88
  127. package/src/gdskills/bundled/stacks/swift-ios/rules/security.mdc +28 -53
  128. package/src/gdskills/bundled/stacks/swift-ios/rules/testing.mdc +32 -65
  129. package/src/gdskills/bundled/stacks/vue/rules/coding-style.mdc +17 -52
  130. package/src/gdskills/bundled/stacks/vue/rules/patterns.mdc +17 -63
  131. package/src/gdskills/bundled/stacks/vue/rules/security.mdc +11 -41
  132. package/src/gdskills/bundled/stacks/vue/rules/testing.mdc +16 -48
@@ -1,5 +1,5 @@
1
1
  ---
2
- description: "NestJS DTO standards for Swagger decorators, validation, and typing."
2
+ description: "NestJS DTO standard shared by code writers and reviewers, with the severities reviewers use: every input is a validated DTO class, validators match the type, nested and query values are transformed, Swagger decorators match optionality. Use when writing or reviewing NestJS controllers and DTOs."
3
3
  alwaysApply: false
4
4
  globs:
5
5
  - "**/*dto*.ts"
@@ -7,45 +7,27 @@ globs:
7
7
  stack_requires: "nestjs"
8
8
  ---
9
9
 
10
- # NestJS DTO Rules
10
+ # NestJS DTOs
11
11
 
12
- ## Purpose
13
- Ensure DTOs are explicit, validated, and API-documented.
12
+ Canon applies: the NestJS validation and OpenAPI guides, class-validator and class-transformer documentation. This rule holds only this project's decisions.
14
13
 
15
- ## When To Apply
16
- Apply when creating or reviewing NestJS DTO files (`*dto*.ts`, `dto/**/*.ts`) in the backend project.
14
+ ## Rules
17
15
 
18
- ## Mandatory Standards
19
- - Use `@ApiProperty()` for required fields.
20
- - Use `@ApiPropertyOptional()` for optional fields.
21
- - Use class-validator decorators (`@IsString`, `@IsNumber`, `@IsEnum`, etc.).
22
- - Use `@IsOptional()` only for truly optional fields.
23
- - Keep decorator descriptions in English.
16
+ 1. **Every controller input is a DTO class** (body, query, and params beyond a single `Parse*Pipe`); an inline type or interface is not validated. `ValidationPipe` runs globally with `whitelist`, `forbidNonWhitelisted` and `transform`.
17
+ 2. **Validators match the declared type and the contract.** A required field has `@ApiProperty()` and no `@IsOptional()`; an optional field has `@ApiPropertyOptional()` and `@IsOptional()`.
18
+ 3. **Nested objects and arrays of objects** have `@ValidateNested()` and `@Type(() => Dto)`; arrays have `@IsArray()`.
19
+ 4. **Query and path numbers and booleans** have `@Type(() => Number)` (or an explicit `@Transform`): they arrive as strings.
20
+ 5. **Decorator descriptions are in English.**
24
21
 
25
- ## Example DTO
26
-
27
- ```typescript
28
- import { IsString, IsEmail, IsOptional, IsUUID, Length } from 'class-validator';
29
- import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
30
- import { Transform } from 'class-transformer';
31
-
32
- export class CreateUserDto {
33
- @ApiProperty({ description: 'User display name', maxLength: 100 })
34
- @IsString()
35
- @Length(1, 100)
36
- name: string;
22
+ ---
37
23
 
38
- @ApiProperty({ description: 'User email address' })
39
- @IsEmail()
40
- @Transform(({ value }) => value.toLowerCase().trim())
41
- email: string;
24
+ ## Review severities (shared with reviewers)
42
25
 
43
- @ApiPropertyOptional({ description: 'External ID from identity provider' })
44
- @IsOptional()
45
- @IsUUID()
46
- externalId?: string;
47
- }
48
- ```
26
+ `review-backend` rates these patterns by this table. Change a row here, never in a reviewer.
49
27
 
50
- ## Output Contract
51
- - DTO examples in responses must be Markdown code blocks.
28
+ | Signal | A finding when | Default | Not a finding |
29
+ |---|---|---|---|
30
+ | Controller input with no DTO class (Rule 1) | a caller controls it | `blocker` with an attack vector stated (input, entry point, impact); `major` with a named malformed input and its wrong outcome; else `info` | input validated by a pipe at the boundary |
31
+ | Validator that contradicts the type or the contract, `@IsOptional()` on a required field, nested object without `@ValidateNested`/`@Type`, query number without `@Type` (Rules 2-4) | a named input passes wrongly or a valid input is rejected | `major` | — |
32
+ | Swagger decorator missing or not matching optionality (Rule 2) | always | `minor` | — |
33
+ | Non-English description (Rule 5) | always | `minor` | — |
@@ -1,5 +1,5 @@
1
1
  ---
2
- description: "Playwright E2E testing standards, test structure, and UI verification workflows."
2
+ description: "Playwright e2e standard shared by code writers and reviewers, with the severities reviewers use: web-first waits instead of sleeps or retries, getByRole and getByLabel locators, auth once in a setup project, independent specs, mocked network, screenshots only on stable surfaces. Use when writing or reviewing Playwright specs."
3
3
  alwaysApply: false
4
4
  globs:
5
5
  - "e2e/**"
@@ -8,315 +8,42 @@ globs:
8
8
  stack_requires: "playwright"
9
9
  ---
10
10
 
11
- # Playwright E2E Testing Guidelines
11
+ # Playwright E2E Testing
12
12
 
13
- ## Purpose
14
- Standardize E2E test creation, execution, and UI verification workflows using Playwright.
13
+ Canon applies: the Playwright documentation on locators, web-first assertions, fixtures and projects. This rule holds only this project's decisions; the general testing rules are in `tdd-workflow.mdc`.
15
14
 
16
- ## When to Apply
17
- - Writing new E2E tests
18
- - Debugging failing tests
19
- - Setting up visual regression tests
20
- - Analyzing UI behavior changes
15
+ ## Rules
21
16
 
22
- ## Prerequisites
17
+ 1. **Wait on a state, never on time.** Use web-first assertions (`await expect(locator).toBeVisible()`) or await the event or response that proves completion (`waitForResponse`). `waitForTimeout`, a fixed delay and `networkidle` are not waits. A flaky spec is fixed by finding the state it races; a retry, a longer timeout or a skip is not a fix.
18
+ 2. **Locators, in this order:** `getByRole` and `getByLabel`; `data-testid` when no role or label fits. CSS classes and XPath never. The string-selector APIs (`page.click(sel)`, `page.fill(sel, v)`, `page.check(sel)`) are deprecated: use a locator.
19
+ 3. **Log in once, in a setup project.** A `setup` project writes `storageState`, and the browser projects depend on it (`dependencies`). Credentials come from the environment, never from a spec. Ordinary specs do not depend on each other or on a spec that writes shared state.
20
+ 4. **A spec owns its data.** It creates what it asserts on, under a unique name, and does not change or delete seeded data. No exact global counts, `.first()` or `.nth(N)` on data the spec does not own.
21
+ 5. **Mock the network at the route** (`page.route`) for anything the spec does not exercise; an unmocked request to an external host is a failure, not a pass-through.
22
+ 6. **Screenshots only** where the repo already has visual-test setup and the surface is stable (no dates, animations or random data); mask or fix what moves. Thresholds live in `playwright.config.ts`, not in a spec.
23
+ 7. **Smoke tags** (`@smoke`) are for fast, reliable, load-bearing flows only.
24
+ 8. **Specs are TypeScript** with descriptive names.
23
25
 
24
- Check Playwright is installed and configured:
25
- ```bash
26
- npm list @playwright/test
27
- ls playwright.config.ts
28
- ```
29
-
30
- ## Run Commands
31
-
32
- ```bash
33
- # Run all tests
34
- npm run e2e
35
-
36
- # Run specific test file
37
- npx playwright test e2e/example.spec.ts
38
-
39
- # Run in headed mode (see browser)
40
- npx playwright test --headed
41
-
42
- # Run with UI mode (interactive debugging)
43
- npx playwright test --ui
44
-
45
- # Run specific project (chromium/firefox/webkit)
46
- npx playwright test --project=chromium
47
-
48
- # Run with trace (for debugging)
49
- npx playwright test --trace on
50
-
51
- # View trace report
52
- npx playwright show-trace trace.zip
53
-
54
- # Generate HTML report
55
- npx playwright test --reporter=html
56
- npx playwright show-report
57
- ```
58
-
59
- ## Test File Structure
60
-
61
- ```typescript
62
- // e2e/feature-name.spec.ts
63
- import { test, expect } from '@playwright/test';
64
-
65
- test.describe('Feature Name', () => {
66
- test.beforeEach(async ({ page }) => {
67
- // Setup: login, navigate, etc.
68
- await page.goto('/path');
69
- });
70
-
71
- test('should display correct initial state', async ({ page }) => {
72
- // Arrange
73
-
74
- // Act
75
-
76
- // Assert
77
- await expect(page.locator('[data-testid="element"]')).toBeVisible();
78
- });
79
-
80
- test('should handle user interaction', async ({ page }) => {
81
- // Test steps
82
- });
83
- });
84
- ```
85
-
86
- ## UI Verification Patterns
87
-
88
- ### Element Visibility
89
- ```typescript
90
- // Check element is visible
91
- await expect(page.locator('.my-class')).toBeVisible();
92
-
93
- // Check element is hidden
94
- await expect(page.locator('.loading')).toBeHidden();
95
-
96
- // Check element contains text
97
- await expect(page.locator('h1')).toContainText('Expected Title');
98
-
99
- // Check element has exact text
100
- await expect(page.locator('.status')).toHaveText('Active');
101
- ```
102
-
103
- ### Form Interactions
104
-
105
- > **Deprecation notice:** `page.fill()`, `page.click()`, and `page.check()` are deprecated.
106
- > Use the locator-based equivalents instead:
107
- > - `page.fill(selector, value)` → `page.locator(selector).fill(value)`
108
- > - `page.click(selector)` → `page.locator(selector).click()`
109
- > - `page.check(selector)` → `page.locator(selector).check()`
110
-
111
- ```typescript
112
- // Fill input
113
- await page.locator('[data-testid="email-input"]').fill('test@example.com');
114
-
115
- // Select from dropdown
116
- await page.locator('select[name="country"]').selectOption('US');
117
-
118
- // Click button
119
- await page.locator('button[type="submit"]').click();
120
-
121
- // Check checkbox
122
- await page.locator('input[type="checkbox"]').check();
123
- ```
124
-
125
- ### Visual Regression Testing
126
-
127
- ```typescript
128
- // Screenshot comparison
129
- test('visual regression - component state', async ({ page }) => {
130
- await page.goto('/component-url');
131
-
132
- // Wait for stability
133
- // DEPRECATED: waitUntil: 'networkidle' / waitForLoadState('networkidle') is deprecated.
134
- // Prefer waitUntil: 'load', waitForLoadState('load'), or explicit waitForSelector / UI state checks.
135
- await page.waitForLoadState('load');
136
-
137
- // Take screenshot
138
- await expect(page).toHaveScreenshot('component-state.png', {
139
- maxDiffPixels: 100
140
- });
141
- });
142
- ```
143
-
144
- **Screenshot Configuration** in `playwright.config.ts`:
145
- ```typescript
146
- expect: {
147
- toHaveScreenshot: {
148
- maxDiffPixels: 100,
149
- threshold: 0.2,
150
- },
151
- },
152
- ```
153
-
154
- ### Responsive Testing
155
-
156
- ```typescript
157
- test('responsive layout', async ({ page }) => {
158
- // Test mobile
159
- await page.setViewportSize({ width: 375, height: 667 });
160
- await page.goto('/');
161
- await expect(page.locator('.mobile-menu')).toBeVisible();
162
-
163
- // Test desktop
164
- await page.setViewportSize({ width: 1280, height: 720 });
165
- await page.goto('/');
166
- await expect(page.locator('.desktop-nav')).toBeVisible();
167
- });
168
- ```
169
-
170
- ## Test Data Attributes
171
-
172
- Use `data-testid` for stable selectors:
173
- ```tsx
174
- // Component
175
- <button data-testid="submit-button">Submit</button>
176
-
177
- // Test (page.click() is deprecated — use locator-based API)
178
- await page.locator('[data-testid="submit-button"]').click();
179
- ```
180
-
181
- ## API Mocking
182
-
183
- ```typescript
184
- import { test, expect } from '@playwright/test';
185
-
186
- test('handles API error', async ({ page }) => {
187
- // Mock API response
188
- await page.route('**/api/users', async route => {
189
- await route.fulfill({
190
- status: 500,
191
- body: JSON.stringify({ error: 'Server error' })
192
- });
193
- });
194
-
195
- await page.goto('/users');
196
- await expect(page.locator('.error-message')).toBeVisible();
197
- });
198
- ```
199
-
200
- ## Authentication Patterns
201
-
202
- ```typescript
203
- test.describe('Authenticated Routes', () => {
204
- test.use({ storageState: 'e2e/auth.json' });
205
-
206
- test('access protected page', async ({ page }) => {
207
- await page.goto('/dashboard');
208
- await expect(page.locator('.dashboard')).toBeVisible();
209
- });
210
- });
211
-
212
- // Setup auth in global setup
213
- test('login flow', async ({ page }) => {
214
- await page.goto('/login');
215
- await page.locator('[data-testid="username"]').fill('user');
216
- await page.locator('[data-testid="password"]').fill('pass');
217
- await page.locator('[data-testid="login-button"]').click();
218
-
219
- // Save state
220
- await page.context().storageState({ path: 'e2e/auth.json' });
221
- });
222
- ```
223
-
224
- ## Debugging Failed Tests
225
-
226
- ```bash
227
- # Run with trace
228
- npx playwright test --trace on
229
-
230
- # View trace
231
- npx playwright show-trace test-results/trace.zip
232
-
233
- # Run in debug mode
234
- npx playwright test --debug
235
-
236
- # Slow motion execution
237
- npx playwright test --headed --slow-mo 1000
238
- ```
239
-
240
- ## Common Issues and Solutions
241
-
242
- ### Flaky Tests
243
- ```typescript
244
- // Add retry logic
245
- await expect.poll(async () => {
246
- const response = await page.evaluate(() => fetch('/api/status'));
247
- return response.status;
248
- }).toBe(200);
249
-
250
- // DEPRECATED: waitForLoadState('networkidle') / waitUntil: 'networkidle' is deprecated.
251
- // Prefer waitForLoadState('load') or explicit waitForSelector / UI state checks.
252
- await page.waitForLoadState('load');
253
- ```
254
-
255
- ### Timing Issues
256
- ```typescript
257
- // Wait for specific element
258
- await page.waitForSelector('.loaded', { timeout: 10000 });
259
-
260
- // Wait for request
261
- await page.waitForRequest('**/api/data');
262
-
263
- // Wait for response
264
- await page.waitForResponse('**/api/data');
265
- ```
266
-
267
- ### Dynamic Content
268
- ```typescript
269
- // Wait for text to appear
270
- await page.waitForFunction(() => {
271
- return document.querySelector('.status')?.textContent === 'Ready';
272
- });
273
- ```
274
-
275
- ## Integration with Feature Analysis
276
-
277
- When using Playwright with `feature-analyzer`:
278
-
279
- 1. **Visual Verification**: After code changes, run visual tests to detect UI regressions
280
- 2. **Flow Validation**: Test critical user flows affected by the feature
281
- 3. **Cross-browser Check**: Verify functionality in all supported browsers
282
- 4. **Responsive Check**: Ensure UI works across different viewports
283
-
284
- ```typescript
285
- // Example: Testing a feature from analysis
286
- test.describe('Feature: User Profile Update (from analysis)', () => {
287
- test('validates profile form changes', async ({ page }) => {
288
- // Based on analysis: test form validation
289
- await page.goto('/profile');
290
-
291
- // Clear and fill (as per DTO changes)
292
- await page.locator('[data-testid="name-input"]').fill('New Name');
293
- await page.locator('[data-testid="save-button"]').click();
294
-
295
- // Verify success (as per API contract)
296
- await expect(page.locator('.success-message')).toBeVisible();
297
- });
298
- });
299
- ```
300
-
301
- ## Output Contract
302
-
303
- - Test files must be TypeScript
304
- - Use descriptive test names
305
- - Include Arrange-Act-Assert comments
306
- - Provide trace/logs for failed tests
307
- - Screenshots must be in `e2e/screenshots/`
308
-
309
- ## CI/CD Integration
26
+ ---
310
27
 
311
- ```yaml
312
- # Example CI step
313
- - name: Run Playwright tests
314
- run: npx playwright test
315
-
316
- - name: Upload test results
317
- uses: actions/upload-artifact@v4
318
- if: always()
319
- with:
320
- name: playwright-report
321
- path: playwright-report/
322
- ```
28
+ ## Review severities (shared with reviewers)
29
+
30
+ `review-testing-practices` rates these patterns by this table. Change a row here, never in the reviewer.
31
+
32
+ | Signal | A finding when | Default | Not a finding |
33
+ |---|---|---|---|
34
+ | `waitForTimeout` or a fixed delay as the wait (Rule 1) | always | `major` | a delay inside a fake-clock test |
35
+ | Backend-dependent assertion with no wait on the response or event that proves completion (Rule 1) | the assertion can race the backend | `major` | an assertion that already retries on the visible state |
36
+ | `networkidle` as the wait (Rule 1) | always | `minor` | — |
37
+ | Flake "fixed" by a retry, a longer timeout or a skip (Rule 1) | one of them is added | `major` | a wait on the proving state |
38
+ | Spec depends on another spec's side effect, or on a storage-state file a spec writes (Rule 3) | specs can run in parallel or in isolation | `major`; `minor` when the config runs them serially | state written by the setup project |
39
+ | Spec mutates or deletes seeded or shared data (Rule 4) | another spec or run reads that data | `major` | data the spec created itself |
40
+ | Exact global count, `.first()` or `.nth(N)` on data the spec does not own (Rule 4) | the environment can hold other rows | `minor`; `major` where a parallel run is shown to change it | a list the spec created in full |
41
+ | Real external host reachable (Rule 5) | a spec calls it, or an unhandled request passes through | `major` | an error path mocked with `page.route` |
42
+ | CSS class or XPath locator where a role, label or test id exists (Rule 2) | always | `minor` | a third-party widget with none of them |
43
+ | Deprecated string-selector API (Rule 2) | always | `minor` | — |
44
+ | Screenshot test on a heavy or non-deterministic surface (Rule 6) | the repo has no visual-test setup, or nothing is masked or fixed | `minor` | a stable component with masked regions |
45
+ | Screenshot threshold loosened inside a spec (Rule 6) | always | `info` | — |
46
+ | Smoke tag on a slow or unreliable flow (Rule 7) | always | `minor` | — |
47
+ | Real secret hard-coded in a spec (Rule 3) | the value is a real credential | rated by the real-credential row of `security-baseline.mdc` Review severities | a test-only value (`info`) |
48
+ | Shared test account or a non-test origin inlined in a spec instead of read from env or the setup project (Rule 3) | the value is a test account or host, not a secret | `major` | a test-only value with no account behind it (`info`) |
49
+ | Non-TypeScript spec or a vague test name (Rule 8) | always | `info` | — |
@@ -1,155 +1,33 @@
1
1
  ---
2
- description: "Security baseline: no secrets in code, parameterized queries, input validation at boundaries, dependency hygiene. Use when writing any code that handles user input, credentials, or external data."
2
+ description: "Security baseline standard shared by code writers and reviewers, with the severities reviewers use: no secrets in code, fail-fast env validation, parameterized queries, input validation at boundaries, dependency hygiene. Use when writing or reviewing code that handles user input, credentials, or external data."
3
3
  alwaysApply: false
4
4
  ---
5
5
 
6
6
  # Security Baseline
7
7
 
8
- ## Purpose
9
- Prevent the most common and highest-impact security vulnerabilities: hardcoded secrets, SQL injection, missing input validation, and exposed sensitive data.
10
-
11
- ## When To Apply
12
- Apply when handling user input, writing queries, managing authentication, reading/writing files, or calling external services.
13
-
14
- ---
8
+ Canon applies: OWASP Top 10, the OWASP Injection, Input Validation and Logging cheat sheets, and the stack security rules. This rule holds only this project's decisions.
15
9
 
16
10
  ## Rules
17
11
 
18
- ### Rule 1: No Secrets in Code or Version Control
19
-
20
- **FORBIDDEN in any committed file:**
21
- - Passwords, API keys, tokens, connection strings
22
- - Private keys (RSA, EC, SSH)
23
- - JWT secrets, session secrets
24
- - Webhook secrets
25
- - Database credentials
26
-
27
- ```typescript
28
- // BAD — secret hardcoded
29
- const client = new S3Client({ credentials: { accessKeyId: 'AKIAIOSFODNN7EXAMPLE', secretAccessKey: 'wJalrXUtn...' } });
30
-
31
- // GOOD — read from environment
32
- const client = new S3Client({
33
- credentials: {
34
- accessKeyId: process.env.AWS_ACCESS_KEY_ID!,
35
- secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY!,
36
- },
37
- });
38
- ```
39
-
40
- **Required:**
41
- - All secrets via environment variables or secret manager (Vault, AWS SSM, etc.)
42
- - `.env` files listed in `.gitignore` before any credential is added
43
- - `process.env.SECRET` access guarded with startup validation (fail-fast if missing)
44
-
45
- ### Rule 2: Parameterized Queries — No String Interpolation
46
- SQL injection is the #1 critical vulnerability. Never build queries by string concatenation.
47
-
48
- ```typescript
49
- // BAD — SQL injection
50
- const result = await db.query(`SELECT * FROM users WHERE id = '${userId}'`);
51
-
52
- // GOOD — parameterized
53
- const result = await db.query('SELECT * FROM users WHERE id = $1', [userId]);
54
-
55
- // GOOD with ORM
56
- const user = await User.findOne({ where: { id: userId } });
57
- ```
58
-
59
- The same rule applies to NoSQL queries: never use `$where` with interpolated strings in MongoDB, never eval-based queries.
60
-
61
- ### Rule 3: Validate All External Input
62
-
63
- Every value from HTTP requests, CLI args, environment variables, and file reads is untrusted. Validate at the boundary before it enters the application:
64
-
65
- ```typescript
66
- // Bad — raw body passed to domain
67
- app.post('/users', async (req, res) => {
68
- await createUser(req.body); // unvalidated
69
- });
70
-
71
- // Good — validate schema at boundary
72
- import { z } from 'zod';
73
- const CreateUserSchema = z.object({
74
- name: z.string().min(1).max(100),
75
- email: z.string().email(),
76
- age: z.number().int().min(0).max(150),
77
- });
78
-
79
- app.post('/users', async (req, res) => {
80
- const result = CreateUserSchema.safeParse(req.body);
81
- if (!result.success) return res.status(400).json({ errors: result.error.issues });
82
- await createUser(result.data); // typed, validated
83
- });
84
- ```
85
-
86
- **Validation requirements:**
87
- - Type coercion is not validation — validate types AND constraints
88
- - Validate string length bounds (prevent oversized payloads)
89
- - Validate numeric ranges (prevent overflow attacks)
90
- - Sanitize HTML if any user input is ever rendered in a browser
91
-
92
- ### Rule 4: Least Privilege for Database Access
93
- - Application database user has only the permissions it needs (no `DROP TABLE`, no `CREATE DATABASE`)
94
- - Separate read and write credentials where possible
95
- - Never use `root` or `admin` database user in application code
96
-
97
- ### Rule 5: Never Log Sensitive Data
98
-
99
- ```typescript
100
- // BAD
101
- logger.info('User login', { user, password: req.body.password });
102
- logger.debug('Payment processed', { card: payment.cardNumber });
103
-
104
- // GOOD — log identifiers, not secrets
105
- logger.info('User login', { userId: user.id, email: user.email });
106
- logger.debug('Payment processed', { paymentId: payment.id, last4: payment.cardLast4 });
107
- ```
108
-
109
- **Never log:** passwords, tokens, full credit card numbers, SSNs, private keys, full session cookies.
110
-
111
- ### Rule 6: Dependency Hygiene
112
- - Run `npm audit` / `bun audit` before shipping any new dependency
113
- - Pin major versions in `package.json` (no `*` or `latest`)
114
- - Prefer dependencies with active maintenance (last commit < 1 year)
115
- - Minimize dependency tree — if you can implement it in 10 lines, don't add a package
116
-
117
- ### Rule 7: Secure Defaults for HTTP
118
- Every HTTP API must have:
119
- - Rate limiting on authentication endpoints
120
- - CORS configured explicitly (not `*` in production)
121
- - Security headers: `X-Content-Type-Options`, `X-Frame-Options`, `Strict-Transport-Security`
122
- - Request size limits (prevent DoS via oversized payloads)
123
-
124
- ---
125
-
126
- ## Pre-Commit Security Check
127
-
128
- Before committing, verify:
129
- - [ ] No API keys, tokens, or passwords in diff
130
- - [ ] No `console.log` with sensitive data
131
- - [ ] New environment variables documented in `.env.example`
132
- - [ ] No `eval()`, `new Function()`, or dynamic `require()` with user input
133
- - [ ] No `dangerouslySetInnerHTML` with unescaped user input (React)
134
-
135
- ---
136
-
137
- ## Iron Laws
12
+ 1. **No credentials in any committed file.** Secrets come from the environment or a secret manager; `.env` is in `.gitignore` before the first credential is added. Required env vars are validated at startup and fail fast; new ones are documented in `.env.example`.
13
+ 2. **Queries are parameterized, with no exception for "internal" data.**
14
+ 3. **External input is validated at the boundary** (HTTP, CLI args, env, file reads) before it reaches the database, filesystem or shell.
15
+ 4. **Never log credentials, tokens or other secrets.**
16
+ 5. **Dependencies:** pin major versions (no `*` or `latest`); prefer packages with a commit in the last year; do not add a package for what is about 10 lines.
138
17
 
139
- **IRON LAW 1: A hardcoded secret in source code is a production security incident the moment it is committed.**
140
- **IRON LAW 2: String interpolation in SQL queries is forbidden. No exceptions for "internal" data.**
141
- **IRON LAW 3: External input that reaches the database, filesystem, or shell without validation is an attack surface.**
18
+ HTTP defaults (a rate limit on auth endpoints, explicit CORS, security headers, request size limits) and database least privilege follow the installed stack security rule.
142
19
 
143
20
  ---
144
21
 
145
- ## Red Flags — Stop and re-read this rule if you are thinking:
22
+ ## Review severities (shared with reviewers)
146
23
 
147
- | Rationalization | Why it's wrong |
148
- |---|---|
149
- | "It's just a dev key, I'll replace it before production" | Dev keys get forgotten in repos — automated secret scanners find them in minutes after push |
150
- | "The input comes from our own frontend, so it's trusted" | Frontends can be bypassed — always validate at the server boundary |
151
- | "SQL injection requires a specific pattern, my query is safe" | Every string-interpolated query is vulnerable — parameterize unconditionally |
152
- | "Logging the token is fine, our logs are private" | Logs are exfiltrated in breaches — sensitive data in logs amplifies every incident |
153
- | "This package has a known CVE but it's not on the attack path" | "Not on the attack path" is an assumption that changes when the system evolves |
24
+ `review-security-code` rates these patterns by this table; the lens's attack-vector law still applies. Change a row here, never in a reviewer.
154
25
 
155
- **IRON LAW: SECURITY VULNERABILITIES DO NOT WAIT FOR CONVENIENT TIMING TO BE EXPLOITED.**
26
+ | Signal | A finding when | Default | Not a finding |
27
+ |---|---|---|---|
28
+ | Real credential in a committed file (Rule 1) | always | `blocker` | an obvious placeholder or test value |
29
+ | Required env var read without startup validation (Rule 1) | always | `minor` | a variable validated elsewhere at startup |
30
+ | Query built by interpolation (Rule 2) | external input reaches it | `blocker` with the attack vector stated | a constant or an allowlisted identifier, with the reason read |
31
+ | External input reaches the database, filesystem or shell unvalidated (Rule 3) | a named input reaches it | `blocker` with the attack vector stated; `major` if the outcome is wrong but not an attacker's gain | validation already done at the boundary above |
32
+ | Credential or secret in a log call (Rule 4) | always | `major` | an identifier or last-four |
33
+ | Dependency range `*` / `latest` (Rule 5) | always | `minor` | — |