Skip to content

[nightshift] test-gap: 54 of 61 source files have zero test coverage (~4.7% test-to-code ratio) #19

@nightshift-micr

Description

@nightshift-micr

Test Coverage Gap Analysis — micr-dev/blog

Executive Summary

Metric Value
Source files (non-test, non-type-decl) 61 files (~4,554 LOC)
Test files 3 files (212 LOC)
Tests 12 passing
Test framework Vitest 4.1 (node environment)
Test-to-code ratio ~4.7% by LOC
Modules with any test coverage 5 of 61 files (~8%)
Estimated functional coverage ~15-20% of pure-logic code

Files WITH Tests

Source File Test File What's Tested
src/lib/post-parser.ts src/lib/posts.test.ts parseEditablePost, default merging, frontmatter parsing
src/lib/posts.ts src/lib/posts.test.ts slugifyTag
src/lib/mdx.tsx src/lib/mdx.test.ts renderMdx (shortcodes, mermaid fallback, ascii fences), getFontStyleSheet, getThemeStyle
src/lib/mermaid-ascii.ts src/lib/mdx.test.ts renderMermaidAscii (flowcharts, sequences)
src/lib/share-links.ts src/lib/share-links.test.ts buildShareHref (x, bluesky, linkedin)

Files WITHOUT Tests

54 source files have zero test coverage, including all React components, all route pages, the API proxy, and several utility modules.


Critical Test Gaps

P0 — High Severity

1. src/lib/post-parser.ts — Zod validation edge cases

  • Gap: Only happy-path parsing tested. No tests for missing frontmatter, invalid YAML, malformed dates, empty required fields.
  • Recommended tests: Missing --- delimiters, invalid YAML, empty title/date/excerpt, non-date strings for date, missing optional fields.
  • Effort: 2–3 hours

2. src/lib/posts.ts — Post loading, tag aggregation, adjacent posts

  • Gap: Only slugifyTag tested. Critical functions untested: getPostBySlug, getPostIndex, getTags, getPostsByTag, getAdjacentPosts, formatDate.
  • Recommended tests: formatDate() edge cases, getAdjacentPosts() first/last/empty, getTags() dedup/count, getPostBySlug() null returns.
  • Effort: 3–4 hours

3. src/lib/mermaid-ascii.ts — Parser edge cases

  • Gap: Only simple flowchart/sequence tested. Complex regex logic with many untested branches.
  • Recommended tests: Empty input, edge labels, different arrow types, node shapes, unknown diagram types, malformed lines.
  • Effort: 2–3 hours

P1 — Medium-High Severity

4. src/lib/mdx.tsx — MDX component rendering edge cases

  • Gap: Happy paths only. Many getMdxComponents branches untested.
  • Effort: 3–4 hours

5. src/lib/og.tsx — OG image layout calculations

  • Gap: Pure functions getOgTitleStyle, getScytheFrame, getOgPreviewTheme completely untested.
  • Effort: 1–2 hours

6. src/lib/og-assets.ts — SVG manipulation

  • Gap: tintSvg, cropScytheSvg, svgToDataUri are pure functions that could be tested.
  • Effort: 1 hour

P2 — Medium Severity

7. src/components/search-page.tsx (169 LOC) — Search functionality

  • Gap: Largest component with zero tests. Extract search/filter logic into pure utility for testing.
  • Effort: 2–3 hours

8. src/components/local-editor.tsx (305 LOC) — MDX editor

  • Gap: Largest file, completely untested. Contains file-system access and editor state management.
  • Effort: 3–4 hours

9. src/app/sitemap.ts — Sitemap generation

  • Gap: No tests verify correct URL structure.
  • Effort: 1 hour

10. src/app/api/agentation/[...path]/route.ts — API proxy

  • Gap: Request forwarding, header stripping, dev-only guard untested.
  • Effort: 1–2 hours

Recommendations

Immediate Actions

  1. Add coverage reporting — Add "test:coverage": "vitest run --coverage" and install @vitest/coverage-v8.
  2. Expand post-parser.ts tests — Zod schema validation is the most critical safety net. Malformed frontmatter could crash the blog.
  3. Test posts.ts functions — Mock filesystem and test all exported functions.
  4. Expand mermaid-ascii.ts tests — Many regex patterns need edge case coverage.

Configuration Improvements

  1. Enable *.test.tsx — vitest config include should be ["src/**/*.test.{ts,tsx}"].
  2. Add jsdom environment for component tests — @testing-library/react requires DOM.

Generated by Nightshift v3 (GLM 5.1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    dayshift/failedManaged by hermes-dayshift-glm

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions