Skip to content

armgit / orca

Public Imported from GitHub
0

Orca is the place for working with a fleet of agents (e.g. Grok Bot, Claude Code). Run any coding agent with your own subscription. Available on desktop, mobile and remote runtime.

5.2 KB
Raw Blame
# Ratcheted by config/scripts/check-flaky-test-pattern-ratchet.mjs; info severity keeps
# `pnpm lint:ast-grep` quiet about the grandfathered baseline.
# The `utils` block matches test-no-real-time-wait.yml; keep them in sync.
# The TSX document below mirrors the TypeScript one; keep them in sync.
id: test-no-polling-loop
language: typescript
severity: info
message: A hand-rolled polling loop guesses at timing. Use expect.poll, vi.waitFor, or a locator assertion, which report what never became true.
note: 'For a deliberate loop, add `// ast-grep-ignore: test-no-polling-loop -- <reason>` above it.'
files:
  - '**/*.test.ts'
  - '**/*.test.tsx'
  - '**/tests/e2e/**'
utils:
  resolves-promise-executor:
    inside:
      stopBy: end
      kind: new_expression
      all:
        - has: { field: constructor, regex: '^Promise$' }
        - has:
            field: arguments
            has:
              nthChild: 1
              any:
                - has: { field: parameter, pattern: $R }
                - has:
                    {
                      field: parameters,
                      has: { nthChild: 1, has: { field: pattern, pattern: $R } }
                    }
  nonzero-delay:
    has: { field: arguments, has: { nthChild: 2, not: { regex: '^0$' } } }
  # Inline checks rather than `constraints`: those run after matching, so a rejected candidate
  # would end a `has` search instead of letting it try the next node.
  real-time-sleep:
    any:
      - kind: call_expression
        has: { field: function, has: { field: property, regex: '^waitForTimeout$' } }
      - kind: await_expression
        has:
          kind: call_expression
          all:
            - has: { field: function, regex: '^setTimeout$' }
            - has: { field: arguments, has: { nthChild: 1, kind: number } }
      - kind: await_expression
        has:
          kind: call_expression
          all:
            - has: { field: function, regex: '^(sleep|delay|wait|pause)$' }
            - has: { field: arguments, has: { nthChild: 1, not: { regex: '^0$' } } }
      # Callback forms first: `any` keeps the first match, and `setTimeout($R, …)` would otherwise
      # bind $R to the callback and fail the executor check.
      - all:
          - pattern: setTimeout(() => $R($$$), $MS)
          - matches: nonzero-delay
          - matches: resolves-promise-executor
      - all:
          - pattern: setTimeout(() => { $R($$$) }, $MS)
          - matches: nonzero-delay
          - matches: resolves-promise-executor
      - all:
          - pattern: setTimeout($R, $MS)
          - matches: nonzero-delay
          - matches: resolves-promise-executor
rule:
  any: [{ kind: while_statement }, { kind: do_statement }, { kind: for_statement }]
  has:
    field: body
    stopBy: end
    matches: real-time-sleep
---
id: test-no-polling-loop-tsx
language: tsx
severity: info
message: A hand-rolled polling loop guesses at timing. Use expect.poll, vi.waitFor, or a locator assertion, which report what never became true.
note: 'For a deliberate loop, add `// ast-grep-ignore: test-no-polling-loop -- <reason>` above it.'
files:
  - '**/*.test.ts'
  - '**/*.test.tsx'
  - '**/tests/e2e/**'
utils:
  resolves-promise-executor:
    inside:
      stopBy: end
      kind: new_expression
      all:
        - has: { field: constructor, regex: '^Promise$' }
        - has:
            field: arguments
            has:
              nthChild: 1
              any:
                - has: { field: parameter, pattern: $R }
                - has:
                    {
                      field: parameters,
                      has: { nthChild: 1, has: { field: pattern, pattern: $R } }
                    }
  nonzero-delay:
    has: { field: arguments, has: { nthChild: 2, not: { regex: '^0$' } } }
  # Inline checks rather than `constraints`: those run after matching, so a rejected candidate
  # would end a `has` search instead of letting it try the next node.
  real-time-sleep:
    any:
      - kind: call_expression
        has: { field: function, has: { field: property, regex: '^waitForTimeout$' } }
      - kind: await_expression
        has:
          kind: call_expression
          all:
            - has: { field: function, regex: '^setTimeout$' }
            - has: { field: arguments, has: { nthChild: 1, kind: number } }
      - kind: await_expression
        has:
          kind: call_expression
          all:
            - has: { field: function, regex: '^(sleep|delay|wait|pause)$' }
            - has: { field: arguments, has: { nthChild: 1, not: { regex: '^0$' } } }
      # Callback forms first: `any` keeps the first match, and `setTimeout($R, …)` would otherwise
      # bind $R to the callback and fail the executor check.
      - all:
          - pattern: setTimeout(() => $R($$$), $MS)
          - matches: nonzero-delay
          - matches: resolves-promise-executor
      - all:
          - pattern: setTimeout(() => { $R($$$) }, $MS)
          - matches: nonzero-delay
          - matches: resolves-promise-executor
      - all:
          - pattern: setTimeout($R, $MS)
          - matches: nonzero-delay
          - matches: resolves-promise-executor
rule:
  any: [{ kind: while_statement }, { kind: do_statement }, { kind: for_statement }]
  has:
    field: body
    stopBy: end
    matches: real-time-sleep