create-principles-disciple 1.138.2 → 1.139.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/console/dist/server/config/pd-config-store.js +9 -2
- package/core/dist/evolution-store.d.ts +4 -2
- package/core/dist/evolution-store.d.ts.map +1 -1
- package/core/dist/evolution-store.js +20 -2
- package/core/dist/evolution-store.js.map +1 -1
- package/core/dist/evolution-store.test.js +8 -4
- package/core/dist/evolution-store.test.js.map +1 -1
- package/core/dist/runtime-v2/__tests__/architecture-regression.test.js +19 -133
- package/core/dist/runtime-v2/__tests__/architecture-regression.test.js.map +1 -1
- package/core/dist/runtime-v2/__tests__/pain-signal-observability.test.js +5 -6
- package/core/dist/runtime-v2/__tests__/pain-signal-observability.test.js.map +1 -1
- package/core/dist/runtime-v2/config/__tests__/pd-config-reasoning.test.d.ts +2 -0
- package/core/dist/runtime-v2/config/__tests__/pd-config-reasoning.test.d.ts.map +1 -0
- package/core/dist/runtime-v2/config/__tests__/pd-config-reasoning.test.js +99 -0
- package/core/dist/runtime-v2/config/__tests__/pd-config-reasoning.test.js.map +1 -0
- package/core/dist/runtime-v2/config/pd-config-agent-binding.d.ts +2 -0
- package/core/dist/runtime-v2/config/pd-config-agent-binding.d.ts.map +1 -1
- package/core/dist/runtime-v2/config/pd-config-agent-binding.js +3 -0
- package/core/dist/runtime-v2/config/pd-config-agent-binding.js.map +1 -1
- package/core/dist/runtime-v2/config/pd-config-types.d.ts +8 -0
- package/core/dist/runtime-v2/config/pd-config-types.d.ts.map +1 -1
- package/core/dist/runtime-v2/config/pd-config-types.js.map +1 -1
- package/core/dist/runtime-v2/config/pd-config-validate.d.ts.map +1 -1
- package/core/dist/runtime-v2/config/pd-config-validate.js +10 -0
- package/core/dist/runtime-v2/config/pd-config-validate.js.map +1 -1
- package/core/dist/runtime-v2/evolution/evolution-types.d.ts +6 -304
- package/core/dist/runtime-v2/evolution/evolution-types.d.ts.map +1 -1
- package/core/dist/runtime-v2/evolution/evolution-types.js +6 -173
- package/core/dist/runtime-v2/evolution/evolution-types.js.map +1 -1
- package/core/dist/runtime-v2/full-trace-contract.d.ts +1 -1
- package/core/dist/runtime-v2/full-trace-contract.js +1 -1
- package/core/dist/runtime-v2/index.d.ts +2 -12
- package/core/dist/runtime-v2/index.d.ts.map +1 -1
- package/core/dist/runtime-v2/index.js +1 -9
- package/core/dist/runtime-v2/index.js.map +1 -1
- package/core/dist/runtime-v2/pain-signal-observability.d.ts.map +1 -1
- package/core/dist/runtime-v2/pain-signal-observability.js +69 -63
- package/core/dist/runtime-v2/pain-signal-observability.js.map +1 -1
- package/core/dist/runtime-v2/pain-signal-runtime-factory.d.ts +2 -0
- package/core/dist/runtime-v2/pain-signal-runtime-factory.d.ts.map +1 -1
- package/core/dist/runtime-v2/pain-signal-runtime-factory.js +2 -0
- package/core/dist/runtime-v2/pain-signal-runtime-factory.js.map +1 -1
- package/core/dist/runtime-v2/types/index.d.ts +0 -2
- package/core/dist/runtime-v2/types/index.d.ts.map +1 -1
- package/core/dist/runtime-v2/types/index.js +0 -1
- package/core/dist/runtime-v2/types/index.js.map +1 -1
- package/core/package.json +1 -1
- package/host-runtime/dist/internalization-consumer-cycle.js +3 -0
- package/host-runtime/package.json +1 -1
- package/package.json +2 -2
- package/pd-cli/dist/commands/runtime-init.js +1 -1
- package/pd-cli/dist/commands/runtime-init.js.map +1 -1
- package/pd-cli/dist/services/runtime-adapter-resolver.d.ts.map +1 -1
- package/pd-cli/dist/services/runtime-adapter-resolver.js +2 -0
- package/pd-cli/dist/services/runtime-adapter-resolver.js.map +1 -1
- package/pd-cli/package.json +1 -1
- package/plugin/dist/bundle.js +483 -571
- package/plugin/dist/core/event-log.d.ts +1 -3
- package/plugin/dist/core/evolution-types.d.ts +9 -32
- package/plugin/dist/core/trajectory.d.ts +10 -4
- package/plugin/dist/governance-audit.js +204 -204
- package/plugin/dist/rulehost-evidence.js +251 -306
- package/plugin/dist/types/event-types.d.ts +1 -1
- package/plugin/openclaw.plugin.json +1 -1
- package/plugin/package.json +1 -1
- package/release-manager/package.json +2 -2
- package/core/dist/runtime-v2/__tests__/golden-trace-candidate-builder.test.d.ts +0 -2
- package/core/dist/runtime-v2/__tests__/golden-trace-candidate-builder.test.d.ts.map +0 -1
- package/core/dist/runtime-v2/__tests__/golden-trace-candidate-builder.test.js +0 -759
- package/core/dist/runtime-v2/__tests__/golden-trace-candidate-builder.test.js.map +0 -1
- package/core/dist/runtime-v2/__tests__/trace-refiner-agent.test.d.ts +0 -2
- package/core/dist/runtime-v2/__tests__/trace-refiner-agent.test.d.ts.map +0 -1
- package/core/dist/runtime-v2/__tests__/trace-refiner-agent.test.js +0 -726
- package/core/dist/runtime-v2/__tests__/trace-refiner-agent.test.js.map +0 -1
- package/core/dist/runtime-v2/__tests__/trace-refiner.test.d.ts +0 -2
- package/core/dist/runtime-v2/__tests__/trace-refiner.test.d.ts.map +0 -1
- package/core/dist/runtime-v2/__tests__/trace-refiner.test.js +0 -527
- package/core/dist/runtime-v2/__tests__/trace-refiner.test.js.map +0 -1
- package/core/dist/runtime-v2/evolution/index.d.ts +0 -2
- package/core/dist/runtime-v2/evolution/index.d.ts.map +0 -1
- package/core/dist/runtime-v2/evolution/index.js +0 -2
- package/core/dist/runtime-v2/evolution/index.js.map +0 -1
- package/core/dist/runtime-v2/golden-trace-candidate-builder.d.ts +0 -23
- package/core/dist/runtime-v2/golden-trace-candidate-builder.d.ts.map +0 -1
- package/core/dist/runtime-v2/golden-trace-candidate-builder.js +0 -193
- package/core/dist/runtime-v2/golden-trace-candidate-builder.js.map +0 -1
- package/core/dist/runtime-v2/golden-trace-replay-adapter.d.ts +0 -18
- package/core/dist/runtime-v2/golden-trace-replay-adapter.d.ts.map +0 -1
- package/core/dist/runtime-v2/golden-trace-replay-adapter.js +0 -18
- package/core/dist/runtime-v2/golden-trace-replay-adapter.js.map +0 -1
- package/core/dist/runtime-v2/trace-refiner-agent.d.ts +0 -71
- package/core/dist/runtime-v2/trace-refiner-agent.d.ts.map +0 -1
- package/core/dist/runtime-v2/trace-refiner-agent.js +0 -239
- package/core/dist/runtime-v2/trace-refiner-agent.js.map +0 -1
- package/core/dist/runtime-v2/trace-refiner.d.ts +0 -47
- package/core/dist/runtime-v2/trace-refiner.d.ts.map +0 -1
- package/core/dist/runtime-v2/trace-refiner.js +0 -261
- package/core/dist/runtime-v2/trace-refiner.js.map +0 -1
- package/core/dist/runtime-v2/types/queue-types.d.ts +0 -51
- package/core/dist/runtime-v2/types/queue-types.d.ts.map +0 -1
- package/core/dist/runtime-v2/types/queue-types.js +0 -44
- package/core/dist/runtime-v2/types/queue-types.js.map +0 -1
- package/plugin/dist/types/queue.d.ts +0 -2
|
@@ -1,726 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* TraceRefinerAgent shadow contract tests (PRI-192).
|
|
3
|
-
*
|
|
4
|
-
* TDD tests for:
|
|
5
|
-
* - createTraceRefinerAgentInput: input construction
|
|
6
|
-
* - validateTraceRefinerAgentOutput: strict output validation
|
|
7
|
-
* - applyTraceRefinerAgentShadowResult: shadow-mode application
|
|
8
|
-
* - SourceRef anti-forgery
|
|
9
|
-
* - Confidence bounds
|
|
10
|
-
* - Blocked status handling
|
|
11
|
-
* - Architecture guard
|
|
12
|
-
*/
|
|
13
|
-
import { describe, it, expect } from 'vitest';
|
|
14
|
-
import { createTraceRefinerAgentInput, validateTraceRefinerAgentOutput, applyTraceRefinerAgentShadowResult, } from '../trace-refiner-agent.js';
|
|
15
|
-
import { refineFullTrace } from '../trace-refiner.js';
|
|
16
|
-
function makeValidFullTrace(overrides) {
|
|
17
|
-
return {
|
|
18
|
-
sourceTaskId: 'task_src_001',
|
|
19
|
-
sourcePainId: 'pain-001',
|
|
20
|
-
sourceRunIds: ['run_001', 'run_002'],
|
|
21
|
-
capturedAt: '2026-05-19T00:00:00Z',
|
|
22
|
-
sourceRefs: [
|
|
23
|
-
{ kind: 'task', id: 'task_src_001' },
|
|
24
|
-
{ kind: 'run', id: 'run_001' },
|
|
25
|
-
{ kind: 'run', id: 'run_002' },
|
|
26
|
-
{ kind: 'artifact', id: 'artifact_log_001' },
|
|
27
|
-
],
|
|
28
|
-
timeline: [
|
|
29
|
-
{ at: '2026-05-19T00:00:00Z', kind: 'user_message', summary: 'Fix the bug' },
|
|
30
|
-
{ at: '2026-05-19T00:00:01Z', kind: 'tool_call', summary: 'Read (succeeded)', metadata: { toolName: 'Read', status: 'succeeded' } },
|
|
31
|
-
{ at: '2026-05-19T00:00:02Z', kind: 'tool_result', summary: 'Error from Read', metadata: { toolName: 'Read', error: 'file not found' } },
|
|
32
|
-
],
|
|
33
|
-
ambiguityNotes: [],
|
|
34
|
-
sanitizationNotes: [],
|
|
35
|
-
...overrides,
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
function makeValidRefinedTrace(fullTrace) {
|
|
39
|
-
return refineFullTrace(fullTrace);
|
|
40
|
-
}
|
|
41
|
-
function makeValidAgentOutput(refinedTrace, overrides) {
|
|
42
|
-
return {
|
|
43
|
-
status: 'refined',
|
|
44
|
-
refinedTrace,
|
|
45
|
-
evidenceMap: [
|
|
46
|
-
{ claim: 'Tool Read failed with file not found', sourceRefs: ['run:run_001'] },
|
|
47
|
-
],
|
|
48
|
-
rejectedEvidence: [],
|
|
49
|
-
confidence: 0.85,
|
|
50
|
-
generatedAt: '2026-05-19T00:01:00Z',
|
|
51
|
-
...overrides,
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
// ── createTraceRefinerAgentInput ──
|
|
55
|
-
describe('createTraceRefinerAgentInput', () => {
|
|
56
|
-
it('sets constraints to literal true values and mode=shadow', () => {
|
|
57
|
-
const fullTrace = makeValidFullTrace();
|
|
58
|
-
const refined = makeValidRefinedTrace(fullTrace);
|
|
59
|
-
const input = createTraceRefinerAgentInput(fullTrace, refined, 'diagnosis_input');
|
|
60
|
-
expect(input.mode).toBe('shadow');
|
|
61
|
-
expect(input.constraints.preserveSourceRefs).toBe(true);
|
|
62
|
-
expect(input.constraints.doNotInventEvidence).toBe(true);
|
|
63
|
-
expect(input.constraints.redactSecrets).toBe(true);
|
|
64
|
-
});
|
|
65
|
-
it('preserves fullTrace and deterministicRefinedTrace', () => {
|
|
66
|
-
const fullTrace = makeValidFullTrace();
|
|
67
|
-
const refined = makeValidRefinedTrace(fullTrace);
|
|
68
|
-
const input = createTraceRefinerAgentInput(fullTrace, refined, 'golden_trace_candidate');
|
|
69
|
-
expect(input.fullTrace).toBe(fullTrace);
|
|
70
|
-
expect(input.deterministicRefinedTrace).toBe(refined);
|
|
71
|
-
});
|
|
72
|
-
it('sets objective correctly', () => {
|
|
73
|
-
const fullTrace = makeValidFullTrace();
|
|
74
|
-
const refined = makeValidRefinedTrace(fullTrace);
|
|
75
|
-
const input1 = createTraceRefinerAgentInput(fullTrace, refined, 'diagnosis_input');
|
|
76
|
-
expect(input1.objective).toBe('diagnosis_input');
|
|
77
|
-
const input2 = createTraceRefinerAgentInput(fullTrace, refined, 'golden_trace_candidate');
|
|
78
|
-
expect(input2.objective).toBe('golden_trace_candidate');
|
|
79
|
-
const input3 = createTraceRefinerAgentInput(fullTrace, refined, 'l2_replay_case');
|
|
80
|
-
expect(input3.objective).toBe('l2_replay_case');
|
|
81
|
-
});
|
|
82
|
-
});
|
|
83
|
-
// ── validateTraceRefinerAgentOutput: valid refined output ──
|
|
84
|
-
describe('validateTraceRefinerAgentOutput: valid output', () => {
|
|
85
|
-
it('valid refined output passes strict validator', () => {
|
|
86
|
-
const fullTrace = makeValidFullTrace();
|
|
87
|
-
const refined = makeValidRefinedTrace(fullTrace);
|
|
88
|
-
const input = createTraceRefinerAgentInput(fullTrace, refined, 'diagnosis_input');
|
|
89
|
-
const output = makeValidAgentOutput(refined);
|
|
90
|
-
const result = validateTraceRefinerAgentOutput(output, input);
|
|
91
|
-
expect(result.ok).toBe(true);
|
|
92
|
-
if (result.ok) {
|
|
93
|
-
expect(result.output.status).toBe('refined');
|
|
94
|
-
expect(result.output.confidence).toBe(0.85);
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
// ── validateTraceRefinerAgentOutput: claim without sourceRefs ──
|
|
99
|
-
describe('validateTraceRefinerAgentOutput: sourceRefs validation', () => {
|
|
100
|
-
it('claim without sourceRefs fails', () => {
|
|
101
|
-
const fullTrace = makeValidFullTrace();
|
|
102
|
-
const refined = makeValidRefinedTrace(fullTrace);
|
|
103
|
-
const input = createTraceRefinerAgentInput(fullTrace, refined, 'diagnosis_input');
|
|
104
|
-
const output = makeValidAgentOutput(refined, {
|
|
105
|
-
evidenceMap: [
|
|
106
|
-
{ claim: 'Some claim without refs', sourceRefs: [] },
|
|
107
|
-
],
|
|
108
|
-
});
|
|
109
|
-
const result = validateTraceRefinerAgentOutput(output, input);
|
|
110
|
-
expect(result.ok).toBe(false);
|
|
111
|
-
if (!result.ok) {
|
|
112
|
-
expect(result.errors.some((e) => e.includes('sourceRefs'))).toBe(true);
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
it('invented source ref not present in input fails', () => {
|
|
116
|
-
const fullTrace = makeValidFullTrace();
|
|
117
|
-
const refined = makeValidRefinedTrace(fullTrace);
|
|
118
|
-
const input = createTraceRefinerAgentInput(fullTrace, refined, 'diagnosis_input');
|
|
119
|
-
const output = makeValidAgentOutput(refined, {
|
|
120
|
-
evidenceMap: [
|
|
121
|
-
{ claim: 'Claim with invented ref', sourceRefs: ['task:invented_task_999'] },
|
|
122
|
-
],
|
|
123
|
-
});
|
|
124
|
-
const result = validateTraceRefinerAgentOutput(output, input);
|
|
125
|
-
expect(result.ok).toBe(false);
|
|
126
|
-
if (!result.ok) {
|
|
127
|
-
expect(result.errors.some((e) => e.includes('invented') || e.includes('allowed'))).toBe(true);
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
it('valid sourceRef from fullTrace.sourceRefs passes', () => {
|
|
131
|
-
const fullTrace = makeValidFullTrace();
|
|
132
|
-
const refined = makeValidRefinedTrace(fullTrace);
|
|
133
|
-
const input = createTraceRefinerAgentInput(fullTrace, refined, 'diagnosis_input');
|
|
134
|
-
const output = makeValidAgentOutput(refined, {
|
|
135
|
-
evidenceMap: [
|
|
136
|
-
{ claim: 'Valid claim', sourceRefs: ['task:task_src_001'] },
|
|
137
|
-
],
|
|
138
|
-
});
|
|
139
|
-
const result = validateTraceRefinerAgentOutput(output, input);
|
|
140
|
-
expect(result.ok).toBe(true);
|
|
141
|
-
});
|
|
142
|
-
it('valid sourceRef from refinedTrace.evidenceRefs passes', () => {
|
|
143
|
-
const fullTrace = makeValidFullTrace();
|
|
144
|
-
const refined = makeValidRefinedTrace(fullTrace);
|
|
145
|
-
const input = createTraceRefinerAgentInput(fullTrace, refined, 'diagnosis_input');
|
|
146
|
-
const output = makeValidAgentOutput(refined, {
|
|
147
|
-
evidenceMap: [
|
|
148
|
-
{ claim: 'Valid claim from evidenceRefs', sourceRefs: refined.evidenceRefs },
|
|
149
|
-
],
|
|
150
|
-
});
|
|
151
|
-
const result = validateTraceRefinerAgentOutput(output, input);
|
|
152
|
-
expect(result.ok).toBe(true);
|
|
153
|
-
});
|
|
154
|
-
it('valid sourceRef from refinedTrace.keyEvents evidenceRefs passes', () => {
|
|
155
|
-
const fullTrace = makeValidFullTrace();
|
|
156
|
-
const refined = makeValidRefinedTrace(fullTrace);
|
|
157
|
-
const input = createTraceRefinerAgentInput(fullTrace, refined, 'diagnosis_input');
|
|
158
|
-
const keyEventRefs = refined.keyEvents.flatMap((e) => e.evidenceRefs);
|
|
159
|
-
if (keyEventRefs.length === 0) {
|
|
160
|
-
return;
|
|
161
|
-
}
|
|
162
|
-
const output = makeValidAgentOutput(refined, {
|
|
163
|
-
evidenceMap: [
|
|
164
|
-
{ claim: 'Valid claim from keyEvents', sourceRefs: keyEventRefs.slice(0, 1) },
|
|
165
|
-
],
|
|
166
|
-
});
|
|
167
|
-
const result = validateTraceRefinerAgentOutput(output, input);
|
|
168
|
-
expect(result.ok).toBe(true);
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
// ── validateTraceRefinerAgentOutput: status=blocked ──
|
|
172
|
-
describe('validateTraceRefinerAgentOutput: blocked status', () => {
|
|
173
|
-
it('status=blocked preserves blockedReason and does not replace deterministic trace', () => {
|
|
174
|
-
const fullTrace = makeValidFullTrace();
|
|
175
|
-
const refined = makeValidRefinedTrace(fullTrace);
|
|
176
|
-
const input = createTraceRefinerAgentInput(fullTrace, refined, 'diagnosis_input');
|
|
177
|
-
const output = makeValidAgentOutput(refined, {
|
|
178
|
-
status: 'blocked',
|
|
179
|
-
blockedReason: 'Insufficient evidence to refine',
|
|
180
|
-
evidenceMap: [],
|
|
181
|
-
confidence: 0,
|
|
182
|
-
});
|
|
183
|
-
const result = validateTraceRefinerAgentOutput(output, input);
|
|
184
|
-
expect(result.ok).toBe(true);
|
|
185
|
-
if (result.ok) {
|
|
186
|
-
expect(result.output.status).toBe('blocked');
|
|
187
|
-
expect(result.output.blockedReason).toBe('Insufficient evidence to refine');
|
|
188
|
-
}
|
|
189
|
-
});
|
|
190
|
-
it('status=blocked without blockedReason fails', () => {
|
|
191
|
-
const fullTrace = makeValidFullTrace();
|
|
192
|
-
const refined = makeValidRefinedTrace(fullTrace);
|
|
193
|
-
const input = createTraceRefinerAgentInput(fullTrace, refined, 'diagnosis_input');
|
|
194
|
-
const output = makeValidAgentOutput(refined, {
|
|
195
|
-
status: 'blocked',
|
|
196
|
-
blockedReason: undefined,
|
|
197
|
-
evidenceMap: [],
|
|
198
|
-
confidence: 0,
|
|
199
|
-
});
|
|
200
|
-
const result = validateTraceRefinerAgentOutput(output, input);
|
|
201
|
-
expect(result.ok).toBe(false);
|
|
202
|
-
if (!result.ok) {
|
|
203
|
-
expect(result.errors.some((e) => e.includes('blockedReason'))).toBe(true);
|
|
204
|
-
}
|
|
205
|
-
});
|
|
206
|
-
it('status=blocked with empty blockedReason fails', () => {
|
|
207
|
-
const fullTrace = makeValidFullTrace();
|
|
208
|
-
const refined = makeValidRefinedTrace(fullTrace);
|
|
209
|
-
const input = createTraceRefinerAgentInput(fullTrace, refined, 'diagnosis_input');
|
|
210
|
-
const output = makeValidAgentOutput(refined, {
|
|
211
|
-
status: 'blocked',
|
|
212
|
-
blockedReason: '',
|
|
213
|
-
evidenceMap: [],
|
|
214
|
-
confidence: 0,
|
|
215
|
-
});
|
|
216
|
-
const result = validateTraceRefinerAgentOutput(output, input);
|
|
217
|
-
expect(result.ok).toBe(false);
|
|
218
|
-
if (!result.ok) {
|
|
219
|
-
expect(result.errors.some((e) => e.includes('blockedReason'))).toBe(true);
|
|
220
|
-
}
|
|
221
|
-
});
|
|
222
|
-
});
|
|
223
|
-
// ── validateTraceRefinerAgentOutput: invalid output ──
|
|
224
|
-
describe('validateTraceRefinerAgentOutput: invalid output', () => {
|
|
225
|
-
it('invalid agent output returns agent_output_invalid and selectedTrace remains deterministic', () => {
|
|
226
|
-
const fullTrace = makeValidFullTrace();
|
|
227
|
-
const refined = makeValidRefinedTrace(fullTrace);
|
|
228
|
-
const input = createTraceRefinerAgentInput(fullTrace, refined, 'diagnosis_input');
|
|
229
|
-
const result = applyTraceRefinerAgentShadowResult(input, { garbage: true });
|
|
230
|
-
expect(result.mode).toBe('shadow');
|
|
231
|
-
expect(result.selectedTrace).toEqual(refined);
|
|
232
|
-
expect(result.agentRefinedTrace).toBeNull();
|
|
233
|
-
expect(result.acceptedAgentOutput).toBeNull();
|
|
234
|
-
expect(result.telemetry.decision).toBe('agent_output_invalid');
|
|
235
|
-
expect(result.telemetry.errors.length).toBeGreaterThan(0);
|
|
236
|
-
});
|
|
237
|
-
});
|
|
238
|
-
// ── applyTraceRefinerAgentShadowResult: shadow mode ──
|
|
239
|
-
describe('applyTraceRefinerAgentShadowResult: shadow mode', () => {
|
|
240
|
-
it('valid shadow output records agentRefinedTrace but selectedTrace remains deterministic', () => {
|
|
241
|
-
const fullTrace = makeValidFullTrace();
|
|
242
|
-
const refined = makeValidRefinedTrace(fullTrace);
|
|
243
|
-
const input = createTraceRefinerAgentInput(fullTrace, refined, 'diagnosis_input');
|
|
244
|
-
const agentOutput = makeValidAgentOutput(refined);
|
|
245
|
-
const result = applyTraceRefinerAgentShadowResult(input, agentOutput);
|
|
246
|
-
expect(result.mode).toBe('shadow');
|
|
247
|
-
expect(result.selectedTrace).toEqual(refined);
|
|
248
|
-
expect(result.selectedTrace).toBe(input.deterministicRefinedTrace);
|
|
249
|
-
expect(result.agentRefinedTrace).not.toBeNull();
|
|
250
|
-
expect(result.acceptedAgentOutput).not.toBeNull();
|
|
251
|
-
expect(result.telemetry.decision).toBe('agent_refined_recorded');
|
|
252
|
-
});
|
|
253
|
-
it('blocked agent output records agent_blocked decision', () => {
|
|
254
|
-
const fullTrace = makeValidFullTrace();
|
|
255
|
-
const refined = makeValidRefinedTrace(fullTrace);
|
|
256
|
-
const input = createTraceRefinerAgentInput(fullTrace, refined, 'diagnosis_input');
|
|
257
|
-
const agentOutput = makeValidAgentOutput(refined, {
|
|
258
|
-
status: 'blocked',
|
|
259
|
-
blockedReason: 'Cannot refine',
|
|
260
|
-
evidenceMap: [],
|
|
261
|
-
confidence: 0,
|
|
262
|
-
});
|
|
263
|
-
const result = applyTraceRefinerAgentShadowResult(input, agentOutput);
|
|
264
|
-
expect(result.mode).toBe('shadow');
|
|
265
|
-
expect(result.selectedTrace).toEqual(refined);
|
|
266
|
-
expect(result.telemetry.decision).toBe('agent_blocked');
|
|
267
|
-
});
|
|
268
|
-
});
|
|
269
|
-
// ── validateTraceRefinerAgentOutput: confidence bounds ──
|
|
270
|
-
describe('validateTraceRefinerAgentOutput: confidence bounds', () => {
|
|
271
|
-
it('confidence NaN fails', () => {
|
|
272
|
-
const fullTrace = makeValidFullTrace();
|
|
273
|
-
const refined = makeValidRefinedTrace(fullTrace);
|
|
274
|
-
const input = createTraceRefinerAgentInput(fullTrace, refined, 'diagnosis_input');
|
|
275
|
-
const output = makeValidAgentOutput(refined, { confidence: NaN });
|
|
276
|
-
const result = validateTraceRefinerAgentOutput(output, input);
|
|
277
|
-
expect(result.ok).toBe(false);
|
|
278
|
-
if (!result.ok) {
|
|
279
|
-
expect(result.errors.some((e) => e.includes('confidence'))).toBe(true);
|
|
280
|
-
}
|
|
281
|
-
});
|
|
282
|
-
it('confidence Infinity fails', () => {
|
|
283
|
-
const fullTrace = makeValidFullTrace();
|
|
284
|
-
const refined = makeValidRefinedTrace(fullTrace);
|
|
285
|
-
const input = createTraceRefinerAgentInput(fullTrace, refined, 'diagnosis_input');
|
|
286
|
-
const output = makeValidAgentOutput(refined, { confidence: Infinity });
|
|
287
|
-
const result = validateTraceRefinerAgentOutput(output, input);
|
|
288
|
-
expect(result.ok).toBe(false);
|
|
289
|
-
if (!result.ok) {
|
|
290
|
-
expect(result.errors.some((e) => e.includes('confidence'))).toBe(true);
|
|
291
|
-
}
|
|
292
|
-
});
|
|
293
|
-
it('confidence < 0 fails', () => {
|
|
294
|
-
const fullTrace = makeValidFullTrace();
|
|
295
|
-
const refined = makeValidRefinedTrace(fullTrace);
|
|
296
|
-
const input = createTraceRefinerAgentInput(fullTrace, refined, 'diagnosis_input');
|
|
297
|
-
const output = makeValidAgentOutput(refined, { confidence: -0.1 });
|
|
298
|
-
const result = validateTraceRefinerAgentOutput(output, input);
|
|
299
|
-
expect(result.ok).toBe(false);
|
|
300
|
-
if (!result.ok) {
|
|
301
|
-
expect(result.errors.some((e) => e.includes('confidence'))).toBe(true);
|
|
302
|
-
}
|
|
303
|
-
});
|
|
304
|
-
it('confidence > 1 fails', () => {
|
|
305
|
-
const fullTrace = makeValidFullTrace();
|
|
306
|
-
const refined = makeValidRefinedTrace(fullTrace);
|
|
307
|
-
const input = createTraceRefinerAgentInput(fullTrace, refined, 'diagnosis_input');
|
|
308
|
-
const output = makeValidAgentOutput(refined, { confidence: 1.5 });
|
|
309
|
-
const result = validateTraceRefinerAgentOutput(output, input);
|
|
310
|
-
expect(result.ok).toBe(false);
|
|
311
|
-
if (!result.ok) {
|
|
312
|
-
expect(result.errors.some((e) => e.includes('confidence'))).toBe(true);
|
|
313
|
-
}
|
|
314
|
-
});
|
|
315
|
-
it('confidence 0 passes', () => {
|
|
316
|
-
const fullTrace = makeValidFullTrace();
|
|
317
|
-
const refined = makeValidRefinedTrace(fullTrace);
|
|
318
|
-
const input = createTraceRefinerAgentInput(fullTrace, refined, 'diagnosis_input');
|
|
319
|
-
const output = makeValidAgentOutput(refined, { confidence: 0, evidenceMap: [] });
|
|
320
|
-
const result = validateTraceRefinerAgentOutput(output, input);
|
|
321
|
-
expect(result.ok).toBe(true);
|
|
322
|
-
});
|
|
323
|
-
it('confidence 1 passes', () => {
|
|
324
|
-
const fullTrace = makeValidFullTrace();
|
|
325
|
-
const refined = makeValidRefinedTrace(fullTrace);
|
|
326
|
-
const input = createTraceRefinerAgentInput(fullTrace, refined, 'diagnosis_input');
|
|
327
|
-
const output = makeValidAgentOutput(refined, { confidence: 1 });
|
|
328
|
-
const result = validateTraceRefinerAgentOutput(output, input);
|
|
329
|
-
expect(result.ok).toBe(true);
|
|
330
|
-
});
|
|
331
|
-
});
|
|
332
|
-
// ── validateTraceRefinerAgentOutput: refinedTrace evidenceRefs ──
|
|
333
|
-
describe('validateTraceRefinerAgentOutput: refinedTrace evidenceRefs', () => {
|
|
334
|
-
it('refinedTrace evidenceRefs with invented refs fail', () => {
|
|
335
|
-
const fullTrace = makeValidFullTrace();
|
|
336
|
-
const refined = makeValidRefinedTrace(fullTrace);
|
|
337
|
-
const input = createTraceRefinerAgentInput(fullTrace, refined, 'diagnosis_input');
|
|
338
|
-
const badRefinedTrace = {
|
|
339
|
-
...refined,
|
|
340
|
-
evidenceRefs: ['task:invented_task_999'],
|
|
341
|
-
};
|
|
342
|
-
const output = makeValidAgentOutput(badRefinedTrace);
|
|
343
|
-
const result = validateTraceRefinerAgentOutput(output, input);
|
|
344
|
-
expect(result.ok).toBe(false);
|
|
345
|
-
if (!result.ok) {
|
|
346
|
-
expect(result.errors.some((e) => e.includes('evidenceRefs') || e.includes('invented') || e.includes('allowed'))).toBe(true);
|
|
347
|
-
}
|
|
348
|
-
});
|
|
349
|
-
it('refinedTrace keyEvents evidenceRefs with invented refs fail', () => {
|
|
350
|
-
const fullTrace = makeValidFullTrace();
|
|
351
|
-
const refined = makeValidRefinedTrace(fullTrace);
|
|
352
|
-
const input = createTraceRefinerAgentInput(fullTrace, refined, 'diagnosis_input');
|
|
353
|
-
const badRefinedTrace = {
|
|
354
|
-
...refined,
|
|
355
|
-
keyEvents: [
|
|
356
|
-
{
|
|
357
|
-
kind: 'failure',
|
|
358
|
-
summary: 'Some failure',
|
|
359
|
-
evidenceRefs: ['run:invented_run_999'],
|
|
360
|
-
severity: 'high',
|
|
361
|
-
at: '2026-05-19T00:00:00Z',
|
|
362
|
-
},
|
|
363
|
-
],
|
|
364
|
-
};
|
|
365
|
-
const output = makeValidAgentOutput(badRefinedTrace);
|
|
366
|
-
const result = validateTraceRefinerAgentOutput(output, input);
|
|
367
|
-
expect(result.ok).toBe(false);
|
|
368
|
-
if (!result.ok) {
|
|
369
|
-
expect(result.errors.some((e) => e.includes('keyEvents') || e.includes('evidenceRefs') || e.includes('invented') || e.includes('allowed'))).toBe(true);
|
|
370
|
-
}
|
|
371
|
-
});
|
|
372
|
-
});
|
|
373
|
-
// ── validateTraceRefinerAgentOutput: structural validation ──
|
|
374
|
-
describe('validateTraceRefinerAgentOutput: structural validation', () => {
|
|
375
|
-
it('null output fails', () => {
|
|
376
|
-
const fullTrace = makeValidFullTrace();
|
|
377
|
-
const refined = makeValidRefinedTrace(fullTrace);
|
|
378
|
-
const input = createTraceRefinerAgentInput(fullTrace, refined, 'diagnosis_input');
|
|
379
|
-
const result = validateTraceRefinerAgentOutput(null, input);
|
|
380
|
-
expect(result.ok).toBe(false);
|
|
381
|
-
if (!result.ok) {
|
|
382
|
-
expect(result.errors.length).toBeGreaterThan(0);
|
|
383
|
-
}
|
|
384
|
-
});
|
|
385
|
-
it('missing status fails', () => {
|
|
386
|
-
const fullTrace = makeValidFullTrace();
|
|
387
|
-
const refined = makeValidRefinedTrace(fullTrace);
|
|
388
|
-
const input = createTraceRefinerAgentInput(fullTrace, refined, 'diagnosis_input');
|
|
389
|
-
const output = makeValidAgentOutput(refined);
|
|
390
|
-
delete output.status;
|
|
391
|
-
const result = validateTraceRefinerAgentOutput(output, input);
|
|
392
|
-
expect(result.ok).toBe(false);
|
|
393
|
-
});
|
|
394
|
-
it('missing refinedTrace fails', () => {
|
|
395
|
-
const fullTrace = makeValidFullTrace();
|
|
396
|
-
const refined = makeValidRefinedTrace(fullTrace);
|
|
397
|
-
const input = createTraceRefinerAgentInput(fullTrace, refined, 'diagnosis_input');
|
|
398
|
-
const output = makeValidAgentOutput(refined);
|
|
399
|
-
delete output.refinedTrace;
|
|
400
|
-
const result = validateTraceRefinerAgentOutput(output, input);
|
|
401
|
-
expect(result.ok).toBe(false);
|
|
402
|
-
});
|
|
403
|
-
it('missing generatedAt fails', () => {
|
|
404
|
-
const fullTrace = makeValidFullTrace();
|
|
405
|
-
const refined = makeValidRefinedTrace(fullTrace);
|
|
406
|
-
const input = createTraceRefinerAgentInput(fullTrace, refined, 'diagnosis_input');
|
|
407
|
-
const output = makeValidAgentOutput(refined);
|
|
408
|
-
delete output.generatedAt;
|
|
409
|
-
const result = validateTraceRefinerAgentOutput(output, input);
|
|
410
|
-
expect(result.ok).toBe(false);
|
|
411
|
-
});
|
|
412
|
-
it('invalid status value fails', () => {
|
|
413
|
-
const fullTrace = makeValidFullTrace();
|
|
414
|
-
const refined = makeValidRefinedTrace(fullTrace);
|
|
415
|
-
const input = createTraceRefinerAgentInput(fullTrace, refined, 'diagnosis_input');
|
|
416
|
-
const output = makeValidAgentOutput(refined, { status: 'unknown_status' });
|
|
417
|
-
const result = validateTraceRefinerAgentOutput(output, input);
|
|
418
|
-
expect(result.ok).toBe(false);
|
|
419
|
-
});
|
|
420
|
-
});
|
|
421
|
-
// ── Architecture guard ──
|
|
422
|
-
describe('PRI-192 TraceRefinerAgent architecture guard', () => {
|
|
423
|
-
it('trace-refiner-agent.ts has no openclaw-plugin import', async () => {
|
|
424
|
-
const { readFileSync } = await import('node:fs');
|
|
425
|
-
const { resolve } = await import('node:path');
|
|
426
|
-
const src = readFileSync(resolve(__dirname, '..', 'trace-refiner-agent.ts'), 'utf-8');
|
|
427
|
-
expect(src).not.toContain('openclaw-plugin');
|
|
428
|
-
});
|
|
429
|
-
it('trace-refiner-agent.ts has no fs/path/process/network import', async () => {
|
|
430
|
-
const { readFileSync } = await import('node:fs');
|
|
431
|
-
const { resolve } = await import('node:path');
|
|
432
|
-
const src = readFileSync(resolve(__dirname, '..', 'trace-refiner-agent.ts'), 'utf-8');
|
|
433
|
-
expect(src).not.toContain('node:fs');
|
|
434
|
-
expect(src).not.toContain('node:path');
|
|
435
|
-
expect(src).not.toContain('node:process');
|
|
436
|
-
expect(src).not.toContain('node:http');
|
|
437
|
-
expect(src).not.toContain('node:https');
|
|
438
|
-
expect(src).not.toContain('node:net');
|
|
439
|
-
expect(src).not.toContain('fetch(');
|
|
440
|
-
});
|
|
441
|
-
it('trace-refiner-agent.ts has no LLM imports', async () => {
|
|
442
|
-
const { readFileSync } = await import('node:fs');
|
|
443
|
-
const { resolve } = await import('node:path');
|
|
444
|
-
const src = readFileSync(resolve(__dirname, '..', 'trace-refiner-agent.ts'), 'utf-8');
|
|
445
|
-
expect(src).not.toContain('openai');
|
|
446
|
-
expect(src).not.toContain('anthropic');
|
|
447
|
-
});
|
|
448
|
-
it('core barrel exports TraceRefinerAgent types and functions', async () => {
|
|
449
|
-
const { readFileSync } = await import('node:fs');
|
|
450
|
-
const { resolve } = await import('node:path');
|
|
451
|
-
const src = readFileSync(resolve(__dirname, '..', 'index.ts'), 'utf-8');
|
|
452
|
-
expect(src).toContain('TraceRefinerAgentInput');
|
|
453
|
-
expect(src).toContain('TraceRefinerAgentOutput');
|
|
454
|
-
expect(src).toContain('createTraceRefinerAgentInput');
|
|
455
|
-
expect(src).toContain('validateTraceRefinerAgentOutput');
|
|
456
|
-
expect(src).toContain('applyTraceRefinerAgentShadowResult');
|
|
457
|
-
});
|
|
458
|
-
});
|
|
459
|
-
// ── Additional coverage from PR review ──
|
|
460
|
-
describe('validateTraceRefinerAgentOutput: rejectedEvidence anti-forgery', () => {
|
|
461
|
-
it('rejectedEvidence with invented sourceRefs fails', () => {
|
|
462
|
-
const fullTrace = makeValidFullTrace();
|
|
463
|
-
const refined = makeValidRefinedTrace(fullTrace);
|
|
464
|
-
const input = createTraceRefinerAgentInput(fullTrace, refined, 'diagnosis_input');
|
|
465
|
-
const output = makeValidAgentOutput(refined, {
|
|
466
|
-
rejectedEvidence: [
|
|
467
|
-
{ reason: 'Some rejection', sourceRefs: ['task:invented_task_999'] },
|
|
468
|
-
],
|
|
469
|
-
});
|
|
470
|
-
const result = validateTraceRefinerAgentOutput(output, input);
|
|
471
|
-
expect(result.ok).toBe(false);
|
|
472
|
-
if (!result.ok) {
|
|
473
|
-
expect(result.errors.some((e) => e.includes('invented') || e.includes('allowed'))).toBe(true);
|
|
474
|
-
}
|
|
475
|
-
});
|
|
476
|
-
});
|
|
477
|
-
describe('validateTraceRefinerAgentOutput: refinedTrace non-string evidenceRefs', () => {
|
|
478
|
-
it('refinedTrace evidenceRefs with non-string element fails', () => {
|
|
479
|
-
const fullTrace = makeValidFullTrace();
|
|
480
|
-
const refined = makeValidRefinedTrace(fullTrace);
|
|
481
|
-
const input = createTraceRefinerAgentInput(fullTrace, refined, 'diagnosis_input');
|
|
482
|
-
const badRefinedTrace = {
|
|
483
|
-
...refined,
|
|
484
|
-
evidenceRefs: [42],
|
|
485
|
-
};
|
|
486
|
-
const output = makeValidAgentOutput(badRefinedTrace);
|
|
487
|
-
const result = validateTraceRefinerAgentOutput(output, input);
|
|
488
|
-
expect(result.ok).toBe(false);
|
|
489
|
-
if (!result.ok) {
|
|
490
|
-
expect(result.errors.some((e) => e.includes('evidenceRefs') && e.includes('string'))).toBe(true);
|
|
491
|
-
}
|
|
492
|
-
});
|
|
493
|
-
it('refinedTrace keyEvents evidenceRefs with non-string element fails', () => {
|
|
494
|
-
const fullTrace = makeValidFullTrace();
|
|
495
|
-
const refined = makeValidRefinedTrace(fullTrace);
|
|
496
|
-
const input = createTraceRefinerAgentInput(fullTrace, refined, 'diagnosis_input');
|
|
497
|
-
const badRefinedTrace = {
|
|
498
|
-
...refined,
|
|
499
|
-
keyEvents: [
|
|
500
|
-
{
|
|
501
|
-
kind: 'failure',
|
|
502
|
-
summary: 'Some failure',
|
|
503
|
-
evidenceRefs: [null],
|
|
504
|
-
severity: 'high',
|
|
505
|
-
at: '2026-05-19T00:00:00Z',
|
|
506
|
-
},
|
|
507
|
-
],
|
|
508
|
-
};
|
|
509
|
-
const output = makeValidAgentOutput(badRefinedTrace);
|
|
510
|
-
const result = validateTraceRefinerAgentOutput(output, input);
|
|
511
|
-
expect(result.ok).toBe(false);
|
|
512
|
-
if (!result.ok) {
|
|
513
|
-
expect(result.errors.some((e) => e.includes('keyEvents') && e.includes('string'))).toBe(true);
|
|
514
|
-
}
|
|
515
|
-
});
|
|
516
|
-
});
|
|
517
|
-
describe('validateTraceRefinerAgentOutput: refinedTrace lineage validation', () => {
|
|
518
|
-
it('refinedTrace with mismatched sourceTaskId fails', () => {
|
|
519
|
-
const fullTrace = makeValidFullTrace();
|
|
520
|
-
const refined = makeValidRefinedTrace(fullTrace);
|
|
521
|
-
const input = createTraceRefinerAgentInput(fullTrace, refined, 'diagnosis_input');
|
|
522
|
-
const badRefinedTrace = {
|
|
523
|
-
...refined,
|
|
524
|
-
sourceTaskId: 'wrong_task_id',
|
|
525
|
-
};
|
|
526
|
-
const output = makeValidAgentOutput(badRefinedTrace);
|
|
527
|
-
const result = validateTraceRefinerAgentOutput(output, input);
|
|
528
|
-
expect(result.ok).toBe(false);
|
|
529
|
-
if (!result.ok) {
|
|
530
|
-
expect(result.errors.some((e) => e.includes('sourceTaskId'))).toBe(true);
|
|
531
|
-
}
|
|
532
|
-
});
|
|
533
|
-
it('refinedTrace with mismatched sourcePainId fails', () => {
|
|
534
|
-
const fullTrace = makeValidFullTrace();
|
|
535
|
-
const refined = makeValidRefinedTrace(fullTrace);
|
|
536
|
-
const input = createTraceRefinerAgentInput(fullTrace, refined, 'diagnosis_input');
|
|
537
|
-
const badRefinedTrace = {
|
|
538
|
-
...refined,
|
|
539
|
-
sourcePainId: 'wrong_pain_id',
|
|
540
|
-
};
|
|
541
|
-
const output = makeValidAgentOutput(badRefinedTrace);
|
|
542
|
-
const result = validateTraceRefinerAgentOutput(output, input);
|
|
543
|
-
expect(result.ok).toBe(false);
|
|
544
|
-
if (!result.ok) {
|
|
545
|
-
expect(result.errors.some((e) => e.includes('sourcePainId'))).toBe(true);
|
|
546
|
-
}
|
|
547
|
-
});
|
|
548
|
-
it('refinedTrace with mismatched sourceRunIds fails', () => {
|
|
549
|
-
const fullTrace = makeValidFullTrace();
|
|
550
|
-
const refined = makeValidRefinedTrace(fullTrace);
|
|
551
|
-
const input = createTraceRefinerAgentInput(fullTrace, refined, 'diagnosis_input');
|
|
552
|
-
const badRefinedTrace = {
|
|
553
|
-
...refined,
|
|
554
|
-
sourceRunIds: ['wrong_run_id'],
|
|
555
|
-
};
|
|
556
|
-
const output = makeValidAgentOutput(badRefinedTrace);
|
|
557
|
-
const result = validateTraceRefinerAgentOutput(output, input);
|
|
558
|
-
expect(result.ok).toBe(false);
|
|
559
|
-
if (!result.ok) {
|
|
560
|
-
expect(result.errors.some((e) => e.includes('sourceRunIds'))).toBe(true);
|
|
561
|
-
}
|
|
562
|
-
});
|
|
563
|
-
it('refinedTrace with matching lineage passes', () => {
|
|
564
|
-
const fullTrace = makeValidFullTrace();
|
|
565
|
-
const refined = makeValidRefinedTrace(fullTrace);
|
|
566
|
-
const input = createTraceRefinerAgentInput(fullTrace, refined, 'diagnosis_input');
|
|
567
|
-
const output = makeValidAgentOutput(refined);
|
|
568
|
-
const result = validateTraceRefinerAgentOutput(output, input);
|
|
569
|
-
expect(result.ok).toBe(true);
|
|
570
|
-
});
|
|
571
|
-
});
|
|
572
|
-
describe('validateTraceRefinerAgentOutput: refinedTrace complete shape validation', () => {
|
|
573
|
-
it('missing refinedTrace.sourceRunIds fails', () => {
|
|
574
|
-
const fullTrace = makeValidFullTrace();
|
|
575
|
-
const refined = makeValidRefinedTrace(fullTrace);
|
|
576
|
-
const input = createTraceRefinerAgentInput(fullTrace, refined, 'diagnosis_input');
|
|
577
|
-
const badRefinedTrace = { ...refined, sourceRunIds: undefined };
|
|
578
|
-
const output = makeValidAgentOutput(badRefinedTrace);
|
|
579
|
-
const result = validateTraceRefinerAgentOutput(output, input);
|
|
580
|
-
expect(result.ok).toBe(false);
|
|
581
|
-
if (!result.ok) {
|
|
582
|
-
expect(result.errors.some((e) => e.includes('sourceRunIds') && e.includes('array'))).toBe(true);
|
|
583
|
-
}
|
|
584
|
-
});
|
|
585
|
-
it('non-array sourceRunIds fails', () => {
|
|
586
|
-
const fullTrace = makeValidFullTrace();
|
|
587
|
-
const refined = makeValidRefinedTrace(fullTrace);
|
|
588
|
-
const input = createTraceRefinerAgentInput(fullTrace, refined, 'diagnosis_input');
|
|
589
|
-
const badRefinedTrace = { ...refined, sourceRunIds: 'not-array' };
|
|
590
|
-
const output = makeValidAgentOutput(badRefinedTrace);
|
|
591
|
-
const result = validateTraceRefinerAgentOutput(output, input);
|
|
592
|
-
expect(result.ok).toBe(false);
|
|
593
|
-
if (!result.ok) {
|
|
594
|
-
expect(result.errors.some((e) => e.includes('sourceRunIds') && e.includes('array'))).toBe(true);
|
|
595
|
-
}
|
|
596
|
-
});
|
|
597
|
-
it('sourceRunIds with non-string item fails', () => {
|
|
598
|
-
const fullTrace = makeValidFullTrace();
|
|
599
|
-
const refined = makeValidRefinedTrace(fullTrace);
|
|
600
|
-
const input = createTraceRefinerAgentInput(fullTrace, refined, 'diagnosis_input');
|
|
601
|
-
const badRefinedTrace = { ...refined, sourceRunIds: [42] };
|
|
602
|
-
const output = makeValidAgentOutput(badRefinedTrace);
|
|
603
|
-
const result = validateTraceRefinerAgentOutput(output, input);
|
|
604
|
-
expect(result.ok).toBe(false);
|
|
605
|
-
if (!result.ok) {
|
|
606
|
-
expect(result.errors.some((e) => e.includes('sourceRunIds') && e.includes('string'))).toBe(true);
|
|
607
|
-
}
|
|
608
|
-
});
|
|
609
|
-
it('missing refinedTrace.evidenceRefs fails', () => {
|
|
610
|
-
const fullTrace = makeValidFullTrace();
|
|
611
|
-
const refined = makeValidRefinedTrace(fullTrace);
|
|
612
|
-
const input = createTraceRefinerAgentInput(fullTrace, refined, 'diagnosis_input');
|
|
613
|
-
const badRefinedTrace = { ...refined, evidenceRefs: undefined };
|
|
614
|
-
const output = makeValidAgentOutput(badRefinedTrace);
|
|
615
|
-
const result = validateTraceRefinerAgentOutput(output, input);
|
|
616
|
-
expect(result.ok).toBe(false);
|
|
617
|
-
if (!result.ok) {
|
|
618
|
-
expect(result.errors.some((e) => e.includes('evidenceRefs') && e.includes('array'))).toBe(true);
|
|
619
|
-
}
|
|
620
|
-
});
|
|
621
|
-
it('non-array evidenceRefs fails', () => {
|
|
622
|
-
const fullTrace = makeValidFullTrace();
|
|
623
|
-
const refined = makeValidRefinedTrace(fullTrace);
|
|
624
|
-
const input = createTraceRefinerAgentInput(fullTrace, refined, 'diagnosis_input');
|
|
625
|
-
const badRefinedTrace = { ...refined, evidenceRefs: 'not-array' };
|
|
626
|
-
const output = makeValidAgentOutput(badRefinedTrace);
|
|
627
|
-
const result = validateTraceRefinerAgentOutput(output, input);
|
|
628
|
-
expect(result.ok).toBe(false);
|
|
629
|
-
if (!result.ok) {
|
|
630
|
-
expect(result.errors.some((e) => e.includes('evidenceRefs') && e.includes('array'))).toBe(true);
|
|
631
|
-
}
|
|
632
|
-
});
|
|
633
|
-
it('missing refinedTrace.keyEvents fails', () => {
|
|
634
|
-
const fullTrace = makeValidFullTrace();
|
|
635
|
-
const refined = makeValidRefinedTrace(fullTrace);
|
|
636
|
-
const input = createTraceRefinerAgentInput(fullTrace, refined, 'diagnosis_input');
|
|
637
|
-
const badRefinedTrace = { ...refined, keyEvents: undefined };
|
|
638
|
-
const output = makeValidAgentOutput(badRefinedTrace);
|
|
639
|
-
const result = validateTraceRefinerAgentOutput(output, input);
|
|
640
|
-
expect(result.ok).toBe(false);
|
|
641
|
-
if (!result.ok) {
|
|
642
|
-
expect(result.errors.some((e) => e.includes('keyEvents') && e.includes('array'))).toBe(true);
|
|
643
|
-
}
|
|
644
|
-
});
|
|
645
|
-
it('non-array keyEvents fails', () => {
|
|
646
|
-
const fullTrace = makeValidFullTrace();
|
|
647
|
-
const refined = makeValidRefinedTrace(fullTrace);
|
|
648
|
-
const input = createTraceRefinerAgentInput(fullTrace, refined, 'diagnosis_input');
|
|
649
|
-
const badRefinedTrace = { ...refined, keyEvents: 'not-array' };
|
|
650
|
-
const output = makeValidAgentOutput(badRefinedTrace);
|
|
651
|
-
const result = validateTraceRefinerAgentOutput(output, input);
|
|
652
|
-
expect(result.ok).toBe(false);
|
|
653
|
-
if (!result.ok) {
|
|
654
|
-
expect(result.errors.some((e) => e.includes('keyEvents') && e.includes('array'))).toBe(true);
|
|
655
|
-
}
|
|
656
|
-
});
|
|
657
|
-
it('keyEvent non-object fails', () => {
|
|
658
|
-
const fullTrace = makeValidFullTrace();
|
|
659
|
-
const refined = makeValidRefinedTrace(fullTrace);
|
|
660
|
-
const input = createTraceRefinerAgentInput(fullTrace, refined, 'diagnosis_input');
|
|
661
|
-
const badRefinedTrace = {
|
|
662
|
-
...refined,
|
|
663
|
-
keyEvents: [
|
|
664
|
-
'not-an-object',
|
|
665
|
-
],
|
|
666
|
-
};
|
|
667
|
-
const output = makeValidAgentOutput(badRefinedTrace);
|
|
668
|
-
const result = validateTraceRefinerAgentOutput(output, input);
|
|
669
|
-
expect(result.ok).toBe(false);
|
|
670
|
-
if (!result.ok) {
|
|
671
|
-
expect(result.errors.some((e) => e.includes('keyEvents[0]') && e.includes('object'))).toBe(true);
|
|
672
|
-
}
|
|
673
|
-
});
|
|
674
|
-
it('keyEvent null fails', () => {
|
|
675
|
-
const fullTrace = makeValidFullTrace();
|
|
676
|
-
const refined = makeValidRefinedTrace(fullTrace);
|
|
677
|
-
const input = createTraceRefinerAgentInput(fullTrace, refined, 'diagnosis_input');
|
|
678
|
-
const badRefinedTrace = {
|
|
679
|
-
...refined,
|
|
680
|
-
keyEvents: [
|
|
681
|
-
null,
|
|
682
|
-
],
|
|
683
|
-
};
|
|
684
|
-
const output = makeValidAgentOutput(badRefinedTrace);
|
|
685
|
-
const result = validateTraceRefinerAgentOutput(output, input);
|
|
686
|
-
expect(result.ok).toBe(false);
|
|
687
|
-
if (!result.ok) {
|
|
688
|
-
expect(result.errors.some((e) => e.includes('keyEvents[0]') && e.includes('object'))).toBe(true);
|
|
689
|
-
}
|
|
690
|
-
});
|
|
691
|
-
it('keyEvent missing evidenceRefs fails', () => {
|
|
692
|
-
const fullTrace = makeValidFullTrace();
|
|
693
|
-
const refined = makeValidRefinedTrace(fullTrace);
|
|
694
|
-
const input = createTraceRefinerAgentInput(fullTrace, refined, 'diagnosis_input');
|
|
695
|
-
const badRefinedTrace = {
|
|
696
|
-
...refined,
|
|
697
|
-
keyEvents: [
|
|
698
|
-
{ kind: 'failure', summary: 'x', evidenceRefs: undefined, severity: 'high', at: '2026-05-19T00:00:00Z' },
|
|
699
|
-
],
|
|
700
|
-
};
|
|
701
|
-
const output = makeValidAgentOutput(badRefinedTrace);
|
|
702
|
-
const result = validateTraceRefinerAgentOutput(output, input);
|
|
703
|
-
expect(result.ok).toBe(false);
|
|
704
|
-
if (!result.ok) {
|
|
705
|
-
expect(result.errors.some((e) => e.includes('keyEvents[0].evidenceRefs') && e.includes('array'))).toBe(true);
|
|
706
|
-
}
|
|
707
|
-
});
|
|
708
|
-
it('keyEvent non-array evidenceRefs fails', () => {
|
|
709
|
-
const fullTrace = makeValidFullTrace();
|
|
710
|
-
const refined = makeValidRefinedTrace(fullTrace);
|
|
711
|
-
const input = createTraceRefinerAgentInput(fullTrace, refined, 'diagnosis_input');
|
|
712
|
-
const badRefinedTrace = {
|
|
713
|
-
...refined,
|
|
714
|
-
keyEvents: [
|
|
715
|
-
{ kind: 'failure', summary: 'x', evidenceRefs: 'not-array', severity: 'high', at: '2026-05-19T00:00:00Z' },
|
|
716
|
-
],
|
|
717
|
-
};
|
|
718
|
-
const output = makeValidAgentOutput(badRefinedTrace);
|
|
719
|
-
const result = validateTraceRefinerAgentOutput(output, input);
|
|
720
|
-
expect(result.ok).toBe(false);
|
|
721
|
-
if (!result.ok) {
|
|
722
|
-
expect(result.errors.some((e) => e.includes('keyEvents[0].evidenceRefs') && e.includes('array'))).toBe(true);
|
|
723
|
-
}
|
|
724
|
-
});
|
|
725
|
-
});
|
|
726
|
-
//# sourceMappingURL=trace-refiner-agent.test.js.map
|