Claude
Skills
Sign in
Back

test

Included with Lifetime
$97 forever

Unified Playwright test automation. Default runs full autonomous loop. Use --explore for interactive, --ticket ENG-123 for Linear tickets, --describe for text descriptions.

Code Review

What this skill does


# /test - Unified Test Automation

Generate production-ready Playwright tests with multiple input modes. Default mode runs the full autonomous loop with pattern learning.

## Quick Start

```bash
/test login              # Full autonomous (default) - explore → plan → generate → heal → learn
/test --explore login    # Interactive exploration only - opens visible browser
/test --ticket ENG-123   # From Linear ticket - fetches AC, generates tests
/test --describe "..."   # From user description - skips exploration
```

## Modes Comparison

| Mode | Explore | Plan | Generate | Heal | Learn |
|------|---------|------|----------|------|-------|
| `/test login` (default) | ✅ Auto | ✅ | ✅ | ✅ 5x | ✅ |
| `/test --explore login` | ✅ Interactive | ❌ | ❌ | ❌ | ❌ |
| `/test --ticket ENG-123` | ❌ (from AC) | ✅ | ✅ | ✅ | ✅ |
| `/test --describe "..."` | ❌ (from text) | ✅ | ✅ | ✅ | ✅ |

---

## Workflow Overview

```
┌─────────────────────────────────────────────────────────────────────────────┐
│                            /test {feature}                                   │
├─────────────────────────────────────────────────────────────────────────────┤
│                                                                              │
│  INPUT SOURCES:                                                              │
│  ├── Default → EXPLORE with Playwright MCP                                  │
│  ├── --ticket → Linear ticket acceptance criteria                           │
│  ├── --describe → User text description                                     │
│  └── --explore → Interactive exploration only (STOPS after explore)         │
│                                                                              │
│  PHASES:                                                                     │
│  0. SETUP → Auto-config, load patterns, discover credentials                │
│  0.6 LOAD CONTEXT → triqual_load_context tool builds context files (MANDATORY, BLOCKING)│
│  1. EXPLORE → Playwright MCP (skip with --ticket/--describe)                │
│  2. PLAN → Quoth context output + input source                              │
│  3. GENERATE → .spec.ts in .draft/tests/ (NEVER directly to tests/)         │
│  4. HEAL LOOP → Run → Fix → Re-run (max 5 iterations)                       │
│  5. PROMOTE → User approves → Move to production test directory             │
│  6. LEARN → Save patterns + anti-patterns                                   │
│                                                                              │
└─────────────────────────────────────────────────────────────────────────────┘
```

---

## Phase 0: SETUP (Auto-Config & Authentication)

This phase loads configuration and handles authentication before any exploration.

### 0.1 Load Configuration

Read `triqual.config.ts` if it exists:

```bash
# Check for TypeScript config
ls triqual.config.ts 2>/dev/null
```

If TypeScript config exists, read it to extract configuration values. The config uses `defineConfig` from `triqual` for type safety:

```typescript
// triqual.config.ts
import { defineConfig } from 'triqual';

export default defineConfig({
  project_id: 'my-app',
  testDir: './tests',
  baseUrl: 'http://localhost:3000',
  auth: { strategy: 'storageState', ... },
  // ...
});
```

If missing, prompt user to run `/init` first or auto-detect basic config.

### 0.2 Load Existing Patterns

Read from `${PLUGIN_ROOT}/context/`:

- `patterns-learned.json` - Successful patterns from previous runs
- `anti-patterns-learned.json` - Known failure→fix mappings

### 0.3 Handle Authentication

Based on `auth.strategy` from config, authenticate before exploration:

#### Strategy: `storageState` (Fastest)

If `.auth/user.json` exists and is configured:

