Skip to content

Test Caching Reconstruction Fix Summary

Changes Made

1. Updated Method Calls to Match Current API

  • Changed stack._to_config_cached() to stack._to_config_with_cache()
  • Changed stack._resource_hashes.get(key) to stack._version_tracker.get_version(resource)
  • Updated all references to use the version-based caching system

2. Added Explicit Cache Invalidation

  • Added calls to stack._invalidate_resource_cache(resource) after modifying resources
  • This ensures the version tracker knows the resource has changed

3. Fixed Synthesis Flow

  • Changed from calling stack._synthesize(str(tmp_path)) directly to app.synth(outdir=str(tmp_path))
  • This ensures proper synthesis flow through the app

4. Updated File Paths

  • Changed from Path(tmp_path) / "stacks" / stack.nf_id / "cdk.tf.json"
  • To Path(tmp_path) / app.nf_id / stack.nf_id / "nf.tf.json"
  • Matches the actual output structure: <outdir>/<app_id>/<stack_id>/nf.tf.json

5. Fixed Stack Hash Computation

  • Added imports and moves to the stack hash computation in _compute_stack_hash_v2()
  • This ensures that changes to import blocks invalidate the synthesis cache
  • Previously only resources, providers, outputs, and variables were included

6. Removed Unnecessary Cache Clearing

  • Removed clearing of _resource_hashes and _resource_configs after invalidation
  • The invalidation system already marks resources as needing recomputation
  • Clearing these would lose track of what changed

Key Insights

  1. The synthesis caching system uses stack hashes to determine if re-synthesis is needed
  2. Import and Move blocks weren't included in the hash, so changes to them didn't trigger re-synthesis
  3. The version-based caching system requires explicit invalidation when resources change
  4. The test was bypassing the normal app synthesis flow which caused path issues

All Tests Now Pass

All 12 tests in test_caching_reconstruction.py now pass successfully, validating that: - Basic caching and reconstruction works - Child modifications invalidate parent caches appropriately
- Token changes trigger reconstruction - Nested config changes are detected - Provider changes affect resources - Import and move blocks work with caching - Selective cache invalidation works correctly - Runtime functions prevent caching as expected - Performance edge cases are handled properly