caspian-utils 0.1.20 → 0.1.22
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/docs/index.md +1 -1
- package/dist/docs/installation.md +2 -3
- package/dist/docs/testing.md +29 -20
- package/package.json +1 -1
package/dist/docs/index.md
CHANGED
|
@@ -95,7 +95,7 @@ The packaged Caspian docs referenced by this index live here:
|
|
|
95
95
|
- `metadata.md` - Static and dynamic metadata, SEO inheritance, and Open Graph or Twitter card tags
|
|
96
96
|
- `routing.md` - Next.js App Router-style file-based routing with `src/app`, dynamic segments, dashboard and section layouts, route groups, nested layouts, shared-shell scroll-reset ownership, single-parent authored templates, and backend Python companions that do not own visible markup
|
|
97
97
|
- `project-structure.md` - Default Caspian layout and where route files, reusable UI in `src/components/`, reusable non-UI code in `src/lib/`, and database files belong
|
|
98
|
-
- `testing.md` - Recommended app-owned testing, type-checking, and linting gate over `main.py` and `src/**` (
|
|
98
|
+
- `testing.md` - Recommended app-owned testing, type-checking, and linting gate over `main.py` and `src/**` (pyright + ruff + pytest behind one command, so the gate and Pylance in the editor report the same thing), plus the auto-fix command and why ruff must not auto-delete component imports used as `<x-*>` tags (F401 unfixable); not a shipped feature and not gated by a `caspian.config.json` flag, so verify the actual command, tools, and config in the project
|
|
99
99
|
|
|
100
100
|
## AI Retrieval Notes
|
|
101
101
|
|
|
@@ -68,9 +68,8 @@ If the project enables MCP, use `mcp.md` after scaffold to place the app-owned F
|
|
|
68
68
|
For the best development experience, use these VS Code extensions:
|
|
69
69
|
|
|
70
70
|
- [Caspian Official Framework Support](https://marketplace.visualstudio.com/items?itemName=JeffersonAbrahamOmier.caspian)
|
|
71
|
-
- [Python](https://marketplace.visualstudio.com/items?itemName=ms-python.python)
|
|
72
|
-
- [Pyright](https://marketplace.visualstudio.com/items?itemName=ms-pyright.pyright)
|
|
73
|
-
- [Pyrefly](https://marketplace.visualstudio.com/items?itemName=tamasfe.pyrefly)
|
|
71
|
+
- [Python](https://marketplace.visualstudio.com/items?itemName=ms-python.python) — ships [Pylance](https://marketplace.visualstudio.com/items?itemName=ms-python.vscode-pylance) as the default language server, which is Pyright under the hood and therefore agrees with the `npm run check` gate (recommended).
|
|
72
|
+
- [Pyright](https://marketplace.visualstudio.com/items?itemName=ms-pyright.pyright) — optional if you want the standalone Pyright server and CLI on top of Pylance; otherwise Pylance already covers editor parity.
|
|
74
73
|
- [Prisma](https://marketplace.visualstudio.com/items?itemName=Prisma.prisma)
|
|
75
74
|
- [Tailwind CSS IntelliSense](https://marketplace.visualstudio.com/items?itemName=bradlc.vscode-tailwindcss)
|
|
76
75
|
|
package/dist/docs/testing.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: Testing And Quality Gate
|
|
3
|
-
description: Use this page when the task mentions tests, pytest, type checking,
|
|
3
|
+
description: Use this page when the task mentions tests, pytest, type checking, pyright, linting, ruff, auto-fixing lint (ruff --fix / check:fix), unused-import (F401) removal, a quality gate, CI checks, or "make the code production-ready" for a Caspian app's own Python. Explains the recommended one-command gate over `main.py` and `src/**`, and why ruff must not auto-delete component imports used as `<x-*>` tags.
|
|
4
4
|
related:
|
|
5
5
|
title: Related docs
|
|
6
6
|
description: Pair the quality gate with the runtime map when a failing check points into core files, and with the structure and command docs when deciding where tests and tooling belong.
|
|
@@ -26,11 +26,11 @@ Caspian does not ship a test runner, type checker, or linter. Quality tooling is
|
|
|
26
26
|
|
|
27
27
|
Expose a single gate command so an agent or CI has exactly one thing to run. The recommended command runs three tools in one pass and reports every problem with its exact location:
|
|
28
28
|
|
|
29
|
-
- **type check** — [
|
|
29
|
+
- **type check** — [pyright](https://github.com/microsoft/pyright) over `main.py` and `src/**` (Pylance, the default VS Code Python language server, is Pyright under the hood and reads the same `[tool.pyright]` config, so the editor and `npm run check` report the same thing)
|
|
30
30
|
- **lint** — [ruff](https://docs.astral.sh/ruff/)
|
|
31
31
|
- **tests** — [pytest](https://docs.pytest.org)
|
|
32
32
|
|
|
33
|
-
The command should print each problem as `path:line:col [tool:code] message` and exit non-zero when any check fails, so the file and line to fix are always explicit. Prefer a single `npm run check` script (backed by an app-owned orchestrator such as `settings/check.py`) over separate `test` / `lint` / `typecheck` scripts, so the surface stays minimal. Keep a per-tool escape hatch (for example `--only
|
|
33
|
+
The command should print each problem as `path:line:col [tool:code] message` and exit non-zero when any check fails, so the file and line to fix are always explicit. Prefer a single `npm run check` script (backed by an app-owned orchestrator such as `settings/check.py`) over separate `test` / `lint` / `typecheck` scripts, so the surface stays minimal. Keep a per-tool escape hatch (for example `--only pyright`) for debugging rather than as additional npm scripts.
|
|
34
34
|
|
|
35
35
|
## Source Of Truth
|
|
36
36
|
|
|
@@ -57,7 +57,7 @@ Keep the dev tooling in a dependency group and install it with `uv sync --group
|
|
|
57
57
|
```toml
|
|
58
58
|
[dependency-groups]
|
|
59
59
|
dev = [
|
|
60
|
-
"
|
|
60
|
+
"pyright>=1.1",
|
|
61
61
|
"ruff>=0.6",
|
|
62
62
|
"pytest>=8.0",
|
|
63
63
|
]
|
|
@@ -75,26 +75,33 @@ extend-exclude = [".venv", "node_modules"]
|
|
|
75
75
|
select = ["E", "F", "W"]
|
|
76
76
|
ignore = ["E501"]
|
|
77
77
|
|
|
78
|
-
[tool.
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
[tool.pyright]
|
|
79
|
+
# Pylance (the VS Code Python extension) reads this same config, so the editor
|
|
80
|
+
# and `npm run check` report the same thing instead of disagreeing.
|
|
81
|
+
include = ["main.py", "src"]
|
|
82
|
+
exclude = [".venv", "node_modules", "**/__pycache__"]
|
|
83
|
+
# `basic` is Pylance's default mode. It catches reportArgumentType-style bugs
|
|
84
|
+
# (e.g. passing a dict[str, str | None] to a TypedDict whose field is `str`)
|
|
85
|
+
# without flooding the gate with strict-mode noise. Subject the generated Prisma
|
|
86
|
+
# Python ORM under `src/lib/prisma/**` to its own exclusion so its
|
|
87
|
+
# Optional-everywhere models do not dominate the gate.
|
|
88
|
+
pythonPlatform = "Windows" # or Linux/Darwin to match the deploy target
|
|
89
|
+
typeCheckingMode = "basic"
|
|
90
|
+
# Mirror suppressions from older pyrefly-based setups if you migrated; otherwise
|
|
91
|
+
# leave these out. Re-enable per-rule when tightening.
|
|
92
|
+
# reportReturnType = "none"
|
|
93
|
+
# reportAssignmentType = "none"
|
|
81
94
|
```
|
|
82
95
|
|
|
83
96
|
## Auto-Fixing, And Why Ruff Must Not Delete Component Imports
|
|
84
97
|
|
|
85
|
-
The gate only **reports**. Ruff can also **fix** many lint findings in place, so a second command is worth exposing alongside the gate — recommended `npm run check:fix`, backed by
|
|
98
|
+
The gate only **reports**. Ruff can also **fix** many lint findings in place, so a second command is worth exposing alongside the gate — recommended `npm run check:fix`, backed by a small orchestrator (for example `settings/fix.py`) that applies safe fixes and then re-runs the gate to print the authoritative report of what is left. Type errors (pyright) and failing tests (pytest) are never auto-fixed.
|
|
86
99
|
|
|
87
|
-
|
|
88
|
-
ruff check . --fix-only && <the gate command>
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
Use `--fix-only` (not `--fix`): plain `--fix` exits non-zero whenever unfixable findings remain, which would stop the `&&` from ever reaching the gate. `--fix-only` applies the available fixes, exits `0`, and lets the gate re-run and print the authoritative report of what is left. Type errors (pyrefly) and failing tests (pytest) are never auto-fixed.
|
|
100
|
+
**Hazard — unused-import autofix (`F401`) breaks single-file components.** A single-file component imports its children and then uses them **only** as `<x-*>` tags inside an `html(...)` / `render_html(...)` template string, for example `from .Dialog import DialogContent` used as `<x-dialog-content>`. Ruff parses Python, not the template string, so it reports the import as unused (`F401`) and `--fix` would delete it. That import is load-bearing: Caspian resolves the tag from the **module's globals at render time** (see `component_decorator._attach_caller_scope`, which scans the caller module for `Component` instances). Deleting it breaks rendering at runtime, silently. This affects any component file, so it cannot be scoped by path — but it also must not disable dead-import cleanup for ordinary Python.
|
|
92
101
|
|
|
93
|
-
|
|
102
|
+
Handle it in three layers, all generic:
|
|
94
103
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
1. **Never auto-delete imports.** Mark `F401` unfixable so `--fix`/`--fix-only` reports but never strips it, project-wide:
|
|
104
|
+
1. **Never let a raw `ruff check --fix` delete an import.** Mark `F401` unfixable so ruff reports but never strips it, project-wide — this protects anyone who runs ruff directly:
|
|
98
105
|
|
|
99
106
|
```toml
|
|
100
107
|
[tool.ruff.lint]
|
|
@@ -103,15 +110,17 @@ Handle it in two layers, both generic:
|
|
|
103
110
|
unfixable = ["F401"]
|
|
104
111
|
```
|
|
105
112
|
|
|
106
|
-
2. **
|
|
113
|
+
2. **Let the fixer still clean genuinely dead imports.** The `check:fix` orchestrator lists `F401` findings under the project config, marks any file that contains an import used as an `<x-*>` tag as *component-guarded*, and removes dead imports only from the **non-guarded** files. Because the project config makes `F401` unfixable, re-enable removal for that step with an **isolated** ruff run scoped to those exact files: `ruff check <files> --select F401 --fix-only --isolated` (`--isolated` ignores the project config so `F401` is fixable again; passing explicit files keeps include/exclude moot). Guarded files are skipped whole and left for the gate to report, so a load-bearing import is never at risk.
|
|
114
|
+
|
|
115
|
+
3. **Keep the gate honest.** In the orchestrator (`settings/check.py`), drop the `F401` findings whose bound symbol is actually used as an `<x-*>` tag in the same file, and keep the rest — so the gate still fails on genuinely dead imports. Derive the tag exactly as the compiler does: `x-{camel_to_kebab(import_name)}` (mirror `casp.string_helpers.camel_to_kebab`; e.g. `DialogContent` → `<x-dialog-content`). Pull the symbol from the ruff JSON message (`` `.Dialog.DialogContent` imported but unused`` → last dotted segment, or the alias after ` as `), then match `<x-dialog-content` on a tag boundary in the file source. Share this detection between the fixer and the gate in one module (for example `settings/_component_imports.py`).
|
|
107
116
|
|
|
108
|
-
**Working rule:** when the gate reports an `F401
|
|
117
|
+
**Working rule:** when the gate reports an `F401` in a component-guarded file, remove that import by hand only after confirming it is not used as an `<x-*>` tag anywhere in the same file. Do not blanket-ignore `F401` or re-enable its autofix globally — it cannot see template usage.
|
|
109
118
|
|
|
110
119
|
## Things To Verify Before Editing Or Explaining
|
|
111
120
|
|
|
112
121
|
- Confirm the gate command name and orchestrator path in `package.json` and `settings/`, since they are app-owned and may differ per project.
|
|
113
122
|
- Confirm the dev tools are actually installed (`[dependency-groups]` in `pyproject.toml`, resolved in `uv.lock`) before telling a user to run the gate.
|
|
114
|
-
- Check `[tool.
|
|
123
|
+
- Check `[tool.pyright]` in `pyproject.toml`. A project may set `typeCheckingMode = "basic"` (Pylance's default, recommended) and individually silence rules with `reportReturnType = "none"` / `reportAssignmentType = "none"` (commonly done to mirror older pyrefly-based setups). Any rule silenced there is then not reported by the gate, so do not assume every annotation mismatch is caught. Pylance in the editor reads this same config, so the IDE and `npm run check` agree.
|
|
115
124
|
- Keep the scope on app code. If a check points into `.venv/Lib/site-packages/casp/**`, use [core-runtime-map.md](./core-runtime-map.md) to understand the runtime, but do not add framework files to the app's test, lint, or type-check scope.
|
|
116
125
|
|
|
117
126
|
## Working Rule For Agents
|