mirror of
https://github.com/AmanTahiliani/box-box.git
synced 2026-08-08 04:06:18 -04:00
Compare commits
1 Commits
feat/issue
...
feat/issue
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8fd358748d |
@@ -24,7 +24,7 @@ bin/dev CLI: `dev implement <issue#> --harness <name> [--dry-run]`
|
|||||||
- **Groom** (interactive, Claude): `/groom <issue#>` runs a seeded grill-me → writes a
|
- **Groom** (interactive, Claude): `/groom <issue#>` runs a seeded grill-me → writes a
|
||||||
Ready spec into the issue body → sets Effort/Priority → leaves Stage at `Research`.
|
Ready spec into the issue body → sets Effort/Priority → leaves Stage at `Research`.
|
||||||
You review and flip to `Ready`.
|
You review and flip to `Ready`.
|
||||||
- **Implement** (any harness): `.agents/bin/dev implement <issue#> --harness <name>`
|
- **Implement** (recommended harnesses: `codex` or `cursor`): `.agents/bin/dev implement <issue#> --harness <name>`
|
||||||
(or `/implement …` in Claude to supervise) → isolated worktree → runs the harness
|
(or `/implement …` in Claude to supervise) → isolated worktree → runs the harness
|
||||||
headless on the spec → build gate → opens a PR → sets Stage `In Review`.
|
headless on the spec → build gate → opens a PR → sets Stage `In Review`.
|
||||||
- **Review + merge**: use the `review` skill from a harness different from the
|
- **Review + merge**: use the `review` skill from a harness different from the
|
||||||
@@ -42,8 +42,17 @@ local adapter state.
|
|||||||
## Adding / fixing a harness
|
## Adding / fixing a harness
|
||||||
|
|
||||||
Edit one function in `harnesses.sh`: `harness_<name> <workdir> <promptfile>`, running the
|
Edit one function in `harnesses.sh`: `harness_<name> <workdir> <promptfile>`, running the
|
||||||
tool non-interactively in `<workdir>` on the prompt. `claude`/`codex`/`opencode` are
|
tool non-interactively in `<workdir>` on the prompt. For current implementation
|
||||||
wired; `pi`/`cursor` are stubs — confirm their headless flags before trusting.
|
dispatch, prefer `codex` or `cursor`; `claude` and `opencode` remain available, and
|
||||||
|
`pi` still needs flag verification before trusting.
|
||||||
|
|
||||||
|
`agy` / Antigravity is deliberately disabled for non-dry-run dispatch as of
|
||||||
|
2026-07-04. Phase 1 testing found the headless path unreliable: with
|
||||||
|
`--new-project` it ignored the prompt and tried to scaffold, while without it the CLI
|
||||||
|
could resume a stale conversation and hang past the print timeout. Keep using
|
||||||
|
`.agents/bin/dev implement <issue#> --harness agy --dry-run` for prompt inspection
|
||||||
|
only; real dispatch should use `codex` or `cursor` until a fresh Antigravity
|
||||||
|
headless invocation is verified and documented.
|
||||||
|
|
||||||
Always `--dry-run` a new harness first: it renders the exact prompt and plan, touching
|
Always `--dry-run` a new harness first: it renders the exact prompt and plan, touching
|
||||||
nothing (no worktree, PR, or state change).
|
nothing (no worktree, PR, or state change).
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# .agents/bin/dev — box-box agentic dev CLI. Works from any harness's shell.
|
# .agents/bin/dev — box-box agentic dev CLI. Works from any harness's shell.
|
||||||
#
|
#
|
||||||
# dev implement <issue#> --harness <claude|codex|opencode|pi|cursor> [--dry-run] [--base <branch>]
|
# dev implement <issue#> --harness <codex|cursor|claude|opencode|pi|agy> [--dry-run] [--base <branch>]
|
||||||
#
|
#
|
||||||
# Grooming is driven interactively via the Claude Code /groom skill; this CLI covers
|
# Grooming is driven interactively via the Claude Code /groom skill; this CLI covers
|
||||||
# the implement lane (dispatch a Ready issue to a harness → worktree → gate → PR).
|
# the implement lane (dispatch a Ready issue to a harness → worktree → gate → PR).
|
||||||
@@ -15,7 +15,7 @@ box-box dev CLI
|
|||||||
|
|
||||||
dev implement <issue#> --harness <name> [--dry-run] [--base <branch>]
|
dev implement <issue#> --harness <name> [--dry-run] [--base <branch>]
|
||||||
|
|
||||||
harnesses: claude, codex, opencode (supported) · pi, cursor (verify flags in .agents/harnesses.sh)
|
harnesses: codex, cursor (recommended) · claude, opencode (available) · agy (dry-run only, disabled for dispatch) · pi (verify flags)
|
||||||
--dry-run render the prompt + plan, touch nothing (no worktree/PR/state change)
|
--dry-run render the prompt + plan, touch nothing (no worktree/PR/state change)
|
||||||
--base base branch for the worktree/PR (default: main)
|
--base base branch for the worktree/PR (default: main)
|
||||||
EOF
|
EOF
|
||||||
|
|||||||
@@ -11,6 +11,18 @@
|
|||||||
|
|
||||||
# ---- MUST-HAVE ----
|
# ---- MUST-HAVE ----
|
||||||
|
|
||||||
|
harness_disabled_reason() { # <name> -> reason on stdout; 0 means disabled
|
||||||
|
case "$1" in
|
||||||
|
agy)
|
||||||
|
cat <<'EOF'
|
||||||
|
agy is disabled for implementation dispatch as of 2026-07-04: Antigravity headless mode was observed to ignore prompts with --new-project, resume stale conversations without it, and hang past print timeouts. Use codex or cursor until a fresh headless invocation is verified.
|
||||||
|
EOF
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
*) return 1 ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
harness_claude() { # Claude Code — print mode, auto-accept edits
|
harness_claude() { # Claude Code — print mode, auto-accept edits
|
||||||
local dir="$1" prompt="$2"
|
local dir="$1" prompt="$2"
|
||||||
( cd "$dir" && claude -p "$(cat "$prompt")" --permission-mode acceptEdits )
|
( cd "$dir" && claude -p "$(cat "$prompt")" --permission-mode acceptEdits )
|
||||||
@@ -31,14 +43,11 @@ harness_cursor() { # Cursor CLI agent — composer-2.5, hea
|
|||||||
( cd "$dir" && cursor-agent -p "$(cat "$prompt")" --model composer-2.5 --force --trust )
|
( cd "$dir" && cursor-agent -p "$(cat "$prompt")" --model composer-2.5 --force --trust )
|
||||||
}
|
}
|
||||||
|
|
||||||
harness_agy() { # Antigravity CLI — UNRELIABLE headless (2026-07): with
|
harness_agy() { # Antigravity CLI — disabled until headless is verified
|
||||||
# --new-project it ignores the prompt and asks to scaffold a project; without it, it
|
local reason
|
||||||
# resumes the previous conversation (silently keeping its old model — --model only
|
reason="$(harness_disabled_reason agy)"
|
||||||
# applies to new conversations) and can hang past the print timeout. Do not trust for
|
echo "harness_agy: $reason" >&2
|
||||||
# dispatch until fixed upstream; verify with a trivial prompt first.
|
return 2
|
||||||
local dir="$1" prompt="$2"
|
|
||||||
( cd "$dir" && agy --print --print-timeout 60m \
|
|
||||||
--model="Gemini 3.1 Pro (High)" --dangerously-skip-permissions "$(cat "$prompt")" )
|
|
||||||
}
|
}
|
||||||
|
|
||||||
# ---- NICE-TO-HAVE (verify the exact invocation for your version before trusting) ----
|
# ---- NICE-TO-HAVE (verify the exact invocation for your version before trusting) ----
|
||||||
|
|||||||
@@ -52,6 +52,15 @@ dispatch() { # <issue#> <harness> [--dry-run] [--base <branch>]
|
|||||||
if ! declare -f "harness_$harness" >/dev/null 2>&1; then
|
if ! declare -f "harness_$harness" >/dev/null 2>&1; then
|
||||||
echo "no adapter for harness '$harness' — add harness_$harness() to .agents/harnesses.sh" >&2; return 2
|
echo "no adapter for harness '$harness' — add harness_$harness() to .agents/harnesses.sh" >&2; return 2
|
||||||
fi
|
fi
|
||||||
|
if [ "$dry" != 1 ] && declare -f harness_disabled_reason >/dev/null 2>&1; then
|
||||||
|
local disabled_reason
|
||||||
|
if disabled_reason="$(harness_disabled_reason "$harness")"; then
|
||||||
|
echo "harness '$harness' is disabled for non-dry-run dispatch." >&2
|
||||||
|
echo " $disabled_reason" >&2
|
||||||
|
echo " Use --dry-run for prompt inspection, or dispatch with --harness codex/cursor." >&2
|
||||||
|
return 2
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
local repo_root title body slug branch wt prompt
|
local repo_root title body slug branch wt prompt
|
||||||
repo_root="$(git rev-parse --show-toplevel)" || return 1
|
repo_root="$(git rev-parse --show-toplevel)" || return 1
|
||||||
|
|||||||
59
.agents/test/dispatch_disabled_harness_test.sh
Executable file
59
.agents/test/dispatch_disabled_harness_test.sh
Executable file
@@ -0,0 +1,59 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
|
||||||
|
cd "$ROOT"
|
||||||
|
|
||||||
|
# shellcheck source=/dev/null
|
||||||
|
source "$ROOT/.agents/lib/dispatch.sh"
|
||||||
|
|
||||||
|
issue_title() { echo "Disable agy harness smoke"; }
|
||||||
|
issue_body() { echo "## Spec"; echo; echo "Smoke prompt body"; }
|
||||||
|
get_field() { echo "Ready"; }
|
||||||
|
set_stage() { echo "unexpected set_stage $*" >&2; return 99; }
|
||||||
|
run_gate() { echo "unexpected run_gate $*" >&2; return 99; }
|
||||||
|
|
||||||
|
unexpected_git_file="$(mktemp "${TMPDIR:-/tmp}/boxbox-agy-git.XXXX")"
|
||||||
|
rm -f "$unexpected_git_file"
|
||||||
|
git() {
|
||||||
|
if [ "${1:-}" = "rev-parse" ]; then
|
||||||
|
command git "$@"
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
echo "unexpected git $*" >&2
|
||||||
|
touch "$unexpected_git_file"
|
||||||
|
return 99
|
||||||
|
}
|
||||||
|
|
||||||
|
set +e
|
||||||
|
non_dry_output="$(dispatch 47 agy 2>&1)"
|
||||||
|
non_dry_status=$?
|
||||||
|
set -e
|
||||||
|
|
||||||
|
[ "$non_dry_status" -eq 2 ] || {
|
||||||
|
echo "expected agy non-dry-run to exit 2, got $non_dry_status" >&2
|
||||||
|
echo "$non_dry_output" >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
[[ "$non_dry_output" == *"harness 'agy' is disabled"* ]] || {
|
||||||
|
echo "expected disabled-harness message" >&2
|
||||||
|
echo "$non_dry_output" >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
[ ! -e "$unexpected_git_file" ] || {
|
||||||
|
echo "agy non-dry-run reached git before failing" >&2
|
||||||
|
echo "$non_dry_output" >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
dry_output="$(dispatch 47 agy --dry-run 2>&1)"
|
||||||
|
[[ "$dry_output" == *"[dry-run] no worktree / harness / PR / state change"* ]] || {
|
||||||
|
echo "expected agy dry-run to render dispatch preview" >&2
|
||||||
|
echo "$dry_output" >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
[[ "$dry_output" == *"Smoke prompt body"* ]] || {
|
||||||
|
echo "expected agy dry-run prompt body" >&2
|
||||||
|
echo "$dry_output" >&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
42
cmd/main.go
42
cmd/main.go
@@ -27,7 +27,6 @@ func main() {
|
|||||||
ingestMeeting := flag.Int("ingest-meeting", 0, "Ingest meeting metadata and Race Hub datasets for all sessions")
|
ingestMeeting := flag.Int("ingest-meeting", 0, "Ingest meeting metadata and Race Hub datasets for all sessions")
|
||||||
ingestSession := flag.Int("ingest-session", 0, "Ingest Race Hub datasets for a session key")
|
ingestSession := flag.Int("ingest-session", 0, "Ingest Race Hub datasets for a session key")
|
||||||
ingestNews := flag.Bool("ingest-news", false, "Refresh RSS/Atom paddock briefing feeds")
|
ingestNews := flag.Bool("ingest-news", false, "Refresh RSS/Atom paddock briefing feeds")
|
||||||
prefetchTrackOutlines := flag.Int("prefetch-track-outlines", 0, "Warm the web track-outline cache for a season year (for web-only hosts, run before --web so /api/v1/track-outline can serve live maps)")
|
|
||||||
dryRun := flag.Bool("dry-run", false, "Preview ingestion without writing domain rows")
|
dryRun := flag.Bool("dry-run", false, "Preview ingestion without writing domain rows")
|
||||||
force := flag.Bool("force", false, "Re-ingest datasets even if already tracked in the session_coverage table as completed")
|
force := flag.Bool("force", false, "Re-ingest datasets even if already tracked in the session_coverage table as completed")
|
||||||
coverageYear := flag.Int("coverage", 0, "Show season coverage report for the given year")
|
coverageYear := flag.Int("coverage", 0, "Show season coverage report for the given year")
|
||||||
@@ -77,21 +76,11 @@ func main() {
|
|||||||
if *ingestNews {
|
if *ingestNews {
|
||||||
ingestFlags++
|
ingestFlags++
|
||||||
}
|
}
|
||||||
if *prefetchTrackOutlines != 0 {
|
|
||||||
ingestFlags++
|
|
||||||
}
|
|
||||||
if ingestFlags > 0 {
|
if ingestFlags > 0 {
|
||||||
if ingestFlags > 1 {
|
if ingestFlags > 1 {
|
||||||
fmt.Fprintln(os.Stderr, "box-box: only one of --ingest-year, --backfill-season, --ingest-meeting, --ingest-session, --ingest-news, or --prefetch-track-outlines may be set")
|
fmt.Fprintln(os.Stderr, "box-box: only one of --ingest-year, --backfill-season, --ingest-meeting, --ingest-session, or --ingest-news may be set")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
if *prefetchTrackOutlines != 0 {
|
|
||||||
if err := runTrackOutlinePrefetch(client, *prefetchTrackOutlines); err != nil {
|
|
||||||
fmt.Fprintf(os.Stderr, "box-box track outline prefetch error: %v\n", err)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if *ingestNews {
|
if *ingestNews {
|
||||||
if err := runNewsIngestion(*dryRun, *dbPath); err != nil {
|
if err := runNewsIngestion(*dryRun, *dbPath); err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "box-box ingest error: %v\n", err)
|
fmt.Fprintf(os.Stderr, "box-box ingest error: %v\n", err)
|
||||||
@@ -185,35 +174,6 @@ func runIngestion(client *api.OpenF1Client, year, meetingKey, sessionKey int, fo
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func runTrackOutlinePrefetch(client *api.OpenF1Client, year int) error {
|
|
||||||
log.SetOutput(os.Stderr)
|
|
||||||
|
|
||||||
fmt.Fprintf(os.Stderr, "track outlines: warming HTTP cache %s for %d\n", api.DefaultCacheDBPath(), year)
|
|
||||||
|
|
||||||
meetings, err := client.GetMeetingsForYear(year)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("fetch meetings for %d: %w", year, err)
|
|
||||||
}
|
|
||||||
|
|
||||||
result := client.PrefetchTrackOutlinesForYear(year, meetings)
|
|
||||||
fmt.Printf(
|
|
||||||
"track outlines %d: cached %d/%d unique circuit(s) before, %d/%d after; %d skipped, %d fetched, %d failed\n",
|
|
||||||
result.Year,
|
|
||||||
result.CachedBefore,
|
|
||||||
result.UniqueCircuits,
|
|
||||||
result.CachedAfter,
|
|
||||||
result.UniqueCircuits,
|
|
||||||
result.Skipped,
|
|
||||||
result.Fetched,
|
|
||||||
result.Failed,
|
|
||||||
)
|
|
||||||
|
|
||||||
if result.CachedAfter == 0 {
|
|
||||||
return fmt.Errorf("cached zero track outlines for %d", year)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func runNewsIngestion(dryRun bool, dbPath string) error {
|
func runNewsIngestion(dryRun bool, dbPath string) error {
|
||||||
log.SetOutput(os.Stderr)
|
log.SetOutput(os.Stderr)
|
||||||
|
|
||||||
|
|||||||
@@ -94,12 +94,6 @@ func cacheDBPath() string {
|
|||||||
return filepath.Join(".cache", "box-box", "cache.db")
|
return filepath.Join(".cache", "box-box", "cache.db")
|
||||||
}
|
}
|
||||||
|
|
||||||
// DefaultCacheDBPath returns the HTTP cache database path used by the OpenF1
|
|
||||||
// client in both TUI and web modes.
|
|
||||||
func DefaultCacheDBPath() string {
|
|
||||||
return cacheDBPath()
|
|
||||||
}
|
|
||||||
|
|
||||||
// ttlForURL determines the appropriate TTL based on the URL pattern.
|
// ttlForURL determines the appropriate TTL based on the URL pattern.
|
||||||
// Returns 0 (CacheTTLForever) for historical data that will never change.
|
// Returns 0 (CacheTTLForever) for historical data that will never change.
|
||||||
func ttlForURL(url string) time.Duration {
|
func ttlForURL(url string) time.Duration {
|
||||||
|
|||||||
@@ -623,19 +623,6 @@ func (c *OpenF1Client) GetTeamRadio(sessionKey, driverNumber int) ([]models.Team
|
|||||||
// to maximise the chance of finding data quickly.
|
// to maximise the chance of finding data quickly.
|
||||||
var candidateDrivers = []int{1, 11, 44, 16, 55, 4, 14, 63, 81, 24}
|
var candidateDrivers = []int{1, 11, 44, 16, 55, 4, 14, 63, 81, 24}
|
||||||
|
|
||||||
// TrackOutlinePrefetchResult summarizes a season track-outline cache warming
|
|
||||||
// run. Counts are scoped to the unique non-zero circuit keys in the provided
|
|
||||||
// meeting list.
|
|
||||||
type TrackOutlinePrefetchResult struct {
|
|
||||||
Year int
|
|
||||||
UniqueCircuits int
|
|
||||||
CachedBefore int
|
|
||||||
CachedAfter int
|
|
||||||
Skipped int
|
|
||||||
Fetched int
|
|
||||||
Failed int
|
|
||||||
}
|
|
||||||
|
|
||||||
// PrefetchTrackOutlines fetches GPS location data for every circuit in the
|
// PrefetchTrackOutlines fetches GPS location data for every circuit in the
|
||||||
// provided meeting list and stores it in the cache so the track map tab can
|
// provided meeting list and stores it in the cache so the track map tab can
|
||||||
// render during live sessions when the free-tier API is locked.
|
// render during live sessions when the free-tier API is locked.
|
||||||
@@ -645,58 +632,28 @@ type TrackOutlinePrefetchResult struct {
|
|||||||
// Errors per-circuit are silently ignored — this is a best-effort operation
|
// Errors per-circuit are silently ignored — this is a best-effort operation
|
||||||
// and must never block or crash the main UI.
|
// and must never block or crash the main UI.
|
||||||
func (c *OpenF1Client) PrefetchTrackOutlines(meetings []models.Meeting) {
|
func (c *OpenF1Client) PrefetchTrackOutlines(meetings []models.Meeting) {
|
||||||
year := time.Now().Year()
|
|
||||||
for _, m := range meetings {
|
|
||||||
if m.Year != 0 {
|
|
||||||
year = m.Year
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
_ = c.PrefetchTrackOutlinesForYear(year, meetings)
|
|
||||||
}
|
|
||||||
|
|
||||||
// PrefetchTrackOutlinesForYear fetches and caches track outlines for unique
|
|
||||||
// circuits in the provided meeting list, storing them under the explicit season
|
|
||||||
// year. Unlike PrefetchTrackOutlines, it returns accounting suitable for CLI
|
|
||||||
// cache-warming workflows.
|
|
||||||
func (c *OpenF1Client) PrefetchTrackOutlinesForYear(year int, meetings []models.Meeting) TrackOutlinePrefetchResult {
|
|
||||||
const maxWorkers = 3
|
const maxWorkers = 3
|
||||||
|
|
||||||
result := TrackOutlinePrefetchResult{Year: year}
|
year := time.Now().Year()
|
||||||
uniqueByCircuit := make(map[int]models.Meeting)
|
|
||||||
var unique []models.Meeting
|
// Filter to meetings that need fetching.
|
||||||
|
var pending []models.Meeting
|
||||||
for _, m := range meetings {
|
for _, m := range meetings {
|
||||||
if m.CircuitKey == 0 {
|
if m.CircuitKey == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if _, exists := uniqueByCircuit[m.CircuitKey]; exists {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
uniqueByCircuit[m.CircuitKey] = m
|
|
||||||
unique = append(unique, m)
|
|
||||||
}
|
|
||||||
|
|
||||||
result.UniqueCircuits = len(unique)
|
|
||||||
|
|
||||||
// Filter to meetings that need fetching.
|
|
||||||
var pending []models.Meeting
|
|
||||||
for _, m := range unique {
|
|
||||||
if _, ok := c.cache.GetTrackOutline(m.CircuitKey, year); ok {
|
if _, ok := c.cache.GetTrackOutline(m.CircuitKey, year); ok {
|
||||||
result.CachedBefore++
|
|
||||||
result.Skipped++
|
|
||||||
continue // already cached for this season
|
continue // already cached for this season
|
||||||
}
|
}
|
||||||
pending = append(pending, m)
|
pending = append(pending, m)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(pending) == 0 {
|
if len(pending) == 0 {
|
||||||
result.CachedAfter = result.CachedBefore
|
return
|
||||||
return result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sem := make(chan struct{}, maxWorkers)
|
sem := make(chan struct{}, maxWorkers)
|
||||||
var wg sync.WaitGroup
|
var wg sync.WaitGroup
|
||||||
var mu sync.Mutex
|
|
||||||
|
|
||||||
for _, mtg := range pending {
|
for _, mtg := range pending {
|
||||||
mtg := mtg // capture
|
mtg := mtg // capture
|
||||||
@@ -705,34 +662,19 @@ func (c *OpenF1Client) PrefetchTrackOutlinesForYear(year int, meetings []models.
|
|||||||
go func() {
|
go func() {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
defer func() { <-sem }()
|
defer func() { <-sem }()
|
||||||
ok := c.prefetchCircuit(mtg, year)
|
c.prefetchCircuit(mtg, year)
|
||||||
mu.Lock()
|
|
||||||
if ok {
|
|
||||||
result.Fetched++
|
|
||||||
} else {
|
|
||||||
result.Failed++
|
|
||||||
}
|
|
||||||
mu.Unlock()
|
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
|
||||||
for _, m := range unique {
|
|
||||||
if _, ok := c.cache.GetTrackOutline(m.CircuitKey, year); ok {
|
|
||||||
result.CachedAfter++
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// prefetchCircuit fetches the track outline for a single meeting and stores it.
|
// prefetchCircuit fetches the track outline for a single meeting and stores it.
|
||||||
// It prefers completed sessions (past date_end) so the data is full and stable.
|
// It prefers completed sessions (past date_end) so the data is full and stable.
|
||||||
func (c *OpenF1Client) prefetchCircuit(mtg models.Meeting, year int) bool {
|
func (c *OpenF1Client) prefetchCircuit(mtg models.Meeting, year int) {
|
||||||
sessions, err := c.GetSessionsForMeeting(int(mtg.MeetingKey))
|
sessions, err := c.GetSessionsForMeeting(int(mtg.MeetingKey))
|
||||||
if err != nil || len(sessions) == 0 {
|
if err != nil || len(sessions) == 0 {
|
||||||
return false
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pick the best session: prefer a completed race, then any session with
|
// Pick the best session: prefer a completed race, then any session with
|
||||||
@@ -754,7 +696,7 @@ func (c *OpenF1Client) prefetchCircuit(mtg models.Meeting, year int) bool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if bestSession == nil {
|
if bestSession == nil {
|
||||||
return false
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try candidate drivers in order until we find one with enough points.
|
// Try candidate drivers in order until we find one with enough points.
|
||||||
@@ -764,7 +706,7 @@ func (c *OpenF1Client) prefetchCircuit(mtg models.Meeting, year int) bool {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// Store under the circuit key for this year and stop.
|
// Store under the circuit key for this year and stop.
|
||||||
return c.cache.SetTrackOutline(mtg.CircuitKey, year, locs) == nil
|
_ = c.cache.SetTrackOutline(mtg.CircuitKey, year, locs)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,109 +0,0 @@
|
|||||||
package api
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"net/http"
|
|
||||||
"net/http/httptest"
|
|
||||||
"strconv"
|
|
||||||
"testing"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/AmanTahiliani/box-box/internal/models"
|
|
||||||
)
|
|
||||||
|
|
||||||
func newTrackOutlineTestClient(t *testing.T, srvURL string) *OpenF1Client {
|
|
||||||
t.Helper()
|
|
||||||
t.Setenv("HOME", t.TempDir())
|
|
||||||
t.Setenv("XDG_CACHE_HOME", t.TempDir())
|
|
||||||
|
|
||||||
c := NewOpenF1Client(srvURL, 5*time.Second)
|
|
||||||
c.pacer = &requestPacer{}
|
|
||||||
t.Cleanup(func() { _ = c.Close() })
|
|
||||||
return c
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestPrefetchTrackOutlinesForYearSkipsCachedAndWritesLocations(t *testing.T) {
|
|
||||||
var sessionsByMeeting = map[string][]models.Session{
|
|
||||||
"202": {
|
|
||||||
{
|
|
||||||
SessionKey: 9002,
|
|
||||||
SessionName: "Race",
|
|
||||||
MeetingKey: 202,
|
|
||||||
CircuitKey: 2,
|
|
||||||
DateEnd: "2026-01-01T12:00:00+00:00",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
var sessionsRequested []string
|
|
||||||
var locationsRequested []string
|
|
||||||
|
|
||||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
switch r.URL.Path {
|
|
||||||
case "/v1/sessions":
|
|
||||||
meetingKey := r.URL.Query().Get("meeting_key")
|
|
||||||
sessionsRequested = append(sessionsRequested, meetingKey)
|
|
||||||
_ = json.NewEncoder(w).Encode(sessionsByMeeting[meetingKey])
|
|
||||||
case "/v1/location":
|
|
||||||
sessionKey := r.URL.Query().Get("session_key")
|
|
||||||
driverNumber := r.URL.Query().Get("driver_number")
|
|
||||||
locationsRequested = append(locationsRequested, sessionKey+"/"+driverNumber)
|
|
||||||
_ = json.NewEncoder(w).Encode(testLocations(9002, 1, 51))
|
|
||||||
default:
|
|
||||||
t.Fatalf("unexpected request path %s", r.URL.Path)
|
|
||||||
}
|
|
||||||
}))
|
|
||||||
defer srv.Close()
|
|
||||||
|
|
||||||
client := newTrackOutlineTestClient(t, srv.URL)
|
|
||||||
if err := client.Cache().SetTrackOutline(1, 2026, testLocations(9001, 1, 51)); err != nil {
|
|
||||||
t.Fatalf("SetTrackOutline() error = %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
result := client.PrefetchTrackOutlinesForYear(2026, []models.Meeting{
|
|
||||||
{MeetingKey: 101, Year: 2026, Circuit: models.Circuit{CircuitKey: 1}},
|
|
||||||
{MeetingKey: 202, Year: 2026, Circuit: models.Circuit{CircuitKey: 2}},
|
|
||||||
{MeetingKey: 303, Year: 2026, Circuit: models.Circuit{CircuitKey: 2}},
|
|
||||||
})
|
|
||||||
|
|
||||||
if result.UniqueCircuits != 2 {
|
|
||||||
t.Fatalf("UniqueCircuits = %d, want 2", result.UniqueCircuits)
|
|
||||||
}
|
|
||||||
if result.CachedBefore != 1 || result.Skipped != 1 || result.Fetched != 1 || result.Failed != 0 || result.CachedAfter != 2 {
|
|
||||||
t.Fatalf("unexpected result: %+v", result)
|
|
||||||
}
|
|
||||||
if got, want := len(sessionsRequested), 1; got != want {
|
|
||||||
t.Fatalf("sessions requested %d time(s), want %d: %v", got, want, sessionsRequested)
|
|
||||||
}
|
|
||||||
if sessionsRequested[0] != "202" {
|
|
||||||
t.Fatalf("requested meeting %s, want 202", sessionsRequested[0])
|
|
||||||
}
|
|
||||||
if got, want := len(locationsRequested), 1; got != want {
|
|
||||||
t.Fatalf("locations requested %d time(s), want %d: %v", got, want, locationsRequested)
|
|
||||||
}
|
|
||||||
if locationsRequested[0] != "9002/1" {
|
|
||||||
t.Fatalf("requested location %s, want 9002/1", locationsRequested[0])
|
|
||||||
}
|
|
||||||
|
|
||||||
locs, ok := client.Cache().GetTrackOutline(2, 2026)
|
|
||||||
if !ok {
|
|
||||||
t.Fatal("expected circuit 2 outline to be cached")
|
|
||||||
}
|
|
||||||
if len(locs) != 51 {
|
|
||||||
t.Fatalf("cached %d locations, want 51", len(locs))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func testLocations(sessionKey, driverNumber, count int) []models.Location {
|
|
||||||
locs := make([]models.Location, count)
|
|
||||||
for i := range locs {
|
|
||||||
locs[i] = models.Location{
|
|
||||||
Date: "2026-01-01T12:00:" + strconv.Itoa(i%60) + "+00:00",
|
|
||||||
DriverNumber: driverNumber,
|
|
||||||
MeetingKey: 202,
|
|
||||||
SessionKey: sessionKey,
|
|
||||||
X: float64(i),
|
|
||||||
Y: float64(i * 2),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return locs
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user