Skip to content

Add comprehensive tests for validation and transformation functions#151

Merged
hawkeyexl merged 4 commits intomainfrom
coverage
Jan 7, 2026
Merged

Add comprehensive tests for validation and transformation functions#151
hawkeyexl merged 4 commits intomainfrom
coverage

Conversation

@hawkeyexl
Copy link
Contributor

@hawkeyexl hawkeyexl commented Jan 7, 2026

  • Create a new test file validate.test.js to cover various scenarios for the validate and transformToSchemaKey functions.
  • Implement tests for input validation, including checks for missing, null, and empty schema keys, as well as missing or null objects.
  • Add tests to verify behavior when schemas are not found and for valid objects against defined schemas.
  • Include tests for invalid objects to ensure proper error handling and validation feedback.
  • Test backward compatibility by transforming v2 schemas to v3 and validating the results.
  • Ensure original objects remain unchanged after validation.
  • Cover transformation scenarios for various schema types, including config, context, and openApi transformations.
  • Implement error handling tests to confirm that invalid transformations throw appropriate errors.

Summary by CodeRabbit

  • New Features

    • Added automated code-coverage reporting with enforced baseline checks and HTML/text/json reporting.
  • Tests

    • Expanded and reorganized unit tests for file handling, path resolution, validation, and transformation to improve coverage and edge-case handling.
  • Documentation

    • Added comprehensive TDD, coverage, and testing guidance with examples and command references.
  • Chores

    • Integrated coverage checks into CI and added test scripts plus an automated ratchet-check tool for coverage baselines.

✏️ Tip: You can customize this high-level summary in your review settings.

- Create a new test file `validate.test.js` to cover various scenarios for the `validate` and `transformToSchemaKey` functions.
- Implement tests for input validation, including checks for missing, null, and empty schema keys, as well as missing or null objects.
- Add tests to verify behavior when schemas are not found and for valid objects against defined schemas.
- Include tests for invalid objects to ensure proper error handling and validation feedback.
- Test backward compatibility by transforming v2 schemas to v3 and validating the results.
- Ensure original objects remain unchanged after validation.
- Cover transformation scenarios for various schema types, including config, context, and openApi transformations.
- Implement error handling tests to confirm that invalid transformations throw appropriate errors.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 7, 2026

Warning

Rate limit exceeded

@hawkeyexl has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 7 minutes and 27 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between f4a86c1 and 1b01e23.

📒 Files selected for processing (3)
  • scripts/check-coverage-ratchet.js
  • src/resolvePaths.js
  • src/validate.js

Walkthrough

Adds coverage tooling and enforcement: c8 config, 100% baseline file, a ratchet check script, CI steps to run and upload coverage, new npm scripts and c8 devDependency, coverage-ignore pragmas in two sources, expanded tests, and TDD/coverage documentation.

Changes

Cohort / File(s) Summary
Coverage config & thresholds
\.c8rc.json, coverage-thresholds.json
New c8 configuration enabling all coverage, including src and excluding src/schemas/dereferenceSchemas.js; baseline file sets lines/statements/functions/branches = 100.
Ratchet enforcement script
scripts/check-coverage-ratchet.js
New Node script comparing coverage/coverage-summary.json to coverage-thresholds.json, printing diffs, suggesting updates on improvements, and exiting non‑zero on regressions or invalid/missing data.
CI workflows
.github/workflows/auto-dev-release.yml, .github/workflows/npm-test.yml
Adds job/steps to run npm run test:coverage, npm run test:coverage:ratchet, and upload coverage/ artifact; conditional step in release workflow.
Package scripts & devDependency
package.json
Adds c8 to devDependencies and scripts: test:coverage, test:coverage:html, test:coverage:check, test:coverage:ratchet.
Documentation & guidance
.claude/skills/tdd-coverage/SKILL.md, AGENTS.md, CLAUDE.md
New/updated docs describing a strict TDD/coverage process, test mappings, commands, CI guidance, examples, and testing requirements.
Source coverage pragmas
src/resolvePaths.js, src/validate.js
Added /* c8 ignore start */ / /* c8 ignore stop */ blocks around examples or dead-code regions; no behavioral changes.
Test suite expansion
test/files.test.js, test/resolvePaths.test.js, test/validate.test.js
Reorganized and substantially expanded tests covering input validation, remote/local parsing, resolvePaths path resolution, validate transformations/backcompat, and many edge cases.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    actor CI as GitHub Actions
    participant Repo as Repository
    participant Runner as Job Runner / npm
    participant C8 as c8 (instrumenter)
    participant Coverage as coverage/coverage-summary.json
    participant Ratchet as check-coverage-ratchet.js
    participant Baseline as coverage-thresholds.json

    CI->>Repo: workflow trigger
    CI->>Runner: run `npm run test:coverage`
    Runner->>C8: instrument & execute tests
    C8->>Coverage: write coverage-summary.json
    Runner-->>CI: tests finished (reports produced)

    CI->>Runner: run `npm run test:coverage:ratchet`
    Runner->>Ratchet: execute ratchet script
    Ratchet->>Baseline: load baseline thresholds
    Ratchet->>Coverage: load current metrics
    alt any metric < baseline
        Ratchet-->>CI: exit 1 (regression)
    else any metric > baseline
        Ratchet-->>CI: exit 0 (suggest update)
    else metrics == baseline
        Ratchet-->>CI: exit 0 (ok)
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 I hopped through scripts and tests with glee,

