Files
ai-passport/tests/test_profile_upload.cjs
T
hex2077 6a7f4e010b chore: 新增大量静态资源、测试桩文件与配置文件,清理旧无用资源
本次提交新增了多种字体、UI图片、音频剪辑等静态资源,添加了测试桩文件与项目配置文件,同时清理了部分已废弃的旧图片与测试桩代码文件。
2026-09-22 00:42:26 +08:00

17 lines
1.5 KiB
JavaScript

const fs=require('fs'),vm=require('vm'),assert=require('assert');
const source=fs.readFileSync(require('path').join(__dirname,'../configure/profile-core.js'),'utf8');
let delays=0;const scope={TextEncoder,TextDecoder,Uint8Array,Uint8ClampedArray,setTimeout:fn=>{delays++;fn()}};
vm.createContext(scope);vm.runInContext(source+'\nthis.helpers={deviceError,beginProfileUpload};',scope);
(async()=>{
const {deviceError,beginProfileUpload}=scope.helpers;
const args={badge:1,baseRevision:42,profile:{qrPresent:true},format:4};let calls=0;
const transient={rpc:async(op,p)=>{assert.equal(op,'begin');assert.strictEqual(p,args);if(++calls<4)throw deviceError({error:'ESP_ERR_INVALID_STATE',reason:'display_pending'});return {ok:true}}};
assert((await beginProfileUpload(transient,args)).ok);assert.equal(calls,4);assert.equal(delays,3);
for(const reason of ['profile_changed','upload_busy',undefined]){
calls=0;await assert.rejects(()=>beginProfileUpload({rpc:async()=>{calls++;throw deviceError({error:'ESP_ERR_INVALID_STATE',reason})}},args));assert.equal(calls,1);assert.equal(args.baseRevision,42);
}
calls=0;await assert.rejects(()=>beginProfileUpload({rpc:async()=>{calls++;throw deviceError({error:'ESP_ERR_INVALID_STATE',reason:'display_pending'})}},args));assert.equal(calls,16);
assert(deviceError({reason:'profile_changed'}).message.includes('当前编辑已保留'));
console.log('Upload recovery PASS: bounded display retry, unchanged revision, no retry for conflicts/other sessions/unknown failures');
})().catch(e=>{console.error(e);process.exitCode=1});