Files
chandra/justfile
T
Claude 80af76fb15
CI / test (push) Canceled after 21m14s
Password dialog rebuilt: a separate polkit agent, one state machine, explicit errors
The first version ran polkit registration, polkit-agent-helper-1, the PAM
conversation and the drawing inside the compositor's frame loop, with
overlapping state in two layers. A helper that quit before asking was taken
for a wrong password and restarted in a loop that wiped the field (typing
seemed dead), a refused registration quietly started a third-party agent,
and the dialog and the Face unlock window each grabbed the keyboard.

Now:
- chandra-polkit-agent (compositor/authagent, /usr/local/lib/chandra) does
  polkit and PAM. Each request runs one state machine (polkit/machine.mbt:
  starting, asking, checking, failed, done). A check that quits or can't
  start is Failed with the reason and waits for Try again; only a wrong
  password starts the next check by itself. It logs each step to stderr
  (the session log), never the typed text.
- The compositor starts it on a socket pair and only draws what it says
  (host/auth.mbt, auth_draw.mbt; line protocol in polkit/wire.mbt). One
  input owner (grab_input): the dialog, else the Face unlock window.
- No silent fallback: if the agent can't run, polkit refuses it, polkit
  doesn't answer in 10 s, or it dies, a notice on screen says why (a crash
  after it ran restarts it, up to 3 times, and says so). The third-party
  agent runs only when the Settings switch is off.
- chandra-ctl auth-demo [password|face|face-ok|die|slow|users] shows the
  real dialog with a pretend check (password "demo"), no root needed;
  chandra-ctl auth-status says whether the agent is registered.
- just install builds and installs the agent (just auth-agent).

Tests: polkit_test (link, machine, view, helper Gone) and auth_test end to
end through handle_input: the agent loop in-process against a mock polkit
on a private dbus-daemon plus a mock helper, and the real agent program
spawned by the compositor (demo, and registered with the mock polkit).
Typing on a real xkb keymap, wrong password, cancel, withdrawal, helper
quitting early or missing, polkit refusing, agent not starting or crashing,
demo modes, Face unlock Apply. 170/170 host and 20/20 polkit tests pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hgkRPrAzXECBUGmNEE
2026-11-26 05:09:49 +00:00

196 lines
9.2 KiB
Makefile

