From 25e56c33eaccc55d8fe0eecbe38e3d60b84a6c6d Mon Sep 17 00:00:00 2001 From: vybe Date: Fri, 22 May 2026 10:19:39 +0000 Subject: [PATCH] =?UTF-8?q?refactor:=20add=20getStatusCommand=20pure=20hel?= =?UTF-8?q?per=20+=20test=20(TDD=20step=202=20=E2=80=94=20prepares=20low-d?= =?UTF-8?q?uty-cycle=20status=20calls)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tailscalectl/lib.js | 7 ++++++- test/lib.test.js | 9 ++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/tailscalectl/lib.js b/tailscalectl/lib.js index 4dfaba1..b675532 100644 --- a/tailscalectl/lib.js +++ b/tailscalectl/lib.js @@ -103,6 +103,11 @@ function buildToggleCommand(isConnected) { return isConnected ? ["tailscale", "down"] : ["tailscale", "up"] } +// Single source of truth for the status command used for on-demand and post-action verification. +function getStatusCommand() { + return ["tailscale", "status", "--json"] +} + function errorMessage(cmd) { var messages = { "up": "Failed to connect to Tailscale", @@ -128,5 +133,5 @@ function formatError(action, detail) { // CommonJS export for Node.js tests (ignored by QML) if (typeof module !== "undefined" && module.exports) { - module.exports = { parsePeers, makeExitNodeCommand, findActiveExitNode, errorMessage, formatError, validateClipboardTool, buildCopyCommand, nextClipboardTool, allClipboardTools, buildToggleCommand, parseStatusResult, getStrings, shouldShowClearExitNode, isActiveExitNode } + module.exports = { parsePeers, makeExitNodeCommand, findActiveExitNode, errorMessage, formatError, getStatusCommand, validateClipboardTool, buildCopyCommand, nextClipboardTool, allClipboardTools, buildToggleCommand, parseStatusResult, getStrings, shouldShowClearExitNode, isActiveExitNode } } diff --git a/test/lib.test.js b/test/lib.test.js index 1ca6db6..22ad0e6 100644 --- a/test/lib.test.js +++ b/test/lib.test.js @@ -1,7 +1,7 @@ import { test } from "node:test" import assert from "node:assert" import lib from "../tailscalectl/lib.js" -const { parsePeers, makeExitNodeCommand, findActiveExitNode, errorMessage, formatError, validateClipboardTool, buildCopyCommand, nextClipboardTool, allClipboardTools, buildToggleCommand, parseStatusResult, getStrings, shouldShowClearExitNode, isActiveExitNode } = lib +const { parsePeers, makeExitNodeCommand, findActiveExitNode, errorMessage, formatError, getStatusCommand, validateClipboardTool, buildCopyCommand, nextClipboardTool, allClipboardTools, buildToggleCommand, parseStatusResult, getStrings, shouldShowClearExitNode, isActiveExitNode } = lib /* * Test coverage note for #48: @@ -260,3 +260,10 @@ test("formatError handles empty or falsy detail gracefully", () => { assert.strictEqual(formatError("down", ""), "Failed to disconnect from Tailscale") assert.strictEqual(formatError("connect", null), "Failed to connect to Tailscale") }) + +// --- getStatusCommand (new pure helper for low-duty-cycle architecture) --- + +test("getStatusCommand returns the canonical tailscale status --json argv", () => { + const cmd = getStatusCommand() + assert.deepStrictEqual(cmd, ["tailscale", "status", "--json"]) +})