Skip to content

fix: yaml-validator getMaxDepth trata null como nível extra de profundidade#514

Open
nikolasdehor wants to merge 3 commits intoSynkraAI:mainfrom
nikolasdehor:fix/yaml-validator-null-depth
Open

fix: yaml-validator getMaxDepth trata null como nível extra de profundidade#514
nikolasdehor wants to merge 3 commits intoSynkraAI:mainfrom
nikolasdehor:fix/yaml-validator-null-depth

Conversation

@nikolasdehor
Copy link
Contributor

@nikolasdehor nikolasdehor commented Feb 25, 2026

Descrição

Corrige bug no cálculo de profundidade de objetos YAML onde valores null eram contados como nível adicional de aninhamento.

Em JavaScript, typeof null === 'object' — isso fazia o getMaxDepth() tratar null como um objeto e fazer recursão desnecessária, inflando o contador de profundidade. Configs YAML com valores null (muito comum) podiam disparar falsos warnings de deep_nesting.

Mudança

 for (const value of Object.values(obj)) {
-  if (typeof value === 'object') {
+  if (typeof value === 'object' && value !== null) {
     const depth = this.getMaxDepth(value, currentDepth + 1);

Testes

16 testes unitários para getMaxDepth() cobrindo:

  • Objetos vazios, flat, aninhados (1-12 níveis)
  • Múltiplos branches com profundidades diferentes
  • Regressão do bug: null como valor, mix de null com objetos, arrays com null
  • Edge cases: null/undefined/string/number diretos, currentDepth customizado
  • Threshold de >10 níveis (deep nesting warning)
PASS tests/core/utils/yaml-validator-depth.test.js
Tests: 16 passed, 16 total

Closes #512

Summary by CodeRabbit

  • Bug Fixes
    • YAML validator depth calculation now ignores null values in nested structures, preventing incorrect recursion and depth reporting.
  • Chores
    • Updated install manifest version and refreshed file metadata and timestamps to reflect the latest build.

Copilot AI review requested due to automatic review settings February 25, 2026 17:35
@vercel
Copy link

vercel bot commented Feb 25, 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.

@coderabbitai
Copy link

coderabbitai bot commented Feb 25, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 02588c5 and beb1460.

📒 Files selected for processing (3)
  • .aios-core/development/scripts/yaml-validator.js
  • .aios-core/infrastructure/scripts/yaml-validator.js
  • .aios-core/install-manifest.yaml

Walkthrough

Fixes YAML validator's getMaxDepth to avoid recursing into null values by requiring value !== null alongside typeof value === 'object', correcting depth calculations for structures containing null.

Changes

Cohort / File(s) Summary
YAML Validator updates
.aios-core/core/utils/yaml-validator.js, .aios-core/development/scripts/yaml-validator.js, .aios-core/infrastructure/scripts/yaml-validator.js
Adjusted getMaxDepth recursion condition from typeof value === 'object' to typeof value === 'object' && value !== null to prevent counting null as an extra depth level.
Manifest metadata
.aios-core/install-manifest.yaml
Bumped manifest version and generated_at; updated per-file sha256 hashes and sizes. Metadata-only changes, no functional/API changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main fix: preventing null values from being treated as extra depth levels in the yaml-validator's getMaxDepth function.
Linked Issues check ✅ Passed All code changes directly address issue #512: adding null checks to the getMaxDepth recursion condition across all three yaml-validator copies, with comprehensive unit tests validating the fix.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing the null-depth bug in yaml-validator files. The manifest version bump reflects the updated content and is an appropriate administrative change.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ 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

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.

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 25, 2026
Copy link

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 fixes a bug in the YAML validator where null values were incorrectly counted as additional nesting levels. The root cause is JavaScript's quirk where typeof null === 'object', causing the getMaxDepth() method to recurse on null values. This could trigger false warnings about deep nesting in valid YAML configurations.

Changes:

  • Added null check to getMaxDepth() method in yaml-validator.js (line 264)
  • Added comprehensive test suite with 16 test cases covering the fix and edge cases

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
.aios-core/core/utils/yaml-validator.js Added && value !== null check before recursing on object values in getMaxDepth() method
tests/core/utils/yaml-validator-depth.test.js New test file with 16 tests covering empty objects, nested objects, null handling, arrays, and deep nesting scenarios

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

let maxDepth = currentDepth;
for (const value of Object.values(obj)) {
if (typeof value === 'object') {
if (typeof value === 'object' && value !== null) {
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

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

The fix correctly addresses the bug where null values were incorrectly counted as nested objects. However, there are duplicate copies of this file in .aios-core/development/scripts/yaml-validator.js (line 261) and .aios-core/infrastructure/scripts/yaml-validator.js (line 261) that have the same getMaxDepth method with the same bug, but are not fixed in this PR. These duplicate files should also receive the same fix to maintain consistency across the codebase.

Copilot uses AI. Check for mistakes.

test('profundidade correta com array contendo objetos', () => {
const obj = { list: [{ a: 1 }, { b: { c: 2 } }] };
// list = 1, list[1].b = 2 + list = 3
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

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

The comment explaining the depth calculation could be clearer. The current comment "list = 1, list[1].b = 2 + list = 3" is somewhat confusing. A clearer explanation would be: "list array is 1 level deep, objects in array add 1 level (total 2), nested object b.c adds 1 more level (total 3)".

Suggested change
// list = 1, list[1].b = 2 + list = 3
// list array is 1 level deep, objects in array add 1 level (total 2), nested object b.c adds 1 more level (total 3)

Copilot uses AI. Check for mistakes.
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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
.aios-core/infrastructure/scripts/yaml-validator.js (1)

1-1: ⚠️ Potential issue | 🔴 Critical

CI blocker: regenerate the manifest before merging.

The pipeline is failing with:

Manifest is OUTDATED. Modified file with hash mismatch.

Run npm run generate:manifest locally, commit the updated manifest, and re-push. This affects both modified files and must be resolved before the PR can be merged.

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

In @.aios-core/infrastructure/scripts/yaml-validator.js at line 1, The CI is
failing due to an outdated manifest; run the npm script "generate:manifest"
locally to regenerate the manifest artifact, verify the updated manifest
reflects the latest changes (resolving "Manifest is OUTDATED. Modified file with
hash mismatch."), add and commit the regenerated manifest file to the branch,
and push the commit so the pipeline can pass.
.aios-core/development/scripts/yaml-validator.js (1)

1-397: 🛠️ Refactor suggestion | 🟠 Major

Consolidate three diverging copies of YAMLValidator into a single re-export from the canonical core utility.

The three copies do exist in .aios-core/core/utils/yaml-validator.js, .aios-core/development/scripts/yaml-validator.js, and .aios-core/infrastructure/scripts/yaml-validator.js. They are already diverging in meaningful ways:

  • Infrastructure copy: Uses undeclared const key at line 330 (unused variable without prefix)
  • Development copy: Uses const _key at the same location (prefixed to signal intentional non-use)
  • Core version: More modernized implementation with Object.hasOwn() instead of hasOwnProperty(), proper JSDoc documentation, and different code patterns

The infrastructure copy represents a maintenance risk—it has an undeclared variable that should either be removed or properly prefixed. Rather than patching each copy separately, replace both the development and infrastructure variants with a simple re-export:

Suggested consolidation
-/**
- * YAML Validator for AIOS Developer Meta-Agent
- * ...
- */
-const yaml = require('js-yaml');
-const fs = require('fs-extra');
-
-class YAMLValidator { ... }
-
-module.exports = YAMLValidator;
+module.exports = require('../../core/utils/yaml-validator');

(Adjust the relative path to match each script's location.)

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

In @.aios-core/development/scripts/yaml-validator.js around lines 1 - 397, The
file contains a divergent local implementation of the YAMLValidator class
(symbols: class YAMLValidator, methods validate, validateFile,
validateStructure, validateFieldStructure, validateFieldTypes, getMaxDepth,
fixIndentation, fixQuotes) and must be consolidated to re-export the single
canonical implementation from the core utility; replace the local class and its
code with a simple re-export of the canonical YAMLValidator module (i.e.
export/require the core YAMLValidator) so both development and infrastructure
copies no longer diverge—if you must keep any local code, remove the
undeclared/unused variable (the stray const key) and convert any hasOwnProperty
uses to Object.hasOwn() to match the core implementation.
♻️ Duplicate comments (1)
.aios-core/development/scripts/yaml-validator.js (1)

254-268: Same correct fix as the infrastructure copy.

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

In @.aios-core/development/scripts/yaml-validator.js around lines 254 - 268,
Update getMaxDepth to match the infrastructure copy: treat any non-null object
(including arrays) as a level by returning currentDepth + 1 for object nodes and
recurse into all children while properly incrementing depth; specifically adjust
the logic in getMaxDepth (and its recursive call this.getMaxDepth) so the root
object counts as depth 1 and nested objects increment depth correctly instead of
returning the currentDepth prematurely for object nodes.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In @.aios-core/development/scripts/yaml-validator.js:
- Around line 1-397: The file contains a divergent local implementation of the
YAMLValidator class (symbols: class YAMLValidator, methods validate,
validateFile, validateStructure, validateFieldStructure, validateFieldTypes,
getMaxDepth, fixIndentation, fixQuotes) and must be consolidated to re-export
the single canonical implementation from the core utility; replace the local
class and its code with a simple re-export of the canonical YAMLValidator module
(i.e. export/require the core YAMLValidator) so both development and
infrastructure copies no longer diverge—if you must keep any local code, remove
the undeclared/unused variable (the stray const key) and convert any
hasOwnProperty uses to Object.hasOwn() to match the core implementation.

In @.aios-core/infrastructure/scripts/yaml-validator.js:
- Line 1: The CI is failing due to an outdated manifest; run the npm script
"generate:manifest" locally to regenerate the manifest artifact, verify the
updated manifest reflects the latest changes (resolving "Manifest is OUTDATED.
Modified file with hash mismatch."), add and commit the regenerated manifest
file to the branch, and push the commit so the pipeline can pass.

---

Duplicate comments:
In @.aios-core/development/scripts/yaml-validator.js:
- Around line 254-268: Update getMaxDepth to match the infrastructure copy:
treat any non-null object (including arrays) as a level by returning
currentDepth + 1 for object nodes and recurse into all children while properly
incrementing depth; specifically adjust the logic in getMaxDepth (and its
recursive call this.getMaxDepth) so the root object counts as depth 1 and nested
objects increment depth correctly instead of returning the currentDepth
prematurely for object nodes.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 33b1f91 and 7d33bc4.

📒 Files selected for processing (2)
  • .aios-core/development/scripts/yaml-validator.js
  • .aios-core/infrastructure/scripts/yaml-validator.js

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 25, 2026
typeof null === 'object' é um quirk do JavaScript. O loop em
getMaxDepth() usava apenas typeof value === 'object' para decidir
recursão, fazendo null inflar a profundidade calculada em +1.

Adiciona guard value !== null para tratar null como folha.

Closes SynkraAI#512
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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
.aios-core/core/utils/yaml-validator.js (1)

257-271: ⚠️ Potential issue | 🟠 Major

Code fix is correct, but test file was not found in repository.

The addition of && value !== null at line 264 correctly prevents null values from being recursed into during depth calculation, mirroring the guard at line 258. This resolves the false positive deep_nesting warnings.

However, despite the PR claim of 16 added tests, no test file exists in the repository for the getMaxDepth() method. Per coding guidelines for CRITICAL PATH core modules, test coverage is required for new/modified functions. Please add tests covering:

  • Null values mixed with nested objects
  • Arrays containing null
  • Pure null input
  • Deep nested structures with null at various levels
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.aios-core/core/utils/yaml-validator.js around lines 257 - 271, The PR added
a null-guard to getMaxDepth but no tests were committed; add a new test file
that exercises the getMaxDepth function with the required cases: (1) objects
containing nulls mixed with nested objects, (2) arrays containing null values,
(3) a pure null input, and (4) deeply nested objects with nulls at various
levels; for each case assert the expected depth returned by getMaxDepth and
include descriptive test names so CI verifies the deep_nesting fix.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In @.aios-core/core/utils/yaml-validator.js:
- Around line 257-271: The PR added a null-guard to getMaxDepth but no tests
were committed; add a new test file that exercises the getMaxDepth function with
the required cases: (1) objects containing nulls mixed with nested objects, (2)
arrays containing null values, (3) a pure null input, and (4) deeply nested
objects with nulls at various levels; for each case assert the expected depth
returned by getMaxDepth and include descriptive test names so CI verifies the
deep_nesting fix.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7d33bc4 and 347fac7.

📒 Files selected for processing (1)
  • .aios-core/core/utils/yaml-validator.js

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 26, 2026
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 (1)
.aios-core/install-manifest.yaml (1)

1-3: Auto-generated manifest — ensure it was regenerated via the documented command.

The header states this file should be regenerated with npm run generate:manifest. Confirm this command was executed after modifying yaml-validator.js to ensure all hashes are accurate.

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

In @.aios-core/install-manifest.yaml around lines 1 - 3, The install manifest
header says it must be regenerated; after changing yaml-validator.js you need to
run the manifest generator and commit the new file: run the documented command
`npm run generate:manifest` (which executes
scripts/generate-install-manifest.js), verify .aios-core/install-manifest.yaml
was updated with new hashes, and include that regenerated file in your PR so
hashes match the modified yaml-validator.js; re-run tests/CI to confirm no
drift.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In @.aios-core/install-manifest.yaml:
- Around line 1-3: The install manifest header says it must be regenerated;
after changing yaml-validator.js you need to run the manifest generator and
commit the new file: run the documented command `npm run generate:manifest`
(which executes scripts/generate-install-manifest.js), verify
.aios-core/install-manifest.yaml was updated with new hashes, and include that
regenerated file in your PR so hashes match the modified yaml-validator.js;
re-run tests/CI to confirm no drift.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 347fac7 and 02588c5.

📒 Files selected for processing (1)
  • .aios-core/install-manifest.yaml

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 27, 2026
Copilot detectou que development/scripts/ e infrastructure/scripts/
contêm cópias do yaml-validator.js com o mesmo bug typeof null.
Aplica a mesma correção && value \!== null em ambas.
@Pedrovaleriolopez
Copy link
Contributor

Rebase + Manifest Necessários

@nikolasdehor Este PR tem conflitos de merge (provavelmente install-manifest.yaml).

Ações necessárias:

  1. Rebase em main
  2. Executar npm run generate:manifest para regenerar o manifest
  3. Push da branch atualizada

O fix do null depth está aprovado — merge imediato após essas ações.

— Gage (DevOps)

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.

bug: yaml-validator getMaxDepth conta null como nível extra de profundidade

3 participants