Skip to content

Commit 5db9958

Browse files
committed
Added repo cursor rules and other docs for AI
1 parent 70ff5de commit 5db9958

File tree

7 files changed

+142
-23
lines changed

7 files changed

+142
-23
lines changed

.cursor/rules/executing-commands.mdc

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,19 @@ alwaysApply: true
66
Almost all commands in the monorepo should be executed when `pnpm run ...` from the root of the monorepo. For example, running tests for the `@internal/run-engine` internal package:
77

88
```
9-
pnpm run test --filter @internal/run-engine
10-
```
9+
pnpm run dev --filter webapp
10+
```
11+
12+
But often, when running tests, it's better to `cd` into the directory and then run tests:
13+
14+
```
15+
cd apps/webapp
16+
pnpm run test
17+
```
18+
19+
This way you can run for a single file easily:
20+
21+
```
22+
cd internal-packages/run-engine
23+
pnpm run test ./src/engine/tests/ttl.test.ts
24+
```

.cursor/rules/repo.mdc

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,4 @@ description: understanding the structure of the monorepo
33
globs:
44
alwaysApply: true
55
---
6-
This is a pnpm 8.15.5 monorepo that uses turborepo [turbo.json](mdc:turbo.json). The following workspaces are relevant:
7-
8-
- <root>/apps/webapp is a remix app that is the main API and dashboard for trigger.dev
9-
- <root>/packages/trigger-sdk is the `@trigger.dev/sdk` main SDK package
10-
- <root>/packages/cli-v3 is the `trigger.dev` CLI package
11-
- <root>/packages/core is the `@trigger.dev/core` package that is shared across the SDK and other packages
12-
- <root>/packages/build defines the types and prebuilt build extensions for trigger.dev
13-
- <root>/packages/react-hooks defines some useful react hooks like our realtime hooks
14-
- <root>/internal-packages/* are packages that are used internally only, not published, and usually they have a tsc build step and are used in the webapp
15-
- <root>/references/* are test workspaces that we use to write and test the system. Not quite e2e tests or automated, but just a useful place to help develop new features
16-
- <root>/docs is our trigger.dev/docs mintlify documentation site
17-
18-
Other things in the monorepo to note:
19-
20-
The [Dockerfile](mdc:docker/Dockerfile) is the one that creates the main trigger.dev published image, and the [docker-compose.yml](mdc:docker/docker-compose.yml) is the file we run locally to start postgresql, redis, and electric when we are doing local development. The [CONTRIBUTING.md](mdc:CONTRIBUTING.md) file defines the steps it takes for OSS contributors to start contributing.
6+
We've documented the structure of our monorepo here: [repo.md](mdc:ai/references/repo.md)

.cursor/rules/webapp.mdc

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,34 @@ globs: apps/webapp/**/*.tsx,apps/webapp/**/*.ts
44
alwaysApply: false
55
---
66

7-
# Your rule content
8-
97
The main trigger.dev webapp, which powers it's API and dashboard and makes up the docker image that is produced as an OSS image, is a Remix 2.1.0 app that uses an express server, written in TypeScript. The following subsystems are either included in the webapp or are used by the webapp in another part of the monorepo:
108

119
- `@trigger.dev/database` exports a Prisma 5.4.1 client that is used extensively in the webapp to access a PostgreSQL instance. The schema file is [schema.prisma](mdc:internal-packages/database/prisma/schema.prisma)
1210
- `@trigger.dev/core` is a published package and is used to share code between the `@trigger.dev/sdk` and the webapp. It includes functionality but also a load of Zod schemas for data validation. When importing from `@trigger.dev/core` in the webapp, we never import the root `@trigger.dev/core` path, instead we favor one of the subpath exports that you can find in [package.json](mdc:packages/core/package.json)
11+
- `@internal/run-engine` has all the code needed to trigger a run and take it through it's lifecycle to completion.
12+
- `@internal/redis-worker` is a custom redis based background job/worker system that's used in the webapp and also used inside the run engine.
13+
14+
## Environment variables and testing
15+
16+
In the webapp, all environment variables are accessed through the `env` export of [env.server.ts](mdc:apps/webapp/app/env.server.ts), instead of directly accessing `process.env`.
17+
18+
Ideally, the `env.server.ts` file would never be imported into a test file, either directly or indirectly. Tests should only imported classes and functions from a file matching `app/**/*.ts` of the webapp, and that file should not use environment variables, everything should be passed through as options instead. This "service/configuration" separation is important, and can be seen in a few places in the code for examples:
19+
20+
- [realtimeClient.server.ts](mdc:apps/webapp/app/services/realtimeClient.server.ts) is the testable service, and [realtimeClientGlobal.server.ts](mdc:apps/webapp/app/services/realtimeClientGlobal.server.ts) is the configuration
21+
22+
Also for writing tests in the webapp, checkout our [tests.md](mdc:ai/references/tests.md) guide
23+
24+
## Legacy run engine vs Run Engine 2.0
25+
26+
We originally the Trigger.dev "Run Engine" not as a single system, but just spread out all over the codebase, with no real separate or encapsulation. And we didn't even call it a "Run Engine". With Run Engine 2.0, we've completely rewritten big parts of the way the system works, and moved it over to an internal package called `@internal/run-engine`. So we've retroactively named the previous run engine "Legacy run engine". We're focused almost exclusively now on moving to Run Engine 2.0 and will be deprecating and removing the legacy run engine code eventually.
27+
28+
## Where to look for code
29+
30+
- The trigger API endpoint is [api.v1.tasks.$taskId.trigger.ts](mdc:apps/webapp/app/routes/api.v1.tasks.$taskId.trigger.ts)
31+
- The batch trigger API endpoint is [api.v1.tasks.batch.ts](mdc:apps/webapp/app/routes/api.v1.tasks.batch.ts)
32+
- Setup code for the prisma client is in [db.server.ts](mdc:apps/webapp/app/db.server.ts)
33+
- The run engine is configured in [runEngine.server.ts](mdc:apps/webapp/app/v3/runEngine.server.ts)
34+
- All the "services" that are found in app/v3/services/**/*.server.ts
35+
- The code for the TaskEvent data, which is the otel data sent from tasks to our servers, is in both the [eventRepository.server.ts](mdc:apps/webapp/app/v3/eventRepository.server.ts) and also the [otlpExporter.server.ts](mdc:apps/webapp/app/v3/otlpExporter.server.ts). The otel endpoints which are hit from production and development otel exporters is [otel.v1.logs.ts](mdc:apps/webapp/app/routes/otel.v1.logs.ts) and [otel.v1.traces.ts](mdc:apps/webapp/app/routes/otel.v1.traces.ts)
36+
- We use "presenters" to move more complex loader code into a class, and you can find those are app/v3/presenters/**/*.server.ts
37+

.cursor/rules/writing-tests.mdc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
description: How to write tests in the monorepo
3+
globs:
4+
alwaysApply: true
5+
---
6+
Follow our [tests.md](mdc:ai/references/tests.md) guide for how to write tests in the monorepo.

.cursorignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
# Add directories or file patterns to ignore during indexing (e.g. foo/ or *.csv)
1+
apps/docker-provider/
2+
apps/kubernetes-provider/
3+
apps/proxy/
4+
apps/coordinator/
5+
packages/rsc/
6+
.changeset
7+
.zed

ai/references/repo.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
## Repo Overview
2+
3+
This is a pnpm 8.15.5 monorepo that uses turborepo @turbo.json. The following workspaces are relevant
4+
5+
## Apps
6+
7+
- <root>/apps/webapp is a remix app that is the main API and dashboard for trigger.dev
8+
- <root>/apps/supervisor is a node.js app that handles the execution of built tasks, interaction with the webapp through internal "engine" APIs, as well as interfacing with things like docker or kubernetes, to execute the code.
9+
10+
## Public Packages
11+
12+
- <root>/packages/trigger-sdk is the `@trigger.dev/sdk` main SDK package.
13+
- <root>/packages/cli-v3 is the `trigger.dev` CLI package. See our [CLI dev command](https://trigger.dev/docs/cli-dev.md) and [Deployment](https://trigger.dev/docs/deployment/overview.md) docs for more information.
14+
- <root>/packages/core is the `@trigger.dev/core` package that is shared across the SDK and other packages
15+
- <root>/packages/build defines the types and prebuilt build extensions for trigger.dev. See our [build extensions docs](https://trigger.dev/docs/config/extensions/overview.md) for more information.
16+
- <root>/packages/react-hooks defines some useful react hooks like our realtime hooks. See our [Realtime hooks](https://trigger.dev/docs/frontend/react-hooks/realtime.md) and our [Trigger hooks](https://trigger.dev/docs/frontend/react-hooks/triggering.md) for more information.
17+
18+
## Internal Packages
19+
20+
- <root>/internal-packages/\* are packages that are used internally only, not published, and usually they have a tsc build step and are used in the webapp
21+
- <root>/internal-packages/database is the `@trigger.dev/database` package that exports a prisma client, has the schema file, and exports a few other helpers.
22+
- <root>/internal-packages/run-engine is the `@internal/run-engine` package that is "Run Engine 2.0" and handles moving a run all the way through it's lifecycle
23+
- <root>/internal-packages/redis-worker is the `@internal/redis-worker` package that implements a custom background job/worker sytem powered by redis for offloading work to the background, used in the webapp and also in the Run Engine 2.0.
24+
- <root>/internal-packages/redis is the `@internal/redis` package that exports Redis types and the `createRedisClient` function to unify how we create redis clients in the repo. It's not used everywhere yet, but it's the preferred way to create redis clients from now on.
25+
- <root>/internal-packages/testcontainers is the `@internal/testcontainers` package that exports a few useful functions for spinning up local testcontainers when writing vitest tests. See our [tests.md](./tests.md) file for more information.
26+
- <root>/internal-packages/zodworker is the `@internal/zodworker` package that implements a wrapper around graphile-worker that allows us to use zod to validate our background jobs. We are moving away from using graphile-worker as our background job system, replacing it with our own redis-worker package.
27+
28+
## References
29+
30+
- <root>/references/\* are test workspaces that we use to write and test the system. Not quite e2e tests or automated, but just a useful place to help develop new features
31+
32+
## Other
33+
34+
- <root>/docs is our trigger.dev/docs mintlify documentation site
35+
- <root>/docker/Dockerfile is the one that creates the main trigger.dev published image
36+
- <root>/docker/docker-compose.yml is the file we run locally to start postgresql, redis, and electric when we are doing local development. You can run it with `pnpm run docker`
37+
- <root>/CONTRIBUTING.md defines the steps it takes for OSS contributors to start contributing.

ai/references/tests.md

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,22 @@
33
We use vitest exclusively for testing. To execute tests for a particular workspace, run the following command:
44

55
```bash
6-
pnpm test --filter webapp
6+
pnpm run test --filter webapp
77
```
88

9-
Prefer running tests on a single file:
9+
Prefer running tests on a single file (and first cding into the directory):
1010

1111
```bash
12-
pnpm test --filter webapp/src/components/Button.test.ts
12+
cd apps/webapp
13+
pnpm run test ./src/components/Button.test.ts
14+
```
15+
16+
If you are cd'ing into a directory, you may have to build dependencies first:
17+
18+
```bash
19+
pnpm run build --filter webapp
20+
cd apps/webapp
21+
pnpm run test ./src/components/Button.test.ts
1322
```
1423

1524
## Writing Tests
@@ -34,3 +43,39 @@ describe("redisTest", () => {
3443
});
3544
});
3645
```
46+
47+
postgresTest:
48+
49+
```typescript
50+
import { postgresTest } from "@internal/testcontainers";
51+
52+
describe("postgresTest", () => {
53+
postgresTest("should use postgres", async ({ prisma }) => {
54+
// prisma is an instance of PrismaClient
55+
});
56+
});
57+
```
58+
59+
containerTest:
60+
61+
```typescript
62+
import { containerTest } from "@internal/testcontainers";
63+
64+
describe("containerTest", () => {
65+
containerTest("should use container", async ({ prisma, redisOptions }) => {
66+
// container has both prisma and redis
67+
});
68+
});
69+
```
70+
71+
## Dos and Dont's
72+
73+
- Do not mock anything.
74+
- Do not use mocks in tests.
75+
- Do not use spies in tests.
76+
- Do not use stubs in tests.
77+
- Do not use fakes in tests.
78+
- Do not use sinon in tests.
79+
- Structure each test with a setup, action, and assertion style.
80+
- Feel free to write long test names.
81+
- If there is any randomness in the code under test, use `seedrandom` to make it deterministic by allowing the caller to provide a seed.

0 commit comments

Comments
 (0)