Explorar o código

Use the isolated runtime for legacy appointment deletion

彭峰 hai 1 hora
pai
achega
13a254aff6

+ 3 - 1
scripts/lib/legacy-appointment-deletions.mjs

@@ -1,8 +1,10 @@
 import {readFileSync} from 'node:fs';
+import {withXiaoshuRuntime} from './xiaoshu-runtime-compat.mjs';
 export function buildAppointmentDeletionGateway(company,windows=[]){
  const read=name=>readFileSync(new URL('../cloud/'+name+'.js',import.meta.url),'utf8');
  const code=(read('legacy-writing-sync-ownership')+'\n'+read('legacy-appointment-deletions')).replaceAll('__COMPANY_ID__',JSON.stringify(company)).replaceAll('__WINDOWS__',JSON.stringify(windows));
- new Function(code);return code;
+ const source=withXiaoshuRuntime(code);
+ new Function(source);return source;
 }
 export function patchAppointmentDeletionCapability(code){
  if(code.includes("appointmentDeletionVersion:'confirmed-ids-v1'"))return code;

+ 1 - 1
scripts/tests/legacy-appointment-deletions.test.mjs

@@ -30,7 +30,7 @@ after(()=>db.close());
 beforeEach(async()=>{
  await db.exec('TRUNCATE "CommonModel","CourseAppointment","CourseCreditReservation","LessonRecord","LessonRecordFact","LessonCompletionReport","LegacySyncConflict","LegacyDirectBaseline","LegacyDirectBatch","LegacyDirectSourcePage"');
  liveIds=new Set([100]);fail=false;wrongFilter=false;canaryMissing=false;readHook=null;
- context={Psql,URLSearchParams,AbortSignal,Date,Parse:{Config:{get:async()=>({get:key=>({legacyScheduleApiUrl:'https://old.invalid/api',legacyScheduleApiId:'test',legacyScheduleApiKey:'test'}[key])})}},fetch:async url=>{
+ context={Psql,URLSearchParams,AbortSignal,Date,Parse:{User:function(){},Config:{get:async()=>({get:key=>({legacyScheduleApiUrl:'https://old.invalid/api',legacyScheduleApiId:'test',legacyScheduleApiKey:'test'}[key])})}},fetch:async url=>{
   const p=new URL(url).searchParams,requested=p.get('ids')?.split(',').map(Number);
   if(readHook&&requested&&!requested.includes(100))await readHook();
   if(fail&&requested&&!requested.includes(100))return{ok:true,json:async()=>({retcode:-1,result:[],page:{itemCount:0,pageCount:0}})};