Skip to content

Commit 3a6884a

Browse files
authored
Merge pull request #22 from G4brym/upgrade-workers-compat
Upgrade workers compat
2 parents cf3038c + 71da410 commit 3a6884a

Some content is hidden

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

63 files changed

+1850
-1884
lines changed

.github/dependabot.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "npm"
4+
directories:
5+
- "/pnpm-lock.yaml"
6+
- "/packages/worker"
7+
- "/packages/worker/dev"
8+
- "/packages/github-action"
9+
schedule:
10+
interval: "weekly"
11+
groups:
12+
prod-deps:
13+
dependency-type: "production"
14+
dev-deps:
15+
dependency-type: "development"
16+
- package-ecosystem: "github-actions"
17+
directory: "/"
18+
schedule:
19+
interval: "weekly"

.github/workflows/ci.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
runs-on: ubuntu-latest
88
strategy:
99
matrix:
10-
python-version: ["3.11", "3.12"]
10+
python-version: ["3.12"]
1111

1212
steps:
1313
- name: Check out code
@@ -26,6 +26,9 @@ jobs:
2626
- name: Install pnpm
2727
run: npm install -g pnpm
2828

29+
- name: Install uv
30+
run: pip install uv
31+
2932
- name: Install dependencies
3033
run: pnpm install
3134

AGENTS.md

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,23 @@ This document provides guidance for AI agents working on the `django-cf` reposit
44

55
### Project Overview
66

7-
`django-cf` is a Django application designed to run on Cloudflare Workers. It utilizes Cloudflare D1 for its database and Durable Objects for stateful operations. The core of this example project is located in `templates/durable-objects/`.
7+
`django-cf` is a Python package that integrates Django with Cloudflare services. It provides database backends for Cloudflare D1 and Durable Objects, plus middleware for Cloudflare Access authentication. Two complete example projects are provided in the `templates/` directory: one using D1 and one using Durable Objects.
88

99
### Running Tests
1010

11-
The project uses `pnpm` for managing Node.js dependencies and running scripts. The test execution process is defined in `.github/workflows/ci.yml` and can be replicated locally as follows:
11+
The project uses `npm` for Node.js dependencies and `uv` for Python dependencies. The test execution process is defined in `.github/workflows/ci.yml` and can be replicated locally as follows:
1212

13-
1. **Install pnpm**: If you don't have pnpm installed, you can install it globally using npm:
13+
1. **Install Dependencies**: Navigate to the project root and run:
1414
```bash
15-
npm install -g pnpm
15+
npm install
16+
uv sync
1617
```
17-
2. **Install Project Dependencies**: Navigate to the project root and run:
18+
This installs both Node.js and Python dependencies required for the project.
19+
2. **Run Tests**: Execute the tests using:
1820
```bash
19-
pnpm install
21+
pytest
2022
```
21-
This command installs both Node.js and Python dependencies required for the project, including those for the worker in `templates/durable-objects/`.
22-
3. **Set up Tests**: Run the test setup script:
23-
```bash
24-
pnpm run setup-test
25-
```
26-
This script typically handles tasks like installing Python development dependencies (e.g., `pytest`, Django) and setting up the Django environment within the worker.
27-
4. **Run Tests**: Execute the tests using:
28-
```bash
29-
pnpm run test
30-
```
31-
This command will execute `pytest` which, in turn, uses the `WorkerFixture` in `tests/test_worker.py`. The fixture manages the Cloudflare worker lifecycle (starting `wrangler dev`) for the integration tests.
23+
This command will execute `pytest` which uses the `WorkerFixture` in `tests/test_worker.py`. The fixture manages the Cloudflare worker lifecycle (starting `wrangler dev`) for the integration tests.
3224

3325
**Test Structure Details**:
3426
* Integration tests are located in the `tests/` directory. This directory must contain an `__init__.py` file to be treated as a package.
@@ -44,37 +36,48 @@ The project uses `pnpm` for managing Node.js dependencies and running scripts. T
4436

4537
### Key Files and Directories
4638

47-
* `pyproject.toml`: Defines project metadata, Python dependencies, and build settings for the wrapper/library aspects.
39+
* `pyproject.toml`: Defines project metadata, Python dependencies, and build settings.
4840
* `AGENTS.md`: This file.
49-
* `templates/durable-objects/`: Contains the actual Django application deployed to Cloudflare.
50-
* `package.json`: Node.js dependencies for the worker, including `wrangler`.
51-
* `wrangler.toml` (or `wrangler.jsonc`): Wrangler configuration file.
52-
* `src/worker.py`: Python entry point for the worker, using `django-cf` library components.
53-
* `src/app/`: Standard Django project directory.
54-
* `settings.py`: Django settings.
55-
* `urls.py`: Django URL configurations, including admin and management endpoints.
41+
* `django_cf/`: Main package containing database backends and middleware.
42+
* `db/backends/d1/`: D1 database backend implementation.
43+
* `db/backends/do/`: Durable Objects database backend implementation.
44+
* `middleware/`: Cloudflare Access authentication middleware.
45+
* `templates/d1/`: Complete Django example using D1 database.
46+
* `package.json`: Node.js dependencies and npm scripts (`dev`, `deploy`).
47+
* `wrangler.jsonc`: Wrangler configuration.
48+
* `pyproject.toml`: Python project configuration.
49+
* `src/index.py`: Worker entrypoint.
50+
* `src/app/`: Django project directory.
51+
* `templates/durable-objects/`: Complete Django example using Durable Objects.
52+
* `package.json`: Node.js dependencies and npm scripts (`dev`, `deploy`).
53+
* `wrangler.jsonc`: Wrangler configuration.
54+
* `pyproject.toml`: Python project configuration.
55+
* `src/index.py`: Worker entrypoint.
56+
* `src/app/`: Django project directory.
5657
* `tests/`: Contains integration tests.
5758
* `__init__.py`: Makes `tests/` a Python package.
58-
* `test_worker.py`: Defines the worker fixture and basic setup tests (migrations, admin creation).
59-
* `test_admin.py`: Contains tests for the Django admin interface (login, logout, etc.).
59+
* `test_worker.py`: Defines the worker fixture and basic setup tests.
60+
* `test_admin.py`: Contains tests for the Django admin interface.
6061

6162
### Workflow for Future Agents
6263

63-
1. **Understand the Setup**: The Django app runs inside a Cloudflare Worker, managed by Wrangler. Tests interact with this via HTTP.
64-
2. **Dependencies First**: Always ensure both Python (`pip install -e .[dev]`) and Node (`npm install` in the root and `templates/durable-objects/`) dependencies are up to date.
65-
3. **Write Tests**: For new Django views or functionalities within `templates/durable-objects/src/app/`, add corresponding integration tests in the `tests/` directory.
66-
4. **Run Tests**: Execute `pytest` to verify changes. Debug any worker startup issues by examining output from the `WorkerFixture`.
67-
5. **Update AGENTS.md**: If you make significant changes to the testing process, dependency management, or project structure, update this document.
64+
1. **Understand the Setup**: The `django-cf` package provides backends and middleware for Django on Cloudflare Workers. Two complete templates are provided for reference.
65+
2. **Dependencies First**: Always ensure both Python (`uv sync`) and Node (`npm install`) dependencies are up to date.
66+
3. **Database Backends**: The package supports D1 (via `django_cf.db.backends.d1`) and Durable Objects (via `django_cf.db.backends.do`).
67+
4. **Write Tests**: For new features, add corresponding integration tests in the `tests/` directory.
68+
5. **Run Tests**: Execute `pytest` to verify changes. Debug any worker startup issues by examining output from the `WorkerFixture`.
69+
6. **Update AGENTS.md**: If you make significant changes to the testing process, dependency management, or project structure, update this document.
6870

6971
### Troubleshooting Tests
7072

7173
* **`worker failed to start`**:
7274
* Check the `stdout` and `stderr` printed by the test fixture for errors from `wrangler dev`.
73-
* Ensure `npm install` completed successfully in `templates/durable-objects/`.
75+
* Ensure `npm install` and `uv sync` completed successfully.
7476
* Verify that the port selected by `get_free_port()` is indeed available.
7577
* **`ImportError: attempted relative import with no known parent package`**: Ensure `tests/__init__.py` exists.
76-
* **`no tests ran` when running `pytest`**: Ensure you are running `pytest` from the root directory of the project. If you are in a subdirectory (e.g., `templates/durable-objects/`), `pytest` might not discover the tests in the `tests/` directory. Running `pytest tests/` from the root should correctly discover and run the tests.
78+
* **`no tests ran` when running `pytest`**: Ensure you are running `pytest` from the root directory of the project. If you are in a subdirectory (e.g., `templates/d1/` or `templates/durable-objects/`), `pytest` might not discover the tests in the `tests/` directory. Running `pytest tests/` from the root should correctly discover and run the tests.
7779
* **CSRF token issues**: The `get_csrf_token` helper in `tests/test_admin.py` is a basic string parser. If Django admin templates change significantly, this helper might need updating (e.g., to use a proper HTML parser).
80+
* **Database backend issues**: Remember that both D1 and Durable Objects have transactions disabled. All queries are committed immediately with no rollback capability.
7881
7982
### Continuous Integration
8083

0 commit comments

Comments
 (0)