Skip to content

Add unit tests for hallucination-control scoring (splitSentencesFast, computeHallucControlImprovement) #3

Description

@deepintai

Context

The semantic cache plugin computes a hallucination-control "improvement" score (based on hedging language and citation density) that drives a dashboard metric. The two core helpers, splitSentencesFast() and computeHallucControlImprovement(), have no test coverage — the deepintshield_server/plugins/semanticcache/ package has no *_test.go files. Both functions are pure and dependency-free, making them ideal for a first contribution.

What to do

Create deepintshield_server/plugins/semanticcache/hallucination_control_test.go covering:

  1. splitSentencesFast(s string) []string (line ~328): sentence boundaries on ., !, ?, and newlines; empty string; single word with no terminator; trailing/leading whitespace.
  2. computeHallucControlImprovement(response string) float64 (line ~293):
    • Response full of hedging language vs. one with none.
    • Response with citations (e.g. [source: ...], https://... URLs) vs. none.
    • Mixed hedging + citations.
    • Empty string returns a sane value.
    • Assert the result is always within [0, 1].

Acceptance criteria

  • New file deepintshield_server/plugins/semanticcache/hallucination_control_test.go.
  • Both functions exercised, including empty/whitespace/single-sentence edge cases.
  • Every returned score asserted to be in [0, 1].
  • go test ./... for the plugin passes locally with no external dependencies.
  • Follows existing Go test conventions used elsewhere in the repo.

File pointers

  • Implementation: deepintshield_server/plugins/semanticcache/hallucination_control.go
    • computeHallucControlImprovement at line ~293
    • splitSentencesFast at line ~328
  • Test-style reference: deepintshield_server/plugins/guardrails/cache_reuse_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