Skip to content

Add code coverage enforcement and tests#11

Merged
colemancda merged 11 commits into
masterfrom
feature/code-coverage
Jul 18, 2026
Merged

Add code coverage enforcement and tests#11
colemancda merged 11 commits into
masterfrom
feature/code-coverage

Conversation

@colemancda

@colemancda colemancda commented Jul 17, 2026

Copy link
Copy Markdown
Member

Adds code coverage tooling to CI, raises library coverage to effectively 100% of reachable code, and publishes coverage to GitHub Code Quality.

Changes

Tooling

  • Scripts/coverage.sh — runs the test suite with coverage instrumentation, exports LCOV (coverage.lcov) and Cobertura XML (coverage.xml) reports, and enforces a minimum line-coverage threshold (default 80%). Coverage is measured against the CoreModelSQLite library sources only; dependencies, generated sources, and the test target are excluded. The Cobertura report is generated directly from the llvm-cov JSON with no external converter dependency.
  • CI (swift.yml) — new coverage job that:
    • runs the script, failing the build below the threshold
    • uploads the Cobertura report via actions/upload-code-coverage@v1 so the coverage percentage surfaces on pull requests (code-quality: write permission; fail-on-error: false while Code Quality is in public preview)
    • uploads .build/coverage/ as a build artifact

Tests (+51, all exercising behavior through the public API)

  • PredicateTests.swift — predicate-to-SQL WHERE translation: constant/compound predicates, NULL handling, string operators, IN/BETWEEN, to-many membership subqueries (join-table, foreign-key, and symmetric self-relationship branches), function-call comparisons, and error paths.
  • AttributeValueTests.swift — binding round-trips and decode failures for every attribute type.
  • ModelDataTests.swift — row decoding, partial upserts, invalid relationship values.
  • Database branch tests — sort-descriptor validation and function sorts, offset-without-limit, cache invalidation, to-many write branches.

Source

  • One genuinely unreachable COUNT(*) fallback is now marked with assertionFailure, documenting it as an impossible state rather than an untested path.

Result

Before After
Library line coverage 90.64% 99.62% (1045/1049 lines)
Files at 100% 4/10 8/10

The only remaining uncovered lines are defensive assertion paths that cannot execute without violating internal invariants.

Cover the predicate-to-SQL WHERE clause translation paths: constant and compound predicates, NULL handling, string operators, IN/BETWEEN, to-many relationship membership subqueries, function-call comparisons, and error paths. Raises library line coverage to 94.75%.
COUNT(*) always returns a single integer row, so the guard's else branch is unreachable in practice; document that with an assertion.
Cover the storage-class-mismatch decode errors, integer overflow, decimal conversions, and the Binding accessor helpers.
Cover the to-many-on-to-one rejection and the row decode error paths (missing / non-text primary key).
Cover invalid expression shapes, function-call comparison edge cases (NULL, nested arguments, unsupported operators), and scalar/collection binding paths.
Cover to-many relationship writes, no-op upsert, invalid sort property, and custom-function arguments of every storage class.
Cover the symmetric self-relationship join paths (fetch/delete/membership UNION), a missing inverse relationship, and a fetch offset with no limit.
Emit a Cobertura report (coverage.xml) from the llvm-cov JSON, filtered to the library sources, for GitHub Code Quality's actions/upload-code-coverage.
Add the actions/upload-code-coverage step and code-quality:write permission so the coverage percentage surfaces on pull requests. fail-on-error is disabled while the feature is in public preview.
@github-code-quality

Copy link
Copy Markdown

Code Coverage Overview

Languages: Swift

Swift / code-coverage/llvm-cov

The overall coverage in the branch is 100%. Coverage data for the branch is not yet available.

Show a code coverage summary of the most covered files.
File b596ed3 +/-
Sources/CoreMod.../Database.swift 100%
Sources/CoreMod...Predicate.swift 100%
Sources/CoreMod...buteValue.swift 100%
Sources/CoreMod...ModelData.swift 100%
Sources/CoreMod...ationship.swift 100%
Sources/CoreMod...ibuteType.swift 100%
Sources/CoreMod...mFunction.swift 100%
Sources/CoreMod...ewContext.swift 100%
Sources/CoreMod...scription.swift 100%
Sources/CoreMod...Attribute.swift 100%

Code Coverage is in Public Preview. Learn more and provide us with your feedback.

@colemancda
colemancda merged commit eeeb323 into master Jul 18, 2026
28 checks passed
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