Counting branches, lines, and each decree,
The ratchet hums to guard the score,
Coverage baked and docs galore,
A rabbit cheers: keep quality! 🐇

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately summarizes the main objective: adding comprehensive tests for validation and transformation functions, which aligns with the primary change of introducing validate.test.js and other test files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In @AGENTS.md:
- Around line 143-151: Update the AGENTS.md coverage table to match
coverage-thresholds.json by changing all metric thresholds to 100% (Lines,
Statements, Functions, Branches); replace the existing values (98.3%, 98.3%,
100%, 95.28%) in the "Current coverage thresholds" table with 100% for each
metric so the documentation matches the actual configuration.
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8c9891d and 6e13e96.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (14)
  • .c8rc.json
  • .claude/skills/tdd-coverage/SKILL.md
  • .github/workflows/auto-dev-release.yml
  • .github/workflows/npm-test.yml
  • AGENTS.md
  • CLAUDE.md
  • coverage-thresholds.json
  • package.json
  • scripts/check-coverage-ratchet.js
  • src/resolvePaths.js
  • src/validate.js
  • test/files.test.js
  • test/resolvePaths.test.js
  • test/validate.test.js
🧰 Additional context used
📓 Path-based instructions (6)
**/*.{js,ts}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{js,ts}: Always clone objects using JSON.parse(JSON.stringify(object)) before validation to avoid mutations
validate() returns { valid, errors, object } and never throws; handle errors via return object
transformToSchemaKey() throws on incompatible schemas or invalid results; catch exceptions when calling this function
readFile() returns null on errors and logs warnings to console; do not assume errors throw exceptions
resolvePaths() throws on invalid object types or missing nested object types; validate inputs before calling
Do not assume validation mutates objects; always handle the returned validated object

Files:

  • src/resolvePaths.js
  • scripts/check-coverage-ratchet.js
  • test/validate.test.js
  • test/files.test.js
  • src/validate.js
  • test/resolvePaths.test.js
src/**/*.js

📄 CodeRabbit inference engine (AGENTS.md)

Use escapeRegExp() helper when converting user strings to regex patterns in transformToSchemaKey()

Files:

  • src/resolvePaths.js
  • src/validate.js
src/resolvePaths.js

📄 CodeRabbit inference engine (AGENTS.md)

src/resolvePaths.js: Path resolution respects config.relativePathBase setting: 'file' (relative to file location) or 'cwd' (relative to working directory)
Skip path resolution for HTTP(S) URLs, already-absolute paths, and user data properties (e.g., requestData)
Resolve path property relative to directory if directory is absolute (special case in resolvePaths)
For new config path properties, add to configPaths in resolvePaths.js; for spec properties, add to specPaths

Files:

  • src/resolvePaths.js
