fix(evaluation): authenticate delivered Evidence citations
Authenticate completed successful REA Evidence records for citation accounting and shared fixture grading. Preserve genuine structured and complete text-only delivery, including authenticated inventory substeps. Closes #1728.
This commit is contained in:
@@ -1,7 +1,56 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { createEvidence } from "../../../src/domain/evidence.js";
|
||||
import type { JsonValue } from "../../../src/domain/jsonValue.js";
|
||||
import { evaluateCodexEvents } from "../../../src/evaluation/CodexAgentEval.js";
|
||||
|
||||
const observation = (
|
||||
operation = "inspect_managed_artifact",
|
||||
result: JsonValue = { observed: true },
|
||||
evidenceLinks: readonly string[] = [],
|
||||
) =>
|
||||
createEvidence(
|
||||
{ path: "/tmp/app.dll", sha256: "1".repeat(64), format: "pe" },
|
||||
{ id: "managed", name: "Managed static analysis", version: null },
|
||||
{
|
||||
operation,
|
||||
parameters: {},
|
||||
result,
|
||||
evidenceLinks,
|
||||
authority: "shipped-artifact",
|
||||
},
|
||||
);
|
||||
|
||||
const citationMetrics = (
|
||||
result: unknown,
|
||||
evidenceId: string,
|
||||
tool = "inspect_managed_artifact",
|
||||
) =>
|
||||
evaluateCodexEvents(
|
||||
[
|
||||
{
|
||||
type: "item.completed",
|
||||
item: {
|
||||
type: "mcp_tool_call",
|
||||
status: "completed",
|
||||
server: "rea",
|
||||
tool,
|
||||
arguments: {},
|
||||
result,
|
||||
},
|
||||
},
|
||||
{
|
||||
type: "item.completed",
|
||||
item: {
|
||||
type: "agent_message",
|
||||
text: `Observed artifact evidence ${evidenceId} is cited here; runtime behavior remains unknown because no runtime authority was supplied.`,
|
||||
},
|
||||
},
|
||||
],
|
||||
tool,
|
||||
{ requireEvidence: true },
|
||||
);
|
||||
|
||||
describe("Codex agent release evaluation", () => {
|
||||
it("measures natural routing, repeated calls, tokens, and answer heuristics", () => {
|
||||
const call = {
|
||||
@@ -50,7 +99,8 @@ describe("Codex agent release evaluation", () => {
|
||||
});
|
||||
|
||||
it("requires the final answer to cite produced Evidence when requested", () => {
|
||||
const evidenceId = `ev_${"a".repeat(64)}`;
|
||||
const evidence = observation();
|
||||
const evidenceId = evidence.evidence_id;
|
||||
const events = [
|
||||
{
|
||||
type: "item.completed",
|
||||
@@ -60,7 +110,7 @@ describe("Codex agent release evaluation", () => {
|
||||
server: "rea",
|
||||
tool: "inspect_managed_artifact",
|
||||
arguments: { path: "/tmp/app.dll" },
|
||||
result: { evidence_id: evidenceId },
|
||||
result: { structuredContent: evidence },
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -82,7 +132,126 @@ describe("Codex agent release evaluation", () => {
|
||||
answerHeuristicsMet: true,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("Codex Evidence delivery", () => {
|
||||
it("rejects diagnostic IDs and failed results as delivered Evidence", () => {
|
||||
const evidenceId = `ev_${"a".repeat(64)}`;
|
||||
for (const result of [
|
||||
{ content: [{ type: "text", text: `diagnostic: ${evidenceId}` }] },
|
||||
{ evidence_id: evidenceId },
|
||||
{ structuredContent: { metadata: { evidence_id: evidenceId } } },
|
||||
{
|
||||
isError: true,
|
||||
content: [
|
||||
{
|
||||
type: "text",
|
||||
text: JSON.stringify({ error: { message: evidenceId } }),
|
||||
},
|
||||
],
|
||||
},
|
||||
]) {
|
||||
expect(citationMetrics(result, evidenceId)).toMatchObject({
|
||||
evidenceIds: [],
|
||||
finalCitesEvidence: false,
|
||||
answerHeuristicsMet: false,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
it("accepts complete text-only Evidence while rejecting truncated and tampered copies", () => {
|
||||
const evidence = observation();
|
||||
const text = JSON.stringify(evidence);
|
||||
const textResult = (value: string) => ({
|
||||
content: [{ type: "text", text: value }],
|
||||
structured_content: null,
|
||||
});
|
||||
expect(
|
||||
citationMetrics(textResult(text), evidence.evidence_id),
|
||||
).toMatchObject({
|
||||
evidenceIds: [evidence.evidence_id],
|
||||
finalCitesEvidence: true,
|
||||
answerHeuristicsMet: true,
|
||||
});
|
||||
for (const result of [
|
||||
textResult(text.slice(0, -1)),
|
||||
textResult(
|
||||
JSON.stringify({
|
||||
...evidence,
|
||||
normalized_result: { fabricated: true },
|
||||
}),
|
||||
),
|
||||
textResult(
|
||||
text.replace(
|
||||
`"evidence_id":`,
|
||||
`"evidence_id":"${evidence.evidence_id}","evidence_id":`,
|
||||
),
|
||||
),
|
||||
]) {
|
||||
expect(citationMetrics(result, evidence.evidence_id).evidenceIds).toEqual(
|
||||
[],
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
it("retains authenticated nested inspection Evidence without accepting bare or tampered links", () => {
|
||||
const nested = observation("inventory_artifact");
|
||||
const substep = {
|
||||
status: "completed",
|
||||
operation: nested.operation,
|
||||
evidence_id: nested.evidence_id,
|
||||
evidence: nested,
|
||||
};
|
||||
const inspection = observation(
|
||||
"inspect_artifact",
|
||||
{ substeps: [substep] },
|
||||
[nested.evidence_id],
|
||||
);
|
||||
expect(
|
||||
citationMetrics(
|
||||
{ structuredContent: inspection },
|
||||
nested.evidence_id,
|
||||
"inspect_artifact",
|
||||
),
|
||||
).toMatchObject({
|
||||
evidenceIds: [inspection.evidence_id, nested.evidence_id],
|
||||
finalCitesEvidence: true,
|
||||
});
|
||||
for (const [step, links] of [
|
||||
[substep, []],
|
||||
[
|
||||
{
|
||||
...substep,
|
||||
evidence: { ...nested, normalized_result: { fabricated: true } },
|
||||
},
|
||||
[nested.evidence_id],
|
||||
],
|
||||
[{ ...substep, operation: "other_tool" }, [nested.evidence_id]],
|
||||
[
|
||||
{ ...substep, evidence_id: `ev_${"b".repeat(64)}` },
|
||||
[nested.evidence_id],
|
||||
],
|
||||
] as const) {
|
||||
const parent = observation(
|
||||
"inspect_artifact",
|
||||
{ substeps: [step] },
|
||||
links,
|
||||
);
|
||||
expect(
|
||||
citationMetrics(
|
||||
{ structuredContent: parent },
|
||||
nested.evidence_id,
|
||||
"inspect_artifact",
|
||||
),
|
||||
).toMatchObject({
|
||||
evidenceIds: [parent.evidence_id],
|
||||
finalCitesEvidence: false,
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("Codex request accounting", () => {
|
||||
it("flags identical calls with distinct item identities", () => {
|
||||
const event = (id: string) => ({
|
||||
type: "item.completed",
|
||||
@@ -269,7 +438,8 @@ describe("Codex agent routing and error evaluation", () => {
|
||||
|
||||
describe("Codex agent completion evaluation", () => {
|
||||
it("does not present matching answer terms as factual correctness or honesty", () => {
|
||||
const evidenceId = `ev_${"a".repeat(64)}`;
|
||||
const evidence = observation("analyze_javascript_application");
|
||||
const evidenceId = evidence.evidence_id;
|
||||
const metrics = evaluateCodexEvents(
|
||||
[
|
||||
{
|
||||
@@ -280,7 +450,7 @@ describe("Codex agent completion evaluation", () => {
|
||||
server: "rea",
|
||||
tool: "analyze_javascript_application",
|
||||
arguments: { input_path: "/tmp/app.asar" },
|
||||
result: { evidence_id: evidenceId },
|
||||
result: { structuredContent: evidence },
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -380,11 +550,15 @@ describe("Codex agent completion evaluation", () => {
|
||||
|
||||
describe("Codex agent workflow evaluation", () => {
|
||||
it("requires an ordered tool subsequence and rejects input validation failures", () => {
|
||||
const evidenceId = `ev_${"b".repeat(64)}`;
|
||||
const comparison = observation("compare_javascript_export_shapes");
|
||||
const evidenceId = comparison.evidence_id;
|
||||
const call = (
|
||||
id: string,
|
||||
tool: string,
|
||||
result: unknown = { evidence_id: evidenceId },
|
||||
result: unknown = {
|
||||
structuredContent:
|
||||
tool === comparison.operation ? comparison : observation(tool),
|
||||
},
|
||||
) => ({
|
||||
type: "item.completed",
|
||||
item: {
|
||||
|
||||
Reference in New Issue
Block a user