Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions autobot-slm-backend/ansible/roles/frontend/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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 }}"
Expand All @@ -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_*
Expand Down
44 changes: 44 additions & 0 deletions repo_tests/frontend_role_keeps_the_lockfile_20517_test.py
Original file line number Diff line number Diff line change
@@ -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"]