test/*.test.js

📄 CodeRabbit inference engine (AGENTS.md)

test/*.test.js: Test structure uses Mocha + Chai; validate schema examples in test/schema.test.js (auto-generated from schemas)
Use dynamic import for Chai in test files for ESM compatibility

Files:

  • test/validate.test.js
  • test/files.test.js
  • test/resolvePaths.test.js
test/files.test.js

📄 CodeRabbit inference engine (AGENTS.md)

Use Sinon stubs in test/files.test.js for mocking external dependencies in file reading tests

Files:

  • test/files.test.js
src/validate.js

📄 CodeRabbit inference engine (AGENTS.md)

src/validate.js: Enable AJV configuration options: coerceTypes: true, useDefaults: true for automatic type conversion and default value application
Dynamic defaults must generate unique IDs for stepId and configId fields using uuid when useDefaults is enabled
When creating new schema version (e.g., v4), update compatibleSchemas map and add transformation logic in transformToSchemaKey()
Handle schema property transformations: typeKeys.delay → type.inputDelay, maxVariation (0-100) → (0-1), and app → browsers structure changes
All step_v3 schemas must accept 12 different v2 action schemas (checkLink_v2, find_v2, etc.) via compatibleSchemas map

Files:

  • src/validate.js
🧠 Learnings (26)
📓 Common learnings
Learnt from: CR
Repo: doc-detective/common PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T23:59:43.235Z
Learning: Applies to src/validate.js : When creating new schema version (e.g., v4), update compatibleSchemas map and add transformation logic in transformToSchemaKey()
Learnt from: CR
Repo: doc-detective/common PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T23:59:43.235Z
Learning: Applies to test/*.test.js : Test structure uses Mocha + Chai; validate schema examples in test/schema.test.js (auto-generated from schemas)
📚 Learning: 2025-11-25T23:59:43.235Z
Learnt from: CR
Repo: doc-detective/common PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T23:59:43.235Z
Learning: Applies to src/resolvePaths.js : For new config path properties, add to configPaths in resolvePaths.js; for spec properties, add to specPaths

Applied to files:

  • src/resolvePaths.js
  • test/resolvePaths.test.js
📚 Learning: 2025-11-25T23:59:43.235Z
Learnt from: CR
Repo: doc-detective/common PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T23:59:43.235Z
Learning: Applies to **/*.{js,ts} : resolvePaths() throws on invalid object types or missing nested object types; validate inputs before calling

Applied to files:

  • src/resolvePaths.js
  • AGENTS.md
  • src/validate.js
  • test/resolvePaths.test.js
📚 Learning: 2025-11-25T23:59:43.235Z
Learnt from: CR
Repo: doc-detective/common PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T23:59:43.235Z
Learning: Applies to src/resolvePaths.js : Skip path resolution for HTTP(S) URLs, already-absolute paths, and user data properties (e.g., requestData)

Applied to files:

  • src/resolvePaths.js
  • test/resolvePaths.test.js
📚 Learning: 2025-11-25T23:59:43.235Z
Learnt from: CR
Repo: doc-detective/common PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T23:59:43.235Z
Learning: Applies to src/resolvePaths.js : Resolve path property relative to directory if directory is absolute (special case in resolvePaths)

Applied to files:

  • src/resolvePaths.js
  • test/resolvePaths.test.js
📚 Learning: 2025-11-25T23:59:43.235Z
Learnt from: CR
Repo: doc-detective/common PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T23:59:43.235Z
Learning: Applies to src/resolvePaths.js : Path resolution respects config.relativePathBase setting: 'file' (relative to file location) or 'cwd' (relative to working directory)

Applied to files:

  • src/resolvePaths.js
  • test/resolvePaths.test.js
📚 Learning: 2025-11-25T23:59:43.235Z
Learnt from: CR
Repo: doc-detective/common PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T23:59:43.235Z
Learning: GitHub Actions npm-test runs full matrix tests across OS (ubuntu, windows, macos) and Node versions (18, 20, 22, 24)

Applied to files:

  • .github/workflows/npm-test.yml
  • .github/workflows/auto-dev-release.yml
