Skip to content

feat: add caching infrastructure for Drive metadata#83

Merged
rianjs merged 2 commits intomainfrom
feat/drive-cache-infrastructure
Jan 27, 2026
Merged

feat: add caching infrastructure for Drive metadata#83
rianjs merged 2 commits intomainfrom
feat/drive-cache-infrastructure

Conversation

@rianjs
Copy link
Copy Markdown
Contributor

@rianjs rianjs commented Jan 27, 2026

Summary

This PR adds caching infrastructure to support fast repeated lookups for Drive API metadata. This is Phase 1 of shared drive support.

Closes #84

New Features

  • Cache package (internal/cache/): TTL-based cache implementation

    • GetDrives() / SetDrives() for storing shared drive lists
    • Clear() to remove all cached data
    • GetStatus() for cache status reporting
    • Automatic expiration based on configurable TTL
  • Cache commands (gro config cache):

    • gro config cache show - display cache status (location, TTL, cached data)
    • gro config cache clear - clear all cached data
    • gro config cache ttl <hours> - update cache TTL
  • Config persistence (internal/config/):

    • Config struct for user settings
    • LoadConfig() / SaveConfig() for persistence
    • Default 24-hour cache TTL
  • Init integration: Cache TTL prompt during gro init setup

Files Changed

File Description
internal/cache/cache.go NEW - Cache implementation
internal/cache/cache_test.go NEW - Cache tests
internal/cmd/config/cache.go NEW - Cache management commands
internal/config/config.go Add Config struct and persistence
internal/cmd/config/config.go Register cache subcommand
internal/cmd/initcmd/init.go Add cache TTL prompt
README.md Document cache configuration

Next Steps

Phase 2 (#85) will add shared drive support that uses this cache for fast name→ID resolution:

  • gro drive drives command to list shared drives
  • --my-drive and --drive <name> flags for list/search/tree commands
  • Search/list across all drives by default

Test plan

  • All tests pass (make test)
  • Lint checks pass (make lint)
  • Cache package has comprehensive unit tests
  • Manual testing: gro init prompts for cache TTL
  • Manual testing: gro config cache show/clear/ttl commands work

- Add test-chocolatey.yml: validates Chocolatey packaging on PRs
- Add test-winget.yml: validates Winget manifest schema on PRs
- Add chocolatey-publish.yml: manual workflow to publish to Chocolatey
- Add winget-publish.yml: manual workflow to publish to Winget
- Add snap/snapcraft.yaml: Snap package definition
- Add snap job to release.yml (disabled, awaiting personal-files approval)
- Migrate Homebrew to goreleaser homebrew_casks (cleaner, includes xattr)
- Remove manual update-homebrew job from release.yml
Add a caching layer to support fast repeated lookups for Drive API metadata
(shared drive lists, etc). This is Phase 1 of shared drive support.

New files:
- internal/cache/cache.go: TTL-based cache implementation with GetDrives,
  SetDrives, Clear, and GetStatus methods
- internal/cache/cache_test.go: Comprehensive tests for cache package
- internal/cmd/config/cache.go: Cache management commands (show, clear, ttl)

Modified files:
- internal/config/config.go: Add Config struct, LoadConfig, SaveConfig,
  GetCacheTTL functions for persisting user settings
- internal/cmd/config/config.go: Register cache subcommand
- internal/cmd/initcmd/init.go: Add cache TTL prompt during setup
- README.md: Document cache configuration and commands

Features:
- Configurable cache TTL (default 24 hours) set during `gro init`
- `gro config cache show` - display cache status
- `gro config cache clear` - clear all cached data
- `gro config cache ttl <hours>` - update cache TTL
- Cache stored in ~/.config/google-readonly/cache/
- Automatic expiration based on TTL
@rianjs rianjs force-pushed the feat/drive-cache-infrastructure branch from 7a2ead0 to f77d74d Compare January 27, 2026 11:16
@rianjs rianjs merged commit 0baa278 into main Jan 27, 2026
4 checks passed
@rianjs
Copy link
Copy Markdown
Contributor Author

rianjs commented Jan 27, 2026

TDD Assessment: Test Coverage for Caching Infrastructure

I reviewed the test coverage for the changes introduced in this PR. Here's the assessment:

Coverage Summary

Package Coverage
internal/cache 90.0%
internal/config 33.3% ⚠️
internal/cmd/config 15.0%
internal/cmd/initcmd 14.0% (unchanged logic)

What's Well Tested

internal/cache/cache.go - Excellent coverage (90%)

  • New() - 77.8%
  • GetDrives() - 92.3%
  • SetDrives() - 83.3%
  • Clear() - 100%
  • GetStatus() - 100%
  • GetDir() - 100%

The cache package has comprehensive tests covering:

  • Cache creation with default and custom TTL
  • Get/Set operations for drives
  • Cache expiration behavior
  • Corrupted cache handling (graceful degradation)
  • Cache clearing
  • Status reporting

Gaps Requiring Tests

internal/config/config.go - New functions at 0% coverage:

  • GetConfigPath() - 0%
  • LoadConfig() - 0%
  • SaveConfig() - 0%
  • GetCacheTTL() - 0%
  • GetCacheTTLHours() - 0%

These are critical config management functions that should be tested.

internal/cmd/config/cache.go - New cache commands at ~10% coverage:

  • newCacheShowCommand() - 14.3%
  • newCacheClearCommand() - 9.1%
  • newCacheTTLCommand() - 8.3%

The RunE handlers are untested. While testing Cobra command handlers can be more involved, at minimum the command structure, flags, and argument validation should be tested.

Recommendation

Not sufficient for TDD approach. The cache package itself is well-tested, but the supporting infrastructure (config functions, cache commands) lacks adequate coverage.

Suggested additions:

  1. Add tests for LoadConfig(), SaveConfig(), GetCacheTTL(), GetCacheTTLHours() in internal/config/config_test.go
  2. Add tests for the cache subcommands in internal/cmd/config/config_test.go - at minimum testing command structure and flag validation

These tests would bring the overall coverage to an acceptable level for confident refactoring and maintenance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: add caching infrastructure for Drive metadata

1 participant