diff --git a/autobot-slm-backend/ansible/roles/frontend/tasks/main.yml b/autobot-slm-backend/ansible/roles/frontend/tasks/main.yml index 5ea66044a0..2ee14fcc30 100644 --- a/autobot-slm-backend/ansible/roles/frontend/tasks/main.yml +++ b/autobot-slm-backend/ansible/roles/frontend/tasks/main.yml @@ -206,7 +206,7 @@ # node_modules/@autobot/* unlinked (or dangling at an old libs revision) so the # install below does NOT recreate the file: symlinks — vite then externalises # @autobot/ui to a bare specifier and the app white-pages at runtime. Remove the -# @autobot scope first so `npm install` re-creates every file: workspace symlink +# @autobot scope first so the install re-creates every file: workspace symlink # against the freshly-synced libs/ + autobot-plugins/ trees. - name: "Frontend | Remove stale @autobot workspace symlinks so npm relinks file: deps (#12112)" ansible.builtin.file: @@ -217,9 +217,12 @@ when: package_json_path.stat.exists tags: ['frontend', 'npm'] +# #20517: npm ci, the same install the updater runs: `npm install` rewrote the deployed +# package-lock.json, which the Full-Tree Drift Check then reported as drift. esbuild is +# declared in package.json and pinned in the lockfile, so this installs it too. - name: "Frontend | Install npm dependencies" ansible.builtin.command: - cmd: npm install --legacy-peer-deps + cmd: npm ci --ignore-scripts chdir: "{{ frontend_install_dir }}/autobot-frontend" become: true become_user: "{{ frontend_user }}" @@ -230,16 +233,6 @@ changed_when: _npm_install.rc == 0 tags: ['frontend', 'npm'] -- name: "Frontend | Install esbuild (required by vite/rolldown)" - ansible.builtin.command: - cmd: npm install esbuild --legacy-peer-deps - chdir: "{{ frontend_install_dir }}/autobot-frontend" - become: true - become_user: "{{ frontend_user }}" - when: package_json_path.stat.exists - changed_when: true - tags: ['frontend', 'npm'] - # #10084: Vite bakes VITE_* into the bundle at BUILD time from .env* files in # the project root (vite.config.js → loadEnv(mode, cwd)). The /etc/autobot copy # above is not on that path, so without this the bundle ships with NO VITE_* diff --git a/repo_tests/frontend_role_keeps_the_lockfile_20517_test.py b/repo_tests/frontend_role_keeps_the_lockfile_20517_test.py new file mode 100644 index 0000000000..da500df630 --- /dev/null +++ b/repo_tests/frontend_role_keeps_the_lockfile_20517_test.py @@ -0,0 +1,44 @@ +# Copyright 2025-2026 mrveiss +# SPDX-License-Identifier: Apache-2.0 +"""#20517: installing the frontend must not rewrite its lockfile, which then reads as drift.""" + +from __future__ import annotations + +import json +import re + +from repo_tests._paths import repo_root + +_ANSIBLE = "autobot-slm-backend/ansible" +_INSTALL = re.compile(r"cmd:\s*(npm (?:install|i|ci)\b.*)") + + +def _frontend_installs(path: str) -> list[str]: + """Every npm install command in the file that runs in the autobot-frontend directory.""" + lines = (repo_root() / path).read_text(encoding="utf-8").splitlines() + return [ + match.group(1).strip() + for number, line in enumerate(lines) + if (match := _INSTALL.search(line)) and lines[number + 1].rstrip().endswith('/autobot-frontend"') + ] + + +def test_the_role_installs_the_way_the_updater_does() -> None: + role = _frontend_installs(f"{_ANSIBLE}/roles/frontend/tasks/main.yml") + updater = _frontend_installs(f"{_ANSIBLE}/playbooks/update-all-nodes.yml") + assert role == ["npm ci --ignore-scripts"] + assert updater == role # control: the matcher does read the updater's install + + +def test_the_matcher_sees_the_command_that_rewrote_the_lockfile() -> None: + assert _INSTALL.search(" cmd: npm install --legacy-peer-deps") + assert _INSTALL.search(" cmd: npm install esbuild --legacy-peer-deps") + + +def test_esbuild_still_arrives_from_the_lockfile() -> None: + """The role's separate esbuild install went away because npm ci already brings it.""" + frontend = repo_root() / "autobot-frontend" + declared = json.loads((frontend / "package.json").read_text(encoding="utf-8")) + assert "esbuild" in {**declared.get("dependencies", {}), **declared.get("devDependencies", {})} + lock = json.loads((frontend / "package-lock.json").read_text(encoding="utf-8")) + assert "node_modules/esbuild" in lock["packages"]