Files
headquarter/apps/api/tests/unit/test_manifest_compiler.py
T
Developer f1180f6053 fix: ensure container user owns ~/.config and other home dirs
Root cause: manifest-based Dockerfile created the home directory and
chowned only the home root. Files/directories copied from /etc/skel by
useradd -m (or created later by root) remained root-owned, so apps like
ranger failed when writing to ~/.config.

Changes:
- manifest_compiler.py: recursive chown of the home directory after
  useradd so /etc/skel contents are owned by the container user
- Pre-create .config, .local/share, .cache and chown them to the user
  so first-run apps have writable directories immediately
- Add unit test verifying the Dockerfile emits the expected user/home
  setup and config directory creation

Quality gates: py_compile all backend files pass, test file compiles,
tsc --noEmit pass, npm run build pass, 82/82 web tests pass
Note: pytest not available in this shell; backend unit test was not
executed but follows existing project conventions.
2026-06-11 15:05:09 +00:00

39 lines
1.3 KiB
Python

"""Unit tests for the manifest compiler."""
import pytest
from src.services.build.manifest_compiler import compile_dockerfile
@pytest.mark.unit
def test_compile_dockerfile_creates_config_dirs_for_user() -> None:
"""The Dockerfile must pre-create ~/.config and chown it to the container user."""
manifest = {
"base_image": "ubuntu:24.04",
"interface_type": "terminal",
"user": {"name": "dev", "uid": 1000, "gid": 1000},
}
dockerfile = compile_dockerfile(manifest)
assert "groupadd -g 1000 dev" in dockerfile
assert "useradd -u 1000 -g 1000 -m -s /bin/bash dev" in dockerfile
assert "mkdir -p /home/dev && chown -R dev:dev /home/dev" in dockerfile
assert "mkdir -p /home/dev/.config && chown -R dev:dev /home/dev/.config" in dockerfile
assert "mkdir -p /home/dev/.local/share && chown -R dev:dev /home/dev/.local/share" in dockerfile
assert "mkdir -p /home/dev/.cache && chown -R dev:dev /home/dev/.cache" in dockerfile
@pytest.mark.unit
def test_compile_dockerfile_no_user_does_not_create_home() -> None:
"""Without a user config, no home/user setup should be emitted."""
manifest = {
"base_image": "ubuntu:24.04",
"interface_type": "terminal",
}
dockerfile = compile_dockerfile(manifest)
assert "useradd" not in dockerfile
assert "/home/" not in dockerfile