Skip to content

Commit 0feb98a

Browse files
committed
docs(tests): restore the heavy-graph, global-mock and permanent-implementation rules and small doc pointers
1 parent 3112afc commit 0feb98a

4 files changed

Lines changed: 29 additions & 6 deletions

File tree

‎.claude/rules/sim-testing.md‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ Global (installed by `vitest.setup.ts` — knobs only, no `vi.mock`):
125125
| `@sim/platform-authz/workflow` | `workflowAuthzMockFns` (`workflow-authz.mock`) |
126126
| `@/lib/environment/utils` | `environmentUtilsMockFns` (`environment-utils.mock`) |
127127

128+
Also global, with no knobs — never re-mock: the console/terminal/execution stores,
129+
`@/blocks/registry`, `@/tools/registry`, `@/tools/metadata`, `@/tools/metadata-outputs`,
130+
`@trigger.dev/core/v3`. `apps/sim/vitest.setup.ts` is the authoritative list.
131+
128132
Helpers — use these instead of redefining them:
129133

130134
| Need | Helper |
@@ -147,6 +151,11 @@ module scope or in `beforeAll` is undone before the first test. Integration mode
147151
fixtures (restore/unstub off). Node is the default environment — add
148152
`/** @vitest-environment jsdom */` only when the test needs the DOM.
149153

154+
Those resets clear call history and undo spies, but not an implementation you install on a central
155+
mock's `vi.fn`: `xMockFns.mockFoo.mockReturnValue(...)` carries into later tests in the file. Prefer
156+
`*Once`; a test that installs a permanent one calls `mockFoo.mockReset()` (which restores the
157+
default) in `beforeEach`.
158+
150159
### Performance rules
151160

152161
The suite's wall time is bound by the single Vite server thread that serves every module fetch and
@@ -155,8 +164,10 @@ The suite's wall time is bound by the single Vite server thread that serves ever
155164
1. `vi.hoisted()` + `vi.mock()` + static imports. Never `vi.resetModules()` + `vi.doMock()` +
156165
dynamic `import()`, except for a module that caches a singleton at module scope.
157166
2. Never `vi.importActual()`/`importOriginal` to build a partial mock — use the central mock.
158-
3. No real timers: `vi.useFakeTimers()`, `flushMicrotasks()`, or `flushMacrotask()`.
159-
4. Absolute imports only.
167+
3. Mock heavy graphs a test does not need and the setup does not already mock: `@/blocks`,
168+
`@/triggers/registry`, `@/tools/generated/*`.
169+
4. No real timers: `vi.useFakeTimers()`, `flushMicrotasks()`, or `flushMacrotask()`.
170+
5. Absolute imports only.
160171

161172
### Running
162173

‎.cursor/rules/sim-testing.mdc‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ Global (installed by `vitest.setup.ts` — knobs only, no `vi.mock`):
123123
| `@sim/platform-authz/workflow` | `workflowAuthzMockFns` (`workflow-authz.mock`) |
124124
| `@/lib/environment/utils` | `environmentUtilsMockFns` (`environment-utils.mock`) |
125125

126+
Also global, with no knobs — never re-mock: the console/terminal/execution stores,
127+
`@/blocks/registry`, `@/tools/registry`, `@/tools/metadata`, `@/tools/metadata-outputs`,
128+
`@trigger.dev/core/v3`. `apps/sim/vitest.setup.ts` is the authoritative list.
129+
126130
Helpers — use these instead of redefining them:
127131

128132
| Need | Helper |
@@ -145,6 +149,11 @@ module scope or in `beforeAll` is undone before the first test. Integration mode
145149
fixtures (restore/unstub off). Node is the default environment — add
146150
`/** @vitest-environment jsdom */` only when the test needs the DOM.
147151

152+
Those resets clear call history and undo spies, but not an implementation you install on a central
153+
mock's `vi.fn`: `xMockFns.mockFoo.mockReturnValue(...)` carries into later tests in the file. Prefer
154+
`*Once`; a test that installs a permanent one calls `mockFoo.mockReset()` (which restores the
155+
default) in `beforeEach`.
156+
148157
### Performance rules
149158

150159
The suite's wall time is bound by the single Vite server thread that serves every module fetch and
@@ -153,8 +162,10 @@ The suite's wall time is bound by the single Vite server thread that serves ever
153162
1. `vi.hoisted()` + `vi.mock()` + static imports. Never `vi.resetModules()` + `vi.doMock()` +
154163
dynamic `import()`, except for a module that caches a singleton at module scope.
155164
2. Never `vi.importActual()`/`importOriginal` to build a partial mock — use the central mock.
156-
3. No real timers: `vi.useFakeTimers()`, `flushMicrotasks()`, or `flushMacrotask()`.
157-
4. Absolute imports only.
165+
3. Mock heavy graphs a test does not need and the setup does not already mock: `@/blocks`,
166+
`@/triggers/registry`, `@/tools/generated/*`.
167+
4. No real timers: `vi.useFakeTimers()`, `flushMicrotasks()`, or `flushMacrotask()`.
168+
5. Absolute imports only.
158169