📚 Learning: 2025-11-25T23:59:43.235Z
Learnt from: CR
Repo: doc-detective/common PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T23:59:43.235Z
Learning: Applies to test/*.test.js : Test structure uses Mocha + Chai; validate schema examples in test/schema.test.js (auto-generated from schemas)

Applied to files:

  • AGENTS.md
  • CLAUDE.md
  • .claude/skills/tdd-coverage/SKILL.md
  • test/validate.test.js
  • test/files.test.js
  • src/validate.js
  • package.json
  • test/resolvePaths.test.js
📚 Learning: 2025-11-25T23:59:43.235Z
Learnt from: CR
Repo: doc-detective/common PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T23:59:43.235Z
Learning: Applies to src/validate.js : When creating new schema version (e.g., v4), update compatibleSchemas map and add transformation logic in transformToSchemaKey()

Applied to files:

  • AGENTS.md
  • test/validate.test.js
  • src/validate.js
📚 Learning: 2025-11-25T23:59:43.235Z
Learnt from: CR
Repo: doc-detective/common PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T23:59:43.235Z
Learning: Applies to src/validate.js : Handle schema property transformations: typeKeys.delay → type.inputDelay, maxVariation (0-100) → (0-1), and app → browsers structure changes

Applied to files:

  • AGENTS.md
  • test/validate.test.js
  • src/validate.js
📚 Learning: 2025-11-25T23:59:43.235Z
Learnt from: CR
Repo: doc-detective/common PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T23:59:43.235Z
Learning: Applies to **/*.{js,ts} : validate() returns { valid, errors, object } and never throws; handle errors via return object

Applied to files:

  • AGENTS.md
  • .claude/skills/tdd-coverage/SKILL.md
  • test/validate.test.js
  • src/validate.js
📚 Learning: 2025-11-25T23:59:43.235Z
Learnt from: CR
Repo: doc-detective/common PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T23:59:43.235Z
Learning: Applies to **/*.{js,ts} : transformToSchemaKey() throws on incompatible schemas or invalid results; catch exceptions when calling this function

Applied to files:

  • AGENTS.md
  • test/validate.test.js
  • src/validate.js
📚 Learning: 2025-11-25T23:59:43.235Z
Learnt from: CR
Repo: doc-detective/common PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T23:59:43.235Z
Learning: Applies to test/*.test.js : Use dynamic import for Chai in test files for ESM compatibility

Applied to files:

  • AGENTS.md
  • test/files.test.js
  • package.json
📚 Learning: 2025-11-25T23:59:43.235Z
Learnt from: CR
Repo: doc-detective/common PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T23:59:43.235Z
Learning: Applies to src/schemas/src_schemas/*.json : Always include examples array in all schemas (required for test generation)

Applied to files:

  • AGENTS.md
📚 Learning: 2025-11-25T23:59:43.235Z
Learnt from: CR
Repo: doc-detective/common PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T23:59:43.235Z
Learning: Do not edit generated files directly: build/, output_schemas/, or schemas.json (regenerated on npm run build)

Applied to files:

  • AGENTS.md
📚 Learning: 2025-11-25T23:59:43.235Z
Learnt from: CR
Repo: doc-detective/common PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T23:59:43.235Z
Learning: Applies to **/*.{js,ts} : Do not assume validation mutates objects; always handle the returned validated object

Applied to files:

  • AGENTS.md
  • test/validate.test.js
  • src/validate.js
📚 Learning: 2025-11-25T23:59:43.235Z
Learnt from: CR
Repo: doc-detective/common PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T23:59:43.235Z
Learning: Applies to **/*.{js,ts} : Always clone objects using JSON.parse(JSON.stringify(object)) before validation to avoid mutations

Applied to files:

  • AGENTS.md
  • test/validate.test.js
  • src/validate.js
📚 Learning: 2025-11-25T23:59:43.235Z
Learnt from: CR
Repo: doc-detective/common PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T23:59:43.235Z
Learning: Applies to src/validate.js : Dynamic defaults must generate unique IDs for stepId and configId fields using uuid when useDefaults is enabled

Applied to files:

  • AGENTS.md
  • test/validate.test.js
📚 Learning: 2025-11-25T23:59:43.235Z
Learnt from: CR
Repo: doc-detective/common PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T23:59:43.235Z
Learning: Applies to src/validate.js : All step_v3 schemas must accept 12 different v2 action schemas (checkLink_v2, find_v2, etc.) via compatibleSchemas map

Applied to files:

  • test/validate.test.js
  • src/validate.js
📚 Learning: 2025-08-22T20:01:21.087Z
Learnt from: hawkeyexl
Repo: doc-detective/common PR: 134
File: src/schemas/output_schemas/report_v3.schema.json:5695-5921
Timestamp: 2025-08-22T20:01:21.087Z
Learning: The report_v3.schema.json includes dragAndDrop via inclusion in the spec schema, which includes the test and step schemas, creating a chain of schema inclusions.

Applied to files:

  • test/validate.test.js
📚 Learning: 2025-11-25T23:59:43.235Z
Learnt from: CR
Repo: doc-detective/common PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T23:59:43.235Z
Learning: Applies to test/files.test.js : Use Sinon stubs in test/files.test.js for mocking external dependencies in file reading tests

Applied to files:

  • test/files.test.js
  • test/resolvePaths.test.js
📚 Learning: 2025-11-25T23:59:43.235Z
Learnt from: CR
Repo: doc-detective/common PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T23:59:43.235Z
Learning: Applies to src/files.js : In readFile(), detect remote vs local files: use axios for http:// or https://, use fs.promises.readFile for local files

Applied to files:

  • test/files.test.js
📚 Learning: 2025-11-25T23:59:43.235Z
Learnt from: CR
Repo: doc-detective/common PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T23:59:43.235Z
Learning: Applies to **/*.{js,ts} : readFile() returns null on errors and logs warnings to console; do not assume errors throw exceptions

