From ec1383504bb3f6534f0ff4ecfa71e8e9108602ee Mon Sep 17 00:00:00 2001 From: AO55 Date: Tue, 17 Nov 2026 12:41:36 -0300 Subject: [PATCH 1/6] [tracer] An approved report's issue names no game The repository's issues never name a game, and the issue held the game's title and title ID, the player's note and the log's last lines (a path to a dump names the game). The issue is titled by the report's signature and console; a title ID in a value is , a value naming a game's file is cut whole, and the note and last lines stay on the report's page, which the issue links. Signed-off-by: AO55 --- docs/TESTING.md | 6 ++- docs/TRACER.md | 26 ++++++----- scripts/test-mutants.py | 18 ++++++++ tracer/src/issues.c | 94 ++++++++++++++++++++++++++++++-------- tracer/src/issues.h | 11 +++-- tracer/tests/test_tracer.c | 41 +++++++++++++++-- 6 files changed, 158 insertions(+), 38 deletions(-) diff --git a/docs/TESTING.md b/docs/TESTING.md index 9515604..fd1f759 100644 --- a/docs/TESTING.md +++ b/docs/TESTING.md @@ -79,6 +79,8 @@ temporary folder: site's disk kept free (a report and an update refused under `TRACER_MIN_FREE` before any download, with the MiB said, one that fits taken, a disk that cannot be read, no floor), the JSON with no Discord id, the channels it answers in (a list, `all`, none, and other words refused); +- what an issue may hold of a report's text (a title ID as ``, a value naming a game's file cut whole, an + extension alone and a commit kept); - the issues an approval files, through a fake GitHub: an administrator's reaction files one, a second files none, anyone else's reaction or another emoji nothing, a refusal said and tried again, the settings and their refusals; - how old a report's build is, through a fake GitHub: behind main, the plurals, a commit asked once an hour, `-dirty` @@ -119,8 +121,8 @@ temporary folder: `python3 scripts/test-mutants.py` then changes Tracer's code one way at a time in a copy of the tree, and expects its tests to fail on each: `tracer/src/rules.c` (a threshold one off, a comparison that lets one more in, a condition left out: 19 mutants, `test_tracer --rules`); what a report keeps of its files, in `files.c`, `report.c` and `issues.c` (a -zip's screenshots, a picture never read as a log, the paths outside a home, the limits said with their values: 30 -mutants, `test_tracer --files`); what a log holds of a run, in `probe.c` (Amberlith's starting note, a name that only +zip's screenshots, a picture never read as a log, the paths outside a home, the limits said with their values, what +an issue may hold of the game: 33 mutants, `test_tracer --files`); what a log holds of a run, in `probe.c` (Amberlith's starting note, a name that only begins like it, libc's detail kept, a worker's answer naming another program: 4 mutants, `test_tracer --probe`); and the worker's locale for a zip's names, made before it shuts itself in (1 mutant, the whole suite). A mutant they pass, or one whose text its file no longer has once, fails it. About 30 s. diff --git a/docs/TRACER.md b/docs/TRACER.md index ba372ee..9329e48 100644 --- a/docs/TRACER.md +++ b/docs/TRACER.md @@ -208,17 +208,21 @@ Each is a message that mentions Tracer, in a channel it answers in: A report becomes a GitHub issue once a server's administrator approves it: with `TRACER_ISSUES_REPO`, the owner or an administrator of the server it was sent in (or one of `TRACER_ADMINS`) reacts to one of its messages (the one that sent it, an update, Tracer's answer) with the approval's emoji, `TRACER_ISSUES_EMOJI`, the check mark by default. Tracer -opens the issue in that repository with what the site shows of the report: its facts and its first log's summary (home -folders and the folders of paths outside them as `~`, addresses as `[ip]` and `[email]`, no dumps), each of a log's or -a player's words in a code block, where GitHub links no `@name` and no `#number`, the report's page, and its -screenshots, each the site's picture 320 pixels wide linked to it and named by its number in the report (a file's -name is a player's words). GitHub's API takes no file for an issue: its image proxy fetches each picture from the site, -so the site must answer it. The issue's number goes into the database, onto -the report's page and its JSON, and into a short reply on Discord. A report is filed once: a second approval opens no -other issue, and one GitHub refused (its status and message in the reply) is tried again by the next approval. Anyone -else's reaction, and another emoji, are left as they are. GitHub is asked from the bot's own process, with a 30 s -timeout; the worker that reads the files never holds this token either. The gateway asks for the reactions only when -`TRACER_ISSUES_REPO` is set. +opens the issue in that repository, titled `Tracer report 12: ()`, with what the site +shows of the failure: its facts (console, game version, build, system, GPU, driver, outcome, signature, what the runtime +missed) and its first log's fatal and frames (home folders and the folders of paths outside them as `~`, addresses as +`[ip]` and `[email]`, no dumps), each of a log's words in a code block, where GitHub links no `@name` and no `#number`, +the report's page, and its screenshots, each the site's picture 320 pixels wide linked to it and named by its number in +the report (a file's name is a player's words). GitHub's API takes no file for an issue: its image proxy fetches each +picture from the site, so the site must answer it. An issue names no game, as the repository's issues never do: no +title, no title ID (one in a value is written ``), no player's note and no last lines (where a game's name may +be), and a value that names a game's file (a dump's, an update's, a mod's: `.nsp`, `.xci`, `.3ds`, `.pchtxt`...) is cut +whole, as the name before it may hold spaces; the report's page, which the issue links, has them all. The issue's number +goes into the database, onto the report's page and its JSON, and into a short reply on Discord. A report is filed once: +a second approval opens no other issue, and one GitHub refused (its status and message in the reply) is tried again by +the next approval. Anyone else's reaction, and another emoji, are left as they are. GitHub is asked from the bot's own +process, with a 30 s timeout; the worker that reads the files never holds this token either. The gateway asks for the +reactions only when `TRACER_ISSUES_REPO` is set. ## How old a build is diff --git a/scripts/test-mutants.py b/scripts/test-mutants.py index 2b5c348..76cf7e4 100755 --- a/scripts/test-mutants.py +++ b/scripts/test-mutants.py @@ -259,6 +259,24 @@ ' tilded = tr_public_log(shown, n, &n);\n' ' free(shown);', ), + ( + "the issue keeps a title ID", + 'issues.c', + ' if (run == 16 && (at + 1 == n || !hex(s[at + 1]))) {', + ' if (run == 17 && (at + 1 == n || !hex(s[at + 1]))) {', + ), + ( + "the issue keeps a line that names a game's file", + 'issues.c', + ' if (game_file(s, end)) {', + ' if (0 && game_file(s, end)) {', + ), + ( + "a word that is an extension alone is a game's file", + 'issues.c', + ' if (i <= 1 || i == n) return 0;', + ' if (!i || i == n) return 0;', + ), ( 'the issue has no screenshots', 'issues.c', diff --git a/tracer/src/issues.c b/tracer/src/issues.c index 2b252af..c7cb130 100644 --- a/tracer/src/issues.c +++ b/tracer/src/issues.c @@ -3,6 +3,7 @@ #include "issues.h" #include #include +#include #define GITHUB_API "https://api.github.com/" #define TITLE_MAX 200 /* an issue title's bytes at most */ @@ -96,19 +97,80 @@ static char* one_line(const char* text, size_t max) { return t; } +/* the extensions of a game's files: a dump's, an update's, a patch's, a mod's (tools/tracer.py's --upstream's) */ +static const char* const GAME_FILES[] = {"nsp", "nsz", "xci", "xcz", "nro", "nso", "3ds", "3dsx", + "cia", "cci", "cxi", "gba", "agb", "vpk", "pchtxt", "ips"}; + +/* whether the n bytes at s, a word, end in a game file's extension */ +static int game_file(const char* s, size_t n) { + size_t i, k; + for (i = n; i > 0 && s[i - 1] != '.'; --i) + if (!((s[i - 1] >= 'a' && s[i - 1] <= 'z') || (s[i - 1] >= 'A' && s[i - 1] <= 'Z') || + (s[i - 1] >= '0' && s[i - 1] <= '9'))) + return 0; + if (i <= 1 || i == n) return 0; /* a name before the dot, and an extension after it */ + for (k = 0; k < sizeof GAME_FILES / sizeof *GAME_FILES; ++k) + if (n - i == strlen(GAME_FILES[k]) && !strncasecmp(s + i, GAME_FILES[k], n - i)) return 1; + return 0; +} +static int hex(char c) { return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || (c >= 'A' && c <= 'F'); } + +/* the n bytes at s, a word, with each title ID in it (16 hex digits, no more) as , into b */ +static void put_word(Buf* b, const char* s, size_t n) { + size_t at, run = 0, from = 0; + for (at = 0; at < n; ++at) { + run = hex(s[at]) ? run + 1 : 0; + if (run == 16 && (at + 1 == n || !hex(s[at + 1]))) { + buf_addn(b, s + from, at + 1 - 16 - from); + buf_add(b, ""); + from = at + 1; + run = 0; + } + } + buf_addn(b, s + from, n - from); +} + +char* tr_upstream_text(const char* text, size_t max) { + Buf b = {0}; + char *line = one_line(text, (size_t)-1), *out; + const char* s; + for (s = line; *s;) { /* a game's file anywhere: the whole text goes, as a name with spaces is before it */ + size_t n = strcspn(s, " "), end = n; + while (end && strchr(".,;:)]}>'\"", s[end - 1])) --end; /* the punctuation after it */ + if (game_file(s, end)) { + free(line); + return rei_strdup(""); + } + s += n + (s[n] == ' '); + } + for (s = line; *s;) { + size_t n = strcspn(s, " "); + put_word(&b, s, n); + if (s[n] == ' ') buf_add(&b, " "); + s += n + (s[n] == ' '); + } + free(line); + out = one_line(b.text ? b.text : "", max); + buf_free(&b); + return out; +} + char* tr_issue_title(const StReport* r) { - /* no "#12": GitHub would link the repository's own issue 12 */ - char *raw = rei_format("Report %ld: %s (%s)", r->id, r->title, r->outcome ? r->outcome : "no failure logged"), - *t = one_line(raw, TITLE_MAX); + /* no "#12": GitHub would link the repository's own issue 12; no game: the issue is upstream's */ + char *raw = r->signature + ? rei_format("Tracer report %ld: %s (%s)", r->id, r->signature, r->console ? r->console : "a game") + : rei_format("Tracer report %ld: %s (%s)", r->id, r->outcome ? r->outcome : "no failure logged", + r->console ? r->console : "a game"), + *t = tr_upstream_text(raw, TITLE_MAX); free(raw); return t; } -/* a line of the code block: name and value, when there is one */ +/* a line of the code block: name and value, when there is one, as an issue may hold it */ static void fact(Buf* b, const char* name, const char* value) { char* v; if (!value || !*value) return; - v = one_line(value, 500); + v = tr_upstream_text(value, 500); buf_printf(b, "%-13s %s\n", name, v); free(v); } @@ -142,7 +204,7 @@ char* tr_issue_body(const StReport* r, const StFile* files, int nfiles, const ch Buf facts = {0}, b = {0}; const StFile* log = NULL; cJSON* s = NULL; - const cJSON *frame, *line; + const cJSON* frame; size_t fence; int i; char* build = @@ -150,8 +212,6 @@ char* tr_issue_body(const StReport* r, const StFile* files, int nfiles, const ch for (i = 0; i < nfiles && !log; ++i) if (!strcmp(files[i].kind, "log")) log = &files[i]; if (log && log->summary) s = cJSON_Parse(log->summary); - fact(&facts, "Game", r->title); - fact(&facts, "Title ID", r->title_id); fact(&facts, "Console", r->console); fact(&facts, "Game version", r->version); fact(&facts, "Build", build ? build : r->build); @@ -161,7 +221,6 @@ char* tr_issue_body(const StReport* r, const StFile* files, int nfiles, const ch fact(&facts, "Outcome", r->outcome ? r->outcome : "no failure logged"); fact(&facts, "Signature", r->signature); fact(&facts, "Missed", r->missed); - fact(&facts, "Note", r->note); free(build); { const cJSON* failure = cJSON_GetObjectItemCaseSensitive(s, "failure"); @@ -178,25 +237,22 @@ char* tr_issue_body(const StReport* r, const StFile* files, int nfiles, const ch free(text); first = 0; } - first = 1; - cJSON_ArrayForEach(line, cJSON_GetObjectItemCaseSensitive(s, "tail")) if (cJSON_IsString(line)) { - fact(&facts, first ? "Last lines" : "", line->valuestring); - first = 0; - } } fence = ticks(facts.text) + 1; if (fence < 3) fence = 3; buf_printf(&b, - "Tracer's report %ld, approved on Discord by a server's administrator: its logs, screenshots and " - "videos are on %s/r/%ld/\n\n", + "Tracer's report %ld, approved on Discord by a server's administrator: the game, its logs, the " + "player's words, screenshots and videos are on %s/r/%ld/\n\n", r->id, url, r->id); for (i = 0; i < (int)fence; ++i) buf_add(&b, "`"); buf_add(&b, "text\n"); buf_add(&b, facts.text ? facts.text : ""); for (i = 0; i < (int)fence; ++i) buf_add(&b, "`"); - buf_add(&b, - "\n\nThe log's home folders, and the folders of a path outside them, are written as ~ and its addresses " - "as [ip] and [email]; the crash report's dumps of the game's bytes are not in it.\n"); + buf_add( + &b, + "\n\nThe game is named on the report's page, not here: a title ID is written as , and a line that " + "names a game's file is cut. The log's home folders, and the folders of a path outside them, are written as ~ and " + "its addresses as [ip] and [email]; the crash report's dumps of the game's bytes are not in it.\n"); shots(&b, r->id, files, nfiles, url); buf_free(&facts); cJSON_Delete(s); diff --git a/tracer/src/issues.h b/tracer/src/issues.h index 29d76cc..cb13d05 100644 --- a/tracer/src/issues.h +++ b/tracer/src/issues.h @@ -28,10 +28,15 @@ void tr_issues_free(TrIssues* is); /* the start's line saying them, every value but the token's; owned */ char* tr_issues_said(const TrIssues* is); -/* report r's issue: its title, and its body of what the site shows (files' summaries, its page at url, its screenshots - as the site's images linked to them), each of a log's or a player's words in a code block, where GitHub links no - @name and no #number, and no "#" before the report's own number; owned */ +/* report r's issue: its title, and its body of what the site shows of the failure (its facts, the first log's fatal + and frames, its page at url, its screenshots as the site's images linked to them), each of a log's words in a code + block, where GitHub links no @name and no #number, and no "#" before the report's own number; owned. Neither names + the game: no title, no title ID (a value holding one has it as ), no game file's name (a value with one is + cut), no player's note and no last lines, which may; the report's page has them */ char* tr_issue_title(const StReport* r); +/* text as an issue may hold it, on one line, cut to max bytes: each title ID (16 hex digits) as , and the whole + text cut when a word of it names a game's file (.nsp, .xci, .3ds...), as the name before it may have spaces; owned */ +char* tr_upstream_text(const char* text, size_t max); char* tr_issue_body(const StReport* r, const StFile* files, int nfiles, const char* url); /* the issue opened: 0 with *number and *url (owned, its page on GitHub), or -1 with why (owned): GitHub's status and message, or no answer */ diff --git a/tracer/tests/test_tracer.c b/tracer/tests/test_tracer.c index 55b00b2..e3403f3 100644 --- a/tracer/tests/test_tracer.c +++ b/tracer/tests/test_tracer.c @@ -2763,6 +2763,32 @@ static TrReaction reaction(u64 user, u64 guild, u64 message, const char* emoji) r.emoji = rei_strdup(emoji); return r; } +/* what an issue may hold of a log's or a report's text: no title ID, no game's file */ +static void test_upstream_text(void) { + char* t; + t = tr_upstream_text("svcBreak in 0100A6301214E000 sdk+1470d8", 200); + SAME(t, "svcBreak in sdk+1470d8"); + free(t); + t = tr_upstream_text("at [0100a6301214e000][v0], then 0004000000055d00.", 200); + SAME(t, "at [][v0], then ."); + free(t); + t = tr_upstream_text("commit 0123456789abcdef0123456789abcdef01234567 and a1b2c3d4e5f60718a", 200); + SAME(t, "commit 0123456789abcdef0123456789abcdef01234567 and a1b2c3d4e5f60718a"); /* not 16 digits */ + free(t); + t = tr_upstream_text("could not open ~/Some Game [0100A6301214E000][v0].nsp, so it stopped", 200); + SAME(t, ""); + free(t); + t = tr_upstream_text("loading ~/mods/Patch.PCHTXT", 200); + SAME(t, ""); + free(t); + t = tr_upstream_text("an .nsp is a dump; libnsp.so, x.nspx and nsp stay\na line", 200); + SAME(t, "an .nsp is a dump; libnsp.so, x.nspx and nsp stay a line"); /* ".nsp" alone names no file */ + free(t); + t = tr_upstream_text("0100A6301214E000", 5); + SAME(t, " Date: Tue, 17 Nov 2026 12:47:33 -0300 Subject: [PATCH 2/6] [tracer] Link a report to an issue that exists: link and unlink An approval opens a new issue; a report of a failure an issue already tracks had no way to point at it. "@Tracer link 12 1234" (or a reply with "@Tracer link 1234"), from those who approve, checks the issue or pull request on GitHub, keeps it as an approval's, and comments on it with the report's page, so each links to the other; "unlink" takes it out. Signed-off-by: AO55 --- docs/TESTING.md | 6 +- docs/TRACER.md | 11 +++ scripts/test-mutants.py | 9 +- tracer/src/issues.c | 57 ++++++++++++ tracer/src/issues.h | 6 ++ tracer/src/message.c | 39 ++++++++ tracer/src/message.h | 6 +- tracer/src/report.c | 88 ++++++++++++++++++- tracer/tests/test_tracer.c | 176 +++++++++++++++++++++++++++++++++++++ 9 files changed, 392 insertions(+), 6 deletions(-) diff --git a/docs/TESTING.md b/docs/TESTING.md index fd1f759..8e342ac 100644 --- a/docs/TESTING.md +++ b/docs/TESTING.md @@ -81,6 +81,9 @@ temporary folder: answers in (a list, `all`, none, and other words refused); - what an issue may hold of a report's text (a title ID as ``, a value naming a game's file cut whole, an extension alone and a commit kept); +- a report linked to an issue that exists (`link`, `unlink`), through a fake GitHub: by an administrator only, in a + reply or by number, the comment that links back, a pull request, an issue that is none, a refused comment said, the + approval opening none for a linked report; - the issues an approval files, through a fake GitHub: an administrator's reaction files one, a second files none, anyone else's reaction or another emoji nothing, a refusal said and tried again, the settings and their refusals; - how old a report's build is, through a fake GitHub: behind main, the plurals, a commit asked once an hour, `-dirty` @@ -124,7 +127,8 @@ out: 19 mutants, `test_tracer --rules`); what a report keeps of its files, in `f zip's screenshots, a picture never read as a log, the paths outside a home, the limits said with their values, what an issue may hold of the game: 33 mutants, `test_tracer --files`); what a log holds of a run, in `probe.c` (Amberlith's starting note, a name that only begins like it, libc's detail kept, a worker's answer naming another program: 4 mutants, `test_tracer --probe`); and -the worker's locale for a zip's names, made before it shuts itself in (1 mutant, the whole suite). A mutant they pass, +the worker's locale for a zip's names, made before it shuts itself in, and who links a report to an issue (2 mutants, +the whole suite). A mutant they pass, or one whose text its file no longer has once, fails it. About 30 s. `make -C tracer bench [RUNS=1000] [FOLDER=/tmp/tracer-bench]` (`tracer/tests/bench_probe.c`, built by `make test`, diff --git a/docs/TRACER.md b/docs/TRACER.md index 9329e48..2662f83 100644 --- a/docs/TRACER.md +++ b/docs/TRACER.md @@ -202,6 +202,8 @@ Each is a message that mentions Tracer, in a channel it answers in: | `@Tracer add 12`, and words; or a reply to one of report 12's messages | adds the message's files and words to report 12 | the one who sent it, the server's owner and administrators, `TRACER_ADMINS` | | a reply with no file, to a message with a log | a report of that message | anyone | | `@Tracer delete 12`, or `@Tracer delete` in a reply | deletes report 12 | the one who sent it, the server's owner and administrators, `TRACER_ADMINS` | +| `@Tracer link 12 1234`, or `@Tracer link 1234` in a reply | links report 12 to issue or pull request 1234 of `TRACER_ISSUES_REPO` ([Issues](#issues)) | the server's owner and administrators, `TRACER_ADMINS` | +| `@Tracer unlink 12`, or `@Tracer unlink` in a reply | takes report 12's link to an issue out | the same | ## Issues @@ -224,6 +226,15 @@ the next approval. Anyone else's reaction, and another emoji, are left as they a process, with a 30 s timeout; the worker that reads the files never holds this token either. The gateway asks for the reactions only when `TRACER_ISSUES_REPO` is set. +A report also links to an issue or a pull request that exists, in the same repository: `@Tracer link 12 1234` (`#12` +and `#1234` too), or a reply to one of its messages with `@Tracer link 1234`, from those who approve. Tracer asks +GitHub for it (`GET repos//issues/1234`, which answers pull requests too), keeps its number and page as an +approval's, draws the report's page again and comments on the issue with the report's page, `Tracer report 12 is +linked to this issue, by a server's administrator on Discord: `, so each links to the other. A number GitHub has +no issue for, and a comment GitHub refuses, are said with its status and message; the link stays without its +comment. A report linked to another issue says which it replaced; `@Tracer unlink 12` takes the link out, the comment +on GitHub staying. A report with an issue opens no other at an approval. + ## How old a build is How old a new report's build is goes into the reply and onto the report's page and its JSON (`build_age`), as it was diff --git a/scripts/test-mutants.py b/scripts/test-mutants.py index 76cf7e4..e153f23 100755 --- a/scripts/test-mutants.py +++ b/scripts/test-mutants.py @@ -313,8 +313,15 @@ ), ) -# what only the whole suite holds: the worker, a process of its own shut in its folder (test_worker) +# what only the whole suite holds: the worker, a process of its own shut in its folder (test_worker); who links a +# report to an issue (test_links) WORKER = ( + ( + 'anyone links a report to an issue', + 'report.c', + ' if (!admin(t, m, r.guild)) {\n st_report_free(&r);\n return said("Only the server', + ' if (0) {\n st_report_free(&r);\n return said("Only the server', + ), ( "the worker makes a zip's locale once shut in, where its files do not open", 'worker.c', diff --git a/tracer/src/issues.c b/tracer/src/issues.c index c7cb130..3d5f81a 100644 --- a/tracer/src/issues.c +++ b/tracer/src/issues.c @@ -293,3 +293,60 @@ int tr_issue_open(const TrIssues* is, const char* title, const char* body, long* free(path); return *url ? 0 : -1; } + +/* GitHub's answer as why: its status and message, or why none came; owned */ +static char* refused(const RgAnswer* a, const cJSON* got, const char* method, const char* path) { + return a->status ? rei_format("GitHub answered %d to %s %s: %s", a->status, method, path, + jstr(got, "message") ? jstr(got, "message") : "no message") + : rei_format("GitHub did not answer %s %s: %s", method, path, a->error ? a->error : "no reason"); +} + +int tr_issue_get(const TrIssues* is, long number, char** url, int* pull, char** state, char** why) { + char *path = rei_format("repos/%s/issues/%ld", is->repo, number), *full = rei_format(GITHUB_API "%s", path); + RgAnswer a; + cJSON* got; + *url = *state = *why = NULL; + *pull = 0; + memset(&a, 0, sizeof a); + is->fetch(is->ctx, "GET", full, NULL, NULL, &a); + got = a.body ? cJSON_Parse(a.body) : NULL; + if (a.status == 200 && (long)jnum(got, "number") == number && jstr(got, "html_url") && + !strncmp(jstr(got, "html_url"), "https://github.com/", 19)) { + *url = rei_strdup(jstr(got, "html_url")); + *pull = cJSON_IsObject(cJSON_GetObjectItemCaseSensitive(got, "pull_request")); + *state = rei_strdup(jstr(got, "state") ? jstr(got, "state") : "open"); + } else + *why = refused(&a, got, "GET", path); + cJSON_Delete(got); + free(a.body); + free(a.etag); + free(a.error); + free(full); + free(path); + return *url ? 0 : -1; +} + +int tr_issue_comment(const TrIssues* is, long number, const char* body, char** why) { + char *path = rei_format("repos/%s/issues/%ld/comments", is->repo, number), + *full = rei_format(GITHUB_API "%s", path), *request; + cJSON *ask = cJSON_CreateObject(), *got; + RgAnswer a; + int ok; + *why = NULL; + jset(ask, "body", body); + request = cJSON_PrintUnformatted(ask); + cJSON_Delete(ask); + memset(&a, 0, sizeof a); + is->fetch(is->ctx, "POST", full, request, NULL, &a); + got = a.body ? cJSON_Parse(a.body) : NULL; + ok = a.status == 201; + if (!ok) *why = refused(&a, got, "POST", path); + cJSON_Delete(got); + free(a.body); + free(a.etag); + free(a.error); + free(request); + free(full); + free(path); + return ok ? 0 : -1; +} diff --git a/tracer/src/issues.h b/tracer/src/issues.h index cb13d05..ec151a6 100644 --- a/tracer/src/issues.h +++ b/tracer/src/issues.h @@ -41,4 +41,10 @@ char* tr_issue_body(const StReport* r, const StFile* files, int nfiles, const ch /* the issue opened: 0 with *number and *url (owned, its page on GitHub), or -1 with why (owned): GitHub's status and message, or no answer */ int tr_issue_open(const TrIssues* is, const char* title, const char* body, long* number, char** url, char** why); +/* issue number of is->repo as GitHub has it (an issue or a pull request, which GitHub numbers alike): 0 with *url + (owned, its page), *pull (1 for a pull request) and *state (owned: "open", "closed"), or -1 with why (owned): + GitHub's status and message, or no answer */ +int tr_issue_get(const TrIssues* is, long number, char** url, int* pull, char** state, char** why); +/* body as a comment on issue number: 0, or -1 with why (owned) */ +int tr_issue_comment(const TrIssues* is, long number, const char* body, char** why); #endif diff --git a/tracer/src/message.c b/tracer/src/message.c index f288431..b3056c2 100644 --- a/tracer/src/message.c +++ b/tracer/src/message.c @@ -185,6 +185,45 @@ static char* cut_note(char* t) { char* tr_words(const char* content) { return cut_note(plain_words(content ? content : "")); } +/* a number at *at, with or without a "#" before it, then a space or the end: its value, *at past it; 0 for none */ +static long number_at(const char** at) { + const char* s = *at + (**at == '#'); + char* end; + long v = isdigit((unsigned char)*s) ? strtol(s, &end, 10) : 0; + if (v <= 0 || (*end && *end != ' ')) return 0; + *at = end + (*end == ' '); + return v; +} + +TrVerb tr_link(const char* content, long* report, long* issue) { + char* t = plain_words(content); + const char* at; + TrVerb verb = TR_REPORT; + long first, second; + *report = *issue = 0; + if (!strncasecmp(t, "link ", 5)) { + at = t + 5; + first = number_at(&at); + second = first && *at ? number_at(&at) : 0; + if (first && !*at) { + verb = TR_LINK; + *report = second ? first : 0; + *issue = second ? second : first; + } + } else if (!strcasecmp(t, "unlink")) + verb = TR_UNLINK; + else if (!strncasecmp(t, "unlink ", 7)) { + at = t + 7; + first = number_at(&at); + if (first && !*at) { + verb = TR_UNLINK; + *report = first; + } + } + free(t); + return verb; +} + TrVerb tr_command(const char* content, char** note, long* number) { char *t = plain_words(content), *end; TrVerb verb = TR_REPORT; diff --git a/tracer/src/message.h b/tracer/src/message.h index 279675d..b4f34cb 100644 --- a/tracer/src/message.h +++ b/tracer/src/message.h @@ -49,11 +49,15 @@ u64 tr_deleted(const char* json, size_t len); /* READY's user id, and its name (owned, or NULL) when name is given */ u64 tr_ready(const char* json, size_t len, char** name); -typedef enum { TR_REPORT, TR_HELP, TR_DELETE, TR_ADD } TrVerb; +typedef enum { TR_REPORT, TR_HELP, TR_DELETE, TR_ADD, TR_LINK, TR_UNLINK } TrVerb; /* what content asks of the bot, its mentions left out: "help"; "delete 12" (or "delete #12", *number 12), or "delete" alone (*number 0: the report the message replies to); "add 12" (or "add #12") and a note after it; else a report. *note (owned) is the rest of the text on one line, cut to TR_NOTE bytes; "" for none */ TrVerb tr_command(const char* content, char** note, long* number); +/* whether content links a report to a GitHub issue: "link 12 1234" (*report 12, *issue 1234; "#12", "#1234" too), or + "link 1234" (*report 0: the report the message replies to); "unlink 12", or "unlink" alone (*report 0). TR_LINK, + TR_UNLINK, or TR_REPORT for any other text (tr_command's to read) */ +TrVerb tr_link(const char* content, long* report, long* issue); /* content's words, its mentions left out, on one line and cut to TR_NOTE bytes, as a report's note; owned */ char* tr_words(const char* content); #endif diff --git a/tracer/src/report.c b/tracer/src/report.c index 4929515..507a073 100644 --- a/tracer/src/report.c +++ b/tracer/src/report.c @@ -249,7 +249,9 @@ static cJSON* help(void) { "`@Tracer add 12` with them. For a log someone sent without mentioning me, reply to their message and " "mention me: I make a report of it.\n\n" "`@Tracer delete 12`, or a reply with `@Tracer delete`, deletes a report (yours, or any for an " - "administrator). Deleting your message deletes what it sent: the report, or what it added.", + "administrator). Deleting your message deletes what it sent: the report, or what it added.\n\n" + "An administrator links a report to a GitHub issue or pull request with `@Tracer link 12 1234` (or a reply " + "to it with `@Tracer link 1234`), and takes the link out with `@Tracer unlink 12`.", TONE_SAID); } @@ -1328,11 +1330,89 @@ static cJSON* from_reply(Tracer* t, const TrMessage* m, const char* note, long* return e; } +/* report id linked to issue (an issue or a pull request of TRACER_ISSUES_REPO), or to none (issue 0), by m's author, + who approves reports: the link kept, the site drawn again, a comment on the issue that links back to the report */ +static cJSON* linked(Tracer* t, const TrMessage* m, long id, long issue, int unlink) { + StReport r; + char *text, *url = NULL, *state = NULL, *why = NULL; + int pull = 0; + cJSON* e; + if (!t->issues || !t->issues->repo) + return said("No repository is set for the issues (TRACER_ISSUES_REPO), so a report links to none."); + if (!id) + return said(unlink ? "Which report? `@Tracer unlink 12`, or a reply to the report with `@Tracer unlink`." + : "Which report? `@Tracer link 12 1234` links report 12 to issue 1234, or a reply to the " + "report with `@Tracer link 1234`."); + if (st_get(t->store, id, &r, NULL, NULL) != 1) { + text = rei_format("There is no report #%ld.", id); + e = said(text); + free(text); + return e; + } + if (!admin(t, m, r.guild)) { + st_report_free(&r); + return said("Only the server's owner and administrators link a report to an issue, as they approve one."); + } + if (r.issue < 0) { + text = rei_format("Report #%ld's issue is being opened: try again in a moment, please.", id); + } else if (unlink) { + if (!r.issue) + text = rei_format("Report #%ld is linked to no issue.", id); + else if (st_set_issue(t->store, id, 0, NULL)) + text = rei_strdup("The link could not be taken out: try again later, please."); + else { + site_update(t->store, t->root, id, r.key); + rei_log("report #%ld is linked to no issue, by %llu: it was #%ld", id, (unsigned long long)m->author, + r.issue); + text = rei_format("Report #%ld is linked to no issue now: it was #%ld, whose comment that links to the " + "report stays.", + id, r.issue); + } + } else if (r.issue == issue) + text = rei_format("Report #%ld is linked to #%ld already.", id, issue); + else if (tr_issue_get(t->issues, issue, &url, &pull, &state, &why)) + text = rei_format("Report #%ld was not linked to #%ld: %s", id, issue, why); + else if (st_set_issue(t->store, id, issue, url)) + text = rei_strdup("The link could not be kept: try again later, please."); + else { + char *page = rei_format("%s/r/%ld/", t->url, id), + *body = rei_format("Tracer report %ld is linked to this %s, by a server's administrator on Discord: %s", + id, pull ? "pull request" : "issue", page), + *refusal = NULL; + site_update(t->store, t->root, id, r.key); + if (tr_issue_comment(t->issues, issue, body, &refusal)) + rei_log("report #%ld linked to #%ld, and the comment that links back was refused: %s", id, issue, refusal); + rei_log("report #%ld is linked to #%ld (%s), by %llu", id, issue, url, (unsigned long long)m->author); + char* instead = r.issue > 0 ? rei_format(", in place of #%ld", r.issue) : rei_strdup(""); + text = rei_format( + "Report #%ld is linked to %s #%ld (%s) now%s.%s%s", id, pull ? "pull request" : "issue", issue, state, + instead, refusal ? " Its comment that links back to the report was refused: " : "", refusal ? refusal : ""); + free(instead); + free(refusal); + free(body); + free(page); + } + e = said(text); + if (url) jset(e, "url", url); + free(text); + free(url); + free(state); + free(why); + st_report_free(&r); + return e; +} + cJSON* tr_answer(Tracer* t, const TrMessage* m, long* report) { char* note; - long number, target; + long number, target, issue; cJSON* e = NULL; - TrVerb verb = tr_command(m->content, ¬e, &number); + TrVerb verb = tr_link(m->content, &number, &issue); + if (verb != TR_REPORT) { /* link or unlink: the report named, else the one the message replies to */ + target = number ? number : m->reply_to ? st_report_of(t->store, m->reply_to) : m->reply_report; + *report = 0; + return linked(t, m, target, issue, verb == TR_UNLINK); + } + verb = tr_command(m->content, ¬e, &number); *report = 0; target = number ? number : m->reply_to ? st_report_of(t->store, m->reply_to) : 0; if (!target && m->reply_report) { /* an answer of the bot's that was not kept: its embed's link names the report */ @@ -1350,6 +1430,8 @@ cJSON* tr_answer(Tracer* t, const TrMessage* m, long* report) { : said("Which report? `@Tracer delete 12`, or a reply to the report with `@Tracer delete`."); break; case TR_ADD: e = updated(t, m, target, note, report); break; + case TR_LINK: + case TR_UNLINK: break; /* tr_link's, above */ case TR_REPORT: /* a reply to a report adds to it; a reply alone to another message makes a report of it */ if (target) e = m->nfiles || *note ? updated(t, m, target, note, report) : known(t, m, target); diff --git a/tracer/tests/test_tracer.c b/tracer/tests/test_tracer.c index e3403f3..b29dfec 100644 --- a/tracer/tests/test_tracer.c +++ b/tracer/tests/test_tracer.c @@ -2928,6 +2928,181 @@ static void test_issues(void) { gh_body = NULL; } +/* GitHub for the links: issue 1234 open, pull request 77 closed, 5 none; a comment answered comment_status */ +static int comment_status = 201, link_asks; +static char *comment_body, comment_url[256]; +static void fake_links(void* ctx, const char* method, const char* url, const char* body, const char* etag, + RgAnswer* out) { + (void)ctx; + (void)etag; + memset(out, 0, sizeof *out); + ++link_asks; + if (!strcmp(method, "POST") && strstr(url, "/comments")) { + snprintf(comment_url, sizeof comment_url, "%s %s", method, url); + free(comment_body); + comment_body = rei_strdup(body ? body : ""); + out->status = comment_status; + out->body = rei_strdup(comment_status == 201 ? "{\"id\":1}" : "{\"message\":\"Must have admin rights\"}"); + } else if (!strcmp(url, "https://api.github.com/repos/o/r/issues/1234")) { + out->status = 200; + out->body = rei_strdup("{\"number\":1234,\"html_url\":\"https://github.com/o/r/issues/1234\"," + "\"state\":\"open\"}"); + } else if (!strcmp(url, "https://api.github.com/repos/o/r/issues/77")) { + out->status = 200; + out->body = rei_strdup("{\"number\":77,\"html_url\":\"https://github.com/o/r/pull/77\",\"state\":" + "\"closed\",\"pull_request\":{\"url\":\"x\"}}"); + } else { + out->status = 404; + out->body = rei_strdup("{\"message\":\"Not Found\"}"); + } +} + +/* a report linked to an issue that exists, by an administrator: the link both ways (the database, the page, a comment + on the issue), a pull request, an issue that is none, a refused comment, unlinked; no one else links */ +static void test_links(void) { + TrIssues is; + TrMessage m; + StReport rep; + long id, n, issue; + char *t, *p, *rel; + /* the commands */ + CHECK(tr_link("<@99> link 12 1234", &n, &issue) == TR_LINK && n == 12 && issue == 1234); + CHECK(tr_link("<@99> LINK #12 #1234", &n, &issue) == TR_LINK && n == 12 && issue == 1234); + CHECK(tr_link("<@99> link #1234", &n, &issue) == TR_LINK && n == 0 && issue == 1234); + CHECK(tr_link("<@99> unlink 12", &n, &issue) == TR_UNLINK && n == 12); + CHECK(tr_link("<@99> unlink", &n, &issue) == TR_UNLINK && n == 0); + CHECK(tr_link("<@99> link 12 1234 please", &n, &issue) == TR_REPORT); + CHECK(tr_link("<@99> link it", &n, &issue) == TR_REPORT && tr_link("<@99> linked 12", &n, &issue) == TR_REPORT); + CHECK(tr_link("<@99> unlink 12 x", &n, &issue) == TR_REPORT && tr_link("<@99> help", &n, &issue) == TR_REPORT); + /* no repository: said */ + tracer.issues = NULL; + m = message(8200, 150, "<@99> link 1 1234"); + t = answer_text(respond(&m)); + HAS(t, "No repository is set for the issues (TRACER_ISSUES_REPO), so a report links to none."); + free(t); + tr_message_free(&m); + memset(&is, 0, sizeof is); + is.repo = "o/r"; + is.emoji = "\xe2\x9c\x85"; + is.fetch = fake_links; + tracer.issues = &is; + m = message(8201, 150, "<@99> it crashes"); + attach(&m, "game.log", "https://cdn.discordapp.com/1/game.log", 10); + free(answer_text(respond(&m))); + tr_message_free(&m); + id = st_report_of(tracer.store, 8201); + CHECK(id > 0); + /* its sender, no administrator: refused, GitHub not asked */ + link_asks = 0; + m = message(8202, 150, ""); + free(m.content); + m.content = rei_format("<@99> link %ld 1234", id); + t = answer_text(respond(&m)); + HAS(t, "Only the server's owner and administrators link a report to an issue"); + free(t); + tr_message_free(&m); + CHECK(link_asks == 0); + /* an administrator, in a reply to the report: linked, a comment on the issue */ + m = message(8203, 88, "<@99> link #1234"); + m.roles[m.nroles++] = 5; + m.reply_to = 8201; + t = answer_text(respond(&m)); + rel = rei_format("Report #%ld is linked to issue #1234 (open) now.", id); + HAS(t, rel); + free(rel); + free(t); + tr_message_free(&m); + SAME(comment_url, "POST https://api.github.com/repos/o/r/issues/1234/comments"); + rel = rei_format("Tracer report %ld is linked to this issue, by a server's administrator on Discord: " + "https://reports.example/r/%ld/", + id, id); + HAS(comment_body, rel); + free(rel); + CHECK(st_get(tracer.store, id, &rep, NULL, NULL) == 1 && rep.issue == 1234); + SAME(rep.issue_url, "https://github.com/o/r/issues/1234"); + st_report_free(&rep); + rel = rei_format("r/%ld/index.html", id); + p = page(rel); + HAS(p, "
Issue
#1234
"); + free(p); + free(rel); + /* the same again: nothing asked */ + link_asks = 0; + m = message(8204, 88, ""); + free(m.content); + m.content = rei_format("<@99> link %ld 1234", id); + m.roles[m.nroles++] = 5; + t = answer_text(respond(&m)); + HAS(t, "is linked to #1234 already."); + free(t); + tr_message_free(&m); + CHECK(link_asks == 0); + /* an issue that is none: said with GitHub's answer, the link as it was */ + m = message(8205, 88, ""); + free(m.content); + m.content = rei_format("<@99> link %ld 5", id); + m.roles[m.nroles++] = 5; + t = answer_text(respond(&m)); + HAS(t, "was not linked to #5: GitHub answered 404 to GET repos/o/r/issues/5: Not Found"); + free(t); + tr_message_free(&m); + /* a pull request, its comment refused: linked all the same, the refusal said */ + comment_status = 403; + m = message(8206, 88, ""); + free(m.content); + m.content = rei_format("<@99> link %ld 77", id); + m.roles[m.nroles++] = 5; + t = answer_text(respond(&m)); + rel = rei_format("Report #%ld is linked to pull request #77 (closed) now, in place of #1234. Its comment that " + "links back to the report was refused: GitHub answered 403 to POST repos/o/r/issues/77/comments: " + "Must have admin rights", + id); + HAS(t, rel); + free(rel); + free(t); + tr_message_free(&m); + comment_status = 201; + CHECK(st_get(tracer.store, id, &rep, NULL, NULL) == 1 && rep.issue == 77); + st_report_free(&rep); + /* the approval opens none for a linked report */ + { + TrReaction r = reaction(88, 33, 8201, "\xe2\x9c\x85"); + r.roles[r.nroles++] = 5; + link_asks = 0; + CHECK(!tr_approved(&tracer, &r) && link_asks == 0); + tr_reaction_free(&r); + } + /* unlinked: none, and unlinked again said so */ + m = message(8207, 88, ""); + free(m.content); + m.content = rei_format("<@99> unlink %ld", id); + m.roles[m.nroles++] = 5; + t = answer_text(respond(&m)); + HAS(t, "is linked to no issue now: it was #77, whose comment that links to the report stays."); + free(t); + tr_message_free(&m); + m = message(8208, 88, "<@99> unlink"); + m.roles[m.nroles++] = 5; + m.reply_to = 8201; + t = answer_text(respond(&m)); + HAS(t, "is linked to no issue."); + free(t); + tr_message_free(&m); + CHECK(st_get(tracer.store, id, &rep, NULL, NULL) == 1 && rep.issue == 0 && !rep.issue_url); + st_report_free(&rep); + /* no report named, none replied to */ + m = message(8209, 88, "<@99> link 1234"); + m.roles[m.nroles++] = 5; + t = answer_text(respond(&m)); + HAS(t, "Which report? `@Tracer link 12 1234` links report 12 to issue 1234"); + free(t); + tr_message_free(&m); + CHECK(tr_forget(&tracer, 8201)); + tracer.issues = NULL; + free(comment_body); + comment_body = NULL; +} + /* ---- the build's age ---- */ static int gql_asks, gql_status = 200; static char *gql_answer, *gql_body; @@ -4577,6 +4752,7 @@ static void every_test(const char* self_path) { test_worker(self_path); test_untraceable(self_path); test_issues(); + test_links(); test_age(); test_archive_download(); test_zip_reports(); From 67dd197fbc421ec5b1aa057bdba53bccbcce4bab Mon Sep 17 00:00:00 2001 From: AO55 Date: Tue, 17 Nov 2026 12:54:21 -0300 Subject: [PATCH 3/6] [tracer] Follow a report's issue, and tell its sender once the fix is out A report's issue was filed and forgotten: nothing on its page said it was fixed, and the player who sent it never heard. Every 10 minutes Tracer asks GitHub how each linked issue or pull request stands, keeps the pull request that fixed it and the first nightly that has its commit, and shows them on the page and in the JSON; with TRACER_NOTIFY=reply or ping (off by default) it replies to the report's message once that nightly is out. Signed-off-by: AO55 --- dist/freebsd/tracer.env.sample | 5 +- docs/SECURITY.md | 2 +- docs/TESTING.md | 9 +- docs/TRACER.md | 23 +++- rei/src/rest.c | 15 +- rei/src/rest.h | 5 +- rei/tests/test_rei.c | 5 + scripts/test-mutants.py | 14 +- tracer/Makefile | 11 +- tracer/src/follow.c | 242 +++++++++++++++++++++++++++++++++ tracer/src/follow.h | 24 ++++ tracer/src/main.c | 39 +++++- tracer/src/report.h | 8 ++ tracer/src/site.c | 40 +++++- tracer/src/store.c | 81 ++++++++++- tracer/src/store.h | 17 ++- tracer/src/tracer.h | 2 +- tracer/tests/test_tracer.c | 202 +++++++++++++++++++++++++++ 18 files changed, 718 insertions(+), 26 deletions(-) create mode 100644 tracer/src/follow.c create mode 100644 tracer/src/follow.h diff --git a/dist/freebsd/tracer.env.sample b/dist/freebsd/tracer.env.sample index b94b057..185d09a 100644 --- a/dist/freebsd/tracer.env.sample +++ b/dist/freebsd/tracer.env.sample @@ -7,10 +7,13 @@ TRACER_URL=https:// # TRACER_TITLES=file the games' names, made here by scripts/make-titles.py --out file (none without it) # TRACER_ISSUES_REPO=OWNER/NAME the repository an administrator's approval (a reaction) files a report into (none # without it: no issue) -# TRACER_ISSUES_TOKEN=... a fine-grained token of that repository alone, Issues read and write +# TRACER_ISSUES_TOKEN=... a fine-grained token of that repository alone: Issues read and write, Pull requests and +# Contents read (the issues followed, their fixes compared with the nightlies) # TRACER_ISSUES_EMOJI=... the approval's emoji (the check mark without it) # TRACER_ISSUES_LABELS=a,b the labels each issue gets (none without it) # TRACER_UPSTREAM_REPO=OWNER/NAME the repository whose main a report's build is compared with, its owner's nightly # the nightlies' (scarletnx/ScarletNX without it; asked with TRACER_ISSUES_TOKEN) # TRACER_MIN_FREE=MiB the site's file system's MiB kept free: a report that would go under it is refused (1024 # without it; 0 for no floor) +# TRACER_NOTIFY=ping once a report's fix is in a nightly, a reply tells its sender: ping pings them, reply does +# not (off without it); needs TRACER_ISSUES_REPO and its token diff --git a/docs/SECURITY.md b/docs/SECURITY.md index 277b16d..e32d345 100644 --- a/docs/SECURITY.md +++ b/docs/SECURITY.md @@ -29,7 +29,7 @@ environment (`GIT_CONFIG_*`), and `push.sh` gives curl the push token from its h | Token | Of | What it may do | |---|---|---| | ReiWimsy's `GITHUB_TOKEN` | GitHub, fine-grained | public repositories, read-only | -| Tracer's `TRACER_ISSUES_TOKEN` | GitHub, fine-grained | the issues' repository alone: Issues, read and write | +| Tracer's `TRACER_ISSUES_TOKEN` | GitHub, fine-grained | the issues' repository alone: Issues, read and write; Pull requests and Contents, read | | AccordWimsy's `GITHUB_TOKEN` | GitHub, fine-grained, of the organization | read-only: Contents, Issues, Pull requests, Metadata | | AccordWimsy's `ACCORDWIMSY_FORGEJO_TOKEN` | the forge, its own user | `write:repository`, `write:issue`, `write:organization`, `read:user` | | ReiWimsy's Discord invite | the server | View Channels, Send Messages, Send Messages in Threads, Embed Links, Read Message History, Manage Messages (its first round deletes the webhooks' cards) | diff --git a/docs/TESTING.md b/docs/TESTING.md index 8e342ac..26d48bb 100644 --- a/docs/TESTING.md +++ b/docs/TESTING.md @@ -84,6 +84,11 @@ temporary folder: - a report linked to an issue that exists (`link`, `unlink`), through a fake GitHub: by an administrator only, in a reply or by number, the comment that links back, a pull request, an issue that is none, a refused comment said, the approval opening none for a linked report; +- the issues followed (`TRACER_NOTIFY` and its refusals), through a fake GitHub: an issue and a pull request open, + then closed by a merged pull request whose commit no nightly has yet and merged with it in one (the sender told + once, pinged, by a reply to the report's message), the next nightly having the first, GitHub failing, a reopened + issue losing its fix, one fixed with no one told asked no more, a report linked to another issue forgetting the + first's; - the issues an approval files, through a fake GitHub: an administrator's reaction files one, a second files none, anyone else's reaction or another emoji nothing, a refusal said and tried again, the settings and their refusals; - how old a report's build is, through a fake GitHub: behind main, the plurals, a commit asked once an hour, `-dirty` @@ -127,8 +132,8 @@ out: 19 mutants, `test_tracer --rules`); what a report keeps of its files, in `f zip's screenshots, a picture never read as a log, the paths outside a home, the limits said with their values, what an issue may hold of the game: 33 mutants, `test_tracer --files`); what a log holds of a run, in `probe.c` (Amberlith's starting note, a name that only begins like it, libc's detail kept, a worker's answer naming another program: 4 mutants, `test_tracer --probe`); and -the worker's locale for a zip's names, made before it shuts itself in, and who links a report to an issue (2 mutants, -the whole suite). A mutant they pass, +the worker's locale for a zip's names, made before it shuts itself in, who links a report to an issue, and when a +report's sender is told its fix is out (4 mutants, the whole suite). A mutant they pass, or one whose text its file no longer has once, fails it. About 30 s. `make -C tracer bench [RUNS=1000] [FOLDER=/tmp/tracer-bench]` (`tracer/tests/bench_probe.c`, built by `make test`, diff --git a/docs/TRACER.md b/docs/TRACER.md index 2662f83..9d2eb69 100644 --- a/docs/TRACER.md +++ b/docs/TRACER.md @@ -14,6 +14,7 @@ * [Summarized and named again](#summarized-and-named-again) * [Commands](#commands) * [Issues](#issues) + * [Followed, and the sender told](#followed-and-the-sender-told) * [How old a build is](#how-old-a-build-is) * [What the runs say together](#what-the-runs-say-together) * [What it keeps of people](#what-it-keeps-of-people) @@ -235,6 +236,25 @@ no issue for, and a comment GitHub refuses, are said with its status and message comment. A report linked to another issue says which it replaced; `@Tracer unlink 12` takes the link out, the comment on GitHub staying. A report with an issue opens no other at an approval. +### Followed, and the sender told + +With `TRACER_ISSUES_TOKEN`, every 10 minutes Tracer asks GitHub (one GraphQL query for 50 issues at a time, from the +bot's own process) how each report's issue or pull request stands, and the report's page and JSON say it +(`issue_state`, `issue_reason`): open, closed and why (`COMPLETED`, `NOT_PLANNED`...), merged. A pull request linked +that merged, or the one whose merge closed the issue as completed (a commit that closed it too), is the report's fix +(`fix_pr`, `fix_commit`); then the newest nightly of `TRACER_UPSTREAM_REPO`'s owner is compared with that commit +(`GET repos//compare/...`), and the first that has it is kept (`fix_nightly`). An +issue reopened loses its fix. + +With `TRACER_NOTIFY=reply` or `ping`, once a report's fix is in a nightly, Tracer replies to the message that sent the +report, once (`ping` pings its author, as a reply does; `reply` does not): + + Report #74: fixed + Fixed by pull request #1479 (abc1234), in nightly 2026-11-10 (def5678). Try it, and send a new log if it still fails. + +A report whose fix is in a nightly, its sender told (or no one, with `TRACER_NOTIFY=off`), is asked no more. A report +linked to another issue starts over. What GitHub refuses is said in the log, and asked again in the next round. + ## How old a build is How old a new report's build is goes into the reply and onto the report's page and its JSON (`build_age`), as it was @@ -335,9 +355,10 @@ fill in; an empty value stops the service): | `TRACER_ASSETS` | `/usr/local/share/tracer` | where `style.css`, `site.js` and `tracer.svg` are | | `TRACER_TITLES` | none: no list | the games' names by title ID, made by `scripts/make-titles.py --out FILE`; without it a game its logs don't name keeps its title ID | | `TRACER_ISSUES_REPO` | none: no issue is filed | `OWNER/NAME`: the repository an approved report becomes an issue of; the start's log line says it, or that it is not set | -| `TRACER_ISSUES_TOKEN` | none: needed with the repository | a fine-grained token of that repository alone, with Issues read and write and nothing else; never in the log | +| `TRACER_ISSUES_TOKEN` | none: needed with the repository | a fine-grained token of that repository alone, with Issues read and write, Pull requests and Contents read (the issues followed, a fix compared with the nightlies) and nothing else; never in the log | | `TRACER_ISSUES_EMOJI` | the check mark (U+2705) | the approval's emoji: its character, or a server emoji's name | | `TRACER_ISSUES_LABELS` | none | `label,label`: the labels each issue gets | +| `TRACER_NOTIFY` | `off` | `reply` or `ping`: a report's sender is told by a reply, which pings them with `ping`, once its fix is in a nightly ([Followed, and the sender told](#followed-and-the-sender-told)); needs `TRACER_ISSUES_REPO`; any other word stops it, naming the value | | `TRACER_MIN_FREE` | `1024` | the MiB the site's file system keeps free: a report whose files would go under it is refused ([above](#deleting-and-the-hourly-limit)); `0` for no floor; a value that is no whole number from 0 to 1048576 stops it, naming the value | | `TRACER_UPSTREAM_REPO` | `scarletnx/ScarletNX` | `OWNER/NAME`: the repository whose main a report's build is compared with, its owner's `nightly` the nightlies'; asked with `TRACER_ISSUES_TOKEN`, not at all without it | diff --git a/rei/src/rest.c b/rei/src/rest.c index f05e158..689ab78 100644 --- a/rei/src/rest.c +++ b/rei/src/rest.c @@ -56,8 +56,9 @@ static void said_wrong(const char* what, const char* path, const RgAnswer* a) { : a->body ? a->body : "nothing"); } -/* the body of a message carrying embed: no pings, a reply to reply_to when not 0; owned */ -static char* message_of(const cJSON* embed, u64 reply_to) { +/* the body of a message carrying embed: a reply to reply_to when not 0, which pings its author when ping is 1, and + no other ping; owned */ +static char* message_of(const cJSON* embed, u64 reply_to, int ping) { cJSON *m = cJSON_CreateObject(), *embeds = cJSON_AddArrayToObject(m, "embeds"), *mentions = cJSON_AddObjectToObject(m, "allowed_mentions"); char* text; @@ -69,7 +70,7 @@ static char* message_of(const cJSON* embed, u64 reply_to) { snprintf(id, sizeof id, "%llu", (unsigned long long)reply_to); cJSON_AddStringToObject(ref, "message_id", id); cJSON_AddBoolToObject(ref, "fail_if_not_exists", 0); - cJSON_AddBoolToObject(mentions, "replied_user", 0); + cJSON_AddBoolToObject(mentions, "replied_user", ping); } text = cJSON_PrintUnformatted(m); cJSON_Delete(m); @@ -105,8 +106,10 @@ cJSON* dc_emojis(Dc* d) { free(path); return items; } -u64 dc_post(Dc* d, u64 channel, const cJSON* embed, u64 reply_to) { - char *path = rei_format("channels/%llu/messages", (unsigned long long)channel), *body = message_of(embed, reply_to); +u64 dc_post(Dc* d, u64 channel, const cJSON* embed, u64 reply_to) { return dc_reply(d, channel, embed, reply_to, 0); } +u64 dc_reply(Dc* d, u64 channel, const cJSON* embed, u64 reply_to, int ping) { + char *path = rei_format("channels/%llu/messages", (unsigned long long)channel), + *body = message_of(embed, reply_to, ping); RgAnswer a = {0}; u64 id = 0; if (ask(d, "POST", path, body, &a) == 200) { @@ -136,7 +139,7 @@ static int done_or_gone(const char* what, const char* path, RgAnswer* a, int sta } int dc_edit(Dc* d, u64 channel, u64 message, const cJSON* embed) { char *path = rei_format("channels/%llu/messages/%llu", (unsigned long long)channel, (unsigned long long)message), - *body = message_of(embed, 0); + *body = message_of(embed, 0, 0); RgAnswer a = {0}; int said = done_or_gone("PATCH", path, &a, ask(d, "PATCH", path, body, &a)); free(body); diff --git a/rei/src/rest.h b/rei/src/rest.h index 1ca629c..930f4f0 100644 --- a/rei/src/rest.h +++ b/rei/src/rest.h @@ -2,7 +2,8 @@ Copyright 2026 the ScarletNX contributors */ /* Discord's REST API for the messages the bot sends, edits and deletes, through a fetch it is given (http.c's, with "Bot ", or the tests'). A 429 waits what Discord says and asks again, DC_TRIES in all; its messages ping no - one. The gateway (the messages it reads) is Concord's, in main.c */ + one, but for a reply dc_reply is told to ping, whose author alone it pings. The gateway (the messages it reads) is + Concord's, in main.c */ #ifndef REI_REST_H #define REI_REST_H #include "github.h" @@ -24,6 +25,8 @@ u64 dc_self(Dc* d); cJSON* dc_emojis(Dc* d); /* embed posted in channel, a reply to message reply_to when not 0: the new message's id, or 0 (said in the log) */ u64 dc_post(Dc* d, u64 channel, const cJSON* embed, u64 reply_to); +/* dc_post's reply, which pings the author of reply_to when ping is 1 (Discord's replied_user), no one else */ +u64 dc_reply(Dc* d, u64 channel, const cJSON* embed, u64 reply_to, int ping); /* 0 done, 404 when the message or its channel is gone, else Discord's status (-1 for no answer), said in the log */ int dc_edit(Dc* d, u64 channel, u64 message, const cJSON* embed); int dc_remove(Dc* d, u64 channel, u64 message); diff --git a/rei/tests/test_rei.c b/rei/tests/test_rei.c index 0c00d0c..3ba02d6 100644 --- a/rei/tests/test_rei.c +++ b/rei/tests/test_rei.c @@ -445,6 +445,11 @@ static void rest_tests(void) { CHECK(dc_post(&d, 7, e, 99) == 1234567890123456789ULL); HAS(posted_body, "\"message_reference\":{\"message_id\":\"99\""); HAS(posted_body, "\"allowed_mentions\":{\"parse\":[],\"replied_user\":false}"); + /* a reply told to ping: its author alone */ + CHECK(dc_reply(&d, 7, e, 98, 1) == 1234567890123456789ULL); + HAS(posted_body, "\"message_reference\":{\"message_id\":\"98\""); + HAS(posted_body, "\"allowed_mentions\":{\"parse\":[],\"replied_user\":true}"); + CHECK(dc_reply(&d, 7, e, 97, 0) && strstr(posted_body, "\"replied_user\":false")); answer("PATCH", DC_API "channels/7/messages/70", 404, "{\"code\":10008}"); CHECK(dc_edit(&d, 7, 70, e) == 404); answer("PATCH", DC_API "channels/7/messages/71", 429, "{\"retry_after\":0.25}"); diff --git a/scripts/test-mutants.py b/scripts/test-mutants.py index e153f23..3939336 100755 --- a/scripts/test-mutants.py +++ b/scripts/test-mutants.py @@ -314,8 +314,20 @@ ) # what only the whole suite holds: the worker, a process of its own shut in its folder (test_worker); who links a -# report to an issue (test_links) +# report to an issue (test_links); when a report's sender is told its fix is out (test_follow) WORKER = ( + ( + "a sender is told before a nightly has the fix", + 'follow.c', + ' if (t->notify != TR_NOTIFY_OFF && now.fix_nightly && !r[i].told) {', + ' if (t->notify != TR_NOTIFY_OFF && now.fix_commit && !r[i].told) {', + ), + ( + "a nightly behind the fix has it", + 'follow.c', + ' has = !strcmp(status, "ahead") || !strcmp(status, "identical");', + ' has = 1;', + ), ( 'anyone links a report to an issue', 'report.c', diff --git a/tracer/Makefile b/tracer/Makefile index e483f66..b0249de 100644 --- a/tracer/Makefile +++ b/tracer/Makefile @@ -35,8 +35,8 @@ OURS = $(WARN) $(DEFS) -Isrc -I$(REI)/src -I$(REI)/third_party/cjson -Ithird_par LIBS = $(SQLITE_LIBS) $(ARCHIVE_LIBS) $(ZLIB_LIBS) $(CXXRT) -lpthread -lm LOGIC = src/message.o src/files.o src/probe.o src/rules.o src/store.o src/site.o src/report.o src/titles.o \ - src/channels.o src/worker.o src/issues.o src/age.o src/mcp.o src/rei_util.o third_party/cjson.o third_party/logscan.o \ - third_party/demangle.o + src/channels.o src/worker.o src/issues.o src/age.o src/follow.o src/mcp.o src/rei_util.o third_party/cjson.o \ + third_party/logscan.o third_party/demangle.o all: tracer tracer-mcp @@ -85,6 +85,9 @@ src/issues.o: src/issues.c src/issues.h src/store.h src/probe.h src/tracer.h $(CC) $(CFLAGS) $(OURS) -c -o $@ src/issues.c src/age.o: src/age.c src/age.h src/store.h src/probe.h src/tracer.h $(CC) $(CFLAGS) $(OURS) -c -o $@ src/age.c +src/follow.o: src/follow.c src/follow.h src/report.h src/age.h src/issues.h src/site.h src/store.h src/probe.h \ + src/message.h src/titles.h src/tracer.h + $(CC) $(CFLAGS) $(OURS) -c -o $@ src/follow.c src/channels.o: src/channels.c src/channels.h src/tracer.h $(CC) $(CFLAGS) $(OURS) -c -o $@ src/channels.c src/titles.o: src/titles.c src/titles.h src/tracer.h @@ -99,8 +102,8 @@ src/mcp_main.o: src/mcp_main.c src/mcp.h src/tracer.h src/fetch.o: src/fetch.c src/fetch.h src/tracer.h $(CC) $(CFLAGS) $(OURS) $(CURL_CFLAGS) -c -o $@ src/fetch.c # Concord's headers are not ours: their warnings are theirs -src/main.o: src/main.c $(LOGSCAN_FILES) src/age.h src/channels.h src/issues.h src/worker.h src/fetch.h src/report.h \ - src/site.h src/store.h src/probe.h src/message.h src/tracer.h $(REI)/src/watch.h +src/main.o: src/main.c $(LOGSCAN_FILES) src/age.h src/channels.h src/follow.h src/issues.h src/worker.h src/fetch.h \ + src/report.h src/site.h src/store.h src/probe.h src/message.h src/tracer.h $(REI)/src/watch.h $(CC) $(CFLAGS) $(OURS) $(CURL_CFLAGS) -isystem $(CONCORD)/include/concord -c -o $@ src/main.c src/rei_util.o: $(REI)/src/util.c $(REI)/src/rei.h $(CC) $(CFLAGS) $(OURS) -c -o $@ $(REI)/src/util.c diff --git a/tracer/src/follow.c b/tracer/src/follow.c new file mode 100644 index 0000000..58fcca9 --- /dev/null +++ b/tracer/src/follow.c @@ -0,0 +1,242 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later + Copyright 2026 the ScarletNX contributors */ +#include "follow.h" +#include +#include +#include + +#include "site.h" + +#define GITHUB_API "https://api.github.com/" +#define GRAPHQL GITHUB_API "graphql" + +int tr_notify_of(const char* value, int issues, TrNotify* notify, char** why) { + *why = NULL; + *notify = TR_NOTIFY_OFF; + if (!value || !*value || !strcmp(value, "off")) return 0; + if (!strcmp(value, "reply")) + *notify = TR_NOTIFY_REPLY; + else if (!strcmp(value, "ping")) + *notify = TR_NOTIFY_PING; + else { + *why = rei_format("TRACER_NOTIFY=%s is none of off, reply and ping", value); + return -1; + } + if (!issues) { + *why = rei_format("TRACER_NOTIFY=%s needs TRACER_ISSUES_REPO: a report's fix is known by its issue", value); + *notify = TR_NOTIFY_OFF; + return -1; + } + return 0; +} + +char* tr_follow_said(const Tracer* t) { + static const char* const how[] = {"no one is told (TRACER_NOTIFY=off)", + "its sender is told by a reply (TRACER_NOTIFY=reply)", + "its sender is told by a reply that pings them (TRACER_NOTIFY=ping)"}; + if (!t->issues || !t->issues->repo) + return rei_strdup("follow: no issue followed, as TRACER_ISSUES_REPO is not set"); + return rei_format("follow: the reports' issues in %s asked of GitHub every %d s; once a report's fix is in a " + "nightly of %s, %s", + t->issues->repo, TR_FOLLOW, t->age ? t->age->owner : "the upstream's owner", how[t->notify]); +} + +/* the query for issues[0..n) of owner/name, and the newest nightly of nightly_owner: an alias i each */ +static char* query_of(const long* issues, int n) { + Buf b = {0}; + int i; + buf_add(&b, "query($owner:String!,$name:String!,$nightly:String!){repository(owner:$owner,name:$name){"); + for (i = 0; i < n; ++i) + buf_printf(&b, + "i%ld:issueOrPullRequest(number:%ld){__typename ...on Issue{state stateReason " + "timelineItems(itemTypes:[CLOSED_EVENT],last:1){nodes{...on ClosedEvent{closer{__typename " + "...on PullRequest{number merged mergeCommit{oid}} ...on Commit{oid}}}}}} ...on PullRequest{state " + "merged mergeCommit{oid}}}", + issues[i], issues[i]); + buf_add(&b, "}nightly:repository(owner:$nightly,name:\"nightly\"){latestRelease{tagName}}}"); + return buf_take(&b); +} + +/* a string's copy, lower-cased, or NULL */ +static char* lower(const char* s) { + char *t = s ? rei_strdup(s) : NULL, *p; + for (p = t; p && *p; ++p) + if (*p >= 'A' && *p <= 'Z') *p = (char)(*p - 'A' + 'a'); + return t; +} +static int same_text(const char* a, const char* b) { return a == b || (a && b && !strcmp(a, b)); } + +/* r's issue as GitHub's node o says it now, into *now (its strings owned): its state and reason, and the fix that a + merged pull request or the pull request whose merge closed the issue as completed is; the nightly kept while the + fix is the same */ +static void state_of(const StReport* r, const cJSON* o, StReport* now) { + const char* kind = jstr(o, "__typename"); + memset(now, 0, sizeof *now); + now->id = r->id; + if (kind && !strcmp(kind, "PullRequest")) { + now->issue_state = lower(jstr(o, "state")); + if (jbool(o, "merged") && jstr(jpath(o, "mergeCommit"), "oid")) { + now->fix_pr = r->issue; + now->fix_commit = rei_strdup(jstr(jpath(o, "mergeCommit"), "oid")); + } + } else if (kind && !strcmp(kind, "Issue")) { + const cJSON* closer = jpath(cJSON_GetArrayItem(jpath(o, "timelineItems.nodes"), + cJSON_GetArraySize(jpath(o, "timelineItems.nodes")) - 1), + "closer"); + const char *closer_kind = jstr(closer, "__typename"), *reason = jstr(o, "stateReason"); + now->issue_state = lower(jstr(o, "state")); + now->issue_reason = reason ? rei_strdup(reason) : NULL; + if (now->issue_state && !strcmp(now->issue_state, "closed") && reason && !strcmp(reason, "COMPLETED")) { + if (closer_kind && !strcmp(closer_kind, "PullRequest") && jbool(closer, "merged") && + jstr(jpath(closer, "mergeCommit"), "oid")) { + now->fix_pr = (long)jnum(closer, "number"); + now->fix_commit = rei_strdup(jstr(jpath(closer, "mergeCommit"), "oid")); + } else if (closer_kind && !strcmp(closer_kind, "Commit") && jstr(closer, "oid")) + now->fix_commit = rei_strdup(jstr(closer, "oid")); + } + } + if (now->fix_commit && same_text(now->fix_commit, r->fix_commit) && r->fix_nightly) + now->fix_nightly = rei_strdup(r->fix_nightly); +} + +/* whether the nightly tagged tag ("nightly--<7 hex>") has commit, GitHub's compare of the two in the upstream + repository: 1, 0, or -1 when GitHub did not say (said) */ +static int nightly_has(const Tracer* t, const char* tag, const char* commit) { + char* url = rei_format(GITHUB_API "repos/%s/compare/%s...%s", t->age->repo, commit, tag + 19); + RgAnswer a; + cJSON* got; + const char* status; + int has = -1; + memset(&a, 0, sizeof a); + t->issues->fetch(t->issues->ctx, "GET", url, NULL, NULL, &a); + got = a.body ? cJSON_Parse(a.body) : NULL; + status = jstr(got, "status"); + if (a.status == 200 && status) + has = !strcmp(status, "ahead") || !strcmp(status, "identical"); + else + rei_log("follow: GitHub answered %d to GET %s: %.200s", a.status, url, + a.error ? a.error + : jstr(got, "message") ? jstr(got, "message") + : "no message"); + cJSON_Delete(got); + free(a.body); + free(a.etag); + free(a.error); + free(url); + return has; +} + +/* r's sender told that its fix is in its nightly, once: 1 when told */ +static int told(Tracer* t, const StReport* r) { + char *title = rei_format("Report #%ld: fixed", r->id), *page = rei_format("%s/r/%ld/", t->url, r->id), + *by = r->fix_pr ? rei_format("pull request #%ld (%.7s)", r->fix_pr, r->fix_commit) + : rei_format("commit %.7s", r->fix_commit), + *text = rei_format("Fixed by %s, in nightly %.10s (%s). Try it, and send a new log if it still fails.", by, + r->fix_nightly + 8, r->fix_nightly + 19); + cJSON* e = cJSON_CreateObject(); + u64 reply; + jset(e, "title", title); + jset(e, "description", text); + jset(e, "url", page); + cJSON_AddNumberToObject(e, "color", 0x22d3ee); + reply = t->tell ? t->tell(t->tell_ctx, r->channel, r->message, e, t->notify == TR_NOTIFY_PING) : 0; + if (reply) { + st_set_told(t->store, r->id, rei_now()); + st_link(t->store, reply, r->id); + rei_log("report #%ld: its sender told it is fixed by %s, in %s", r->id, by, r->fix_nightly); + } else + rei_log("report #%ld: its sender could not be told it is fixed (Discord took no reply): asked again next round", + r->id); + cJSON_Delete(e); + free(text); + free(by); + free(page); + free(title); + return reply != 0; +} + +int tr_follow(Tracer* t) { + StReport* r; + int n, i, from, changed = 0, failed = 0; + if (!t->issues || !t->issues->repo || !t->issues->fetch || !t->age) return 0; + if (st_followed(t->store, t->notify != TR_NOTIFY_OFF, &r, &n)) return -1; + for (from = 0; from < n && !failed; from += TR_FOLLOW_BATCH) { + long issues[TR_FOLLOW_BATCH]; + int k = 0, j; + cJSON *ask = cJSON_CreateObject(), *vars = cJSON_AddObjectToObject(ask, "variables"), *got; + const char* slash = strchr(t->issues->repo, '/'); + char *query, *owner = rei_format("%.*s", (int)(slash - t->issues->repo), t->issues->repo), *body; + const char* tag; + RgAnswer a; + for (i = from; i < n && i < from + TR_FOLLOW_BATCH; ++i) { /* each issue once, though several reports link it */ + for (j = 0; j < k && issues[j] != r[i].issue; ++j) continue; + if (j == k) issues[k++] = r[i].issue; + } + query = query_of(issues, k); + jset(ask, "query", query); + jset(vars, "owner", owner); + jset(vars, "name", slash + 1); + jset(vars, "nightly", t->age->owner); + body = cJSON_PrintUnformatted(ask); + cJSON_Delete(ask); + memset(&a, 0, sizeof a); + t->issues->fetch(t->issues->ctx, "POST", GRAPHQL, body, NULL, &a); + got = a.body ? cJSON_Parse(a.body) : NULL; + if (a.status != 200 || !cJSON_IsObject(jpath(got, "data.repository"))) { + rei_log("follow: GitHub answered %d to the query of %d issues of %s: %.200s", a.status, k, t->issues->repo, + a.error ? a.error + : jstr(cJSON_GetArrayItem(jpath(got, "errors"), 0), "message") + ? jstr(cJSON_GetArrayItem(jpath(got, "errors"), 0), "message") + : a.body ? a.body + : "nothing"); + failed = 1; + } + tag = jstr(jpath(got, "data.nightly.latestRelease"), "tagName"); + if (tag && (strncmp(tag, "nightly-", 8) || strlen(tag) != 26)) tag = NULL; /* nightly--<7 hex> alone */ + for (i = from; !failed && i < n && i < from + TR_FOLLOW_BATCH; ++i) { + char alias[32]; + StReport now; + snprintf(alias, sizeof alias, "i%ld", r[i].issue); + if (!cJSON_IsObject(cJSON_GetObjectItemCaseSensitive(jpath(got, "data.repository"), alias))) { + rei_log("follow: report #%ld's #%ld is not in GitHub's answer for %s", r[i].id, r[i].issue, + t->issues->repo); + continue; + } + state_of(&r[i], cJSON_GetObjectItemCaseSensitive(jpath(got, "data.repository"), alias), &now); + if (now.fix_commit && !now.fix_nightly && tag && nightly_has(t, tag, now.fix_commit) == 1) + now.fix_nightly = rei_strdup(tag); + if (!same_text(now.issue_state, r[i].issue_state) || !same_text(now.issue_reason, r[i].issue_reason) || + now.fix_pr != r[i].fix_pr || !same_text(now.fix_commit, r[i].fix_commit) || + !same_text(now.fix_nightly, r[i].fix_nightly)) { + if (!st_set_followed(t->store, &now)) { + rei_log("report #%ld: #%ld is %s%s%s%s%s", r[i].id, r[i].issue, + now.issue_state ? now.issue_state : "unknown", now.issue_reason ? ", " : "", + now.issue_reason ? now.issue_reason : "", now.fix_nightly ? ", fixed in " : "", + now.fix_nightly ? now.fix_nightly : ""); + site_update(t->store, t->root, r[i].id, r[i].key); + ++changed; + } + } + if (t->notify != TR_NOTIFY_OFF && now.fix_nightly && !r[i].told) { + StReport fixed = r[i]; + fixed.fix_pr = now.fix_pr; + fixed.fix_commit = now.fix_commit; + fixed.fix_nightly = now.fix_nightly; + changed += told(t, &fixed); + } + free(now.issue_state); + free(now.issue_reason); + free(now.fix_commit); + free(now.fix_nightly); + } + cJSON_Delete(got); + free(a.body); + free(a.etag); + free(a.error); + free(body); + free(owner); + free(query); + } + st_reports_free(r, n); + return failed ? -1 : changed; +} diff --git a/tracer/src/follow.h b/tracer/src/follow.h new file mode 100644 index 0000000..5e81b75 --- /dev/null +++ b/tracer/src/follow.h @@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-3.0-or-later + Copyright 2026 the ScarletNX contributors */ +/* The issues and pull requests reports are linked to (by an approval or "link"), followed on GitHub every TR_FOLLOW + seconds from the bot's own process with TRACER_ISSUES_TOKEN: one GraphQL query for TR_FOLLOW_BATCH of them at a time, + with the newest nightly of TRACER_UPSTREAM_REPO's owner. Each report keeps its issue's state (open, closed and why, + merged), the pull request that fixed it (a merged pull request linked, or the one whose merge closed the issue as + completed) and its merge commit, and the first nightly that has that commit (GitHub's compare of the commit and the + nightly's); with TRACER_NOTIFY, a reply to the report's own message says it once that nightly is out */ +#ifndef TR_FOLLOW_H +#define TR_FOLLOW_H +#include "report.h" + +#define TR_FOLLOW 600 /* the seconds between two rounds */ +#define TR_FOLLOW_BATCH 50 /* the issues one query asks for */ + +/* TRACER_NOTIFY's value into *notify: off (none, the default), reply, ping. 0, or -1 with why (owned) for another + value or for reply and ping without an issues' repository (issues true when there is one) */ +int tr_notify_of(const char* value, int issues, TrNotify* notify, char** why); +/* the start's line saying how the issues are followed; owned */ +char* tr_follow_said(const Tracer* t); +/* one round: each followed report's issue asked of GitHub, kept and drawn again where it changed, and its sender told + when its fix is in a nightly (t->notify). The reports changed or told, or -1 when GitHub did not answer (said) */ +int tr_follow(Tracer* t); +#endif diff --git a/tracer/src/main.c b/tracer/src/main.c index e618880..d4dd78c 100644 --- a/tracer/src/main.c +++ b/tracer/src/main.c @@ -30,6 +30,7 @@ sends the text and the attachments of a message that mentions it */ #include "age.h" #include "channels.h" #include "fetch.h" +#include "follow.h" #include "issues.h" #include "http.h" #include "report.h" @@ -45,6 +46,7 @@ sends the text and the attachments of a message that mentions it */ static struct { const char *token, *url, *db, *site, *assets, *titles; double min_free; /* bytes */ + TrNotify notify; u64 channels[LISTED], admins[LISTED]; int nchannels, nadmins; } env; @@ -105,7 +107,7 @@ static void read_env(void) { known |= !strncmp(*e, KNOWN[k], strlen(KNOWN[k])) && (*e)[strlen(KNOWN[k])] == '='; if (!known) stop("%s: no such setting (TRACER_TOKEN, _URL, _CHANNELS, _ADMINS, _DB, _SITE, _ASSETS, _TITLES, " - "_ISSUES_REPO, _ISSUES_TOKEN, _ISSUES_EMOJI, _ISSUES_LABELS, _UPSTREAM_REPO, _MIN_FREE)", + "_ISSUES_REPO, _ISSUES_TOKEN, _ISSUES_EMOJI, _ISSUES_LABELS, _UPSTREAM_REPO, _MIN_FREE, _NOTIFY)", *e); } env.token = setting("TRACER_TOKEN", NULL); @@ -144,6 +146,8 @@ static void read_env(void) { issues.ctx = &github_auth; /* a build's age: asked with the same token, once a commit */ if (tr_age_settings(&age, environment, &why)) stop("%s", why); + /* a report's sender told its fix is out */ + if (tr_notify_of(getenv("TRACER_NOTIFY"), issues.repo != NULL, &env.notify, &why)) stop("%s", why); age.fetch = token ? rh_fetch : NULL; age.ctx = &github_auth; } @@ -151,7 +155,7 @@ static void read_env(void) { /* ---- the events waiting for the thread ---- */ -enum { EV_CREATE, EV_DELETE, EV_REACTION }; +enum { EV_CREATE, EV_DELETE, EV_REACTION, EV_FOLLOW }; static struct { int kind[WAITING]; char* json[WAITING]; /* owned: a MESSAGE_CREATE's or MESSAGE_REACTION_ADD's data, or NULL with id for a deletion */ @@ -318,13 +322,31 @@ static void* handle(void* unused) { cJSON_Delete(e); tr_reaction_free(&r); } - } else + } else if (kind == EV_FOLLOW) + tr_follow(&tracer); + else tr_forget(&tracer, id); free(json); } return NULL; } +/* a round of the issues' following (follow.h) every TR_FOLLOW seconds, on the thread of the events, which alone holds + the database */ +static void* follow_rounds(void* unused) { + (void)unused; + for (;;) { + sleep(TR_FOLLOW); + push(EV_FOLLOW, NULL, 0, 0); + } + return NULL; +} +/* a reply that tells a report's sender its fix is out */ +static u64 tell(void* ctx, u64 channel, u64 message, const cJSON* embed, int ping) { + (void)ctx; + return dc_reply(&dc, channel, embed, message, ping); +} + /* ---- the gateway ---- */ static void ready(const char* json, size_t size) { @@ -342,6 +364,11 @@ static void ready(const char* json, size_t size) { int code = pthread_create(&thread, NULL, handle, NULL); if (code) stop("the thread of the reports did not start: %s", strerror(code)); pthread_detach(thread); + if (issues.repo && age.fetch) { /* the issues followed: with their repository and the token */ + if ((code = pthread_create(&thread, NULL, follow_rounds, NULL))) + stop("the thread of the issues' rounds did not start: %s", strerror(code)); + pthread_detach(thread); + } started = 1; } } @@ -435,6 +462,8 @@ int main(int argc, char** argv) { tracer.message = message_got; tracer.content_intent = content_intent; tracer.min_free = env.min_free; + tracer.notify = env.notify; + tracer.tell = tell; { /* the disk the reports land on, said once */ char* why; double now = tr_free_bytes(env.site, &why); @@ -468,6 +497,10 @@ int main(int argc, char** argv) { said = tr_age_said(&age); rei_log("%s", said); free(said); + said = age.fetch || !issues.repo ? tr_follow_said(&tracer) + : rei_strdup("follow: no issue followed, as TRACER_ISSUES_TOKEN is not set"); + rei_log("%s", said); + free(said); } rei_log("workers: %s --report reads each report's files, without the settings, the tokens and this process's " "memory", diff --git a/tracer/src/report.h b/tracer/src/report.h index 108d8e8..c2766e9 100644 --- a/tracer/src/report.h +++ b/tracer/src/report.h @@ -27,6 +27,9 @@ typedef struct { char* probe_why; /* owned: why a first log with lines of edenprobe holds no run of it, NULL for none */ } Taken; +/* how a report's sender is told its fix is in a nightly (follow.h): not at all, a reply, a reply that pings them */ +typedef enum { TR_NOTIFY_OFF, TR_NOTIFY_REPLY, TR_NOTIFY_PING } TrNotify; + typedef struct Tracer Tracer; struct Tracer { Store* store; @@ -62,6 +65,11 @@ struct Tracer { /* the bytes free on the file system of path (statvfs's for an unprivileged user), -1 with why (owned) when it cannot be read; NULL for tr_free_bytes */ double (*free_bytes)(const char* path, char** why); + TrNotify notify; /* TRACER_NOTIFY's */ + /* embed posted as a reply to message of channel, which pings its author when ping is 1: the reply's id, 0 when + Discord took none (said in the log); NULL for no Discord */ + u64 (*tell)(void* ctx, u64 channel, u64 message, const cJSON* embed, int ping); + void* tell_ctx; }; /* the bytes free on the file system of path for an unprivileged user (statvfs), or -1 with why (owned) */ diff --git a/tracer/src/site.c b/tracer/src/site.c index 27753e2..89ab9d1 100644 --- a/tracer/src/site.c +++ b/tracer/src/site.c @@ -637,7 +637,40 @@ char* site_report_html(const StReport* r, const StFile* files, int nfiles, const if (r->issue > 0 && r->issue_url && !strncmp(r->issue_url, "https://github.com/", 19)) { buf_add(&b, "
Issue
issue_url); - buf_printf(&b, "\">#%ld
\n", r->issue); + buf_printf(&b, "\">#%ld", r->issue); + if (r->issue_state) { /* as GitHub said it last (follow.h) */ + buf_add(&b, " "); + esc(&b, r->issue_state); + if (r->issue_reason) { + buf_add(&b, " ("); + esc(&b, r->issue_reason); + buf_add(&b, ")"); + } + } + if (r->fix_commit && hex(r->fix_commit)) { /* in the issue's repository: https://github.com/OWNER/NAME */ + const char* at = r->issue_url + 19; + int base = 19, slashes = 0; + char* repo; + for (; *at && slashes < 2; ++at, ++base) slashes += *at == '/'; + if (slashes == 2) --base; + repo = rei_format("%.*s", base, r->issue_url); + buf_add(&b, "
fixed by "); + if (r->fix_pr) { + buf_add(&b, "pull request #%ld, ", r->fix_pr, r->fix_pr); + } + buf_add(&b, "%.7s", r->fix_commit, r->fix_commit); + free(repo); + if (r->fix_nightly) { + buf_add(&b, ", in "); + esc(&b, r->fix_nightly); + } else + buf_add(&b, ", in no nightly yet"); + } + buf_add(&b, "\n"); } buf_add(&b, "\n"); if (probe) probe_section(&b, probe); @@ -713,6 +746,11 @@ static cJSON* report_object(const StReport* r) { if (r->issue > 0 && r->issue_url) { cJSON_AddNumberToObject(o, "issue", (double)r->issue); jset(o, "issue_url", r->issue_url); + jset(o, "issue_state", r->issue_state); + jset(o, "issue_reason", r->issue_reason); + if (r->fix_pr) cJSON_AddNumberToObject(o, "fix_pr", (double)r->fix_pr); + jset(o, "fix_commit", r->fix_commit); + jset(o, "fix_nightly", r->fix_nightly); } return o; } diff --git a/tracer/src/store.c b/tracer/src/store.c index ba0db02..5739a46 100644 --- a/tracer/src/store.c +++ b/tracer/src/store.c @@ -70,12 +70,21 @@ static const char* const UPGRADES[] = { "CREATE INDEX probe_cases_name ON probe_cases(name, report, result);", /* 9, the program a run's starting note names: Amberlith, or edenprobe, the name before its 1.0.0 (NULL: a run kept before this, all edenprobe's) */ - "ALTER TABLE probe_runs ADD COLUMN program TEXT;"}; + "ALTER TABLE probe_runs ADD COLUMN program TEXT;", + /* 10, each report's issue as GitHub said it last, the pull request and nightly that fixed it, and when its sender + was told */ + "ALTER TABLE reports ADD COLUMN issue_state TEXT;" + "ALTER TABLE reports ADD COLUMN issue_reason TEXT;" + "ALTER TABLE reports ADD COLUMN fix_pr INTEGER NOT NULL DEFAULT 0;" + "ALTER TABLE reports ADD COLUMN fix_commit TEXT;" + "ALTER TABLE reports ADD COLUMN fix_nightly TEXT;" + "ALTER TABLE reports ADD COLUMN told REAL NOT NULL DEFAULT 0;"}; /* a report's columns, in the order row_report reads them */ #define REPORT_COLUMNS \ "id, created, guild, channel, message, poster, game, title, named, title_id, note, version, build, commit_id, " \ - "branch, system, gpu, driver, outcome, signature, missed, console, issue, issue_url, age" + "branch, system, gpu, driver, outcome, signature, missed, console, issue, issue_url, age, issue_state, " \ + "issue_reason, fix_pr, fix_commit, fix_nightly, told" static void said(Store* s, const char* what) { rei_log("the database, %s: %s", what, sqlite3_errmsg(s->db)); } @@ -457,7 +466,9 @@ int st_claim_issue(Store* s, long report) { } int st_set_issue(Store* s, long report, long number, const char* url) { - sqlite3_stmt* q = prepared(s, "UPDATE reports SET issue = ?, issue_url = ? WHERE id = ?"); + sqlite3_stmt* q = + prepared(s, "UPDATE reports SET issue = ?, issue_url = ?, issue_state = NULL, issue_reason = NULL," + " fix_pr = 0, fix_commit = NULL, fix_nightly = NULL, told = 0 WHERE id = ?"); int ok; if (!q) return -1; sqlite3_bind_int64(q, 1, number); @@ -469,6 +480,60 @@ int st_set_issue(Store* s, long report, long number, const char* url) { return ok ? 0 : -1; } +int st_set_followed(Store* s, const StReport* r) { + sqlite3_stmt* q = prepared(s, "UPDATE reports SET issue_state = ?, issue_reason = ?, fix_pr = ?, fix_commit = ?," + " fix_nightly = ? WHERE id = ?"); + int ok; + if (!q) return -1; + text_at(q, 1, r->issue_state); + text_at(q, 2, r->issue_reason); + sqlite3_bind_int64(q, 3, r->fix_pr); + text_at(q, 4, r->fix_commit); + text_at(q, 5, r->fix_nightly); + sqlite3_bind_int64(q, 6, r->id); + ok = sqlite3_step(q) == SQLITE_DONE; + if (!ok) said(s, "an issue's state kept"); + sqlite3_finalize(q); + return ok ? 0 : -1; +} + +int st_set_told(Store* s, long report, double when) { + sqlite3_stmt* q = prepared(s, "UPDATE reports SET told = ? WHERE id = ?"); + int ok; + if (!q) return -1; + sqlite3_bind_double(q, 1, when); + sqlite3_bind_int64(q, 2, report); + ok = sqlite3_step(q) == SQLITE_DONE; + if (!ok) said(s, "a sender told kept"); + sqlite3_finalize(q); + return ok ? 0 : -1; +} + +static void row_report(sqlite3_stmt* q, StReport* r); +int st_followed(Store* s, int telling, StReport** reports, int* n) { + sqlite3_stmt* q = prepared(s, "SELECT " REPORT_COLUMNS " FROM reports WHERE issue > 0 AND NOT (fix_nightly IS NOT" + " NULL AND (told > 0 OR ? = 0)) ORDER BY id"); + int cap = 0; + *reports = NULL; + *n = 0; + if (!q) return -1; + sqlite3_bind_int(q, 1, telling); + while (sqlite3_step(q) == SQLITE_ROW) { + if (*n == cap) { + cap = cap ? cap * 2 : 16; + *reports = realloc(*reports, (size_t)cap * sizeof **reports); + if (!*reports) { + fputs(REI_NAME ": out of memory\n", stderr); + abort(); + } + } + memset(&(*reports)[*n], 0, sizeof **reports); + row_report(q, &(*reports)[(*n)++]); + } + sqlite3_finalize(q); + return 0; +} + int st_set_bytes(Store* s, long report, int n, double bytes) { sqlite3_stmt* q = prepared(s, "UPDATE files SET bytes = ? WHERE report = ? AND n = ?"); int ok; @@ -578,6 +643,12 @@ static void row_report(sqlite3_stmt* q, StReport* r) { r->issue = (long)sqlite3_column_int64(q, 22); r->issue_url = text_of(q, 23); r->age = text_of(q, 24); + r->issue_state = text_of(q, 25); + r->issue_reason = text_of(q, 26); + r->fix_pr = (long)sqlite3_column_int64(q, 27); + r->fix_commit = text_of(q, 28); + r->fix_nightly = text_of(q, 29); + r->told = sqlite3_column_double(q, 30); } int st_get(Store* s, long id, StReport* r, StFile** files, int* nfiles) { @@ -701,6 +772,10 @@ void st_report_free(StReport* r) { free(r->console); free(r->issue_url); free(r->age); + free(r->issue_state); + free(r->issue_reason); + free(r->fix_commit); + free(r->fix_nightly); memset(r, 0, sizeof *r); } diff --git a/tracer/src/store.h b/tracer/src/store.h index bca2035..ba21e3e 100644 --- a/tracer/src/store.h +++ b/tracer/src/store.h @@ -25,6 +25,13 @@ typedef struct { char* issue_url; /* owned: that issue's page, NULL for none */ char* age; /* owned: how far its build was behind main when it came, or that it is not a published one (age.h's line), NULL for none */ + /* its issue as GitHub said it last (follow.h), NULL each before it was asked: */ + char* issue_state; /* owned: "open", "closed", or "merged" for a pull request */ + char* issue_reason; /* owned: why an issue closed, as GitHub says it ("COMPLETED", "NOT_PLANNED"), NULL for none */ + long fix_pr; /* the pull request that fixed it (the issue's closer, or the pull request itself), 0 for none */ + char* fix_commit; /* owned: that pull request's merge commit, NULL for none */ + char* fix_nightly; /* owned: the first nightly's tag that has it, NULL before one does */ + double told; /* when the one who sent it was told it is fixed, 0 for not */ } StReport; /* what GitHub said of a commit (age.h), kept by the commit */ @@ -94,8 +101,16 @@ int st_set_bytes(Store* s, long report, int n, double bytes); /* report's issue taken for one being opened (issue -1): 1 when it was, 0 when the report has one or one is being opened already, -1 for an error */ int st_claim_issue(Store* s, long report); -/* report's issue: its number and page, or (number 0, url NULL) none again after a failure. 0, or -1 */ +/* report's issue: its number and page, or (number 0, url NULL) none again after a failure; what was followed of the + one before forgotten. 0, or -1 */ int st_set_issue(Store* s, long report, long number, const char* url); +/* report's issue as GitHub says it now (r's issue_state, issue_reason, fix_pr, fix_commit and fix_nightly): 0, or -1 */ +int st_set_followed(Store* s, const StReport* r); +/* when report's sender was told it is fixed: 0, or -1 */ +int st_set_told(Store* s, long report, double when); +/* the reports with an issue, but those whose fix is in a nightly already and whose sender was told (or is not, as + telling is 0), the oldest first; *n of them, owned (st_reports_free) */ +int st_followed(Store* s, int telling, StReport** reports, int* n); int st_set_facts(Store* s, const StReport* r); /* report id's game named again, as a later log names it: 0, or -1 */ int st_set_game(Store* s, long id, const char* key, const char* title, const char* title_id, int named); diff --git a/tracer/src/tracer.h b/tracer/src/tracer.h index a779470..e224f13 100644 --- a/tracer/src/tracer.h +++ b/tracer/src/tracer.h @@ -20,7 +20,7 @@ #define TR_KEYS \ "TRACER_TOKEN", "TRACER_URL", "TRACER_CHANNELS", "TRACER_ADMINS", "TRACER_DB", "TRACER_SITE", "TRACER_ASSETS", \ "TRACER_TITLES", "TRACER_ISSUES_REPO", "TRACER_ISSUES_TOKEN", "TRACER_ISSUES_EMOJI", "TRACER_ISSUES_LABELS", \ - "TRACER_UPSTREAM_REPO", "TRACER_MIN_FREE" + "TRACER_UPSTREAM_REPO", "TRACER_MIN_FREE", "TRACER_NOTIFY" #define TR_MIN_FREE 1024 /* the MiB the site's file system keeps free when TRACER_MIN_FREE does not say */ /* a download: url's body into out (cleared first), max bytes at most. 0, or -1 with why (owned) */ diff --git a/tracer/tests/test_tracer.c b/tracer/tests/test_tracer.c index b29dfec..248491d 100644 --- a/tracer/tests/test_tracer.c +++ b/tracer/tests/test_tracer.c @@ -33,6 +33,7 @@ #include "channels.h" #include "age.h" #include "files.h" +#include "follow.h" #include "issues.h" #include "mcp.h" #include "message.h" @@ -3103,6 +3104,206 @@ static void test_links(void) { comment_body = NULL; } +/* ---- the issues followed ---- */ +static char* follow_answer; /* GraphQL's answer, whole */ +static int follow_status = 200, follow_asks; +static char follow_query[8192]; +static const char* compare_of[4][2]; /* a commit's first letters, and the compare's status for it */ +static void fake_follow(void* ctx, const char* method, const char* url, const char* body, const char* etag, + RgAnswer* out) { + int i; + (void)ctx; + (void)etag; + memset(out, 0, sizeof *out); + ++follow_asks; + if (!strcmp(method, "POST") && !strcmp(url, "https://api.github.com/graphql")) { + snprintf(follow_query, sizeof follow_query, "%s", body ? body : ""); + out->status = follow_status; + out->body = rei_strdup(follow_status == 200 ? follow_answer : "{\"message\":\"Server Error\"}"); + return; + } + for (i = 0; i < 4 && compare_of[i][0]; ++i) + if (strstr(url, "/compare/") && strstr(url, compare_of[i][0])) { + out->status = 200; + out->body = rei_format("{\"status\":\"%s\"}", compare_of[i][1]); + return; + } + out->status = 404; + out->body = rei_strdup("{\"message\":\"Not Found\"}"); +} +static int tells, told_ping; +static char told_text[1024]; +static u64 told_to; +static u64 fake_tell(void* ctx, u64 channel, u64 message, const cJSON* embed, int ping) { + (void)ctx; + (void)channel; + ++tells; + told_ping = ping; + told_to = message; + snprintf(told_text, sizeof told_text, "%s %s", jstr(embed, "title"), jstr(embed, "description")); + return 990000 + (u64)tells; +} +/* GraphQL's answer: issue 1234's node, pull request 77's, and the newest nightly's tag */ +static void follow_says(const char* issue, const char* pull, const char* tag) { + free(follow_answer); + follow_answer = rei_format("{\"data\":{\"repository\":{\"i1234\":%s,\"i77\":%s},\"nightly\":{\"latestRelease\":{" + "\"tagName\":\"%s\"}}}}", + issue, pull, tag); +} +#define FIX_A "f00d000000000000000000000000000000000000" +#define FIX_B "beef000000000000000000000000000000000000" +static void test_follow(void) { + TrIssues is; + TrAge a; + TrNotify n; + StReport r; + TrMessage m; + char *why, *p, *rel; + long first, second; + /* the setting */ + CHECK(!tr_notify_of(NULL, 0, &n, &why) && n == TR_NOTIFY_OFF); + CHECK(!tr_notify_of("ping", 1, &n, &why) && n == TR_NOTIFY_PING); + CHECK(!tr_notify_of("reply", 1, &n, &why) && n == TR_NOTIFY_REPLY); + CHECK(tr_notify_of("loud", 1, &n, &why) == -1); + SAME(why, "TRACER_NOTIFY=loud is none of off, reply and ping"); + free(why); + CHECK(tr_notify_of("ping", 0, &n, &why) == -1); + SAME(why, "TRACER_NOTIFY=ping needs TRACER_ISSUES_REPO: a report's fix is known by its issue"); + free(why); + /* two reports: one linked to issue 1234, the other to pull request 77 */ + memset(&is, 0, sizeof is); + is.repo = "o/r"; + is.emoji = "\xe2\x9c\x85"; + is.fetch = fake_follow; + memset(&a, 0, sizeof a); + snprintf(a.repo, sizeof a.repo, "o/r"); + snprintf(a.owner, sizeof a.owner, "o"); + snprintf(a.name, sizeof a.name, "r"); + tracer.issues = &is; + tracer.age = &a; + tracer.notify = TR_NOTIFY_PING; + tracer.tell = fake_tell; + m = message(8300, 160, "<@99> first"); + attach(&m, "game.log", "https://cdn.discordapp.com/1/game.log", 10); + free(answer_text(respond(&m))); + tr_message_free(&m); + m = message(8301, 161, "<@99> second"); + attach(&m, "game.log", "https://cdn.discordapp.com/1/game.log", 10); + free(answer_text(respond(&m))); + tr_message_free(&m); + first = st_by_message(tracer.store, 8300); + second = st_by_message(tracer.store, 8301); + CHECK(!st_set_issue(tracer.store, first, 1234, "https://github.com/o/r/issues/1234")); + CHECK(!st_set_issue(tracer.store, second, 77, "https://github.com/o/r/pull/77")); + /* both open: kept, nobody told */ + follow_says("{\"__typename\":\"Issue\",\"state\":\"OPEN\",\"stateReason\":null,\"timelineItems\":{\"nodes\":[]}}", + "{\"__typename\":\"PullRequest\",\"state\":\"OPEN\",\"merged\":false,\"mergeCommit\":null}", + "nightly-2026-11-17-aaaaaaa"); + tells = 0; + CHECK(tr_follow(&tracer) == 2 && tells == 0); + CHECK(strstr(follow_query, "i1234:issueOrPullRequest(number:1234)") != NULL); + CHECK(strstr(follow_query, "i77:issueOrPullRequest(number:77)") != NULL); + CHECK(strstr(follow_query, "\"nightly\":\"o\"") != NULL); + CHECK(st_get(tracer.store, first, &r, NULL, NULL) == 1); + SAME(r.issue_state, "open"); + CHECK(!r.fix_commit && !r.told); + st_report_free(&r); + CHECK(tr_follow(&tracer) == 0); /* nothing changed: nothing drawn again */ + /* the issue closed by a pull request whose commit no nightly has yet; the pull request merged, in the nightly: its + sender told, pinged, once */ + follow_says("{\"__typename\":\"Issue\",\"state\":\"CLOSED\",\"stateReason\":\"COMPLETED\",\"timelineItems\":{" + "\"nodes\":[{\"closer\":{\"__typename\":\"PullRequest\",\"number\":1479,\"merged\":true," + "\"mergeCommit\":{\"oid\":\"" FIX_A "\"}}}]}}", + "{\"__typename\":\"PullRequest\",\"state\":\"MERGED\",\"merged\":true,\"mergeCommit\":{\"oid\":\"" FIX_B + "\"}}", + "nightly-2026-11-17-aaaaaaa"); + compare_of[0][0] = "f00d0000"; + compare_of[0][1] = "behind"; + compare_of[1][0] = "beef0000"; + compare_of[1][1] = "ahead"; + compare_of[2][0] = NULL; + CHECK(tr_follow(&tracer) == 3 && tells == 1 && told_ping == 1 && told_to == 8301); + rel = rei_format("Report #%ld: fixed Fixed by pull request #77 (beef000), in nightly 2026-11-17 (aaaaaaa). Try " + "it, and send a new log if it still fails.", + second); + SAME(told_text, rel); + free(rel); + CHECK(st_get(tracer.store, first, &r, NULL, NULL) == 1); + SAME(r.issue_state, "closed"); + SAME(r.issue_reason, "COMPLETED"); + SAME(r.fix_commit, FIX_A); + CHECK(r.fix_pr == 1479 && !r.fix_nightly && !r.told); + st_report_free(&r); + CHECK(st_get(tracer.store, second, &r, NULL, NULL) == 1); + SAME(r.issue_state, "merged"); + SAME(r.fix_nightly, "nightly-2026-11-17-aaaaaaa"); + CHECK(r.fix_pr == 77 && r.told > 0); + st_report_free(&r); + CHECK(st_report_of(tracer.store, 990001) == second); /* the reply leads to the report too */ + rel = rei_format("r/%ld/index.html", first); + p = page(rel); + HAS(p, + ">#1234 closed (COMPLETED)
fixed by pull request #1479, " + "f00d000, in no nightly yet"); + free(p); + free(rel); + rel = rei_format("api/r/%ld.json", second); + p = page(rel); + HAS(p, "\"issue_state\":\"merged\""); + HAS(p, "\"fix_pr\":77"); + HAS(p, "\"fix_nightly\":\"nightly-2026-11-17-aaaaaaa\""); + free(p); + free(rel); + /* the next nightly has the first fix: its sender told, the second not again */ + follow_says("{\"__typename\":\"Issue\",\"state\":\"CLOSED\",\"stateReason\":\"COMPLETED\",\"timelineItems\":{" + "\"nodes\":[{\"closer\":{\"__typename\":\"PullRequest\",\"number\":1479,\"merged\":true," + "\"mergeCommit\":{\"oid\":\"" FIX_A "\"}}}]}}", + "{\"__typename\":\"PullRequest\",\"state\":\"MERGED\",\"merged\":true,\"mergeCommit\":{\"oid\":\"" FIX_B + "\"}}", + "nightly-2026-11-18-bbbbbbb"); + compare_of[0][1] = "identical"; + CHECK(tr_follow(&tracer) == 2 && tells == 2 && told_to == 8300); + CHECK(strstr(follow_query, "i1234:") != NULL); + CHECK(!strstr(follow_query, "i77:")); /* fixed in a nightly and told: no longer asked */ + CHECK(strstr(told_text, "Fixed by pull request #1479 (f00d000), in nightly 2026-11-18 (bbbbbbb)") != NULL); + CHECK(tr_follow(&tracer) == 0 && tells == 2); + /* GitHub failing: said, nothing changed */ + follow_status = 502; + st_set_told(tracer.store, first, 0); + CHECK(tr_follow(&tracer) == -1 && tells == 2); + follow_status = 200; + /* a report linked to another issue forgets what was followed of the first */ + tracer.notify = TR_NOTIFY_OFF; + CHECK(!st_set_issue(tracer.store, second, 1234, "https://github.com/o/r/issues/1234")); + CHECK(st_get(tracer.store, second, &r, NULL, NULL) == 1 && !r.issue_state && !r.fix_nightly && !r.told); + st_report_free(&r); + /* reopened: no fix; the first report, fixed in a nightly, is no longer asked */ + follow_says("{\"__typename\":\"Issue\",\"state\":\"OPEN\",\"stateReason\":\"REOPENED\",\"timelineItems\":{" + "\"nodes\":[]}}", + "null", "nightly-2026-11-18-bbbbbbb"); + CHECK(tr_follow(&tracer) == 1 && tells == 2); + CHECK(st_get(tracer.store, second, &r, NULL, NULL) == 1); + SAME(r.issue_state, "open"); + SAME(r.issue_reason, "REOPENED"); + CHECK(!r.fix_commit && !r.fix_nightly && !r.fix_pr); + st_report_free(&r); + /* fixed again, in a nightly, with no one told (TRACER_NOTIFY=off): kept, and asked no more */ + follow_says("{\"__typename\":\"Issue\",\"state\":\"CLOSED\",\"stateReason\":\"COMPLETED\",\"timelineItems\":{" + "\"nodes\":[{\"closer\":{\"__typename\":\"Commit\",\"oid\":\"" FIX_A "\"}}]}}", + "null", "nightly-2026-11-18-bbbbbbb"); + CHECK(tr_follow(&tracer) == 1 && tells == 2); + CHECK(st_get(tracer.store, second, &r, NULL, NULL) == 1 && !r.fix_pr && r.fix_nightly && !r.told); + st_report_free(&r); + follow_asks = 0; + CHECK(tr_follow(&tracer) == 0 && follow_asks == 0); + CHECK(tr_forget(&tracer, 8300) && tr_forget(&tracer, 8301)); + tracer.issues = NULL; + tracer.age = NULL; + tracer.tell = NULL; + free(follow_answer); + follow_answer = NULL; +} + /* ---- the build's age ---- */ static int gql_asks, gql_status = 200; static char *gql_answer, *gql_body; @@ -4753,6 +4954,7 @@ static void every_test(const char* self_path) { test_untraceable(self_path); test_issues(); test_links(); + test_follow(); test_age(); test_archive_download(); test_zip_reports(); From 0dcde6b72b76e95f09b3f66d4de3b109f812268f Mon Sep 17 00:00:00 2001 From: AO55 Date: Tue, 17 Nov 2026 12:57:21 -0300 Subject: [PATCH 4/6] [tracer] Name the reports of the same failure, and link an approval to their issue Twenty-one reports of the live site repeat a game's failure another report has, and nothing said so, nor kept an approval from opening one issue each. A new report's reply, its page and its JSON name the newest five reports with its signature and their issues; an approval of a report whose game and signature a linked report has links it to that issue, with a comment, and opens none. Signed-off-by: AO55 --- docs/TESTING.md | 4 +- docs/TRACER.md | 8 +++- scripts/test-mutants.py | 9 +++- tracer/src/report.c | 69 +++++++++++++++++++++++++++++ tracer/src/site.c | 27 ++++++++++-- tracer/src/site.h | 2 + tracer/src/store.c | 22 +++++++++- tracer/src/store.h | 7 +++ tracer/src/tracer.h | 1 + tracer/tests/test_tracer.c | 89 ++++++++++++++++++++++++++++++++++++++ 10 files changed, 231 insertions(+), 7 deletions(-) diff --git a/docs/TESTING.md b/docs/TESTING.md index 26d48bb..c1e6c27 100644 --- a/docs/TESTING.md +++ b/docs/TESTING.md @@ -89,6 +89,8 @@ temporary folder: once, pinged, by a reply to the report's message), the next nightly having the first, GitHub failing, a reopened issue losing its fix, one fixed with no one told asked no more, a report linked to another issue forgetting the first's; +- two reports of one failure: each named in the other's reply, page and JSON, the second's approval linking it to the + first's issue with a comment and opening none, the first gone from the second's page with its message; - the issues an approval files, through a fake GitHub: an administrator's reaction files one, a second files none, anyone else's reaction or another emoji nothing, a refusal said and tried again, the settings and their refusals; - how old a report's build is, through a fake GitHub: behind main, the plurals, a commit asked once an hour, `-dirty` @@ -133,7 +135,7 @@ zip's screenshots, a picture never read as a log, the paths outside a home, the an issue may hold of the game: 33 mutants, `test_tracer --files`); what a log holds of a run, in `probe.c` (Amberlith's starting note, a name that only begins like it, libc's detail kept, a worker's answer naming another program: 4 mutants, `test_tracer --probe`); and the worker's locale for a zip's names, made before it shuts itself in, who links a report to an issue, and when a -report's sender is told its fix is out (4 mutants, the whole suite). A mutant they pass, +report's sender is told its fix is out, and an approval of a failure an issue has (5 mutants, the whole suite). A mutant they pass, or one whose text its file no longer has once, fails it. About 30 s. `make -C tracer bench [RUNS=1000] [FOLDER=/tmp/tracer-bench]` (`tracer/tests/bench_probe.c`, built by `make test`, diff --git a/docs/TRACER.md b/docs/TRACER.md index 9d2eb69..8caf1e1 100644 --- a/docs/TRACER.md +++ b/docs/TRACER.md @@ -236,6 +236,12 @@ no issue for, and a comment GitHub refuses, are said with its status and message comment. A report linked to another issue says which it replaced; `@Tracer unlink 12` takes the link out, the comment on GitHub staying. A report with an issue opens no other at an approval. +A new report whose first log failed with a signature other reports have (the log summary's: where and how the run +ended) names the newest five in its reply (`Same failure: #40 (issue #1234), #52`), on its page and in its JSON +(`same_failure`), whatever their game; their pages name it too. An approval of a report whose game and signature a +report linked to an issue has links it to that issue, with a comment on it that says so, and opens none: `Report #61 +has the failure of report #40, which is issue #1234: linked to it, and no other issue opened.` + ### Followed, and the sender told With `TRACER_ISSUES_TOKEN`, every 10 minutes Tracer asks GitHub (one GraphQL query for 50 issues at a time, from the @@ -325,7 +331,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/.html` | a game's reports: `` its title ID, or `n-` and its name's letters for a game known by name | -| `r//` | a report: its facts, its screenshots (each shown small, and opened whole by a click), 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`); a run of edenprobe's has its counts and each case that did not pass | +| `r//` | a report: its facts (its issue as GitHub said it last, and its fix; the other reports of its failure), its screenshots (each shown small, and opened whole by a click), 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`); a run of edenprobe's has its counts and each case that did not pass | | `probe/index.html` | the runs of Amberlith: the machines (an emulator, a driver and its version, a system), each case that fails somewhere with its results on each machine, each suite's, and each run | | `probe/c/.html` | a case of Amberlith: `` 16 hex digits of its suite and name; its results on each machine, what the rules say of it, and its newest 200 failures and skips with their detail | | `probe/d/.html` | a driver, by the ban table's name (`radv`, `nvidia`; `unknown` for the console's reports): its machines, the cases that fail on it, its ban candidates, its runs | diff --git a/scripts/test-mutants.py b/scripts/test-mutants.py index 3939336..c4065c6 100755 --- a/scripts/test-mutants.py +++ b/scripts/test-mutants.py @@ -314,8 +314,15 @@ ) # what only the whole suite holds: the worker, a process of its own shut in its folder (test_worker); who links a -# report to an issue (test_links); when a report's sender is told its fix is out (test_follow) +# report to an issue (test_links); when a report's sender is told its fix is out (test_follow); an approval of a +# failure an issue has (test_same_failure) WORKER = ( + ( + "an approval opens a new issue for a failure an issue has", + 'report.c', + ' if (i < n) {\n e = same_linked(', + ' if (0 && i < n) {\n e = same_linked(', + ), ( "a sender is told before a nightly has the fix", 'follow.c', diff --git a/tracer/src/report.c b/tracer/src/report.c index 507a073..d19ec4b 100644 --- a/tracer/src/report.c +++ b/tracer/src/report.c @@ -255,6 +255,14 @@ static cJSON* help(void) { TONE_SAID); } +/* the pages of the reports of signature's failure drawn again, as except came or went: TR_SAME * 4 at most, the + newest, whose pages name except */ +static void same_drawn(Tracer* t, const char* signature, long except) { + long ids[TR_SAME * 4], issues[TR_SAME * 4]; + int n = signature ? st_same_failure(t->store, signature, NULL, except, ids, issues, TR_SAME * 4) : 0, i; + for (i = 0; i < n; ++i) site_report_page(t->store, t->root, ids[i]); +} + /* report id gone: its files, its page, its row, and the pages that listed it */ static void forget(Tracer* t, long id) { StReport r; @@ -264,6 +272,7 @@ static void forget(Tracer* t, long id) { if (!st_remove(t->store, id)) { site_forget(t->root, id, files, nfiles); site_update(t->store, t->root, 0, r.key); + same_drawn(t, r.signature, id); } st_report_free(&r); st_files_free(files, nfiles); @@ -742,6 +751,18 @@ static cJSON* made(Tracer* t, const StReport* r, const Taken* k) { add_field(e, "Not kept", skipped); free(skipped); } + if (r->signature) { /* the newest other reports of this failure, any game's, with their issues */ + long ids[TR_SAME + 1], issues[TR_SAME + 1]; + int n = st_same_failure(t->store, r->signature, NULL, r->id, ids, issues, TR_SAME + 1), i; + Buf same = {0}; + for (i = 0; i < n && i < TR_SAME; ++i) { + buf_printf(&same, "%s#%ld", i ? ", " : "", ids[i]); + if (issues[i] > 0) buf_printf(&same, " (issue #%ld)", issues[i]); + } + if (n > TR_SAME) buf_add(&same, ", and more"); + if (same.len) add_field(e, "Same failure", same.text); + buf_free(&same); + } if (k->probe_why) { /* lines of edenprobe that are no whole run: kept as a log, not on the Probe pages */ char* why = plain(k->probe_why, 1000); add_field(e, "Not a run of Amberlith", why); @@ -1083,6 +1104,7 @@ static cJSON* reported(Tracer* t, const TrMessage* asker, const TrMessage* m, co return said("The report could not be kept: try again later, please."); } site_update(t->store, t->root, r.id, r.key); + same_drawn(t, r.signature, r.id); rei_log("report #%ld: %d logs, %d screenshots, %s", r.id, k.logs, k.images, r.key); e = made(t, &r, &k); *report = r.id; @@ -1585,6 +1607,42 @@ int tr_rescan(Tracer* t, const char* version) { return done; } +/* approved report r linked to issue, report other's, which has the same game's same failure, in place of a new one: + the link kept, the issue told in a comment; the reply (owned) */ +static cJSON* same_linked(Tracer* t, const StReport* r, long other, long issue) { + StReport o; + char *text, *why = NULL, *body, *page; + cJSON* e; + if (st_get(t->store, other, &o, NULL, NULL) != 1 || !o.issue_url) + return said("The approval could not be kept: try again later, please."); + if (st_claim_issue(t->store, r->id) != 1 || st_set_issue(t->store, r->id, issue, o.issue_url)) { + st_set_issue(t->store, r->id, 0, NULL); + st_report_free(&o); + return said("The approval could not be kept: try again later, please."); + } + site_update(t->store, t->root, r->id, r->key); + page = rei_format("%s/r/%ld/", t->url, r->id); + body = rei_format("Tracer report %ld has this issue's failure (the same game, the same signature as report %ld), " + "approved on Discord by a server's administrator: %s", + r->id, other, page); + if (tr_issue_comment(t->issues, issue, body, &why)) + rei_log("report #%ld linked to #%ld as report #%ld is, and the comment that says so was refused: %s", r->id, + issue, other, why); + rei_log("report #%ld approved: linked to #%ld, report #%ld's, the same game's same failure", r->id, issue, other); + text = + rei_format("Report #%ld has the failure of report #%ld, which is issue #%ld: linked to it, and no other issue " + "opened.%s%s", + r->id, other, issue, why ? " Its comment on the issue was refused: " : "", why ? why : ""); + e = said(text); + jset(e, "url", o.issue_url); + free(text); + free(body); + free(page); + free(why); + st_report_free(&o); + return e; +} + cJSON* tr_approved(Tracer* t, const TrReaction* r) { StReport rep; StFile* files; @@ -1600,6 +1658,17 @@ cJSON* tr_approved(Tracer* t, const TrReaction* r) { st_files_free(files, nfiles); return NULL; } + if (!rep.issue && rep.signature) { /* the same game's same failure an issue has already: linked to it */ + long ids[TR_SAME], issues[TR_SAME]; + int n = st_same_failure(t->store, rep.signature, rep.key, id, ids, issues, TR_SAME), i; + for (i = 0; i < n && issues[i] <= 0; ++i) continue; + if (i < n) { + e = same_linked(t, &rep, ids[i], issues[i]); + st_report_free(&rep); + st_files_free(files, nfiles); + return e; + } + } if ((claimed = st_claim_issue(t->store, id)) != 1) { if (!claimed) rei_log("report #%ld approved again: %s", id, diff --git a/tracer/src/site.c b/tracer/src/site.c index 89ab9d1..d07b1b6 100644 --- a/tracer/src/site.c +++ b/tracer/src/site.c @@ -621,6 +621,15 @@ char* site_report_html(const StReport* r, const StFile* files, int nfiles, const field(&b, "Game version", r->version); field(&b, "Signature", r->signature); field(&b, "Missed", r->missed); + if (r->nsame) { /* the newest other reports of this failure, any game's */ + int k; + buf_add(&b, "
Same failure
"); + for (k = 0; k < r->nsame; ++k) { + buf_printf(&b, "%s#%ld", k ? ", " : "", r->same[k], r->same[k]); + if (r->same_issue[k] > 0) buf_printf(&b, " (issue #%ld)", r->same_issue[k]); + } + buf_add(&b, "
\n"); + } if (hex(r->commit) || (r->build && *r->build) || r->age) { /* the build, its commit linked, and how old it was */ buf_add(&b, "
Build
"); esc(&b, r->build ? r->build : r->commit ? r->commit : ""); @@ -752,6 +761,16 @@ static cJSON* report_object(const StReport* r) { jset(o, "fix_commit", r->fix_commit); jset(o, "fix_nightly", r->fix_nightly); } + if (r->nsame) { + cJSON* same = cJSON_AddArrayToObject(o, "same_failure"); + int k; + for (k = 0; k < r->nsame; ++k) { + cJSON* each = cJSON_CreateObject(); + cJSON_AddNumberToObject(each, "report", (double)r->same[k]); + if (r->same_issue[k] > 0) cJSON_AddNumberToObject(each, "issue", (double)r->same_issue[k]); + cJSON_AddItemToArray(same, each); + } + } return o; } static char* printed(cJSON* o) { @@ -915,7 +934,7 @@ static int write_page(const char* root, const char* rel, char* html) { return done; } -static int report_page(Store* s, const char* root, long id) { +int site_report_page(Store* s, const char* root, long id) { StReport r; StFile* files; StNote* notes = NULL; @@ -925,6 +944,8 @@ static int report_page(Store* s, const char* root, long id) { char* rel = rei_format("r/%ld/index.html", id); st_notes(s, id, ¬es, &nnotes); if (!strcmp(r.key, PROBE_KEY)) run = st_probe_get(s, id, &probe, 1) == 1; + if (r.signature && (r.nsame = st_same_failure(s, r.signature, NULL, id, r.same, r.same_issue, TR_SAME)) < 0) + r.nsame = 0; done = write_page(root, rel, site_report_html(&r, files, nfiles, notes, nnotes, run ? &probe : NULL)); free(rel); rel = rei_format("api/r/%ld.json", id); @@ -977,7 +998,7 @@ static int lists(Store* s, const char* root, StGame* games, int ngames) { int site_update(Store* s, const char* root, long id, const char* key) { StGame* games; int n, done = 0, probe = key && !strcmp(key, PROBE_KEY); - if (id) done |= report_page(s, root, id); + if (id) done |= site_report_page(s, root, id); if (st_games(s, &games, &n)) return -1; if (!probe) done |= game_page(s, root, key, games, n); done |= lists(s, root, games, n); @@ -1023,7 +1044,7 @@ int site_rebuild(Store* s, const char* root) { st_games_free(games, ngames); return -1; } - for (i = 0; i < n; ++i) done |= report_page(s, root, all[i].id); + for (i = 0; i < n; ++i) done |= site_report_page(s, root, all[i].id); for (i = 0; i < ngames; ++i) done |= game_page(s, root, games[i].key, games, ngames); done |= lists(s, root, games, ngames); done |= site_probe(s, root); diff --git a/tracer/src/site.h b/tracer/src/site.h index 9887fb4..2f9d11b 100644 --- a/tracer/src/site.h +++ b/tracer/src/site.h @@ -47,6 +47,8 @@ int site_assets(const char* from, const char* root); /* a report's page, its game's page (gone when the game has no report left) and the lists drawn again, and every page of the runs of edenprobe when key is PROBE_KEY: 0, or -1 */ int site_update(Store* s, const char* root, long id, const char* key); +/* report id's page and JSON drawn again, alone (its game's and the lists left as they are): 0, or -1 */ +int site_report_page(Store* s, const char* root, long id); /* the pages of the runs of edenprobe, every one drawn again from the database: probe/index.html (each case that fails somewhere, by machine: the emulator, the driver and its version, the system; each suite; each run), probe/c/.html (a case on each machine, and its failures and skips with their detail, the newest 200), diff --git a/tracer/src/store.c b/tracer/src/store.c index 5739a46..7b19fb1 100644 --- a/tracer/src/store.c +++ b/tracer/src/store.c @@ -78,7 +78,9 @@ static const char* const UPGRADES[] = { "ALTER TABLE reports ADD COLUMN fix_pr INTEGER NOT NULL DEFAULT 0;" "ALTER TABLE reports ADD COLUMN fix_commit TEXT;" "ALTER TABLE reports ADD COLUMN fix_nightly TEXT;" - "ALTER TABLE reports ADD COLUMN told REAL NOT NULL DEFAULT 0;"}; + "ALTER TABLE reports ADD COLUMN told REAL NOT NULL DEFAULT 0;", + /* 11, the reports of one failure, found by their signature */ + "CREATE INDEX reports_signature ON reports(signature, id);"}; /* a report's columns, in the order row_report reads them */ #define REPORT_COLUMNS \ @@ -534,6 +536,24 @@ int st_followed(Store* s, int telling, StReport** reports, int* n) { return 0; } +int st_same_failure(Store* s, const char* signature, const char* key, long except, long* ids, long* issues, int max) { + sqlite3_stmt* q = prepared(s, "SELECT id, issue FROM reports WHERE signature = ? AND id != ? AND (? IS NULL OR" + " game = ?) ORDER BY id DESC LIMIT ?"); + int n = 0; + if (!q) return -1; + text_at(q, 1, signature); + sqlite3_bind_int64(q, 2, except); + text_at(q, 3, key); + text_at(q, 4, key); + sqlite3_bind_int(q, 5, max); + while (n < max && sqlite3_step(q) == SQLITE_ROW) { + ids[n] = (long)sqlite3_column_int64(q, 0); + issues[n++] = (long)sqlite3_column_int64(q, 1); + } + sqlite3_finalize(q); + return n; +} + int st_set_bytes(Store* s, long report, int n, double bytes) { sqlite3_stmt* q = prepared(s, "UPDATE files SET bytes = ? WHERE report = ? AND n = ?"); int ok; diff --git a/tracer/src/store.h b/tracer/src/store.h index ba21e3e..5dfe3af 100644 --- a/tracer/src/store.h +++ b/tracer/src/store.h @@ -32,6 +32,10 @@ typedef struct { char* fix_commit; /* owned: that pull request's merge commit, NULL for none */ char* fix_nightly; /* owned: the first nightly's tag that has it, NULL before one does */ double told; /* when the one who sent it was told it is fixed, 0 for not */ + /* not kept: the newest other reports whose first log failed with its signature (st_same_failure) and each one's + issue, filled where its page is drawn */ + long same[TR_SAME], same_issue[TR_SAME]; + int nsame; } StReport; /* what GitHub said of a commit (age.h), kept by the commit */ @@ -114,6 +118,9 @@ int st_followed(Store* s, int telling, StReport** reports, int* n); int st_set_facts(Store* s, const StReport* r); /* report id's game named again, as a later log names it: 0, or -1 */ int st_set_game(Store* s, long id, const char* key, const char* title, const char* title_id, int named); +/* the reports whose first log failed with signature, but except, the newest first: their ids, and each one's issue (0 + for none), max at most; their count, or -1 said in the log. key, when not NULL, keeps them to that game */ +int st_same_failure(Store* s, const char* signature, const char* key, long except, long* ids, long* issues, int max); /* the report sent as message, or 0 */ long st_by_message(Store* s, u64 message); /* report id, and its files (*files owned, NULL when not wanted): 1, 0 when there is none, -1 said in the log */ diff --git a/tracer/src/tracer.h b/tracer/src/tracer.h index e224f13..4444f33 100644 --- a/tracer/src/tracer.h +++ b/tracer/src/tracer.h @@ -16,6 +16,7 @@ #define TR_HOURLY 10 /* the reports one person sends in an hour */ #define TR_ROLES 256 /* the roles of a member that a message names, at most */ #define TR_KEY 72 /* a game's key: its title ID, or n- and its name's letters and digits */ +#define TR_SAME 5 /* the other reports of a failure a report's reply and page name, at most */ /* the bot's settings, its env file's keys; tracer-mcp knows them too, so that both may be given one env file */ #define TR_KEYS \ "TRACER_TOKEN", "TRACER_URL", "TRACER_CHANNELS", "TRACER_ADMINS", "TRACER_DB", "TRACER_SITE", "TRACER_ASSETS", \ diff --git a/tracer/tests/test_tracer.c b/tracer/tests/test_tracer.c index 248491d..4505b0e 100644 --- a/tracer/tests/test_tracer.c +++ b/tracer/tests/test_tracer.c @@ -3104,6 +3104,94 @@ static void test_links(void) { comment_body = NULL; } +/* ---- the reports of one failure ---- */ +/* two reports of one failure: each named in the other's reply, page and JSON; the second's approval links it to the + first's issue, no new one opened; the first gone from the second's page with its message */ +static void test_same_failure(void) { + TrIssues is; + TrMessage m; + TrReaction r; + StReport rep; + long first, second; + char *t, *p, *rel, *want; + memset(&is, 0, sizeof is); + is.repo = "o/r"; + is.emoji = "\xe2\x9c\x85"; + is.fetch = fake_links; + tracer.issues = &is; + m = message(8400, 170, "<@99> it stops"); + attach(&m, "game.log", "https://cdn.discordapp.com/1/game.log", 10); + free(answer_text(respond(&m))); + tr_message_free(&m); + first = st_by_message(tracer.store, 8400); + CHECK(!st_set_issue(tracer.store, first, 1234, "https://github.com/o/r/issues/1234")); + m = message(8401, 171, "<@99> it stops for me too"); + attach(&m, "game.log", "https://cdn.discordapp.com/1/game.log", 10); + t = answer_text(respond(&m)); + tr_message_free(&m); + second = st_by_message(tracer.store, 8401); + want = rei_format("#%ld (issue #1234)", first); + HAS(t, "Same failure"); + HAS(t, want); + free(want); + free(t); + rel = rei_format("r/%ld/index.html", second); + p = page(rel); + want = rei_format("
Same failure
#%ld (issue #1234)", first, first); + HAS(p, want); + free(want); + free(p); + free(rel); + rel = rei_format("r/%ld/index.html", first); /* drawn again as the second came */ + p = page(rel); + want = rei_format("#%ld", second, second); + HAS(p, want); + free(want); + free(p); + free(rel); + rel = rei_format("api/r/%ld.json", second); + p = page(rel); + want = rei_format("\"same_failure\":[{\"report\":%ld,\"issue\":1234}", first); + HAS(p, want); + free(want); + free(p); + free(rel); + /* the second approved: linked to the first's issue, which a comment tells, and no issue opened */ + link_asks = 0; + r = reaction(88, 33, 8401, "\xe2\x9c\x85"); + r.roles[r.nroles++] = 5; + t = answer_text(tr_approved(&tracer, &r)); + tr_reaction_free(&r); + want = rei_format("Report #%ld has the failure of report #%ld, which is issue #1234: linked to it, and no other " + "issue opened.", + second, first); + HAS(t, want); + free(want); + free(t); + CHECK(link_asks == 1); + SAME(comment_url, "POST https://api.github.com/repos/o/r/issues/1234/comments"); + want = rei_format("Tracer report %ld has this issue's failure (the same game, the same signature as report %ld)", + second, first); + HAS(comment_body, want); + free(want); + CHECK(st_get(tracer.store, second, &rep, NULL, NULL) == 1 && rep.issue == 1234); + SAME(rep.issue_url, "https://github.com/o/r/issues/1234"); + st_report_free(&rep); + /* the first gone: the second's page names it no more */ + CHECK(tr_forget(&tracer, 8400)); + rel = rei_format("r/%ld/index.html", second); + p = page(rel); + want = rei_format("#%ld", first, first); + LACKS(p, want); + free(want); + free(p); + free(rel); + CHECK(tr_forget(&tracer, 8401)); + tracer.issues = NULL; + free(comment_body); + comment_body = NULL; +} + /* ---- the issues followed ---- */ static char* follow_answer; /* GraphQL's answer, whole */ static int follow_status = 200, follow_asks; @@ -4955,6 +5043,7 @@ static void every_test(const char* self_path) { test_issues(); test_links(); test_follow(); + test_same_failure(); test_age(); test_archive_download(); test_zip_reports(); From 7581d9a0840b05ece9dedacce3a2c527ac7273f8 Mon Sep 17 00:00:00 2001 From: AO55 Date: Tue, 17 Nov 2026 13:03:40 -0300 Subject: [PATCH 5/6] [docs] The issues' token reads pull requests and contents too, in Install Signed-off-by: AO55 --- docs/INSTALL.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/INSTALL.md b/docs/INSTALL.md index d3e583a..96c2c4f 100644 --- a/docs/INSTALL.md +++ b/docs/INSTALL.md @@ -119,8 +119,9 @@ A channel id for `REIWIMSY_CHANNELS` and the card channels: Developer Mode, righ (the site's address), `TRACER_CHANNELS` (channels' ids, or `all` for every channel it can read; without it no report is taken), and the other keys [Tracer](./TRACER.md#settings) lists. For the issues, `TRACER_ISSUES_REPO` and `TRACER_ISSUES_TOKEN`: on GitHub, - Settings, Developer settings, Fine-grained tokens, the repository alone, the permission Issues: Read and write, - nothing else. For the games' names, `TRACER_TITLES`, a file `python3 scripts/make-titles.py --out FILE` makes in + Settings, Developer settings, Fine-grained tokens, the repository alone, the permissions Issues: Read and write, + Pull requests: Read and Contents: Read (the issues followed, a fix compared with the nightlies), nothing else; and + `TRACER_NOTIFY=ping` for a report's sender to be told when its fix is out. For the games' names, `TRACER_TITLES`, a file `python3 scripts/make-titles.py --out FILE` makes in the jail. 5. On, and started: From aad581924a979bf9698f136217490d1917305a4e Mon Sep 17 00:00:00 2001 From: AO55 Date: Tue, 17 Nov 2026 13:10:04 -0300 Subject: [PATCH 6/6] [tracer] An issue's title holds no "#", not even a log's own The title is the report's signature, a log's words that may hold a "#12", which GitHub links to the repository's own issue 12. Signed-off-by: AO55 --- tracer/src/issues.c | 4 +++- tracer/tests/test_tracer.c | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/tracer/src/issues.c b/tracer/src/issues.c index 3d5f81a..9f9d090 100644 --- a/tracer/src/issues.c +++ b/tracer/src/issues.c @@ -161,8 +161,10 @@ char* tr_issue_title(const StReport* r) { ? rei_format("Tracer report %ld: %s (%s)", r->id, r->signature, r->console ? r->console : "a game") : rei_format("Tracer report %ld: %s (%s)", r->id, r->outcome ? r->outcome : "no failure logged", r->console ? r->console : "a game"), - *t = tr_upstream_text(raw, TITLE_MAX); + *t = tr_upstream_text(raw, TITLE_MAX), *p; free(raw); + for (p = t; *p; ++p) /* a log's own "#12" too */ + if (*p == '#') *p = ' '; return t; } diff --git a/tracer/tests/test_tracer.c b/tracer/tests/test_tracer.c index 4505b0e..9e97e54 100644 --- a/tracer/tests/test_tracer.c +++ b/tracer/tests/test_tracer.c @@ -2788,6 +2788,16 @@ static void test_upstream_text(void) { t = tr_upstream_text("0100A6301214E000", 5); SAME(t, " (Switch)"); + free(t); + } } static void test_issues(void) {