AgentSkillsCN

qstash-generate

生成符合正确Schema与功能组合的QStash测试套件YAML文件。 当用户提出以下需求时使用此功能:(1) 生成测试用例;(2) 创建测试套件;(3) 为某项功能搭建测试框架;(4) 编写QStash测试的YAML文件;(5) 创建新的测试用例。 可通过“生成测试”“创建测试套件”“为……新建测试”“搭建测试框架”“编写测试”等指令触发。

SKILL.md
--- frontmatter
name: qstash-generate
description: |
  Generate QStash test suite YAML files with correct schema and feature combinations.
  Use when user asks to: (1) generate a test, (2) create a test suite, (3) scaffold tests for a feature,
  (4) write YAML for QStash testing, (5) create a new test case.
  Triggers: "generate test", "create test suite", "new test for", "scaffold tests", "write a test".

qstash-generate

Generate YAML test suites for qstash-stress with correct schema and feature combinations.

Test Suite Schema

yaml
name: "Suite Name"
description: "What this suite tests"

setup:                           # Optional: Run before tests
  - action: create_queue
    queue: my-queue
    parallelism: 1

tests:
  - id: TEST-001                 # Required: Unique ID (uppercase, hyphen-separated)
    name: "Test case name"       # Required: Human-readable description
    tags: [tag1, tag2]           # Optional: For filtering (--tags, --exclude-tags)
    skip: false                  # Optional: Skip this test
    description: "Details"       # Optional: Extended description
    publish:                     # Required: Message configuration
      # ... see Publish Configuration below
    expect:                      # Optional: Assertions
      # ... see Expect Configuration below
    timeout: 2m                  # Optional: Test timeout (default: 5m)

cleanup:                         # Optional: Run after tests
  - action: delete_queue
    queue: my-queue

Publish Configuration Fields

Destination (one required)

FieldTypeDescription
urlstringDestination URL (supports ${RECEIVER_URL} variable)
queuestringQueue name (uses enqueue API)
url_groupstringURL group name for fanout

Content

FieldTypeDescription
bodyobject/stringMessage payload (JSON object or raw string)
methodstringHTTP method: GET, POST, PUT, DELETE, PATCH (default: POST)
headersmapCustom headers (key: value)
forward_headersmapHeaders to forward to destination (Upstash-Forward-*)

Timing

FieldTypeDescription
delaydurationDelay before delivery (e.g., "30s", "5m")
not_beforetimestampUnix timestamp for scheduled delivery
cronstringCron expression for recurring schedules
timeoutdurationDelivery timeout (e.g., "30s")

Retries

FieldTypeDescription
retriesintMax retry attempts (0-5, default: 3)
retry_delaystringRetry delay expression (e.g., "pow(2, retried) * 1000")

Callbacks

FieldTypeDescription
callbackstringURL for success/attempt callbacks
failure_callbackstringURL for final failure callback (DLQ)

Deduplication

FieldTypeDescription
dedup_idstringExplicit deduplication ID
content_based_dedupboolEnable content-based deduplication

Flow Control

FieldTypeDescription
flow_control_keystringFlow control group key
flow_control_valuestringRate limit config: "rate=N,period=Xs,parallelism=M"

Expect Configuration Fields

FieldTypeDescription
deliveredboolExpect message to be delivered
callback_receivedboolExpect callback to be received
status_codeintExpected HTTP status from receiver
maxLatencydurationMaximum acceptable delivery latency
minLatencydurationMinimum expected delivery latency
min_retriesintMinimum retry attempts before success
in_dlqboolExpect message to end in DLQ
errorboolExpect publish to fail
deduplicatedboolExpect message to be deduplicated

Feature Compatibility Matrix

Feature AFeature BCompatibleNotes
queuedelayNOQStash API limitation
queuenot_beforeNOQStash API limitation
crondelayYESDelay applied after each trigger
cronflow_controlYESRate limits scheduled deliveries
callbackretriesYESCallback per attempt, not final
dedup_idcontent_based_dedupNOUse one or the other
url_groupqueueNODifferent destination types

Common Patterns

1. Simple Publish

yaml
- id: PUB-001
  name: "Basic publish"
  tags: [basic, publish]
  publish:
    url: "${RECEIVER_URL}/message"
    body:
      message: "Hello World"
  expect:
    delivered: true
    maxLatency: 30s
  timeout: 2m

2. Callback Test

yaml
- id: CBK-001
  name: "Success callback"
  tags: [callback]
  publish:
    url: "${RECEIVER_URL}/message/success"
    callback: "${RECEIVER_URL}/callback/success"
    body:
      test: "callback"
  expect:
    delivered: true
    callback_received: true
  timeout: 2m

