Debug issues and write tests for deployed applications. Use this skill when the user reports bugs, wants to add tests, or needs help troubleshooting. Covers unit testing for rapid iteration, browser console debugging, and systematic bug reproduction.
Standardmäßig ist der Prompt ausgewählt, der zuerst die Quelle prüft. Sie können zu einem direkten Befehl wechseln oder eine lokale Kopie herunterladen.
Quelldateien prüfen
Lesen Sie SKILL.md und alle von SkillsMP angezeigten Begleitdateien, bevor Sie sich für eine Installation entscheiden.
Mit Codex oder Claude installieren Kopieren Sie diesen Prompt, fügen Sie ihn in Codex, Claude oder einen anderen Assistant ein und lassen Sie die Skill-Seite prüfen und installieren.
Ein direkter Befehl überspringt den Prüf-Prompt. Prüfen Sie die Quelle, bevor Sie ihn ausführen.
Debug issues and write tests for deployed applications. Use this skill when the user reports bugs, wants to add tests, or needs help troubleshooting. Covers unit testing for rapid iteration, browser console debugging, and systematic bug reproduction.
license
Complete terms in LICENSE.txt
Testing and Debugging
This skill guides debugging deployed applications and writing tests for rapid iteration. The key insight: unit tests are the fastest way to reproduce and fix bugs.
The Unit Test Debugging Workflow
This is the most effective debugging workflow. Instead of repeatedly deploying and manually testing in the browser, write a unit test that reproduces the bug:
Why Unit Tests for Debugging?
Approach
Cycle Time
Reliability
Deploy → Browser → Manual test
30-60 seconds
Variable
Run unit test
1-2 seconds
Consistent
A 30x speedup means you can iterate 30 times faster. This compounds: what takes an hour with manual testing takes 2 minutes with unit tests.
The Workflow
Understand the bug - Read the user report, check console errors, understand expected vs actual behavior
Write a failing test - Create a test that reproduces the exact failure
// Example: User reports "discount not applied to cart total"test('applies discount code to cart total', () => {
const cart = createCart([
{ name: 'Widget', price: 100 },
{ name: 'Gadget', price: 50 }
]);
cart.applyDiscount('SAVE20'); // 20% offexpect(cart.total).toBe(120); // Was returning 150
});
Run the test to confirm it fails - Verify you've reproduced the bug
bun test
Fix the code - Make changes to fix the failing test
Run the test again - Confirm the fix works
bun test
Deploy - Once tests pass, publish through the mediated project tool (not a package-manager or Wrangler deploy command)
import { vi } from'vitest';
test('displays error when API fails', async () => {
// Mock the fetch to simulate API failure
vi.spyOn(global, 'fetch').mockRejectedValue(newError('Network error'));
const result = awaitloadUserData('user-123');
expect(result.error).toBe('Failed to load user data');
});
functionprocessOrder(order: Order) {
debugger; // Browser will pause here when DevTools is open// ... rest of function
}
Common Bug Patterns
Off-by-One Errors
// Bug: Loop skips last itemfor (let i = 0; i < items.length - 1; i++) { ... }
// Fix: Include last itemfor (let i = 0; i < items.length; i++) { ... }
Async/Await Issues
// Bug: Not awaiting async functionfunctionloadData() {
const data = fetchData(); // Returns Promise, not data!returnprocessData(data);
}
// Fix: Await the promiseasyncfunctionloadData() {
const data = awaitfetchData();
returnprocessData(data);
}
Type Coercion
// Bug: String concatenation instead of additionconst total = price + tax; // "100" + "10" = "10010"// Fix: Parse numbersconst total = Number(price) + Number(tax); // 110
Null/Undefined Access
// Bug: Accessing property on undefinedconst name = user.profile.name; // Crashes if profile is undefined// Fix: Optional chainingconst name = user?.profile?.name ?? 'Unknown';
Test Commands
# Run all tests
bun test# Run tests in watch mode (re-runs on file changes)
bun test --watch
# Run a specific test file
bun test src/cart.test.ts
# Run tests matching a pattern
bun test -t "discount"# Run with coverage report
bun test --coverage
Visual Verification
Screenshots and browser sessions are opt-in verification tools, not an automatic post-deploy step. A successful deploy is enough for routine build-and-ship requests. Use these tools when the user asks for visual/browser/E2E verification, the task is specifically diagnosing a deployed UI/runtime issue, or browser evidence is explicitly required.
For a requested deployed app UI check, use js_exec:
This uses Cloudflare Browser Rendering through the platform binding, including
for access-controlled apps. Prefer unit/integration tests with Vitest for logic
and API behavior.
Interactive Browser Testing
For requested or task-required end-to-end checks of a deployed app — clicking
buttons, filling forms, asserting rendered text, catching console errors —
launch an interactive browser session in js_exec with env.BROWSER. Do not add
this pass automatically after a successful deploy. It runs on Cloudflare
Browser Rendering (access-controlled apps included) and exposes a
Playwright-style API:
const b = await env.BROWSER.launch({ scriptName: "my-app", path: "/" });
try {
await b.fill("#todo-input", "buy milk");
await b.click("button[type=submit]");
await b.waitForText("buy milk"); // throws if it never appearsif (!await b.hasText("buy milk")) thrownewError("todo is not visible");
const count = await b.count(".todo-item");
if (count !== 1) thrownewError(`expected 1 todo, got ${count}`);
const logs = await b.logs(); // { console, pageErrors, requestFailures }if (logs.pageErrors.length) thrownewError(`page errors: ${logs.pageErrors.join("; ")}`);
} {
b.();
}
Other session methods: goto, type, press, select, hover, waitForSelector, waitForFunction, waitForTimeout (fixed sleep in ms — prefer the condition-based waits), evaluate (run JS in the page), textContent (no selector returns visible body text), hasText (immediate boolean check), getAttribute, exists, content (HTML), url, title, screenshot. press(key) dispatches to the currently focused element/page; pass { selector } to focus first, and verify its effect from UI state rather than assuming an application listener handled it. Run await tools.help({ runtime: "env.BROWSER" }) for full usage. Keep the whole test inside one js_exec call, always close() the session, and note sessions auto-close after 5 minutes.
Limitation: for access-controlled apps, server-streamed responses (Server-Sent
Events / streaming fetch) are buffered by the session's request proxy, so
realtime/SSE-driven UI updates will not arrive mid-session. Standard
request/response and interaction testing works normally. On hosted camelAI, a
public deploy avoids this proxy limitation only when the user has authorized
public visibility. Self-hosted enterprise apps cannot be made public; use
direct authenticated browser/E2E coverage where available, or unit/integration
tests for the streaming path.