Dozzle full log download
************************

Always examine the logs from the downloaded complete Dozzle logs ZIP
file instead of relying on the visible stream. Use the visible stream
only to find the right containers, merged-log page, and download URL.

After opening the merged stream for the app, use the top-right two-dot
menu's "Download" action when working manually. In browser automation,
the same ZIP URL is usually present as an anchor whose "href" contains
"/api/containers/" and "/download?stdout=1&stderr=1".

Find it with:

   Array.from(document.querySelectorAll("a"))
     .map((a) => ({ text: a.innerText.trim(), href: a.href }))
     .filter((a) => a.href.includes("/download"));

Find the Dozzle username and password in the deployment's "launch-
info.json" or on the server, as described in "browser-and-
dashboard.md" (Credentials). Do not ask the user to paste them, and do
not print the values.

If direct "curl -u <dozzle-username>:<dozzle-password>" returns "401",
fetch the ZIP through the authenticated browser session instead;
Dozzle uses the browser login session. The download is a ZIP
containing one log file per container. For post-completion downloads,
save it in the deployment folder's "local/" subfolder:

   deployment-tests/<YYYYMMDD-HHMMSS>-<app-name>/local/logs.zip
   deployment-tests/<YYYYMMDD-HHMMSS>-<app-name>/local/logs/

For throwaway intermediate scans during the run, use a system temp
path (e.g. "/tmp/dozzle-<app-name>/") so nothing transient lands in
the repository.


Dozzle API shortcut
===================

Dozzle's root page may serve the SPA shell without authenticating, but
the API requires the login session cookie. Basic auth is not enough
for endpoints such as "/api/events/stream".

Use "/api/token" to get a "jwt" cookie:

   mkdir -p /tmp/psynet-dozzle-debug
   curl -sS -c /tmp/psynet-dozzle-debug/cookies.txt \
     -b /tmp/psynet-dozzle-debug/cookies.txt \
     -X POST \
     -F "username=<dozzle-username>" \
     -F "password=<dozzle-password>" \
     "https://logs.experiments1.cococo-lab.cornell.edu/api/token"

Then sample the Server-Sent Events stream. The initial "containers-
changed" event contains the container list, including "id", "name",
"host", "state", and Docker Compose labels:

   timeout 12 curl -sS -N \
     -b /tmp/psynet-dozzle-debug/cookies.txt \
     -H "Accept: text/event-stream" \
     "https://logs.experiments1.cococo-lab.cornell.edu/api/events/stream"

Filter the "data: [...]" JSON for the app name. To download logs for
multiple containers, join each container as "<host>~<id>" and separate
containers with commas:

   https://logs.experiments1.cococo-lab.cornell.edu/api/containers/<host>~<id>,<host>~<id>/download?stdout=1&stderr=1

Then unpack it and scan all extracted logs. Expect file names like:

* "<app>-clock-1-<timestamp>.log"

* "<app>-web-1-<timestamp>.log"

* "<app>-worker_1-1-<timestamp>.log"

* "<app>-redis-1-<timestamp>.log"

* "<app>_pgbouncer-<timestamp>.log"
