diff --git a/actions/setup/js/action_setup_otlp.cjs b/actions/setup/js/action_setup_otlp.cjs index 3de1e20783..5af21e42e8 100644 --- a/actions/setup/js/action_setup_otlp.cjs +++ b/actions/setup/js/action_setup_otlp.cjs @@ -44,8 +44,9 @@ async function run() { const { sendJobSetupSpan, isValidTraceId, isValidSpanId } = require(path.join(__dirname, "send_otlp_span.cjs")); - const parsedStartMs = parseInt(process.env.SETUP_START_MS || "0", 10); - const startMs = Number.isFinite(parsedStartMs) ? parsedStartMs : 0; + const rawStartMs = process.env.SETUP_START_MS; + const parsedMs = /^\d+$/.test(rawStartMs ?? "") ? Number(rawStartMs) : NaN; + const startMs = Number.isSafeInteger(parsedMs) ? parsedMs : 0; // Explicitly read INPUT_TRACE_ID and pass it as options.traceId so the // activation job's trace ID is used even when process.env propagation diff --git a/actions/setup/js/action_setup_otlp.test.cjs b/actions/setup/js/action_setup_otlp.test.cjs index ffdf3e20ef..6527246f4e 100644 --- a/actions/setup/js/action_setup_otlp.test.cjs +++ b/actions/setup/js/action_setup_otlp.test.cjs @@ -164,6 +164,30 @@ describe("action_setup_otlp.cjs", () => { expect(mockSendJobSetupSpan).toHaveBeenCalledWith(expect.objectContaining({ startMs: 0 })); }); + + it("should pass startMs=0 when SETUP_START_MS is a partial number string like '123abc'", async () => { + process.env.SETUP_START_MS = "123abc"; + + await run(); + + expect(mockSendJobSetupSpan).toHaveBeenCalledWith(expect.objectContaining({ startMs: 0 })); + }); + + it("should pass startMs=0 when SETUP_START_MS is scientific notation like '1e3'", async () => { + process.env.SETUP_START_MS = "1e3"; + + await run(); + + expect(mockSendJobSetupSpan).toHaveBeenCalledWith(expect.objectContaining({ startMs: 0 })); + }); + + it("should pass startMs=0 when SETUP_START_MS is hex notation like '0x10'", async () => { + process.env.SETUP_START_MS = "0x10"; + + await run(); + + expect(mockSendJobSetupSpan).toHaveBeenCalledWith(expect.objectContaining({ startMs: 0 })); + }); }); describe("INPUT_TRACE_ID handling", () => {