diff --git a/.cursor/rules/deno-testing.mdc b/.cursor/rules/deno-testing.mdc new file mode 100644 index 000000000..d20605ad7 --- /dev/null +++ b/.cursor/rules/deno-testing.mdc @@ -0,0 +1,46 @@ +--- +description: Mandatory Deno-based testing requirements for HPKE-JS code modifications +globs: ["**/*.ts", "**/*.js", "test/**/*"] +alwaysApply: true +--- + +# Deno Testing Requirements for HPKE-JS + +## Mandatory Testing for Code Changes +- All code modifications MUST be accompanied by appropriate tests to verify functionality +- Tests MUST be written using Deno's native testing framework +- Use `@std/testing/bdd` for behavior-driven testing when appropriate +- Use `@std/assert` for assertions + +## Deno Task Usage +- ALWAYS use the predefined Deno tasks from `deno.json` instead of running commands directly +- Primary testing command: `deno task test:deno` for comprehensive testing +- For specific package testing, use: `deno task test:deno:` + +Available package-specific test tasks: +- `deno task test:deno:common` +- `deno task test:deno:core` +- `deno task test:deno:chacha20poly1305` +- `deno task test:deno:dhkem-x25519` +- `deno task test:deno:dhkem-x448` +- `deno task test:deno:dhkem-secp256k1` +- `deno task test:deno:hybridkem-x-wing` +- `deno task test:deno:hpke-js` +- `deno task test:deno:ml-kem` + +## Testing Workflow +1. Before making changes: Run relevant tests to establish baseline +2. After making changes: Run tests to verify functionality +3. Use `deno task test:deno` for full project testing +4. Use package-specific tasks for focused testing during development + +## Test File Conventions +- Test files MUST be placed in the `test/` directory within each package +- Test files MUST follow the naming convention: `*.test.ts` +- Import test utilities from `@std/assert` and `@std/testing/bdd` + +## Code Quality Integration +- `deno task test:deno` includes formatting, linting, type checking, and tests +- Individual quality checks: `deno task check` for type checking +- Coverage enabled with `--coverage=coverage` +- Use `deno task cov` to generate coverage reports diff --git a/.cursor/rules/development-workflow.mdc b/.cursor/rules/development-workflow.mdc new file mode 100644 index 000000000..aaeb5459d --- /dev/null +++ b/.cursor/rules/development-workflow.mdc @@ -0,0 +1,28 @@ +--- +description: Development workflow standards for HPKE-JS project +globs: ["src/**/*", "test/**/*"] +alwaysApply: false +--- + +# Development Workflow Standards + +## Pre-Commit Testing +- Run `deno task test:deno` before committing changes +- Ensure all tests pass before requesting code reviews +- Use package-specific tasks during active development for faster feedback + +## Error Handling Protocol +- If tests fail, investigate and fix issues before proceeding +- Check both test logic and implementation code +- Use `deno task check` to identify type-related issues +- Use formatting and linting to catch style issues + +## Multi-Runtime Considerations +- For significant changes, consider running the full test suite: `deno task test` +- This includes Deno, Node.js, browser, Cloudflare Workers, and Bun testing +- For quick iterations, focus on Deno tests: `deno task test:deno` + +## Test Execution Features +- Tests run with `--fail-fast` flag for quick feedback +- Tests run with `--parallel` flag for faster execution +- Tests include documentation tests (`--doc`) to verify code examples \ No newline at end of file diff --git a/.cursor/rules/package-specific-testing.mdc b/.cursor/rules/package-specific-testing.mdc new file mode 100644 index 000000000..b422e5818 --- /dev/null +++ b/.cursor/rules/package-specific-testing.mdc @@ -0,0 +1,30 @@ +--- +description: Package-specific testing guidance for HPKE-JS components +globs: ["packages/*/src/**/*", "packages/*/test/**/*"] +alwaysApply: false +--- + +# Package-Specific Testing Guidance + +## Available Packages and Test Commands + +### Core Packages +- **common**: `deno task test:deno:common` - Common utilities and base functionality +- **core**: `deno task test:deno:core` - Core HPKE implementation +- **hpke-js**: `deno task test:deno:hpke-js` - Main HPKE library + +### Cryptographic Packages +- **chacha20poly1305**: `deno task test:deno:chacha20poly1305` - ChaCha20-Poly1305 AEAD +- **dhkem-x25519**: `deno task test:deno:dhkem-x25519` - X25519 DHKEM +- **dhkem-x448**: `deno task test:deno:dhkem-x448` - X448 DHKEM +- **dhkem-secp256k1**: `deno task test:deno:dhkem-secp256k1` - secp256k1 DHKEM +- **ml-kem**: `deno task test:deno:ml-kem` - ML-KEM post-quantum cryptography + +### Hybrid KEM Packages +- **hybridkem-x-wing**: `deno task test:deno:hybridkem-x-wing` - X-Wing hybrid KEM + +## Package-Specific Development Tips +- Use focused package testing during active development +- Run individual package tests for faster feedback loops +- Each package has its own `test/` directory with `*.test.ts` files +- Package tests include conformance tests for cryptographic standards \ No newline at end of file diff --git a/.cursor/rules/test-templates.mdc b/.cursor/rules/test-templates.mdc new file mode 100644 index 000000000..e11933193 --- /dev/null +++ b/.cursor/rules/test-templates.mdc @@ -0,0 +1,74 @@ +--- +description: Test file templates and patterns for HPKE-JS +globs: ["test/**/*.ts", "**/*.test.ts"] +alwaysApply: false +--- + +# Test File Templates and Patterns + +## Basic Test Structure +Use this template when creating new test files: + +```typescript +import { assertEquals, assertRejects, assertThrows } from "@std/assert"; +import { describe, it } from "@std/testing/bdd"; + +describe("YourModule", () => { + it("should perform expected behavior", () => { + // Arrange + const input = "test input"; + + // Act + const result = yourFunction(input); + + // Assert + assertEquals(result, expectedOutput); + }); + + it("should handle error cases", () => { + assertThrows(() => { + yourFunction(invalidInput); + }, Error, "Expected error message"); + }); +}); +``` + +## Async Test Pattern +For testing asynchronous operations: + +```typescript +import { assertEquals } from "@std/assert"; +import { describe, it } from "@std/testing/bdd"; + +describe("AsyncModule", () => { + it("should handle async operations", async () => { + const result = await yourAsyncFunction(); + assertEquals(result, expectedValue); + }); + + it("should reject with proper error", async () => { + await assertRejects( + async () => await yourAsyncFunction(invalidInput), + Error, + "Expected error message" + ); + }); +}); +``` + +## Import Patterns +Standard imports for HPKE-JS tests: + +```typescript +// For assertions +import { assertEquals, assertRejects, assertThrows } from "@std/assert"; + +// For BDD-style tests +import { describe, it, beforeEach, afterEach } from "@std/testing/bdd"; + +// For cryptographic testing +import { CipherSuite } from "../src/cipherSuite.ts"; +import type { AeadInterface } from "../src/interfaces/aeadInterface.ts"; +``` + +@packages/common/test/hmac.test.ts \ No newline at end of file