. "$BST_LIB"
# The deb / run-postinsts first-boot deferral path. brintos-postinst-canary ships a
# pkg_postinst_ontarget that do_rootfs must never execute (there is no wasm32
# qemu-user) and that run-postinsts -> `dpkg --configure -a` must execute on first
# browser boot. Rootfs-time behaviour is asserted in the build log, not here; these
# cases assert what is observable on the target after that first boot.
#
# Numbered ahead of 80-dpkg.test deliberately: the runner globs tests/*.test in
# sorted order, and that suite's install/remove/purge lifecycle rewrites the same
# status DB no-unpacked reads.
require dpkg run-postinsts/dpkg

stamp=/var/lib/brintos-postinst-canary.stamp

if ! dpkg -l brintos-postinst-canary >/dev/null 2>&1; then
  bst_skip run-postinsts/canary "brintos-postinst-canary not installed on this image"
else
  # The deferred scriptlet ran on the target and its exec produced output. A
  # non-empty stamp is the assertion rather than its text: uname's exact wording
  # is the runtime's to choose, but only a wasm32 binary that really executed can
  # have written anything at all.
  check run-postinsts/stamp test -s "$stamp"

  # `dpkg --configure -a` went all the way through: no package is left half-
  # configured. grep -q exits 1 when it finds no match, which is the pass here.
  check_rc run-postinsts/no-unpacked 1 grep -q "^Status:.*unpacked" /var/lib/dpkg/status

  # The canary itself reached the configured state, not just the others.
  check_out run-postinsts/canary-installed "install ok installed" \
      sh -c "dpkg -s brintos-postinst-canary 2>&1"
fi