3. Retry Test

yaml
- id: RET-001
  name: "Retry on failure"
  tags: [retry]
  publish:
    url: "${RECEIVER_URL}/message/fail?fail_count=2"
    retries: 3
    retry_delay: "2000"  # 2 seconds between retries
    body:
      test: "retry"
  expect:
    delivered: true
    min_retries: 2
  timeout: 3m

4. Schedule Test

yaml
- id: SCH-001
  name: "Every minute schedule"
  tags: [schedule, long-term]
  publish:
    url: "${RECEIVER_URL}/schedule/sch-001"
    cron: "* * * * *"
    body:
      scheduleTestId: "SCH-001"
  timeout: 90s

5. Queue Test (with setup/cleanup)

yaml
name: "Queue Tests"
setup:
  - action: create_queue
    queue: test-queue
    parallelism: 1

tests:
  - id: QUE-001
    name: "Queue FIFO ordering"
    tags: [queue]
    publish:
      url: "${RECEIVER_URL}/queue/test-queue"
      queue: "test-queue"
      body:
        sequence: 1
    expect:
      delivered: true
    timeout: 2m

cleanup:
  - action: delete_queue
    queue: test-queue

6. Multi-Step Test

yaml
- id: DLQ-001
  name: "Fail to DLQ then retry"
  tags: [dlq, multi-step]
  steps:
    - id: publish_fail
      action: publish
      publish:
        url: "${RECEIVER_URL}/message/fail"
        retries: 0
        failure_callback: "${RECEIVER_URL}/callback/failure"
      save:
        my_test_id: "${testId}"

    - id: wait_dlq
      action: wait
      wait:
        for: callback
        test_id: "${my_test_id}"
        timeout: 30s
      expect:
        in_dlq: true

    - id: retry_dlq
      action: api
      api:
        method: POST
        endpoint: "/v2/dlq/${wait_dlq.dlqId}"
  timeout: 2m

7. Parallel Publish (Flow Control)

yaml
- id: FC-001
  name: "Rate limited publish"
  tags: [flowcontrol]
  publish:
    url: "${RECEIVER_URL}/message"
    flow_control_key: "my-fc-key"
    flow_control_value: "rate=5,period=1m,parallelism=1"
    body:
      test: "flow control"
  expect:
    delivered: true
  timeout: 2m

8. DLQ Test

yaml
- id: DLQ-001
  name: "Message to DLQ after retries"
  tags: [dlq]
  publish:
    url: "${RECEIVER_URL}/message/fail"
    retries: 1
    failure_callback: "${RECEIVER_URL}/callback/failure"
    body:
      test: "dlq"
  expect:
    delivered: false
    callback_received: true
  timeout: 3m

Receiver Endpoints

The qstash-stress receiver provides these test endpoints:

EndpointBehavior
/messageStandard message handler (200 OK)
/message/successAlways returns 200
/message/failAlways returns 500 (configurable)
/message/fail?fail_count=NFails N times, then succeeds
/message/slow?delay=5sResponds after configurable delay
/message/timeoutNever responds (for timeout testing)
/message/flakyRandom success/failure
/callback/successSuccess callback handler
/callback/failureFailure callback handler
/schedule/{id}Schedule delivery handler
/queue/{name}Queue delivery handler
/group/{name}URL group delivery handler

Generation Workflow

  1. Identify the feature to test: What QStash capability? (publish, retry, schedule, etc.)
  2. Check compatibility: Review the Feature Compatibility Matrix
  3. Choose a pattern: Start from the closest Common Pattern above
  4. Set unique ID: Use format PREFIX-NNN (e.g., SCH-001, RET-005)
  5. Add appropriate tags: For filtering with --tags and --exclude-tags
  6. Set realistic timeout: Based on expected behavior (retries, delays, etc.)
  7. Define expectations: What should happen? Delivered? Callback? Retries?

ID Naming Conventions

PrefixUsage
BAS-Basic publish tests
RET-Retry tests
CBK-Callback tests
SCH-Schedule tests
QUE-Queue tests
DLQ-Dead letter queue tests
FC- / FCL-Flow control tests
DED-Deduplication tests
SEC-Security tests
EDG-Edge case tests

Tag Conventions

TagMeaning
basicSimple, fast tests
slowTests that take > 1 minute
long-termSchedule tests for monitoring
skipTests to skip by default
retryTests retry behavior
callbackTests callback behavior
scheduleTests cron scheduling
queueTests queue operations
dlqTests dead letter queue
flowcontrolTests rate limiting
securitySecurity-related tests