159170
### Running
160171

‎CLAUDE.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
You are a professional software engineer. All code must follow best practices: accurate, readable, clean, and efficient.
44

5-
This file (also `AGENTS.md`) holds the repo-wide rules. Area detail lives in `.claude/rules/*.md`: Claude loads each one by path, and any other agent reads the file a section points to before editing in that area. Skills live in `.agents/skills/`.
5+
This file (also `AGENTS.md`) holds the repo-wide rules. Area detail lives in `.claude/rules/*.md` (indexed in `apps/sim/AGENTS.md`): Claude loads each one by path, and any other agent reads the file a section points to before editing in that area. Skills live in `.agents/skills/`.
66

77
## Global Standards
88

@@ -24,7 +24,7 @@ This file (also `AGENTS.md`) holds the repo-wide rules. Area detail lives in `.c
2424
- `compareStrings(left, right)` from `@sim/utils/string` — code-unit ordering for hashes, fingerprints, and cross-process comparisons; never `localeCompare` there
2525
- `backoffWithJitter(attempt, retryAfterMs, options?)` / `parseRetryAfter(header)` from `@sim/utils/retry` — never reimplement exponential backoff inline
2626
- **Deployment flags in the browser**: client code inside a workspace, organization, or standalone settings surface reads `hosted`, `billingEnabled`, `chatEnabled`, and the enterprise feature set through `useDeploymentShape()` (components) or `getDeploymentShape()` (block conditions, stores, helpers) from `@/lib/core/config/deployment-shape`, never `isHosted`/`isBillingEnabled`/... from `env-flags`. Those constants freeze at module init from the root layout's `NEXT_PUBLIC_*` transport, which Next's bare 404 shell and `global-error` never emit, so a recovered tab would render Sim Cloud as self-hosted; the reader is seeded from the server-resolved workspace host context, organization layout, or standalone settings layout instead. Server code keeps reading `env-flags`.
27-
- **Type-checking**: `bun run type-check` (per workspace) or `bunx turbo run type-check` (all). Never remove the `@typescript/native` alias from the root `devDependencies`. Nothing imports it; it exists so a bare `tsc` resolves to the native TypeScript 7 compiler. `apps/sim` needs `@typescript/typescript6`, whose `@typescript/old` dependency (an alias of `typescript@6`) ships its own `tsc` bin, and bin winners are picked by lexical sort, so without the alias `tsc` silently becomes the ~10x slower JavaScript compiler. `bun run check:native-typecheck` enforces this ([microsoft/typescript-go#4567](https://github.com/microsoft/typescript-go/issues/4567)).
27+
- **Type-checking**: `bun run type-check` (per workspace) or `bunx turbo run type-check` (all). Never remove the `@typescript/native` alias from the root `devDependencies`. Nothing imports it; it exists so a bare `tsc` resolves to the native TypeScript 7 compiler. `apps/sim` needs `@typescript/typescript6`, whose `@typescript/old` dependency (an alias of `typescript@6`) ships its own `tsc` bin, and bin winners are picked by lexical sort, so without the alias `tsc` silently becomes the ~10x slower JavaScript compiler. `bun run check:native-typecheck` enforces this, and also fails when a newly added dependency that sorts ahead of `@typescript/native` ships a `tsc` bin ([microsoft/typescript-go#4567](https://github.com/microsoft/typescript-go/issues/4567)).
2828
- **Checks**: `bun run lint` autofixes formatting; `bun run check:audits` runs every `check:*` audit CI enforces.
2929

3030
## Architecture

‎apps/sim/AGENTS.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Applies to `apps/sim/**` on top of the root [AGENTS.md](/AGENTS.md), which holds
1010
- URL state, list and menu order, caching: `sim-url-state.md`, `sim-list-ordering.md`, `sim-caching.md`
1111
- Tools, blocks, triggers: `sim-integrations.md`; isolated-vm sandbox worker: `sim-sandbox.md`
1212
- Tests: `sim-testing.md` and the `test-audit` skill
13+
- Landing pages: `app/(landing)/CLAUDE.md`, `landing-seo-geo.md`, `constitution.md` (product language)
1314

1415
<!-- BEGIN:nextjs-agent-rules -->
1516

0 commit comments

Comments
 (0)