Skip to content

Harden cfgutil device actions + add end-to-end architecture docs#124

Merged
AdamXweb merged 2 commits into
mainfrom
feat/eager-shannon-b87c90
Jul 7, 2026
Merged

Harden cfgutil device actions + add end-to-end architecture docs#124
AdamXweb merged 2 commits into
mainfrom
feat/eager-shannon-b87c90

Conversation

@adamXbot

@adamXbot adamXbot commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

Two threads from a source-level audit of the macOS/Tauri cfgutil "back up then delete apps off the phone" flow:

  1. Fix — device-action safety (fix(device-actions)): two defects that were invisible to CI because tests used synthetic bare-hex ECIDs and never exercised gate ordering.

    • ECID normalization. cfgutil keys its JSON output by 0x-prefixed ECIDs (0x9118908BB6027), but isValidEcid rejected the x. On a real device, recordBackup threw → no backup stamp → checkUninstallGate always returned backup_missing, silently breaking the freshness gate and the audit trail. Replaced with normalizeEcid (strip 0x, upper-case, validate hex body); stamps key off the canonical form so any spelling round-trips. The backup route now 400s on a malformed ECID instead of 500-ing.
    • Gate ordering. The wizard ran the destructive cfgutil call before the server gate, so the server could only refuse to log, never to act. runBulkUninstall now pre-flights GET /api/device-actions/uninstall before the first removal and fails closed; recording POSTs check res.ok and surface failures instead of swallowing them.
  2. Docs — end-to-end architecture dossier (docs): Mermaid diagrams of every process (system map, add/track, cfgutil import, backup+delete, background jobs, wayback, gate chain) with weak points marked inline and gathered into an improvement backlog keyed to each diagram. Renders on GitHub, stays diffable — no duplicate raster images to drift. Plus a self-contained good-first-issue spec (backlog §3·5) sized for an external agent.

What's verified

  • pnpm test — 438 pass / 0 fail (4 new tests pin the 0x round-trip + pre-flight)
  • pnpm typecheck, pnpm lint, pnpm lint:i18n — all clean (en/zh parity at 4759 keys)
  • All Mermaid blocks parse under Mermaid 11 (GitHub's renderer)

Not addressed here (tracked in the backlog)

The two highest-severity findings need a Mac with Apple Configurator to verify and are out of scope for this PR:

  • §3·1cfgutil backup --backup-output appears in no public cfgutil docs; may fail on real hardware. Check: cfgutil help backup.
  • §3·2 — backup success is exit-code only; nothing verifies files landed on disk.

See docs/ARCHITECTURE.md §7 for the full backlog and suggested order.

🤖 Generated with Claude Code

adamXbot and others added 2 commits July 7, 2026 22:12
Two safety defects in the cfgutil backup/delete flow, both invisible to CI
because tests used synthetic bare-hex ECIDs and never exercised the gate
ordering.

ECID normalization: cfgutil keys its JSON output by 0x-prefixed ECIDs
(e.g. 0x9118908BB6027), but isValidEcid rejected the `x`. With a real
device, recordBackup threw, the backup stamp was never written, and
checkUninstallGate always returned backup_missing — silently breaking the
freshness gate and the audit trail. Replace isValidEcid with normalizeEcid
(strip 0x, upper-case, validate hex body); key stamps off the canonical
form so any spelling round-trips. The backup route now 400s on a malformed
ECID instead of throwing a 500.

Gate ordering: the wizard ran the destructive cfgutil call before the
server gate, so the server could only refuse to *log*, never to *act*.
runBulkUninstall now pre-flights GET /api/device-actions/uninstall before
the first removal and fails closed on denial or an unreachable service.
Backup/uninstall recording POSTs check res.ok and surface failures as
visible warnings instead of vanishing into the console.

Tests pin the 0x round-trip and the pre-flight behaviour; correct two
route/comment claims that overstated what the server gate can prevent
(the native Touch ID prompt is the real control).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Document every process the app runs — system map, add/track, cfgutil
device import, backup+delete, background jobs, wayback, and the feature-
flag gate chain — as Mermaid diagrams that render on GitHub and stay
diffable. Weak points are marked inline and collected into an improvement
backlog keyed to each diagram, so findings and their fix status live in
one place instead of drifting apart.

Add docs/specs/3-5-server-stamp-backup-variant.md, a self-contained
good-first-issue spec (drive the delete-confirm modal's backup variant
from the server stamp) sized for an external agent — TypeScript-only,
self-verifiable in the node:test suite, no hardware.

Wire both into the AGENTS.md architecture section and the README docs list.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@AdamXweb AdamXweb merged commit 177b25a into main Jul 7, 2026
13 checks passed
@AdamXweb AdamXweb deleted the feat/eager-shannon-b87c90 branch July 7, 2026 12:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants