Agent Zero AI framework
Add tag existence validation to self-update system
frdel78ea2040a9db
diff --git a/helpers/self_update.py b/helpers/self_update.pyindex 95d197ac1..89b1386d6 100644--- a/helpers/self_update.py+++ b/helpers/self_update.py@@ -315,6 +315,20 @@ def schedule_update(if not _is_selector_supported_tag(normalized_tag):raise ValueError("Release tag must be v1.0 or newer.")+ available_tags, tag_lookup_error = get_available_tags(+ normalized_branch,+ repo_dir=repository,+ query=normalized_tag,+ )+ if tag_lookup_error:+ raise RuntimeError(+ f"Failed to verify release tag {normalized_tag} on branch {normalized_branch}: {tag_lookup_error}"+ )+ if normalized_tag not in available_tags:+ raise ValueError(+ f"Version {normalized_tag} does not exist on branch {normalized_branch}."+ )+normalized_policy = backup_conflict_policy.strip().lower()if normalized_policy not in BACKUP_CONFLICT_POLICIES:raise ValueError(diff --git a/tests/test_self_update_tag_filter.py b/tests/test_self_update_tag_filter.pyindex 703fbe1cb..e2789b2fb 100644--- a/tests/test_self_update_tag_filter.py+++ b/tests/test_self_update_tag_filter.py@@ -2,6 +2,8 @@ import sysimport typesfrom pathlib import Path+import pytest+PROJECT_ROOT = Path(__file__).resolve().parents[1]if str(PROJECT_ROOT) not in sys.path:@@ -49,3 +51,53 @@ def test_self_update_frontend_filters_old_tag_suggestions():assert "response.tags.filter((tag) => this.isSupportedSuggestionTag(tag))" in contentassert "Release tag must use the format vX.Y." in contentassert "Release tag must be v1.0 or newer." in content+ assert "this.info?.defaults?.branch ||" in content+ assert "Version ${tag} does not exist on branch" in content+ assert "this.selectedTagExistsOnBranch" in content+++def test_self_update_modal_validates_exact_tag_on_blur():+ modal_path = (+ PROJECT_ROOT+ / "webui"+ / "components"+ / "settings"+ / "external"+ / "self-update-modal.html"+ )+ content = modal_path.read_text(encoding="utf-8")++ assert '@blur="$store.selfUpdateStore.onTagBlur()"' in content+ assert '@mousedown.prevent="$store.selfUpdateStore.selectTag(tag)"' in content+ assert "$store.selfUpdateStore.tagExistenceWarning" in content+++def test_self_update_schedule_rejects_missing_tag_on_branch(monkeypatch, tmp_path):+ monkeypatch.setattr(+ self_update,+ "get_repo_version_info",+ lambda _repo: {+ "branch": "development",+ "describe": "v1.0",+ "short_tag": "v1.0",+ "commit": "abc123",+ "short_commit": "abc123",+ },+ )+ monkeypatch.setattr(+ self_update,+ "get_available_tags",+ lambda branch, *, repo_dir=None, query="": (["v1.0"], ""),+ )+ monkeypatch.setattr(self_update, "_write_yaml", lambda path, payload: None)++ with pytest.raises(ValueError, match=r"Version v1\.1 does not exist on branch development\."):+ self_update.schedule_update(+ branch="development",+ tag="v1.1",+ backup_usr=True,+ backup_path="",+ backup_name="",+ backup_conflict_policy="rename",+ repo_dir=tmp_path,+ )diff --git a/webui/components/settings/external/self-update-modal.html b/webui/components/settings/external/self-update-modal.htmlindex f265f3d47..c11bc2972 100644--- a/webui/components/settings/external/self-update-modal.html+++ b/webui/components/settings/external/self-update-modal.html@@ -142,6 +142,7 @@x-model="$store.selfUpdateStore.form.tag"@input="$store.selfUpdateStore.onTagInput()"@focus="$store.selfUpdateStore.openTagDropdown()"+ @blur="$store.selfUpdateStore.onTagBlur()"@keydown.enter.prevent="$store.selfUpdateStore.searchTags()"placeholder="v1.0":disabled="$store.selfUpdateStore.isBusy"@@ -168,7 +169,7 @@<template x-for="tag in $store.selfUpdateStore.groupedTagSuggestions.matched" :key="`match-${tag}`"><divclass="self-update-tag-item"- @click="$store.selfUpdateStore.selectTag(tag)"+ @mousedown.prevent="$store.selfUpdateStore.selectTag(tag)"x-text="tag"></div></template>@@ -181,7 +182,7 @@<template x-for="tag in $store.selfUpdateStore.groupedTagSuggestions.rest" :key="`rest-${tag}`"><divclass="self-update-tag-item"- @click="$store.selfUpdateStore.selectTag(tag)"+ @mousedown.prevent="$store.selfUpdateStore.selectTag(tag)"x-text="tag"></div></template>@@ -193,6 +194,10 @@<span x-text="$store.selfUpdateStore.versionCompatibilityWarning"></span></div>+ <div class="self-update-warning-banner" x-show="$store.selfUpdateStore.tagExistenceWarning">+ <span x-text="$store.selfUpdateStore.tagExistenceWarning"></span>+ </div>+<div class="field"><div class="field-label"><div class="field-title">Back up <code>/a0/usr</code> first</div>diff --git a/webui/components/settings/external/self-update-store.js b/webui/components/settings/external/self-update-store.jsindex f15272333..fabf07772 100644--- a/webui/components/settings/external/self-update-store.js+++ b/webui/components/settings/external/self-update-store.js@@ -18,6 +18,7 @@ const model = {info: null,tagSuggestions: [],tagDropdownOpen: false,+ tagExistenceChecked: false,restartStatusText: "",restartDetailText: "",form: {@@ -66,6 +67,15 @@ const model = {return { matched, rest };},+ get trimmedTag() {+ return (this.form.tag || "").trim();+ },++ get selectedTagExistsOnBranch() {+ const tag = this.trimmedTag;+ return Boolean(tag) && this.tagSuggestions.includes(tag);+ },+get versionCompatibilityWarning() {const current = this.parseCompatibilityTag(this.currentVersion);const target = this.parseCompatibilityTag(this.form.tag);@@ -79,11 +89,31 @@ const model = {return "";},+ get tagExistenceWarning() {+ const tag = this.trimmedTag;+ if (+ !this.tagExistenceChecked ||+ this.tagsLoading ||+ this.tagsError ||+ !tag ||+ !this.parseSelectorTag(tag) ||+ !this.isSupportedSelectorTag(tag)+ ) {+ return "";+ }+ if (!this.selectedTagExistsOnBranch) {+ return `Version ${tag} does not exist on branch ${this.form.branch || "main"}.`;+ }+ return "";+ },+get canScheduleUpdate() {return (this.isSupported &&!this.isBusy &&+ !this.tagsLoading &&this.isSupportedSelectorTag(this.form.tag) &&+ this.selectedTagExistsOnBranch &&!this.versionCompatibilityWarning);},@@ -101,6 +131,7 @@ const model = {this.restarting = false;this.tagsLoading = false;this.tagDropdownOpen = false;+ this.tagExistenceChecked = false;this.restartStatusText = "";this.restartDetailText = "";this.removeProgressOverlay();@@ -268,6 +299,7 @@ const model = {}this.info = response;this.applyFormState(response.pending || response.defaults || {});+ this.tagExistenceChecked = Boolean((this.form.tag || "").trim());await this.searchTags({ openResults: false });} catch (error) {console.error("Failed to load self-update info:", error);@@ -278,7 +310,11 @@ const model = {},applyFormState(source) {- this.form.branch = source?.branch || "main";+ this.form.branch =+ this.info?.defaults?.branch ||+ this.currentBranch ||+ source?.branch ||+ "main";this.form.tag =typeof source?.tag === "string" ? source.tag : this.currentVersion;this.form.backup_usr =@@ -299,13 +335,20 @@ const model = {async onBranchChanged() {this.openTagDropdown();+ this.tagExistenceChecked = Boolean(this.trimmedTag);await this.searchTags();},onTagInput() {+ this.tagExistenceChecked = false;this.openTagDropdown();},+ async onTagBlur() {+ this.tagExistenceChecked = Boolean(this.trimmedTag);+ await this.searchTags({ openResults: false });+ },+async searchTags({ openResults = true } = {}) {const requestId = ++this._tagRequestId;this.tagsLoading = true;@@ -344,6 +387,7 @@ const model = {selectTag(tag) {this.form.tag = tag;+ this.tagExistenceChecked = true;this.tagDropdownOpen = false;},@@ -400,6 +444,15 @@ const model = {return;}+ if (!this.selectedTagExistsOnBranch) {+ this.tagExistenceChecked = true;+ await this.searchTags({ openResults: false });+ if (!this.selectedTagExistsOnBranch) {+ this.error = `Version ${this.trimmedTag} does not exist on branch ${this.form.branch || "main"}.`;+ return;+ }+ }+this.saving = true;this.error = "";try {