Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

testdriver:cache

БесплатноБез исполняемых скриптовНе проверен

Speed up tests with screenshot-based caching

testdriveraiот testdriverai★ 342 звезды на GitHub

Об этом скилле

Overview

The cache system makes repeated test runs faster. It compares screenshots to cached results. When the screen did not change much, TestDriver uses the cached element positions again. It does not make an AI call.

The cache works at two levels:

  • Screen cache: a pixel diff comparison between the present screenshot and the cached screenshot
  • Element cache: OpenCV template matching to make sure that the cached element position is still correct

How It Works

  1. On find(), the SDK sends the present screenshot and the cache metadata to the API.
  2. The API compares the screenshot against the cached results for the same cacheKey.
  3. If the screen pixel diff is in the screen threshold AND the element template match is more than the element threshold, TestDriver returns the cached position.
  4. If not, TestDriver makes a new AI call and caches the result.
flowchart LR
    A[Screenshot + cacheKey] --> B{Screen Diff\n< threshold?}
    B -- Yes --> C{Template\nMatch OK?}
    C -- Yes --> D[Return cached position]
    B -- No --> E[AI Call - fresh]
    C -- No --> F[AI Call - fresh]

Configuration

Constructor Options

const testdriver = new TestDriver({
  cache: {
    enabled: true,
    thresholds: {
      find: {
        screen: 0.05,     // 5% pixel diff allowed (default)
        element: 0.8,     // 80% OpenCV correlation required (default)
      },
      assert: 0.05,       // 5% pixel diff for assertions (default)
    },
  },
  cacheKey: 'my-custom-key',   // overrides auto-generated key
});
Cache configuration object, or `false` to disable entirely. Enable or disable the cache system. Requires a valid `cacheKey` to actually activate.
<ParamField path="thresholds" type="CacheThresholds">
  Threshold configuration for different command types.

  <Expandable title="properties">
    <ParamField path="find" type="FindCacheThresholds">
      Thresholds for `find()` and `findAll()`.

      <Expandable title="properties">
        <ParamField path="screen" type="number" default={0.05}>
          Maximum pixel diff percentage allowed between the current screenshot and the cached screenshot. Lower values require a closer match. Range: `0` to `1`.
        </ParamField>
        
        <ParamField path="element" type="number" default={0.8}>
          Minimum OpenCV template matching correlation required for the cached element crop. Higher values require a closer match. Range: `0` to `1`. Only used for `find()`, not `findAll()`.
        </ParamField>
      </Expandable>
    </ParamField>
    
    <ParamField path="assert" type="number" default={0.05}>
      Maximum pixel diff allowed for assertion cache hits.
    </ParamField>
  </Expandable>
</ParamField>
Unique key for cache lookups. If not provided, an auto-generated key is created from a SHA-256 hash of the calling test file (first 16 hex characters). The cache key changes automatically when your test file changes, providing automatic cache invalidation.

Disabling Cache

// Via constructor
const testdriver = new TestDriver({ cache: false });

// Via environment variable
// TD_NO_CACHE=true npx vitest run

When cache is disabled, all thresholds are set to -1 internally, causing the API to skip cache lookups.

Per-Command Overrides

Override cache thresholds for individual commands:

// Stricter screen matching for this specific find
const el = await testdriver.find('submit button', {
  cache: {
    thresholds: { screen: 0.01, element: 0.95 },
  },
});

// Custom cache key for a specific assertion
await testdriver.assert('dashboard loaded', {
  cache: { threshold: 0.01 },
  cacheKey: 'dashboard-check',
});

Threshold Priority

Thresholds are resolved in priority order (highest wins):

Priority Source Example
1 (highest) Per-command option find(desc, { cache: { thresholds: { screen: 0.1 } } })
2 Legacy number argument find(desc, 0.1)
3 Global constructor config new TestDriver({ cache: { thresholds: { find: { screen: 0.1 } } } })
4 (lowest) Hard-coded defaults screen: 0.05, element: 0.8, assert: 0.05

Auto-Generated Cache Key

When you don't specify a cacheKey, the SDK automatically generates one:

  1. Walks the call stack to find your test file
  2. Reads the file content
  3. Computes a SHA-256 hash of the content
  4. Uses the first 16 hex characters as the cache key

This means:

  • Same test file → same cache key → cache hits
  • Modified test file → different h
Полный SKILL.md на GitHub

Установить testdriver:cache в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

FAQ

Что делает скилл testdriver:cache?

Speed up tests with screenshot-based caching

Как установить скилл testdriver:cache?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл testdriver:cache запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить testdriver:cache с