@mrciphersmith/keryx 0.4.29 → 0.4.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +2446 -1391
- package/dist/core.js +90 -27
- package/dist/keryx-general-worker-entry.js +82 -25
- package/package.json +1 -1
- package/src/gdskills/bundled/install-manifest.json +2 -0
- package/src/gdskills/bundled/rules/core/api-contracts.mdc +21 -136
- package/src/gdskills/bundled/rules/core/async-patterns.mdc +18 -171
- package/src/gdskills/bundled/rules/core/clean-architecture.mdc +21 -3
- package/src/gdskills/bundled/rules/core/cli-interface-design.mdc +63 -194
- package/src/gdskills/bundled/rules/core/code-style-patterns.mdc +36 -49
- package/src/gdskills/bundled/rules/core/concurrency-patterns.mdc +32 -0
- package/src/gdskills/bundled/rules/core/database-patterns.mdc +26 -148
- package/src/gdskills/bundled/rules/core/error-handling.mdc +7 -8
- package/src/gdskills/bundled/rules/core/frontend-assistant.mdc +14 -29
- package/src/gdskills/bundled/rules/core/layout-rendering.mdc +51 -0
- package/src/gdskills/bundled/rules/core/mobx-store-template.mdc +69 -511
- package/src/gdskills/bundled/rules/core/nestjs-dto.mdc +18 -36
- package/src/gdskills/bundled/rules/core/playwright-testing.mdc +35 -308
- package/src/gdskills/bundled/rules/core/security-baseline.mdc +18 -140
- package/src/gdskills/bundled/rules/core/solid-principles.mdc +31 -7
- package/src/gdskills/bundled/rules/core/storybook-guidelines.mdc +20 -22
- package/src/gdskills/bundled/rules/core/tdd-workflow.mdc +37 -74
- package/src/gdskills/bundled/rules/core/ui-anti-slop.mdc +48 -37
- package/src/gdskills/bundled/skills/quality/deprecation-path/SKILL.md +1 -1
- package/src/gdskills/bundled/skills/review/review-architecture/SKILL.md +24 -60
- package/src/gdskills/bundled/skills/review/review-backend/SKILL.md +13 -65
- package/src/gdskills/bundled/skills/review/review-clean-code/SKILL.md +22 -35
- package/src/gdskills/bundled/skills/review/review-frontend/SKILL.md +16 -309
- package/src/gdskills/bundled/skills/review/review-frontend-conventions/SKILL.md +7 -21
- package/src/gdskills/bundled/skills/review/review-highload/SKILL.md +83 -227
- package/src/gdskills/bundled/skills/review/review-layout/SKILL.md +22 -28
- package/src/gdskills/bundled/skills/review/review-logic/SKILL.md +8 -8
- package/src/gdskills/bundled/skills/review/review-performance/SKILL.md +15 -37
- package/src/gdskills/bundled/skills/review/review-security-code/SKILL.md +7 -7
- package/src/gdskills/bundled/skills/review/review-style/SKILL.md +31 -66
- package/src/gdskills/bundled/skills/review/review-testing-practices/SKILL.md +21 -39
- package/src/gdskills/bundled/skills/review/review-ui-ux/SKILL.md +42 -82
- package/src/gdskills/bundled/stacks/angular/rules/coding-style.mdc +15 -57
- package/src/gdskills/bundled/stacks/angular/rules/patterns.mdc +16 -60
- package/src/gdskills/bundled/stacks/angular/rules/security.mdc +11 -49
- package/src/gdskills/bundled/stacks/angular/rules/testing.mdc +13 -52
- package/src/gdskills/bundled/stacks/c-cpp/rules/coding-style.mdc +33 -57
- package/src/gdskills/bundled/stacks/c-cpp/rules/patterns.mdc +35 -62
- package/src/gdskills/bundled/stacks/c-cpp/rules/security.mdc +35 -62
- package/src/gdskills/bundled/stacks/c-cpp/rules/testing.mdc +34 -54
- package/src/gdskills/bundled/stacks/ci-github-gitlab/rules/patterns.mdc +27 -56
- package/src/gdskills/bundled/stacks/ci-github-gitlab/rules/security.mdc +51 -119
- package/src/gdskills/bundled/stacks/csharp-dotnet/rules/coding-style.mdc +42 -74
- package/src/gdskills/bundled/stacks/csharp-dotnet/rules/patterns.mdc +45 -84
- package/src/gdskills/bundled/stacks/csharp-dotnet/rules/security.mdc +34 -59
- package/src/gdskills/bundled/stacks/csharp-dotnet/rules/testing.mdc +33 -62
- package/src/gdskills/bundled/stacks/django/rules/coding-style.mdc +15 -56
- package/src/gdskills/bundled/stacks/django/rules/patterns.mdc +16 -68
- package/src/gdskills/bundled/stacks/django/rules/security.mdc +13 -71
- package/src/gdskills/bundled/stacks/django/rules/testing.mdc +16 -62
- package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/coding-style.mdc +30 -53
- package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/patterns.mdc +20 -56
- package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/security.mdc +52 -122
- package/src/gdskills/bundled/stacks/docker-k8s-terraform/rules/testing.mdc +23 -42
- package/src/gdskills/bundled/stacks/fastapi/rules/coding-style.mdc +13 -47
- package/src/gdskills/bundled/stacks/fastapi/rules/patterns.mdc +18 -81
- package/src/gdskills/bundled/stacks/fastapi/rules/security.mdc +13 -75
- package/src/gdskills/bundled/stacks/fastapi/rules/testing.mdc +14 -58
- package/src/gdskills/bundled/stacks/flutter-dart/rules/coding-style.mdc +36 -74
- package/src/gdskills/bundled/stacks/flutter-dart/rules/patterns.mdc +30 -66
- package/src/gdskills/bundled/stacks/flutter-dart/rules/security.mdc +33 -67
- package/src/gdskills/bundled/stacks/flutter-dart/rules/testing.mdc +41 -73
- package/src/gdskills/bundled/stacks/go/rules/coding-style.mdc +36 -57
- package/src/gdskills/bundled/stacks/go/rules/patterns.mdc +27 -42
- package/src/gdskills/bundled/stacks/go/rules/security.mdc +26 -43
- package/src/gdskills/bundled/stacks/go/rules/testing.mdc +23 -41
- package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/coding-style.mdc +18 -37
- package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/patterns.mdc +26 -43
- package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/security.mdc +25 -37
- package/src/gdskills/bundled/stacks/java-kotlin-spring/rules/testing.mdc +34 -50
- package/src/gdskills/bundled/stacks/kotlin-android/rules/coding-style.mdc +28 -65
- package/src/gdskills/bundled/stacks/kotlin-android/rules/patterns.mdc +34 -78
- package/src/gdskills/bundled/stacks/kotlin-android/rules/security.mdc +35 -68
- package/src/gdskills/bundled/stacks/kotlin-android/rules/testing.mdc +34 -68
- package/src/gdskills/bundled/stacks/mobx/rules/coding-style.mdc +18 -64
- package/src/gdskills/bundled/stacks/mobx/rules/patterns.mdc +13 -66
- package/src/gdskills/bundled/stacks/mobx/rules/security.mdc +8 -35
- package/src/gdskills/bundled/stacks/mobx/rules/testing.mdc +10 -39
- package/src/gdskills/bundled/stacks/nestjs/rules/coding-style.mdc +32 -45
- package/src/gdskills/bundled/stacks/nestjs/rules/patterns.mdc +40 -60
- package/src/gdskills/bundled/stacks/nestjs/rules/security.mdc +30 -50
- package/src/gdskills/bundled/stacks/nestjs/rules/testing.mdc +27 -47
- package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/coding-style.mdc +14 -48
- package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/patterns.mdc +15 -67
- package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/security.mdc +12 -50
- package/src/gdskills/bundled/stacks/nextjs-nuxt/rules/testing.mdc +11 -43
- package/src/gdskills/bundled/stacks/php-laravel/rules/coding-style.mdc +17 -58
- package/src/gdskills/bundled/stacks/php-laravel/rules/patterns.mdc +15 -56
- package/src/gdskills/bundled/stacks/php-laravel/rules/security.mdc +13 -50
- package/src/gdskills/bundled/stacks/php-laravel/rules/testing.mdc +14 -55
- package/src/gdskills/bundled/stacks/python/rules/coding-style.mdc +13 -41
- package/src/gdskills/bundled/stacks/python/rules/patterns.mdc +20 -61
- package/src/gdskills/bundled/stacks/python/rules/security.mdc +15 -57
- package/src/gdskills/bundled/stacks/python/rules/testing.mdc +16 -50
- package/src/gdskills/bundled/stacks/react/rules/coding-style.mdc +14 -40
- package/src/gdskills/bundled/stacks/react/rules/patterns.mdc +15 -55
- package/src/gdskills/bundled/stacks/react/rules/security.mdc +13 -49
- package/src/gdskills/bundled/stacks/react/rules/testing.mdc +10 -37
- package/src/gdskills/bundled/stacks/ruby-rails/rules/coding-style.mdc +12 -45
- package/src/gdskills/bundled/stacks/ruby-rails/rules/patterns.mdc +18 -67
- package/src/gdskills/bundled/stacks/ruby-rails/rules/security.mdc +11 -60
- package/src/gdskills/bundled/stacks/ruby-rails/rules/testing.mdc +14 -65
- package/src/gdskills/bundled/stacks/rust/rules/coding-style.mdc +39 -65
- package/src/gdskills/bundled/stacks/rust/rules/patterns.mdc +33 -60
- package/src/gdskills/bundled/stacks/rust/rules/security.mdc +35 -57
- package/src/gdskills/bundled/stacks/rust/rules/testing.mdc +29 -52
- package/src/gdskills/bundled/stacks/sql-db/rules/coding-style.mdc +12 -48
- package/src/gdskills/bundled/stacks/sql-db/rules/patterns.mdc +22 -113
- package/src/gdskills/bundled/stacks/sql-db/rules/security.mdc +11 -56
- package/src/gdskills/bundled/stacks/sql-db/rules/testing.mdc +14 -59
- package/src/gdskills/bundled/stacks/swift-ios/rules/coding-style.mdc +29 -65
- package/src/gdskills/bundled/stacks/swift-ios/rules/patterns.mdc +41 -88
- package/src/gdskills/bundled/stacks/swift-ios/rules/security.mdc +28 -53
- package/src/gdskills/bundled/stacks/swift-ios/rules/testing.mdc +32 -65
- package/src/gdskills/bundled/stacks/vue/rules/coding-style.mdc +17 -52
- package/src/gdskills/bundled/stacks/vue/rules/patterns.mdc +17 -63
- package/src/gdskills/bundled/stacks/vue/rules/security.mdc +11 -41
- package/src/gdskills/bundled/stacks/vue/rules/testing.mdc +16 -48
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
---
|
|
2
|
-
description: "NestJS DTO
|
|
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
|
|
10
|
+
# NestJS DTOs
|
|
11
11
|
|
|
12
|
-
|
|
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
|
-
##
|
|
16
|
-
Apply when creating or reviewing NestJS DTO files (`*dto*.ts`, `dto/**/*.ts`) in the backend project.
|
|
14
|
+
## Rules
|
|
17
15
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
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
|
-
|
|
39
|
-
@IsEmail()
|
|
40
|
-
@Transform(({ value }) => value.toLowerCase().trim())
|
|
41
|
-
email: string;
|
|
24
|
+
## Review severities (shared with reviewers)
|
|
42
25
|
|
|
43
|
-
|
|
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
|
-
|
|
51
|
-
|
|
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
|
|
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
|
|
11
|
+
# Playwright E2E Testing
|
|
12
12
|
|
|
13
|
-
|
|
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
|
-
##
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
312
|
-
|
|
313
|
-
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
**
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
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
|
-
##
|
|
22
|
+
## Review severities (shared with reviewers)
|
|
146
23
|
|
|
147
|
-
|
|
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
|
-
|
|
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` | — |
|