Skip to content

Commit 85a46d2

Browse files
Alon YeshurunCopilot
andcommitted
fix: address copilot review comments
- Fix init_defaults() to set changed=True after deleting mode key and also clean up legacy fab_mode key - Update test_context_persistence comments to reflect that REPL mode (not disabled persistence) is why file ops are skipped - Use tmp_path instead of tempfile.mkdtemp() in _create_temp_config for automatic cleanup - Rename double-underscore test names to single underscore in test_core - Update PR description: Context singleton (not fab_constant) exposes runtime mode helpers Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent ddb8d4a commit 85a46d2

5 files changed

Lines changed: 23 additions & 22 deletions

File tree

src/fabric_cli/core/fab_state_config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def init_defaults():
5959
# Migration: remove the deprecated 'mode' key (mode is now detected at runtime)
6060
if fab_constant.FAB_MODE in current_config:
6161
del current_config[fab_constant.FAB_MODE]
62+
changed = True
6263

6364
for key in fab_constant.FAB_CONFIG_KEYS_TO_VALID_VALUES:
6465
old_key = f"fab_{key}"

tests/test_core/test_context_persistence.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,11 @@ def mock_get_config(key):
109109
patch.object(context, "_load_context_from_file") as mock_load,
110110
):
111111

112-
# Set the context - this should NOT trigger file save when persistence is disabled
112+
# Set the context - file save is skipped because REPL/interactive runtime mode
113+
# disables context-file persistence even when the setting is enabled
113114
context.context = workspace
114115

115-
# Get the context - this should NOT trigger file load when persistence is disabled
116+
# Get the context - file load is skipped for the same reason
116117
result = context.context
117118

118119
# Verify that file operations were not called

tests/test_core/test_fab_fs_mv_folder.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def mock_api_response_failure():
6363
@patch("fabric_cli.utils.fab_ui.print_output_format")
6464
@patch("fabric_cli.utils.fab_mem_store.upsert_folder_to_cache")
6565
@patch("fabric_cli.client.fab_api_folders.move_folder")
66-
def test_change_folder_parent__folder_target_success(
66+
def test_change_folder_parent_folder_target_success(
6767
mock_move_folder_api,
6868
mock_upsert_folder_cache,
6969
mock_print_output,

tests/test_core/test_fab_hiearchy.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -555,27 +555,27 @@ def _make_item(item_type: str, parent=None) -> Item:
555555
class TestBuildPayload:
556556
"""Validate _build_definition includes format when provided."""
557557

558-
def test_with_format__includes_format_key(self, tmp_path):
558+
def test_with_format_includes_format_key(self, tmp_path):
559559
(tmp_path / "notebook.ipynb").write_text("{}")
560560
result = _build_definition(str(tmp_path), "ipynb")
561561
assert result["format"] == "ipynb"
562562
assert len(result["parts"]) == 1
563563
assert result["parts"][0]["path"] == "notebook.ipynb"
564564

565-
def test_without_format__no_format_key(self, tmp_path):
565+
def test_without_format_no_format_key(self, tmp_path):
566566
(tmp_path / "notebook.ipynb").write_text("{}")
567567
result = _build_definition(str(tmp_path))
568568
assert "format" not in result
569569
assert len(result["parts"]) == 1
570570

571-
def test_empty_format__no_format_key(self, tmp_path):
571+
def test_empty_format_no_format_key(self, tmp_path):
572572
(tmp_path / "file.json").write_text("{}")
573573
result = _build_definition(str(tmp_path), "")
574574
assert "format" not in result
575575

576576
# -- Payload construction tests -------------------------------------------
577577

578-
def test_payload__lakehouse(self):
578+
def test_payload_lakehouse(self):
579579
"""Any item type can have a payload constructed."""
580580
item = _make_item("Lakehouse")
581581

@@ -588,7 +588,7 @@ def _mock_build(path, resolved_format=""):
588588
assert payload["displayName"] == "item"
589589
assert payload["definition"] == {"parts": {"key": "value"}}
590590

591-
def test_payload__kql_dashboard(self):
591+
def test_payload_kql_dashboard(self):
592592
"""KQLDashboard (was in ImportDefinitionTypes) still works."""
593593
item = _make_item("KQLDashboard")
594594

@@ -601,7 +601,7 @@ def _mock_build(path, resolved_format=""):
601601

602602
# -- Folder-based items include folderId ----------------------------------
603603

604-
def test_payload__item_in_folder__includes_folder_id(self):
604+
def test_payload_item_in_folder_includes_folder_id(self):
605605
"""Items inside a folder should have folderId set."""
606606
tenant = Tenant(name="t", id="tid")
607607
ws = Workspace(name="ws", id="wsid", parent=tenant, type="Workspace")
@@ -619,14 +619,14 @@ def _mock_build(path, resolved_format=""):
619619
assert payload["folderId"] == "folder123"
620620
assert payload["definition"]["format"] == "ipynb"
621621

622-
def test_payload__item_in_workspace__folder_id_none(self):
622+
def test_payload_item_in_workspace_folder_id_none(self):
623623
"""Items directly under workspace should have folderId=None."""
624624
item = _make_item("Notebook")
625625
assert item.folder_id is None
626626

627627
# -- Unknown format is now validated upstream by resolve_definition_format --
628628

629-
def test_unknown_format__raises_error(self):
629+
def test_unknown_format_raises_error(self):
630630
"""Unknown format raises FabricCLIError during resolution."""
631631
from fabric_cli.utils.fab_item_util import resolve_definition_format
632632

tests/test_core/test_fab_state_config.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,19 +104,18 @@ def tracking_write(data):
104104
# region init_defaults migration
105105

106106

107-
def _create_temp_config(monkeypatch, config_data):
107+
def _create_temp_config(monkeypatch, tmp_path, config_data):
108108
"""Create a temp config file with the given data and monkeypatch cfg.config_file to point to it."""
109-
tmpdir = tempfile.mkdtemp()
110-
config_file = os.path.join(tmpdir, "config.json")
109+
config_file = os.path.join(tmp_path, "config.json")
111110
with open(config_file, "w") as f:
112111
json.dump(config_data, f)
113112
monkeypatch.setattr(cfg, "config_file", config_file)
114113
return config_file
115114

116115

117-
def test_init_defaults_removes_mode_key_success(monkeypatch):
116+
def test_init_defaults_removes_mode_key_success(monkeypatch, tmp_path):
118117
"""If an existing config file contains 'mode', init_defaults must delete it."""
119-
config_file = _create_temp_config(monkeypatch, {
118+
config_file = _create_temp_config(monkeypatch, tmp_path, {
120119
fab_constant.FAB_MODE: fab_constant.FAB_MODE_INTERACTIVE,
121120
fab_constant.FAB_CACHE_ENABLED: "true",
122121
})
@@ -128,9 +127,9 @@ def test_init_defaults_removes_mode_key_success(monkeypatch):
128127
assert result[fab_constant.FAB_CACHE_ENABLED] == "true"
129128

130129

131-
def test_init_defaults_no_mode_key_success(monkeypatch):
130+
def test_init_defaults_no_mode_key_success(monkeypatch, tmp_path):
132131
"""Config without 'mode' must initialize cleanly (distinct from removes_mode_key: verifies no error on absence)."""
133-
config_file = _create_temp_config(monkeypatch, {
132+
config_file = _create_temp_config(monkeypatch, tmp_path, {
134133
fab_constant.FAB_DEBUG_ENABLED: "true",
135134
})
136135

@@ -141,9 +140,9 @@ def test_init_defaults_no_mode_key_success(monkeypatch):
141140
assert result[fab_constant.FAB_DEBUG_ENABLED] == "true"
142141

143142

144-
def test_init_defaults_applies_missing_defaults_success(monkeypatch):
143+
def test_init_defaults_applies_missing_defaults_success(monkeypatch, tmp_path):
145144
"""init_defaults must fill in missing default values."""
146-
config_file = _create_temp_config(monkeypatch, {})
145+
config_file = _create_temp_config(monkeypatch, tmp_path, {})
147146

148147
cfg.init_defaults()
149148

@@ -154,9 +153,9 @@ def test_init_defaults_applies_missing_defaults_success(monkeypatch):
154153
)
155154

156155

157-
def test_init_defaults_preserves_user_overrides_success(monkeypatch):
156+
def test_init_defaults_preserves_user_overrides_success(monkeypatch, tmp_path):
158157
"""User-set values must not be overwritten by defaults."""
159-
config_file = _create_temp_config(monkeypatch, {
158+
config_file = _create_temp_config(monkeypatch, tmp_path, {
160159
fab_constant.FAB_CACHE_ENABLED: "false",
161160
})
162161

0 commit comments

Comments
 (0)