跳转到正文
报告库
用途分类 / 内容写作

Javascript Testing Patterns Skill 安全审计

作者说它能做什么(原文)

Implement comprehensive testing strategies using Jest, Vitest, and Testing Library for unit tests, integration tests, and end-to-end testing with mocking, fixtures, and test-driven development. Use when writing JavaScript/TypeScript tests, setting up test infrastructure, or implementing TDD/BDD workflows.

第三方安全检查结论

先别安装或运行

已检查文件
2
发现的风险
2
会不会运行危险命令?检查是否下载程序后直接运行、让他人远程控制电脑,或藏起要运行的命令。未发现风险
会不会泄露文件和密钥?检查是否发送含密码或密钥的文件,以及代码里是否直接写了密钥。发现 1 项风险
高风险

集成测试会清空并删除 users 表,缺少确认数据库确为一次性测试库的保护

原文依据:6 处
发现了什么

指南要求每次测试前截断表,并在结束后删除表。一个 API 示例直接复用应用的数据库连接;代码没有检查数据库名、环境或禁止生产连接。另一个示例虽写死为 test_db,但仍执行相同的破坏性查询。

为什么需要注意

如果应用配置、环境变量或本地凭据误指向共享、开发或生产数据库,运行测试可永久删除全部用户记录或整个 users 表。

该风险有源码支持,但内容是供用户采用的测试示例,并非 Skill 自身已执行的操作。主指南明确要求每次测试前截断表、结束后清理;API 示例复用应用导出的 pool,随后无环境或数据库名校验便 DROP/TRUNCATE users。若测试配置误连到共享库或生产库,会永久删除表或数据。用户可要求作者加入仅允许专用测试数据库的硬性校验,并在运行前核对连接目标与测试账户权限。

