fix: parse day and fractional-second components in FromTimeSpan (cherry-pick of #435) - #452
Open
NickJosevski wants to merge 1 commit into
Open
fix: parse day and fractional-second components in FromTimeSpan (cherry-pick of #435)#452NickJosevski wants to merge 1 commit into
NickJosevski 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.