Skip to content

Commit 361f567

Browse files
authored
Merge branch 'main' into copilot/fix-24562
2 parents 6d2e428 + 79035c8 commit 361f567

File tree

171 files changed

+10373
-2794
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

171 files changed

+10373
-2794
lines changed

.github/actions/build-vsix/action.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ runs:
2222
using: 'composite'
2323
steps:
2424
- name: Install Node
25-
uses: actions/setup-node@v4
25+
uses: actions/setup-node@v6
2626
with:
2727
node-version: ${{ inputs.node_version }}
2828
cache: 'npm'
@@ -32,7 +32,7 @@ runs:
3232

3333
# Jedi LS depends on dataclasses which is not in the stdlib in Python 3.7.
3434
- name: Use Python 3.9 for JediLSP
35-
uses: actions/setup-python@v5
35+
uses: actions/setup-python@v6
3636
with:
3737
python-version: 3.9
3838
cache: 'pip'
@@ -93,7 +93,7 @@ runs:
9393
VSIX_NAME: ${{ inputs.vsix_name }}
9494

9595
- name: Upload VSIX
96-
uses: actions/upload-artifact@v4
96+
uses: actions/upload-artifact@v6
9797
with:
9898
name: ${{ inputs.artifact_name }}
9999
path: ${{ inputs.vsix_name }}

.github/actions/lint/action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ runs:
1010
using: 'composite'
1111
steps:
1212
- name: Install Node
13-
uses: actions/setup-node@v4
13+
uses: actions/setup-node@v6
1414
with:
1515
node-version: ${{ inputs.node_version }}
1616
cache: 'npm'
@@ -36,7 +36,7 @@ runs:
3636
shell: bash
3737

3838
- name: Install Python
39-
uses: actions/setup-python@v5
39+
uses: actions/setup-python@v6
4040
with:
4141
python-version: '3.x'
4242
cache: 'pip'
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
applyTo: '**'
3+
description: This document describes how to deal with learnings that you make. (meta instruction)
4+
---
5+
6+
This document describes how to deal with learnings that you make.
7+
It is a meta-instruction file.
8+
9+
Structure of learnings:
10+
11+
- Each instruction file has a "Learnings" section.
12+
- Each learning has a counter that indicates how often that learning was useful (initially 1).
13+
- Each learning has a 1 sentence description of the learning that is clear and concise.
14+
15+
Example:
16+
17+
```markdown
18+
## Learnings
19+
20+
- Prefer `const` over `let` whenever possible (1)
21+
- Avoid `any` type (3)
22+
```
23+
24+
When the user tells you "learn!", you should:
25+
26+
- extract a learning from the recent conversation
27+
_ identify the problem that you created
28+
_ identify why it was a problem
29+
_ identify how you were told to fix it/how the user fixed it
30+
_ generate only one learning (1 sentence) that helps to summarize the insight gained
31+
- then, add the reflected learning to the "Learnings" section of the most appropriate instruction file
32+
33+
Important: Whenever a learning was really useful, increase the counter!!
34+
When a learning was not useful and just caused more problems, decrease the counter.
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
---
2+
applyTo: 'python_files/tests/pytestadapter/test_discovery.py'
3+
description: 'A guide for adding new tests for pytest discovery and JSON formatting in the test_pytest_collect suite.'
4+
---
5+
6+
# How to Add New Pytest Discovery Tests
7+
8+
This guide explains how to add new tests for pytest discovery and JSON formatting in the `test_pytest_collect` suite. Follow these steps to ensure your tests are consistent and correct.
9+
10+
---
11+
12+
## 1. Add Your Test File
13+
14+
- Place your new test file/files in the appropriate subfolder under:
15+
```
16+
python_files/tests/pytestadapter/.data/
17+
```
18+
- Organize folders and files to match the structure you want to test. For example, to test nested folders, create the corresponding directory structure.
19+
- In your test file, mark each test function with a comment:
20+
```python
21+
def test_function(): # test_marker--test_function
22+
...
23+
```
24+
25+
**Root Node Matching:**
26+
27+
- The root node in your expected output must match the folder or file you pass to pytest discovery. For example, if you run discovery on a subfolder, the root `"name"`, `"path"`, and `"id_"` in your expected output should be that subfolder, not the parent `.data` folder.
28+
- Only use `.data` as the root if you are running discovery on the entire `.data` folder.
29+
30+
**Example:**
31+
If you run:
32+
33+
```python
34+
helpers.runner([os.fspath(TEST_DATA_PATH / "myfolder"), "--collect-only"])
35+
```
36+
37+
then your expected output root should be:
38+
39+
```python
40+
{
41+
"name": "myfolder",
42+
"path": os.fspath(TEST_DATA_PATH / "myfolder"),
43+
"type_": "folder",
44+
...
45+
}
46+
```
47+
48+
---
49+
50+
## 2. Update `expected_discovery_test_output.py`
51+
52+
- Open `expected_discovery_test_output.py` in the same test suite.
53+
- Add a new expected output dictionary for your test file, following the format of existing entries.
54+
- Use the helper functions and path conventions:
55+
- Use `os.fspath()` for all paths.
56+
- Use `find_test_line_number("function_name", file_path)` for the `lineno` field.
57+
- Use `get_absolute_test_id("relative_path::function_name", file_path)` for `id_` and `runID`.
58+
- Always use current path concatenation (e.g., `TEST_DATA_PATH / "your_folder" / "your_file.py"`).
59+
- Create new constants as needed to keep the code clean and maintainable.
60+
61+
**Important:**
62+
63+
- Do **not** read the entire `expected_discovery_test_output.py` file if you only need to add or reference a single constant. This file is very large; prefer searching for the relevant section or appending to the end.
64+
65+
**Example:**
66+
If you run discovery on a subfolder:
67+
68+
```python
69+
helpers.runner([os.fspath(TEST_DATA_PATH / "myfolder"), "--collect-only"])
70+
```
71+
72+
then your expected output root should be:
73+
74+
```python
75+
myfolder_path = TEST_DATA_PATH / "myfolder"
76+
my_expected_output = {
77+
"name": "myfolder",
78+
"path": os.fspath(myfolder_path),
79+
"type_": "folder",
80+
...
81+
}
82+
```
83+
84+
- Add a comment above your dictionary describing the structure, as in the existing examples.
85+
86+
---
87+
88+
## 3. Add Your Test to `test_discovery.py`
89+
90+
- In `test_discovery.py`, add your new test as a parameterized case to the main `test_pytest_collect` function. Do **not** create a standalone test function for new discovery cases.
91+
- Reference your new expected output constant from `expected_discovery_test_output.py`.
92+
93+
**Example:**
94+
95+
```python
96+
@pytest.mark.parametrize(
97+
("file", "expected_const"),
98+
[
99+
("myfolder", my_expected_output),
100+
# ... other cases ...
101+
],
102+
)
103+
def test_pytest_collect(file, expected_const):
104+
...
105+
```
106+
107+
---
108+
109+
## 4. Run and Verify
110+
111+
- Run the test suite to ensure your new test is discovered and passes.
112+
- If the test fails, check your expected output dictionary for path or structure mismatches.
113+
114+
---
115+
116+
## 5. Tips
117+
118+
- Always use the helper functions for line numbers and IDs.
119+
- Match the folder/file structure in `.data` to the expected JSON structure.
120+
- Use comments to document the expected output structure for clarity.
121+
- Ensure all `"path"` and `"id_"` fields in your expected output match exactly what pytest returns, including absolute paths and root node structure.
122+
123+
---
124+
125+
**Reference:**
126+
See `expected_discovery_test_output.py` for more examples and formatting. Use search or jump to the end of the file to avoid reading the entire file when possible.
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
---
2+
applyTo: 'python_files/**'
3+
description: Guide for running and fixing Python quality checks (Ruff and Pyright) that run in CI
4+
---
5+
6+
# Python Quality Checks — Ruff and Pyright
7+
8+
Run the same Python quality checks that run in CI. All checks target `python_files/` and use config from `python_files/pyproject.toml`.
9+
10+
## Commands
11+
12+
```bash
13+
npm run check-python # Run both Ruff and Pyright
14+
npm run check-python:ruff # Linting and formatting only
15+
npm run check-python:pyright # Type checking only
16+
```
17+
18+
## Fixing Ruff Errors
19+
20+
**Auto-fix most issues:**
21+
22+
```bash
23+
cd python_files
24+
python -m ruff check . --fix
25+
python -m ruff format
26+
npm run check-python:ruff # Verify
27+
```
28+
29+
**Manual fixes:**
30+
31+
- Ruff shows file, line number, rule code (e.g., `F841`), and description
32+
- Open the file, read the error, fix the code
33+
- Common: line length (100 char max), import sorting, unused variables
34+
35+
## Fixing Pyright Errors
36+
37+
**Common patterns and fixes:**
38+
39+
- **Undefined variable/import**: Add the missing import
40+
- **Type mismatch**: Correct the type or add type annotations
41+
- **Missing return type**: Add `-> ReturnType` to function signatures
42+
```python
43+
def my_function() -> str: # Add return type
44+
return "result"
45+
```
46+
47+
**Verify:**
48+
49+
```bash
50+
npm run check-python:pyright
51+
```
52+
53+
## Configuration
54+
55+
- **Ruff**: Line length 100, Python 3.9+, 40+ rule families (flake8, isort, pyupgrade, etc.)
56+
- **Pyright**: Version 1.1.308 (or whatever is found in the environment), ignores `lib/` and 15+ legacy files
57+
- Config: `python_files/pyproject.toml` sections `[tool.ruff]` and `[tool.pyright]`
58+
59+
## Troubleshooting
60+
61+
**"Module not found" in Pyright**: Install dependencies
62+
63+
```bash
64+
python -m pip install --upgrade -r build/test-requirements.txt
65+
nox --session install_python_libs
66+
```
67+
68+
**Import order errors**: Auto-fix with `ruff check . --fix`
69+
70+
**Type errors in ignored files**: Legacy files in `pyproject.toml` ignore list—fix if working on them
71+
72+
## When Writing Tests
73+
74+
**Always format your test files before committing:**
75+
76+
```bash
77+
cd python_files
78+
ruff format tests/ # Format all test files
79+
# or format specific files:
80+
ruff format tests/unittestadapter/test_utils.py
81+
```
82+
83+
**Best practice workflow:**
84+
85+
1. Write your test code
86+
2. Run `ruff format` on the test files
87+
3. Run the tests to verify they pass
88+
4. Run `npm run check-python` to catch any remaining issues
89+
90+
This ensures your tests pass both functional checks and quality checks in CI.
91+
92+
## Learnings
93+
94+
- Always run `npm run check-python` before pushing to catch CI failures early (1)
95+
- Use `ruff check . --fix` to auto-fix most linting issues before manual review (1)
96+
- Pyright version must match CI (1.1.308) to avoid inconsistent results between local and CI runs (1)
97+
- Always run `ruff format` on test files after writing them to avoid formatting CI failures (1)

0 commit comments

Comments
 (0)