SKILL.md:490来自说明文档打开原文件
Integration tests verify real database operations and HTTP endpoints using `supertest` and a test database instance. Always truncate tables in `beforeEach` and tear down in `afterAll`.For full API integration test examples (supertest + PostgreSQL) and database repository integration tests, see [references/advanced-testing-patterns.md](references/advanced-testing-patterns.md).
查看另外 5 个位置
references/advanced-testing-patterns.md:11来自说明文档打开原文件
// tests/integration/user.api.test.tsimport request from "supertest";import { app } from "../../src/app";import { pool } from "../../src/config/database";describe("User API Integration Tests", () => {  beforeAll(async () => {    // Setup test database    await pool.query("CREATE TABLE IF NOT EXISTS users (...)");  });
references/advanced-testing-patterns.md:21来自说明文档打开原文件
  afterAll(async () => {    // Cleanup    await pool.query("DROP TABLE IF EXISTS users");    await pool.end();  });  beforeEach(async () => {    // Clear data before each test    await pool.query("TRUNCATE TABLE users CASCADE");  });
references/advanced-testing-patterns.md:155来自说明文档打开原文件
  beforeAll(async () => {    pool = new Pool({      host: "localhost",      port: 5432,      database: "test_db",      user: "test_user",      password: "test_password",    });
references/advanced-testing-patterns.md:13来自说明文档打开原文件
import { app } from "../../src/app";import { pool } from "../../src/config/database";
references/advanced-testing-patterns.md:27来自说明文档打开原文件
  beforeEach(async () => {    // Clear data before each test    await pool.query("TRUNCATE TABLE users CASCADE");  });
会不会删除文件或一直在后台运行?检查是否大范围删除文件、改写磁盘,或设置自动启动。未发现风险
会不会绕过安全保护?检查是否跳过网站安全验证、开放过多文件权限,或取消操作前的确认。发现 1 项风险
低风险

全局 fetch 模拟未恢复,可能污染同一进程中的其他测试

原文依据:3 处
发现了什么

示例直接覆盖 global.fetch,而清理步骤只调用 vi.clearAllMocks;这会清除调用记录,但不会把原始 fetch 实现恢复回来。

为什么需要注意

随后在同一测试进程运行、原本应执行真实或不同网络行为的测试可能继续使用空模拟,产生误导性的通过、异常返回值或漏检。

该风险成立,但仅在用户复制此示例并与其他测试共用同一进程时发生。代码直接将 global.fetch 替换为 mock;beforeEach 只调用 vi.clearAllMocks,它会清除 mock 状态,却没有恢复原始全局函数。因此后续依赖真实 fetch 的测试可能继续使用 mock,造成误判或失败。用户可要求作者示范用 spy 并在 afterEach 恢复,或把全局 mock 限定在隔离的测试文件/进程中。

SKILL.md:239来自说明文档打开原文件
// Mock fetch globallyglobal.fetch = vi.fn();describe("ApiService", () => {  let service: ApiService;  beforeEach(() => {    service = new ApiService();    vi.clearAllMocks();  });
查看另外 2 个位置
SKILL.md:235来自说明文档打开原文件
// services/api.service.test.tsimport { describe, it, expect, vi, beforeEach } from "vitest";import { ApiService } from "./api.service";// Mock fetch globallyglobal.fetch = vi.fn();
SKILL.md:245来自说明文档打开原文件
  beforeEach(() => {    service = new ApiService();    vi.clearAllMocks();  });
会不会误导 AI 或隐藏内容?检查工作说明是否要求 AI 忽略你的指令、干扰检查结果,或夹带看不见的文字。未发现风险
会不会偷偷改推广链接或收款方?检查是否强制替换推广链接或收款对象,同时要求隐瞒更改。未发现风险

Skill 逻辑拆解

8 个说明模块

这是一个测试模式参考指南,内容由配置和示例代码组成;提供的来源中没有安装脚本、自动执行入口或要求提升权限的指令。

查看原文
SKILL.md:2来自说明文档打开原文件
---name: javascript-testing-patternsdescription: Implement comprehensive testing strategies using Jest, Vitest, and Testing Library for unit tests, integration tests, and end-to-end testing with mocking, fixtures, and test-driven development. Use when writing JavaScript/TypeScript tests, setting up test infrastructure, or implementing TDD/BDD workflows.---
SKILL.md:6来自说明文档打开原文件
# JavaScript Testing PatternsComprehensive guide for implementing robust testing strategies in JavaScript/TypeScript applications using modern testing frameworks and best practices.

异步 API 单元测试把全局 fetch 替换为 Vitest 模拟,因此示例测试不会实际联系 api.example.com。

查看原文
SKILL.md:239来自说明文档打开原文件
// Mock fetch globallyglobal.fetch = vi.fn();
SKILL.md:254来自说明文档打开原文件
      (fetch as any).mockResolvedValueOnce({        ok: true,        json: async () => mockUser,      });

邮件示例中的实现会从环境变量读取 SMTP 凭据并发送邮件,但对应测试显式模拟 nodemailer 和 sendMail;只有在用户把服务实现用于非模拟环境时才会产生真实邮件。

查看原文
SKILL.md:308来自说明文档打开原文件
export class EmailService {  private transporter = nodemailer.createTransport({    host: process.env.SMTP_HOST,    port: 587,    auth: {      user: process.env.SMTP_USER,      pass: process.env.SMTP_PASS,    },  });  async sendEmail(to: string, subject: string, html: string) {    await this.transporter.sendMail({      from: process.env.EMAIL_FROM,      to,      subject,      html,    });  }
SKILL.md:331来自说明文档打开原文件
vi.mock("nodemailer", () => ({  default: {    createTransport: vi.fn(() => ({      sendMail: vi.fn().mockResolvedValue({ messageId: "123" }),    })),  },}));
从这里开始 · 工作说明SKILL.md
javascript-testing-patterns
连线表示工作说明包含的模块,不是实际运行顺序。点击模块可查看原文。

文件引用关系图

1 处引用
哪些文件发起引用引用了什么
连线表示真实的文件引用,不是运行顺序。点击节点可高亮相关连线,并查看具体文件和原文位置。虚线表示还有文件需要定位。
文件与检查记录2 个文件

检查范围与遗漏

逐文件查看涉及的内容

下方列出本次涉及的原文范围;纳入检查不代表已查清所有问题。

  • SKILL.md已纳入全文
  • references/advanced-testing-patterns.md已纳入全文

这份报告只针对上方版本。我们看了拿到的代码和说明文件,没有实际运行 Skill,也没有检查它另外安装的软件包。因此,这不是“保证安全”的承诺;换了版本或使用环境,结果也可能不同。

  • SKILL.md工作说明
  • references/advanced-testing-patterns.md配套文件

代码和说明中提到的操作

连接外部网站
SKILL.md:218来自说明文档打开原文件
  async fetchUser(id: string): Promise<User> {    const response = await fetch(`https://api.example.com/users/${id}`);    if (!response.ok) {
SKILL.md:226来自说明文档打开原文件
  async createUser(user: CreateUserDTO): Promise<User> {    const response = await fetch("https://api.example.com/users", {      method: "POST",
SKILL.md:262来自说明文档打开原文件
      expect(user).toEqual(mockUser);      expect(fetch).toHaveBeenCalledWith("https://api.example.com/users/1");    });
读取密钥或账号配置
SKILL.md:309来自说明文档打开原文件
  private transporter = nodemailer.createTransport({    host: process.env.SMTP_HOST,    port: 587,
SKILL.md:312来自说明文档打开原文件
    auth: {      user: process.env.SMTP_USER,      pass: process.env.SMTP_PASS,
SKILL.md:313来自说明文档打开原文件
      user: process.env.SMTP_USER,      pass: process.env.SMTP_PASS,    },
读取了多少行
1,052
文件校验值(用于核对版本)
fb0a025f6be283ab36f8ea499d755ee2221901936c25dfd784bc67294c149518