Skip to content

Commit ea3601b

Browse files
committed
fix: reject import-only flags when --export-diff is set
_validate_argument_combinations now explicitly errors on: - --slugs with --export-diff - --verify-images with --export-diff - --force-resolve-conflicts with --export-diff Previously these were silently ignored, potentially confusing users who passed them expecting them to take effect during an export run. Added three regression tests for the new checks.
1 parent 241d240 commit ea3601b

3 files changed

Lines changed: 62 additions & 1 deletion

File tree

ignored.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"a": "b"}

nb-dt-import.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,12 @@ def _validate_argument_combinations(parser, args):
839839
parser.error("--export-diff cannot be used with --remove-components")
840840
if args.export_diff and getattr(args, "remove_unmanaged_types", False):
841841
parser.error("--remove-unmanaged-types is an import-only flag and cannot be used with --export-diff")
842+
if args.export_diff and getattr(args, "slugs", None):
843+
parser.error("--slugs is an import-only flag and cannot be used with --export-diff")
844+
if args.export_diff and getattr(args, "verify_images", False):
845+
parser.error("--verify-images is an import-only flag and cannot be used with --export-diff")
846+
if args.export_diff and getattr(args, "force_resolve_conflicts", False):
847+
parser.error("--force-resolve-conflicts is an import-only flag and cannot be used with --export-diff")
842848
if args.remove_components and not args.update:
843849
parser.error("--remove-components requires --update")
844850
if args.remove_unmanaged_types and not args.remove_components:

tests/test_nb_dt_import.py

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1509,7 +1509,61 @@ def test_validate_argument_combinations_blocks_remove_unmanaged_with_export_diff
15091509
"--remove-unmanaged-types is an import-only flag and cannot be used with --export-diff"
15101510
)
15111511

1512-
def test_run_export_diff_wires_exporter_and_progress(self, nb_dt_import):
1512+
def test_validate_argument_combinations_blocks_slugs_with_export_diff(self, nb_dt_import):
1513+
parser = MagicMock()
1514+
parser.error.side_effect = SystemExit(2)
1515+
args = SimpleNamespace(
1516+
export_diff=True,
1517+
update=False,
1518+
only_new=False,
1519+
remove_components=False,
1520+
remove_unmanaged_types=False,
1521+
force_resolve_conflicts=False,
1522+
slugs=["nokia-7750"],
1523+
verify_images=False,
1524+
)
1525+
with pytest.raises(SystemExit):
1526+
nb_dt_import._validate_argument_combinations(parser, args)
1527+
parser.error.assert_called_once_with("--slugs is an import-only flag and cannot be used with --export-diff")
1528+
1529+
def test_validate_argument_combinations_blocks_verify_images_with_export_diff(self, nb_dt_import):
1530+
parser = MagicMock()
1531+
parser.error.side_effect = SystemExit(2)
1532+
args = SimpleNamespace(
1533+
export_diff=True,
1534+
update=False,
1535+
only_new=False,
1536+
remove_components=False,
1537+
remove_unmanaged_types=False,
1538+
force_resolve_conflicts=False,
1539+
slugs=[],
1540+
verify_images=True,
1541+
)
1542+
with pytest.raises(SystemExit):
1543+
nb_dt_import._validate_argument_combinations(parser, args)
1544+
parser.error.assert_called_once_with(
1545+
"--verify-images is an import-only flag and cannot be used with --export-diff"
1546+
)
1547+
1548+
def test_validate_argument_combinations_blocks_force_resolve_with_export_diff(self, nb_dt_import):
1549+
parser = MagicMock()
1550+
parser.error.side_effect = SystemExit(2)
1551+
args = SimpleNamespace(
1552+
export_diff=True,
1553+
update=False,
1554+
only_new=False,
1555+
remove_components=False,
1556+
remove_unmanaged_types=False,
1557+
force_resolve_conflicts=True,
1558+
slugs=[],
1559+
verify_images=False,
1560+
)
1561+
with pytest.raises(SystemExit):
1562+
nb_dt_import._validate_argument_combinations(parser, args)
1563+
parser.error.assert_called_once_with(
1564+
"--force-resolve-conflicts is an import-only flag and cannot be used with --export-diff"
1565+
)
1566+
15131567
"""_run_export_diff wires up Exporter with progress panel and console."""
15141568
handle = MagicMock()
15151569
progress = MagicMock()

0 commit comments

Comments
 (0)