merge: integrate review-19-formula-diagnostics
This commit is contained in:
commit
1e09b5b85e
5 files changed
+37
-9
No files matched your search
Vendored
+1
-1
@@ -372,7 +372,7 @@ ${this._constructorStack}
|
||||
Lifetime used`):new AB("Lifetime not alive")}},WU=class extends L6{constructor($,U){super($,void 0,void 0,U)}get dupable(){return!0}dup(){return this}dispose(){}},bI=class extends L6{constructor($,U,W,G){super($,U,W,G)}dispose(){this._alive=!1}};Y4=class $ extends E4{constructor(){super(...arguments);this._disposables=new L6(new Set),this.manage=(U)=>(this._disposables.value.add(U),U)}static withScope(U){let W=new $,G;try{return U(W)}catch(X){throw G=X,X}finally{OB(W,G)}}static withScopeMaybeAsync(U,W){return em(void 0,function*(G){let X=new $,D;try{return yield*G.of(W.call(U,G,X))}catch(Y){throw D=Y,Y}finally{OB(X,D)}})}static async withScopeAsync(U){let W=new $,G;try{return await U(W)}catch(X){throw G=X,X}finally{OB(W,G)}}get alive(){return this._disposables.alive}dispose(){let U=Array.from(this._disposables.value.values()).reverse();for(let W of U)W.alive&&W.dispose();this._disposables.dispose()}};SB=class $ extends E4{static success(U){return new Ul(U)}static fail(U,W){return new Wl(U,W)}static is(U){return U instanceof $}},Ul=class extends SB{constructor($){super();this.value=$}get alive(){return V3(this.value)?this.value.alive:!0}dispose(){V3(this.value)&&this.value.dispose()}unwrap(){return this.value}unwrapOr($){return this.value}},Wl=class extends SB{constructor($,U){super();this.error=$,this.onUnwrap=U}get alive(){return V3(this.error)?this.error.alive:!0}dispose(){V3(this.error)&&this.error.dispose()}unwrap(){throw this.onUnwrap(this),this.error}unwrapOr($){return $}},h8=SB,Xl=class extends E4{constructor($){super();this.resolve=(U)=>{this.resolveHandle.alive&&(this.context.unwrapResult(this.context.callFunction(this.resolveHandle,this.context.undefined,U||this.context.undefined)).dispose(),this.disposeResolvers(),this.onSettled())},this.reject=(U)=>{this.rejectHandle.alive&&(this.context.unwrapResult(this.context.callFunction(this.rejectHandle,this.context.undefined,U||this.context.undefined)).dispose(),this.disposeResolvers(),this.onSettled())},this.dispose=()=>{this.handle.alive&&this.handle.dispose(),this.disposeResolvers()},this.context=$.context,this.owner=$.context.runtime,this.handle=$.promiseHandle,this.settled=new Promise((U)=>{this.onSettled=U}),this.resolveHandle=$.resolveHandle,this.rejectHandle=$.rejectHandle}get alive(){return this.handle.alive||this.resolveHandle.alive||this.rejectHandle.alive}disposeResolvers(){this.resolveHandle.alive&&this.resolveHandle.dispose(),this.rejectHandle.alive&&this.rejectHandle.dispose()}},D4$=Symbol("Unstable"),Y4$=Object.freeze({BaseObjects:!0,Date:!0,Eval:!0,StringNormalize:!0,RegExp:!0,JSON:!0,Proxy:!0,MapSet:!0,TypedArrays:!0,Promise:!0});Kl=class extends E4{constructor($,U){super();this.handle=$,this.context=U,this._isDone=!1,this.owner=U.runtime}[Symbol.iterator](){return this}next($){if(!this.alive||this._isDone)return{done:!0,value:void 0};let U=this._next??(this._next=this.context.getProp(this.handle,"next"));return this.callIteratorMethod(U,$)}return($){if(!this.alive)return{done:!0,value:void 0};let U=this.context.getProp(this.handle,"return");if(U===this.context.undefined&&$===void 0)return this.dispose(),{done:!0,value:void 0};let W=this.callIteratorMethod(U,$);return U.dispose(),this.dispose(),W}throw($){if(!this.alive)return{done:!0,value:void 0};let U=$ instanceof L6?$:this.context.newError($),W=this.context.getProp(this.handle,"throw"),G=this.callIteratorMethod(W,$);return U.alive&&U.dispose(),W.dispose(),this.dispose(),G}get alive(){return this.handle.alive}dispose(){this._isDone=!0,this.handle.dispose(),this._next?.dispose()}callIteratorMethod($,U){let W=U?this.context.callFunction($,this.handle,U):this.context.callFunction($,this.handle);if(W.error)return this.dispose(),{value:W};let G=this.context.getProp(W.value,"done").consume((D)=>this.context.dump(D)),X=this.context.getProp(W.value,"value");return W.value.dispose(),G&&this.dispose(),{value:h8.success(X),done:G}}};RI=class extends E4{constructor($,U,W){if(W===P3)throw new Q1("cannot create HostRef with undefined id");super();this.runtime=$,this.handle=U,this.id=W}get alive(){return this.handle.alive}dispose(){this.handle.dispose()}get value(){return this.runtime.hostRefs.get(this.id)}},Zl=class extends lI{constructor($){super($.module);this.scope=new Y4,this.copyJSValue=(U)=>this.ffi.QTS_DupValuePointer(this.ctx.value,U),this.freeJSValue=(U)=>{this.ffi.QTS_FreeValuePointer(this.ctx.value,U)},$.ownedLifetimes?.forEach((U)=>this.scope.manage(U)),this.owner=$.owner,this.module=$.module,this.ffi=$.ffi,this.rt=$.rt,this.ctx=this.scope.manage($.ctx)}get alive(){return this.scope.alive}dispose(){return this.scope.dispose()}[Symbol.dispose](){return this.dispose()}manage($){return this.scope.manage($)}consumeJSCharPointer($){let U=this.module.UTF8ToString($);return this.ffi.QTS_FreeCString(this.ctx.value,$),U}heapValueHandle($,U){let W=U?(G)=>{U(),this.freeJSValue(G)}:this.freeJSValue;return new L6($,this.copyJSValue,W,this.owner)}staticHeapValueHandle($){return this.manage(this.hea
Line truncated
|
||||
${W.stack}Host: ${L}`),Object.assign(Q,Y),Q}throw new jB(W)}return $.value}[Symbol.for("nodejs.util.inspect.custom")](){return this.alive?`${this.constructor.name} { ctx: ${this.ctx.value} rt: ${this.rt.value} }`:`${this.constructor.name} { disposed }`}getFunction($){let U=this.runtime.hostRefs.get($);if(typeof U!="function")throw Error(`Host reference ${$} is not a function`);return U}errorToHandle($){return $ instanceof L6?$:this.newError($)}encodeBinaryJSON($){let U=this.ffi.QTS_bjson_encode(this.ctx.value,$.value);return this.memory.heapValueHandle(U)}decodeBinaryJSON($){let U=this.ffi.QTS_bjson_decode(this.ctx.value,$.value);return this.memory.heapValueHandle(U)}success($){return h8.success($)}fail($){return h8.fail($,(U)=>this.unwrapResult(U))}},zl=class extends E4{constructor($){super();this.scope=new Y4,this.contextMap=new Map,this.hostRefs=new Ll,this._debugMode=!1,this.cToHostCallbacks={freeHostRef:(U,W)=>{if(U!==this.rt.value)throw Error("Runtime pointer mismatch");this.hostRefs.delete(W)},shouldInterrupt:(U)=>{if(U!==this.rt.value)throw Error("QuickJSContext instance received C -> JS interrupt with mismatched rt");let W=this.interruptHandler;if(!W)throw Error("QuickJSContext had no interrupt handler");return W(this)?1:0},loadModuleSource:CI(this,function*(U,W,G,X){let D=this.moduleLoader;if(!D)throw Error("Runtime has no module loader");if(W!==this.rt.value)throw Error("Runtime pointer mismatch");let Y=this.contextMap.get(G)??this.newContext({contextPointer:G});try{let Q=yield*U(D(X,Y));if(typeof Q=="object"&&"error"in Q&&Q.error)throw this.debugLog("cToHostLoadModule: loader returned error",Q.error),Q.error;let L=typeof Q=="string"?Q:("value"in Q)?Q.value:Q;return this.memory.newHeapCharPointer(L).value.ptr}catch(Q){return this.debugLog("cToHostLoadModule: caught error",Q),Y.throw(Q),0}}),normalizeModule:CI(this,function*(U,W,G,X,D){let Y=this.moduleNormalizer;if(!Y)throw Error("Runtime has no module normalizer");if(W!==this.rt.value)throw Error("Runtime pointer mismatch");let Q=this.contextMap.get(G)??this.newContext({contextPointer:G});try{let L=yield*U(Y(X,D,Q));if(typeof L=="object"&&"error"in L&&L.error)throw this.debugLog("cToHostNormalizeModule: normalizer returned error",L.error),L.error;let K=typeof L=="string"?L:L.value;return Q.getMemory(this.rt.value).newHeapCharPointer(K).value.ptr}catch(L){return this.debugLog("normalizeModule: caught error",L),Q.throw(L),0}})},$.ownedLifetimes?.forEach((U)=>this.scope.manage(U)),this.module=$.module,this.memory=new lI(this.module),this.ffi=$.ffi,this.rt=$.rt,this.callbacks=$.callbacks,this.scope.manage(this.rt),this.callbacks.setRuntimeCallbacks(this.rt.value,this.cToHostCallbacks),this.executePendingJobs=this.executePendingJobs.bind(this),VB&&this.setDebugMode(!0)}get alive(){return this.scope.alive}dispose(){return this.scope.dispose()}newContext($={}){let U=Gl($.intrinsics),W=new L6($.contextPointer||this.ffi.QTS_NewContext(this.rt.value,U),void 0,(X)=>{this.contextMap.delete(X),this.callbacks.deleteContext(X),this.ffi.QTS_FreeContext(X)}),G=new Jl({module:this.module,ctx:W,ffi:this.ffi,rt:this.rt,ownedLifetimes:$.ownedLifetimes,runtime:this,callbacks:this.callbacks});return this.contextMap.set(W.value,G),G}setModuleLoader($,U){this.moduleLoader=$,this.moduleNormalizer=U,this.ffi.QTS_RuntimeEnableModuleLoader(this.rt.value,this.moduleNormalizer?1:0)}removeModuleLoader(){this.moduleLoader=void 0,this.ffi.QTS_RuntimeDisableModuleLoader(this.rt.value)}hasPendingJob(){return!!this.ffi.QTS_IsJobPending(this.rt.value)}setInterruptHandler($){let U=this.interruptHandler;this.interruptHandler=$,U||this.ffi.QTS_RuntimeEnableInterruptHandler(this.rt.value)}removeInterruptHandler(){this.interruptHandler&&(this.ffi.QTS_RuntimeDisableInterruptHandler(this.rt.value),this.interruptHandler=void 0)}executePendingJobs($=-1){let U=this.memory.newMutablePointerArray(1),W=this.ffi.QTS_ExecutePendingJob(this.rt.value,$??-1,U.value.ptr),G=U.value.typedArray[0];if(U.dispose(),G===0)return this.ffi.QTS_FreeValuePointerRuntime(this.rt.value,W),h8.success(0);let X=this.contextMap.get(G)??this.newContext({contextPointer:G}),D=X.getMemory(this.rt.value).heapValueHandle(W);if(X.typeof(D)==="number"){let Y=X.getNumber(D);return D.dispose(),h8.success(Y)}else{let Y=Object.assign(D,{context:X});return h8.fail(Y,(Q)=>X.unwrapResult(Q))}}setMemoryLimit($){if($<0&&$!==-1)throw Error("Cannot set memory limit to negative number. To unset, pass -1");this.ffi.QTS_RuntimeSetMemoryLimit(this.rt.value,$)}computeMemoryUsage(){let $=this.getSystemContext().getMemory(this.rt.value);return $.heapValueHandle(this.ffi.QTS_RuntimeComputeMemoryUsage(this.rt.value,$.ctx.value))}dumpMemoryUsage(){return this.memory.consumeHeapCharPointer(this.ffi.QTS_RuntimeDumpMemoryUsage(this.rt.value))}setMaxStackSize($){if($<0)throw Error("Cannot set memory limit to negative number. To unset, pass 0.");this.ffi.QTS_RuntimeSetMaxStackSize(this.rt.value,$)}assertOwned($){if($.owner&&$.owner.rt!==this.rt)throw
Line truncated
|
||||
${$}
|
||||
})()`,P=O.evalCode(V,"workflow-script.js");if(P.error){let S=O.dump(P.error);throw P.error.dispose(),S}let M;try{let S=O.getPromiseState(P.value);if(!(S.type==="fulfilled"&&S.notAPromise)){if(S.type==="fulfilled")S.value.dispose();if(S.type==="rejected")S.error.dispose();throw Error("Sandbox only supports synchronous return values")}M=O.dump(P.value);let E=JSON.stringify(M);if(E!==void 0&&Buffer.byteLength(E)>tI)throw Error("Sandbox return value exceeds 1MB")}finally{P.value.dispose()}return{success:!0,durationMs:Number((performance.now()-D).toFixed(2)),returnValue:M,logs:X,inputs:U}}catch(Z){let J=Number((performance.now()-D).toFixed(2)),z=Y?"Script execution timed out":Z?.message||String(Z),O,H,B=Z?.stack||"",j=B.match(/workflow-script\.js:(\d+)(?::(\d+))?/);if(j){let A=Number(j[1]);O=Math.max(1,A-1),H=j[2]?Number(j[2]):void 0}return{success:!1,durationMs:J,returnValue:void 0,logs:X,error:{name:Z?.name||"ExecutionError",message:z,stack:B,line:O,column:H},inputs:U}}finally{K?.dispose(),L?.dispose()}}var rI,Nl=33554432,tI=1048576,Ol=65536,Bl=500,jl;var aI=b(()=>{oI();rI=Ek(wI(),1)});var sI=b(()=>{PI();aI()});function _6($,U){$.push({...U,category:U.category??(U.severity==="error"?"hard_block":"soft_advice")})}function Pl($){let W=[...(typeof $.code==="string"?$.code:"").matchAll(/\{\{\s*([^{}]+?)\s*\}\}|\b(?:ctx|input|output|context)\.([A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*)/g)].map((G)=>(G[1]||G[2]||"").trim()).filter(Boolean);return[...new Set(W)]}function eI($,U=""){return $.map((W,G)=>{let X=U?`${U}.${G}`:String(G);return{type:W.type,name:W.name,label:W.label||W.displayName||"",path:X,orderIndex:W.orderIndex,levelIndex:W.levelIndex,children:eI(W.tasks||[],X)}})}function $w($){let U=$;if(typeof U.specificationId==="string"&&U.specificationId.trim())return U.specificationId.trim();if(Array.isArray($.inputs)){let W=$.inputs.find((G)=>G.key==="specificationId");if(W&&typeof W.value==="string"&&W.value.trim())return W.value.trim()}else if(U.inputs&&typeof U.inputs==="object"){let W=U.inputs.specificationId;if(typeof W==="string"&&W.trim())return W.trim()}return}function Uw($){let U=$;if(Array.isArray(U.form))return U.form.filter((W)=>Boolean(W&&typeof W==="object"));if(U.form&&typeof U.form==="object")return Object.entries(U.form).map(([W,G])=>({key:W,value:G}));if(Array.isArray($.inputs)){let W=$.inputs.find((G)=>G.key==="form");if(W&&Array.isArray(W.value))return W.value.filter((G)=>Boolean(G&&typeof G==="object"));if(W&&W.value&&typeof W.value==="object")return Object.entries(W.value).map(([G,X])=>({key:G,value:X}))}else if(U.inputs&&typeof U.inputs==="object"){let W=U.inputs.form;if(Array.isArray(W))return W.filter((G)=>Boolean(G&&typeof G==="object"));if(W&&typeof W==="object")return Object.entries(W).map(([G,X])=>({key:G,value:X}))}return[]}function Ww($){if(!$||typeof $!=="object")return[];let U=[],W=$;if(Array.isArray(W.filters))for(let G of W.filters)U.push(...Ww(G));else if("key"in W||"value"in W)U.push({key:W.key,value:W.value,compare:W.compare,label:W.label});return U}function TB($){let U=new Set,W=(G)=>{for(let X of G){if(X.type==="flow-create-task"){let D=$w(X);if(D)U.add(D)}if(Array.isArray(X.tasks)&&X.tasks.length>0)W(X.tasks)}};return W($.tasks||[]),[...U]}function Xw($,U){if($.type!=="condition")return!1;let W=$,G=W.combineFilters??W.filters??$.inputs??W.conditions??{},X=JSON.stringify(G);if(X.includes(`${U}.$status`)||X.includes(`${U}.status`)||X.includes(`${U}.result`)||X.includes(`${U}.data`))return!0;return X.includes(U)&&(X.includes("$status")||X.includes("\u662F\u5426\u8FD0\u884C\u6210\u529F"))}function Gw($,U,W){let G=[];return $.forEach((X,D)=>{let Y=`${U}.${D}`;if(X.type==="ekuaibao-datalink-edit"){G.push({task:X,path:Y});return}if(Xw(X,W))return;if(Array.isArray(X.tasks)&&X.tasks.length>0)G.push(...Gw(X.tasks,Y,W))}),G}function Ml($,U,W){if(!$.type.includes("datalink"))return;let G=$,X=[];if(Array.isArray($.inputs)){for(let Q of $.inputs)if(Q&&typeof Q==="object")X.push({key:Q.key||Q.name||"input",value:Q.value})}else if(G.inputs&&typeof G.inputs==="object")for(let[Q,L]of Object.entries(G.inputs))X.push({key:Q,value:L});let D=Uw($);for(let Q of D)if(Q.key)X.push({key:Q.key,value:Q.value});if(Array.isArray(G.mapping)){for(let Q of G.mapping)if(Q&&typeof Q==="object"){let L=Q;X.push({key:String(L.key||L.target||"field"),value:L.value??L.source})}}let Y=$.fields??G.fields;if(Array.isArray(Y)){for(let Q of Y)if(Q&&typeof Q==="object"){let L=Q;X.push({key:String(L.key||L.label||"field"),value:L.value})}}for(let Q of X)if(typeof Q.value==="string"){let L=Q.value.match(Vl);if(L)_6(W,{severity:"error",code:"MISPLACED_FORMULA_IN_DATALINK_MAPPING",path:U,message:`DataLink \u4EFB\u52A1 '${$.label||$.name}' \u7684\u5B57\u6BB5 '${Q.key}' \u914D\u7F6E\u4E86\u8868\u5355\u516C\u5F0F '${L[0]}...'\u3002\u5408\u601D DataLink \u5C5E\u4E8E\u5E95\u5C42\u6570\u636E\u5199\u5165\u8282\u70B9\uFF0C\u4E0D\u652F\u6301\u524D\u7AEF\u8868\u5355\u516C\u5F0F\u6C42\u503C\uFF0C\u4F20\u5165\u516C\u5F0F\u5B57\u7B26\Line truncated
|
||||
})()`,P=O.evalCode(V,"workflow-script.js");if(P.error){let S=O.dump(P.error);throw P.error.dispose(),S}let M;try{let S=O.getPromiseState(P.value);if(!(S.type==="fulfilled"&&S.notAPromise)){if(S.type==="fulfilled")S.value.dispose();if(S.type==="rejected")S.error.dispose();throw Error("Sandbox only supports synchronous return values")}M=O.dump(P.value);let E=JSON.stringify(M);if(E!==void 0&&Buffer.byteLength(E)>tI)throw Error("Sandbox return value exceeds 1MB")}finally{P.value.dispose()}return{success:!0,durationMs:Number((performance.now()-D).toFixed(2)),returnValue:M,logs:X,inputs:U}}catch(Z){let J=Number((performance.now()-D).toFixed(2)),z=Y?"Script execution timed out":Z?.message||String(Z),O,H,B=Z?.stack||"",j=B.match(/workflow-script\.js:(\d+)(?::(\d+))?/);if(j){let A=Number(j[1]);O=Math.max(1,A-1),H=j[2]?Number(j[2]):void 0}return{success:!1,durationMs:J,returnValue:void 0,logs:X,error:{name:Z?.name||"ExecutionError",message:z,stack:B,line:O,column:H},inputs:U}}finally{K?.dispose(),L?.dispose()}}var rI,Nl=33554432,tI=1048576,Ol=65536,Bl=500,jl;var aI=b(()=>{oI();rI=Ek(wI(),1)});var sI=b(()=>{PI();aI()});function _6($,U){$.push({...U,category:U.category??(U.severity==="error"?"hard_block":"soft_advice")})}function Pl($){let W=[...(typeof $.code==="string"?$.code:"").matchAll(/\{\{\s*([^{}]+?)\s*\}\}|\b(?:ctx|input|output|context)\.([A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*)*)/g)].map((G)=>(G[1]||G[2]||"").trim()).filter(Boolean);return[...new Set(W)]}function eI($,U=""){return $.map((W,G)=>{let X=U?`${U}.${G}`:String(G);return{type:W.type,name:W.name,label:W.label||W.displayName||"",path:X,orderIndex:W.orderIndex,levelIndex:W.levelIndex,children:eI(W.tasks||[],X)}})}function $w($){let U=$;if(typeof U.specificationId==="string"&&U.specificationId.trim())return U.specificationId.trim();if(Array.isArray($.inputs)){let W=$.inputs.find((G)=>G.key==="specificationId");if(W&&typeof W.value==="string"&&W.value.trim())return W.value.trim()}else if(U.inputs&&typeof U.inputs==="object"){let W=U.inputs.specificationId;if(typeof W==="string"&&W.trim())return W.trim()}return}function Uw($){let U=$;if(Array.isArray(U.form))return U.form.filter((W)=>Boolean(W&&typeof W==="object"));if(U.form&&typeof U.form==="object")return Object.entries(U.form).map(([W,G])=>({key:W,value:G}));if(Array.isArray($.inputs)){let W=$.inputs.find((G)=>G.key==="form");if(W&&Array.isArray(W.value))return W.value.filter((G)=>Boolean(G&&typeof G==="object"));if(W&&W.value&&typeof W.value==="object")return Object.entries(W.value).map(([G,X])=>({key:G,value:X}))}else if(U.inputs&&typeof U.inputs==="object"){let W=U.inputs.form;if(Array.isArray(W))return W.filter((G)=>Boolean(G&&typeof G==="object"));if(W&&typeof W==="object")return Object.entries(W).map(([G,X])=>({key:G,value:X}))}return[]}function Ww($){if(!$||typeof $!=="object")return[];let U=[],W=$;if(Array.isArray(W.filters))for(let G of W.filters)U.push(...Ww(G));else if("key"in W||"value"in W)U.push({key:W.key,value:W.value,compare:W.compare,label:W.label});return U}function TB($){let U=new Set,W=(G)=>{for(let X of G){if(X.type==="flow-create-task"){let D=$w(X);if(D)U.add(D)}if(Array.isArray(X.tasks)&&X.tasks.length>0)W(X.tasks)}};return W($.tasks||[]),[...U]}function Xw($,U){if($.type!=="condition")return!1;let W=$,G=W.combineFilters??W.filters??$.inputs??W.conditions??{},X=JSON.stringify(G);if(X.includes(`${U}.$status`)||X.includes(`${U}.status`)||X.includes(`${U}.result`)||X.includes(`${U}.data`))return!0;return X.includes(U)&&(X.includes("$status")||X.includes("\u662F\u5426\u8FD0\u884C\u6210\u529F"))}function Gw($,U,W){let G=[];return $.forEach((X,D)=>{let Y=`${U}.${D}`;if(X.type==="ekuaibao-datalink-edit"){G.push({task:X,path:Y});return}if(Xw(X,W))return;if(Array.isArray(X.tasks)&&X.tasks.length>0)G.push(...Gw(X.tasks,Y,W))}),G}function Ml($,U,W){if(!$.type.includes("datalink"))return;let G=$,X=[];if(Array.isArray($.inputs)){for(let Q of $.inputs)if(Q&&typeof Q==="object")X.push({key:Q.key||Q.name||"input",value:Q.value,type:Q.type})}else if(G.inputs&&typeof G.inputs==="object")for(let[Q,L]of Object.entries(G.inputs))X.push({key:Q,value:L});let D=Uw($);for(let Q of D)if(Q.key)X.push({key:Q.key,value:Q.value,type:Q.type});if(Array.isArray(G.mapping)){for(let Q of G.mapping)if(Q&&typeof Q==="object"){let L=Q;X.push({key:String(L.key||L.target||"field"),value:L.value??L.source,type:L.type})}}let Y=$.fields??G.fields;if(Array.isArray(Y)){for(let Q of Y)if(Q&&typeof Q==="object"){let L=Q;X.push({key:String(L.key||L.label||"field"),value:L.value,type:L.type})}}for(let Q of X)if(typeof Q.value==="string"){let L=Q.value.trim().match(Vl),K=typeof Q.type==="string"?Q.type.toLowerCase():"";if(["text","string","textarea","multiline","richtext"].includes(K))continue;let Z=["date","datetime","timestamp","number","numeric","integer","decimal","float","money"].includes(K);if(L)_6(W,{severity:Z?"error":"warning",code:"MISPLACED_FORMULA_IN_DATALINK_MAPPING",path:U,message:Z?`DataLink \u4EFB\u52A1 '${$.labLine truncated
|
||||
INSERT OR IGNORE INTO preferences (
|
||||
id, name, is_default, rules_reject, rules_review, rules_pass_note, rules_approve, updated_at
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
||||
|
||||
@@ -93,7 +93,7 @@ hose-use workflow eval-script --code="return a + b;" --input='{"a":1,"b":2}'
|
||||
| 规则代码 (`code`) | 级别 | 触发根因与运行后果 | 修复措施与建议 |
|
||||
|---|---|---|---|
|
||||
| `PERMISSION_MISSING_NODE` | error | 工作流使用了当前租户尚未开通的灰度节点(如 `code-js2`、AI节点等),运行时合思引擎直接阻断抛错 | 使用 `hose-use workflow nodes grant <type>` 开通权限,或替换为已开通节点 |
|
||||
| `MISPLACED_FORMULA_IN_DATALINK_MAPPING` | error | 在 DataLink 业务对象写入/修改节点的字段映射中填入了表单公式(如 `AddMonths(...)`),底层写入引擎无法求值导致 `ParseException` | 前置增加【代码节点】(JS/MVEL)计算变量,在 DataLink 节点中引用计算结果 |
|
||||
| `MISPLACED_FORMULA_IN_DATALINK_MAPPING` | error | 在已知数值或日期字段中填写完整表单公式(如 `AddMonths(...)`);类型未知仅给软建议,普通文本不阻断 | 前置增加【代码节点】(JS/MVEL)计算变量,在 DataLink 节点中引用计算结果 |
|
||||
| `EMPTY_CODE` | error | 代码节点(`code` / `code-js2`)缺少可执行脚本,流程执行到该节点时空指针或停止流转 | 补充清洗/计算脚本或移除无用代码节点 |
|
||||
| `DEADLOCK_TRIGGER_STATE_FILTER` | error | 触发器节点配置了 `state` 单据审批状态过滤(如 `REJECTED` / `被驳回`),合思出站事件初始阶段状态为空或动作事件,导致事件 100% 被静默丢弃,流程永久不触发 | 移除 `state` 过滤,改用通知类型(`action`)过滤或后置条件节点 |
|
||||
| `DEADLOCK_CONDITION_STATE_FILTER` | error | 条件节点使用单据审批状态 `state` 匹配中文 `被驳回/审批驳回`,动作事件载荷不满足中文匹配,判定恒为 false | 改用通知类型 `action` 匹配宏枚举(如 `flow.rejected`) |
|
||||
@@ -147,3 +147,5 @@ hose-use workflow eval-script --code="return a + b;" --input='{"a":1,"b":2}'
|
||||
灰度开通网关明确返回失败时,CLI 保留失败详情并返回非零退出码;文本输出不再宣称权限生效,JSON 中的 `success` 与退出码保持一致。
|
||||
|
||||
监听结果区分完成、超时、快照和取消:只有到达终态才发送 `job_completed`;超时发送 `timeout` 并设置 `timedOut`,取消设置 `cancelled`。CLI 超时或取消返回非零退出码;`--once` 的运行中快照仍可成功返回,且不冒充完成。持续监听的总超时预算覆盖正在跟踪的 Job。
|
||||
|
||||
公式诊断仅对完整公式表达式且具有明确数值/日期字段类型的映射执行硬阻断;类型未知降为软建议,明确文本类型及备注中的公式样式词语不构成阻断。
|
||||
@@ -232,7 +232,7 @@ function findUnguardedDatalinkEdits(
|
||||
}
|
||||
|
||||
const FORMULA_REGEX =
|
||||
/\b(AddMonths|dateDIF|DATEADD|DATEDIF|IF|SUM|ROUND|INT|TEXT|YEAR|MONTH|DAY)\s*\(/i;
|
||||
/^(?:=\s*)?(AddMonths|dateDIF|DATEADD|DATEDIF|IF|SUM|ROUND|INT|TEXT|YEAR|MONTH|DAY)\s*\([\s\S]*\)$/i;
|
||||
|
||||
function checkMisplacedFormulasInDatalink(
|
||||
task: WorkflowTask,
|
||||
@@ -241,13 +241,13 @@ function checkMisplacedFormulasInDatalink(
|
||||
): void {
|
||||
if (!task.type.includes("datalink")) return;
|
||||
const raw = task as Record<string, unknown>;
|
||||
const inspectTargets: Array<{ key: string; value: unknown }> = [];
|
||||
const inspectTargets: Array<{ key: string; value: unknown; type?: unknown }> = [];
|
||||
|
||||
// 1. inspect task.inputs
|
||||
if (Array.isArray(task.inputs)) {
|
||||
for (const inp of task.inputs) {
|
||||
if (inp && typeof inp === "object") {
|
||||
inspectTargets.push({ key: inp.key || (inp as any).name || "input", value: inp.value });
|
||||
inspectTargets.push({ key: inp.key || (inp as any).name || "input", value: inp.value, type: (inp as any).type });
|
||||
}
|
||||
}
|
||||
} else if (raw.inputs && typeof raw.inputs === "object") {
|
||||
@@ -260,7 +260,7 @@ function checkMisplacedFormulasInDatalink(
|
||||
const formEntries = getTaskFormEntries(task);
|
||||
for (const entry of formEntries) {
|
||||
if (entry.key) {
|
||||
inspectTargets.push({ key: entry.key, value: entry.value });
|
||||
inspectTargets.push({ key: entry.key, value: entry.value, type: entry.type });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -272,6 +272,7 @@ function checkMisplacedFormulasInDatalink(
|
||||
inspectTargets.push({
|
||||
key: String(item.key || item.target || "field"),
|
||||
value: item.value ?? item.source,
|
||||
type: item.type,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -286,6 +287,7 @@ function checkMisplacedFormulasInDatalink(
|
||||
inspectTargets.push({
|
||||
key: String(item.key || item.label || "field"),
|
||||
value: item.value,
|
||||
type: item.type,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -293,13 +295,18 @@ function checkMisplacedFormulasInDatalink(
|
||||
|
||||
for (const target of inspectTargets) {
|
||||
if (typeof target.value === "string") {
|
||||
const match = target.value.match(FORMULA_REGEX);
|
||||
const match = target.value.trim().match(FORMULA_REGEX);
|
||||
const fieldType = typeof target.type === "string" ? target.type.toLowerCase() : "";
|
||||
if (["text", "string", "textarea", "multiline", "richtext"].includes(fieldType)) continue;
|
||||
const strongType = ["date", "datetime", "timestamp", "number", "numeric", "integer", "decimal", "float", "money"].includes(fieldType);
|
||||
if (match) {
|
||||
addDiagnostic(diagnostics, {
|
||||
severity: "error",
|
||||
severity: strongType ? "error" : "warning",
|
||||
code: "MISPLACED_FORMULA_IN_DATALINK_MAPPING",
|
||||
path,
|
||||
message: `DataLink 任务 '${task.label || task.name}' 的字段 '${target.key}' 配置了表单公式 '${match[0]}...'。合思 DataLink 属于底层数据写入节点,不支持前端表单公式求值,传入公式字符串会导致后端强类型解析崩溃 (如 ParseException)。请前置添加【代码节点】计算该值并在此处引用。`,
|
||||
message: strongType
|
||||
? `DataLink 任务 '${task.label || task.name}' 的 ${fieldType} 字段 '${target.key}' 配置了表单公式 '${match[0]}'。底层数据写入不求值表单公式,强类型字段不能接受该表达式;请前置添加【代码节点】计算该值并在此处引用。`
|
||||
: `DataLink 任务 '${task.label || task.name}' 的字段 '${target.key}' 包含疑似公式 '${match[0]}',但缺少可验证的字段类型,仅作为建议。若需要计算,请前置添加【代码节点】;若为文本,请保留字面量。`,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
import { expect, test } from "bun:test";
|
||||
import { analyzeWorkflow } from "./analyzer.js";
|
||||
function analyze(value: string, type?: string) {
|
||||
return analyzeWorkflow({ id: "wf", label: "wf", state: 1, version: "1", tasks: [{ name: "write", type: "ekuaibao-datalink-create", fields: [{ key: "field", value, type }] }] } as any);
|
||||
}
|
||||
test("ordinary text and explicit text formulas never cause hard blocks", () => {
|
||||
for (const value of ["Annual ROUND(1) review", "IF(required) then contact us", '"ROUND(1)"']) expect(analyze(value).diagnostics).toHaveLength(0);
|
||||
expect(analyze("ROUND(1)", "text").diagnostics).toHaveLength(0);
|
||||
});
|
||||
test("only a complete formula in a known strong type causes a hard block", () => {
|
||||
const unknown = analyze("AddMonths(date, 1)");
|
||||
expect(unknown.summary.passed).toBe(true);
|
||||
expect(unknown.diagnostics[0].category).toBe("soft_advice");
|
||||
const date = analyze("AddMonths(date, 1)", "date");
|
||||
expect(date.summary.passed).toBe(false);
|
||||
expect(date.diagnostics[0].category).toBe("hard_block");
|
||||
expect(analyze("ROUND(1)", "NUMBER").summary.hardBlocks).toBe(1);
|
||||
});
|
||||
@@ -206,6 +206,7 @@ describe("Workflow static analysis", () => {
|
||||
mapping: [
|
||||
{
|
||||
key: "amortizationMonth",
|
||||
type: "date",
|
||||
value: "AddMonths(date, 1)",
|
||||
},
|
||||
],
|
||||
|
||||
Reference in new issue
Block a user