Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .amazonq/rules/development-rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- Use snake_case for Python methods
- Include type hints: `list[str]`, `dict[str, int]`, `Type | None`
- Follow linting rules (black, isort, ruff, mypy)
- **NO noise docstrings**: Avoid docstrings that merely restate the function name (e.g., `"""Test CLI help command."""` for `test_cli_help()`). Only add docstrings when they provide meaningful context beyond what the code itself conveys

## Testing

Expand Down
74 changes: 14 additions & 60 deletions .amazonq/rules/problem-creation.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

When user requests a problem by **number** or **name/slug**, the assistant will:

1. **Scrape** problem data using `.templates/leetcode/scrape.py`
1. **Scrape** problem data using `lcpy scrape`
2. **Transform** data into proper JSON template format
3. **CRITICAL: Include images** - Extract image URLs from scraped data and add to readme_examples with format: `![Example N](image_url)\n\n` before code blocks
- Check scraped data for image URLs in the `raw_content` field
- Look for patterns: `https://assets.leetcode.com/uploads/...` or `<img alt="" src="..." />`
- Common patterns: `kthtree1.jpg`, `kthtree2.jpg`, `clone_graph.png`, `container.jpg`
- Images provide crucial visual context, especially for tree and graph problems
- Always verify images are included in `readme_examples` and accessible
4. **Create** JSON file in `.templates/leetcode/json/{problem_name}.json`
4. **Create** JSON file in `leetcode_py/cli/resources/leetcode/json/problems/{problem_name}.json`
5. **Update** Makefile with `PROBLEM ?= {problem_name}`
6. **Generate** problem structure using `make p-gen`
7. **Verify** with `make p-lint` - fix template issues in JSON if possible, or manually fix generated files if template limitations
Expand All @@ -22,15 +22,15 @@ When user requests a problem by **number** or **name/slug**, the assistant will:

```bash
# Fetch by number
poetry run python .templates/leetcode/scrape.py -n 1
lcpy scrape -n 1

# Fetch by slug
poetry run python .templates/leetcode/scrape.py -s "two-sum"
lcpy scrape -s "two-sum"
```

## JSON Template Format

Required fields for `.templates/leetcode/json/{problem_name}.json`:
Required fields for `leetcode_py/cli/resources/leetcode/json/problems/{problem_name}.json`:

**CRITICAL: Use single quotes for Python strings in playground fields to avoid JSON escaping issues with Jupyter notebooks.**

Expand All @@ -41,61 +41,15 @@ Required fields for `.templates/leetcode/json/{problem_name}.json`:
- `playground_assertion`: Use single quotes for string literals
- Double quotes in JSON + cookiecutter + Jupyter notebook = triple escaping issues

**Reference examples in `.templates/leetcode/examples/` for complete templates:**

- `basic.json5` - All standard problems (array, string, tree, linked list, etc.)
- `design.json5` - Data structure design problems (LRU Cache, etc.)

````json
{
"problem_name": "two_sum",
"solution_class_name": "Solution",
"problem_number": "1",
"problem_title": "Two Sum",
"difficulty": "Easy",
"topics": "Array, Hash Table",
"tags": ["grind-75"],
"readme_description": "Given an array of integers `nums` and an integer `target`, return indices of the two numbers such that they add up to `target`.",
"readme_examples": [
{
"content": "![Example 1](https://example.com/image1.jpg)\n\n```\nInput: nums = [2,7,11,15], target = 9\nOutput: [0,1]\n```\n**Explanation:** Because nums[0] + nums[1] == 9, we return [0, 1]."
}
],
"readme_constraints": "- 2 <= nums.length <= 10^4\n- -10^9 <= nums[i] <= 10^9\n- -10^9 <= target <= 10^9\n- Only one valid answer exists.",
"readme_additional": "",
"solution_imports": "",
"solution_methods": [
{
"name": "two_sum",
"parameters": "nums: list[int], target: int",
"return_type": "list[int]",
"dummy_return": "[]"
}
],
"test_imports": "import pytest\nfrom leetcode_py.test_utils import logged_test\nfrom .solution import Solution",
"test_class_name": "TwoSum",
"test_helper_methods": [
{
"name": "setup_method",
"parameters": "",
"body": "self.solution = Solution()"
}
],
"test_methods": [
{
"name": "test_two_sum",
"parametrize": "nums, target, expected",
"parametrize_typed": "nums: list[int], target: int, expected: list[int]",
"test_cases": "[([2, 7, 11, 15], 9, [0, 1]), ([3, 2, 4], 6, [1, 2])]",
"body": "result = self.solution.two_sum(nums, target)\nassert result == expected"
}
],
"playground_imports": "from solution import Solution",
"playground_test_case": "# Example test case\nnums = [2, 7, 11, 15]\ntarget = 9\nexpected = [0, 1]",
"playground_execution": "result = Solution().two_sum(nums, target)\nresult",
"playground_assertion": "assert result == expected"
}
````
**Reference the complete template example:**

