@@ -134,6 +134,15 @@ describe('assessPullRequest', () => {
134134 expect ( await assess ( [ file ( 'src/example.js' ) ] , fetchImpl ) ) . toMatchObject ( {
135135 status : 'low' ,
136136 aiComplete : true ,
137+ trace : {
138+ model : 'muse-spark-1.2' ,
139+ forcedBy : [ ] ,
140+ decision : {
141+ requiresMetaImport : false ,
142+ reason : 'Checked the changed behavior.' ,
143+ evidenceFiles : [ ] ,
144+ } ,
145+ } ,
137146 } ) ;
138147 expect ( fetchImpl ) . toHaveBeenCalledWith (
139148 'https://api.meta.ai/v1/responses' ,
@@ -184,17 +193,35 @@ describe('assessPullRequest', () => {
184193
185194 test ( 'can escalate a workflow-only change when the model finds a concrete risk' , async ( ) => {
186195 const path = '.github/workflows/test-all.yml' ;
187- expect (
188- await assess ( [ file ( path ) ] , async ( ) => modelResponse ( true , [ path ] ) ) ,
189- ) . toMatchObject ( { status : 'high' , aiComplete : true } ) ;
196+ const result = await assess ( [ file ( path ) ] , async ( ) =>
197+ modelResponse ( true , [ path ] ) ,
198+ ) ;
199+ expect ( result ) . toMatchObject ( {
200+ status : 'high' ,
201+ aiComplete : true ,
202+ trace : {
203+ forcedBy : [ ] ,
204+ decision : {
205+ requiresMetaImport : true ,
206+ reason : 'Checked the changed behavior.' ,
207+ evidenceFiles : [ path ] ,
208+ } ,
209+ } ,
210+ } ) ;
211+ expect ( JSON . stringify ( result . trace ) ) . not . toContain ( 'test-key' ) ;
212+ expect ( JSON . stringify ( result . trace ) ) . not . toContain ( '@@ -1 +1 @@' ) ;
190213 } ) ;
191214
192215 test ( 'never downgrades a sensitive path based on model output' , async ( ) => {
193216 expect (
194217 await assess ( [ file ( 'packages/react-native/package.json' ) ] , async ( ) =>
195218 modelResponse ( false ) ,
196219 ) ,
197- ) . toMatchObject ( { status : 'high' , aiComplete : true } ) ;
220+ ) . toMatchObject ( {
221+ status : 'high' ,
222+ aiComplete : true ,
223+ trace : { forcedBy : [ 'packages/react-native/package.json' ] } ,
224+ } ) ;
198225 } ) ;
199226
200227 test ( 'honors a high-risk label on otherwise low-risk files' , async ( ) => {
@@ -216,31 +243,83 @@ describe('assessPullRequest', () => {
216243 await assess ( [ file ( 'src/example.js' ) ] , async ( ) => {
217244 throw new Error ( 'Network failure' ) ;
218245 } ) ,
219- ) . toEqual ( { status : 'unknown' , aiComplete : false } ) ;
246+ ) . toMatchObject ( {
247+ status : 'unknown' ,
248+ aiComplete : false ,
249+ trace : { failure : 'model_request_failed' } ,
250+ } ) ;
220251 expect (
221252 await assess ( [ file ( 'package.json' ) ] , async ( ) => {
222253 throw new Error ( 'Network failure' ) ;
223254 } ) ,
224- ) . toEqual ( { status : 'high' , aiComplete : false } ) ;
255+ ) . toMatchObject ( {
256+ status : 'high' ,
257+ aiComplete : false ,
258+ trace : {
259+ failure : 'model_request_failed' ,
260+ forcedBy : [ 'package.json' ] ,
261+ } ,
262+ } ) ;
263+ } ) ;
264+
265+ test ( 'records a safe failure category without logging the HTTP response' , async ( ) => {
266+ const result = await assess ( [ file ( 'src/example.js' ) ] , async ( ) => ( {
267+ ok : false ,
268+ status : 429 ,
269+ } ) ) ;
270+ expect ( result ) . toMatchObject ( {
271+ status : 'unknown' ,
272+ aiComplete : false ,
273+ trace : { failure : 'model_http_429' } ,
274+ } ) ;
275+ } ) ;
276+
277+ test ( 'does not expose invalid model output in the trace' , async ( ) => {
278+ const result = await assess ( [ file ( 'src/example.js' ) ] , async ( ) => ( {
279+ ok : true ,
280+ json : async ( ) => ( { output_text : 'untrusted raw model output' } ) ,
281+ } ) ) ;
282+ expect ( result ) . toMatchObject ( {
283+ status : 'unknown' ,
284+ aiComplete : false ,
285+ trace : { failure : 'invalid_model_decision' } ,
286+ } ) ;
287+ expect ( JSON . stringify ( result . trace ) ) . not . toContain ( 'untrusted raw' ) ;
288+ } ) ;
289+
290+ test ( 'bounds the number of evidence paths in the trace' , async ( ) => {
291+ const paths = Array . from ( { length : 11 } , ( _ , i ) => `src/file${ i } .js` ) ;
292+ const result = await assess (
293+ paths . map ( path => file ( path ) ) ,
294+ async ( ) => modelResponse ( true , paths ) ,
295+ ) ;
296+ expect ( result . trace . decision . evidenceFiles ) . toHaveLength ( 10 ) ;
297+ expect ( result . trace . decision . evidenceFileCount ) . toBe ( 11 ) ;
225298 } ) ;
226299
227300 test ( 'treats missing patches and capped file listings as incomplete' , async ( ) => {
228301 const fetchImpl = jest . fn ( ) ;
229302 expect (
230303 await assess ( [ file ( 'image.png' , { patch : undefined } ) ] , fetchImpl ) ,
231- ) . toEqual ( {
304+ ) . toMatchObject ( {
232305 status : 'unknown' ,
233306 aiComplete : false ,
307+ trace : { failure : 'missing_or_incomplete_patch' } ,
234308 } ) ;
235309 expect (
236310 await assess ( Array ( 3000 ) . fill ( file ( 'README.md' ) ) , fetchImpl ) ,
237- ) . toEqual ( {
311+ ) . toMatchObject ( {
238312 status : 'unknown' ,
239313 aiComplete : false ,
314+ trace : { failure : 'file_list_capped' } ,
240315 } ) ;
241316 expect (
242317 await assess ( [ file ( 'src/large.js' , { changes : 500 } ) ] , fetchImpl ) ,
243- ) . toEqual ( { status : 'unknown' , aiComplete : false } ) ;
318+ ) . toMatchObject ( {
319+ status : 'unknown' ,
320+ aiComplete : false ,
321+ trace : { failure : 'missing_or_incomplete_patch' } ,
322+ } ) ;
244323 expect ( fetchImpl ) . not . toHaveBeenCalled ( ) ;
245324 } ) ;
246325} ) ;
0 commit comments