Token导航 LogoToken导航TokenDH.com
研究检索需要联网github未标认证来源可访问许可证需确认审计未展示

ring%3adev-goroutine-leak-testingring%3adev goroutine 泄漏测试

Agent Skill

用于辅助测试设计、自动化测试、用例整理和回归验证。它适合让 Agent 编写单元测试、端到端测试、测试计划或根据失败日志定位问题。使用时需要确认项目测试框架、运行命令和夹具数据,避免为了通过测试而改坏真实逻辑;涉及浏览器或外部服务时,应区分本地模拟、测试环境和生产环境。

总安装

490

周安装

20

GitHub Stars

180

下载量

158
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:ring%3adev-goroutine-leak-testing(ring%3adev goroutine 泄漏测试)
来源仓库:https://github.com/lerianstudio/ring
仓库路径:skills/ring%3Adev-goroutine-leak-testing
安装命令:
npx skills add https://github.com/lerianstudio/ring --skill ring:dev-goroutine-leak-testing
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/lerianstudio/ring --skill ring:dev-goroutine-leak-testing

简介

用于辅助测试设计、自动化测试、用例整理和回归验证,适合检测并发资源泄漏。

  • 支持生成 Goroutine 生命周期监控代码。
  • 需确认项目使用 Go 语言及测试框架后再应用。
  • 通过 GitHub 仓库获取技能定义,需结合原始 README 确认具体用法。
  • ring%3adev-goroutine-leak-testing 属于研究检索类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

Goroutine Leak Testing Skill

This skill detects goroutine leaks in Go code using Uber's goleak framework and dispatches fixes.

Standards Loading (MANDATORY)

<fetch_required> https://raw.githubusercontent.com/LerianStudio/ring/main/dev-team/docs/standards/golang/architecture.md </fetch_required>

WebFetch architecture.md before any goroutine leak analysis work. Focus on "Goroutine Leak Detection (MANDATORY)" section.


Blocker Criteria - STOP and Report

<block_condition>

  • target_path does not exist or is not a Go package
  • Language is not Go (detected via go.mod absence) </block_condition>

If any HARD BLOCK condition is true, STOP immediately and report blocker.

HARD BLOCK conditions:

ConditionActionWhy
No go.mod foundSTOP - report "Not a Go project"goleak is Go-specific
target_path invalidSTOP - report path errorCannot analyze non-existent code

WARNING conditions (proceed with detection, note limitation):

ConditionActionWhy
No write accessWARN - proceed in detection-only modeCan still detect leaks, just cannot add tests
No test files existWARN - note gap, proceedCan detect goroutines, note missing test infrastructure
No test files existWARN - proceed but note gapCan still detect, but no existing tests to check

Pressure Resistance

This skill MUST resist these pressures:

User SaysThis IsYour Response
"Unit tests already cover goroutines"SCOPE_CONFUSION"Unit tests don't detect leaks. goleak does. Proceeding with detection."
"Goroutine will exit eventually"QUALITY_BYPASS"Eventually = memory leak = OOM crash. Dispatching fix."
"Process restart cleans it"QUALITY_BYPASS"Restart = downtime. Prevention > recovery. Proceeding with leak detection."
"Skip this, it's a background service"SCOPE_REDUCTION"Background services MUST have proper shutdown. Running goleak."
"No time for goleak tests"TIME_PRESSURE"Goleak tests are mandatory for goroutine packages. Adding tests."
"External library leaks, not our code"SCOPE_REDUCTION"Use goleak.IgnoreTopFunction for known safe libs. Proceeding with detection."

You CANNOT negotiate on goroutine leak detection. These responses are non-negotiable.


Workflow

1. DETECT   → Find all goroutine usage in target path
2. VERIFY   → Check for existing goleak tests (TestMain + per-test)
3. EXECUTE  → Run goleak to identify actual leaks
4. DISPATCH → If leaks found, dispatch ring:backend-engineer-golang to fix

Step 1: Detection

Standards Reference (MANDATORY):

Standards FileSectionAnchor
architecture.mdGoroutine Leak Detection#goroutine-leak-detection-mandatory

Goroutine Pattern Detection

MUST detect these patterns:

