File size: 5,396 Bytes
18d3630
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""release.py must stamp bootstrap-installer versions with the release semver.

Tauri CFBundleShortVersionString is read from
apps/bootstrap-installer/src-tauri/tauri.conf.json (and the sibling
package.json). Those files were hardcoded 0.0.1 and omitted from
update_version_files / the --publish --bump git add list, so Hermes-Setup.dmg
always shipped 0.0.1. Same class as the desktop stamp (#68783 / PR #68796).
"""

from __future__ import annotations

import importlib.util
import json
from pathlib import Path

SCRIPT = Path(__file__).resolve().parents[2] / "scripts" / "release.py"


def _load():
    spec = importlib.util.spec_from_file_location(
        "release_bootstrap_installer_version", SCRIPT
    )
    mod = importlib.util.module_from_spec(spec)
    spec.loader.exec_module(mod)
    return mod


release = _load()


def _json_version(path: Path) -> str:
    return json.loads(path.read_text(encoding="utf-8"))["version"]


def _patch_repo(tmp_path, monkeypatch, *, with_installer: bool = True):
    repo = tmp_path
    init_py = repo / "hermes_cli" / "__init__.py"
    init_py.parent.mkdir(parents=True)
    init_py.write_text(
        '__version__ = "0.0.1"\n__release_date__ = "2026.1.1"\n',
        encoding="utf-8",
    )
    pyproject = repo / "pyproject.toml"
    pyproject.write_text('version = "0.0.1"\n', encoding="utf-8")

    desktop_pkg = repo / "apps" / "desktop" / "package.json"
    desktop_pkg.parent.mkdir(parents=True)
    desktop_pkg.write_text('{"version":"0.0.1"}\n', encoding="utf-8")

    installer_pkg = repo / "apps" / "bootstrap-installer" / "package.json"
    tauri_conf = (
        repo / "apps" / "bootstrap-installer" / "src-tauri" / "tauri.conf.json"
    )
    cargo_toml = repo / "apps" / "bootstrap-installer" / "src-tauri" / "Cargo.toml"
    if with_installer:
        tauri_conf.parent.mkdir(parents=True)
        installer_pkg.write_text(
            '{"name":"x","version":"0.0.1"}\n', encoding="utf-8"
        )
        tauri_conf.write_text(
            '{"productName":"Hermes","version":"0.0.1"}\n', encoding="utf-8"
        )
        cargo_toml.write_text('[package]\nversion = "0.0.1"\n', encoding="utf-8")

    monkeypatch.setattr(release, "REPO_ROOT", repo)
    monkeypatch.setattr(release, "VERSION_FILE", init_py)
    monkeypatch.setattr(release, "PYPROJECT_FILE", pyproject)
    return {
        "repo": repo,
        "init_py": init_py,
        "pyproject": pyproject,
        "desktop_pkg": desktop_pkg,
        "installer_pkg": installer_pkg,
        "tauri_conf": tauri_conf,
        "cargo_toml": cargo_toml,
    }


def test_update_version_files_stamps_bootstrap_installer(tmp_path, monkeypatch):
    paths = _patch_repo(tmp_path, monkeypatch)

    release.update_version_files("0.21.1", "2026.9.10")

    assert _json_version(paths["installer_pkg"]) == "0.21.1"
    assert _json_version(paths["tauri_conf"]) == "0.21.1"
    assert 'version = "0.21.1"' in paths["cargo_toml"].read_text(encoding="utf-8")

    # CONTROL: existing desktop / Python stamps still happen.
    assert _json_version(paths["desktop_pkg"]) == "0.21.1"
    assert 'version = "0.21.1"' in paths["pyproject"].read_text(encoding="utf-8")
    init_text = paths["init_py"].read_text(encoding="utf-8")
    assert '__version__ = "0.21.1"' in init_text
    assert '__release_date__ = "2026.9.10"' in init_text


def test_update_version_files_skips_missing_installer_dir(tmp_path, monkeypatch):
    paths = _patch_repo(tmp_path, monkeypatch, with_installer=False)

    release.update_version_files("0.21.1", "2026.9.10")

    assert not paths["installer_pkg"].exists()
    assert not paths["tauri_conf"].exists()
    assert _json_version(paths["desktop_pkg"]) == "0.21.1"
    assert 'version = "0.21.1"' in paths["pyproject"].read_text(encoding="utf-8")
    assert '__version__ = "0.21.1"' in paths["init_py"].read_text(encoding="utf-8")


def test_update_version_files_does_not_invent_version_keys(tmp_path, monkeypatch):
    paths = _patch_repo(tmp_path, monkeypatch)
    original = '{"name":"x","productName":"Hermes"}\n'
    paths["installer_pkg"].write_text(original, encoding="utf-8")
    paths["tauri_conf"].write_text(original, encoding="utf-8")

    release.update_version_files("0.21.1", "2026.9.10")

    assert paths["installer_pkg"].read_text(encoding="utf-8") == original
    assert paths["tauri_conf"].read_text(encoding="utf-8") == original
    assert _json_version(paths["desktop_pkg"]) == "0.21.1"


def test_version_files_to_stage_includes_installer_when_present(tmp_path, monkeypatch):
    paths = _patch_repo(tmp_path, monkeypatch)

    staged = release.version_files_to_stage()

    assert str(paths["init_py"]) in staged
    assert str(paths["pyproject"]) in staged
    assert str(paths["desktop_pkg"]) in staged
    assert str(paths["installer_pkg"]) in staged
    assert str(paths["tauri_conf"]) in staged
    assert str(paths["cargo_toml"]) in staged


def test_version_files_to_stage_omits_missing_installer(tmp_path, monkeypatch):
    paths = _patch_repo(tmp_path, monkeypatch, with_installer=False)

    staged = release.version_files_to_stage()

    assert str(paths["installer_pkg"]) not in staged
    assert str(paths["tauri_conf"]) not in staged
    assert str(paths["cargo_toml"]) not in staged
    assert str(paths["desktop_pkg"]) in staged
    assert str(paths["init_py"]) in staged
    assert str(paths["pyproject"]) in staged