Skip to content

Commit f9788a7

Browse files
authored
base: experimentally add .cursor/rules. (#660)
1 parent a7c54b4 commit f9788a7

File tree

4 files changed

+178
-0
lines changed

4 files changed

+178
-0
lines changed

.cursor/rules/deno-testing.mdc

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
description: Mandatory Deno-based testing requirements for HPKE-JS code modifications
3+
globs: ["**/*.ts", "**/*.js", "test/**/*"]
4+
alwaysApply: true
5+
---
6+
7+
# Deno Testing Requirements for HPKE-JS
8+
9+
## Mandatory Testing for Code Changes
10+
- All code modifications MUST be accompanied by appropriate tests to verify functionality
11+
- Tests MUST be written using Deno's native testing framework
12+
- Use `@std/testing/bdd` for behavior-driven testing when appropriate
13+
- Use `@std/assert` for assertions
14+
15+
## Deno Task Usage
16+
- ALWAYS use the predefined Deno tasks from `deno.json` instead of running commands directly
17+
- Primary testing command: `deno task test:deno` for comprehensive testing
18+
- For specific package testing, use: `deno task test:deno:<package-name>`
19+
20+
Available package-specific test tasks:
21+
- `deno task test:deno:common`
22+
- `deno task test:deno:core`
23+
- `deno task test:deno:chacha20poly1305`
24+
- `deno task test:deno:dhkem-x25519`
25+
- `deno task test:deno:dhkem-x448`
26+
- `deno task test:deno:dhkem-secp256k1`
27+
- `deno task test:deno:hybridkem-x-wing`
28+
- `deno task test:deno:hpke-js`
29+
- `deno task test:deno:ml-kem`
30+
31+
## Testing Workflow
32+
1. Before making changes: Run relevant tests to establish baseline
33+
2. After making changes: Run tests to verify functionality
34+
3. Use `deno task test:deno` for full project testing
35+
4. Use package-specific tasks for focused testing during development
36+
37+
## Test File Conventions
38+
- Test files MUST be placed in the `test/` directory within each package
39+
- Test files MUST follow the naming convention: `*.test.ts`
40+
- Import test utilities from `@std/assert` and `@std/testing/bdd`
41+
42+
## Code Quality Integration
43+
- `deno task test:deno` includes formatting, linting, type checking, and tests
44+
- Individual quality checks: `deno task check` for type checking
45+
- Coverage enabled with `--coverage=coverage`
46+
- Use `deno task cov` to generate coverage reports
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
description: Development workflow standards for HPKE-JS project
3+
globs: ["src/**/*", "test/**/*"]
4+
alwaysApply: false
5+
---
6+
7+
# Development Workflow Standards
8+
9+
## Pre-Commit Testing
10+
- Run `deno task test:deno` before committing changes
11+
- Ensure all tests pass before requesting code reviews
12+
- Use package-specific tasks during active development for faster feedback
13+
14+
## Error Handling Protocol
15+
- If tests fail, investigate and fix issues before proceeding
16+
- Check both test logic and implementation code
17+
- Use `deno task check` to identify type-related issues
18+
- Use formatting and linting to catch style issues
19+
20+
## Multi-Runtime Considerations
21+
- For significant changes, consider running the full test suite: `deno task test`
22+
- This includes Deno, Node.js, browser, Cloudflare Workers, and Bun testing
23+
- For quick iterations, focus on Deno tests: `deno task test:deno`
24+
25+
## Test Execution Features
26+
- Tests run with `--fail-fast` flag for quick feedback
27+
- Tests run with `--parallel` flag for faster execution
28+
- Tests include documentation tests (`--doc`) to verify code examples
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
---
2+
description: Package-specific testing guidance for HPKE-JS components
3+
globs: ["packages/*/src/**/*", "packages/*/test/**/*"]
4+
alwaysApply: false
5+
---
6+
7+
# Package-Specific Testing Guidance
8+
9+
## Available Packages and Test Commands
10+
11+
### Core Packages
12+
- **common**: `deno task test:deno:common` - Common utilities and base functionality
13+
- **core**: `deno task test:deno:core` - Core HPKE implementation
14+
- **hpke-js**: `deno task test:deno:hpke-js` - Main HPKE library
15+
16+
### Cryptographic Packages
17+
- **chacha20poly1305**: `deno task test:deno:chacha20poly1305` - ChaCha20-Poly1305 AEAD
18+
- **dhkem-x25519**: `deno task test:deno:dhkem-x25519` - X25519 DHKEM
19+
- **dhkem-x448**: `deno task test:deno:dhkem-x448` - X448 DHKEM
20+
- **dhkem-secp256k1**: `deno task test:deno:dhkem-secp256k1` - secp256k1 DHKEM
21+
- **ml-kem**: `deno task test:deno:ml-kem` - ML-KEM post-quantum cryptography
22+
23+
### Hybrid KEM Packages
24+
- **hybridkem-x-wing**: `deno task test:deno:hybridkem-x-wing` - X-Wing hybrid KEM
25+
26+
## Package-Specific Development Tips
27+
- Use focused package testing during active development
28+
- Run individual package tests for faster feedback loops
29+
- Each package has its own `test/` directory with `*.test.ts` files
30+
- Package tests include conformance tests for cryptographic standards

.cursor/rules/test-templates.mdc

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
description: Test file templates and patterns for HPKE-JS
3+
globs: ["test/**/*.ts", "**/*.test.ts"]
4+
alwaysApply: false
5+
---
6+
7+
# Test File Templates and Patterns
8+
9+
## Basic Test Structure
10+
Use this template when creating new test files:
11+
12+
```typescript
13+
import { assertEquals, assertRejects, assertThrows } from "@std/assert";
14+
import { describe, it } from "@std/testing/bdd";
15+
16+
describe("YourModule", () => {
17+
it("should perform expected behavior", () => {
18+
// Arrange
19+
const input = "test input";
20+
21+
// Act
22+
const result = yourFunction(input);
23+
24+
// Assert
25+
assertEquals(result, expectedOutput);
26+
});
27+
28+
it("should handle error cases", () => {
29+
assertThrows(() => {
30+
yourFunction(invalidInput);
31+
}, Error, "Expected error message");
32+
});
33+
});
34+
```
35+
36+
## Async Test Pattern
37+
For testing asynchronous operations:
38+
39+
```typescript
40+
import { assertEquals } from "@std/assert";
41+
import { describe, it } from "@std/testing/bdd";
42+
43+
describe("AsyncModule", () => {
44+
it("should handle async operations", async () => {
45+
const result = await yourAsyncFunction();
46+
assertEquals(result, expectedValue);
47+
});
48+
49+
it("should reject with proper error", async () => {
50+
await assertRejects(
51+
async () => await yourAsyncFunction(invalidInput),
52+
Error,
53+
"Expected error message"
54+
);
55+
});
56+
});
57+
```
58+
59+
## Import Patterns
60+
Standard imports for HPKE-JS tests:
61+
62+
```typescript
63+
// For assertions
64+
import { assertEquals, assertRejects, assertThrows } from "@std/assert";
65+
66+
// For BDD-style tests
67+
import { describe, it, beforeEach, afterEach } from "@std/testing/bdd";
68+
69+
// For cryptographic testing
70+
import { CipherSuite } from "../src/cipherSuite.ts";
71+
import type { AeadInterface } from "../src/interfaces/aeadInterface.ts";
72+
```
73+
74+
@packages/common/test/hmac.test.ts

0 commit comments

Comments
 (0)