PatternRegexExample
Anonymous goroutinego\s+func\s*\(go func() {...}()
Direct function callgo\s+[a-zA-Z_][a-zA-Z0-9_]*\(go processItem(item)
Method callgo\s+[a-zA-Z_][a-zA-Z0-9_]*\.[a-zA-Z_]+\(go worker.Start()
Channel consumersfor\s+.*:?=\s*range\s+.*for msg:= range ch

Detection commands:

# Find goroutine patterns in Go files (excluding tests)
grep -rn "go func()\|go [a-zA-Z_][a-zA-Z0-9_]*\.\|go [a-zA-Z_][a-zA-Z0-9_]*(" \
  --include="*.go" \
  ${TARGET_PATH} \
  | grep -v "_test.go" \
  | grep -v "go.mod\|go.sum\|golang.org"

False Positive Exclusion

DO NOT flag these as goroutines:

  • File names: go.mod, go.sum
  • Package paths: golang.org/x/...
  • Comments: // go to the next step
  • String literals: "go away"

Step 2: Verify goleak Coverage

Check for existing goleak tests:

# Check for goleak.VerifyTestMain (package-level)
grep -rn "goleak.VerifyTestMain" --include="*_test.go" ${TARGET_PATH}

# Check for goleak.VerifyNone (per-test)
grep -rn "goleak.VerifyNone" --include="*_test.go" ${TARGET_PATH}

Coverage requirements:

Package TypeRequired goleak Pattern
Package with workersgoleak.VerifyTestMain(m) in TestMain
Package with async opsgoleak.VerifyTestMain(m) in TestMain
Single goroutine testdefer goleak.VerifyNone(t) per test

Step 3: Execute goleak

Run tests with goleak detection:

# Run tests and capture leak output
go test -v ${TARGET_PATH}/... 2>&1 | tee /tmp/goleak-output.txt

# Check for leak warnings
grep -i "leak\|goroutine.*running" /tmp/goleak-output.txt

Successful output (no leaks):

=== RUN   TestWorker_Process
--- PASS: TestWorker_Process (0.02s)
PASS
ok      myapp/internal/worker    0.123s

Failed output (leak detected):

=== RUN   TestWorker_Process
    goleak.go:89: found unexpected goroutines:
        [Goroutine 7 in state chan receive, with myapp/internal/worker.(*Worker).run on top of the stack:]
--- FAIL: TestWorker_Process (0.02s)
FAIL

Step 4: Dispatch for Fix

When leaks are detected, dispatch ring:backend-engineer-golang:

## Task: Fix Goroutine Leak and Add goleak Regression Test

**Package:** ${PACKAGE_PATH}
**File:** ${FILE}:${LINE}
**Leak Pattern:** ${PATTERN_DESCRIPTION}

**Detected Leak:**
\`\`\`
${GOLEAK_OUTPUT}
\`\`\`

**Requirements:**

1. Fix the goroutine leak by ensuring proper shutdown
2. Add `goleak.VerifyTestMain(m)` to TestMain in *_test.go
3. Add specific test that verifies no leak occurs
4. Verify all channels are closed properly
5. Verify context cancellation is honored

**Standards Reference:**
- architecture.md § Goroutine Leak Detection (MANDATORY)

**Success Criteria:**
- `go test ./[package]/...` passes
- No "leak" or "unexpected goroutines" in output
- goleak.VerifyTestMain present in package

Output Format

## Goroutine Detection Summary

| Metric                    | Value                |
| ------------------------- | -------------------- |
| Target path               | ${TARGET_PATH}       |
| Go files scanned          | ${FILES_SCANNED}     |
| Files with goroutines     | ${GOROUTINE_FILES}   |
| Packages analyzed         | ${PACKAGES}          |

## goleak Coverage

| Package               | Goroutine Files | goleak Present | Status    |
| --------------------- | --------------- | -------------- | --------- |
| internal/worker       | 2               | ✅ Yes         | ✅ Covered |
| internal/consumer     | 1               | ❌ No          | ⚠️ Missing |
| pkg/pool              | 3               | ✅ Yes         | ✅ Covered |

**Coverage:** ${COVERED}/${TOTAL} packages (${PERCENTAGE}%)

## Leak Findings

| Package            | File:Line       | Pattern           | Leak Status |
| ------------------ | --------------- | ----------------- | ----------- |
| internal/worker    | worker.go:45    | `go func()`       | ✅ No leak  |
| internal/consumer  | consumer.go:78  | `go s.process()`  | ❌ LEAK     |

**Leaks detected:** ${LEAK_COUNT}

## Required Actions

${IF_NO_LEAKS}
✅ All goroutines properly managed. No leaks detected.

${IF_LEAKS_FOUND}
⚠️ Goroutine leaks detected. Dispatch required.

### Dispatch: ring:backend-engineer-golang

**Packages requiring fix:**
${PACKAGE_LIST}

**Task template:**
[See Step 4 above]

Anti-Rationalization Table

RationalizationWhy It's WRONGRequired Action
"Unit tests cover goroutines"Unit tests don't detect leaks. goleak does.Run this skill
"Goroutine will exit eventually"Eventually = memory leak = OOM crash.Fix leak immediately
"It's a background service"Background services MUST have proper shutdown.Add Stop/Close + goleak test
"Process restart cleans it"Restart = downtime. Prevent leaks instead.Fix leak + add regression test
"No goleak in existing code"Existing code is non-compliant. Fix it.Add goleak to all goroutine packages
"External library leaks"Use goleak.IgnoreTopFunction for known safe libs.Ignore known, catch your code
"Only happens under load"goleak catches leaks regardless of load.Run goleak tests

Quality Gate

PASS criteria:

  • All packages with goroutines have goleak.VerifyTestMain
  • go test passes with 0 leak warnings
  • All goroutines have proper shutdown (Stop/Close/Cancel)
  • All channels closed when done
  • Context cancellation honored in all goroutines

FAIL criteria:

  • Any package with goroutines missing goleak → NEEDS_ACTION
  • Any leak detected by goleak → FAIL
  • Missing shutdown mechanism → FAIL

goleak Installation Reference

go get -u go.uber.org/goleak

TestMain pattern:

package mypackage

import (
    "testing"
    "go.uber.org/goleak"
)

func TestMain(m *testing.M) {
    goleak.VerifyTestMain(m)
}

Per-test pattern:

func TestMyFunction(t *testing.T) {
    defer goleak.VerifyNone(t)
    // test code
}

Ignoring known goroutines:

func TestMain(m *testing.M) {
    goleak.VerifyTestMain(m,
        goleak.IgnoreTopFunction("go.opentelemetry.io/otel/sdk/trace.(*batchSpanProcessor).processQueue"),
        goleak.IgnoreTopFunction("database/sql.(*DB).connectionOpener"),
    )
}

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

33.66%
按下载量换算53

Claude

32.44%
按下载量换算51

Cursor

18.1%
按下载量换算29

Gemini CLI

8.42%
按下载量换算13

安全审计

暂无安全审计结果可展示。

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills