Skip to content

test: core-logic unit tests + coverage tooling (46% -> 54%)#1245

Merged
chhoumann merged 1 commit into
masterfrom
test/core-coverage
May 29, 2026
Merged

test: core-logic unit tests + coverage tooling (46% -> 54%)#1245
chhoumann merged 1 commit into
masterfrom
test/core-coverage

Conversation

@chhoumann
Copy link
Copy Markdown
Owner

@chhoumann chhoumann commented May 29, 2026

Builds out the runtime-behavior safety net for the core logic (we had 1126 tests but zero coverage visibility).

Coverage tooling

@vitest/coverage-v8 + a test:coverage script + config (coverage/ gitignored). Baseline was 45.86% statements.

273 new tests across the most under-covered core modules

module before after
services/choiceService 0% 99%
utils/packageTraversal 0% 98%
services/packageExportService 0% 98%
services/packageImportService 0% 95%
formatters/completeFormatter 43% 88%
ai/OpenAIRequest 3% 100%
quickAddApi 35% 93%

Overall statement coverage 45.86% → 54.14%. All tests self-contained (mock Obsidian via vi.mock / fakes; deterministic), and they assert correct behavior — where the code looked wrong, the behavior was not locked in.

One type fix (surfaced by the tests)

The public suggester API declared its displayItems mapper as (value, index?, arr?) => string[], but it's applied per-item via actualItems.map(...) and must return a single string. The old type would reject a correct => string user-script callback. Fixed both signatures — type-only, no runtime change.

Suspected bugs

The tests surfaced 6 suspected bugs (1 medium, 5 low) — filed as a follow-up issue, not encoded into the tests. The notable one: quickAddApi.executeChoice logs an error for an unknown choice but then still calls execute(undefined) instead of returning early.

Verification

bun run test (1399 pass), bun run build-with-lint clean (tsc + eslint + esbuild), bun run check (svelte-check) clean.


Open in Devin Review

Summary by CodeRabbit

Release Notes

  • New Features

    • Updated the suggester API to accept display items as a function returning a single string per item, in addition to arrays of strings.
  • Tests

    • Added comprehensive test suite coverage for core functionality and services.
  • Chores

    • Added test coverage reporting configuration and updated project ignore patterns.

Review Change Stack

Adds @vitest/coverage-v8, a `test:coverage` script, and coverage config, then
273 unit tests across the most under-covered core modules — each goes from
0-43% to 88-100% statement coverage:
- services/choiceService        0  -> 99%
- utils/packageTraversal        0  -> 98%
- services/packageExportService 0  -> 98%
- services/packageImportService 0  -> 95%
- formatters/completeFormatter  43 -> 88%
- ai/OpenAIRequest              3  -> 100%
- quickAddApi                   35 -> 93%
Overall statements 45.86% -> 54.14%.

The tests surfaced an incorrect type on the public `suggester` API: the
displayItems mapper was declared `(value, index?, arr?) => string[]`, but it is
applied per-item via `actualItems.map(...)` and must return a single `string`
(the old type rejected correct user-script callbacks). Fixed both signatures —
type-only, no runtime change.

Other suspected bugs found while writing the tests are filed as a separate issue
and deliberately NOT locked into the tests (the suite asserts correct behavior).
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages Bot commented May 29, 2026

Deploying quickadd with  Cloudflare Pages  Cloudflare Pages

Latest commit: e220d0c
Status: ✅  Deploy successful!
Preview URL: https://bf541b40.quickadd.pages.dev
Branch Preview URL: https://test-core-coverage.quickadd.pages.dev

View logs

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 29, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6f899bd2-f34e-447a-9705-a3bf504b93ab

📥 Commits

Reviewing files that changed from the base of the PR and between 539605d and e220d0c.

