Skip to content

Commit 29ddd58

Browse files
committed
docs: update instructions for python, pytest, and react router
Generated-by: aiautocommit
1 parent 36402b7 commit 29ddd58

6 files changed

Lines changed: 227 additions & 92 deletions

.github/copilot-instructions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ session_id = client_secret_id.split("_secret")[0]
3434

3535
### Agent instructions
3636

37-
- When running python tests, use an already open terminal and the `pytest` binary.
37+
- Run python tests with `pytest` only. If tests fail because of a configuration or system error, do not attempt to fix and let me know. I will fix it.
3838
- If you added models, generate a migration with `just migration {add,delete,update}_model_other_description`

.github/instructions/pytest-integration-tests.instructions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ applyTo: "tests/integration/**/*.py"
44
## Pytest Integration Tests
55

66
- Look to tests/factories.py to generate any required database state
7-
- Here's an example of how to create + persist a factory `DistributionFactory.save()`
7+
- Here's an example of how to create + persist a factory `DistributionFactory.build(domain=PYTHON_TEST_SERVER_HOST).save()`
88
- Add the `server` factory to each test
99
- Use the `faker` factory to generate emails, etc.
1010
- Don't add obvious `assert` descriptions

.github/instructions/python.instructions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ When writing Python:
1616
* No variable interpolation in log messages.
1717
* Do not coerce database IDs or dates to strings
1818
* Do not fix import ordering or other formatting issues.
19+
* Do not ever edit any files in `migrations/versions/`
1920

2021
### Date & DateTime
2122

.github/instructions/react-router.instructions.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ applyTo: "web/app/routes/**/*.tsx"
44
## React Router
55

66
- You are using the latest version of React Router (v7).
7+
- Always include the suffix `Page` when naming the default export of a route.
78
- The primary export in a routes file should specify `loaderData` like `export default function RouteNamePage({ loaderData }: Route.ComponentProps)`. `loaderData` is the return value from `clientLoader`.
89
- Use `href("/products/:id", { id: "abc123" })` to generate a url path for a route managed by the application.
910
- Look at [routes.ts](mdc:web/app/routes.ts) to determine what routes and path parameters exist.
@@ -43,7 +44,7 @@ export async function clientLoader(loaderArgs: Route.ClientLoaderArgs) {
4344
}
4445
```
4546

46-
### How to use clientLoader
47+
### How to Use `clientLoader`
4748

4849
- `export async function clientLoader(loaderArgs: Route.ClientLoaderArgs) {`
4950
- Load any server data required for page load here, not in the component function.
@@ -53,10 +54,38 @@ export async function clientLoader(loaderArgs: Route.ClientLoaderArgs) {
5354
- `loaderArgs` and all sub-objects are all fully typed
5455
- `loaderArgs.params.id` to get URL parameters
5556

56-
### Using API Data
57+
### Loading Backend Data
5758

5859
- `~/configuration/client` re-exports all types and functions from `client/*`. Import from `~/configuration/client` instead of anything you find in the `client/` folder/package.
5960
- For each API endpoint, there's a fully typed async function that can be used to call it. Never attempt to call an API endpoint directly.
61+
- Do not generate types for API parameters or responses. Reference the autogenerated types that are re-exported in `~/configuration/client`
62+
- For instance, the `getSignedUrl` function in [web/client/sdk.gen.ts] has a `SignedUrlResponse` type in [web/client/types.gen.ts]
63+
- This same type is used in the function signature, i.e. `type SignedUrlResponse = Awaited<ReturnType<typeof getSignedUrl>>["data"]`
64+
6065
- When using an import from `~/configuration/client`:
6166
- use `body:` for request params
6267
- always `const { data, error } = await theCall()`
68+
69+
`clientLoader` can only be used on initial page load within a route. If you need to load additional server data on component mount:
70+
71+
```tsx
72+
import { useQuery } from "@tanstack/react-query"
73+
import {
74+
// these options correspond to the server route
75+
createCheckoutSessionOptions,
76+
publicClient,
77+
} from "~/configuration/client"
78+
79+
function TheComponent() {
80+
const { data, error } = useQuery({
81+
enabled: open,
82+
...createCheckoutSessionOptions({
83+
// or `client` if authenticated
84+
client: publicClient,
85+
body: { /* API parameters here */ },
86+
}),
87+
})
88+
89+
// remember to display errors by checking `error`
90+
}
91+
```

.github/instructions/typescript.instructions.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ applyTo: "**/*.ts,**/*.tsx"
88
- Use `lib/` for generic code, `utils/` for project utilities, `hooks/` for React hooks, and `helpers/` for page-specific helpers.
99
- Prefer `function theName() {` over `const theName = () =>`
1010
- Use `import { invariant } from @epic-web/invariant` instead of another invariant library
11+
- Use `requireEnv("VITE_THE_ENV_VAR")` instead of `process.env.THE_ENV_VAR`
1112

1213
Here's how frontend code is organized in `web/app/`:
1314

0 commit comments

Comments
 (0)