Applied to files:

  • test/files.test.js
📚 Learning: 2025-11-25T23:59:43.235Z
Learnt from: CR
Repo: doc-detective/common PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T23:59:43.235Z
Learning: Applies to src/files.js : In readFile(), detect format by extension: .json → JSON.parse(), .yaml/.yml → YAML.parse(), others → raw string; return raw content on parse errors

Applied to files:

  • test/files.test.js
📚 Learning: 2025-11-25T23:59:43.235Z
Learnt from: CR
Repo: doc-detective/common PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T23:59:43.235Z
Learning: GitHub Actions auto-dev-release skips if commit message contains [skip ci] or Release, or if only .md/.txt/.yml/.yaml/.github/ files changed

Applied to files:

  • .github/workflows/auto-dev-release.yml
📚 Learning: 2025-11-25T23:59:43.235Z
Learnt from: CR
Repo: doc-detective/common PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-11-25T23:59:43.235Z
Learning: Do not modify package.json version in PRs; auto-dev-release workflow handles version bumps automatically

Applied to files:

  • .github/workflows/auto-dev-release.yml
🧬 Code graph analysis (3)
test/validate.test.js (1)
src/validate.js (10)
  • require (1-1)
  • require (9-9)
  • result (90-90)
  • result (353-356)
  • result (446-449)
  • result (476-479)
  • result (492-495)
  • result (531-534)
  • result (575-578)
  • result (595-595)
src/validate.js (2)
test/validate.test.js (1)
  • require (3-3)
src/index.js (4)
  • require (1-1)
  • require (2-2)
  • require (3-3)
  • require (4-4)
test/resolvePaths.test.js (1)
src/resolvePaths.js (4)
  • require (3-3)
  • path (2-2)
  • config (230-232)
  • object (233-247)
🔇 Additional comments (30)
coverage-thresholds.json (1)

1-8: LGTM! Coverage ratchet configuration is well-structured.

The 100% baseline thresholds establish a strong quality bar for the project. The description clearly communicates the ratchet pattern (values only increase), and the structure is appropriate for consumption by the enforcement script.

.c8rc.json (1)

1-8: LGTM! C8 configuration is appropriate.

The configuration correctly targets source files under src/, provides multiple reporter formats for flexibility, and delegates threshold enforcement to the ratchet script rather than using C8's built-in check-coverage.

src/validate.js (6)

151-162: LGTM! Defensive code correctly excluded from coverage.

The comment accurately explains that transformToSchemaKey validates internally before returning (lines 353-359 and similar blocks throughout the function), making this error path unreachable under normal operation. The c8 ignore is appropriate for this defensive code.


450-454: LGTM! Unreachable defensive validation correctly excluded.

The transformation logic for config_v3 (lines 363-395) is deterministic and, when correct, always produces valid output. This validation failure check is defensive code that would only execute if the transformation logic itself is buggy. The c8 ignore is appropriate.


535-539: LGTM! Defensive nested validation check correctly excluded.

Since all nested transformations (lines 509-529) validate and throw on error, the objects are guaranteed valid by the time the final validation occurs at line 531. This error check is unreachable defensive code, appropriately excluded from coverage.


579-584: LGTM! Defensive nested validation correctly excluded.

The nested transformations (lines 552-573) validate before returning, making the error check at line 581-583 unreachable defensive code. The c8 ignore is appropriate, and line 584 correctly returns the validated object.


586-587: LGTM! Dead code correctly identified and excluded.

The incompatibility check at lines 198-201 ensures that incompatible schema pairs throw before reaching this point, and all valid transformations are handled by the preceding conditional blocks. This return statement is truly unreachable, and the c8 ignore is appropriate.


591-598: LGTM! Direct execution block correctly excluded from coverage.

The require.main === module block is standard for example/testing code that only runs when the file is executed directly, not when required as a module. Excluding this from coverage metrics is appropriate.

package.json (2)

11-14: LGTM! Coverage scripts are well-structured.

The scripts provide a comprehensive coverage workflow: basic coverage reporting, HTML output for detailed inspection, threshold checking, and ratchet enforcement. They correctly integrate with the c8 configuration and the custom ratchet script.


27-27: No action needed—c8 version is current and secure.

Version ^10.1.3 is the latest stable release (published Dec 10, 2024) with no known security vulnerabilities reported in the package itself.

.claude/skills/tdd-coverage/SKILL.md (3)

13-51: LGTM! Mandatory process is clearly defined and accurate.

The TDD cycle and coverage verification steps are well-documented and align with the tooling setup. The threshold values correctly reference the 100% baselines from coverage-thresholds.json, and the commands match the scripts defined in package.json.


53-91: LGTM! Test structure pattern follows project conventions.

The test location mapping is accurate, and the structure template correctly uses Mocha + Chai with async import for ESM compatibility (as per project learnings). The organization into input validation, happy path, and edge cases provides good coverage guidance.


93-161: LGTM! Commands and patterns are accurate and helpful.

The commands reference matches the scripts in package.json, and the common testing patterns provide practical, correct examples. The transformation test example accurately reflects the transformToSchemaKey usage from src/validate.js, and the Sinon mocking pattern correctly includes cleanup with restore().

src/resolvePaths.js (1)

226-254: LGTM: Appropriate use of coverage ignore markers.

Excluding the direct-run example block from coverage metrics is standard practice. This demo code executes only when the file is invoked directly and is not part of the module's testable API surface.

.github/workflows/auto-dev-release.yml (1)

103-108: LGTM: Coverage verification integrated into dev release pipeline.

The coverage check and ratchet verification ensure code quality standards are maintained before publishing dev releases. The placement after the build step is correct, as schema generation must complete before tests can run.

CLAUDE.md (1)

1-38: LGTM: Clear quick-reference documentation for AI assistants.

The file provides a concise entry point that emphasizes critical requirements (TDD, coverage enforcement) and points to AGENTS.md for comprehensive guidelines. The command reference and file location table are helpful for navigation.

AGENTS.md (1)

109-110: LGTM: Test file documentation updated.

The references to the new test files (validate.test.js and resolvePaths.test.js) are accurate and align with the expanded test coverage introduced in this PR.

.github/workflows/npm-test.yml (1)

42-62: LGTM: Coverage verification added to CI pipeline.

The dedicated coverage job runs independently from the test matrix, enabling parallel execution for faster feedback. The sequence (dereferenceSchemas → test:coverage → ratchet check → artifact upload) is correct, and using Node 20 (LTS) provides a stable baseline for coverage metrics.

scripts/check-coverage-ratchet.js (2)

18-31: LGTM!

The error handling is appropriate, providing clear guidance to users when files are missing or malformed.


33-102: LGTM!

The comparison logic correctly enforces coverage stability and provides actionable feedback when coverage improves.

test/files.test.js (4)

22-77: LGTM!

The input validation tests comprehensively cover all edge cases for the fileURLOrPath parameter with appropriate error message assertions.


79-122: LGTM!

The remote file reading tests properly validate HTTP/HTTPS file handling and error scenarios, with appropriate stub usage.


124-188: LGTM!

The local file reading tests thoroughly cover file format handling and error scenarios, correctly validating that readFile returns null on errors as per the coding guidelines.


190-220: LGTM!

The parse error handling tests correctly verify that raw content is returned when JSON/YAML parsing fails, aligning with the expected behavior.

test/resolvePaths.test.js (1)

1-628: LGTM!

This comprehensive test suite provides excellent coverage of the resolvePaths function, including:

  • Path resolution modes (file-relative and cwd-relative)
  • URL preservation for http, https, and custom URIs
  • Nested object and array handling
  • Error cases with appropriate error messages
  • Edge cases like null objects, empty objects, and directory inference

The tests follow the established Mocha + Chai pattern and properly use Sinon stubs for filesystem operations.

