fix: parse day and fractional-second components in FromTimeSpan (cherry-pick of #435) - #452
fix: parse day and fractional-second components in FromTimeSpan (cherry-pick of #435)#452NickJosevski wants to merge 1 commit into
Conversation
FromTimeSpan read the time span fields at fixed offsets and took the day component from timeSpan[0:0], which is always the empty string. Every value carrying a day component therefore parsed to zero, including "1.00:00:00" — the interval on the default machine policy — and any fractional seconds were dropped. An empty string panicked on a slice bound. Parse the components by separator instead. The day and fractional-second parts are both optional, and the server does not pad the day component to a fixed width, so offsets cannot be assumed. Malformed input now yields a zero duration rather than a panic. The existing tests only logged their results and asserted nothing, which is why this went unnoticed; they now assert, and every case they already covered was returning zero. Closes #434 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> (cherry picked from commit 5d7ef5e) Co-authored-by: Scott Emberson <8268155+Scott-Emberson@users.noreply.github.com>
|
Superseded by #458, merged 2026-08-23. This was a mechanical re-host of #435 so CI could run on it. It went stale while it waited: #458 fixed the same bug independently, rewriting Rebasing onto
Negative time spans are the ones this PR's own description flagged as remaining wrong; #458 handles them. The The additive test coverage is carried forward in #479, with @Scott-Emberson as co-author. #434 and #435 are closed against #458. |
Cherry-pick of #435 by @Scott-Emberson, re-hosted on a branch in this repo solely so CI can run. Authorship is preserved on the commit — this is a mechanical move, not a rewrite, and the work and the analysis are entirely Scott's.
Fork PRs cannot satisfy the required
testcheck:integration-tests.ymlneedssecrets.DB_IMAGE_SA_PASSWORD,OD_IMAGE_ADMIN_API_KEYandOCTOPUS_SERVER_BASE64_LICENSE, and GitHub withholds secrets frompull_requestruns originating on a fork, so the job dies at Initialize containers before any Go executes. #435 is red for that reason and no other.The bug
FromTimeSpanread the day component fromtimeSpan[0:0]— always the empty string — so every value carrying days parsed to zero. Fixed offsets also assumed a single-digit day, fractional seconds were dropped, and an empty string panicked on a slice bound. It is duplicated verbatim inpkg/machinesandpkg/machinepolicies; this fixes both.Running main's parser against this one on the same inputs:
maintoday00:05:0001:30:001.00:00:007.12:30:0007.12:30:0010.00:00:0000:00:00.50000001.02:03:04.5000000""Every day-bearing value was silently wrong rather than failing loudly. Plain
hh:mm:ssis identical before and after, so nothing that works today regresses.Blast radius
Read path only.
ToTimeSpan, which produces what gets sent to the server, is untouched. All 14 in-repo callers ofFromTimeSpansit insideUnmarshalJSONon machine policy, cleanup policy and health check policy. It also closes a quiet data-loss path: today you can read a policy, write it back unchanged, and send a day-scale interval out as zero.Two notes for the release
0sfor these fields starts getting the true duration, which may surface as a one-off Terraform plan on machine policy timeouts. There is noCHANGELOG.mdand goreleaser builds notes from commit subjects only, so this needs a note pasted onto the GitHub Release at tag time. Wording is in a comment on fix: parse day and fractional-second components in FromTimeSpan (changes parsed values) #435.Once this merges
Close #435 pointing here, so Scott gets the credit and knows it wasn't rejected.