Skip to content

test(aifirewall): property tests for Plan and ValidateGuardrail; plan server maps in key order - #326

Merged
0x73746F66 merged 1 commit into
mainfrom
fix/222-aifirewall-plan-properties
Nov 13, 2026
Merged

0x73746F66 merged 1 commit into
mainfrom
fix/222-aifirewall-plan-properties

Conversation

@0x73746F66

Copy link
Copy Markdown
Member

Closes #222

What

New pkg/aifirewall/plan_property_test.go (stdlib testing/quick, like internal/versions and pkg/tea):

  • TestPlanRunsInKindOrder: guardrail < model < provider < key < settings for any generated file/server pair.
  • TestPlanIsDeterministic: equal inputs give the same plan in the same order.
  • TestPlanConverges: applying Mutating(Plan(...)) to the server and planning again yields no mutating change. Provider keys and anyProvider models are not generated: both are re-sent on every apply by design and stay covered by the example tests.
  • TestValidateGuardrailAcceptsExactlyTheEnforceablePairs: all 12 rule types x 4 actions against an explicit table of the pairs the gateway enforces (delimiter_integrity block/flag; redact only on content rules; strip only on tool/mcp).
  • TestValidateGuardrailIsTotal: arbitrary strings never panic and an unknown rule type or action is always refused.

Bug found and fixed

TestPlanIsDeterministic failed on main: Plan ranged over server.Guardrails (prune deletes and drift) and server.Providers (drift) directly, so those changes came out in Go map order, which differs between runs; apply printed and executed them in a different order each time. Both loops now use sortedKeys (made generic), which the model loop already used for the same reason. No behaviour change beyond the order.

Verified

go test ./pkg/aifirewall/ passes (existing tests unchanged, including helpers_test.go's sortedKeys case); go vet, gofmt clean.

@github-actions

Copy link
Copy Markdown
Contributor

Vulnetix config plan

Manager gitops:vulnetix/cli, prune off, plan hash a8bd984f1753c68b180298051dd9e2524ab644d2ebe9e4c7c811ff4126753b5f

Object Action Changes
~ QualityGate/default update (adopt) severity: null -> "high"

0 to create, 1 to update, 0 to delete, 0 unchanged

@0x73746F66 0x73746F66 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reuse review: the plan fix generalises the existing sortedKeys helper to sortedKeys[V any] and routes every server-map loop in Plan through it, instead of adding a second sorter. (Optional: its body could be slices.Sorted(maps.Keys(m)) from the stdlib; not required.) The property tests use math/rand with fixed seeds and the real Plan/ValidateGuardrail. No changes needed.

@0x73746F66 0x73746F66 left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reuse review: no reinvented Vulnetix patterns found. The change stays inside the package it covers, uses stdlib/testify helpers already used by the repo's tests, and adds no new client, auth, config-schema or shared-package duplicate (checked internal/testutils and sibling repos). Rebased onto current main locally: go vet and go test pass for every touched package. The earlier red checks (CodeQL Analyze, Install a release with verified provenance, Lockfile) were GitHub API rate-limit failures, not code failures; this will be re-run on a rebased head before merge.

… server maps in key order

Adds testing/quick properties over generated policy files and server
states: Plan runs in kind order, is deterministic, and converges (applying
its mutating changes leaves nothing to change); ValidateGuardrail accepts
exactly the enforceable rule type and action pairs and answers for any
input.

The determinism property failed: Plan ranged over server.Guardrails and
server.Providers directly, so guardrail drift/deletes and provider drift
came out in map order, different on every apply. Those loops now go
through sortedKeys, made generic, as the model loop already did.

Closes #222
@0x73746F66
0x73746F66 force-pushed the fix/222-aifirewall-plan-properties branch from ae43f1d to ad8a89d Compare November 13, 2026 10:53
@github-actions

Copy link
Copy Markdown
Contributor

Vulnetix config plan

Manager gitops:vulnetix/cli, prune off, plan hash a8bd984f1753c68b180298051dd9e2524ab644d2ebe9e4c7c811ff4126753b5f

Object Action Changes
~ QualityGate/default update (adopt) severity: null -> "high"

0 to create, 1 to update, 0 to delete, 0 unchanged

@0x73746F66
0x73746F66 merged commit 4d829f3 into main Nov 13, 2026
29 of 32 checks passed
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.

Add ordering and idempotence property tests for pkg/aifirewall Plan and ValidateGuardrail

1 participant