Skip to content

test(doctor): 71 testes unitários para módulos doctor (#52)#596

Open
nikolasdehor wants to merge 1 commit intoSynkraAI:mainfrom
nikolasdehor:test/doctor-module-coverage
Open

test(doctor): 71 testes unitários para módulos doctor (#52)#596
nikolasdehor wants to merge 1 commit intoSynkraAI:mainfrom
nikolasdehor:test/doctor-module-coverage

Conversation

@nikolasdehor
Copy link
Contributor

@nikolasdehor nikolasdehor commented Mar 13, 2026

Resumo

Adiciona 71 testes unitários cobrindo todo o módulo doctor/:

  • 10 checks modulares (51 testes): node-version, core-config, rules-files, agent-memory, entity-registry, git-hooks, skills-count, commands-count, hooks-claude-count, settings-json, ide-sync
  • Fix Handler (9 testes): dry-run, apply real, erros, checks sem fixer, múltiplos resultados
  • Orchestrator (11 testes): opções --json, --quiet, --fix, --dry-run, summary counts, tratamento de erros

Detalhes

Cada check é testado com:

  • Exportação correta de name
  • Cenários PASS, WARN, FAIL
  • Edge cases (diretórios inexistentes, JSON inválido, timestamps antigos)
  • Contagem recursiva de arquivos
  • Verificação de registros em settings.local.json

Closes #52 (parcial)

Plano de teste

  • npx jest tests/core/doctor/ — 71/71 testes passando
  • Nenhum mock global — usa fs.mkdtemp para isolamento
  • Cleanup automático em afterEach

Summary by CodeRabbit

  • Tests
    • Added comprehensive test suites for Doctor functionality including checks validation, orchestrator behavior, and fix handler operations.

…rchestrator (SynkraAI#52)

Cobertura completa dos 10 checks modulares (node-version, core-config,
rules-files, agent-memory, entity-registry, git-hooks, skills-count,
commands-count, hooks-claude-count, settings-json, ide-sync), do
fix-handler (dry-run, apply, erros) e do orchestrator (json, quiet, fix).
@vercel
Copy link

vercel bot commented Mar 13, 2026

@nikolasdehor is attempting to deploy a commit to the Pedro Valério Lopez's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions bot added area: agents Agent system related area: workflows Workflow system related squad mcp type: test Test coverage and quality area: core Core framework (.aios-core/core/) area: installer Installer and setup (packages/installer/) area: synapse SYNAPSE context engine area: cli CLI tools (bin/, packages/aios-pro-cli/) area: pro Pro features (pro/) area: health-check Health check system area: docs Documentation (docs/) area: devops CI/CD, GitHub Actions (.github/) labels Mar 13, 2026
@coderabbitai
Copy link

coderabbitai bot commented Mar 13, 2026

Walkthrough

Three new test suites are introduced for the Doctor system: comprehensive tests for individual checks (node-version, core-config, rules-files, etc.), the Doctor Index orchestrator with version and output formatting, and the Fix Handler for applying and validating remediation operations across various scenarios and configurations.

Changes

Cohort / File(s) Summary
Doctor System Tests
tests/core/doctor/doctor-checks.test.js, tests/core/doctor/doctor-index.test.js, tests/core/doctor/fix-handler.test.js
New test suites covering the Doctor diagnostic system: 11+ modular checks with scenarios for file presence/absence, configuration validation, and age-based warnings; orchestrator testing for version exposure, output formatting (plain text and JSON), and fix result handling; fix handler validation for filtering, file creation, dry-run semantics, and settings persistence.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title describes the main change: adding 71 unit tests for the doctor module. It is specific and directly relates to the changeset's core contribution.
Linked Issues check ✅ Passed The PR adds targeted tests for doctor module checks (51 tests), fix handler (9 tests), and orchestrator (11 tests), improving statement/branch/line/function coverage metrics required by issue #52.
Out of Scope Changes check ✅ Passed All changes are focused on the doctor module test coverage. No unrelated modifications to other modules or non-test code were introduced.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

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.

@codecov
Copy link

codecov bot commented Mar 13, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link

@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.

🧹 Nitpick comments (8)
tests/core/doctor/fix-handler.test.js (2)

16-17: Use absolute imports and remove unused import.

The imports use relative paths, and EXPECTED_RULES appears unused in this test file.

♻️ Suggested change
-const { applyFixes } = require('../../../.aiox-core/core/doctor/fix-handler');
-const { EXPECTED_RULES } = require('../../../.aiox-core/core/doctor/checks/rules-files');
+const { applyFixes } = require('@aiox-core/core/doctor/fix-handler');

As per coding guidelines: "Use absolute imports instead of relative imports in all code".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/core/doctor/fix-handler.test.js` around lines 16 - 17, The test file
imports use relative paths and include an unused import EXPECTED_RULES; update
the imports to use absolute module paths and remove the unused EXPECTED_RULES
import. Specifically, replace the relative require for applyFixes with the
project's absolute import path for the .aiox-core core/doctor/fix-handler module
(referencing applyFixes) and delete the line that requires EXPECTED_RULES so
only the needed applyFixes symbol is imported.

160-175: Test assertion is weak — only verifies check name.

This test validates that fixResults[0].check equals 'settings-json' but doesn't assert on applied or message. The comment on line 173 acknowledges uncertainty, but this makes the test less useful for regression detection.

♻️ Consider strengthening the assertion
 const fixResults = await applyFixes(results, context);
 expect(fixResults).toHaveLength(1);
-// Pode ser applied=true (com generator) ou message com install --force
 expect(fixResults[0].check).toBe('settings-json');
+expect(typeof fixResults[0].applied).toBe('boolean');
+expect(typeof fixResults[0].message).toBe('string');
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/core/doctor/fix-handler.test.js` around lines 160 - 175, The test only
checks fixResults[0].check and is too weak; update the assertion to validate
whether the fix actually applied or produced a clear message: after calling
applyFixes(results, context) assert that fixResults has length 1 and then check
fixResults[0] for either applied === true (indicating the generator ran) or that
fixResults[0].message contains the expected guidance (e.g., 'install --force' or
other known instruction). Use the existing variables fixResults, applyFixes,
results and context to locate the test and add a conditional or explicit
assertions to cover both possible outcomes.
tests/core/doctor/doctor-index.test.js (3)

101-106: Test using cwd() may be environment-dependent.

This test omits projectRoot, defaulting to process.cwd(). In CI or different working directories, this could yield varying results. The test passes currently, but consider documenting this dependency or explicitly setting projectRoot for deterministic behavior.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/core/doctor/doctor-index.test.js` around lines 101 - 106, The test
relies on process.cwd() via runDoctorChecks() which is environment-dependent;
make it deterministic by explicitly providing a known projectRoot when calling
runDoctorChecks (or temporarily set process.cwd() to a fixture), e.g., call
runDoctorChecks({ projectRoot: pathToTestFixture }) or wrap the test in a
try/finally that changes cwd and restores it; update the test invoking
runDoctorChecks and reference the fixture path so the expectations on
data.checks remain stable across environments.

33-35: Hardcoded version may cause test brittleness.

The test directly asserts '2.0.0' which will fail whenever DOCTOR_VERSION is bumped. Consider verifying the format (semver) or comparing against the exported constant dynamically if the goal is just to ensure the export exists and has a valid value.

♻️ Alternative approach
 it('deve exportar DOCTOR_VERSION', () => {
-  expect(DOCTOR_VERSION).toBe('2.0.0');
+  expect(typeof DOCTOR_VERSION).toBe('string');
+  expect(DOCTOR_VERSION).toMatch(/^\d+\.\d+\.\d+$/);
 });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/core/doctor/doctor-index.test.js` around lines 33 - 35, The test
currently hardcodes '2.0.0' which will break when DOCTOR_VERSION is bumped;
update the test for DOCTOR_VERSION to assert a valid semver format instead of a
specific value—e.g., use a semver regex or the semver library to assert
semver.valid(DOCTOR_VERSION) or
expect(DOCTOR_VERSION).toMatch(/^\d+\.\d+\.\d+(-.+)?$/)—so the test verifies
DOCTOR_VERSION exists and is a valid semver without depending on a fixed version
string.

16-16: Use absolute imports instead of relative imports.

The import uses a relative path which violates the project's coding guidelines.

♻️ Suggested change

Consider configuring Jest's moduleNameMapper or using a path alias to enable absolute imports:

-const { runDoctorChecks, DOCTOR_VERSION } = require('../../../.aiox-core/core/doctor');
+const { runDoctorChecks, DOCTOR_VERSION } = require('@aiox-core/core/doctor');

As per coding guidelines: "Use absolute imports instead of relative imports in all code".

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/core/doctor/doctor-index.test.js` at line 16, Replace the relative
require "../../../.aiox-core/core/doctor" in the test that imports
runDoctorChecks and DOCTOR_VERSION with an absolute import using your project's
configured path alias (e.g., "core/doctor" or "@aiox-core/core/doctor"); then
update Jest's configuration (moduleNameMapper) to map that alias to the actual
.aiox-core folder so tests resolve the module, and ensure the
require/require-equivalent in the test is updated to use the alias for
runDoctorChecks and DOCTOR_VERSION.
tests/core/doctor/doctor-checks.test.js (3)

39-39: Use absolute imports for all check modules.

All require statements for doctor checks use relative paths. Consider configuring module aliases to enable absolute imports across the test suite.

Example transformation:

-const { run, name } = require('../../../.aiox-core/core/doctor/checks/node-version');
+const { run, name } = require('@aiox-core/core/doctor/checks/node-version');

As per coding guidelines: "Use absolute imports instead of relative imports in all code".

Also applies to: 64-64, 126-126, 198-198, 262-262, 320-320, 375-375, 465-465, 557-557, 656-656, 733-733

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/core/doctor/doctor-checks.test.js` at line 39, The test imports doctor
check modules with relative paths (e.g.,
require('../../../.aiox-core/core/doctor/checks/node-version') in
doctor-checks.test.js); change these to the project's absolute module alias
(e.g., require('@aiox-core/core/doctor/checks/node-version') or the alias your
repo uses) for all occurrences (lines referenced in the review). Update the
require calls for the symbols { run, name } and the other listed check imports
to use the absolute alias, and if necessary adjust the test
resolver/moduleNameMapper or module-alias config so Jest/node can resolve the
new absolute paths.

45-56: Conditional assertion may silently pass without testing.

The if (major >= 18) block means that if the test runs on Node < 18, no assertions execute and the test passes silently. Consider using expect.assertions(n) or restructuring to ensure assertions always run, or add an explicit skip/fail for unsupported Node versions.

♻️ Suggested approach
 it('deve retornar PASS quando Node >= 18', async () => {
-  // Rodando neste ambiente, Node deve ser >= 18
   const result = await run();
   const major = parseInt(process.version.replace('v', '').split('.')[0], 10);

-  if (major >= 18) {
-    expect(result.status).toBe('PASS');
-    expect(result.check).toBe('node-version');
-    expect(result.message).toContain('Node.js');
-    expect(result.fixCommand).toBeNull();
-  }
+  // This test suite requires Node >= 18
+  expect(major).toBeGreaterThanOrEqual(18);
+  expect(result.status).toBe('PASS');
+  expect(result.check).toBe('node-version');
+  expect(result.message).toContain('Node.js');
+  expect(result.fixCommand).toBeNull();
 });
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/core/doctor/doctor-checks.test.js` around lines 45 - 56, The test's
conditional "if (major >= 18)" causes assertions to be skipped on Node < 18;
change the test so assertions always run or the test explicitly fails/skips on
unsupported Node versions: compute major via parseInt(process.version...), call
run() and then either (a) add an explicit guard that throws or calls
test.skip/fail when major < 18, or (b) use expect.assertions(n) and restructure
to assert the expected PASS behavior for major >= 18 and assert a specific
failure/skip outcome for major < 18; update references to run(), result, major
and the test case description accordingly so the test cannot silently pass
without executing assertions.

4-6: Doc comment lists 11 checks but claims 15.

The JSDoc mentions "15 checks modulares" but only lists 11 names. Consider updating the comment to match the actual count.

♻️ Suggested fix
-* Cobre todos os 15 checks modulares: node-version, core-config,
+* Cobre todos os 11 checks modulares: node-version, core-config,
 * rules-files, agent-memory, entity-registry, git-hooks, ide-sync,
 * settings-json, skills-count, commands-count, hooks-claude-count.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@tests/core/doctor/doctor-checks.test.js` around lines 4 - 6, Update the JSDoc
block that currently says "15 checks modulares" to accurately reflect the checks
listed: either change the number to 11 or add the missing 4 check names so the
count matches; edit the JSDoc comment in the doctor-checks.test.js header (the
JSDoc listing node-version, core-config, rules-files, agent-memory,
entity-registry, git-hooks, ide-sync, settings-json, skills-count,
commands-count, hooks-claude-count) to keep the written number and the
enumerated list consistent.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@tests/core/doctor/doctor-checks.test.js`:
- Line 39: The test imports doctor check modules with relative paths (e.g.,
require('../../../.aiox-core/core/doctor/checks/node-version') in
doctor-checks.test.js); change these to the project's absolute module alias
(e.g., require('@aiox-core/core/doctor/checks/node-version') or the alias your
repo uses) for all occurrences (lines referenced in the review). Update the
require calls for the symbols { run, name } and the other listed check imports
to use the absolute alias, and if necessary adjust the test
resolver/moduleNameMapper or module-alias config so Jest/node can resolve the
new absolute paths.
- Around line 45-56: The test's conditional "if (major >= 18)" causes assertions
to be skipped on Node < 18; change the test so assertions always run or the test
explicitly fails/skips on unsupported Node versions: compute major via
parseInt(process.version...), call run() and then either (a) add an explicit
guard that throws or calls test.skip/fail when major < 18, or (b) use
expect.assertions(n) and restructure to assert the expected PASS behavior for
major >= 18 and assert a specific failure/skip outcome for major < 18; update
references to run(), result, major and the test case description accordingly so
the test cannot silently pass without executing assertions.
- Around line 4-6: Update the JSDoc block that currently says "15 checks
modulares" to accurately reflect the checks listed: either change the number to
11 or add the missing 4 check names so the count matches; edit the JSDoc comment
in the doctor-checks.test.js header (the JSDoc listing node-version,
core-config, rules-files, agent-memory, entity-registry, git-hooks, ide-sync,
settings-json, skills-count, commands-count, hooks-claude-count) to keep the
written number and the enumerated list consistent.

In `@tests/core/doctor/doctor-index.test.js`:
- Around line 101-106: The test relies on process.cwd() via runDoctorChecks()
which is environment-dependent; make it deterministic by explicitly providing a
known projectRoot when calling runDoctorChecks (or temporarily set process.cwd()
to a fixture), e.g., call runDoctorChecks({ projectRoot: pathToTestFixture }) or
wrap the test in a try/finally that changes cwd and restores it; update the test
invoking runDoctorChecks and reference the fixture path so the expectations on
data.checks remain stable across environments.
- Around line 33-35: The test currently hardcodes '2.0.0' which will break when
DOCTOR_VERSION is bumped; update the test for DOCTOR_VERSION to assert a valid
semver format instead of a specific value—e.g., use a semver regex or the semver
library to assert semver.valid(DOCTOR_VERSION) or
expect(DOCTOR_VERSION).toMatch(/^\d+\.\d+\.\d+(-.+)?$/)—so the test verifies
DOCTOR_VERSION exists and is a valid semver without depending on a fixed version
string.
- Line 16: Replace the relative require "../../../.aiox-core/core/doctor" in the
test that imports runDoctorChecks and DOCTOR_VERSION with an absolute import
using your project's configured path alias (e.g., "core/doctor" or
"@aiox-core/core/doctor"); then update Jest's configuration (moduleNameMapper)
to map that alias to the actual .aiox-core folder so tests resolve the module,
and ensure the require/require-equivalent in the test is updated to use the
alias for runDoctorChecks and DOCTOR_VERSION.

In `@tests/core/doctor/fix-handler.test.js`:
- Around line 16-17: The test file imports use relative paths and include an
unused import EXPECTED_RULES; update the imports to use absolute module paths
and remove the unused EXPECTED_RULES import. Specifically, replace the relative
require for applyFixes with the project's absolute import path for the
.aiox-core core/doctor/fix-handler module (referencing applyFixes) and delete
the line that requires EXPECTED_RULES so only the needed applyFixes symbol is
imported.
- Around line 160-175: The test only checks fixResults[0].check and is too weak;
update the assertion to validate whether the fix actually applied or produced a
clear message: after calling applyFixes(results, context) assert that fixResults
has length 1 and then check fixResults[0] for either applied === true
(indicating the generator ran) or that fixResults[0].message contains the
expected guidance (e.g., 'install --force' or other known instruction). Use the
existing variables fixResults, applyFixes, results and context to locate the
test and add a conditional or explicit assertions to cover both possible
outcomes.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 903026dc-a49f-4ad6-bb7a-824e7e8e6831

📥 Commits

Reviewing files that changed from the base of the PR and between f74e3e7 and a5077a6.

📒 Files selected for processing (3)
  • tests/core/doctor/doctor-checks.test.js
  • tests/core/doctor/doctor-index.test.js
  • tests/core/doctor/fix-handler.test.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: agents Agent system related area: cli CLI tools (bin/, packages/aios-pro-cli/) area: core Core framework (.aios-core/core/) area: devops CI/CD, GitHub Actions (.github/) area: docs Documentation (docs/) area: health-check Health check system area: installer Installer and setup (packages/installer/) area: pro Pro features (pro/) area: synapse SYNAPSE context engine area: workflows Workflow system related mcp squad type: test Test coverage and quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

test(coverage): Improve global test coverage after ADE implementation

1 participant