Skip to content

Add unit tests for the agentic decision cache (Get/Put/eviction/concurrency) #1

Description

@deepintai

Context

The agentic framework's decision cache is a hot-path component that provides O(1) reuse of ABAC policy decisions, but the entire deepintshield_server/framework/agentic/ package currently has no *_test.go files. This makes the cache a high-value, self-contained target for a first contribution: the public surface is small and the behavior is easy to assert without external services.

The implementation is:

type DecisionCache struct { ... }
func NewDecisionCache(maxSize int) *DecisionCache
func (c *DecisionCache) Get(key string) (Decision, bool)
func (c *DecisionCache) Put(key string, decision Decision, ttl time.Duration)
func (c *DecisionCache) InvalidateTenant(tenant string)
func (c *DecisionCache) Stats() CacheStats

What to do

Create deepintshield_server/framework/agentic/decision_cache_test.go with table-driven tests covering:

  1. Hit / miss: Put then Get the same key returns the stored Decision and ok=true; an unknown key returns ok=false.
  2. TTL expiry: an entry stored with a short TTL is no longer returned after it expires.
  3. Eviction: once maxSize is exceeded, the oldest/least-recently-used entry is dropped (verify it misses while newer entries hit).
  4. InvalidateTenant: entries for a given tenant are removed while other tenants' entries survive.
  5. Stats: hit/miss counters reported by Stats() reflect the operations performed.
  6. Concurrency: run many goroutines doing Get/Put under go test -race with no data races or panics.
  7. Edge cases: zero/negative maxSize, empty key.

Acceptance criteria

  • New file deepintshield_server/framework/agentic/decision_cache_test.go.
  • go test -race ./agentic/... (run from deepintshield_server/framework) passes.
  • At least 7 test cases/functions, each asserting one behavior.
  • No new production-code changes required (tests only).
  • CI passes per the test instructions in CONTRIBUTING.md.

File pointers

  • Implementation: deepintshield_server/framework/agentic/decision_cache.go (NewDecisionCache:33, Get:49, Put:69, InvalidateTenant:85, Stats:116)
  • How the cache is used: deepintshield_server/framework/agentic/decide.go (Decide at line ~285)
  • Test-style reference: deepintshield_server/plugins/guardrails/request_guardrails_test.go

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions