Skip to content

fix: change const to let for policy reassignment in applyPreset#133

Closed
WuKongAI-CMU wants to merge 1 commit intoNVIDIA:mainfrom
WuKongAI-CMU:fix/policies-const-reassignment
Closed

fix: change const to let for policy reassignment in applyPreset#133
WuKongAI-CMU wants to merge 1 commit intoNVIDIA:mainfrom
WuKongAI-CMU:fix/policies-const-reassignment

Conversation

@WuKongAI-CMU
Copy link
Contributor

Summary

  • Fix TypeError: Assignment to constant variable crash in applyPreset() when a sandbox has a policy without a network_policies section
  • Export extractPresetEntries and parseCurrentPolicy for testability
  • Add 9 unit tests for the three pure policy helper functions

Problem

bin/lib/policies.js:94 declares currentPolicy as const, but line 136 reassigns it to prepend version: 1. This code path is reached when a sandbox has a policy YAML that doesn't contain a network_policies: key — the const assignment throws at runtime.

Fix

Change const currentPolicy to let currentPolicy on line 94.

Test plan

  • node --test test/policies-helpers.test.js — 9/9 pass
  • node --test test/*.test.js — full suite 61/61 pass

🤖 Generated with Claude Code

applyPreset() crashes with "Assignment to constant variable" when a
sandbox has a policy without a network_policies section. Change the
declaration from const to let so the fallback path can prepend the
version field.

Also export extractPresetEntries and parseCurrentPolicy for testing
and add 9 unit tests covering all three pure helpers.

Signed-off-by: Peter Tam <nickthetam@gmail.com>
Signed-off-by: peteryuqin <peter.yuqin@gmail.com>
@WuKongAI-CMU
Copy link
Contributor Author

Closing to reduce my open PR count below the repo policy limit and refocus on a smaller set of higher-signal changes. I can revive this branch later if it becomes the right path again.

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.

1 participant