From 04f564f211221fca462426c74360f8ebbc105478 Mon Sep 17 00:00:00 2001 From: repo-worker-code-g Date: Fri, 6 Nov 2026 23:21:29 -0600 Subject: [PATCH] fix(mcpx/plugin): goDurationMs accepts Go dot-fractions and Greek-mu microseconds (#3490) --- pkgs/mcpx/plugin/opencode/mcpx/daemon.test.ts | 21 +++++++++++++++++++ pkgs/mcpx/plugin/opencode/mcpx/daemon.ts | 8 +++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/pkgs/mcpx/plugin/opencode/mcpx/daemon.test.ts b/pkgs/mcpx/plugin/opencode/mcpx/daemon.test.ts index d3b8dc3c13..5e9773c49b 100644 --- a/pkgs/mcpx/plugin/opencode/mcpx/daemon.test.ts +++ b/pkgs/mcpx/plugin/opencode/mcpx/daemon.test.ts @@ -481,6 +481,27 @@ describe("goDurationMs", () => { // #2309: Go accepts a bare "0" as zero. expect(goDurationMs("0")).toBe(0); }); + + test("matches Go on dot fractions and both mu spellings (#3490)", () => { + // Go-parity table: every spelling verified against + // time.ParseDuration (see #3490 for the probe). + const parity: Array<[string, number]> = [ + [".5s", 500], + ["1.s", 1000], + [".5s.5s", 1000], + ["1.5s", 1500], + ["1\u03bcs", 0.001], // GREEK SMALL LETTER MU + ["1\u00b5s", 0.001], // MICRO SIGN + ["1us", 0.001], + [".5\u00b5s", 0.0005], + ]; + for (const [spelling, ms] of parity) expect(goDurationMs(spelling)).toBe(ms); + // Go rejects these spellings; they stay absent, as do negative + // durations per the deliberate divergence pinned above. + for (const bad of ["00", "5.", ".s", "1e3s", "1_000s", "60", "60s please", "-.5s", "-0"]) { + expect(goDurationMs(bad)).toBeUndefined(); + } + }); }); describe("withDaemonAuth (#1975)", () => { diff --git a/pkgs/mcpx/plugin/opencode/mcpx/daemon.ts b/pkgs/mcpx/plugin/opencode/mcpx/daemon.ts index 10d1128275..a212371a0c 100644 --- a/pkgs/mcpx/plugin/opencode/mcpx/daemon.ts +++ b/pkgs/mcpx/plugin/opencode/mcpx/daemon.ts @@ -92,8 +92,12 @@ export const TUNING = { */ export const goDurationMs = (v: string | undefined): number | undefined => { if (!v) return undefined; - const unit: Record = { ns: 1e-6, us: 1e-3, µs: 1e-3, ms: 1, s: 1000, m: 60_000, h: 3_600_000 }; - const re = /(\d+(?:\.\d+)?)(ns|us|µs|ms|s|m|h)/g; + const unit: Record = { ns: 1e-6, us: 1e-3, µs: 1e-3, μs: 1e-3, ms: 1, s: 1000, m: 60_000, h: 3_600_000 }; + // Go's number grammar is digits[.digits*] or .digits, so ".5s" and + // "1.s" are whole components (#3490); Go also accepts both mu + // codepoints for microseconds -- U+00B5 (micro sign) and U+03BC + // (Greek small letter mu) -- so both are in the unit table and here. + const re = /((?:\d+(?:\.\d*)?|\.\d+))(ns|us|µs|μs|ms|s|m|h)/g; let total = 0; let matched = 0; let m: RegExpExecArray | null;