```javascript
// Load saved auth state via browser_run_code
mcp__plugin_triqual-plugin_playwright__browser_run_code({
  code: `async (page) => {
    const fs = require('fs');
    const state = JSON.parse(fs.readFileSync('.auth/user.json', 'utf8'));

    // Add cookies
    if (state.cookies?.length) {
      await page.context().addCookies(state.cookies);
    }

    // Navigate to trigger cookie application
    await page.goto('${baseUrl}');

    // Restore localStorage if present
    if (state.origins?.[0]?.localStorage?.length) {
      await page.evaluate((items) => {
        items.forEach(({ name, value }) => localStorage.setItem(name, value));
      }, state.origins[0].localStorage);
    }

    return 'Auth state loaded';
  }`
})
```

#### Strategy: `uiLogin` (When no saved state)

If credentials are configured but no storageState:

```javascript
// Navigate to login page
mcp__plugin_triqual-plugin_playwright__browser_navigate({
  url: config.auth.uiLogin.loginUrl  // e.g., "/login"
})

// Get page snapshot to find form elements
mcp__plugin_triqual-plugin_playwright__browser_snapshot({})

// Fill login form using configured selectors
mcp__plugin_triqual-plugin_playwright__browser_fill_form({
  fields: [
    {
      name: 'Email',
      type: 'textbox',
      ref: '{email-field-ref}',  // From snapshot
      value: credentials.email
    },
    {
      name: 'Password',
      type: 'textbox',
      ref: '{password-field-ref}',  // From snapshot
      value: credentials.password
    }
  ]
})

// Click submit
mcp__plugin_triqual-plugin_playwright__browser_click({
  ref: '{submit-button-ref}',
  element: 'Login submit button'
})

// Wait for navigation to success URL
mcp__plugin_triqual-plugin_playwright__browser_wait_for({
  text: 'Dashboard'  // Or wait for URL change
})
```

#### Strategy: `setupProject` (Playwright native)

If project uses Playwright's setup project pattern:

```bash
# Run setup project first
npx playwright test --project=setup
```

Then proceed with tests that have `dependencies: ['setup']`.

#### Strategy: `none` (No auth needed)

Skip authentication, proceed directly to exploration.

### 0.4 Verify Authentication

After auth, verify we're logged in:

```javascript
// Take snapshot to confirm auth state
mcp__plugin_triqual-plugin_playwright__browser_snapshot({})

// Check for logged-in indicators:
// - User avatar/menu visible
// - Dashboard or protected content visible
// - No login form visible
```

### 0.5 Optionally Save Auth State

After successful UI login, save state for future runs:

```javascript
// Save state for future runs (optional)
mcp__plugin_triqual-plugin_playwright__browser_run_code({
  code: `async (page) => {
    const state = await page.context().storageState();
    require('fs').writeFileSync('.auth/user.json', JSON.stringify(state, null, 2));
    return 'Auth state saved to .auth/user.json';
  }`
})
```

---

## Phase 0.6: LOAD CONTEXT (EXECUTE IMMEDIATELY AFTER SETUP)

**This is a blocking gate.** The hooks will BLOCK test writing and test-planner dispatch until context files exist.

### Execute Context Loading

Call the context loading tool with just the feature name - the system automatically determines the optimal depth:

```
triqual_load_context({ feature: "{feature}" })
```

If you have a Linear ticket:
```
triqual_load_context({ feature: "{feature}", ticket: "ENG-123" })
```

If you have a description:
```
triqual_load_context({ feature: "{feature}", description: "..." })
```

Wait for the tool to complete before proceeding to Phase 1.

### What Happens Automatically

The tool intelligently analyzes your request and optimizes context depth:
- **Simple features** with existing patterns → Fast local scan
- **New test generation** → Quoth patterns + codebase analysis
- **Complex features** or tickets → Full context with failure history

This optimization saves ~70% tokens on average without any manual configuration.

### Output Files

Context files are written to `.triqual/context/{feature}/`:
- `patterns.md` — Proven patterns from Quoth
- `codebase.md` — Relevant source files, selectors, routes
- `existing-tests.md` — Reusable tests and page objects
- `summary.md` — Index of all context

Additional files are added automatical
Files: 1
Size: 19.8 KB
Complexity: 23/100
Category: Code Review

Related in Code Review