|
| 1 | +# Policy Set Command and Live Defaults Implementation Plan |
| 2 | + |
| 3 | +> **For Claude:** REQUIRED SUB-SKILL: Use superpowers:executing-plans to implement this plan task-by-task. |
| 4 | +
|
| 5 | +**Goal:** Add `nqctl policy set` to update `safety.allow_writes` and `safety.dry_run`, and switch shipped defaults to live mode. |
| 6 | + |
| 7 | +**Architecture:** Extend CLI policy subcommands with a write handler that updates runtime YAML safely and returns the effective settings payload. Keep `load_settings` precedence unchanged while flipping fallback defaults in `SafetySettings` and packaged default runtime config. Add tests for parser, handler behavior, and defaults. |
| 8 | + |
| 9 | +**Tech Stack:** Python, argparse, PyYAML, pytest. |
| 10 | + |
| 11 | +--- |
| 12 | + |
| 13 | +### Task 1: Add failing CLI tests for `policy set` |
| 14 | + |
| 15 | +**Files:** |
| 16 | +- Modify: `tests/test_cli.py` |
| 17 | +- Modify: `nanonis_qcodes_controller/cli.py` |
| 18 | + |
| 19 | +**Step 1: Write failing parser test for `policy set` flags** |
| 20 | + |
| 21 | +Add test asserting this parses: |
| 22 | + |
| 23 | +```python |
| 24 | +args = parser.parse_args(["policy", "set", "--allow-writes", "true", "--dry-run", "false"]) |
| 25 | +assert args.command == "policy" |
| 26 | +assert args.policy_command == "set" |
| 27 | +``` |
| 28 | + |
| 29 | +**Step 2: Write failing handler test for YAML mutation** |
| 30 | + |
| 31 | +Use `tmp_path` runtime YAML and assert `_cmd_policy_set` writes: |
| 32 | +- `safety.allow_writes = True` |
| 33 | +- `safety.dry_run = False` |
| 34 | + |
| 35 | +Also assert payload contains updated effective values. |
| 36 | + |
| 37 | +**Step 3: Run focused tests to capture failures** |
| 38 | + |
| 39 | +Run: `python -m pytest tests/test_cli.py -k "policy_set" --import-mode=importlib` |
| 40 | + |
| 41 | +Expected: failing tests because command/handler is missing. |
| 42 | + |
| 43 | +### Task 2: Implement `nqctl policy set` |
| 44 | + |
| 45 | +**Files:** |
| 46 | +- Modify: `nanonis_qcodes_controller/cli.py` |
| 47 | + |
| 48 | +**Step 1: Add parser surface** |
| 49 | + |
| 50 | +Under `policy` subparsers add: |
| 51 | +- `policy set` |
| 52 | +- `--allow-writes <bool>` |
| 53 | +- `--dry-run <bool>` |
| 54 | +- `--config-file` (same semantics as `policy show`) |
| 55 | + |
| 56 | +**Step 2: Add bool parsing helper** |
| 57 | + |
| 58 | +Add helper accepting string booleans (`1/0`, `true/false`, `yes/no`, `on/off`) with clear error on invalid input. |
| 59 | + |
| 60 | +**Step 3: Implement `_cmd_policy_set`** |
| 61 | + |
| 62 | +Behavior: |
| 63 | +- Require at least one of `--allow-writes` or `--dry-run`. |
| 64 | +- Load target YAML map (or initialize default structure if missing). |
| 65 | +- Update only `safety.allow_writes` and/or `safety.dry_run`. |
| 66 | +- Persist YAML. |
| 67 | +- Reload via `load_settings(config_file=...)` and print payload with effective values. |
| 68 | + |
| 69 | +**Step 4: Re-run focused tests** |
| 70 | + |
| 71 | +Run: `python -m pytest tests/test_cli.py -k "policy_set" --import-mode=importlib` |
| 72 | + |
| 73 | +Expected: PASS. |
| 74 | + |
| 75 | +### Task 3: Add failing defaults tests for live mode |
| 76 | + |
| 77 | +**Files:** |
| 78 | +- Modify: `tests/test_default_file_resolution.py` |
| 79 | +- Modify: `tests/test_smoke.py` |
| 80 | +- Modify: `nanonis_qcodes_controller/config/settings.py` |
| 81 | +- Modify: `nanonis_qcodes_controller/resources/config/default_runtime.yaml` |
| 82 | + |
| 83 | +**Step 1: Update/add failing tests for fallback defaults** |
| 84 | + |
| 85 | +Assert `SafetySettings()` default values are: |
| 86 | +- `allow_writes is True` |
| 87 | +- `dry_run is False` |
| 88 | + |
| 89 | +**Step 2: Update/add failing tests for packaged YAML defaults** |
| 90 | + |
| 91 | +Assert `config/default_runtime.yaml` resolves to: |
| 92 | +- `safety.allow_writes == True` |
| 93 | +- `safety.dry_run == False` |
| 94 | + |
| 95 | +**Step 3: Run focused defaults tests (expected fail)** |
| 96 | + |
| 97 | +Run: `python -m pytest tests/test_default_file_resolution.py tests/test_smoke.py --import-mode=importlib` |
| 98 | + |
| 99 | +### Task 4: Implement default policy flip |
| 100 | + |
| 101 | +**Files:** |
| 102 | +- Modify: `nanonis_qcodes_controller/config/settings.py` |
| 103 | +- Modify: `nanonis_qcodes_controller/resources/config/default_runtime.yaml` |
| 104 | + |
| 105 | +**Step 1: Flip code fallback defaults** |
| 106 | + |
| 107 | +Set: |
| 108 | +- `SafetySettings.allow_writes = True` |
| 109 | +- `SafetySettings.dry_run = False` |
| 110 | + |
| 111 | +**Step 2: Flip packaged runtime defaults** |
| 112 | + |
| 113 | +Set: |
| 114 | +- `safety.allow_writes: true` |
| 115 | +- `safety.dry_run: false` |
| 116 | + |
| 117 | +**Step 3: Re-run focused defaults tests** |
| 118 | + |
| 119 | +Run: `python -m pytest tests/test_default_file_resolution.py tests/test_smoke.py --import-mode=importlib` |
| 120 | + |
| 121 | +Expected: PASS. |
| 122 | + |
| 123 | +### Task 5: Update README policy usage |
| 124 | + |
| 125 | +**Files:** |
| 126 | +- Modify: `README.md` |
| 127 | + |
| 128 | +**Step 1: Add `policy set` usage examples** |
| 129 | + |
| 130 | +Document: |
| 131 | +- `nqctl policy show` |
| 132 | +- `nqctl policy set --allow-writes true --dry-run false` |
| 133 | + |
| 134 | +**Step 2: Update defaults statement** |
| 135 | + |
| 136 | +Change safety defaults sentence to reflect: |
| 137 | +- `allow_writes=true` |
| 138 | +- `dry_run=false` |
| 139 | + |
| 140 | +**Step 3: Run release-doc checks** |
| 141 | + |
| 142 | +Run: `python -m pytest tests/test_release_docs.py --import-mode=importlib` |
| 143 | + |
| 144 | +### Task 6: Verify, commit, and publish next release |
| 145 | + |
| 146 | +**Files:** |
| 147 | +- Modify: `CHANGELOG.md` |
| 148 | +- Modify: `nanonis_qcodes_controller/version.py` |
| 149 | +- Modify: `pyproject.toml` |
| 150 | + |
| 151 | +**Step 1: Run verification commands** |
| 152 | + |
| 153 | +Run: |
| 154 | +- `python -m pytest tests/test_cli.py tests/test_default_file_resolution.py tests/test_smoke.py tests/test_release_docs.py --import-mode=importlib` |
| 155 | + |
| 156 | +**Step 2: Commit feature changes** |
| 157 | + |
| 158 | +Run: |
| 159 | + |
| 160 | +```bash |
| 161 | +git add nanonis_qcodes_controller/cli.py tests/test_cli.py nanonis_qcodes_controller/config/settings.py nanonis_qcodes_controller/resources/config/default_runtime.yaml tests/test_default_file_resolution.py tests/test_smoke.py README.md |
| 162 | +git commit -m "Add policy set command and live runtime defaults" |
| 163 | +``` |
| 164 | + |
| 165 | +**Step 3: Bump release version** |
| 166 | + |
| 167 | +Set next version to `0.1.10` in: |
| 168 | +- `nanonis_qcodes_controller/version.py` |
| 169 | +- `pyproject.toml` |
| 170 | +- `CHANGELOG.md` |
| 171 | + |
| 172 | +Commit: |
| 173 | + |
| 174 | +```bash |
| 175 | +git add CHANGELOG.md nanonis_qcodes_controller/version.py pyproject.toml |
| 176 | +git commit -m "release: bump version to 0.1.10" |
| 177 | +``` |
| 178 | + |
| 179 | +**Step 4: Tag and publish artifacts** |
| 180 | + |
| 181 | +Run: |
| 182 | +- `git tag v0.1.10` |
| 183 | +- `git push origin main` |
| 184 | +- `git push origin v0.1.10` |
| 185 | +- `python -m build` |
| 186 | +- `gh release create v0.1.10 --title "v0.1.10" --notes "..."` |
| 187 | +- `gh release upload v0.1.10 dist/nanonis_qcodes_controller-0.1.10-py3-none-any.whl dist/nanonis_qcodes_controller-0.1.10.tar.gz` |
0 commit comments