oficina / meet Public

Clone
git clone https://amadan.net/oficina/meet

Plain git — no account needed to clone.

Download

Download this file

1package main
2
3import (
4 "bytes"
5 "os"
6 "path/filepath"
7 "strings"
8 "testing"
9)
10
11// fixture is carlos logs output as it prints it: its own prefix, then the
12// app's JSON line. Two people in one call, a call before it, a problem
13// report in two parts, and a text line the summary must skip.
14const fixture = `2026-10-03 14:39:30 [app] calls.bds.oncarlos.com time=2026-10-03T14:39:30.000Z level=INFO msg="rastrillo: serving"
152026-10-03 14:40:00 [app] calls.bds.oncarlos.com {"time":"2026-10-03T14:40:00Z","level":"INFO","msg":"calls: quality","call":"oldcalloldcall22","peer":"zzzzzzzzzzzzzzzz","app":"web","seconds":30,"report":{"seconds":30}}
162026-10-03 14:41:00 [app] calls.bds.oncarlos.com {"time":"2026-10-03T14:41:00Z","level":"INFO","msg":"calls: quality","call":"callcallcallcall","peer":"aaaaaaaaaaaaaaaa","app":"mac","version":"0.4.9","os":"macos","osVersion":"26.0.1","final":false,"seconds":30,"report":{"seconds":30,"devices":{"input":"bluetooth","output":"built-in"},"peers":[{"peer":"bbbbbbbbbbbbbbbb","path":{"local":"srflx","remote":"relay","protocol":"udp"},"rtt":48,"in":{"audio":{"packets":1490,"lost":10,"samples":1440000,"concealed":14400},"video":{"packets":900,"lost":100,"freezes":2,"freezeSeconds":1.5}},"events":{"reconnecting":1,"reconnectingSeconds":4.2,"sentSeconds":[0,24,0]}}]}}
172026-10-03 14:41:05 [app] calls.bds.oncarlos.com {"time":"2026-10-03T14:41:05Z","level":"INFO","msg":"calls: quality","call":"callcallcallcall","peer":"bbbbbbbbbbbbbbbb","app":"web","version":"de04e2d","browser":"chrome","browserVersion":"141.0","os":"windows","osVersion":"10.0","seconds":30,"videoAsked":24,"report":{"seconds":30,"peers":[{"peer":"aaaaaaaaaaaaaaaa","path":{"local":"relay","remote":"srflx","protocol":"tls"},"rtt":180,"in":{"audio":{"packets":1500,"lost":0}},"events":{"cantHearSeconds":3,"askedSeconds":[0,24,0]}}]}}
182026-10-03 14:41:30 [app] calls.bds.oncarlos.com {"time":"2026-10-03T14:41:30Z","level":"INFO","msg":"calls: quality","call":"callcallcallcall","peer":"aaaaaaaaaaaaaaaa","app":"mac","version":"0.4.9","os":"macos","osVersion":"26.0.1","final":true,"seconds":30,"report":{"seconds":30,"peers":[{"peer":"bbbbbbbbbbbbbbbb","path":{"local":"host","remote":"host","protocol":"udp"},"rtt":20}]}}
192026-10-03 14:41:20 [app] calls.bds.oncarlos.com {"time":"2026-10-03T14:41:20Z","level":"WARN","msg":"calls: problem report","ref":"K7Q2M9PD","call":"callcallcallcall","peer":"aaaaaaaaaaaaaaaa","app":"mac","version":"0.4.9","os":"macos","live":true,"note":"video froze","parts":2}
202026-10-03 14:41:20 [app] calls.bds.oncarlos.com {"time":"2026-10-03T14:41:20Z","level":"WARN","msg":"calls: problem report diagnostics","ref":"K7Q2M9PD","call":"callcallcallcall","peer":"aaaaaaaaaaaaaaaa","part":2,"of":2,"text":"second half\n"}
212026-10-03 14:41:20 [app] calls.bds.oncarlos.com {"time":"2026-10-03T14:41:20Z","level":"WARN","msg":"calls: problem report diagnostics","ref":"K7Q2M9PD","call":"callcallcallcall","peer":"aaaaaaaaaaaaaaaa","part":1,"of":2,"text":"first half, "}
22`
23
24func runOn(t *testing.T, args ...string) string {
25 t.Helper()
26 path := filepath.Join(t.TempDir(), "logs")
27 if err := os.WriteFile(path, []byte(fixture), 0o600); err != nil {
28 t.Fatal(err)
29 }
30 f, err := os.Open(path)
31 if err != nil {
32 t.Fatal(err)
33 }
34 defer f.Close()
35 var out bytes.Buffer
36 if err := run(append([]string{"--zone", "Europe/Dublin"}, args...), f, &out); err != nil {
37 t.Fatal(err)
38 }
39 return out.String()
40}
41
42func TestSummaryOfOneCall(t *testing.T) {
43 out := runOn(t, "--at", "2026-10-03 15:41")
44 t.Log("\n" + out)
45 for _, want := range []string{
46 "Call callcallcallcall 2026-10-03 15:41:00 – 15:41:30 Europe/Dublin (30s), 2 people, 1 problem report(s)",
47 "aaaaaa mac 0.4.9 macos 26.0.1 2 reports (input bluetooth, output built-in)",
48 "bbbbbb web de04e2d chrome 141.0 on windows 10.0 1 reports",
49 "aaaaaa ← bbbbbb worst loss 10.0% (video), worst RTT 48 ms, freezes 2 (1.5 s), audio concealed 1.00%, path host→host udp",
50 "relay 50%",
51 "bbbbbb ← aaaaaa worst loss 0.0%, worst RTT 180 ms, freezes 0 (0.0 s), path relay→srflx tls, relay 100%",
52 `15:41:00 aaaaaa: "Reconnecting to bbbbbb…" (4.2 s)`,
53 `15:41:05 bbbbbb: "aaaaaa can't hear you yet" (3.0 s)`,
54 "15:41:30 aaaaaa left (final report)",
55 // §15.30: who asked whom for less video, and for how long.
56 "bbbbbb asked aaaaaa for Minimal for 24s",
57 "aaaaaa sent bbbbbb Minimal for 24s because they asked",
58 `Problem K7Q2M9PD at 15:41:20 from aaaaaa (mac): "video froze"`,
59 } {
60 if !strings.Contains(out, want) {
61 t.Errorf("missing %q", want)
62 }
63 }
64 if strings.Contains(out, "oldcall") {
65 t.Error("--at showed a call that had ended by then")
66 }
67}
68
69func TestSummaryByCallTagAndAProblemReport(t *testing.T) {
70 if out := runOn(t, "--call", "oldcalloldcall22"); !strings.Contains(out, "Call oldcalloldcall22") || strings.Contains(out, "callcallcallcall") {
71 t.Fatalf("--call:\n%s", out)
72 }
73 out := runOn(t, "--problem", "k7q2m9pd")
74 if !strings.Contains(out, "note: video froze") || !strings.Contains(out, "first half, second half") {
75 t.Fatalf("--problem:\n%s", out)
76 }
77}
78
79// carlosFixture is `carlos logs` as it really prints (2026-10-21): the
80// message, then the top-level fields as key=value in key order, values
81// unquoted, a diagnostics chunk's newlines printed as they are, and no
82// `report` at all. Diagnostics text that looks like fields (" in=1",
83// " time=") must stay text.
84const carlosFixture = `2026-10-21 14:38:52 [app] calls.bds.oncarlos.com calls: quality app=mac call=ayhk4nffb2gz7eur final=false freezes=4 maxLossPct=0.1 maxRtt=195.9 os=macos osVersion=27.0.0 peer=p2pq7kdbzubekeu6 reconnecting=0 relay=false remotes=1 screenRebuilds=1 screenStalls=0 seconds=30.9 time=2026-10-21T14:38:52.887559374Z version=0.4.10
852026-10-21 14:39:06 [app] calls.bds.oncarlos.com calls: quality app=web browser=safari browserVersion=26.5 call=ayhk4nffb2gz7eur final=false freezes=0 maxLossPct=0 maxRtt=141 os=macos peer=ce5xx2f463fimkpi reconnecting=0 relay=false remotes=1 screenStalls=2 screenStallsUndecoded=2 seconds=30.2 time=2026-10-21T14:39:06.364245764Z version=882eab8 videoAsked=240 videoSetting=low
862026-10-21 15:06:37 [app] calls.bds.oncarlos.com calls: problem report app=mac call=ayhk4nffb2gz7eur live=true note=it froze, then a=b os=macos osVersion=27.0.0 parts=2 peer=p2pq7kdbzubekeu6 ref=6BPJVTGF time=2026-10-21T15:06:37.899381736Z version=0.4.10
872026-10-21 15:06:37 [app] calls.bds.oncarlos.com calls: problem report diagnostics call=ayhk4nffb2gz7eur of=2 part=1 peer=p2pq7kdbzubekeu6 ref=6BPJVTGF text=Calls diagnostics — a call's details
88## Devices
89device: Microphone [x] in=1 out=0 48000 Hz built-in
9015:48:58.392 info keyframe for p time=2026-10-21T15:06:37.899431639Z
912026-10-21 15:06:37 [app] calls.bds.oncarlos.com calls: problem report diagnostics call=ayhk4nffb2gz7eur of=2 part=2 peer=p2pq7kdbzubekeu6 ref=6BPJVTGF text=eer:ce5xx2f463fimkpi
92stamp time=now ok
93 time=2026-10-21T15:06:37.8995183Z
94(showing the newest 5 lines of this window — narrow it, or raise -n)
95`
96
97func runOnText(t *testing.T, text string, args ...string) string {
98 t.Helper()
99 path := filepath.Join(t.TempDir(), "logs")
100 if err := os.WriteFile(path, []byte(text), 0o600); err != nil {
101 t.Fatal(err)
102 }
103 f, err := os.Open(path)
104 if err != nil {
105 t.Fatal(err)
106 }
107 defer f.Close()
108 var out bytes.Buffer
109 if err := run(append([]string{"--zone", "Europe/Dublin"}, args...), f, &out); err != nil {
110 t.Fatal(err)
111 }
112 return out.String()
113}
114
115func TestCarlosPrintedProblemReport(t *testing.T) {
116 out := runOnText(t, carlosFixture, "--problem", "6bpjvtgf")
117 t.Log("\n" + out)
118 want := "Calls diagnostics — a call's details\n## Devices\ndevice: Microphone [x] in=1 out=0 48000 Hz built-in\n" +
119 "15:48:58.392 info keyframe for peer:ce5xx2f463fimkpi\nstamp time=now ok\n"
120 if !strings.Contains(out, want) {
121 t.Errorf("diagnostics not reassembled; want\n%s", want)
122 }
123 if !strings.Contains(out, "note: it froze, then a=b\n") || !strings.Contains(out, "mac 0.4.10") {
124 t.Error("the head's note or client was misread")
125 }
126}
127
128func TestCarlosPrintedQualityHeadlines(t *testing.T) {
129 out := runOnText(t, carlosFixture, "--call", "ayhk4nffb2gz7eur")
130 t.Log("\n" + out)
131 for _, want := range []string{
132 "Call ayhk4nffb2gz7eur",
133 "p2pq7k mac 0.4.10 macos 27.0.0 1 reports",
134 "worst loss 0.1%, worst RTT 195.9 ms, freezes in 4",
135 "screen 1 rebuilds",
136 "ce5xx2 web 882eab8 safari 26.5 on macos 1 reports",
137 "screen 2 stalls reported here, 2 arriving, not decoded",
138 // §15.30's headline: time asked for less video.
139 "asked someone for less video 4m0s, sent someone less 0s",
140 "Problem 6BPJVTGF",
141 } {
142 if !strings.Contains(out, want) {
143 t.Errorf("missing %q", want)
144 }
145 }
146}
147
148func TestCarlosArgs(t *testing.T) {
149 got := strings.Join(carlosArgs(options{app: "calls", account: "oficina", since: "24h", problem: "6bpjvtgf"}), " ")
150 if !strings.Contains(got, "-field ref=6BPJVTGF") || !strings.Contains(got, "-n 5000") || strings.Contains(got, "-grep") {
151 t.Errorf("--problem fetches %q", got)
152 }
153 got = strings.Join(carlosArgs(options{app: "calls", account: "oficina", since: "2h"}), " ")
154 if !strings.Contains(got, "-n 5000") || !strings.Contains(got, "-grep") {
155 t.Errorf("the summary fetches %q", got)
156 }
157}
158