Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
env:
# Path the compat-tagged test reads from os.Getenv.
LIFTOFF_EXPORT_BIN: /tmp/liftoff-export
run: go test -tags=compat -run TestContractFormats ./...
run: go test -tags=compat -run 'TestContractFormats|TestResolvedWindow' ./...

artifacts:
# Cross-compile review binaries for the platforms reviewers actually use.
Expand Down
51 changes: 32 additions & 19 deletions cmd/bodyweights.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ type bodyweightJSON struct {
}

type bodyweightStatsJSON struct {
Current float64 `json:"current"`
High float64 `json:"high"`
Low float64 `json:"low"`
Change float64 `json:"change"`
RatePerMonth *float64 `json:"ratePerMonth,omitempty"`
Plateau *plateauJSON `json:"plateau,omitempty"`
Months []monthAvgJSON `json:"months"`
Current float64 `json:"current"`
High float64 `json:"high"`
Low float64 `json:"low"`
Change float64 `json:"change"`
RatePerMonth *float64 `json:"ratePerMonth,omitempty"`
Plateau *plateauJSON `json:"plateau,omitempty"`
Months []monthAvgJSON `json:"months"`
}

type plateauJSON struct {
Expand All @@ -72,7 +72,18 @@ var bodyweightsListCmd = &cobra.Command{
if err != nil {
return err
}
entries, err := loadBodyweightEntries(bodyweightsListSinceFlag, bodyweightsListUntilFlag)
since, err := parseDateValue(bodyweightsListSinceFlag)
if err != nil {
return err
}
until, err := parseUntilValue(bodyweightsListUntilFlag)
if err != nil {
return err
}
if printed, err := printResolvedWindow(cmd, since, until); printed || err != nil {
return err
}
entries, err := loadBodyweightEntries(since, until)
if err != nil {
return err
}
Expand Down Expand Up @@ -106,7 +117,18 @@ var bodyweightsStatsCmd = &cobra.Command{
if err != nil {
return err
}
entries, err := loadBodyweightEntries(bodyweightsStatsSinceFlag, bodyweightsStatsUntilFlag)
since, err := parseDateValue(bodyweightsStatsSinceFlag)
if err != nil {
return err
}
until, err := parseUntilValue(bodyweightsStatsUntilFlag)
if err != nil {
return err
}
if printed, err := printResolvedWindow(cmd, since, until); printed || err != nil {
return err
}
entries, err := loadBodyweightEntries(since, until)
if err != nil {
return err
}
Expand Down Expand Up @@ -137,22 +159,13 @@ func init() {
bodyweightsStatsCmd.Flags().StringVar(&bodyweightsStatsFormatFlag, "format", "markdown", "Output format: markdown (default) or json")
}

func loadBodyweightEntries(sinceFlag, untilFlag string) ([]bodyweightEntry, error) {
func loadBodyweightEntries(since, until time.Time) ([]bodyweightEntry, error) {
c := client.New()
var posts []Post
if err := c.Query("post.getMyPosts", nil, &posts); err != nil {
return nil, err
}

since, err := parseDateValue(sinceFlag)
if err != nil {
return nil, err
}
until, err := parseUntilValue(untilFlag)
if err != nil {
return nil, err
}

entries := make([]bodyweightEntry, 0, len(posts))
for _, post := range posts {
weight, err := strconv.ParseFloat(strings.TrimSpace(post.Bodyweight), 64)
Expand Down
28 changes: 28 additions & 0 deletions cmd/resolved_window.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package cmd

import (
"fmt"
"github.com/spf13/cobra"
"time"
)

func init() {
for _, cmd := range []*cobra.Command{listCmd, statsCmd, bodyweightsListCmd, bodyweightsStatsCmd} {
cmd.Flags().Bool("print-resolved-window", false, "Print resolved dates without contacting Liftoff")
}
}

func printResolvedWindow(cmd *cobra.Command, since, until time.Time) (bool, error) {
enabled, err := cmd.Flags().GetBool("print-resolved-window")
if err != nil || !enabled {
return false, err
}
format := func(t time.Time) string {
if t.IsZero() {
return "unbounded"
}
return t.Format(time.RFC3339)
}
_, err = fmt.Fprintf(cmd.OutOrStdout(), "since=%s until_exclusive=%s\n", format(since), format(until))
return true, err
}
35 changes: 35 additions & 0 deletions cmd/resolved_window_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package cmd

import (
"testing"
"time"
)

func TestFilterByWindowIncludesEntireDSTDay(t *testing.T) {
loc, err := time.LoadLocation("America/New_York")
if err != nil {
t.Fatal(err)
}
old := time.Local
time.Local = loc
t.Cleanup(func() { time.Local = old })
for _, tc := range []struct{ day, inside, after string }{
{"2026-03-08", "2026-03-08T23:59:59-04:00", "2026-03-09T00:00:00-04:00"},
{"2026-11-01", "2026-11-01T23:59:59-05:00", "2026-11-02T00:00:00-05:00"},
} {
t.Run(tc.day, func(t *testing.T) {
start, err := parseDateValue(tc.day)
if err != nil {
t.Fatal(err)
}
end, err := parseUntilValue(tc.day)
if err != nil {
t.Fatal(err)
}
got := filterByWindow([]Post{{StartedAt: tc.inside}, {StartedAt: tc.after}}, start, end)
if len(got) != 1 || got[0].StartedAt != tc.inside {
t.Fatalf("filtered posts=%+v", got)
}
})
}
}
13 changes: 8 additions & 5 deletions cmd/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,6 @@ var statsCmd = &cobra.Command{
if err != nil {
return err
}
c := client.New()
var posts []Post
if err := c.Query("post.getMyPosts", nil, &posts); err != nil {
return err
}
since, err := parseDateValue(statsSinceFlag)
if err != nil {
return err
Expand All @@ -60,6 +55,14 @@ var statsCmd = &cobra.Command{
if err != nil {
return err
}
if printed, err := printResolvedWindow(cmd, since, until); printed || err != nil {
return err
}
c := client.New()
var posts []Post
if err := c.Query("post.getMyPosts", nil, &posts); err != nil {
return err
}
posts = filterByWindow(posts, since, until)
if statsExerciseFlag != "" {
posts = filterExercises(posts, statsExerciseFlag)
Expand Down
23 changes: 13 additions & 10 deletions cmd/workouts.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ var workoutsCmd = &cobra.Command{

// SetData mirrors the setsData array items.
type SetData struct {
SetIndex int `json:"setIndex"`
SetType string `json:"setType"`
InputOne json.Number `json:"inputOne"` // weight (kg) or distance
InputTwo json.Number `json:"inputTwo"` // reps or duration (seconds)
SetIndex int `json:"setIndex"`
SetType string `json:"setType"`
InputOne json.Number `json:"inputOne"` // weight (kg) or distance
InputTwo json.Number `json:"inputTwo"` // reps or duration (seconds)
}

// ExerciseData mirrors the exerciseData array items.
Expand Down Expand Up @@ -132,12 +132,6 @@ var listCmd = &cobra.Command{
if err != nil {
return err
}
c := client.New()
var posts []Post
// post.getMyPosts returns all the user's own workouts (Memories view)
if err := c.Query("post.getMyPosts", nil, &posts); err != nil {
return err
}
since, err := parseDateValue(listSinceFlag)
if err != nil {
return err
Expand All @@ -146,6 +140,15 @@ var listCmd = &cobra.Command{
if err != nil {
return err
}
if printed, err := printResolvedWindow(cmd, since, until); printed || err != nil {
return err
}
c := client.New()
var posts []Post
// post.getMyPosts returns all the user's own workouts (Memories view)
if err := c.Query("post.getMyPosts", nil, &posts); err != nil {
return err
}
posts = filterByWindow(posts, since, until)
if listExerciseFlag != "" {
posts = filterExercises(posts, listExerciseFlag)
Expand Down
10 changes: 10 additions & 0 deletions compat_contract_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"testing"

"github.com/quantcli/common/compat"
"github.com/quantcli/common/compat/dates"
"github.com/quantcli/common/compat/formats"
)

Expand Down Expand Up @@ -61,3 +62,12 @@ func TestContractFormats(t *testing.T) {
SkipDataPath: true,
})
}

// TestResolvedWindow verifies local dates independently of upstream credentials.
func TestResolvedWindow(t *testing.T) {
bin := os.Getenv("LIFTOFF_EXPORT_BIN")
if bin == "" {
t.Skip("LIFTOFF_EXPORT_BIN not set")
}
dates.RunResolvedWindow(t, compat.Runner{Binary: bin, Subcommands: []string{"workouts list", "workouts stats", "bodyweights list", "bodyweights stats"}})
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/quantcli/liftoff-export-cli
go 1.26.10

require (
github.com/quantcli/common/compat v0.0.0-20260519113336-de9219e03369
github.com/quantcli/common/compat v0.0.0-20261110001356-0b66a42dfa85
github.com/spf13/cobra v1.10.2
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/quantcli/common/compat v0.0.0-20260519113336-de9219e03369 h1:Ph45Q92vEk4rpcR/NGH/j0oBM9pin2Dk8Rh+Q2mhj3k=
github.com/quantcli/common/compat v0.0.0-20260519113336-de9219e03369/go.mod h1:VBC/zEphSZgCZS1rhWsR3A8EWYSbTkP/MwqWHL7266s=
github.com/quantcli/common/compat v0.0.0-20261110001356-0b66a42dfa85 h1:NxUSVjE+3clP9Ss6uvlwZ0SToE7kmpkioRJ5r8ZUmK4=
github.com/quantcli/common/compat v0.0.0-20261110001356-0b66a42dfa85/go.mod h1:VBC/zEphSZgCZS1rhWsR3A8EWYSbTkP/MwqWHL7266s=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU=
github.com/spf13/cobra v1.10.2/go.mod h1:7C1pvHqHw5A4vrJfjNwvOdzYu0Gml16OCs2GRiTUUS4=
Expand Down
36 changes: 36 additions & 0 deletions resolved_window_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package main_test

import (
"os"
"os/exec"
"path/filepath"
"strings"
"testing"
)

func TestResolvedWindowOffline(t *testing.T) {
bin := filepath.Join(t.TempDir(), "export-cli")
build := exec.Command("go", "build", "-o", bin, ".")
if out, err := build.CombinedOutput(); err != nil {
t.Fatalf("build: %v: %s", err, out)
}
cases := []struct{ zone, day, want string }{
{"Pacific/Honolulu", "2026-04-15", "since=2026-04-15T00:00:00-10:00 until_exclusive=2026-04-16T00:00:00-10:00\n"},
{"Pacific/Kiritimati", "2026-04-15", "since=2026-04-15T00:00:00+14:00 until_exclusive=2026-04-16T00:00:00+14:00\n"},
{"America/New_York", "2026-03-08", "since=2026-03-08T00:00:00-05:00 until_exclusive=2026-03-09T00:00:00-04:00\n"},
{"America/New_York", "2026-11-01", "since=2026-11-01T00:00:00-04:00 until_exclusive=2026-11-02T00:00:00-05:00\n"},
}
for _, sub := range []string{"workouts list", "workouts stats", "bodyweights list", "bodyweights stats"} {
for _, tc := range cases {
t.Run(sub+"/"+tc.zone+"/"+tc.day, func(t *testing.T) {
args := append(strings.Fields(sub), "--since", tc.day, "--until", tc.day, "--print-resolved-window")
cmd := exec.Command(bin, args...)
cmd.Env = []string{"TZ=" + tc.zone, "HOME=" + t.TempDir(), "HTTPS_PROXY=http://127.0.0.1:1", "PATH=" + os.Getenv("PATH")}
out, err := cmd.CombinedOutput()
if err != nil || string(out) != tc.want {
t.Fatalf("output=%q error=%v, want %q", out, err, tc.want)
}
})
}
}
}
Loading