@@ -13,8 +13,15 @@ import {
1313 parseEvidence ,
1414 immutableEvidence ,
1515 withEvidenceCallerInputPath ,
16+ rebindEvidenceToTargetPath ,
1617} from "./evidence.js" ;
17- import { MAX_JSON_DEPTH , type JsonValue } from "./jsonValue.js" ;
18+ import {
19+ MAX_JSON_DEPTH ,
20+ jsonValueSchema ,
21+ type JsonValue ,
22+ } from "./jsonValue.js" ;
23+ import { AnalysisResourceConstraintError } from "./analysisErrorCore.js" ;
24+ import { projectAnalysisError } from "./analysisErrorProjection.js" ;
1825import { createEvidenceBundle } from "./evidenceBundle.js" ;
1926import { freezeJsonSnapshot } from "./immutableJson.js" ;
2027
@@ -183,6 +190,49 @@ it("retains verbatim caller input without changing semantic identity or copying
183190 expect ( ( ) => withEvidenceCallerInputPath ( second , "invalid\0path" ) ) . toThrow ( ) ;
184191} ) ;
185192
193+ it . each ( [ "caller selection" , "subject display" ] ) (
194+ "preserves sealed JSON ownership when rebinding %s metadata" ,
195+ ( metadata ) => {
196+ const original = createEvidence (
197+ TARGET ,
198+ PROVIDER ,
199+ {
200+ operation : "inspect" ,
201+ parameters : { } ,
202+ result : { rows : [ { value : "observed" } ] } ,
203+ rawResult : { source : [ "provider" ] } ,
204+ } ,
205+ { immutable : true } ,
206+ ) ;
207+ const rebound =
208+ metadata === "caller selection"
209+ ? withEvidenceCallerInputPath ( original , "./selected/../alias" )
210+ : rebindEvidenceToTargetPath ( original , {
211+ ...TARGET ,
212+ path : "/tmp/selected-alias" ,
213+ } ) ;
214+ const projected = projectAnalysisError (
215+ new AnalysisResourceConstraintError (
216+ "inspect" ,
217+ "memory" ,
218+ "low heap" ,
219+ null ,
220+ {
221+ partialObservation : rebound ,
222+ } ,
223+ ) ,
224+ ) ;
225+ expect ( rebound ) . not . toBe ( original ) ;
226+ expect ( rebound . evidence_id ) . toBe ( original . evidence_id ) ;
227+ expect ( rebound . normalized_result ) . toBe ( original . normalized_result ) ;
228+ expect ( rebound . raw_result ) . toBe ( original . raw_result ) ;
229+ expect ( projected . details ?. partial_observation ) . toBe ( rebound ) ;
230+ expect ( jsonValueSchema . parse ( rebound ) ) . toBe ( rebound ) ;
231+ expect ( original . caller_input_path ) . toBeUndefined ( ) ;
232+ expect ( original . subject ?. local_path ) . toBe ( TARGET . path ) ;
233+ } ,
234+ ) ;
235+
186236it ( "applies the JSON depth boundary to owned immutable results" , ( ) => {
187237 let result : JsonValue = 1 ;
188238 for ( let index = 0 ; index <= MAX_JSON_DEPTH ; index += 1 )
0 commit comments