$schema: "@gobing-ai/spur/schemas/rule-file.schema.json"
# Bun/tooling rules — Spur standardizes on Bun + bun:test (AGENTS.md "Stack").
# Absorbed from ts-libs/.spur/rules/typescript/bun-only.yaml, re-scoped for the
# apps/** + packages/** + scripts/** app-monorepo layout and the server's
# Cloudflare Workers Vitest suite (the one sanctioned non-bun:test runner — `*.cf.ts`).
include:
  - "package.json"
  - "apps/**/*.ts"
  - "packages/**/*.ts"
  - "scripts/**/*.ts"
rules:
  - id: no-npm-pnpm-yarn-scripts
    description: "Use bun scripts instead of npm, pnpm, or yarn commands (AGENTS.md: no npm/pnpm/yarn)."
    severity: error
    evaluator:
      type: rg
      config:
        pattern: "\\b(npm run|pnpm|yarn)\\b"
    include:
      - "package.json"
      - "apps/*/package.json"
      - "packages/*/package.json"
      - "scripts/**/*.ts"
      - "**/*.yml"
      - "**/*.yaml"
    exclude:
      # Rule-definition YAML legitimately names these tools in patterns/descriptions.
      # (`.spur/rules/**` was de-listed: ripgrep never descends into hidden dirs,
      # so that tree is unreachable by the rg evaluator.)
      - "config/rules/**"

  - id: enforce-bun-test
    description: "Unit/integration tests must use bun:test, not Jest or Mocha. The server's Cloudflare Workers suite (*.cf.ts) is the only sanctioned Vitest runner."
    severity: error
    evaluator:
      type: rg
      config:
        pattern: "from [''\"](jest|mocha|@jest)"
    include:
      - "apps/**/*.test.ts"
      - "packages/**/*.test.ts"
      - "scripts/**/*.test.ts"

  - id: no-vitest-imports-or-apis
    description: "Use bun:test APIs instead of vitest, except the server's Cloudflare Workers tests (*.cf.ts) which must run under the Workers pool via Vitest."
    severity: error
    evaluator:
      type: rg
      config:
        pattern: "from ['\"]vitest['\"]|vi\\.(fn|spyOn|mock|stub)\\b"
    include:
      - "apps/**/*.ts"
      - "packages/**/*.ts"
      - "scripts/**/*.ts"
    exclude:
      # Sanctioned Cloudflare Workers Vitest wiring; `**/*.cf.ts` covers the
      # test files themselves (apps/server/tests/cf/** was redundant — its only
      # occupant is worker-runtime.cf.ts).
      - "apps/server/vitest.cf.config.ts"
      - "**/*.cf.ts"
