一键导入
add-fault-test
Pattern playbook for adding fault injection tests using FaultHarness. Self-certify against this pattern to skip TL design review.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Pattern playbook for adding fault injection tests using FaultHarness. Self-certify against this pattern to skip TL design review.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | add-fault-test |
| description | Pattern playbook for adding fault injection tests using FaultHarness. Self-certify against this pattern to skip TL design review. |
Use this playbook when adding fault injection tests for resilience validation. Following this pattern qualifies for the design review gate exemption — state in your ticket comment that you followed /add-fault-test and note any deviations.
| File | Purpose |
|---|---|
lib/debate/__tests__/faultInjection.ts | FaultHarness class, FaultProfile/Fault/FaultStats types, pre-built AI_FAULT_PROFILES |
lib/debate/__tests__/faultInjection.test.ts | Reference tests — copy patterns from here |
taxonomy-editor/src/server/**/__tests__/*fault*.test.ts | Server-side fault tests |
interface FaultProfile {
name: string;
description: string;
faults: Fault[];
}
interface Fault {
target: FaultTarget; // 'ai-call' | 'storage' | 'rate-limiter' | 'network'
trigger: 'always' | 'nth-call' | 'after-delay' | 'random' | 'match-request';
effect: 'timeout' | 'throw-429' | 'throw-503' | 'throw-enoent' | 'throw-eacces'
| 'corrupt-json' | 'slow-response' | 'auth-fail' | 'circuit-open';
nthCall?: number; // Used with 'nth-call' trigger
delayMs?: number; // Used with 'after-delay' trigger
probability?: number; // Used with 'random' trigger (0.0-1.0)
matchFn?: (url: string, init?: RequestInit) => boolean; // Used with 'match-request'
}
interface FaultStats {
timeouts: number;
retries: number;
fallbackAttempts: number;
errors: number;
}
| Profile | What it does |
|---|---|
silentAiDrop | AI call hangs on 3rd request (nthCall=3, timeout) |
tokenExhaustion | Rate-limit 429 on 5th request |
totalAiOutage | All AI calls return 503 |
flakyNetwork | 30% random timeouts |
authFailFast | Auth fails immediately on every call (401) |
fallbackChainExhaustion | All backends return 503 |
Use a pre-built profile from AI_FAULT_PROFILES if it fits. Otherwise create a custom one:
const myProfile: FaultProfile = {
name: 'storageCorruption',
description: 'JSON file corrupted on disk',
faults: [{ target: 'storage', trigger: 'always', effect: 'corrupt-json' }],
};
import { FaultHarness, AI_FAULT_PROFILES } from '../faultInjection.js';
// or for custom profiles:
import { FaultHarness, type FaultProfile } from '../faultInjection.js';
it('handles silent AI drop with timeout and ActionableError', async () => {
const harness = new FaultHarness(AI_FAULT_PROFILES.silentAiDrop);
harness.install();
try {
// Exercise the code under test
const err = await adapter.generateText('test', 'model-id', { timeoutMs: 10_000 })
.catch((e: unknown) => e);
// Verify behavior under fault
expect(err).toBeInstanceOf(Error);
expect((err as Error).name).toBe('ActionableError');
expect((err as Error).message).toMatch(/timed out/i);
expect(harness.stats.timeouts).toBeGreaterThanOrEqual(1);
} finally {
harness.teardown(); // ALWAYS in finally block
}
});
Every fault test must verify ALL applicable items:
cd taxonomy-editor && npx vitest run --reporter=verbose <your-test-file>
Before marking your ticket done, verify:
harness.install() / harness.teardown() in try/finallyharness.stats assertions verify the fault actually firedvi.useFakeTimers() if needed)npx vitest run <file>harness.teardown() — leaks stubbed fetch into other tests. Always use finally.harness.stats — test passes but fault never fired (wrong trigger config).vi.useFakeTimers() + vi.advanceTimersByTime() instead of real waits.Pattern playbook for adding bridge methods to the taxonomy-editor dual-build architecture. Self-certify against this pattern to skip TL design review.
Pattern playbook for adding REST endpoints to the taxonomy-editor server. Self-certify against this pattern to skip TL design review.
Self-review PowerShell code against the project's PS7 conventions before reporting work as done.
Self-review TypeScript/Electron code against the project's TypeScript Stack Code Review Guide. Run before reporting work as done.
Self-review Python code against the project's Python Packages Code Review Guide. Run before reporting work as done.