diff --git a/.opencode/plugin/mcpx/biome.json b/.opencode/plugin/mcpx/biome.json new file mode 100644 index 0000000000..728c1939ec --- /dev/null +++ b/.opencode/plugin/mcpx/biome.json @@ -0,0 +1,14 @@ +{ + "$schema": "https://biomejs.dev/schemas/2.5.15/schema.json", + "root": false, + "extends": [ + "../../../../../biome.json" + ], + "linter": { + "rules": { + "suspicious": { + "noAssignInExpressions": "off" + } + } + } +} diff --git a/.opencode/plugin/mcpx/daemon.test.ts b/.opencode/plugin/mcpx/daemon.test.ts index d3b8dc3c13..bacba49047 100644 --- a/.opencode/plugin/mcpx/daemon.test.ts +++ b/.opencode/plugin/mcpx/daemon.test.ts @@ -477,10 +477,31 @@ describe("goDurationMs", () => { // Just under the ceiling still parses (the largest Go duration // is 2562047h47m16.854775807s = 2^63-1 ns). expect(goDurationMs("2562047h47m16.854775s")).toBeDefined(); - expect(goDurationMs("2562047h47m16.854775s")).toBeLessThanOrEqual(9_223_372_036_854.776); + expect(goDurationMs("2562047h47m16.854775s")).toBeLessThanOrEqual(9_223_372_036_854.775); // #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/.opencode/plugin/mcpx/daemon.ts b/.opencode/plugin/mcpx/daemon.ts index 10d1128275..05b23b276a 100644 --- a/.opencode/plugin/mcpx/daemon.ts +++ b/.opencode/plugin/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; @@ -113,7 +117,7 @@ export const goDurationMs = (v: string | undefined): number | undefined => { // past the ceiling), and an infinite discovery cooldown silently // disabled daemon rediscovery for the whole session (#2309). // Unparseable-by-Go is this function's "treated as absent". - if (!Number.isFinite(total) || total > 9_223_372_036_854.776) return undefined; + if (!Number.isFinite(total) || total > 9_223_372_036_854.775) return undefined; return v.trim().startsWith("-") ? undefined : total; };