Project format updates
This commit is contained in:
@@ -10,11 +10,12 @@ const KV_TYPE='application/vnd.isa.kv-store';
|
||||
const manifest=id=>({formatVersion:1,id,name:'Example',createdAt:'2026-11-03T12:00:00Z',updatedAt:'2026-11-03T12:00:00Z',unknown:{keep:true}});
|
||||
const project=id=>({id,folderId:id,name:'Example',path:`/projects/${id}.isap`,projectIdentity:id});
|
||||
function fixture() {
|
||||
const files=new Map(),stores=new Map(),snapshots=new Map(),calls=[],projects=new Map();
|
||||
const files=new Map(),stores=new Map(),snapshots=new Map(),calls=[];
|
||||
let creates=0,snapshotSequence=0;
|
||||
function add(path,bytes,type='application/octet-stream') {files.set(path,{bytes:bytes instanceof Uint8Array?bytes:strToU8(bytes),contentType:type,revision:1,id:path});}
|
||||
function folder(path){files.set(path,{kind:'folder',bytes:new Uint8Array(),revision:0,id:path});}
|
||||
function putProject(id,name='Example') {const value={...project(id),name};projects.set(id,value);folder(value.path);folder(`${value.path}/extensions`);folder(`${value.path}/assets`);add(`${value.path}/project.json`,JSON.stringify({...manifest(id),name}),'application/json');return value;}
|
||||
function putProject(id,name='Example') {const value={...project(id),name};folder(value.path);folder(`${value.path}/extensions`);folder(`${value.path}/assets`);add(`${value.path}/project.json`,JSON.stringify({...manifest(id),name}),'application/json');return value;}
|
||||
folder('/projects');
|
||||
const original=putProject('original');
|
||||
const media=new Uint8Array([0,255,17,48,0,99]);
|
||||
add(`${original.path}/assets/audio.bin`,media,'audio/wav');
|
||||
@@ -28,12 +29,10 @@ function fixture() {
|
||||
const bridge={
|
||||
async invoke(command,args) {
|
||||
calls.push({command,args});
|
||||
if(command==='localstorage_get')return [];
|
||||
if(command==='localstorage_get')return args.key==='isa-project-format.folders.v1' ? [{path:'/projects',id:'/projects',canWrite:true}] : [];
|
||||
if(command==='localstorage_put')return {status:'ok'};
|
||||
if(command==='projects_list')return {projects:[...projects.values()]};
|
||||
if(command==='projects_create')return {created:true,project:putProject(`imported-${++creates}`,args.name)};
|
||||
if(command==='filesystem_list_dir')return {authoritative:true,files:[...files].filter(([path])=>path.startsWith(`${args.path}/`)).map(([path,row])=>({path,id:row.id,kind:row.kind??'file',contentType:row.contentType,syncRevision:row.revision,fileSize:row.bytes.length}))};
|
||||
if(command==='filesystem_create_folder') {assert.equal(files.get(args.path.slice(0,args.path.lastIndexOf('/')))?.kind,'folder');folder(args.path);return {status:'ok',path:args.path,fileId:files.get(args.path).id};}
|
||||
if(command==='filesystem_list_dir')return {authoritative:true,files:[...files].filter(([path])=>path===args.path||path.startsWith(`${args.path}/`)).map(([path,row])=>({path,id:row.id,kind:row.kind??'file',contentType:row.contentType,syncRevision:row.revision,fileSize:row.bytes.length}))};
|
||||
if(command==='filesystem_create_folder') {if(args.path.endsWith('.isap'))creates++;assert.equal(files.get(args.path.slice(0,args.path.lastIndexOf('/')))?.kind,'folder');folder(args.path);return {status:'ok',path:args.path,fileId:files.get(args.path).id};}
|
||||
if(command==='filesystem_get_files')return {items:args.files.map(request=>{
|
||||
const row=files.get(request.path);
|
||||
if(!row)return {status:'absent',path:request.path,source:'dashboard',authoritative:true};
|
||||
@@ -206,7 +205,7 @@ test('import activates only complete staged projects and picks unique UTF-16-saf
|
||||
|
||||
test('failed import retires its staged session while preserving the previously active project',async()=>{
|
||||
const f=fixture(),source=await f.client.activate(f.original),bytes=await exportProject(source,{bridge:f.bridge});
|
||||
const normal=f.bridge.invoke.bind(f.bridge);f.bridge.invoke=(command,args)=>command==='filesystem_create_folder'?Promise.reject(new Error('Folder write failed')):normal(command,args);
|
||||
const normal=f.bridge.invoke.bind(f.bridge);f.bridge.invoke=(command,args)=>command==='filesystem_create_folder'&&args.path.endsWith('/extensions/unknown')?Promise.reject(new Error('Folder write failed')):normal(command,args);
|
||||
let staged;const stage=f.client.stageCreate.bind(f.client);f.client.stageCreate=async(...args)=>(staged=await stage(...args));
|
||||
await assert.rejects(importProject(f.client,bytes,{bridge:f.bridge}),error=>error.message==='Folder write failed'&&Boolean(error.project));
|
||||
assert.equal(f.client.active,source);assert.equal(staged.signal.aborted,true);
|
||||
|
||||
Reference in New Issue
Block a user