验证在线 LUT 分类、帧上传与下载应用,准备 1.22.0

这个提交包含在:
mac 于 2026-11-11 18:31:12 +08:00 提交
1 父节点 a2a8624dc0
当前提交 a04c4a69ed
11 个文件已更改
+295 -27

没有与搜索条件相匹配的文件

+96
查看文件
@@ -0,0 +1,96 @@
#import <AppKit/AppKit.h>
#import <CommonCrypto/CommonDigest.h>
#import <objc/runtime.h>
#import "../大鱼调色/Plugin/DYLUTLibrary.h"
#import "../大鱼调色/Plugin/DYLUTBrowser.h"
#import "../大鱼调色/Shared/DYOnlineLUT.h"
#include <cmath>
@interface DYLUTBrowser (OnlineAcceptance)
- (void)sourceChanged:(id)sender;
- (void)revealLibrary:(id)sender;
- (void)previousOnlinePage:(id)sender;
- (void)folderClicked:(id)sender;
- (void)searchChanged:(id)sender;
- (void)captureOnlineFrame;
- (void)thumbnailClicked:(id)sender;
- (void)rebuildGrid;
- (void)layoutBrowser;
@end
static NSMutableArray *checks,*requests;
static NSData *cubeData,*renderPNG;
static NSString *checksum;
static BOOL paid=YES,badDownload=NO;
static NSUInteger activePreviews=0,maxPreviews=0;
static void require(BOOL pass,NSString *name){[checks addObject:@{@"name":name,@"pass":@(pass)}];if(!pass){fprintf(stderr,"FAIL %s\n",name.UTF8String);exit(1);}}
static void pump(BOOL (^done)(void)){
NSDate *end=[NSDate dateWithTimeIntervalSinceNow:15];while(!done()&&end.timeIntervalSinceNow>0)[[NSRunLoop mainRunLoop]runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:.01]];
require(done(),@"asynchronous operation finished");
}
static NSUInteger count(NSString *suffix){NSUInteger n=0;for(NSDictionary *r in requests)if([r[@"path"]hasSuffix:suffix])n++;return n;}
static NSProgress *requestFixture(id cls,SEL sel,NSString *path,NSDictionary *body,BOOL authenticated,DYOnlineLUTReply reply){
NSProgress *task=[NSProgress discreteProgressWithTotalUnitCount:1];
[requests addObject:@{@"path":path,@"body":body?:@{},@"authenticated":@(authenticated)}];
BOOL preview=[path hasSuffix:@"/preview"];if(preview){activePreviews++;maxPreviews=MAX(maxPreviews,activePreviews);}
dispatch_after(dispatch_time(DISPATCH_TIME_NOW,30*NSEC_PER_MSEC),dispatch_get_main_queue(),^{
if(preview)activePreviews--;
if(task.cancelled){reply(nil,[NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorCancelled userInfo:nil]);return;}
if(!paid){reply(nil,[NSError errorWithDomain:@"test" code:403 userInfo:@{NSLocalizedDescriptionKey:@"需要会员或购买权限"}]);return;}
NSData *data=nil;
if([path hasSuffix:@"/catalog"]){
NSString *category=[body[@"category"]length]?body[@"category"]:@"胶片";NSUInteger page=[body[@"page"]unsignedIntegerValue];
NSMutableArray *items=[NSMutableArray array];
for(NSUInteger i=0;i<10;i++)[items addObject:@{@"id":@(1+(page-1)*60+i),@"title":[NSString stringWithFormat:@"测试胶片 %lu",(unsigned long)i],@"category":category,@"file_size":@(cubeData.length),@"checksum":checksum}];
data=[NSJSONSerialization dataWithJSONObject:@{@"items":items,@"categories":@[@"胶片",@"婚礼",@"相机还原"],@"total":@1233,@"page":@(page)}options:0 error:nil];
}else if([path hasSuffix:@"/download"])data=badDownload?[@"broken" dataUsingEncoding:NSUTF8StringEncoding]:cubeData;
else if(preview)data=renderPNG;
reply(data,nil);
});return task;
}
int main(int argc,const char **argv){@autoreleasepool{
if(argc!=2)return 2;checks=[NSMutableArray new];requests=[NSMutableArray new];
NSMutableString *text=[NSMutableString stringWithString:@"TITLE test\nLUT_3D_SIZE 2\n"];
for(int z=0;z<2;z++)for(int y=0;y<2;y++)for(int x=0;x<2;x++)[text appendFormat:@"%d %d %d\n",x,y,z];
cubeData=[[text dataUsingEncoding:NSUTF8StringEncoding]retain];unsigned char bytes[32];CC_SHA256(cubeData.bytes,(CC_LONG)cubeData.length,bytes);NSMutableString *digest=[NSMutableString string];for(unsigned char b:bytes)[digest appendFormat:@"%02x",b];checksum=[digest copy];
NSURL *root=[NSURL fileURLWithPath:[NSTemporaryDirectory()stringByAppendingPathComponent:[@"dayu-online-lut-" stringByAppendingString:NSUUID.UUID.UUIDString]]];
DYLUTLibrary *library=[[DYLUTLibrary alloc]initWithRootURL:root];
__block BOOL imported=NO;__block NSString *installed=nil;
[library importOnlineData:cubeData identifier:@1 name:@"测试风格" category:@"../../胶片/风格" checksum:checksum completion:^(NSString *path,NSError *error){require(path&&!error,@"valid online LUT imports");installed=[path copy];imported=YES;}];pump(^{return imported;});
require([installed hasPrefix:[library.rootURL.path stringByAppendingString:@"/"]]&&![installed.pathComponents containsObject:@".."],@"server names cannot escape local library");
imported=NO;[library importOnlineData:cubeData identifier:@1 name:@"测试风格" category:@"../../胶片/风格" checksum:checksum completion:^(NSString *path,NSError *error){require([path isEqual:installed]&&!error,@"repeat online download reuses matching local file");imported=YES;}];pump(^{return imported;});require(library.entries.count==1,@"repeat imports do not create duplicate LUTs");
imported=NO;[library importOnlineData:cubeData identifier:@2 name:@"损坏" category:@"胶片" checksum:[@"0" stringByPaddingToLength:64 withString:@"0" startingAtIndex:0] completion:^(NSString *path,NSError *error){require(!path&&error,@"checksum mismatch rejected before library changes");imported=YES;}];pump(^{return imported;});require(library.entries.count==1,@"existing local LUT preserved after rejected download");
imported=NO;NSProgress *cancel=[library importOnlineData:cubeData identifier:@2 name:@"取消" category:@"胶片" checksum:checksum completion:^(NSString *path,NSError *error){require(!path&&error.code==NSUserCancelledError,@"cancelled online import reports cancellation");imported=YES;}];[cancel cancel];pump(^{return imported;});
[NSApplication sharedApplication];[NSApp setActivationPolicy:NSApplicationActivationPolicyProhibited];
method_setImplementation(class_getClassMethod(DYOnlineLUTClient.class,@selector(request:body:authenticated:completion:)),(IMP)requestFixture);
NSMutableData *pixels=[NSMutableData dataWithLength:320*180*16];float *p=(float *)pixels.mutableBytes;for(NSUInteger i=0;i<320*180;i++){p[i*4]=.2;p[i*4+1]=.4;p[i*4+2]=.8;p[i*4+3]=1;}
NSDictionary *frame=@{@"standard":pixels,@"standardSize":[NSValue valueWithSize:NSMakeSize(320,180)],@"time":@1};
NSImage *image=DYLUTThumbnail(nil,pixels,320,180,NSMakeSize(320,180),nil);renderPNG=[[(NSBitmapImageRep *)image.representations[0]representationUsingType:NSBitmapImageFileTypePNG properties:@{}]retain];
__block NSString *applied=nil;
DYLUTBrowser *browser=[[DYLUTBrowser alloc]initWithLibrary:library preview:frame selectedPath:nil palette:@{} selection:^NSProgress *(NSString *path,void(^completion)(NSError *)){NSProgress *job=[NSProgress discreteProgressWithTotalUnitCount:1];dispatch_async(dispatch_get_main_queue(),^{[applied release];applied=[path copy];completion(nil);});return job;}];
pump(^{return [browser valueForKey:@"libraryTask"]==nil;});require(!browser.window.visible,@"acceptance never displays an unsigned test app");
NSPopUpButton *source=[browser valueForKey:@"sourceMenu"];[source selectItemAtIndex:1];[browser sourceChanged:source];pump(^{return [[browser valueForKey:@"onlineEntries"]count]==10;});
require(count(@"/catalog")==1&&count(@"/preview")==0,@"opening online categories does not upload a timeline frame");
require([[browser valueForKey:@"folderPaths"]count]==4,@"online categories include all and named categories");
require([[[browser valueForKey:@"countLabel"]stringValue]containsString:@"1233"],@"online total and pagination remain visible");
[browser revealLibrary:nil];pump(^{return [[browser valueForKey:@"onlineCatalogTask"]isFinished]||[browser valueForKey:@"onlineCatalogTask"]==nil;});require([[requests.lastObject objectForKey:@"body"][@"page"]integerValue]==2,@"next page requests page two");
[browser previousOnlinePage:nil];pump(^{return [browser valueForKey:@"onlineCatalogTask"]==nil;});
NSButton *folder=[NSButton buttonWithTitle:@"婚礼" target:nil action:nil];folder.identifier=@"婚礼";[browser folderClicked:folder];pump(^{return [browser valueForKey:@"onlineCatalogTask"]==nil;});require([requests.lastObject[@"body"][@"category"]isEqual:@"婚礼"],@"category filter is sent to the server");
NSUInteger before=count(@"/preview");[browser captureOnlineFrame];pump(^{return count(@"/preview")>before&&[[browser valueForKey:@"onlineTransfers"]count]==0;});
require(maxPreviews<=2,@"browser limits simultaneous remote preview work");
NSDictionary *upload=nil;for(NSDictionary *r in requests)if([r[@"path"]hasSuffix:@"/preview"]){upload=r;break;}
require([upload[@"body"]allKeys].count==1&&[upload[@"body"][@"frame_png"]isKindOfClass:NSString.class],@"frame request sends image pixels without project paths or filenames");
NSBitmapImageRep *uploaded=[NSBitmapImageRep imageRepWithData:[[[NSData alloc]initWithBase64EncodedString:upload[@"body"][@"frame_png"]options:0]autorelease]];require(uploaded.pixelsWide==320&&uploaded.pixelsHigh==180,@"uploaded frame preserves timeline aspect");
NSUInteger previous=count(@"/preview");[browser updatePreview:@{@"standard":pixels,@"standardSize":[NSValue valueWithSize:NSMakeSize(320,180)],@"time":@2}];require(count(@"/preview")==previous,@"new timeline frames never trigger automatic uploads");
NSDictionary *tiles=[browser valueForKey:@"tiles"];NSButton *tile=tiles.allValues.firstObject;[browser thumbnailClicked:tile];pump(^{return [browser valueForKey:@"selectionTask"]==nil&&applied!=nil;});
require([applied hasPrefix:library.rootURL.path]&&[NSFileManager.defaultManager fileExistsAtPath:applied],@"downloaded verified LUT is applied through local host selection");
NSUInteger localCount=library.entries.count;[browser thumbnailClicked:tile];pump(^{return [browser valueForKey:@"selectionTask"]==nil;});require(library.entries.count==localCount,@"repeated online click does not duplicate installed LUT");
badDownload=YES;[browser thumbnailClicked:tile];pump(^{return [browser valueForKey:@"selectionTask"]==nil;});require([[[browser valueForKey:@"statusLabel"]stringValue]containsString:@"大小"],@"incomplete download produces a visible error");badDownload=NO;
paid=NO;[browser folderClicked:folder];pump(^{return [browser valueForKey:@"onlineCatalogTask"]==nil;});require([[browser valueForKey:@"onlineEntries"]count]==0,@"permission rejection removes online entries");
[source selectItemAtIndex:0];[browser sourceChanged:source];require(![[browser valueForKey:@"onlineMode"]boolValue]&&[[browser valueForKey:@"visibleEntries"]count]>0,@"local LUT library remains usable without online permission");
[browser close];[browser release];[library release];[applied release];[installed release];
[NSFileManager.defaultManager removeItemAtURL:root error:nil];
for(NSString *key in NSUserDefaults.standardUserDefaults.dictionaryRepresentation.allKeys)if([key containsString:root.path])[NSUserDefaults.standardUserDefaults removeObjectForKey:key];
NSDictionary *report=@{@"pass":@YES,@"count":@(checks.count),@"checks":checks,@"scope":@"Isolated AppKit browser with simulated network replies; real Cube validation/import; no user credentials, no production frame upload, no visible test app."};
[[NSJSONSerialization dataWithJSONObject:report options:NSJSONWritingPrettyPrinted error:nil]writeToFile:[NSString stringWithUTF8String:argv[1]]atomically:YES];
printf("PASS %lu checks\n",(unsigned long)checks.count);return 0;
}}