Prd/components/dialer-patch/tests/HelpdeskQueueTest.java
Lucy Doupalů be9f14ce34 Helpdesk - operator console + patched GrapheneOS Dialer for call handling
A small helpdesk system: an office Pixel running a patched GrapheneOS Dialer
answers technician calls, records both call legs as separate channels, and a
Ruby backend transcribes them through Whisper and files an AI summary against
the caller.

Squashed to a single commit for sharing. No credentials are included; secrets
live outside the repo in /etc/helpdesk/env on the server or a gitignored
.claude/env.local locally. See .claude/env.local.example for the shape.

Start at README.md, then docs/architecture.md.
2026-07-27 18:50:32 +02:00

50 lines
2.6 KiB
Java

package com.android.dialer.helpdesk.queue;
import static com.android.dialer.helpdesk.http.HttpRetryPolicy.Action.BACKOFF_RETRY;
import static com.android.dialer.helpdesk.http.HttpRetryPolicy.Action.DROP;
import static com.android.dialer.helpdesk.http.HttpRetryPolicy.Action.REFRESH_RETRY;
import static com.android.dialer.helpdesk.http.HttpRetryPolicy.Action.SUCCESS;
/** Standalone off-device test for {@link HelpdeskQueue} — FIFO, dedup, head-of-line replay, ts. */
public class HelpdeskQueueTest {
static int pass = 0, fail = 0;
static void eq(Object got, Object want, String d) {
if (got == null ? want == null : got.equals(want)) { pass++; System.out.println(" ok " + d); }
else { fail++; System.out.println(" FAIL " + d + " (got: " + got + ")"); }
}
public static void main(String[] args) {
HelpdeskQueue q = new HelpdeskQueue();
q.enqueue(new HelpdeskQueue.Item("a", "/calls/incoming", "{}", 1000L));
q.enqueue(new HelpdeskQueue.Item("b", "/calls/answered", "{}", 1005L));
q.enqueue(new HelpdeskQueue.Item("c", "/calls/ended", "{}", 1010L));
eq(q.size(), 3, "three enqueued");
eq(q.head().id, "a", "FIFO: head is first enqueued");
eq(q.head().tsSeconds, 1000L, "head carries its original ts");
q.enqueue(new HelpdeskQueue.Item("a", "/calls/incoming", "{}", 9999L));
eq(q.size(), 3, "duplicate id not re-enqueued");
eq(q.onHeadResult(BACKOFF_RETRY), false, "transient failure keeps the head");
eq(q.head().id, "a", "head unchanged after retry (in-order preserved)");
eq(q.size(), 3, "size unchanged on retry");
eq(q.onHeadResult(REFRESH_RETRY), false, "auth failure also keeps the head");
eq(q.head().tsSeconds, 1000L, "original ts still intact across retries");
eq(q.onHeadResult(SUCCESS), true, "success removes the head");
eq(q.head().id, "b", "queue advances to next in order");
eq(q.size(), 2, "size decremented");
eq(q.onHeadResult(DROP), true, "422/permanent drop removes the head");
eq(q.head().id, "c", "advances past a dropped item");
eq(q.onHeadResult(SUCCESS), true, "last item succeeds");
eq(q.size(), 0, "queue drained");
eq(q.head(), null, "empty head is null");
eq(q.onHeadResult(SUCCESS), false, "onHeadResult on empty is a no-op");
// an id removed from the queue can be enqueued again (dedup set is cleaned on removal)
q.enqueue(new HelpdeskQueue.Item("a", "/calls/incoming", "{}", 2000L));
eq(q.size(), 1, "previously-drained id 'a' can re-enqueue after removal");
System.out.println("\n" + pass + " passed, " + fail + " failed");
System.exit(fail == 0 ? 0 : 1);
}
}