test-setup-patterns

test-setup-patterns is a cursor rule for Cursor from brendadeeznuts1111/betting-brain-v3. It costs 0 tokens per session (1,139 once invoked), scanned A, original, MIT.

A set of rules for preparing tests with Bun, a JavaScript and TypeScript runtime. It defines shared test setup, mock environments, analytics cleanup, and test-name handling.

In plain words
What is it for?
Use it to configure global test helpers, create mock environments, flush analytics test data, and restore mocks after each test.
Why use it?
It keeps tests in a predictable state and clears analytics data and mocked functions between tests. This reduces interference between tests.

Cursor rule for Cursor

Written for Cursor: installed under .cursor/.

Needs its repository: it reads a path above its own folder, which exists only inside the repository. The line is import { createAnalyticsEngineStub } from '../utils/analytics-engine-stub';.

Install

Getting it into your agent

It runs from inside its repository, so the clone comes first — what it calls does not travel with the file alone.

Clone the repo
git clone --depth 1 https://github.com/brendadeeznuts1111/betting-brain-v3
agentmods
npx agentmods add rules/brendadeeznuts1111/betting-brain-v3/test-setup-patterns

Made for: Cursor.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for test-setup-patterns

README.md
[![agentmods](https://agentmods.dev/badge/rules/brendadeeznuts1111/betting-brain-v3/test-setup-patterns.svg)](https://agentmods.dev/rules/brendadeeznuts1111/betting-brain-v3/test-setup-patterns)
Your own site
<a href="https://agentmods.dev/rules/brendadeeznuts1111/betting-brain-v3/test-setup-patterns"><img src="https://agentmods.dev/badge/rules/brendadeeznuts1111/betting-brain-v3/test-setup-patterns.svg" alt="Measured on agentmods" height="20"></a>
Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 1,139 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00000 $0.01139
Opus 5 $0.00000 $0.00570
Sonnet 5 $0.00000 $0.00228
Haiku 4.5 $0.00000 $0.00114

Measured 6d ago against content hash f53ef440fcd3, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-06, from the pricing page.

Security

Grade A, and why

test-setup-patterns scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 6d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/test-setup-patterns.mdc · 202 lines

How it starts

The opening of the file, as written. The whole thing — 202 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Test Setup Patterns

Global Test Configuration

Test Setup File: tests/setup/test-setup.ts


import { vi, beforeAll, beforeEach, afterEach, expect } from 'bun:test';
import { createAnalyticsEngineStub } from '../utils/analytics-engine-stub';

// Global analytics stub instance
let globalAnalyticsStub: ReturnType<typeof createAnalyticsEngineStub> | null = null;
let currentTestName: string = '';

export function getGlobalAnalyticsStub() {
  return globalAnalyticsStub;
}

export function setCurrentTestName(name: string) {
  currentTestName = name;
}

Auto-Flush Pattern

Analytics Tests Only


afterEach(function () {
  if (currentTestName.toLowerCase().includes('analytics') && globalAnalyticsStub) {
    globalAnalyticsStub.flush();
  }
  vi.restoreAllMocks();
});

Test Name Detection


// In analytics tests, always set test name
test('should track analytics calls with stub', async () => {
  setCurrentTestName('should track analytics calls with stub');
  // Test implementation
});

Mock Environment Pattern

Create Mock Environment


import { createMockEnv } from '../utils/test-helpers';

describe('My Analytics Test', () => {
  let mockEnv: any;
  let analytics: any;

  beforeEach(() => {
    const mock = createMockEnv();
    mockEnv = mock.env;
    analytics = mock.analytics;
  });
});

Use Global Stub

// ✅ CORRECT: Use global stub
const analytics = getGlobalAnalyticsStub();

// ❌ WRONG: Create duplicate stubs
const analytics1 = createAnalyticsEngineStub();
const analytics2 = createAnalyticsEngineStub();

Test Isolation Patterns

Fresh Stub Per Test

beforeEach(() => {
  // Create fresh analytics stub for each test
  globalAnalyticsStub = createAnalyticsEngineStub();
});

Console Mocking

beforeEach(() => {
  vi.spyOn(console, 'log').mockImplementation(() => {});
  vi.spyOn(console, 'error').mockImplementation(() => {});
  vi.spyOn(console, 'warn').mockImplementation(() => {});
});

Read the full file on GitHub · 202 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 6d ago First seen · 202 lines · 0 tokens per session scan A f53ef440fcd3

Subscribe to this mod's changes

test-setup-patterns is a cursor rule published in the GitHub repository brendadeeznuts1111/betting-brain-v3 (8 stars, last pushed 11mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 1,139 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.