Face unlock window: live camera preview, Snap, thumbnails, one password on Apply
CI / test (push) Failing after 12m30s

Settings > Session "Add or remove faces…" (and "Remove…" on a face) opens a
compositor-drawn Face unlock window instead of running root steps one by one:

- chandra-face camera runs as the user (no password): it streams a small live
  picture with the face box and a cropped thumbnail per snap; the snaps'
  embeddings stay in that process, nothing is written to disk.
- Click a snap to drop it; mark saved faces Remove/Keep.
- Apply saves the snaps as one face and removes the marked ones in one root
  `chandra-face apply` (JSON on stdin, validated) through run0/pkexec: one
  password prompt.
- New raster host function image-pixels (host-wasm, wasmhost, native) for the
  window's pictures.

Tests: camera session and apply in face/test_face.py; the window end to end
against a fake tool in compositor/host/face_test.mbt. Docs explain why the
change itself still needs root.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hhiJfJNAYqWzQiuKMf
This commit is contained in:
Claude committed 2026-11-26 02:36:29 +00:00
1 parent 0a9787ae36
commit 9f7489cfea
74 files changed
+2617 -89

No files matched your search

+74 -13
View File
@@ -20,6 +20,27 @@ fn fake_face_tool(dir : String) -> String {
#|remove)
#| grep -v "^face $2 " "$S/faces" > "$S/faces.new"; mv "$S/faces.new" "$S/faces"
#| echo "done Removed face $2" ;;
#|camera)
#| # The Face unlock window's camera: a grey 4x3 picture with a face box, a white 2x2
#| # thumbnail per snap, and an apply that changes the faces file.
#| pic() { printf 'frame 4 3 1 0 2 2 36\n'; head -c 36 /dev/zero | tr '\000' '\200'; }
#| echo "info Look at the camera and press Snap"; pic
#| n=0; kept=0
#| while read -r cmd arg; do
#| case "$cmd" in
#| snap) n=$((n+1)); kept=$((kept+1)); printf 'snap %d 2 2 12\n' $n; head -c 12 /dev/zero | tr '\000' '\377'; pic ;;
#| drop) kept=$((kept-1)); pic ;;
#| apply)
#| echo "info Waiting for the password…"
#| for id in $(echo "$arg" | tr ',' ' '); do
#| grep -v "^face $id " "$S/faces" > "$S/faces.new"; mv "$S/faces.new" "$S/faces"
#| done
#| [ $kept -gt 0 ] && printf 'face 2\tFace 2\t2026-11-26\n' >> "$S/faces"
#| echo "$kept $arg" > "$S/applied"
#| echo "done Added Face 2 and removed 1 face"; echo "applied 0"; exit 0 ;;
#| quit) exit 0 ;;
#| esac
#| done ;;
#|pam)
#| if [ "$2" = enable ]; then echo "polkit-1,sudo" > "$S/pam"; else : > "$S/pam"; fi
#| echo "done ok" ;;
@@ -65,7 +86,7 @@ fn face_click(comp : @host.ChandraCompositor, label : String, t : UInt) -> Unit
}
///|
test "Settings > Session: face unlock lists faces, adds one, turns it on, removes one" {
test "Settings > Session: face unlock lists faces and turns it on" {
let dir = "/tmp/chandra-face-test-" + @sys.getpid().to_string()
let tool = fake_face_tool(dir)
let comp = new_comp("face")
@@ -77,12 +98,8 @@ test "Settings > Session: face unlock lists faces, adds one, turns it on, remove
assert_true(texts.contains("Face unlock"))
assert_true(texts.contains("Use my face for passwords"))
assert_true(texts.contains("added 2026-11-20"))
assert_true(texts.contains("Add a face…"))
assert_true(texts.contains("Add or remove faces…"))
assert_false(comp.shell.face.in_use())
// Add a face: the tool's progress shows, then the new face.
face_click(comp, "Add a face…", 10U)
assert_true(face_settle(comp, fn() { face_texts(comp).contains("Face 2") }))
assert_true(face_texts(comp).contains("Added Face 2"))
// The switch: polkit-1 and sudo try the face first.
face_click(comp, "Use my face for passwords", 20U)
assert_true(face_settle(comp, fn() { comp.shell.face.in_use() }))
@@ -90,13 +107,57 @@ test "Settings > Session: face unlock lists faces, adds one, turns it on, remove
if shots != "" {
ignore(@sys.write_file_bytes(shots + "/16-settings-face.png", @renderer.encode_png_compressed(comp.compose_frame())))
}
// Remove takes a second click.
face_click(comp, "Remove", 30U)
assert_true(face_texts(comp).contains("Click again to remove"))
assert_eq(comp.shell.face.faces.length(), 2)
face_click(comp, "Click again to remove", 40U)
assert_true(face_settle(comp, fn() { comp.shell.face.faces.length() == 1 }))
assert_eq(comp.shell.face.faces[0].1, "Face 2")
comp.close()
}
///|
fn face_key(comp : @host.ChandraCompositor, code : UInt, t : UInt) -> Unit {
comp.handle_input(@nested.InputEvent::Key(code, true), t)
comp.handle_input(@nested.InputEvent::Key(code, false), t + 1U)
ignore(comp.compose_frame())
}
///|
test "the Face unlock window: live picture, snaps, a face marked for removal, one Apply" {
let dir = "/tmp/chandra-face-win-" + @sys.getpid().to_string()
let tool = fake_face_tool(dir)
let comp = new_comp("facewin")
comp.shell.set_face_tool(["/bin/sh", tool])
assert_true(comp.shell.open_settings(Session))
assert_true(face_settle(comp, fn() { face_texts(comp).contains("Desk") }))
// "Remove…" on a face opens the window with that face marked; nothing is removed yet.
face_click(comp, "Remove…", 10U)
assert_true(face_settle(comp, fn() { comp.shell.face.window.map(w => w.picture != 0U).unwrap_or(false) }))
let w = comp.shell.face.window.unwrap()
assert_eq(w.remove, ["1"])
assert_eq((w.pic_w, w.pic_h, w.face_box), (4, 3, Some((1, 0, 2, 2))))
assert_eq(w.message, "Look at the camera and press Snap")
// Space snaps (the window has the keyboard), twice; one snap is dropped again.
face_key(comp, 57U, 20U)
assert_true(face_settle(comp, fn() { w.snaps.length() == 1 }))
face_key(comp, 57U, 30U)
assert_true(face_settle(comp, fn() { w.snaps.length() == 2 }))
assert_eq(w.message, "2 pictures: snap more, or press Apply")
comp.shell.face.drop_snap(0)
assert_eq(w.snaps.map(s => s.id), ["2"])
assert_eq(w.message, "1 picture: turn a little and snap again, or press Apply")
let shots = @sys.getenv("CHANDRA_AUTH_SHOTS")
if shots != "" {
ignore(@sys.write_file_bytes(shots + "/17-face-window.png", @renderer.encode_png_compressed(comp.compose_frame())))
}
assert_eq(comp.shell.face.faces.length(), 1)
// Enter applies: one run for the snap and the removal; the window closes, Settings shows it.
face_key(comp, 28U, 40U)
assert_true(face_settle(comp, fn() { comp.shell.face.window is None }))
assert_true(face_settle(comp, fn() { face_texts(comp).contains("Face 2") }))
assert_eq(comp.shell.face.faces.map(f => f.1), ["Face 2"])
assert_eq(comp.shell.face.message, "Added Face 2 and removed 1 face")
assert_eq(@sys.read_file_bytes(dir + "/applied") |> @utf8.decode_lossy, "1 1\n")
// Esc cancels without changing anything.
face_click(comp, "Add or remove faces…", 50U)
assert_true(face_settle(comp, fn() { comp.shell.face.window is Some(_) }))
face_key(comp, 1U, 60U)
assert_true(comp.shell.face.window is None)
comp.close()
}