Skip to content

feat: CLI scanner — static test quality analysis AB#434#1

Merged
i-kosheliev merged 3 commits into
mainfrom
feature/434-cli-scanner
Apr 14, 2026
Merged

feat: CLI scanner — static test quality analysis AB#434#1
i-kosheliev merged 3 commits into
mainfrom
feature/434-cli-scanner

Conversation

@i-kosheliev

Copy link
Copy Markdown
Owner

Summary

  • New CLI: npx @iklab/testkit scan ./tests — static test quality scanner
  • AST-based analysis using acorn + @sveltejs/acorn-typescript
  • Two-tier scanning: structure extraction + code body analysis

What it detects

  • Flaky code patterns: setTimeout, fetch, Date.now, Math.random, process.env, fs I/O
  • Missing assertions (no expect/assert in test body)
  • Conditional assertions (expect inside if/else)
  • Focused tests (.only) and skipped tests (.skip, x-prefix)
  • Duplicate test names across files (Jaccard similarity)
  • Flaky descriptions (via existing flaky() function)

CLI options

  • --json — JSON output for CI integration
  • --threshold <1-10> — min flakiness score to report
  • --no-duplicates — skip duplicate detection
  • --no-code-analysis — descriptions only
  • --pattern <glob> — custom file pattern

Test plan

  • 24 new scanner tests passing
  • 126 existing tests still passing (150 total)
  • Smoke test: scans testkit's own tests successfully
  • Build produces library + CLI outputs

AB#434

🤖 Generated with Claude Code

i-kosheliev and others added 3 commits April 14, 2026 01:43
npx @iklab/testkit scan ./tests — analyzes test files for:
- Flaky code patterns (setTimeout, fetch, Date.now, Math.random, process.env, fs I/O)
- Missing assertions (test bodies without expect/assert)
- Conditional assertions (expect inside if/else)
- Focused tests (.only) and skipped tests (.skip, x-prefix)
- Duplicate test names across files (Jaccard similarity)
- Flaky descriptions (reuses existing flaky() function)

Architecture: AST-based using acorn + @sveltejs/acorn-typescript.
Two-tier analysis: structure extraction + code body scanning.
Text output with ANSI colors + --json flag for CI.
Exit codes: 0 clean, 1 issues found, 2 fatal error.

24 new tests (scanner.test.ts), 150 total passing.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1. process.env: changed isMemberCall to isMemberAccess — was checking
   for process.env() (CallExpression) instead of process.env.X
   (MemberExpression). Pattern never triggered before this fix.
2. Symlink cycle protection: walkDir now tracks visited real paths
   via realpathSync() + Set. Max depth 50 prevents stack overflow.
3. File size limit: CLI skips files > 5MB to prevent OOM on huge
   generated files.
4. New test: process.env detection in flaky fixture.

151 tests passing.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
9 new tests:
- globToRegex: wildcard, question mark, dot escaping, exact match
- text-reporter: header, clean report, summary stats
- json-reporter: valid JSON, all sections present

Also exported globToRegex for testing.
160 total tests passing.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@i-kosheliev i-kosheliev merged commit a710119 into main Apr 14, 2026
3 checks passed
@i-kosheliev i-kosheliev deleted the feature/434-cli-scanner branch April 14, 2026 00:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant