← All Exercises

Detect Configuration Drift as Paths

intermediatejavascript~25min

Background

Drift review needs to point at a specific key, not a whole resource diff. Path-level comparison is what makes a plan reviewable and a reconcile script safe.

Problem

Compare declared configuration with observed state, flatten nested objects into dotted paths, and list every drifted path in sorted order.

Input

JSON object: { declared, actual } (nested plain objects)

Output

JSON object: { drifted: string[], inSync: boolean }

Sample tests

Sample 1

Input: {"declared":{"app":{"replicas":3},"db":{"engine":"postgres"}},"actual":{"app":{"replicas":5},"db":{"engine":"postgres"}}}
Expected: {"drifted":["app.replicas"],"inSync":false}

Sample 2

Input: {"declared":{"app":{"replicas":3,"env":["prod"]}},"actual":{"app":{"replicas":3,"env":["prod"]}}}
Expected: {"drifted":[],"inSync":true}

Your solution

Learning objective

Produce a path-level drift report that a reviewer can act on key by key.