diff --git a/internal/schemavalidators/internal_schemas/aisecuritycontext/ai-security-context-0.1.schema.json b/internal/schemavalidators/internal_schemas/aisecuritycontext/ai-security-context-0.1.schema.json index a98ce2d43..d6c77493c 100644 --- a/internal/schemavalidators/internal_schemas/aisecuritycontext/ai-security-context-0.1.schema.json +++ b/internal/schemavalidators/internal_schemas/aisecuritycontext/ai-security-context-0.1.schema.json @@ -434,6 +434,15 @@ "minimum": 0, "description": "Total number of commits reachable from the scanned revision (git rev-list --count of the target SHA). The denominator a consumer needs to render scan progress as \"N of M commits\" or a percentage. OPTIONAL: omitted when unknown — a shallow clone (whose count would be truncated) or an artifact produced before this field existed. The managed flow mirror-clones full history, so it is populated there. A snapshot of repository size, not a funnel counter, so it is not part of the reconciles invariant." }, + "scan_start_date": { + "type": "string", + "description": "The scan-start-date floor the run used: the oldest commit date the backfill mined to, as an RFC 3339 timestamp or a date. OPTIONAL: omitted when the scan has no floor (the full history) or when the artifact predates this field. It makes the floor attested, so a reader knows the oldest history the scan reached rather than inferring it from the window." + }, + "in_range_commits_total": { + "type": "integer", + "minimum": 0, + "description": "How many commits reachable from the scanned revision are on or after scan_start_date — the denominator for coverage WITHIN the start date, as distinct from repo_commits_total (the whole repository). The difference between the two is the history the start date excludes, so a consumer can show both the in-range coverage and how much an earlier start date would add. OPTIONAL: omitted when there is no floor (it would equal repo_commits_total) or on an artifact produced before this field existed." + }, "pending_survivors": { "type": "integer", "minimum": 0, diff --git a/internal/schemavalidators/schemavalidators_test.go b/internal/schemavalidators/schemavalidators_test.go index ba2c15bb3..459a556ce 100644 --- a/internal/schemavalidators/schemavalidators_test.go +++ b/internal/schemavalidators/schemavalidators_test.go @@ -621,6 +621,22 @@ func TestValidateSecurityContextTriageFields(t *testing.T) { require.NoError(t, schemavalidators.ValidateSecurityContext(payload, "")) }) + t.Run("a context carrying the scan start date and in-range total validates", func(t *testing.T) { + payload, scan := load(t) + // PFM-8172: the attested floor the backfill mined to, and the in-range + // denominator for coverage within that floor (distinct from repo_commits_total). + scan["repo_commits_total"] = 8000 + scan["scan_start_date"] = "2026-05-01T00:00:00Z" + scan["in_range_commits_total"] = 1200 + require.NoError(t, schemavalidators.ValidateSecurityContext(payload, "")) + }) + + t.Run("a negative in_range_commits_total is rejected", func(t *testing.T) { + payload, scan := load(t) + scan["in_range_commits_total"] = -1 + require.ErrorContains(t, schemavalidators.ValidateSecurityContext(payload, ""), "minimum") + }) + t.Run("a survivor missing its required commit_sha is rejected", func(t *testing.T) { payload, _ := load(t) payload["survivors"] = []any{map[string]any{"subject": "no sha"}} diff --git a/pkg/attestation/crafter/materials/aisecuritycontext/aisecuritycontext.go b/pkg/attestation/crafter/materials/aisecuritycontext/aisecuritycontext.go index 9505fb91c..6b89ef784 100644 --- a/pkg/attestation/crafter/materials/aisecuritycontext/aisecuritycontext.go +++ b/pkg/attestation/crafter/materials/aisecuritycontext/aisecuritycontext.go @@ -123,6 +123,18 @@ type ScanStats struct { // so it is outside the reconciles invariant. Omitted (zero) when unknown: a // shallow clone, or an artifact produced before this field existed. RepoCommitsTotal int `json:"repo_commits_total,omitempty"` + // ScanStartDate is the scan-start-date floor the run used: the oldest commit date + // the backfill mined to (RFC 3339 or a date). Omitted when the scan has no floor + // (full history) or predates this field. It makes the floor attested, so a reader + // knows the oldest history the scan reached rather than inferring it. + ScanStartDate string `json:"scan_start_date,omitempty"` + // InRangeCommitsTotal is how many commits reachable from the scanned revision are + // on or after ScanStartDate — the denominator for coverage WITHIN the start date, + // as distinct from RepoCommitsTotal (the whole repository). The difference between + // the two is the history the start date excludes, so a consumer can show both the + // in-range coverage and how much an earlier start date would add. Omitted when + // there is no floor (it equals RepoCommitsTotal) or on an older artifact. + InRangeCommitsTotal int `json:"in_range_commits_total,omitempty"` // PendingSurvivors is how many survivors still await adjudication: neither in // the frontier, nor a triage hole, nor abandoned after the retry cap. Zero // alongside AdjudicationComplete is the drained queue.