mirror of
https://github.com/runkids/skillshare.git
synced 2026-11-19 02:17:09 +00:00
* feat(audit): honor findings accepted with --force via --respect-accepted install and update --force record the findings a user accepted in audit_accepted, but audit ignored that record. A skill installed with --force therefore kept failing `skillshare audit` in CI with no way to let the accepted findings pass (#869). audit --respect-accepted marks those findings as acknowledged. They stay in every output (JSON acknowledged: true, a text/TUI note, "(accepted earlier)" in Markdown, SARIF external suppressions), but they are counted in summary.accepted instead of their severity and no longer fail the audit. Without the flag nothing changes, so existing CI gates keep their behavior. A changed file or snippet produces a new key and blocks again. Tracked repositories record acceptances at the repo root with paths relative to it, so ApplyAcceptedFindings walks up from each skill to match them. The install, update and edit gates use the same function and now honor repo-wide acceptances for skills inside tracked repos too. The dashboard always honors accepted findings: the Audit page mutes them and counts them apart, the skill Audit tab collapses them, and the Dashboard attention card no longer lists a skill whose only blocking findings were accepted. The CLI JSON summary and the server summary share Result.CountOpenBySeverity so both count accepted findings the same way. The oplog records the accepted count and the log views show it. * fix(audit): match acceptances when a single file is scanned A single-file scan names its findings by the file's base name, but the ancestor lookup used the file's whole path as the prefix, so it hashed SKILL.md/SKILL.md instead of the recorded SKILL.md. Auditing a skill file directly with --respect-accepted, and auditing agents inside a tracked repository in the CLI or the dashboard, still failed on unchanged accepted findings. For a file target the prefix is now the file's own directory.
74 lines
2.1 KiB
Go
74 lines
2.1 KiB
Go
package audit
|
|
|
|
import (
|
|
"crypto/sha256"
|
|
"encoding/hex"
|
|
"path"
|
|
"strings"
|
|
)
|
|
|
|
// AcceptKey returns a stable key for acknowledging a finding across updates.
|
|
// It omits the reported line number; detector-specific acceptance context can
|
|
// still bind the key to surrounding or file-wide evidence. A different rule,
|
|
// file, matched text, or acceptance context yields a new key and blocks again.
|
|
func AcceptKey(f Finding) string {
|
|
parts := []string{
|
|
f.RuleID, f.Pattern, f.Analyzer, f.File, normalizeSnippet(f.Snippet),
|
|
}
|
|
if f.acceptanceContext != "" {
|
|
parts = append(parts, f.acceptanceContext)
|
|
}
|
|
raw := strings.Join(parts, "|")
|
|
h := sha256.Sum256([]byte(strings.ToLower(raw)))
|
|
return hex.EncodeToString(h[:])
|
|
}
|
|
|
|
// MarkAcknowledged flags findings whose AcceptKey is in keys. Acknowledged
|
|
// findings stay in the result for display but no longer count toward blocking.
|
|
// Returns the number of findings marked.
|
|
func (r *Result) MarkAcknowledged(keys []string) int {
|
|
return r.MarkAcknowledgedUnder(keys, "")
|
|
}
|
|
|
|
// MarkAcknowledgedUnder is MarkAcknowledged for keys recorded by a scan of an
|
|
// enclosing directory, such as a whole tracked repository: dir is this
|
|
// result's path relative to that directory, as that scan named its files.
|
|
func (r *Result) MarkAcknowledgedUnder(keys []string, dir string) int {
|
|
if r == nil || len(keys) == 0 {
|
|
return 0
|
|
}
|
|
set := make(map[string]bool, len(keys))
|
|
for _, k := range keys {
|
|
set[k] = true
|
|
}
|
|
n := 0
|
|
for i := range r.Findings {
|
|
f := r.Findings[i]
|
|
if dir != "" {
|
|
f.File = path.Join(dir, f.File)
|
|
}
|
|
if !f.Acknowledged && set[AcceptKey(f)] {
|
|
r.Findings[i].Acknowledged = true
|
|
n++
|
|
}
|
|
}
|
|
return n
|
|
}
|
|
|
|
// AcceptKeysAtOrAbove returns keys for unacknowledged findings at or above
|
|
// threshold — the set a --force override accepts.
|
|
func (r *Result) AcceptKeysAtOrAbove(threshold string) []string {
|
|
normalized, err := NormalizeThreshold(threshold)
|
|
if err != nil {
|
|
normalized = DefaultThreshold()
|
|
}
|
|
cutoff := SeverityRank(normalized)
|
|
var keys []string
|
|
for _, f := range r.Findings {
|
|
if !f.Acknowledged && SeverityRank(f.Severity) <= cutoff {
|
|
keys = append(keys, AcceptKey(f))
|
|
}
|
|
}
|
|
return keys
|
|
}
|