See `leetcode_py/cli/resources/leetcode/examples/example.json5` for a comprehensive template with:

- All field definitions and variations
- Comments explaining each field
- Examples for different problem types (basic, tree, linked list, design, trie)
- Proper JSON escaping rules for playground fields
- Multiple solution class patterns

## Naming Conventions

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Test Case Enhancement Rules
# Test Quality Assurance Rules

## Simple Enhancement Workflow

Expand All @@ -7,7 +7,7 @@ When user requests test case enhancement or **test reproducibility verification*
### 1. Problem Resolution

- Use active file context or user-provided problem name
- If unclear, run: `poetry run python .templates/check_test_cases.py --threshold=10 --max=1`
- If unclear, run: `poetry run python -m leetcode_py.tools.check_test_cases --threshold=10 --max=1`

### 2. Enhancement Process

Expand Down Expand Up @@ -55,20 +55,35 @@ mv .cache/leetcode/{problem_name} leetcode/{problem_name}

## Quick Commands

### CLI Commands (Recommended)

```bash
# Find problems needing enhancement
poetry run python .templates/check_test_cases.py --threshold=10
# Generate enhanced problem
lcpy gen -s {problem_name} -o leetcode --force

# Test specific problem
make p-test PROBLEM={problem_name}

# Generate from JSON template
make p-gen PROBLEM={problem_name} FORCE=1

# Lint check
make p-lint PROBLEM={problem_name}
```

### Development Commands

```bash
# Find problems needing enhancement
poetry run python -m leetcode_py.tools.check_test_cases --threshold=10

# Check all problems (no limit)
poetry run python -m leetcode_py.tools.check_test_cases --threshold=10 --max=none

# Check with custom threshold
poetry run python -m leetcode_py.tools.check_test_cases --threshold=12

# Generate from JSON template (uses lcpy internally)
make p-gen PROBLEM={problem_name} FORCE=1
```

## Test Reproducibility Verification

Use this same workflow when CI tests fail due to reproducibility issues:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-test-reproducibility.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
fi

- name: Check test case count
run: poetry run python .templates/check_test_cases.py --threshold=10 --max=100
run: poetry run python -m leetcode_py.tools.check_test_cases --threshold=10 --max=none

- name: Backup existing problems
run: |
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/ci-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ jobs:
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}

- name: Install dependencies
run: poetry install --no-interaction --no-ansi
run: |
poetry install --no-interaction --no-ansi
poetry run pip install -e .

- name: Cache Graphviz installation
id: cache-graphviz
Expand Down
95 changes: 0 additions & 95 deletions .templates/check_test_cases.py

This file was deleted.

26 changes: 0 additions & 26 deletions .templates/leetcode/gen.py

This file was deleted.

48 changes: 0 additions & 48 deletions .templates/leetcode/scrape.py

This file was deleted.

2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Use an LLM assistant (Cursor, GitHub Copilot Chat, Amazon Q) with the rule files

### 2. Enhance Test Cases

- Include `.amazonq/rules/test-case-enhancement.md` in your LLM context
- Include `.amazonq/rules/test-quality-assurance.md` in your LLM context
- Ask: "Enhance test cases for [problem_name] problem"

### 3. Improve Helper Classes
Expand Down
Loading