# Testing Manual checks for coreapp-dev. The scripts call `sudo`, `pacman`/`yay`, `systemctl` and `virsh`, so they change the real system even when `HOME` is a temporary folder. Run these on a machine or VM you don't mind changing. ## Static checks ```bash cd ~/Projects/coreapp-dev for f in install.sh update.sh uninstall.sh bin/coreapp-vm bin/coreapp libvirt/network-hook.sh; do bash -n "$f"; done shellcheck -x install.sh update.sh uninstall.sh bin/coreapp-vm bin/coreapp libvirt/network-hook.sh python3 -m py_compile core/coreapps && rm -rf core/__pycache__ ``` ## install.sh 1. If the system was last upgraded more than a day ago, `bash install.sh` says so and runs `update` first (pacman's lists would otherwise name versions the mirrors have deleted: 404s). Under `update` itself (`COREDESKTOP_ALLOW_PACMAN=1`) it doesn't. 2. `bash install.sh`. It should: - install whichever of `libvirt qemu-base virt-install dnsmasq edk2-ovmf dmidecode` are missing - enable and start `libvirtd.service` - add you to the `libvirt` group - define the `default` network if it's missing, set it to start at boot, and start it - print "coreapp-dev installed.", and the log-out note if your group membership is new 3. Log out and back in, then check: ```bash id -nG | grep -w libvirt systemctl is-active libvirtd virsh -c qemu:///system net-info default # Active: yes, Autostart: yes ls ~/.local/share/coreapp-dev/images ``` 4. Run `bash install.sh` again. It must succeed, print "already enabled" and change nothing. 5. Error paths: - With CoreDesktop missing: `HOME=$(mktemp -d) bash install.sh` should say it needs CoreDesktop and exit 1. ## update.sh 1. `bash update.sh` with everything already installed: no package installs, no prompts apart from sudo, exits 0. 2. Stop the network (`virsh -c qemu:///system net-destroy default`) and run `bash update.sh`: it should start the network again. ## Through CoreDesktop's sibling command Once the repo is in git: ```bash export HOME="$(mktemp -d)" mkdir -p "$HOME/.local/share" ln -s ~/.local/share/coredesktop "$HOME/.local/share/coredesktop" bash "$HOME/.local/share/coredesktop/sibling" add ~/Projects/coreapp-dev bash "$HOME/.local/share/coredesktop/sibling" update bash "$HOME/.local/share/coredesktop/sibling" add ~/Projects/coreapp-dev # re-run is safe ``` ## The coreapp network After `bash update.sh`: ```bash virsh -c qemu:///system net-info coreapp # Active: yes, Autostart: yes sudo ls -l /etc/libvirt/hooks/network.d/coreapp-dev sudo nft list table ip coreapp-dev # masquerade for 10.123.0.0/24 sudo iptables -S | grep coreapp-dev # 3 INPUT and 2 FORWARD accepts grep virbr-coreapp /etc/ufw/user.rules # DHCP, DNS, route rules ``` - Run `bash update.sh` again: no changes, and no ufw rules added twice. (This also checks that the `grep` patterns match how ufw writes its rules; if one doesn't, `update` asks for sudo every time.) - `virsh -c qemu:///system net-destroy coreapp`: the nft table and iptables rules are gone. `net-start coreapp`: they're back. - The hook on its own, in a throwaway namespace (no host changes): ```bash docker run --rm --cap-add NET_ADMIN -v "$PWD/libvirt/network-hook.sh:/hook:ro" \ --entrypoint bash corerelay:local -c \ '/hook coreapp started; /hook coreapp started; iptables -S | grep -c coreapp-dev; /hook coreapp stopped; iptables -S | grep -c coreapp-dev' ``` prints 5, then 0 (the `sysctl` error is expected inside a container). - Moving from the old network (192.168.123.0/24): with a VM running, `bash update.sh` redefines `coreapp` but doesn't restart it, and says how. With no VM running, it restarts it: `net-dumpxml coreapp` shows `10.123.0.1` and the `dhcp-host=52:54:00:c0:4e:10,...` option, and `sudo iptables -S | grep -c 192.168.123` prints 0. - The reservation works: `virsh -c qemu:///system net-dhcp-leases coreapp` lists `coreserver` at `10.123.0.10`. (dnsmasq still logs "cannot read .../coreapp.hostsfile": that file is libvirt's, root-only and now empty.) - From the workstation, the Core's own services answer directly (its containers are on 192.168.0.0/16, so this fails if the VM network is in 192.168.x.x): `curl -sk -o /dev/null -w '%{http_code}\n' --resolve nextcloud.:443:10.123.0.10 https://nextcloud./` prints 302. ## CoreServer VM 1. Put Federated's dashboard key in `~/.config/coreapp-dev/authorized_keys`. 2. `coreapp-vm create`. Without the image, it downloads it first (1.3 GB; interrupt it and run again: it resumes) and checks its SHA-256. It says how many root keys it's installing (2: coreapp-dev's and the dashboard's) and prints `IP: 10.123.0.10` within about two minutes. 3. `coreapp-vm list`: `coreserver` is running at 10.123.0.10. 4. `coreapp-vm ssh` logs in (after cloud-init, a minute later). Inside the VM: - `cat /root/.ssh/authorized_keys` has both keys - `df -h /federated` shows about 50 GB (the disk is 60 GB; `/` stays 10 GB) - `ping -c3 1.1.1.1` and `getent hosts federated.computer` (internet and DNS) - `systemctl is-enabled systemd-resolved` says `masked` 5. `coreapp-vm ssh hostname` prints `coreserver`; `coreapp-vm ip nope` says there's no such VM. 6. `coreapp-vm create` again refuses with "already exists". 7. To see the screen: `virt-viewer -c qemu:///system coreserver`. 8. Once the Core is installed: `virsh -c qemu:///system reboot coreserver`. Within a few minutes all its containers are up again, including `pdns` (`dig +short A @10.123.0.10` answers). 9. `coreapp-vm stop`, then `coreapp-vm start`. 10. `coreapp-vm delete`: asks for the name; anything else keeps the VM. With the name, the VM and `/var/lib/libvirt/images/coreserver.qcow2` are gone, the image in `~/.local/share/coreapp-dev/images/` stays. ## Uninstall On a machine you can rebuild (it removes the network every VM uses): 1. `bash uninstall.sh` with a VM on the `coreapp` network, answering no: it stops, and nothing is removed. 2. Again, answering yes: the VMs and their disks are gone, `virsh -c qemu:///system net-list --all` has no `coreapp`, `/etc/libvirt/hooks/network.d/coreapp-dev` is gone, `sudo iptables -S | grep -c coreapp-dev` prints 0, `grep -c virbr-coreapp /etc/ufw/user.rules` prints 0 (virbr0's rules stay), and `coreapp-vm` isn't on `PATH`. 3. Answering no to the data questions keeps `~/.local/share/coreapp-dev` and `~/.config/coreapp-dev`. 4. `bash install.sh` puts everything back. ## The skill 1. After `bash update.sh`, `~/.claude/skills/coreapp` is a link to `skills/coreapp` in the clone; running it again changes nothing. With a real folder already at that path, it says so and leaves it. 2. `uninstall.sh` removes the link (only if it points at a `skills/coreapp`). 3. Rehearsal: give an agent a small app with the usual problems (listens on 127.0.0.1, keeps its files next to the code, a hard-coded secret) and the task "make it run on our Core as a Coreapp and test it". It should read the skill, write `coreapp.toml` and a Dockerfile, move state to `/data`, use `APP_SECRET`, deploy, check, and report what it couldn't test. ## The installer (coreapps), off the Core `coreapps manifest ` checks a `coreapp.toml` without a Core. With a folder holding a valid one (`coreapp new x` makes one), each of these changes is refused with a message saying what's allowed, and exit 1: - `port = "8080"` (a string), `port = 0` - `image = "coreapp/x"` (no registry, which would mean Docker Hub) - `title = "A $(reboot)"`, a `description` with `"` or `` ` `` - `name = "x-"`, `name = "X"`, `name = "mail"` (one of the Core's hostnames) - an unknown setting (`extra = 1`), `needs = ["redis"]` - a missing `version` `needs = ["sso", "postgres"]` is accepted and printed in setup order (`needs=postgres sso`). `coreapps plan ` off the Core (not root) says to run it as root on the Core. ## Apps (coreapp) Against a Core in the VM (`coreapp-vm list` shows it running). These install test apps on that Core. None may be registered with Federated's monitoring: the generated `/federated/services//service` has no `MONITOR` line. The Core's own scripts trace secrets, so their output goes to `/federated/logs/coreapps/-.log` on the Core (folder mode 700, files 600), never to the terminal unless a step fails. 1. `cd $(mktemp -d) && coreapp new hello`: `./hello` has `coreapp.toml`, `Dockerfile`, `.dockerignore`, `icon.png`, `www/`, `README.md` and `.gitea/workflows/publish.yml`, and nothing else, with no placeholder left (`grep -r '{{[A-Z]' hello` prints nothing; the workflow's `${{ ... }}` are Gitea's). `coreapp new hello` again refuses; so does `coreapp new x-`. 2. `cd hello && coreapp deploy`: updates `/opt/coreapps` on the Core, builds, copies the image, prints `Installing hello at 192.168.5.x` (the first free address there) and `Installed: https://hello./`. On the Core, `/federated/services/hello/` has `service`, `docker-compose.yml.in`, `env.in`, `install`, `uninstall`, `icon.png`, `coreapp.toml` and `.coreapp` (`needs=`); `/federated/apps/hello/.env` is root's, mode 600, with `IMAGE_VERSION` equal to `version` and a random `APP_SECRET`. Superpanel's catalog (`/federated/apps/superpanel/data/catalog.json`) lists `hello`. 3. `coreapp check`: `OK: HTTP 200, valid certificate.` (the first certificate can take a minute). 4. Change `www/index.html`, `coreapp deploy`: "Updating hello to 0.1.0", the container is recreated, the page shows the change, `.env` is unchanged. `coreapp deploy` again: "The Core already has this image.", and the container is the same (`docker inspect -f '{{.Created}}'`); `coreapp deploy --recreate`: a new container, same data. 5. Raise `version` to 0.2.0, `coreapp deploy`: "Updated"; the container runs `:0.2.0`; `docker image ls localhost/coreapp/hello` on the Core lists only 0.2.0. 6. `coreapp status` (address and port), `coreapp logs`, `coreapp shell` (exit with `exit`), `coreapp shell 'id; echo $APP_URL'` (prints both, no terminal needed, also when piped), `coreapp list` (all apps installed by coreapps). 7. `coreapp remove`, answering y: on the Core, `/federated/apps/hello`, `/federated/services/hello`, the container and the image are gone, and the catalog no longer lists `hello`. 8. Refused, with nothing changed on the Core: - `name = "nextcloud"` (one of Federated's apps) or `name = "mail"` - `image = "localhost/coreapp/nope"` with no such image on the Core (change `image`, and skip coreapp's build by running `coreapp-vm ssh /opt/coreapps/coreapps install ` on a copy) - with the app installed with `needs = ["postgres"]`, deploying with `needs = []` ("drops needs postgres") 9. `/data` is writable by the app: with an image that runs as `nobody` (the `--postgres`/`--sso` examples), `coreapp shell` then `touch /data/x` works; on the Core, `/federated/apps//data` belongs to uid 65534. 10. On a Core whose tier isn't enterprise, deploying a new app asks before it's recorded as an add-on; answering no deploys nothing. ### With a database 1. `coreapp new --postgres guest-book`: has `app.py`, no `www/`; `coreapp.toml` has `needs = ["postgres"]` and `health = "/health"`; the README has a Database section. 2. `coreapp deploy`, `coreapp check`. Loading the page several times (`curl -s https://guest-book./ | grep visits`) counts up. On the Core, `docker exec postgresql psql -U postgres -l` lists `coreapp_guest_book`, owned by `coreapp_guest_book`; `.env` has `DB_*`. 3. Change `app.py`, `coreapp deploy`: the change shows, the count continues. 4. `virsh -c qemu:///system reboot coreserver`: once the Core is up, the app answers and the count continues (its log may show "Waiting for the database" first). 5. `coreapp remove`: the `coreapp_guest_book` database and user are gone too. Adding a need later: install `coreapp new notes` (no needs), then set `needs = ["postgres"]` and deploy: "Updating", `.env` gains `DB_*` (the other values unchanged), the database `coreapp_notes` exists, the container has the `DB_*` variables, `.coreapp` says `needs=postgres`. ### With sign-in 1. `coreapp new --sso sso-demo`: has `app.py` and `oidc.py`, no `www/`; `needs = ["sso"]`; the README has a Sign-in section. 2. `coreapp deploy`, `coreapp check`. On the Core, `idproviders.yml` has one `### coreapp-sso-demo begin` block; Authelia is healthy; `docker exec authelia authelia validate-config` is OK; no `*.bak` is left; `/federated/apps/sso-demo/docker-compose.yml` maps `authelia.` to traefik's address (`extra_hosts`). 3. `https://sso-demo./login` redirects to `https://authelia./api/oidc/authorization?...client_id=coreapp-sso-demo...code_challenge_method=S256`. 4. In a browser, sign in with a Core account: the page says "Signed in as ..." with the account's email and groups. "Sign out" goes back to the sign-in link. `/federated/apps/sso-demo/.sso-demo.oidc-client.yml` (mode 600) holds the same block. 5. The copy restores the client: delete the block from `idproviders.yml` (keep a backup), run `/federated/bin/reconcile-authelia-sso`: it says "Restoring sso-demo's Authelia OIDC client" and the block is back. 6. Redeploy: still one client block, and Authelia isn't restarted (`docker inspect -f '{{.State.StartedAt}}' authelia` unchanged). `coreapp remove`: no block and no copy, and running `/federated/bin/reconcile-authelia-sso` doesn't bring it back; Authelia healthy, other clients (Nextcloud) still work. Deploy again: one block. ### With both 1. `coreapp new --postgres --sso team-visits`: `needs = ["postgres", "sso"]`; `app.py` imports `oidc` and `psycopg`. 2. `coreapp deploy`, `coreapp check`. On the Core, `service` has `DEPENDS="postgresql authelia"`, `.env` has `DB_*` and `OIDC_*`. In a browser, sign in: the page shows your name and "Your visits", which counts up on reload. Another account gets its own count; "people who have visited" counts both. 3. `coreapp remove`: the database, user and Authelia client are gone. ### Apps deployed before coreapp.toml An app deployed by an older coreapp (its own `service`, `install`, ... and an empty `.coreapp` marker on the Core) moves over by replacing those files with a `coreapp.toml` with the same name, image and needs. `coreapp deploy` then updates it: same address, `.env` and data unchanged, no needs set up again (they're read from its `DEPENDS`), Authelia not restarted; `.coreapp` then says which needs it has. Apps with an address outside 192.168.5.0/24 get a new one on their next update (the container moves; the app keeps working), and apps with sign-in get their client copy. ## Publishing (coreapp publish) With a throwaway registry on the workstation (`docker run -d --rm --name coreapp-test-registry -p 127.0.0.1:5000:5000 registry:2`; `docker stop coreapp-test-registry` afterwards removes it) and an app in a git repository with an `https://` origin: 1. With `image = "localhost/coreapp/..."`: refused, suggesting an image from the remote (`https://host/Owner/Repo.git` gives `host/owner/repo`). 2. With `image = "localhost:5000/test/"` and an uncommitted change: refused. 3. Committed: builds, pushes, prints the digest, tags the commit `v` (annotated) and prints the push commands. The registry lists the tag (`curl -s http://127.0.0.1:5000/v2/test//tags/list`); the image has the `org.opencontainers.image.*` labels (version, revision, title, source). 4. Again: "already published", nothing pushed. 5. A new commit without raising `version`: "The tag v already exists on another commit". 6. Raise `version`, commit, publish: the new tag is pushed alongside. 7. Registry stopped: "Couldn't check ..." with the error, exit 1. Against a real Gitea (needs the user's account): `docker login ` with a token that has `write:package`, `image = "//"`, `coreapp publish`: the package shows under the owner's Packages, linked to the repository. A private owner's packages need a login to pull. The workflow (`.gitea/workflows/publish.yml`), on a repository with an Actions runner that can use Docker and the secrets `REGISTRY_USER` and `REGISTRY_TOKEN`: pushing tag `v` publishes `image:version`; a tag that doesn't match `version`, a `localhost/` image, or a version already published fails the job with a message.