@@ -12,6 +12,7 @@ import {
1212 getMediaTreatmentCapabilityDetail ,
1313 getMediaTreatmentCapabilityOverview ,
1414 mediaTreatmentCommand ,
15+ resolveMediaTreatmentSource ,
1516} from "./media-treatment.js" ;
1617import { CliRuntimeError } from "../utils/commandResult.js" ;
1718
@@ -22,6 +23,9 @@ describe("applyMediaTreatmentToHtml", () => {
2223 const overview = getMediaTreatmentCapabilityOverview ( ) ;
2324
2425 expect ( overview . families . find ( ( { id } ) => id === "correction" ) ) . not . toHaveProperty ( "items" ) ;
26+ expect ( overview . families . find ( ( { id } ) => id === "grading" ) ) . toMatchObject ( {
27+ label : "Color Grading" ,
28+ } ) ;
2529 expect ( overview . families . find ( ( { id } ) => id === "art" ) ) . not . toHaveProperty ( "items" ) ;
2630 expect ( overview . families . find ( ( { id } ) => id === "overlays" ) ) . toMatchObject ( {
2731 owner : "registry" ,
@@ -76,6 +80,40 @@ describe("applyMediaTreatmentToHtml", () => {
7680 family : "finishing" ,
7781 control : expect . objectContaining ( { key : "vignette" } ) ,
7882 } ) ;
83+ expect ( getMediaTreatmentCapabilityDetail ( "wheels" ) ) . toMatchObject ( {
84+ contract : expect . objectContaining ( { zones : [ "shadows" , "midtones" , "highlights" ] } ) ,
85+ } ) ;
86+ expect ( getMediaTreatmentCapabilityDetail ( "curves" ) ) . toMatchObject ( {
87+ contract : expect . objectContaining ( { channels : [ "master" , "red" , "green" , "blue" ] } ) ,
88+ } ) ;
89+ const hueCurves = getMediaTreatmentCapabilityDetail ( "hue-curves" ) ;
90+ const serializedHueCurves = JSON . stringify ( hueCurves ) ;
91+ expect ( serializedHueCurves ) . toContain ( '"maxPoints":16' ) ;
92+ expect ( serializedHueCurves ) . toContain ( '"key":"hueVsHue"' ) ;
93+ expect ( serializedHueCurves ) . toContain ( '"key":"hueVsSaturation"' ) ;
94+ expect ( serializedHueCurves ) . toContain ( '"key":"hueVsLuma"' ) ;
95+ expect ( getMediaTreatmentCapabilityDetail ( "secondary" ) ) . toMatchObject ( {
96+ contract : expect . objectContaining ( {
97+ max : 4 ,
98+ saturation : expect . objectContaining ( { relation : "min < max" } ) ,
99+ luma : expect . objectContaining ( { relation : "min < max" } ) ,
100+ } ) ,
101+ } ) ;
102+ expect ( getMediaTreatmentCapabilityDetail ( "grading" ) ) . toMatchObject ( {
103+ order : [
104+ "adjust" ,
105+ "wheels" ,
106+ "curves" ,
107+ "hueCurves" ,
108+ "secondaries" ,
109+ "lut" ,
110+ "details" ,
111+ "effects" ,
112+ ] ,
113+ } ) ;
114+ expect ( getMediaTreatmentCapabilityDetail ( "scopes" ) ) . toMatchObject ( {
115+ command : expect . stringContaining ( "--analyze" ) ,
116+ } ) ;
79117 } ) ;
80118
81119 it ( "rejects unknown capability lookups" , ( ) => {
@@ -113,6 +151,82 @@ describe("applyMediaTreatmentToHtml", () => {
113151 expect ( result . html ) . toContain ( "data-color-grading=" ) ;
114152 } ) ;
115153
154+ it ( "normalizes and persists advanced grading on real media" , ( ) => {
155+ const result = applyMediaTreatmentToHtml ( VIDEO , {
156+ selector : "#hero" ,
157+ grading : {
158+ wheels : { shadows : { hue : 205 , amount : 0.08 , level : 0.02 } } ,
159+ curves : {
160+ master : [
161+ [ 0 , 0 ] ,
162+ [ 0.5 , 0.55 ] ,
163+ [ 1 , 1 ] ,
164+ ] ,
165+ } ,
166+ hueCurves : {
167+ hueVsSaturation : [
168+ [ 180 , 0 ] ,
169+ [ 210 , 0.15 ] ,
170+ [ 240 , 0 ] ,
171+ ] ,
172+ } ,
173+ secondaries : [
174+ {
175+ key : {
176+ hue : { center : 215 , range : 25 , softness : 10 } ,
177+ saturation : { min : 0.2 , max : 1 , softness : 0.08 } ,
178+ luma : { min : 0.1 , max : 0.9 , softness : 0.08 } ,
179+ } ,
180+ correction : { saturation : 0.15 , luma : 0.03 } ,
181+ } ,
182+ ] ,
183+ } ,
184+ } ) ;
185+
186+ expect ( result . changed ) . toBe ( true ) ;
187+ expect ( result . value ) . toContain ( '"wheels"' ) ;
188+ expect ( result . value ) . toContain ( '"curves"' ) ;
189+ expect ( result . value ) . toContain ( '"hueCurves"' ) ;
190+ expect ( result . value ) . toContain ( '"secondaries"' ) ;
191+ } ) ;
192+
193+ it ( "persists a disabled secondary without treating it as an active grade" , ( ) => {
194+ const result = applyMediaTreatmentToHtml ( VIDEO , {
195+ selector : "#hero" ,
196+ grading : {
197+ secondaries : [
198+ {
199+ enabled : false ,
200+ key : { hue : { center : 215 , range : 25 } } ,
201+ correction : { saturation : 0.15 } ,
202+ } ,
203+ ] ,
204+ } ,
205+ } ) ;
206+
207+ expect ( result . changed ) . toBe ( true ) ;
208+ expect ( result . value ) . toContain ( '"enabled":false' ) ;
209+ expect ( result . value ) . toContain ( '"secondaries"' ) ;
210+ } ) ;
211+
212+ it ( "resolves nested composition media through the shared project-root contract" , ( ) => {
213+ const project = "/tmp/hf-project" ;
214+
215+ expect (
216+ resolveMediaTreatmentSource (
217+ project ,
218+ "compositions/scene.html" ,
219+ "../capture/talking-head.mp4?v=1#frame" ,
220+ ) ,
221+ ) . toBe ( join ( project , "capture/talking-head.mp4" ) ) ;
222+ expect (
223+ resolveMediaTreatmentSource ( project , "compositions/scene.html" , "assets/photo.webp" ) ,
224+ ) . toBe ( join ( project , "assets/photo.webp" ) ) ;
225+ expect ( ( ) =>
226+ resolveMediaTreatmentSource ( project , "compositions/scene.html" , "https://example.com/a.mp4" ) ,
227+ ) . toThrow ( / l o c a l p r o j e c t a s s e t / ) ;
228+ } ) ;
229+
116230 it ( "merges a validated patch and reports the stored before and after payloads" , ( ) => {
117231 const initial = applyMediaTreatmentToHtml ( VIDEO , {
118232 selector : "#hero" ,
0 commit comments