forked from UiPath/uipath-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_pull.py
More file actions
754 lines (670 loc) · 29.2 KB
/
Copy pathtest_pull.py
File metadata and controls
754 lines (670 loc) · 29.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
# type: ignore
import json
import os
from typing import Any
from unittest.mock import AsyncMock, patch
import pytest
from click.testing import CliRunner
from pytest_httpx import HTTPXMock
from utils.project_details import ProjectDetails
from tests.cli.utils.common import configure_env_vars
from uipath._cli import cli
from uipath._cli._utils._common import may_override_files
from uipath._cli._utils._studio_project import StudioProjectMetadata
from uipath.platform.errors import EnrichedException
def create_uipath_json(functions: dict[str, str] | None = None):
"""Helper to create uipath.json with functions structure."""
if functions is None:
functions = {"main": "main.py:main"}
return {"functions": functions}
class TestPull:
"""Test pull command."""
def test_pull_without_project_id(
self,
runner: CliRunner,
temp_dir: str,
) -> None:
"""Test pull when UIPATH_PROJECT_ID is missing."""
with runner.isolated_filesystem(temp_dir=temp_dir):
result = runner.invoke(cli, ["pull", "./"], catch_exceptions=False, env={})
assert result.exit_code == 1
assert "UIPATH_PROJECT_ID environment variable not found." in result.output
def test_successful_pull(
self,
runner: CliRunner,
temp_dir: str,
project_details: ProjectDetails,
mock_env_vars: dict[str, str],
httpx_mock: HTTPXMock,
) -> None:
"""Test successful project pull with various file operations."""
base_url = "https://cloud.uipath.com/organization"
project_id = "test-project-id"
# Mock the project structure response
mock_structure = {
"id": "root",
"name": "root",
"folders": [
{
"id": "evaluations-folder-id",
"name": "evaluations",
"folders": [
{
"id": "eval-sets-id",
"name": "eval-sets",
"files": [
{
"id": "eval-sets-file-id",
"name": "test-set.json",
"isMain": False,
"fileType": "1",
"isEntryPoint": False,
"ignoredFromPublish": False,
}
],
"folders": [],
},
{
"id": "evaluators-id",
"name": "evaluators",
"files": [
{
"id": "evaluators-file-id",
"name": "test-evaluator.json",
"isMain": False,
"fileType": "1",
"isEntryPoint": False,
"ignoredFromPublish": False,
}
],
"folders": [],
},
],
"files": [],
},
],
"files": [
{
"id": "123",
"name": "main.py",
"isMain": True,
"fileType": "1",
"isEntryPoint": True,
"ignoredFromPublish": False,
},
{
"id": "456",
"name": "pyproject.toml",
"isMain": False,
"fileType": "1",
"isEntryPoint": False,
"ignoredFromPublish": False,
},
{
"id": "789",
"name": "uipath.json",
"isMain": False,
"fileType": "1",
"isEntryPoint": False,
"ignoredFromPublish": False,
},
],
"folderType": "0",
}
httpx_mock.add_response(
url=f"{base_url}/studio_/backend/api/Project/{project_id}/FileOperations/Structure",
json=mock_structure,
)
# Mock file download responses
# For main.py
httpx_mock.add_response(
method="GET",
url=f"{base_url}/studio_/backend/api/Project/{project_id}/FileOperations/File/123",
content=b"print('Hello World')",
)
# For pyproject.toml
httpx_mock.add_response(
method="GET",
url=f"{base_url}/studio_/backend/api/Project/{project_id}/FileOperations/File/456",
content=project_details.to_toml().encode(),
)
# For uipath.json
uipath_json_content = create_uipath_json({"main": "main.py:main"})
httpx_mock.add_response(
method="GET",
url=f"{base_url}/studio_/backend/api/Project/{project_id}/FileOperations/File/789",
content=json.dumps(uipath_json_content).encode(),
)
# For eval-sets/test-set.json
test_set_content = {
"id": "02424d08-f482-4777-ac4d-233add24ee06",
"fileName": "evaluation-set-1752568767335.json",
"evaluatorRefs": [
"429d73a2-a748-4554-83d7-e32dec345931",
"bdb9f7c9-2d9e-4595-81c8-ef2a60216cb9",
],
"evaluations": [],
"name": "Evaluation Set 2",
"batchSize": 10,
"timeoutMinutes": 20,
"modelSettings": [],
"createdAt": "2025-07-15T08:39:27.335Z",
"updatedAt": "2025-07-15T08:39:27.335Z",
}
httpx_mock.add_response(
method="GET",
url=f"{base_url}/studio_/backend/api/Project/{project_id}/FileOperations/File/eval-sets-file-id",
content=json.dumps(test_set_content, indent=2).encode(),
)
# For evaluators/test-evaluator.json
test_evaluator_content = {
"fileName": "evaluator-1752568815245.json",
"id": "52b716b1-c8ef-4da8-af31-fb218d0d5499",
"name": "Evaluator 3",
"description": "An evaluator that judges the agent based on its run history and expected behavior",
"type": 7,
"category": 3,
"prompt": "As an expert evaluator, determine how well the agent did on a scale of 0-100. Focus on if the simulation was successful and if the agent behaved according to the expected output accounting for alternative valid expressions, and reasonable variations in language while maintaining high standards for accuracy and completeness. Provide your score with a justification, explaining briefly and concisely why you gave that score.\n----\nUserOrSyntheticInputGivenToAgent:\n{{UserOrSyntheticInput}}\n----\nSimulationInstructions:\n{{SimulationInstructions}}\n----\nExpectedAgentBehavior:\n{{ExpectedAgentBehavior}}\n----\nAgentRunHistory:\n{{AgentRunHistory}}\n",
"targetOutputKey": "*",
"createdAt": "2025-07-15T08:40:15.245Z",
"updatedAt": "2025-07-15T08:40:15.245Z",
}
httpx_mock.add_response(
method="GET",
url=f"{base_url}/studio_/backend/api/Project/{project_id}/FileOperations/File/evaluators-file-id",
content=json.dumps(test_evaluator_content, indent=2).encode(),
)
with runner.isolated_filesystem(temp_dir=temp_dir):
# Set environment variables
configure_env_vars(mock_env_vars)
os.environ["UIPATH_PROJECT_ID"] = project_id
# Run pull
result = runner.invoke(cli, ["pull", "./"])
assert result.exit_code == 0
# Verify source code files
assert "Downloaded 'main.py'" in result.output
assert "Downloaded 'pyproject.toml'" in result.output
assert "Downloaded 'uipath.json'" in result.output
# Verify source code file contents
with open("main.py", "r") as f:
assert f.read() == "print('Hello World')"
with open("pyproject.toml", "r") as f:
assert f.read() == project_details.to_toml()
with open("uipath.json", "r") as f:
assert json.load(f) == uipath_json_content
# Verify evals folder structure exists
assert os.path.isdir("evaluations")
assert os.path.isdir("evaluations/eval-sets")
assert os.path.isdir("evaluations/evaluators")
# Verify eval files exist and have correct content
with open("evaluations/eval-sets/test-set.json", "r") as f:
assert json.load(f) == test_set_content
with open("evaluations/evaluators/test-evaluator.json", "r") as f:
assert json.load(f) == test_evaluator_content
def test_pull_with_existing_files(
self,
runner: CliRunner,
temp_dir: str,
project_details: ProjectDetails,
mock_env_vars: dict[str, str],
httpx_mock: HTTPXMock,
monkeypatch: Any,
) -> None:
"""Test pull when local files exist and differ from remote."""
base_url = "https://cloud.uipath.com/organization"
project_id = "test-project-id"
# Mock the project structure response
mock_structure = {
"id": "root",
"name": "root",
"folders": [],
"files": [
{
"id": "123",
"name": "main.py",
"isMain": True,
"fileType": "1",
"isEntryPoint": True,
"ignoredFromPublish": False,
},
{
"id": "456",
"name": "pyproject.toml",
"isMain": True,
"fileType": "1",
"isEntryPoint": True,
"ignoredFromPublish": False,
},
],
"folderType": "0",
}
httpx_mock.add_response(
url=f"{base_url}/studio_/backend/api/Project/{project_id}/FileOperations/Structure",
json=mock_structure,
)
# Mock file download response
remote_content = "print('Remote version')"
httpx_mock.add_response(
method="GET",
url=f"{base_url}/studio_/backend/api/Project/{project_id}/FileOperations/File/123",
content=remote_content.encode(),
)
remote_content_toml = "toml content"
httpx_mock.add_response(
method="GET",
url=f"{base_url}/studio_/backend/api/Project/{project_id}/FileOperations/File/456",
content=remote_content_toml.encode(),
)
with runner.isolated_filesystem(temp_dir=temp_dir):
# Create local file with different content
local_content = "print('Local version')"
with open("main.py", "w") as f:
f.write(local_content)
# Set environment variables
configure_env_vars(mock_env_vars)
os.environ["UIPATH_PROJECT_ID"] = project_id
# Mock user input to confirm override
monkeypatch.setattr("click.confirm", lambda *args, **kwargs: True)
# Run pull
result = runner.invoke(cli, ["pull", "./"])
assert result.exit_code == 0
# assert "differs from remote version" in result.output
assert "Updated 'main.py'" in result.output
# Verify file was updated
with open("main.py", "r") as f:
assert f.read() == remote_content
def test_pull_with_api_error(
self,
runner: CliRunner,
temp_dir: str,
project_details: ProjectDetails,
mock_env_vars: dict[str, str],
httpx_mock: HTTPXMock,
) -> None:
"""Test pull when API request fails."""
base_url = "https://cloud.uipath.com/organization"
project_id = "test-project-id"
# Mock API error response
httpx_mock.add_response(
url=f"{base_url}/studio_/backend/api/Project/{project_id}/FileOperations/Structure",
status_code=401,
json={"message": "Unauthorized"},
)
with runner.isolated_filesystem(temp_dir=temp_dir):
# Set environment variables
configure_env_vars(mock_env_vars)
os.environ["UIPATH_PROJECT_ID"] = project_id
result = runner.invoke(cli, ["pull", "./"])
assert result.exit_code == 1
assert isinstance(result.exception, EnrichedException)
assert result.exception.status_code == 401
def test_pull_non_coded_agent_project(
self,
runner: CliRunner,
temp_dir: str,
project_details: ProjectDetails,
mock_env_vars: dict[str, str],
httpx_mock: HTTPXMock,
) -> None:
"""Test pull when the project is not a coded agent project (missing pyproject.toml)."""
base_url = "https://cloud.uipath.com/organization"
project_id = "test-project-id"
# Mock a project structure WITHOUT pyproject.toml (not a coded agent project)
mock_structure = {
"id": "root",
"name": "root",
"folders": [],
"files": [
{
"id": "789",
"name": "uipath.json",
"isMain": False,
"fileType": "1",
"isEntryPoint": False,
"ignoredFromPublish": False,
},
{
"id": "456",
"name": "main.xaml",
"isMain": True,
"fileType": "1",
"isEntryPoint": True,
"ignoredFromPublish": False,
},
],
"folderType": "0",
}
httpx_mock.add_response(
url=f"{base_url}/studio_/backend/api/Project/{project_id}/FileOperations/Structure",
json=mock_structure,
)
with runner.isolated_filesystem(temp_dir=temp_dir):
configure_env_vars(mock_env_vars)
os.environ["UIPATH_PROJECT_ID"] = project_id
result = runner.invoke(cli, ["pull", "./"])
assert result.exit_code == 1
assert (
"The targeted Studio Web project is not of type coded agent"
in result.output
)
assert (
"Please check the UIPATH_PROJECT_ID environment variable"
in result.output
)
def test_pull_multiple_eval_folders(
self,
runner: CliRunner,
temp_dir: str,
project_details: ProjectDetails,
mock_env_vars: dict[str, str],
httpx_mock: HTTPXMock,
) -> None:
"""Test that pull command uses evaluations folder instead of evals."""
base_url = "https://cloud.uipath.com/organization"
project_id = "test-project-id"
# Mock the project structure with evaluations folder
mock_structure = {
"id": "root",
"name": "root",
"folders": [
{
"id": "evaluations-id",
"name": "evaluations",
"folders": [
{
"id": "evaluators-id",
"name": "evaluators",
"files": [
{
"id": "evaluator-1-id",
"name": "contains.json",
"isMain": False,
"fileType": "1",
"isEntryPoint": False,
"ignoredFromPublish": False,
}
],
"folders": [],
},
{
"id": "eval-sets-id",
"name": "eval-sets",
"files": [
{
"id": "eval-set-1-id",
"name": "default.json",
"isMain": False,
"fileType": "1",
"isEntryPoint": False,
"ignoredFromPublish": False,
}
],
"folders": [],
},
],
"files": [],
},
{
"id": "evals-id-legacy",
"name": "evals",
"folders": [
{
"id": "evaluators-id",
"name": "evaluators",
"files": [
{
"id": "evaluator-1-id-legacy",
"name": "contains.json",
"isMain": False,
"fileType": "1",
"isEntryPoint": False,
"ignoredFromPublish": False,
}
],
"folders": [],
},
{
"id": "eval-sets-id",
"name": "eval-sets",
"files": [
{
"id": "eval-set-1-id-legacy",
"name": "default.json",
"isMain": False,
"fileType": "1",
"isEntryPoint": False,
"ignoredFromPublish": False,
}
],
"folders": [],
},
],
"files": [],
},
],
"files": [
{
"id": "main-py-id",
"name": "main.py",
"isMain": True,
"fileType": "1",
"isEntryPoint": True,
"ignoredFromPublish": False,
},
{
"id": "456",
"name": "pyproject.toml",
"isMain": True,
"fileType": "1",
"isEntryPoint": True,
"ignoredFromPublish": False,
},
],
"folderType": "0",
}
httpx_mock.add_response(
url=f"{base_url}/studio_/backend/api/Project/{project_id}/FileOperations/Structure",
json=mock_structure,
)
# Mock file downloads
httpx_mock.add_response(
method="GET",
url=f"{base_url}/studio_/backend/api/Project/{project_id}/FileOperations/File/main-py-id",
content=b"print('test')",
)
httpx_mock.add_response(
method="GET",
url=f"{base_url}/studio_/backend/api/Project/{project_id}/FileOperations/File/456",
content=b"toml content",
)
evaluator_content = {"version": "1.0", "name": "Contains Evaluator"}
httpx_mock.add_response(
method="GET",
url=f"{base_url}/studio_/backend/api/Project/{project_id}/FileOperations/File/evaluator-1-id",
content=json.dumps(evaluator_content, indent=2).encode(),
)
eval_set_content = {"version": "1.0", "name": "Default Eval Set"}
httpx_mock.add_response(
method="GET",
url=f"{base_url}/studio_/backend/api/Project/{project_id}/FileOperations/File/eval-set-1-id",
content=json.dumps(eval_set_content, indent=2).encode(),
)
evaluator_content_legacy = {
"version": "1.0",
"name": "Contains Evaluator legacy",
}
httpx_mock.add_response(
method="GET",
url=f"{base_url}/studio_/backend/api/Project/{project_id}/FileOperations/File/evaluator-1-id-legacy",
content=json.dumps(evaluator_content_legacy, indent=2).encode(),
)
eval_set_content_legacy = {"version": "1.0", "name": "Default Eval Set legacy"}
httpx_mock.add_response(
method="GET",
url=f"{base_url}/studio_/backend/api/Project/{project_id}/FileOperations/File/eval-set-1-id-legacy",
content=json.dumps(eval_set_content_legacy, indent=2).encode(),
)
with runner.isolated_filesystem(temp_dir=temp_dir):
configure_env_vars(mock_env_vars)
os.environ["UIPATH_PROJECT_ID"] = project_id
result = runner.invoke(cli, ["pull", "./"])
assert result.exit_code == 0
# Verify files from evaluations are downloaded to evaluations/ directory
assert os.path.exists("evaluations/evaluators/contains.json")
assert os.path.exists("evaluations/eval-sets/default.json")
# Verify content
with open("evaluations/evaluators/contains.json", "r") as f:
assert json.load(f) == evaluator_content
with open("evaluations/eval-sets/default.json", "r") as f:
assert json.load(f) == eval_set_content
# Verify files from evals are downloaded to evals/ directory
assert os.path.exists("evals/evaluators/contains.json")
assert os.path.exists("evals/eval-sets/default.json")
# Verify content
with open("evals/evaluators/contains.json", "r") as f:
assert json.load(f) == evaluator_content_legacy
with open("evals/eval-sets/default.json", "r") as f:
assert json.load(f) == eval_set_content_legacy
class TestMayOverrideFiles:
"""Test may_override_files function for pull scenarios."""
@pytest.mark.asyncio
async def test_no_remote_metadata_returns_true(self):
"""Test that when remote metadata doesn't exist, returns True without prompting."""
mock_studio_client = AsyncMock()
mock_studio_client.get_project_metadata_async.return_value = None
result = await may_override_files(mock_studio_client, "local")
assert result is True
@pytest.mark.asyncio
async def test_no_local_metadata_prompts_user_confirms(self, tmp_path, monkeypatch):
"""Test that when local metadata doesn't exist, prompts user and returns True on confirm."""
# Create mock remote metadata
remote_metadata = StudioProjectMetadata(
schema_version="1.0",
last_push_date="2025-11-18T17:18:06.809284+00:00",
last_push_author="test-user",
code_version="1.0.0",
)
mock_studio_client = AsyncMock()
mock_studio_client.get_project_metadata_async.return_value = remote_metadata
# Mock UiPathConfig to return non-existent path
with patch("uipath._cli._utils._common.UiPathConfig") as mock_config:
mock_config.studio_metadata_file_path = (
tmp_path / ".uipath" / "metadata.json"
)
# Mock console.confirm to return True
with patch(
"uipath._cli._utils._common.ConsoleLogger"
) as mock_console_class:
mock_console = mock_console_class.return_value
mock_console.confirm.return_value = True
result = await may_override_files(mock_studio_client, "local")
assert result is True
mock_console.warning.assert_called_once()
mock_console.confirm.assert_called_once()
@pytest.mark.asyncio
async def test_no_local_metadata_prompts_user_denies(self, tmp_path):
"""Test that when local metadata doesn't exist, prompts user and returns False on deny."""
remote_metadata = StudioProjectMetadata(
schema_version="1.0",
last_push_date="2025-11-18T17:18:06.809284+00:00",
last_push_author="test-user",
code_version="1.0.0",
)
mock_studio_client = AsyncMock()
mock_studio_client.get_project_metadata_async.return_value = remote_metadata
with patch("uipath._cli._utils._common.UiPathConfig") as mock_config:
mock_config.studio_metadata_file_path = (
tmp_path / ".uipath" / "metadata.json"
)
with patch(
"uipath._cli._utils._common.ConsoleLogger"
) as mock_console_class:
mock_console = mock_console_class.return_value
mock_console.confirm.return_value = False
result = await may_override_files(mock_studio_client, "local")
assert result is False
@pytest.mark.asyncio
async def test_local_version_greater_than_remote_returns_true(self, tmp_path):
"""Test that when local version >= remote version, returns True without prompting."""
remote_metadata = StudioProjectMetadata(
schema_version="1.0",
last_push_date="2025-11-18T17:18:06.809284+00:00",
last_push_author="test-user",
code_version="1.0.0",
)
mock_studio_client = AsyncMock()
mock_studio_client.get_project_metadata_async.return_value = remote_metadata
# Create local metadata file with higher version
metadata_dir = tmp_path / ".uipath"
metadata_dir.mkdir(parents=True)
metadata_file = metadata_dir / "metadata.json"
local_metadata = {
"schemaVersion": "1.0",
"lastPushDate": "2025-11-19T10:00:00.000000+00:00",
"lastPushAuthor": "local-user",
"codeVersion": "2.0.0",
}
metadata_file.write_text(json.dumps(local_metadata))
with patch("uipath._cli._utils._common.UiPathConfig") as mock_config:
mock_config.studio_metadata_file_path = metadata_file
result = await may_override_files(mock_studio_client, "local")
assert result is True
@pytest.mark.asyncio
async def test_local_version_less_than_remote_prompts_user(self, tmp_path):
"""Test that when local version < remote version, prompts user."""
remote_metadata = StudioProjectMetadata(
schema_version="1.0",
last_push_date="2025-11-18T17:18:06.809284+00:00",
last_push_author="test-user",
code_version="2.0.0",
)
mock_studio_client = AsyncMock()
mock_studio_client.get_project_metadata_async.return_value = remote_metadata
# Create local metadata file with lower version
metadata_dir = tmp_path / ".uipath"
metadata_dir.mkdir(parents=True)
metadata_file = metadata_dir / "metadata.json"
local_metadata = {
"schemaVersion": "1.0",
"lastPushDate": "2025-11-17T10:00:00.000000+00:00",
"lastPushAuthor": "local-user",
"codeVersion": "1.0.0",
}
metadata_file.write_text(json.dumps(local_metadata))
with patch("uipath._cli._utils._common.UiPathConfig") as mock_config:
mock_config.studio_metadata_file_path = metadata_file
with patch(
"uipath._cli._utils._common.ConsoleLogger"
) as mock_console_class:
mock_console = mock_console_class.return_value
mock_console.confirm.return_value = True
result = await may_override_files(mock_studio_client, "local")
assert result is True
mock_console.warning.assert_called_once()
mock_console.confirm.assert_called_once()
@pytest.mark.asyncio
async def test_local_version_equal_to_remote_returns_true(self, tmp_path):
"""Test that when local version == remote version, returns True without prompting."""
remote_metadata = StudioProjectMetadata(
schema_version="1.0",
last_push_date="2025-11-18T17:18:06.809284+00:00",
last_push_author="test-user",
code_version="1.0.0",
)
mock_studio_client = AsyncMock()
mock_studio_client.get_project_metadata_async.return_value = remote_metadata
# Create local metadata file with same version
metadata_dir = tmp_path / ".uipath"
metadata_dir.mkdir(parents=True)
metadata_file = metadata_dir / "metadata.json"
local_metadata = {
"schemaVersion": "1.0",
"lastPushDate": "2025-11-18T17:18:06.809284+00:00",
"lastPushAuthor": "local-user",
"codeVersion": "1.0.0",
}
metadata_file.write_text(json.dumps(local_metadata))
with patch("uipath._cli._utils._common.UiPathConfig") as mock_config:
mock_config.studio_metadata_file_path = metadata_file
result = await may_override_files(mock_studio_client, "local")
assert result is True