Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,10 @@
"trace_sessions": {
"$ref": "#/definitions/trace_sessions",
"description": "Chainloop Trace session IDs (session_external_id) declared on the FIX commit via the Chainloop-Trace-Sessions git trailer — the AI coding session(s) that produced the fix. Recorded verbatim by the producer (no DB lookup); sorted + deduped."
},
"trace_checked": {
"$ref": "#/definitions/trace_checked",
"description": "True when the Chainloop graph lookup of the FIX commit gave a definite result (sessions found or no session found). A later scan skips the lookup for this commit."
}
}
},
Expand Down Expand Up @@ -1060,9 +1064,17 @@
"trace_sessions": {
"$ref": "#/definitions/trace_sessions",
"description": "Chainloop Trace session IDs (session_external_id) declared on this INTRODUCING commit via the Chainloop-Trace-Sessions git trailer \u2014 the AI coding session(s) that introduced the flaw. Recorded verbatim by the producer (no DB lookup); sorted + deduped."
},
"trace_checked": {
"$ref": "#/definitions/trace_checked",
"description": "True when the Chainloop graph lookup of this INTRODUCING commit gave a definite result (sessions found or no session found). A later scan skips the lookup for this commit."
}
}
},
"trace_checked": {
"type": "boolean",
"description": "Marks a commit whose AI coding session lookup in the Chainloop graph gave a definite result: at least one session found, or no session found. The producer does not set it when the lookup was denied or failed, so the next scan tries the commit again. Absent means the commit was never looked up, or the artifact was produced before the field existed; a consumer must treat absent and false the same. The mark is not a periodic re-check: a session attested after the lookup of its commit stays unlinked."
},
"commit_sha": {
"type": "string",
"pattern": "^[0-9a-f]{40}$",
Expand Down
88 changes: 88 additions & 0 deletions internal/schemavalidators/schemavalidators_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1196,3 +1196,91 @@ func TestValidateSecurityContextTraceSessions(t *testing.T) {
})
}
}

// TestValidateSecurityContextTraceChecked covers the optional trace_checked mark
// on a fix commit (fingerprint) and on an introducing commit (introduced_by[]).
// The producer sets it when the AI coding session lookup of the commit gave a
// definite result, so that the next scan can skip the commit (PFM-8487).
func TestValidateSecurityContextTraceChecked(t *testing.T) {
loadPayload := func(t *testing.T) map[string]any {
t.Helper()
f, err := os.ReadFile("./testdata/ai_security_context_valid.json")
require.NoError(t, err)

var payload map[string]any
require.NoError(t, json.Unmarshal(f, &payload))
return payload
}

firstFingerprint := func(t *testing.T, payload map[string]any) map[string]any {
t.Helper()
fps, ok := payload["fingerprints"].([]any)
require.True(t, ok)
require.NotEmpty(t, fps)
fp, ok := fps[0].(map[string]any)
require.True(t, ok)
return fp
}

firstIntroducedBy := func(t *testing.T, fp map[string]any) map[string]any {
t.Helper()
origins, ok := fp["introduced_by"].([]any)
require.True(t, ok)
require.NotEmpty(t, origins)
origin, ok := origins[0].(map[string]any)
require.True(t, ok)
return origin
}

t.Run("the fixture carries trace_checked on both commit roles", func(t *testing.T) {
payload := loadPayload(t)
fp := firstFingerprint(t, payload)
require.Equal(t, true, fp["trace_checked"], "fix commit should carry trace_checked")
require.Equal(t, true, firstIntroducedBy(t, fp)["trace_checked"], "introducing commit should carry trace_checked")
require.NoError(t, schemavalidators.ValidateSecurityContext(payload, ""))
})

t.Run("a context without trace_checked validates", func(t *testing.T) {
payload := loadPayload(t)
fp := firstFingerprint(t, payload)
delete(fp, "trace_checked")
delete(firstIntroducedBy(t, fp), "trace_checked")
require.NoError(t, schemavalidators.ValidateSecurityContext(payload, ""))
})

cases := []struct {
name string
value any
wantErr bool
}{
{name: "true", value: true},
{name: "false", value: false},
{name: "a string", value: "true", wantErr: true},
{name: "a number", value: 1, wantErr: true},
{name: "null", value: nil, wantErr: true},
}

for _, tc := range cases {
t.Run("fix commit with "+tc.name, func(t *testing.T) {
payload := loadPayload(t)
firstFingerprint(t, payload)["trace_checked"] = tc.value
err := schemavalidators.ValidateSecurityContext(payload, "")
if tc.wantErr {
require.Error(t, err)
return
}
require.NoError(t, err)
})

t.Run("introducing commit with "+tc.name, func(t *testing.T) {
payload := loadPayload(t)
firstIntroducedBy(t, firstFingerprint(t, payload))["trace_checked"] = tc.value
err := schemavalidators.ValidateSecurityContext(payload, "")
if tc.wantErr {
require.Error(t, err)
return
}
require.NoError(t, err)
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,15 @@
"verified": true,
"trace_sessions": [
"1f2e3d4c-5b6a-7980-a1b2-c3d4e5f60718"
]
],
"trace_checked": true
}
],
"introduced_to_fixed_seconds": 102,
"trace_sessions": [
"8b012929-ba7f-4986-815c-2fbe692a9a98"
]
],
"trace_checked": true
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,11 @@ type CommitRef struct {
// trailer — the AI coding session(s) that introduced the flaw. Recorded
// verbatim by the producer with no DB lookup; sorted + deduped.
TraceSessions []string `json:"trace_sessions,omitempty"`

// TraceChecked is true when the AI coding session lookup of this
// introducing commit gave a definite result (sessions found or no session
// found), so a later scan can skip the lookup.
TraceChecked bool `json:"trace_checked,omitempty"`
}

// Anchor is a byte-verifiable evidence span. A consumer can re-verify it
Expand Down Expand Up @@ -328,6 +333,11 @@ type Fingerprint struct {
// the AI coding session(s) that produced the fix. Recorded verbatim by the
// producer with no DB lookup; sorted + deduped.
TraceSessions []string `json:"trace_sessions,omitempty"`

// TraceChecked is true when the AI coding session lookup of the fix commit
// gave a definite result (sessions found or no session found), so a later
// scan can skip the lookup.
TraceChecked bool `json:"trace_checked,omitempty"`
}

// Data is the AI security context payload: the object the producer writes under
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -548,13 +548,15 @@
"verified": true,
"trace_sessions": [
"1f2e3d4c-5b6a-7980-a1b2-c3d4e5f60718"
]
],
"trace_checked": true
}
],
"introduced_to_fixed_seconds": 40385717,
"trace_sessions": [
"8b012929-ba7f-4986-815c-2fbe692a9a98"
]
],
"trace_checked": true
},
{
"id": "fp_eda80e2676",
Expand Down
Loading