Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ usage.
temporary folder:

- the events and what a message asks; which files are logs, screenshots and videos; the logs unpacked from a `.gz` and
a `.zip`; the screenshots' metadata taken out (PNG, JPEG, WebP, GIF) and broken ones refused; an MP4's place and
camera blanked; text made valid UTF-8;
a `.zip`, and the name each downloads as from the site (a log's, never the archive's); the screenshots' metadata
taken out (PNG, JPEG, WebP, GIF) and broken ones refused; an MP4's place and camera blanked; text made valid UTF-8;
- the game a log names (and the older builds' titles, a garbled one, a name in another script); the crash report's
dumps left out of a log as the log summary leaves them out; the games' names from the list (an update's and an
add-on's ID, a report named at once, one named at the next start, a log's name first, a GBA game by its code, a
Expand Down
2 changes: 1 addition & 1 deletion docs/TRACER.md
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ Static files, drawn again where a report changes them, and all of them at each s
| `index.html` | each game, its latest outcome, its reports' count; a search and a filter by outcome |
| `all.html` | every report, the newest first |
| `g/<key>.html` | a game's reports: `<key>` its title ID, or `n-` and its name's letters for a game known by name |
| `r/<id>/` | a report: its facts, screenshots, and each log with its summary, to read or download |
| `r/<id>/` | a report: its facts, screenshots, and each log with its summary, to read or download (a log sent in a `.zip` or a `.gz` is kept as its text and downloads as one: `logs.zip` as `logs.log`, `game.log.gz` as `game.log`) |
| `api/` | the same as JSON: `games.json`, `reports.json`, `r/<id>.json` (a report with its logs' summaries and the notes added later); no Discord id |
| `style.css`, `site.js`, `tracer.svg` | copied from `TRACER_ASSETS` at each start |

Expand Down
2 changes: 1 addition & 1 deletion tracer/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ src/files.o: src/files.c src/files.h src/tracer.h
$(CC) $(CFLAGS) $(OURS) -c -o $@ src/files.c
src/store.o: src/store.c src/store.h src/tracer.h
$(CC) $(CFLAGS) $(OURS) $(SQLITE_CFLAGS) -c -o $@ src/store.c
src/site.o: src/site.c src/site.h src/store.h src/tracer.h
src/site.o: src/site.c src/site.h src/files.h src/store.h src/tracer.h
$(CC) $(CFLAGS) $(OURS) -c -o $@ src/site.c
src/worker.o: src/worker.c src/worker.h src/report.h src/age.h src/tracer.h
$(CC) $(CFLAGS) $(OURS) -c -o $@ src/worker.c
Expand Down
14 changes: 14 additions & 0 deletions tracer/src/files.c
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,20 @@ int tr_unpack(const char* name, const char* data, size_t n, size_t max, Buf* out
return -1;
}

char* tr_unpacked_name(const char* name) {
size_t n = strlen(name);
if (ends(name, ".zip")) return rei_format("%.*s.log", (int)(n - 4), name);
if (ends(name, ".gz")) {
char* rest = rei_format("%.*s", (int)(n - 3), name);
char* named;
if (ends(rest, ".log") || ends(rest, ".txt")) return rest;
named = rei_format("%s.log", rest);
free(rest);
return named;
}
return rei_strdup(name);
}

char* tr_utf8(const char* text, size_t n) {
const unsigned char* s = (const unsigned char*)text;
Buf b = {0};
Expand Down
4 changes: 4 additions & 0 deletions tracer/src/files.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ int tr_ppm_png(const char* data, size_t n, Buf* out);
/* a log as text: a .gz's or a .zip's (its first .log or .txt, else its first file) unpacked, any other name's bytes
as they are, max bytes at most. 0, or -1 with why (owned) */
int tr_unpack(const char* name, const char* data, size_t n, size_t max, Buf* out, char** why);
/* the name the text tr_unpack made of name is saved as: a .gz's without its .gz ("game.log.gz" as "game.log"), with
.log after it when what is left is no .log or .txt; a .zip's with .log for its .zip ("logs.zip" as "logs.log"); any
other name as it is. The site keeps the text, never the archive. Owned */
char* tr_unpacked_name(const char* name);

/* the n bytes of text with each byte that is not part of valid UTF-8 as U+FFFD, and each NUL left out; owned */
char* tr_utf8(const char* text, size_t n);
Expand Down
6 changes: 5 additions & 1 deletion tracer/src/site.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include <time.h>
#include <unistd.h>

#include "files.h"

/* ---- pieces of a page ---- */

static void esc(Buf* b, const char* s) {
Expand Down Expand Up @@ -357,6 +359,7 @@ static void log_section(Buf* b, const StFile* f) {
cJSON* s = f->summary ? cJSON_Parse(f->summary) : NULL;
const cJSON *failure = cJSON_GetObjectItemCaseSensitive(s, "failure"), *frame;
const char* file = f->path;
char* saved = tr_unpacked_name(f->name); /* the file is the log's text, also when it came in a .zip or a .gz */
buf_add(b, "<section class=\"log\">\n<h2>");
esc(b, f->name);
buf_add(b, " <small>");
Expand All @@ -366,8 +369,9 @@ static void log_section(Buf* b, const StFile* f) {
buf_add(b, "\">View the log</a> <a class=\"button quiet\" href=\"");
esc(b, file);
buf_add(b, "\" download=\"");
esc(b, f->name);
esc(b, saved);
buf_add(b, "\">Download</a></p>\n");
free(saved);
if (cJSON_IsObject(failure)) {
const cJSON* fn = cJSON_GetObjectItemCaseSensitive(failure, "function");
buf_add(b, "<div class=\"failure\">\n");
Expand Down
69 changes: 69 additions & 0 deletions tracer/tests/test_tracer.c
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,25 @@ static void test_unpack(void) {
CHECK(tr_unpack("plain.txt", "text", 4, 3, &out, &why));
free(why);
buf_free(&out);
/* the name the unpacked text is saved as: never an archive's, as it is no archive any more */
{
static const char* const names[][2] = {
{"logs.zip", "logs.log"},
{"scarletnx-logs-2026-11-07.ZIP", "scarletnx-logs-2026-11-07.log"},
{"game.log.gz", "game.log"},
{"notes.TXT.gz", "notes.TXT"},
{"run.gz", "run.log"},
{"backup.tar.gz", "backup.tar.log"},
{"scarletnx.log", "scarletnx.log"},
{"plain.txt", "plain.txt"},
{".zip", ".zip"} /* no name before it: tr_unpack takes it as text, not a zip */};
size_t i;
for (i = 0; i < sizeof names / sizeof *names; ++i) {
char* got = tr_unpacked_name(names[i][0]);
SAME(got, names[i][1]);
free(got);
}
}
}

/* the log's summary as the bot makes it, owned */
Expand Down Expand Up @@ -2782,6 +2801,55 @@ static void test_age(void) {
gql_answer = gql_body = NULL;
}

/* a log sent in a .zip or a .gz is kept as its text: the report page's Download saves that text under a name of a log,
never the archive's, which no program opens as one */
static void test_archive_download(void) {
static char zip[1 << 16], gz[1 << 16];
size_t nzip, ngz;
TrMessage m;
StFile* files;
StReport r;
int nfiles;
char *t, *p, *rel, *data;
data = packed(1, "games/Some Game/scarletnx.log", LOG, &nzip); /* one buffer of packed's: copied before the next */
memcpy(zip, data, nzip);
data = packed(0, "data", LOG, &ngz);
memcpy(gz, data, ngz);
serve("https://cdn.discordapp.com/9/scarletnx-logs-2026-11-07.zip", zip, nzip);
serve("https://cdn.discordapp.com/9/game.log.gz", gz, ngz);
m = message(9500, 950, "<@99> from the launcher's Share Zip");
attach(&m, "scarletnx-logs-2026-11-07.zip", "https://cdn.discordapp.com/9/scarletnx-logs-2026-11-07.zip",
(double)nzip);
attach(&m, "game.log.gz", "https://cdn.discordapp.com/9/game.log.gz", (double)ngz);
t = answer_text(respond(&m));
HAS(t, "2 logs, 0 screenshots");
free(t);
CHECK(st_get(tracer.store, st_by_message(tracer.store, 9500), &r, &files, &nfiles) == 1);
CHECK(nfiles == 2);
if (nfiles == 2) {
SAME(files[0].name, "scarletnx-logs-2026-11-07.zip"); /* what was sent, as the page's heading and JSON say */
rel = rei_format("r/%ld/index.html", r.id);
p = page(rel);
HAS(p, "<h2>scarletnx-logs-2026-11-07.zip <small>");
CHECK(strstr(p, "\" download=\"scarletnx-logs-2026-11-07.log\">Download</a>") != NULL);
CHECK(strstr(p, "\" download=\"game.log\">Download</a>") != NULL);
LACKS(p, "download=\"scarletnx-logs-2026-11-07.zip\"");
LACKS(p, "download=\"game.log.gz\"");
free(p);
free(rel);
/* and the file the link names is the log's text, not a zip's bytes */
rel = rei_format("r/%ld/%s", r.id, files[0].path);
p = page(rel);
CHECK(p && strncmp(p, "PK", 2));
HAS(p, "ScarletNX - Some Game");
free(p);
free(rel);
}
st_report_free(&r);
st_files_free(files, nfiles);
tr_message_free(&m);
}

int main(int argc, char** argv) {
char *db, *command;
if (argc == 2) return as_worker(argv[1]);
Expand Down Expand Up @@ -2834,6 +2902,7 @@ int main(int argc, char** argv) {
test_untraceable(argv[0]);
test_issues();
test_age();
test_archive_download();
}
st_close(tracer.store);
if (getenv("TRACER_TEST_KEEP")) fprintf(stderr, "kept %s\n", site);
Expand Down