⛔ Files ignored due to path filters (1)
  • bun.lock is excluded by !**/*.lock
📒 Files selected for processing (11)
  • .gitignore
  • package.json
  • src/ai/OpenAIRequest.test.ts
  • src/formatters/completeFormatter.test.ts
  • src/quickAddApi.test.ts
  • src/quickAddApi.ts
  • src/services/choiceService.test.ts
  • src/services/packageExportService.test.ts
  • src/services/packageImportService.test.ts
  • src/utils/packageTraversal.test.ts
  • vitest.config.mts

📝 Walkthrough

Walkthrough

This PR adds comprehensive test coverage across the QuickAdd codebase using Vitest: coverage infrastructure (gitignore, npm script, config), a minor refinement to the quickAddApi suggester API signature, and seven new test suites covering the core API, formatters, AI integration, choice/package services, and utility functions.

Changes

Test Coverage & API Refinement

Layer / File(s) Summary
Coverage infrastructure and configuration
.gitignore, package.json, vitest.config.mts
Adds .obsidian-e2e-artifacts and coverage/ ignore patterns, introduces test:coverage npm script with @vitest/coverage-v8 dependency, and configures Vitest v8 coverage with text-summary and json-summary reporters.
QuickAddApi suggester signature refinement
src/quickAddApi.ts
Updates displayItems callback type to return single string per item instead of string[] in both GetApi().suggester() and static QuickAddApi.suggester() method signatures.
QuickAddApi comprehensive test suite
src/quickAddApi.test.ts
Tests static prompt wrappers (input/date/suggester) with cancellation handling, GetApi delegation, date helpers, selection utilities, AI sync validation, executeChoice/format variable management, requestInputs modal flow with date formatting, and fieldSuggestions frontmatter/inline-field collection with caching.
CompleteFormatter token processing test suite
src/formatters/completeFormatter.test.ts
Covers token expansion (GLOBAL_VAR, links, title, selection, clipboard, VALUE, VDATE, MVALUE, FIELD) with error handling for missing files, circular-dependency prevention, selection short-circuiting, cancellation mapping, and dependency injection of date parsers and choice executors.
OpenAIRequest multi-provider test suite
src/ai/OpenAIRequest.test.ts
Tests guard clauses for disabled online features and token limits, OpenAI/Anthropic/Gemini request construction and response mapping with provider-specific headers/body formats, logging lifecycle with cause preservation, and cursor/selection restoration after dispatch.
ChoiceService CRUD and management test suite
src/services/choiceService.test.ts
Tests choice creation with unique ids, deep duplication with recursive Multi/Macro id regeneration, builder selection, deletion confirmation messaging, configuration modal flow, immutable toggle-command creation, command registry wiring, and moveChoice with cycle prevention and immutability.
Package export generation and persistence test suite
src/services/packageExportService.test.ts
Tests generateDefaultPackagePath with timestamp sanitization, buildPackage with metadata/deterministic createdAt/nested-child handling/excluded-choice pruning/asset collection with deduplication, and writePackageToVault with JSON serialization/path normalization/recursive folder creation.
Package import and duplication test suite
src/services/packageImportService.test.ts
Tests parseQuickAddPackage schema validation, readQuickAddPackage path handling, analysePackage conflict detection with pathHint defaulting, applyPackageImport root/tree insertion, duplicate-id remapping with reference updates and Multi child filtering, and asset import with base64 decoding and nested path rewrites.
Package traversal and dependency collection test suite
src/utils/packageTraversal.test.ts
Tests collectChoiceClosure with BFS catalog construction, Macro/Conditional dependency following, inline NestedChoice handling, cycle termination, missing/excluded-id reporting, collectScriptDependencies with user-script and conditional collection, and collectFileDependencies with template/capture-template rules.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly related PRs

  • chhoumann/quickadd#1146: Extends test coverage for collectChoiceClosure, collectScriptDependencies, and collectFileDependencies functions, which are the core traversal behaviors tested in the package traversal utility layer.

Suggested labels

released

Poem

🐰 Tests now bloom across the codebase wide,
Each API, formatter, service verified with pride,
From QuickAdd's heart to package imports' flow,
Coverage gathered—now developers know! ✨

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/core-coverage

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@chhoumann chhoumann merged commit e9a9a06 into master May 29, 2026
7 of 9 checks passed
@chhoumann chhoumann deleted the test/core-coverage branch May 29, 2026 10:51
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

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