test/validate.test.js (5)

6-36: LGTM!

The input validation tests correctly verify that validate() throws errors for missing or invalid required parameters.


38-49: LGTM!

Correctly validates that validate() returns an error result (not throw) when the schema is not found, aligning with the coding guidelines.


51-185: LGTM!

These tests comprehensively validate:

  • Valid object handling with proper result structure
  • The addDefaults parameter behavior
  • Invalid object error reporting
  • Backward compatibility transformations from v2 to v3 schemas

All tests correctly use the return value pattern (checking result.valid, result.errors, result.object) as specified in the coding guidelines.


187-200: LGTM!

This test is essential for verifying that validate() does not mutate the original object, which aligns with the coding guideline to always clone objects before validation.


203-1105: LGTM!

This comprehensive test suite for transformToSchemaKey provides excellent coverage:

  • Same-schema and incompatible-schema handling
  • All major v2-to-v3 transformation paths across multiple schema types
  • Field mappings and value conversions (e.g., maxVariation 0-100 to 0-1, overwrite "byVariation" to "aboveVariation")
  • Nested transformations (contexts, openApi, fileTypes with markup)
  • Error handling for invalid transformation results

The tests correctly verify that transformToSchemaKey throws errors for incompatible schemas and invalid results, aligning with the coding guidelines.

- Set Lines coverage to 100%
- Set Statements coverage to 100%
- Set Branches coverage to 100%
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds comprehensive test coverage for validation and transformation functions along with coverage enforcement tooling. The changes establish a test-driven development (TDD) workflow with mandatory 100% code coverage requirements.

Key Changes

  • New test suites: Added extensive tests for validate(), transformToSchemaKey(), resolvePaths(), and readFile() functions covering input validation, transformations, error handling, and edge cases
  • Coverage infrastructure: Integrated c8 coverage tool with automated ratchet checks to enforce that coverage never decreases
  • Documentation: Added comprehensive TDD guidelines in AGENTS.md, CLAUDE.md, and a dedicated skill document for AI assistants

Reviewed changes

Copilot reviewed 14 out of 15 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test/validate.test.js Comprehensive tests for validation and v2→v3 schema transformation with 1106 lines covering all scenarios
test/resolvePaths.test.js Tests for path resolution with various configurations, relative/absolute paths, and URL handling
test/files.test.js Enhanced file reading tests with better organization and additional input validation coverage
src/validate.js Added c8 ignore comments for defensive unreachable code blocks
src/resolvePaths.js Added c8 ignore comments for direct execution block
package.json Added coverage scripts: test:coverage, test:coverage:html, test:coverage:check, test:coverage:ratchet
package-lock.json Added c8 v10.1.3 and related dependencies
scripts/check-coverage-ratchet.js Script to enforce coverage baseline - fails if any metric decreases
coverage-thresholds.json Baseline thresholds set at 100% for all metrics (lines, statements, functions, branches)
.c8rc.json c8 configuration with reporters and exclusions
.github/workflows/npm-test.yml Added coverage job that runs on Node 20 with coverage verification
.github/workflows/auto-dev-release.yml Added coverage checks before auto-dev releases
AGENTS.md Added testing requirements section with TDD mandate and coverage enforcement details
CLAUDE.md Quick reference for AI assistants pointing to AGENTS.md
.claude/skills/tdd-coverage/SKILL.md Detailed TDD workflow skill document for AI tooling

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 7, 2026

Note

Docstrings generation - SUCCESS
Generated docstrings for this pull request at #152

coderabbitai bot added a commit that referenced this pull request Jan 7, 2026
Docstrings generation was requested by @hawkeyexl.

* #151 (comment)

The following files were modified:

* `scripts/check-coverage-ratchet.js`
* `src/resolvePaths.js`
* `src/validate.js`
Docstrings generation was requested by @hawkeyexl.

* #151 (comment)

The following files were modified:

* `scripts/check-coverage-ratchet.js`
* `src/resolvePaths.js`
* `src/validate.js`

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@hawkeyexl hawkeyexl merged commit b0122a9 into main Jan 7, 2026
15 checks passed
@hawkeyexl hawkeyexl deleted the coverage branch January 7, 2026 22:52
@promptless
Copy link

promptless bot commented Jan 7, 2026

📝 Documentation updates detected!

New suggestion: Document code testing and coverage requirements for doc-detective-common

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.

2 participants