• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

knowledgepixels / nanopub-registry / 22891775829

10 Mar 2026 07:28AM UTC coverage: 27.177% (-0.2%) from 27.342%
22891775829

push

github

tkuhn
feat: add /debug/tasks endpoint to expose the task queue

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

170 of 684 branches covered (24.85%)

Branch coverage included in aggregate %.

551 of 1969 relevant lines covered (27.98%)

4.96 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
src/main/java/com/knowledgepixels/registry/DebugPage.java
1
package com.knowledgepixels.registry;
2

3
import com.mongodb.client.ClientSession;
4
import com.mongodb.client.MongoCursor;
5
import io.vertx.ext.web.RoutingContext;
6
import org.bson.Document;
7

8
import java.io.IOException;
9

10
import static com.knowledgepixels.registry.RegistryDB.collection;
11
import static com.mongodb.client.model.Indexes.ascending;
12

13
public class DebugPage extends Page {
14

15
    public static void show(RoutingContext context) {
16
        DebugPage page;
17
        try (ClientSession s = RegistryDB.getClient().startSession()) {
×
18
            s.startTransaction();
×
19
            page = new DebugPage(s, context);
×
20
            page.show();
×
21
        } catch (IOException ex) {
×
22
            ex.printStackTrace();
×
23
        } finally {
24
            context.response().end();
×
25
            // TODO Clean-up here?
26
        }
27
    }
×
28

29
    private DebugPage(ClientSession mongoSession, RoutingContext context) {
30
        super(mongoSession, context);
×
31
    }
×
32

33
    protected void show() throws IOException {
34
        RoutingContext c = getContext();
×
35

36
        if (getRequestString().matches("/debug/trustPaths")) {
×
37
            String counterString = c.request().getParam("trustStateCounter");
×
38
            if (counterString == null) {
×
39
                print(getTrustPathsTxt(mongoSession));
×
40
            } else {
41
                Long counter = Long.parseLong(counterString);
×
42
                print(RegistryDB.getOne(mongoSession, "debug_trustPaths", new Document("trustStateCounter", counter)).getString("trustStateTxt"));
×
43
            }
44
            setRespContentType("text/plain");
×
45
        } else if (getRequestString().matches("/debug/endorsements")) {
×
46
            MongoCursor<Document> tp = collection("endorsements").find(mongoSession).cursor();
×
47
            while (tp.hasNext()) {
×
48
                Document d = tp.next();
×
49
                println(d.get("agent") + ">" + d.get("pubkey") + " " + d.get("endorsedNanopub") + " " + d.get("source") + " (" + d.get("status") + ")");
×
50
            }
×
51
            setRespContentType("text/plain");
×
52
        } else if (getRequestString().matches("/debug/accounts")) {
×
53
            MongoCursor<Document> tp = collection("accounts").find(mongoSession).cursor();
×
54
            while (tp.hasNext()) {
×
55
                Document d = tp.next();
×
56
                println(d.getString("agent") + ">" + d.get("pubkey") + " " + d.get("depth") + " (" + d.get("status") + ")");
×
57
            }
×
58
        } else if (getRequestString().matches("/debug/tasks")) {
×
59
            setRespContentType("text/plain");
×
60
            try {
61
                MongoCursor<Document> tasks = collection(Collection.TASKS.toString()).find(mongoSession)
×
62
                        .sort(ascending("not-before")).cursor();
×
63
                int count = 0;
×
64
                while (tasks.hasNext()) {
×
65
                    println(tasks.next().toJson());
×
66
                    count++;
×
67
                }
68
                println("Total tasks: " + count);
×
69
            } catch (Exception ex) {
×
70
                println("Error: " + ex.getClass().getName() + ": " + ex.getMessage());
×
71
            }
×
72
        } else if (getRequestString().matches("/debug/peerState")) {
×
73
            setRespContentType("text/plain");
×
74
            try {
75
                long count = collection(Collection.PEER_STATE.toString()).countDocuments(mongoSession);
×
76
                println("peerState documents: " + count);
×
77
                MongoCursor<Document> ps = collection(Collection.PEER_STATE.toString()).find(mongoSession).cursor();
×
78
                while (ps.hasNext()) {
×
79
                    println(ps.next().toJson());
×
80
                }
81
            } catch (Exception ex) {
×
82
                println("Error: " + ex.getClass().getName() + ": " + ex.getMessage());
×
83
            }
×
84
        } else {
85
            c.response().setStatusCode(400).setStatusMessage("Invalid request: " + getFullRequest());
×
86
        }
87
    }
×
88

89
    public static String getTrustPathsTxt(ClientSession mongoSession) {
90
        String s = "";
×
91
        MongoCursor<Document> tp = collection("trustPaths").find(mongoSession).sort(ascending("_id")).cursor();
×
92
        while (tp.hasNext()) {
×
93
            Document d = tp.next();
×
94
            String path = d.getString("_id");
×
95
            path = path.replace(" ", " > ");
×
96
            if (d.getString("type").equals("extended")) {
×
97
                path = path.replaceFirst(" > ([^ ]+)$", " ~ $1");
×
98
            }
99
            s += path + "\n";
×
100
        }
×
101
        return s;
×
102
    }
103

104
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc