From fa04e622013f2fe6ad47a2e52e828eb11e768ece Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Fri, 13 Mar 2026 21:40:50 +0000 Subject: [PATCH] test: tighten shared tailscale and sample coverage --- src/shared/string-sample.test.ts | 10 ++++++++++ src/shared/tailscale-status.test.ts | 22 ++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/src/shared/string-sample.test.ts b/src/shared/string-sample.test.ts index 7ced1e7407a..f86e8e1b349 100644 --- a/src/shared/string-sample.test.ts +++ b/src/shared/string-sample.test.ts @@ -42,4 +42,14 @@ describe("summarizeStringEntries", () => { }), ).toBe("a, b, c, d, e, f (+1)"); }); + + it("does not add a suffix when the limit exactly matches the entry count", () => { + expect( + summarizeStringEntries({ + entries: ["a", "b", "c"], + limit: 3, + emptyText: "ignored", + }), + ).toBe("a, b, c"); + }); }); diff --git a/src/shared/tailscale-status.test.ts b/src/shared/tailscale-status.test.ts index 5826e4b00b3..94128e700ed 100644 --- a/src/shared/tailscale-status.test.ts +++ b/src/shared/tailscale-status.test.ts @@ -32,6 +32,28 @@ describe("shared/tailscale-status", () => { ); }); + it("falls back to the first tailscale ip when DNSName is blank", async () => { + const run = vi.fn().mockResolvedValue({ + code: 0, + stdout: '{"Self":{"DNSName":"","TailscaleIPs":["100.64.0.10","fd7a::2"]}}', + }); + + await expect(resolveTailnetHostWithRunner(run)).resolves.toBe("100.64.0.10"); + }); + + it("continues to later command candidates when earlier output has no usable host", async () => { + const run = vi + .fn() + .mockResolvedValueOnce({ code: 0, stdout: '{"Self":{}}' }) + .mockResolvedValueOnce({ + code: 0, + stdout: '{"Self":{"DNSName":"backup.tail.ts.net."}}', + }); + + await expect(resolveTailnetHostWithRunner(run)).resolves.toBe("backup.tail.ts.net"); + expect(run).toHaveBeenCalledTimes(2); + }); + it("returns null for non-zero exits, blank output, or invalid json", async () => { const run = vi .fn()