mirror of
https://github.com/codeaashu/claude-code.git
synced 2026-04-08 22:28:48 +03:00
3.2 KiB
3.2 KiB
Prompt 16: Add Test Infrastructure & Smoke Tests
Context
You are working in /workspaces/claude-code. The leaked source does not include any test files or test configuration (they were presumably in a separate directory or repo). We need to add a test framework and write smoke tests for core subsystems.
Task
Part A: Set up Vitest
bun add -d vitest @types/node
Create vitest.config.ts:
import { defineConfig } from 'vitest/config'
import { resolve } from 'path'
export default defineConfig({
test: {
globals: true,
environment: 'node',
include: ['tests/**/*.test.ts'],
setupFiles: ['tests/setup.ts'],
testTimeout: 30000,
},
resolve: {
alias: {
'bun:bundle': resolve(__dirname, 'src/shims/bun-bundle.ts'),
},
},
})
Create tests/setup.ts:
// Global test setup
import '../src/shims/preload.js'
Add to package.json:
{
"scripts": {
"test": "vitest run",
"test:watch": "vitest"
}
}
Part B: Write unit tests for shims
tests/shims/bun-bundle.test.ts:
- Test
feature()returnsfalsefor unknown flags - Test
feature()returnsfalsefor disabled flags - Test
feature()returnstruewhen env var is set - Test
feature('ABLATION_BASELINE')always returnsfalse
tests/shims/macro.test.ts:
- Test
MACRO.VERSIONis a string - Test
MACRO.PACKAGE_URLis set - Test
MACRO.ISSUES_EXPLAINERis set
Part C: Write smoke tests for core modules
tests/smoke/tools.test.ts:
- Test that
getTools()returns an array - Test that each tool has: name, description, inputSchema
- Test that BashTool, FileReadTool, FileWriteTool are present
tests/smoke/commands.test.ts:
- Test that
getCommands()returns an array - Test that each command has: name, execute function
- Test that /help and /config commands exist
tests/smoke/context.test.ts:
- Test that
getSystemContext()returns OS info - Test that git status can be collected
- Test that platform detection works on Linux
tests/smoke/prompt.test.ts:
- Test that
getSystemPrompt()returns a non-empty array - Test that the prompt includes tool descriptions
- Test that MACRO references are resolved (no
undefined)
Part D: Write integration tests (if API key available)
tests/integration/api.test.ts:
- Skip if
ANTHROPIC_API_KEYis not set - Test API client creation
- Test a simple message (hello world)
- Test streaming works
- Test tool use (calculator-style tool call)
tests/integration/mcp.test.ts:
- Test MCP server starts
- Test MCP client connects
- Test tool listing
- Test tool execution roundtrip
Part E: Write build tests
tests/build/bundle.test.ts:
- Test that
dist/cli.mjsexists after build - Test that it has a shebang
- Test that it's not empty
- Test that
node dist/cli.mjs --versionexits cleanly
Part F: Add pre-commit hook (optional)
If the project uses git hooks, add:
# In package.json or a git hook
bun run typecheck && bun run test
Verification
bun run testruns all tests- Shim tests pass
- Smoke tests pass (tools, commands, context, prompts load)
- Integration tests are skipped when no API key is set
- Integration tests pass when API key is available
- Test output is clear and readable