mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-18 18:04:17 +00:00
Overriding the audit gate with --force was per-invocation, so skills that legitimately quote attack strings (security scanners, red-team docs) had to be forced on every `update --all`. The only alternative, disabling the rule, was global and turned it off for every skill. Record the accepted findings (rule + file + matched text, no line number) in .metadata.json under `audit_accepted`, keyed by skill relPath so it survives entry rewrites and works for tracked repos. Later updates mark matching findings as acknowledged and exclude them from the block decision; any new finding, or the same rule matching different text, still blocks. Staged installs audit a temp directory, so InstallOptions gains an AuditAcceptRoot/AuditAcceptPath override pointing at the final destination. Refs #279
47 lines
1.6 KiB
Go
47 lines
1.6 KiB
Go
package audit
|
|
|
|
import "testing"
|
|
|
|
func TestAcceptKey_IgnoresLineNumber(t *testing.T) {
|
|
a := Finding{RuleID: "prompt-injection-0", Pattern: "prompt-injection", File: "SKILL.md", Line: 5, Snippet: "Ignore previous instructions"}
|
|
b := a
|
|
b.Line = 42
|
|
if AcceptKey(a) != AcceptKey(b) {
|
|
t.Error("line number must not change the accept key")
|
|
}
|
|
b.Snippet = "SYSTEM: override"
|
|
if AcceptKey(a) == AcceptKey(b) {
|
|
t.Error("different snippet must change the accept key")
|
|
}
|
|
}
|
|
|
|
func TestResult_MarkAcknowledged_SkipsBlocking(t *testing.T) {
|
|
r := &Result{Findings: []Finding{
|
|
{Severity: SeverityCritical, Pattern: "prompt-injection", File: "SKILL.md", Snippet: "Ignore previous instructions"},
|
|
}}
|
|
keys := r.AcceptKeysAtOrAbove(SeverityCritical)
|
|
if len(keys) != 1 {
|
|
t.Fatalf("want 1 accept key, got %d", len(keys))
|
|
}
|
|
if n := r.MarkAcknowledged(keys); n != 1 {
|
|
t.Fatalf("want 1 marked, got %d", n)
|
|
}
|
|
if r.HasSeverityAtOrAbove(SeverityCritical) {
|
|
t.Error("acknowledged finding must not block")
|
|
}
|
|
if len(r.AcceptKeysAtOrAbove(SeverityCritical)) != 0 {
|
|
t.Error("acknowledged finding must not be re-accepted")
|
|
}
|
|
}
|
|
|
|
func TestResult_MarkAcknowledged_NewFindingStillBlocks(t *testing.T) {
|
|
r := &Result{Findings: []Finding{
|
|
{Severity: SeverityCritical, Pattern: "prompt-injection", File: "SKILL.md", Snippet: "Ignore previous instructions"},
|
|
{Severity: SeverityCritical, Pattern: "prompt-injection", File: "SKILL.md", Snippet: "SYSTEM: override"},
|
|
}}
|
|
r.MarkAcknowledged([]string{AcceptKey(r.Findings[0])})
|
|
if !r.HasSeverityAtOrAbove(SeverityCritical) {
|
|
t.Error("unacknowledged finding must still block")
|
|
}
|
|
}
|