Fix repo urls and ref:revision syntax handling for bot_update test data

crrev.com/c/7152830 overhauled how the bot_update output json was
generated but neglected to handle the ref:revision syntax and
crrev.com/c/7147310 added a test data method to enable overriding the
URLs returned for the repos but neglected to actually pass it to the
output_json method. This change rectifies both issues.

Change-Id: I604b0d7ff3f7e68e4829624e5de66efa2f5a61b0
Recipe-Nontrivial-Roll: build
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/7219689
Reviewed-by: Yiwei Zhang <yiwzhang@google.com>
Commit-Queue: Garrett Beaty <gbeaty@google.com>
This commit is contained in:
Garrett Beaty
2025-12-03 11:21:36 -08:00
committed by LUCI CQ
parent 78d752fc04
commit 10902bc85f
4 changed files with 41 additions and 10 deletions

View File

@@ -65,7 +65,7 @@ Recipe module to ensure a checkout is consistent on a bot.
Wrapper for easy calling of bot_update.
&mdash; **def [deapply\_patch](/recipes/recipe_modules/bot_update/api.py#899)(self, bot_update_result):**
&mdash; **def [deapply\_patch](/recipes/recipe_modules/bot_update/api.py#900)(self, bot_update_result):**
Deapplies a patch, taking care of DEPS and solution revisions properly.
@@ -113,7 +113,7 @@ Args:
if a non-empty value is provided and the gclient config doesn't have
exactly 1 solution.
&mdash; **def [get\_project\_revision\_properties](/recipes/recipe_modules/bot_update/api.py#876)(self, project_name, gclient_config=None):**
&mdash; **def [get\_project\_revision\_properties](/recipes/recipe_modules/bot_update/api.py#877)(self, project_name, gclient_config=None):**
Returns all property names used for storing the checked-out revision of
a given project.
@@ -129,12 +129,12 @@ Returns (list of str): All properties that'll hold the checked-out revision
&emsp; **@property**<br>&mdash; **def [last\_returned\_properties](/recipes/recipe_modules/bot_update/api.py#294)(self):**
&mdash; **def [resolve\_fixed\_revision](/recipes/recipe_modules/bot_update/api.py#827)(self, bot_update_result, name):**
&mdash; **def [resolve\_fixed\_revision](/recipes/recipe_modules/bot_update/api.py#828)(self, bot_update_result, name):**
Sets a fixed revision for a single dependency using project revision
properties.
&mdash; **def [step\_name](/recipes/recipe_modules/bot_update/api.py#916)(self, patch, suffix):**
&mdash; **def [step\_name](/recipes/recipe_modules/bot_update/api.py#917)(self, patch, suffix):**
### *recipe_modules* / [depot\_tools](/recipes/recipe_modules/depot_tools)
[DEPS](/recipes/recipe_modules/depot_tools/__init__.py#6): [recipe\_engine/cipd][recipe_engine/recipe_modules/cipd], [recipe\_engine/context][recipe_engine/recipe_modules/context], [recipe\_engine/platform][recipe_engine/recipe_modules/platform], [recipe\_engine/runtime][recipe_engine/recipe_modules/runtime]

View File

@@ -637,6 +637,7 @@ class BotUpdateApi(recipe_api.RecipeApi):
fixed_revisions=fixed_revisions,
got_revision_mapping=reverse_rev_map,
patch_root=patch_root,
repo_urls=self._test_data.get('repo_urls', None),
fail_checkout=self._test_data.get('fail_checkout', False),
fail_patch=self._test_data.get('fail_patch', False),
commit_positions=self._test_data.get('commit_positions', True),

View File

@@ -374,6 +374,7 @@ def GenTests(api):
yield api.test(
'revisions',
ci_build(),
api.properties(patch=False),
api.bot_update.revisions({
'src': '',
'src/foo': '',
@@ -399,6 +400,7 @@ def GenTests(api):
yield api.test(
'revisions-overriding-revision-generation',
ci_build(),
api.properties(patch=False),
api.bot_update.revisions({
'infra': 'a' * 40,
}),
@@ -406,3 +408,27 @@ def GenTests(api):
'bot_update (without patch)', check_revisions_overriding_generation),
api.post_process(post_process.DropExpectation),
)
def check_revisions_ref_revision_syntax(check, output_json):
# Precondition check
if not check(output_json['fixed_revisions']['src'] == 'refs/heads/foo:' +
'a' * 40):
return # pragma: no cover
manifest = output_json['manifest']
# When the ref:revision syntax is used, the revision portion should be used
# as the revision in the output
check(manifest['src']['revision'] == 'a' * 40)
yield api.test(
'ref-revision-syntax',
api.buildbucket.generic_build(),
api.properties(
patch=False,
revision_fallback_chain=True,
revision='refs/heads/foo:' + 'a' * 40,
),
api.bot_update.post_check_output_json(
'bot_update (without patch)', check_revisions_ref_revision_syntax),
api.post_process(post_process.DropExpectation),
)

View File

@@ -137,25 +137,28 @@ class BotUpdateTestApi(recipe_test_api.RecipeTestApi):
if revision == 'HEAD':
return self.gen_revision(project_name)
if revision.startswith('refs/') or revision.startswith('origin/'):
if ':' in revision:
return revision.split(':', 1)[1]
return self.gen_revision('{}@{}'.format(project_name, revision))
return revision
def choose_revision(project_name):
def choose_revision(project_name, revision):
fixed_revision = (fixed_revisions or {}).get(project_name)
assert fixed_revision is None or fixed_revision, (
f'empty fixed_revision provided for {project_name}')
revision = revisions.get(project_name)
match (revision, fixed_revision):
case ('', _):
return resolve_revision(project_name, fixed_revision or 'HEAD')
case (_, None):
return resolve_revision(project_name, revision)
case (_, _) if revision == fixed_revision:
case (_, _) if (revision == fixed_revision
or revision == fixed_revision.split(':', 1)[-1]):
return resolve_revision(project_name, revision)
case _, _:
def will_generate(rev):
return resolve_revision(project_name, rev) != rev
return (':' not in rev
and resolve_revision(project_name, rev) != rev)
# If the revision and fixed_revision are different, then the fixed
# revision must be HEAD or a ref and revision must not be and the
@@ -167,8 +170,8 @@ class BotUpdateTestApi(recipe_test_api.RecipeTestApi):
return revision
resolved_revisions = {
project_name: choose_revision(project_name)
for project_name in revisions
project_name: choose_revision(project_name, revision)
for project_name, revision in revisions.items()
}
for project_name, fixed_revision in fixed_revisions.items():
@@ -192,6 +195,7 @@ class BotUpdateTestApi(recipe_test_api.RecipeTestApi):
ref = fixed_revision
else:
ref = 'refs/heads/main'
ref = ref.split(':', 1)[0]
properties[f'{property_name}_cp'] = '%s@{#%s}' % (
ref, self.gen_commit_position(project_name))