# chandra tasks. `just` lists them.
set shell := ["pixi", "run", "bash", "-euo", "pipefail", "-c"]
export PATH := env_var('HOME') + "/.moon/bin:" + env_var('PATH')
socket := env_var_or_default('XDG_RUNTIME_DIR', '/tmp') + "/wayland-moon-0"
theme := "config/themes/moon-night.json"
exe := "_build/native/debug/build/compositor/bin/bin.exe"
release_exe := "_build/native/release/build/compositor/bin/bin.exe"
tcc := justfile_directory() + "/scripts/tcc/tcc"
default:
@just --list
# Build the vendored tinycc (third_party/tinycc) into _build/tcc, once. Optional: `just build` uses any tcc it can find.
tcc-build:
#!/usr/bin/env bash
set -euo pipefail
[ -x _build/tcc/bin/tcc ] && exit 0
root="$PWD"
rm -rf _build/tcc-src
mkdir -p _build
cp -r third_party/tinycc _build/tcc-src
cd _build/tcc-src
./configure --prefix="$root/_build/tcc" >/dev/null
make -j"$(nproc)" >/dev/null
make install >/dev/null
# Build the panel's wasm modules (application menu, task list, clock, ...) into build/components.
modules:
pixi run modules
# Debug build of the native compositor, compiled and linked with tcc ($TCC, the vendored build if present, or tcc on PATH). Never builds tcc itself.
build:
@{{tcc}} --which >/dev/null
MOON_CC={{tcc}} MOON_STUB_CC={{tcc}} moon build --target native --warn-list -a compositor/bin
# Optimised build with the system C compiler (slower to build, faster to run).
build-release:
moon build --target native --release --warn-list -a compositor/bin
# Chandra's polkit agent (the password dialog's other half; the compositor starts it): docs/auth-dialog.md.
auth-agent:
moon build --target native --release --warn-list -a compositor/authagent
# Show the password dialog in the running session with a pretend check (password "demo"); MODE: password, face, face-ok, die, slow, users.
auth-demo mode="password":
python3 session/chandra-ctl auth-demo {{mode}}
# Run the compositor, built as a wasm component, in a window on your current Wayland session (close the window or Ctrl-C to stop). Connect clients via `just client`.
run: compositor-wasm wasmhost modules
rm -f {{socket}}
build/wasmhost build/compositor.wasm --socket {{socket}} --theme {{theme}} --window
# On an X server (NVIDIA's proprietary driver, docs/x11.md): a window under a window manager, or the whole screen without one.
run-x11: compositor-wasm wasmhost modules
rm -f {{socket}}
build/wasmhost build/compositor.wasm --socket {{socket}} --theme {{theme}} --x11
# Run the native compositor (tcc debug build, with the wasm panel modules) in a window on your current Wayland session.
run-native: build modules
rm -f {{socket}}
{{exe}} --window --socket {{socket}} --theme {{theme}}
# Rebuild the Desktop Pulse plasmoid (wasm component) into compositor/wasm/testdata.
build-pulse:
moon build --target wasm --release
wasm-tools component embed wit _build/wasm/release/build/components/pulse/gen/gen.wasm --world pulse-widget --encoding utf16 -o _build/pulse.embed.wasm
wasm-tools component new _build/pulse.embed.wasm -o compositor/wasm/testdata/pulse.component.wasm
wasm-tools component targets --world pulse-widget wit compositor/wasm/testdata/pulse.component.wasm
# Run the compositor in a window with the Desktop Pulse widget loaded (live system + window integration).
run-pulse: build
rm -f {{socket}}
{{exe}} --window --socket {{socket}} --theme {{theme}} --widget compositor/wasm/testdata/pulse.component.wasm
# One frame of the desktop with Desktop Pulse loaded, to _build/pulse.png.
view-pulse: build
{{exe}} --socket {{socket}}-snap --theme {{theme}} --widget compositor/wasm/testdata/pulse.component.wasm --gfx-out _build/pulse.png
# Run the compositor with no window (clients only; no output).
run-headless: build modules
rm -f {{socket}}
{{exe}} --socket {{socket}} --theme {{theme}}
# Run the wasm compositor on the real display (DRM/KMS + libinput, through the host). Run from a login VT (Ctrl+Alt+F3), not inside another session. Ctrl+Alt+Backspace quits, Ctrl+Alt+F<n> switches VT.
run-drm: compositor-wasm wasmhost modules
rm -f {{socket}}
# Let D-Bus-activated helpers (gcr-prompter's keyring unlock prompt, portals) open windows here.
-dbus-update-activation-environment --systemd WAYLAND_DISPLAY=$(basename {{socket}}) XDG_SESSION_TYPE=wayland XDG_CURRENT_DESKTOP=chandra 2>/dev/null
build/wasmhost build/compositor.wasm --drm --socket {{socket}} --theme {{theme}}
# The same on the native compositor (system-cc release build), for comparison.
run-drm-native: build-release modules
rm -f {{socket}}
-dbus-update-activation-environment --systemd WAYLAND_DISPLAY=$(basename {{socket}}) XDG_SESSION_TYPE=wayland XDG_CURRENT_DESKTOP=chandra 2>/dev/null
{{release_exe}} --drm --socket {{socket}} --theme {{theme}}
# Install everything (login session, panel modules, KDE colors, portal, face unlock); builds as you, then asks for root once. Flags: --link, --native, --pam, --no-face (docs/install.md).
install *flags:
#!/usr/bin/env bash
set -euo pipefail
builds="compositor-wasm wasmhost modules auth-agent"
face=1
for f in {{flags}}; do
case "$f" in
--native) builds="build-release modules auth-agent" ;;
--rust) echo "just install: --rust is gone: the Rust host was removed (2026-11-26); the MoonBit host is the only one" >&2; exit 2 ;;
--no-face) face=0 ;;
--link|--pam|--no-models) ;;
*) echo "just install: unknown flag $f (--link, --native, --pam, --no-face, --no-models)" >&2; exit 2 ;;
esac
done
{{just_executable()}} --justfile "{{justfile()}}" $builds
extra=""
if [ "$face" = 1 ]; then
# Build the PAM module as you, so root only copies it.
cc=$(command -v cc || command -v gcc || command -v clang || true)
mkdir -p build
if [ -n "$cc" ] && "$cc" -O2 -Wall -shared -fPIC -o build/pam_chandra_face.so \
-DCHANDRA_FACE_HELPER='"/usr/local/lib/chandra/chandra-face"' face/pam_chandra_face.c -lpam; then
:
else
echo "warning: skipping face unlock: building its PAM module needs a C compiler and the libpam headers (libpam0g-dev / pam-devel)" >&2
extra="--no-face"
fi
fi
# Face unlock's Python + OpenCV come from a root-owned pixi environment: hand root our pixi.
scripts/as-root python3 "{{justfile_directory()}}/session/install.py" {{flags}} $extra \
--pixi "$(command -v pixi || echo "$HOME/.pixi/bin/pixi")"
# Reload the running session's panel modules from disk (after install or `just modules`), keeping their order and settings. `just reload clock-digital` reloads one. See docs/reloading.md.
reload *name:
python3 session/chandra-ctl reload {{name}}
# Remove everything `just install` installed (face unlock is taken out of every PAM service first). `just uninstall --purge` also deletes the enrolled faces and /etc/chandra/face.conf.
uninstall *flags:
scripts/as-root python3 "{{justfile_directory()}}/session/install.py" --remove {{flags}}
# Face unlock tests (fake camera; add --pam as root with pamtester to test the PAM module too).
test-face *args:
python3 face/test_face.py {{args}}
# Start a Wayland client inside the running compositor (default: foot).
client *cmd="foot":
WAYLAND_DISPLAY={{socket}} {{cmd}}
# Build host + wasm compositor + modules on a sprites.dev sprite (CHANDRA_SPRITE, default chandra-build) and pull the artifacts back.
remote-build *targets:
scripts/remote-build.sh {{targets}}
# Compositor + wasm component + lib tests.
test: modules
XDG_CONFIG_HOME="$(mktemp -d)" CHANDRA_TEST_CONFIG=1 moon test --target native --warn-list -a compositor/renderer compositor/wasm compositor/host
moon test --target wasm --warn-list -a lib/shell lib/panel lib/clock lib/launcher lib/wm lib/taskbar lib/layoutpick lib/modmgr
# Render one composed frame to _build/e2e_frame.png (via the e2e test).
frame: modules
moon test --target native --warn-list -a compositor/host
@echo "wrote _build/e2e_frame.png"
# Everything CI runs.
ci:
scripts/test.sh
# Render one frame of the desktop to _build/desktop.png and open it.
view: build modules
{{exe}} --socket {{socket}}-snap --theme {{theme}} --gfx-out _build/desktop.png
xdg-open _build/desktop.png
# Time the native build (cold / warm / one-file edit), tcc vs system cc, on a temp copy: `just bench 5` or `just bench 3 "tcc cc cc-release"`.
bench runs="3" configs="tcc cc":
scripts/bench-build.sh {{runs}} "{{configs}}"
# Delete build output (compiled compositor, wasm modules, rendered frames) but keep the built tinycc in _build/tcc.
clean:
#!/usr/bin/env bash
set -euo pipefail
rm -rf build
[ -d _build ] && find _build -mindepth 1 -maxdepth 1 ! -name tcc -exec rm -rf {} + || true
echo "cleaned build/ and _build/ (kept _build/tcc; \`just clean-all\` removes that too)"
# Delete all build output, including the built tinycc (the next build recompiles it).
clean-all:
rm -rf _build build
# Build the compositor as a wasm component (build/compositor.wasm): imports only chandra:host/sys.
compositor-wasm:
scripts/build-compositor-wasm.sh
# Build the host that runs the compositor component (build/wasmhost): MoonBit, linking the prebuilt wasmtime C API, so it builds in seconds.
wasmhost:
scripts/build-wasmhost.sh