@replay-kit/core 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +2 -0
- package/dist/app_event.cjs +4 -0
- package/dist/app_event.d.cts +7 -0
- package/dist/app_event.d.ts +7 -0
- package/dist/app_event.js +4 -0
- package/dist/cli.cjs +46 -0
- package/dist/cli.d.cts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +46 -0
- package/dist/enum/index.cjs +1 -0
- package/dist/enum/index.d.cts +1 -0
- package/dist/enum/index.d.ts +1 -0
- package/dist/enum/index.js +1 -0
- package/dist/enum/log_level.enum.cjs +1 -0
- package/dist/enum/log_level.enum.d.cts +7 -0
- package/dist/enum/log_level.enum.d.ts +7 -0
- package/dist/enum/log_level.enum.js +1 -0
- package/dist/error_handle.helper-CQsPSbuz.d.cts +75 -0
- package/dist/error_handle.helper-CQsPSbuz.d.ts +75 -0
- package/dist/helper/crypto.helper.cjs +1 -0
- package/dist/helper/crypto.helper.d.cts +3 -0
- package/dist/helper/crypto.helper.d.ts +3 -0
- package/dist/helper/crypto.helper.js +1 -0
- package/dist/helper/error_handle.helper.cjs +3 -0
- package/dist/helper/error_handle.helper.d.cts +2 -0
- package/dist/helper/error_handle.helper.d.ts +2 -0
- package/dist/helper/error_handle.helper.js +3 -0
- package/dist/helper/index.cjs +4 -0
- package/dist/helper/index.d.cts +4 -0
- package/dist/helper/index.d.ts +4 -0
- package/dist/helper/index.js +4 -0
- package/dist/helper/stack.helper.cjs +2 -0
- package/dist/helper/stack.helper.d.cts +9 -0
- package/dist/helper/stack.helper.d.ts +9 -0
- package/dist/helper/stack.helper.js +2 -0
- package/dist/index-8u1_ya-u.d.ts +36 -0
- package/dist/index-MBKv_hsI.d.cts +36 -0
- package/dist/index.cjs +4 -0
- package/dist/index.d.cts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +4 -0
- package/dist/logger/actions/index.cjs +3 -0
- package/dist/logger/actions/index.d.cts +4 -0
- package/dist/logger/actions/index.d.ts +4 -0
- package/dist/logger/actions/index.js +3 -0
- package/dist/logger/actions/record.action.cjs +2 -0
- package/dist/logger/actions/record.action.d.cts +4 -0
- package/dist/logger/actions/record.action.d.ts +4 -0
- package/dist/logger/actions/record.action.js +2 -0
- package/dist/logger/actions/view_many.action.cjs +2 -0
- package/dist/logger/actions/view_many.action.d.cts +4 -0
- package/dist/logger/actions/view_many.action.d.ts +4 -0
- package/dist/logger/actions/view_many.action.js +2 -0
- package/dist/logger/handler.cjs +3 -0
- package/dist/logger/handler.d.cts +4 -0
- package/dist/logger/handler.d.ts +4 -0
- package/dist/logger/handler.js +3 -0
- package/dist/logger/index.cjs +3 -0
- package/dist/logger/index.d.cts +4 -0
- package/dist/logger/index.d.ts +4 -0
- package/dist/logger/index.js +3 -0
- package/dist/replay/base.cjs +1 -0
- package/dist/replay/base.d.cts +18 -0
- package/dist/replay/base.d.ts +18 -0
- package/dist/replay/base.js +1 -0
- package/dist/replay/handler.cjs +25 -0
- package/dist/replay/handler.d.cts +24 -0
- package/dist/replay/handler.d.ts +24 -0
- package/dist/replay/handler.js +25 -0
- package/dist/replay/helper.cjs +1 -0
- package/dist/replay/helper.d.cts +34 -0
- package/dist/replay/helper.d.ts +34 -0
- package/dist/replay/helper.js +1 -0
- package/dist/replay/index.cjs +25 -0
- package/dist/replay/index.d.cts +6 -0
- package/dist/replay/index.d.ts +6 -0
- package/dist/replay/index.js +25 -0
- package/dist/replay/mode/advance/index.cjs +22 -0
- package/dist/replay/mode/advance/index.d.cts +11 -0
- package/dist/replay/mode/advance/index.d.ts +11 -0
- package/dist/replay/mode/advance/index.js +22 -0
- package/dist/replay/mode/advance/reasons/assigner_cases/base.cjs +14 -0
- package/dist/replay/mode/advance/reasons/assigner_cases/base.d.cts +137 -0
- package/dist/replay/mode/advance/reasons/assigner_cases/base.d.ts +137 -0
- package/dist/replay/mode/advance/reasons/assigner_cases/base.js +14 -0
- package/dist/replay/mode/advance/reasons/assigner_cases/business_logic_rejection_case/index.cjs +14 -0
- package/dist/replay/mode/advance/reasons/assigner_cases/business_logic_rejection_case/index.d.cts +19 -0
- package/dist/replay/mode/advance/reasons/assigner_cases/business_logic_rejection_case/index.d.ts +19 -0
- package/dist/replay/mode/advance/reasons/assigner_cases/business_logic_rejection_case/index.js +14 -0
- package/dist/replay/mode/advance/reasons/assigner_cases/index.cjs +14 -0
- package/dist/replay/mode/advance/reasons/assigner_cases/index.d.cts +15 -0
- package/dist/replay/mode/advance/reasons/assigner_cases/index.d.ts +15 -0
- package/dist/replay/mode/advance/reasons/assigner_cases/index.js +14 -0
- package/dist/replay/mode/advance/reasons/assigner_cases/post_trace_response_mutation_case/index.cjs +14 -0
- package/dist/replay/mode/advance/reasons/assigner_cases/post_trace_response_mutation_case/index.d.cts +18 -0
- package/dist/replay/mode/advance/reasons/assigner_cases/post_trace_response_mutation_case/index.d.ts +18 -0
- package/dist/replay/mode/advance/reasons/assigner_cases/post_trace_response_mutation_case/index.js +14 -0
- package/dist/replay/mode/advance/reasons/assigner_cases/trace_divergence_case/index.cjs +14 -0
- package/dist/replay/mode/advance/reasons/assigner_cases/trace_divergence_case/index.d.cts +18 -0
- package/dist/replay/mode/advance/reasons/assigner_cases/trace_divergence_case/index.d.ts +18 -0
- package/dist/replay/mode/advance/reasons/assigner_cases/trace_divergence_case/index.js +14 -0
- package/dist/replay/mode/advance/reasons/index.cjs +21 -0
- package/dist/replay/mode/advance/reasons/index.d.cts +17 -0
- package/dist/replay/mode/advance/reasons/index.d.ts +17 -0
- package/dist/replay/mode/advance/reasons/index.js +21 -0
- package/dist/replay/mode/advance/reasons/reason_assigner.cjs +14 -0
- package/dist/replay/mode/advance/reasons/reason_assigner.d.cts +25 -0
- package/dist/replay/mode/advance/reasons/reason_assigner.d.ts +25 -0
- package/dist/replay/mode/advance/reasons/reason_assigner.js +14 -0
- package/dist/replay/mode/advance/reasons/reason_printer.cjs +8 -0
- package/dist/replay/mode/advance/reasons/reason_printer.d.cts +25 -0
- package/dist/replay/mode/advance/reasons/reason_printer.d.ts +25 -0
- package/dist/replay/mode/advance/reasons/reason_printer.js +8 -0
- package/dist/replay/mode/advance/reasons/reason_signal.cjs +1 -0
- package/dist/replay/mode/advance/reasons/reason_signal.d.cts +87 -0
- package/dist/replay/mode/advance/reasons/reason_signal.d.ts +87 -0
- package/dist/replay/mode/advance/reasons/reason_signal.js +1 -0
- package/dist/replay/mode/advance/replay.cjs +22 -0
- package/dist/replay/mode/advance/replay.d.cts +57 -0
- package/dist/replay/mode/advance/replay.d.ts +57 -0
- package/dist/replay/mode/advance/replay.js +22 -0
- package/dist/replay/mode/index.cjs +25 -0
- package/dist/replay/mode/index.d.cts +12 -0
- package/dist/replay/mode/index.d.ts +12 -0
- package/dist/replay/mode/index.js +25 -0
- package/dist/replay/mode/smart.replay.cjs +4 -0
- package/dist/replay/mode/smart.replay.d.cts +18 -0
- package/dist/replay/mode/smart.replay.d.ts +18 -0
- package/dist/replay/mode/smart.replay.js +4 -0
- package/dist/setup.cjs +7 -0
- package/dist/setup.d.cts +27 -0
- package/dist/setup.d.ts +27 -0
- package/dist/setup.js +7 -0
- package/dist/trace/builder.cjs +1 -0
- package/dist/trace/builder.d.cts +6 -0
- package/dist/trace/builder.d.ts +6 -0
- package/dist/trace/builder.js +1 -0
- package/dist/trace/context.cjs +2 -0
- package/dist/trace/context.d.cts +2 -0
- package/dist/trace/context.d.ts +2 -0
- package/dist/trace/context.js +2 -0
- package/dist/trace/filter.cjs +1 -0
- package/dist/trace/filter.d.cts +21 -0
- package/dist/trace/filter.d.ts +21 -0
- package/dist/trace/filter.js +1 -0
- package/dist/trace/index.cjs +2 -0
- package/dist/trace/index.d.cts +7 -0
- package/dist/trace/index.d.ts +7 -0
- package/dist/trace/index.js +2 -0
- package/package.json +81 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
var R=Object.defineProperty;var r=(t,e)=>R(t,"name",{value:e,configurable:!0});import D from"http";var S={trace_step_match:r((t=.1)=>({weight:t,serverity:i(t),message:`trace_match (+${t}) \u2192 trace fully matches replay`}),"trace_step_match"),trace_step_not_match:r((t=.25)=>({weight:t,serverity:i(t),message:`trace_step_not_match (+${t}) \u2192 trace partially matches replay`}),"trace_step_not_match"),trace_return_data_match:r((t=.1)=>({weight:t,serverity:i(t),message:`trace_return_data_match (+${t}) \u2192 trace return data is consistent`}),"trace_return_data_match"),trace_return_data_not_match:r((t=.25)=>({weight:t,serverity:i(t),message:`trace_return_data_not_match (+${t}) \u2192 trace return data is inconsistent`}),"trace_return_data_not_match"),response_match:r((t=.1)=>({weight:t,serverity:i(t),message:`response_match (+${t}) \u2192 response is consistent`}),"response_match"),response_not_match:r((t=.25)=>({weight:t,serverity:i(t),message:`response_not_match (+${t}) \u2192 response is inconsistent`}),"response_not_match"),response_status_match:r((t=.1)=>({weight:t,serverity:i(t),message:`response_status_match (+${t}) \u2192 response status is consistent`}),"response_status_match"),response_status_not_match:r((t=.25)=>({weight:t,serverity:i(t),message:`response_status_not_match (+${t}) \u2192 response status is inconsistent`}),"response_status_not_match"),logic_error_indicator:r((t=.6)=>({weight:t,serverity:i(t),message:`logic_error_indicator (+${t}) \u2192 original response status >= 400 triggered logic flag`}),"logic_error_indicator")},y={trace_match:{value:!0,message:"flow is clean"},trace_not_match:{value:!1,message:"flow is not clean"},trace_step_match:{value:!0,message:"no mismatch"},trace_step_not_match:{value:!1,message:"mismatch"},trace_return_data_match:{value:!0,message:"no mismatch"},trace_return_data_not_match:{value:!1,message:"mismatch"},response_match:{value:!0,message:"no mismatch"},response_not_match:{value:!1,message:"mismatch"}};function i(t){return t>.75?"high":t>.55?"medium":"low"}r(i,"getSignalLevel");import o from"chalk";var c=class{static{r(this,"BaseAssignerCase")}get evidenceSource(){return y}get signalSource(){return S}getTraceDivergenceSection(e){let s=e.traceDiff.issues;if(s.length===0)return"No divergence";let a=`
|
|
2
|
+
`;for(let n of s)n.type==="missing_step"&&(a+=o.yellow(`
|
|
3
|
+
* ${n.name}(missing_step):
|
|
4
|
+
`),a+=o.green(` \u2192 original: exists
|
|
5
|
+
`),a+=o.red(" \u2192 replay: missing"),a+=`
|
|
6
|
+
`),n.type==="extra_step"&&(a+=o.yellow(`
|
|
7
|
+
* ${n.name}(extra_step):
|
|
8
|
+
`),a+=o.green(` \u2192 original: none
|
|
9
|
+
`),a+=o.red(" \u2192 replay: exists"),a+=`
|
|
10
|
+
`);return a.trim()}getMessageEdvidence(e){return`${this.evidenceSource[e].value} (${this.evidenceSource[e].message})`}getStatusEdvidence(e){let s=D.STATUS_CODES[e]||"Unknown";return`${e} (${s})`}isTraceMatch(e){return!e.traceDiff.isDifferent}isTraceStepMatch(e){return e.traceDiff.issues.length>0?!e.traceDiff.issues.some(s=>s.type==="missing_step"||s.type==="extra_step"):!0}isTraceReturnDataMatch(e){return e.traceDiff.issues.length>0?!e.traceDiff.issues.some(s=>s.type==="trace_return_data_mismatch"):!0}isResponseMatch(e){return!e.responseDiff.isDifferent}isResponseStatusMatch(e){let{originalStatus:s,replayStatus:a}=this.resolveStatus(e);return s===a}resolveStatus(e){return{originalStatus:Number(e.log.response.status),replayStatus:e.replayResultStatus}}getResponseDiffSection(e){let s=e.responseDiff.issues;if(s.length===0)return"No diff";let a=s.length>1?1:0,n=e.responseDiff.issues[a].not_matched;if(!n)return"No diff";let u=n.original||{},_=n.replay||{},b=new Set([...Object.keys(u),...Object.keys(_)]),l=`
|
|
11
|
+
`;for(let p of b){let f=u[p],d=_[p];f!==d&&(l+=o.yellow(` * ${p}:
|
|
12
|
+
`),l+=o.green(` \u2192 original: ${JSON.stringify(f)}
|
|
13
|
+
`),l+=o.red(` \u2192 replay: ${JSON.stringify(d)}
|
|
14
|
+
`))}return l}};var g=class extends c{static{r(this,"BusinessLogicRejectionCase")}condition(e,s){return this.isTraceMatch(e)&&this.isResponseMatch(e)&&s.originalStatus>=400&&s.replayStatus>=400}assign(e){try{let s=this.resolveStatus(e);if(this.condition(e,s)){let a=e.log.trace?.find(u=>u.parentId===null);return{type:"Business Logic Rejection Case (logic_suspicious)",message:"Response indicates error, but execution original and replay result match expected behavior",possibleCauses:["Business rule might not align with actual execution flow","Or validation logic is too strict / misaligned"],evidence:{traceMatch:this.getMessageEdvidence("trace_match"),responseMatch:this.getMessageEdvidence("response_match"),originalStatus:this.getStatusEdvidence(s.originalStatus),finalResponse:typeof a?.returnData=="object"?JSON.stringify(a.returnData,null,2):a?.returnData},confidence:{signals:{trace_match:this.signalSource.trace_step_match(.3),response_match:this.signalSource.response_match(.3),logic_error_indicator:this.signalSource.logic_error_indicator(.2)},result:0},finalMessage:["This is NOT a runtime bug","This is likely a business logic issue"],references:e.log.stack}}}catch(s){throw s}}};var m=class extends c{static{r(this,"PostTraceResponseMutationCase")}assign(e){try{let s=this.resolveStatus(e);if(this.isTraceStepMatch(e)&&!this.isResponseMatch(e)&&this.isTraceReturnDataMatch(e))return{type:"Response Mismatch Case (post_processing_suspicious)",message:"Execution flow is identical, but response output differs",possibleCauses:["Post-processing logic may be inconsistent","Response mapping or transformation may be incorrect","Data changes may affect the final result.","Non-deterministic behavior (e.g. random, time-based, shared state)"],evidence:{traceMatch:this.getMessageEdvidence("trace_match"),responseMatch:this.getMessageEdvidence("response_not_match"),originalStatus:this.getStatusEdvidence(s.originalStatus),responseDiff:this.getResponseDiffSection(e)},confidence:{signals:{trace_step_match:this.signalSource.trace_step_match(.3),response_mismatch:this.signalSource.response_not_match(.2),trace_return_data_match:this.signalSource.trace_return_data_match(.3)},result:0},finalMessage:["Execution logic is stable, but output is inconsistent","This may indicate issues in response transformation or side effects","This may occur after the business logic is execute complete."],references:e.log.stack}}catch(s){throw s}}};var h=class extends c{static{r(this,"TraceDivergenceCase")}assign(e){try{let s=this.resolveStatus(e);if(!this.isTraceStepMatch(e)&&!this.isResponseMatch(e)&&!this.isTraceReturnDataMatch(e)&&!this.isResponseStatusMatch(e))return{type:"Trace Divergence Case (execution_path_mismatch)",message:"Execution path diverged between original and replay",possibleCauses:["Conditional branch logic may behave differently","Environment or shared state may affect execution flow","Request context may not be deterministic","Replay execution may enter different logic branches","Hidden dependencies or side effects may exist"],evidence:{traceMatch:this.getMessageEdvidence("trace_not_match"),originalStatus:this.getStatusEdvidence(s.originalStatus),traceDivergence:this.getTraceDivergenceSection(e),responseDiff:this.getResponseDiffSection(e)},confidence:{signals:{trace_step_not_match:this.signalSource.trace_step_not_match(.45),trace_return_data_not_match:this.signalSource.trace_return_data_not_match(.25),response_not_match:this.signalSource.response_not_match(.15),response_status_not_match:this.signalSource.response_status_not_match(.1)},result:0},finalMessage:["Replay execution diverged from the original execution flow","This may indicate unstable conditions or branch inconsistency","Root cause likely exists before response generation"],references:e.log.stack}}catch(s){throw s}}};var v=class{static{r(this,"ReasonAssigner")}get case(){return{business_logic_rejection:new g,post_trace_response_mutation:new m,trace_divergence:new h}}};export{v as ReasonAssigner};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";var u=Object.create;var l=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var p=Object.getOwnPropertyNames;var _=Object.getPrototypeOf,y=Object.prototype.hasOwnProperty;var r=(e,t)=>l(e,"name",{value:t,configurable:!0});var f=(e,t)=>{for(var s in t)l(e,s,{get:t[s],enumerable:!0})},m=(e,t,s,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of p(t))!y.call(e,o)&&o!==s&&l(e,o,{get:()=>t[o],enumerable:!(a=h(t,o))||a.enumerable});return e};var d=(e,t,s)=>(s=e!=null?u(_(e)):{},m(t||!e||!e.__esModule?l(s,"default",{value:e,enumerable:!0}):s,e)),v=e=>m(l({},"__esModule",{value:!0}),e);var b={};f(b,{ReasonPrinter:()=>g});module.exports=v(b);var n=d(require("chalk"),1);var S={trace_step_match:r((e=.1)=>({weight:e,serverity:i(e),message:`trace_match (+${e}) \u2192 trace fully matches replay`}),"trace_step_match"),trace_step_not_match:r((e=.25)=>({weight:e,serverity:i(e),message:`trace_step_not_match (+${e}) \u2192 trace partially matches replay`}),"trace_step_not_match"),trace_return_data_match:r((e=.1)=>({weight:e,serverity:i(e),message:`trace_return_data_match (+${e}) \u2192 trace return data is consistent`}),"trace_return_data_match"),trace_return_data_not_match:r((e=.25)=>({weight:e,serverity:i(e),message:`trace_return_data_not_match (+${e}) \u2192 trace return data is inconsistent`}),"trace_return_data_not_match"),response_match:r((e=.1)=>({weight:e,serverity:i(e),message:`response_match (+${e}) \u2192 response is consistent`}),"response_match"),response_not_match:r((e=.25)=>({weight:e,serverity:i(e),message:`response_not_match (+${e}) \u2192 response is inconsistent`}),"response_not_match"),response_status_match:r((e=.1)=>({weight:e,serverity:i(e),message:`response_status_match (+${e}) \u2192 response status is consistent`}),"response_status_match"),response_status_not_match:r((e=.25)=>({weight:e,serverity:i(e),message:`response_status_not_match (+${e}) \u2192 response status is inconsistent`}),"response_status_not_match"),logic_error_indicator:r((e=.6)=>({weight:e,serverity:i(e),message:`logic_error_indicator (+${e}) \u2192 original response status >= 400 triggered logic flag`}),"logic_error_indicator")};function i(e){return e>.75?"high":e>.55?"medium":"low"}r(i,"getSignalLevel");var c=class{static{r(this,"ReasonSignalCls")}findSignalByType(t){try{return S[t]}catch(s){throw s}}sumSignalWeights(t){try{return Object.values(t).reduce((s,a)=>s+a.weight,0)}catch(s){throw s}}};var g=class{static{r(this,"ReasonPrinter")}get reasonSignal(){return new c}title(t){console.log(n.default.yellowBright("** Reason Title:")),console.log(`[!] ${t}`)}description(t){console.log(n.default.yellowBright("** Description:")),console.log(t)}possibleCauses(t){console.log(n.default.yellowBright("** What I think happened:")),t.forEach(s=>{console.log(` \u2192 ${s}`)})}evidence(t){let s=Object.keys(t);console.log(n.default.yellowBright("** Evidence I saw:")),s.forEach(a=>{console.log(` \u2192 ${a}: ${t[a]}`)})}confidence(t){console.log(n.default.yellowBright("** Confidence Reason (why I think this): ")),t.signals&&Object.keys(t.signals).forEach(o=>{console.log(` \u2192 ${t.signals[o].message}`)}),t.result=this.reasonSignal.sumSignalWeights(t.signals);let s=Math.round(t.result*100);console.log(`
|
|
2
|
+
`),console.log(n.default.yellowBright("** Confidence Result: ")),console.log(n.default.green.italic.bold(` * score: ${t.result.toFixed(2)} / 1 `)),console.log(n.default.green.italic.bold(` * percent: ${s} / 100 (%) `))}finalMessage(t){t.length!=0&&(console.log(n.default.yellowBright("** Final Call:")),t.forEach(s=>{console.log(` \u2192 ${s}`)}))}referencePosition(t){if(t&&(console.log(n.default.yellowBright("* Reference Position: ")),console.log(" \u2192 Suspected position:",n.default.red.underline(t.primary?.full_path)),t.context&&t.context.length>0)){let s=t.context.length-1;t.context.forEach((a,o)=>{console.log(` \u2192 (Context ${s-o}): ${a.full_path}`)})}}printReason(t){try{if(!t)return;console.log(n.default.red.italic.bold(`
|
|
3
|
+
Aeeaeae yohh BUT...`)),this.title(t.type),console.log(`
|
|
4
|
+
`),this.description(t.message),console.log(`
|
|
5
|
+
`),this.possibleCauses(t.possibleCauses),console.log(`
|
|
6
|
+
`),this.evidence(t.evidence),console.log(`
|
|
7
|
+
`),this.confidence(t.confidence),console.log(`
|
|
8
|
+
`),this.finalMessage(t.finalMessage||[]),this.referencePosition(t.references)}catch(s){throw s}}};0&&(module.exports={ReasonPrinter});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { RootCauseReason } from '../replay.cjs';
|
|
2
|
+
import '../../../handler.cjs';
|
|
3
|
+
import '../../../../error_handle.helper-CQsPSbuz.cjs';
|
|
4
|
+
import 'async_hooks';
|
|
5
|
+
import '../../../../setup.cjs';
|
|
6
|
+
import '../../../../index-MBKv_hsI.cjs';
|
|
7
|
+
import '../../../../enum/log_level.enum.cjs';
|
|
8
|
+
import '../../../base.cjs';
|
|
9
|
+
import '../../../../trace/filter.cjs';
|
|
10
|
+
import '../../../helper.cjs';
|
|
11
|
+
import './reason_signal.cjs';
|
|
12
|
+
|
|
13
|
+
declare class ReasonPrinter {
|
|
14
|
+
private get reasonSignal();
|
|
15
|
+
private title;
|
|
16
|
+
private description;
|
|
17
|
+
private possibleCauses;
|
|
18
|
+
private evidence;
|
|
19
|
+
private confidence;
|
|
20
|
+
private finalMessage;
|
|
21
|
+
private referencePosition;
|
|
22
|
+
printReason(reason: RootCauseReason): void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { ReasonPrinter };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { RootCauseReason } from '../replay.js';
|
|
2
|
+
import '../../../handler.js';
|
|
3
|
+
import '../../../../error_handle.helper-CQsPSbuz.js';
|
|
4
|
+
import 'async_hooks';
|
|
5
|
+
import '../../../../setup.js';
|
|
6
|
+
import '../../../../index-8u1_ya-u.js';
|
|
7
|
+
import '../../../../enum/log_level.enum.js';
|
|
8
|
+
import '../../../base.js';
|
|
9
|
+
import '../../../../trace/filter.js';
|
|
10
|
+
import '../../../helper.js';
|
|
11
|
+
import './reason_signal.js';
|
|
12
|
+
|
|
13
|
+
declare class ReasonPrinter {
|
|
14
|
+
private get reasonSignal();
|
|
15
|
+
private title;
|
|
16
|
+
private description;
|
|
17
|
+
private possibleCauses;
|
|
18
|
+
private evidence;
|
|
19
|
+
private confidence;
|
|
20
|
+
private finalMessage;
|
|
21
|
+
private referencePosition;
|
|
22
|
+
printReason(reason: RootCauseReason): void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export { ReasonPrinter };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
var g=Object.defineProperty;var r=(e,t)=>g(e,"name",{value:t,configurable:!0});import n from"chalk";var m={trace_step_match:r((e=.1)=>({weight:e,serverity:a(e),message:`trace_match (+${e}) \u2192 trace fully matches replay`}),"trace_step_match"),trace_step_not_match:r((e=.25)=>({weight:e,serverity:a(e),message:`trace_step_not_match (+${e}) \u2192 trace partially matches replay`}),"trace_step_not_match"),trace_return_data_match:r((e=.1)=>({weight:e,serverity:a(e),message:`trace_return_data_match (+${e}) \u2192 trace return data is consistent`}),"trace_return_data_match"),trace_return_data_not_match:r((e=.25)=>({weight:e,serverity:a(e),message:`trace_return_data_not_match (+${e}) \u2192 trace return data is inconsistent`}),"trace_return_data_not_match"),response_match:r((e=.1)=>({weight:e,serverity:a(e),message:`response_match (+${e}) \u2192 response is consistent`}),"response_match"),response_not_match:r((e=.25)=>({weight:e,serverity:a(e),message:`response_not_match (+${e}) \u2192 response is inconsistent`}),"response_not_match"),response_status_match:r((e=.1)=>({weight:e,serverity:a(e),message:`response_status_match (+${e}) \u2192 response status is consistent`}),"response_status_match"),response_status_not_match:r((e=.25)=>({weight:e,serverity:a(e),message:`response_status_not_match (+${e}) \u2192 response status is inconsistent`}),"response_status_not_match"),logic_error_indicator:r((e=.6)=>({weight:e,serverity:a(e),message:`logic_error_indicator (+${e}) \u2192 original response status >= 400 triggered logic flag`}),"logic_error_indicator")};function a(e){return e>.75?"high":e>.55?"medium":"low"}r(a,"getSignalLevel");var i=class{static{r(this,"ReasonSignalCls")}findSignalByType(t){try{return m[t]}catch(s){throw s}}sumSignalWeights(t){try{return Object.values(t).reduce((s,o)=>s+o.weight,0)}catch(s){throw s}}};var c=class{static{r(this,"ReasonPrinter")}get reasonSignal(){return new i}title(t){console.log(n.yellowBright("** Reason Title:")),console.log(`[!] ${t}`)}description(t){console.log(n.yellowBright("** Description:")),console.log(t)}possibleCauses(t){console.log(n.yellowBright("** What I think happened:")),t.forEach(s=>{console.log(` \u2192 ${s}`)})}evidence(t){let s=Object.keys(t);console.log(n.yellowBright("** Evidence I saw:")),s.forEach(o=>{console.log(` \u2192 ${o}: ${t[o]}`)})}confidence(t){console.log(n.yellowBright("** Confidence Reason (why I think this): ")),t.signals&&Object.keys(t.signals).forEach(l=>{console.log(` \u2192 ${t.signals[l].message}`)}),t.result=this.reasonSignal.sumSignalWeights(t.signals);let s=Math.round(t.result*100);console.log(`
|
|
2
|
+
`),console.log(n.yellowBright("** Confidence Result: ")),console.log(n.green.italic.bold(` * score: ${t.result.toFixed(2)} / 1 `)),console.log(n.green.italic.bold(` * percent: ${s} / 100 (%) `))}finalMessage(t){t.length!=0&&(console.log(n.yellowBright("** Final Call:")),t.forEach(s=>{console.log(` \u2192 ${s}`)}))}referencePosition(t){if(t&&(console.log(n.yellowBright("* Reference Position: ")),console.log(" \u2192 Suspected position:",n.red.underline(t.primary?.full_path)),t.context&&t.context.length>0)){let s=t.context.length-1;t.context.forEach((o,l)=>{console.log(` \u2192 (Context ${s-l}): ${o.full_path}`)})}}printReason(t){try{if(!t)return;console.log(n.red.italic.bold(`
|
|
3
|
+
Aeeaeae yohh BUT...`)),this.title(t.type),console.log(`
|
|
4
|
+
`),this.description(t.message),console.log(`
|
|
5
|
+
`),this.possibleCauses(t.possibleCauses),console.log(`
|
|
6
|
+
`),this.evidence(t.evidence),console.log(`
|
|
7
|
+
`),this.confidence(t.confidence),console.log(`
|
|
8
|
+
`),this.finalMessage(t.finalMessage||[]),this.referencePosition(t.references)}catch(s){throw s}}};export{c as ReasonPrinter};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var c=Object.defineProperty;var l=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var s=(e,t)=>c(e,"name",{value:t,configurable:!0});var g=(e,t)=>{for(var a in t)c(e,a,{get:t[a],enumerable:!0})},p=(e,t,a,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of u(t))!_.call(e,n)&&n!==a&&c(e,n,{get:()=>t[n],enumerable:!(i=l(t,n))||i.enumerable});return e};var h=e=>p(c({},"__esModule",{value:!0}),e);var S={};g(S,{ReasonSignalCls:()=>m,evidenceSource:()=>y,signalSource:()=>o});module.exports=h(S);var o={trace_step_match:s((e=.1)=>({weight:e,serverity:r(e),message:`trace_match (+${e}) \u2192 trace fully matches replay`}),"trace_step_match"),trace_step_not_match:s((e=.25)=>({weight:e,serverity:r(e),message:`trace_step_not_match (+${e}) \u2192 trace partially matches replay`}),"trace_step_not_match"),trace_return_data_match:s((e=.1)=>({weight:e,serverity:r(e),message:`trace_return_data_match (+${e}) \u2192 trace return data is consistent`}),"trace_return_data_match"),trace_return_data_not_match:s((e=.25)=>({weight:e,serverity:r(e),message:`trace_return_data_not_match (+${e}) \u2192 trace return data is inconsistent`}),"trace_return_data_not_match"),response_match:s((e=.1)=>({weight:e,serverity:r(e),message:`response_match (+${e}) \u2192 response is consistent`}),"response_match"),response_not_match:s((e=.25)=>({weight:e,serverity:r(e),message:`response_not_match (+${e}) \u2192 response is inconsistent`}),"response_not_match"),response_status_match:s((e=.1)=>({weight:e,serverity:r(e),message:`response_status_match (+${e}) \u2192 response status is consistent`}),"response_status_match"),response_status_not_match:s((e=.25)=>({weight:e,serverity:r(e),message:`response_status_not_match (+${e}) \u2192 response status is inconsistent`}),"response_status_not_match"),logic_error_indicator:s((e=.6)=>({weight:e,serverity:r(e),message:`logic_error_indicator (+${e}) \u2192 original response status >= 400 triggered logic flag`}),"logic_error_indicator")},y={trace_match:{value:!0,message:"flow is clean"},trace_not_match:{value:!1,message:"flow is not clean"},trace_step_match:{value:!0,message:"no mismatch"},trace_step_not_match:{value:!1,message:"mismatch"},trace_return_data_match:{value:!0,message:"no mismatch"},trace_return_data_not_match:{value:!1,message:"mismatch"},response_match:{value:!0,message:"no mismatch"},response_not_match:{value:!1,message:"mismatch"}};function r(e){return e>.75?"high":e>.55?"medium":"low"}s(r,"getSignalLevel");var m=class{static{s(this,"ReasonSignalCls")}findSignalByType(t){try{return o[t]}catch(a){throw a}}sumSignalWeights(t){try{return Object.values(t).reduce((a,i)=>a+i.weight,0)}catch(a){throw a}}};0&&(module.exports={ReasonSignalCls,evidenceSource,signalSource});
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
type SignalDetails = {
|
|
2
|
+
weight: number;
|
|
3
|
+
serverity?: "low" | "medium" | "high";
|
|
4
|
+
message?: string;
|
|
5
|
+
};
|
|
6
|
+
type ReasonSignal = {
|
|
7
|
+
[key: string]: SignalDetails;
|
|
8
|
+
};
|
|
9
|
+
declare const signalSource: {
|
|
10
|
+
/**
|
|
11
|
+
* When: original log trace step match replay trace step
|
|
12
|
+
*/
|
|
13
|
+
readonly trace_step_match: (weight?: number) => SignalDetails;
|
|
14
|
+
/**
|
|
15
|
+
* When: original log trace step mismatch replay trace step
|
|
16
|
+
*/
|
|
17
|
+
readonly trace_step_not_match: (weight?: number) => SignalDetails;
|
|
18
|
+
/**
|
|
19
|
+
* When: original log trace return data match replay trace return data
|
|
20
|
+
*/
|
|
21
|
+
readonly trace_return_data_match: (weight?: number) => SignalDetails;
|
|
22
|
+
/**
|
|
23
|
+
* When: original log trace return data mismatch replay trace return data
|
|
24
|
+
*/
|
|
25
|
+
readonly trace_return_data_not_match: (weight?: number) => SignalDetails;
|
|
26
|
+
/**
|
|
27
|
+
* When: original log response match replay response
|
|
28
|
+
*/
|
|
29
|
+
readonly response_match: (weight?: number) => SignalDetails;
|
|
30
|
+
/**
|
|
31
|
+
* When: original log response mismatch replay response
|
|
32
|
+
*/
|
|
33
|
+
readonly response_not_match: (weight?: number) => SignalDetails;
|
|
34
|
+
/**
|
|
35
|
+
* When: original response status match replay response status
|
|
36
|
+
*/
|
|
37
|
+
readonly response_status_match: (weight?: number) => SignalDetails;
|
|
38
|
+
/**
|
|
39
|
+
* When: original response status mismatch replay response status
|
|
40
|
+
*/
|
|
41
|
+
readonly response_status_not_match: (weight?: number) => SignalDetails;
|
|
42
|
+
/**
|
|
43
|
+
* When: original response status >= 400
|
|
44
|
+
*/
|
|
45
|
+
readonly logic_error_indicator: (weight?: number) => SignalDetails;
|
|
46
|
+
};
|
|
47
|
+
declare const evidenceSource: {
|
|
48
|
+
trace_match: {
|
|
49
|
+
value: boolean;
|
|
50
|
+
message: string;
|
|
51
|
+
};
|
|
52
|
+
trace_not_match: {
|
|
53
|
+
value: boolean;
|
|
54
|
+
message: string;
|
|
55
|
+
};
|
|
56
|
+
trace_step_match: {
|
|
57
|
+
value: boolean;
|
|
58
|
+
message: string;
|
|
59
|
+
};
|
|
60
|
+
trace_step_not_match: {
|
|
61
|
+
value: boolean;
|
|
62
|
+
message: string;
|
|
63
|
+
};
|
|
64
|
+
trace_return_data_match: {
|
|
65
|
+
value: boolean;
|
|
66
|
+
message: string;
|
|
67
|
+
};
|
|
68
|
+
trace_return_data_not_match: {
|
|
69
|
+
value: boolean;
|
|
70
|
+
message: string;
|
|
71
|
+
};
|
|
72
|
+
response_match: {
|
|
73
|
+
value: boolean;
|
|
74
|
+
message: string;
|
|
75
|
+
};
|
|
76
|
+
response_not_match: {
|
|
77
|
+
value: boolean;
|
|
78
|
+
message: string;
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
type SignalTypes = keyof typeof signalSource;
|
|
82
|
+
declare class ReasonSignalCls {
|
|
83
|
+
findSignalByType(type: SignalTypes): ((weight?: number) => SignalDetails) | ((weight?: number) => SignalDetails) | ((weight?: number) => SignalDetails) | ((weight?: number) => SignalDetails) | ((weight?: number) => SignalDetails) | ((weight?: number) => SignalDetails) | ((weight?: number) => SignalDetails) | ((weight?: number) => SignalDetails) | ((weight?: number) => SignalDetails);
|
|
84
|
+
sumSignalWeights(signals: Record<string, SignalDetails>): number;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export { type ReasonSignal, ReasonSignalCls, type SignalDetails, type SignalTypes, evidenceSource, signalSource };
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
type SignalDetails = {
|
|
2
|
+
weight: number;
|
|
3
|
+
serverity?: "low" | "medium" | "high";
|
|
4
|
+
message?: string;
|
|
5
|
+
};
|
|
6
|
+
type ReasonSignal = {
|
|
7
|
+
[key: string]: SignalDetails;
|
|
8
|
+
};
|
|
9
|
+
declare const signalSource: {
|
|
10
|
+
/**
|
|
11
|
+
* When: original log trace step match replay trace step
|
|
12
|
+
*/
|
|
13
|
+
readonly trace_step_match: (weight?: number) => SignalDetails;
|
|
14
|
+
/**
|
|
15
|
+
* When: original log trace step mismatch replay trace step
|
|
16
|
+
*/
|
|
17
|
+
readonly trace_step_not_match: (weight?: number) => SignalDetails;
|
|
18
|
+
/**
|
|
19
|
+
* When: original log trace return data match replay trace return data
|
|
20
|
+
*/
|
|
21
|
+
readonly trace_return_data_match: (weight?: number) => SignalDetails;
|
|
22
|
+
/**
|
|
23
|
+
* When: original log trace return data mismatch replay trace return data
|
|
24
|
+
*/
|
|
25
|
+
readonly trace_return_data_not_match: (weight?: number) => SignalDetails;
|
|
26
|
+
/**
|
|
27
|
+
* When: original log response match replay response
|
|
28
|
+
*/
|
|
29
|
+
readonly response_match: (weight?: number) => SignalDetails;
|
|
30
|
+
/**
|
|
31
|
+
* When: original log response mismatch replay response
|
|
32
|
+
*/
|
|
33
|
+
readonly response_not_match: (weight?: number) => SignalDetails;
|
|
34
|
+
/**
|
|
35
|
+
* When: original response status match replay response status
|
|
36
|
+
*/
|
|
37
|
+
readonly response_status_match: (weight?: number) => SignalDetails;
|
|
38
|
+
/**
|
|
39
|
+
* When: original response status mismatch replay response status
|
|
40
|
+
*/
|
|
41
|
+
readonly response_status_not_match: (weight?: number) => SignalDetails;
|
|
42
|
+
/**
|
|
43
|
+
* When: original response status >= 400
|
|
44
|
+
*/
|
|
45
|
+
readonly logic_error_indicator: (weight?: number) => SignalDetails;
|
|
46
|
+
};
|
|
47
|
+
declare const evidenceSource: {
|
|
48
|
+
trace_match: {
|
|
49
|
+
value: boolean;
|
|
50
|
+
message: string;
|
|
51
|
+
};
|
|
52
|
+
trace_not_match: {
|
|
53
|
+
value: boolean;
|
|
54
|
+
message: string;
|
|
55
|
+
};
|
|
56
|
+
trace_step_match: {
|
|
57
|
+
value: boolean;
|
|
58
|
+
message: string;
|
|
59
|
+
};
|
|
60
|
+
trace_step_not_match: {
|
|
61
|
+
value: boolean;
|
|
62
|
+
message: string;
|
|
63
|
+
};
|
|
64
|
+
trace_return_data_match: {
|
|
65
|
+
value: boolean;
|
|
66
|
+
message: string;
|
|
67
|
+
};
|
|
68
|
+
trace_return_data_not_match: {
|
|
69
|
+
value: boolean;
|
|
70
|
+
message: string;
|
|
71
|
+
};
|
|
72
|
+
response_match: {
|
|
73
|
+
value: boolean;
|
|
74
|
+
message: string;
|
|
75
|
+
};
|
|
76
|
+
response_not_match: {
|
|
77
|
+
value: boolean;
|
|
78
|
+
message: string;
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
type SignalTypes = keyof typeof signalSource;
|
|
82
|
+
declare class ReasonSignalCls {
|
|
83
|
+
findSignalByType(type: SignalTypes): ((weight?: number) => SignalDetails) | ((weight?: number) => SignalDetails) | ((weight?: number) => SignalDetails) | ((weight?: number) => SignalDetails) | ((weight?: number) => SignalDetails) | ((weight?: number) => SignalDetails) | ((weight?: number) => SignalDetails) | ((weight?: number) => SignalDetails) | ((weight?: number) => SignalDetails);
|
|
84
|
+
sumSignalWeights(signals: Record<string, SignalDetails>): number;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export { type ReasonSignal, ReasonSignalCls, type SignalDetails, type SignalTypes, evidenceSource, signalSource };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var c=Object.defineProperty;var t=(e,a)=>c(e,"name",{value:a,configurable:!0});var m={trace_step_match:t((e=.1)=>({weight:e,serverity:s(e),message:`trace_match (+${e}) \u2192 trace fully matches replay`}),"trace_step_match"),trace_step_not_match:t((e=.25)=>({weight:e,serverity:s(e),message:`trace_step_not_match (+${e}) \u2192 trace partially matches replay`}),"trace_step_not_match"),trace_return_data_match:t((e=.1)=>({weight:e,serverity:s(e),message:`trace_return_data_match (+${e}) \u2192 trace return data is consistent`}),"trace_return_data_match"),trace_return_data_not_match:t((e=.25)=>({weight:e,serverity:s(e),message:`trace_return_data_not_match (+${e}) \u2192 trace return data is inconsistent`}),"trace_return_data_not_match"),response_match:t((e=.1)=>({weight:e,serverity:s(e),message:`response_match (+${e}) \u2192 response is consistent`}),"response_match"),response_not_match:t((e=.25)=>({weight:e,serverity:s(e),message:`response_not_match (+${e}) \u2192 response is inconsistent`}),"response_not_match"),response_status_match:t((e=.1)=>({weight:e,serverity:s(e),message:`response_status_match (+${e}) \u2192 response status is consistent`}),"response_status_match"),response_status_not_match:t((e=.25)=>({weight:e,serverity:s(e),message:`response_status_not_match (+${e}) \u2192 response status is inconsistent`}),"response_status_not_match"),logic_error_indicator:t((e=.6)=>({weight:e,serverity:s(e),message:`logic_error_indicator (+${e}) \u2192 original response status >= 400 triggered logic flag`}),"logic_error_indicator")},l={trace_match:{value:!0,message:"flow is clean"},trace_not_match:{value:!1,message:"flow is not clean"},trace_step_match:{value:!0,message:"no mismatch"},trace_step_not_match:{value:!1,message:"mismatch"},trace_return_data_match:{value:!0,message:"no mismatch"},trace_return_data_not_match:{value:!1,message:"mismatch"},response_match:{value:!0,message:"no mismatch"},response_not_match:{value:!1,message:"mismatch"}};function s(e){return e>.75?"high":e>.55?"medium":"low"}t(s,"getSignalLevel");var n=class{static{t(this,"ReasonSignalCls")}findSignalByType(a){try{return m[a]}catch(r){throw r}}sumSignalWeights(a){try{return Object.values(a).reduce((r,i)=>r+i.weight,0)}catch(r){throw r}}};export{n as ReasonSignalCls,l as evidenceSource,m as signalSource};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";var W=Object.create;var v=Object.defineProperty;var G=Object.getOwnPropertyDescriptor;var V=Object.getOwnPropertyNames;var Y=Object.getPrototypeOf,Q=Object.prototype.hasOwnProperty;var a=(s,e)=>v(s,"name",{value:e,configurable:!0});var X=(s,e)=>{for(var t in e)v(s,t,{get:e[t],enumerable:!0})},I=(s,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of V(e))!Q.call(s,n)&&n!==t&&v(s,n,{get:()=>e[n],enumerable:!(r=G(e,n))||r.enumerable});return s};var d=(s,e,t)=>(t=s!=null?W(Y(s)):{},I(e||!s||!s.__esModule?v(t,"default",{value:s,enumerable:!0}):t,s)),Z=s=>I(v({},"__esModule",{value:!0}),s);var ce={};X(ce,{AdvanceReplay:()=>F});module.exports=Z(ce);var h=d(require("chalk"),1);var ae=require("ulid"),N=require("async_hooks");var ee=d(require("fs"),1),te=d(require("chalk"),1),re=d(require("path"),1),se=require("bundle-require");var de=new N.AsyncLocalStorage;var A=d(require("crypto"),1);function B(s){try{return A.default.createHash("md5").update(s).digest("hex")}catch(e){throw e}}a(B,"cryptoHash");var L="__root__";function oe(s){let e=new Map;for(let t of s){let r=t.parentId||L;e.has(r)||e.set(r,[]),e.get(r).push(t)}return e}a(oe,"buildTraceTree");function ie(s,e,t){return`${t}->${s.name}#${e}`}a(ie,"buildSignature");function $(s){try{let n=function(o,l){(t.get(o)||[]).sort((i,p)=>i.start-p.start).forEach((i,p)=>{let f=ie(i,p,l),y=B(f);r.push({...i,signature:y,rawSignature:f}),n(i.id,y)})};var e=n;a(n,"walk");let t=oe(s),r=[];return n(L,L),r}catch(t){throw t}}a($,"flattenTrace");var S=class{constructor(e){this.config=e}config;static{a(this,"ReplayFilterManager")}matchPattern(e,t){try{return e instanceof RegExp?e.test(t):e.includes("*")?new RegExp("^"+e.replace(/\*/g,".*")+"$").test(t):e===t}catch(r){throw r}}async filterTrace(e){try{if(!this.config.filters||!e||e.length===0)return e;let t=this.config.filters;return e.filter(r=>{let n=r.name;return!t.ignoreSteps?.some(l=>this.matchPattern(l,n))})}catch(t){throw t}}async filterNonOptionalTrace(e){try{if(!this.config.filters||!e||e.length===0)return e;let t=this.config.filters;return e.filter(r=>{let n=r.name;return!t.optionalSteps?.some(l=>this.matchPattern(l,n))})}catch(t){throw t}}isOptionalStep(e){try{return this.config.filters?.optionalSteps?.some(t=>this.matchPattern(t,e))}catch(t){throw t}}async filterResponse(e){try{if(!this.config.filters||!e)return e;let t=Object.keys(e.error);if(t.length===0)return e;let r=this.config.filters;for(let n of t)r.ignoreFields?.includes(n)&&delete e.error[n];return{...e,error:e.error}}catch(t){throw t}}};var st=require("dotenv/config.js");var D=class{constructor(e){this.config=e}config;static{a(this,"ReplayHelper")}get filterManager(){return new S(this.config)}setConfig(e){this.config=e}normalize(e){if(!e)return e;if(typeof e=="string")try{return JSON.parse(e)}catch{return e}return e}stableStringify(e){return JSON.stringify(this.sortKeys(e))}sortKeys(e){return Array.isArray(e)?e.map(t=>this.sortKeys(t)):e&&typeof e=="object"?Object.keys(e).sort().reduce((t,r)=>(t[r]=this.sortKeys(e[r]),t),{}):e}compareTrace(e,t){try{let r=[],n=new Map(e.map(c=>[c.signature,c])),o=new Map(t.map(c=>[c.signature,c])),l={};for(let[c,i]of n)l[i.name]={id:i.id,parentId:i.parentId,original:i.returnData,replay:null},o.has(i.signature)||this.filterManager.isOptionalStep(i.name)||r.push({type:"missing_step",name:i.name,message:`Missing step: ${c}`});for(let[c,i]of o)l[i.name].replay=i.returnData,n.has(i.signature)||c&&this.filterManager.isOptionalStep(i.name)||r.push({type:"extra_step",name:i.name,message:`Extra step: ${c}`});for(let c in l){let i=l[c].original,p=l[c].replay;i!==p&&r.push({type:"trace_return_data_mismatch",name:c,message:"Trace return data mismatch",not_matched:{original:i,replay:p}})}return{isDifferent:r.length>0,issues:r}}catch(r){throw r}}compareResponse(e,t){try{let r=[];e.status!==t.status&&r.push({type:"status_mismatch",message:"Status code mismatch",not_matched:{original:e.status,replay:t.status}});let n=this.normalize(e.error),o=this.normalize(t.error),l=this.stableStringify(n),c=this.stableStringify(o);return l!==c&&r.push({type:"body_mismatch",message:"Response mismatch",not_matched:{original:n,replay:o}}),{isDifferent:r.length>0,issues:r}}catch(r){throw r}}fullUrl(e){return`${process.env.SERVER_URL}${e}`}async sendRequest(e){try{return await fetch(this.fullUrl(e.request.url),{method:e.request.method,headers:{"Content-Type":"application/json","x-is-replay":"true"},body:JSON.stringify(e.request.body)})}catch(t){throw t}}};var w=class{constructor(e){this.config=e}config;static{a(this,"BaseReplay")}get filterManager(){return new S(this.config)}get replayHelper(){return new D(this.config)}};var H=d(require("http"),1);var O={trace_step_match:a((s=.1)=>({weight:s,serverity:m(s),message:`trace_match (+${s}) \u2192 trace fully matches replay`}),"trace_step_match"),trace_step_not_match:a((s=.25)=>({weight:s,serverity:m(s),message:`trace_step_not_match (+${s}) \u2192 trace partially matches replay`}),"trace_step_not_match"),trace_return_data_match:a((s=.1)=>({weight:s,serverity:m(s),message:`trace_return_data_match (+${s}) \u2192 trace return data is consistent`}),"trace_return_data_match"),trace_return_data_not_match:a((s=.25)=>({weight:s,serverity:m(s),message:`trace_return_data_not_match (+${s}) \u2192 trace return data is inconsistent`}),"trace_return_data_not_match"),response_match:a((s=.1)=>({weight:s,serverity:m(s),message:`response_match (+${s}) \u2192 response is consistent`}),"response_match"),response_not_match:a((s=.25)=>({weight:s,serverity:m(s),message:`response_not_match (+${s}) \u2192 response is inconsistent`}),"response_not_match"),response_status_match:a((s=.1)=>({weight:s,serverity:m(s),message:`response_status_match (+${s}) \u2192 response status is consistent`}),"response_status_match"),response_status_not_match:a((s=.25)=>({weight:s,serverity:m(s),message:`response_status_not_match (+${s}) \u2192 response status is inconsistent`}),"response_status_not_match"),logic_error_indicator:a((s=.6)=>({weight:s,serverity:m(s),message:`logic_error_indicator (+${s}) \u2192 original response status >= 400 triggered logic flag`}),"logic_error_indicator")},q={trace_match:{value:!0,message:"flow is clean"},trace_not_match:{value:!1,message:"flow is not clean"},trace_step_match:{value:!0,message:"no mismatch"},trace_step_not_match:{value:!1,message:"mismatch"},trace_return_data_match:{value:!0,message:"no mismatch"},trace_return_data_not_match:{value:!1,message:"mismatch"},response_match:{value:!0,message:"no mismatch"},response_not_match:{value:!1,message:"mismatch"}};function m(s){return s>.75?"high":s>.55?"medium":"low"}a(m,"getSignalLevel");var P=class{static{a(this,"ReasonSignalCls")}findSignalByType(e){try{return O[e]}catch(t){throw t}}sumSignalWeights(e){try{return Object.values(e).reduce((t,r)=>t+r.weight,0)}catch(t){throw t}}};var u=d(require("chalk"),1);var R=class{static{a(this,"BaseAssignerCase")}get evidenceSource(){return q}get signalSource(){return O}getTraceDivergenceSection(e){let t=e.traceDiff.issues;if(t.length===0)return"No divergence";let r=`
|
|
2
|
+
`;for(let n of t)n.type==="missing_step"&&(r+=u.default.yellow(`
|
|
3
|
+
* ${n.name}(missing_step):
|
|
4
|
+
`),r+=u.default.green(` \u2192 original: exists
|
|
5
|
+
`),r+=u.default.red(" \u2192 replay: missing"),r+=`
|
|
6
|
+
`),n.type==="extra_step"&&(r+=u.default.yellow(`
|
|
7
|
+
* ${n.name}(extra_step):
|
|
8
|
+
`),r+=u.default.green(` \u2192 original: none
|
|
9
|
+
`),r+=u.default.red(" \u2192 replay: exists"),r+=`
|
|
10
|
+
`);return r.trim()}getMessageEdvidence(e){return`${this.evidenceSource[e].value} (${this.evidenceSource[e].message})`}getStatusEdvidence(e){let t=H.default.STATUS_CODES[e]||"Unknown";return`${e} (${t})`}isTraceMatch(e){return!e.traceDiff.isDifferent}isTraceStepMatch(e){return e.traceDiff.issues.length>0?!e.traceDiff.issues.some(t=>t.type==="missing_step"||t.type==="extra_step"):!0}isTraceReturnDataMatch(e){return e.traceDiff.issues.length>0?!e.traceDiff.issues.some(t=>t.type==="trace_return_data_mismatch"):!0}isResponseMatch(e){return!e.responseDiff.isDifferent}isResponseStatusMatch(e){let{originalStatus:t,replayStatus:r}=this.resolveStatus(e);return t===r}resolveStatus(e){return{originalStatus:Number(e.log.response.status),replayStatus:e.replayResultStatus}}getResponseDiffSection(e){let t=e.responseDiff.issues;if(t.length===0)return"No diff";let r=t.length>1?1:0,n=e.responseDiff.issues[r].not_matched;if(!n)return"No diff";let o=n.original||{},l=n.replay||{},c=new Set([...Object.keys(o),...Object.keys(l)]),i=`
|
|
11
|
+
`;for(let p of c){let f=o[p],y=l[p];f!==y&&(i+=u.default.yellow(` * ${p}:
|
|
12
|
+
`),i+=u.default.green(` \u2192 original: ${JSON.stringify(f)}
|
|
13
|
+
`),i+=u.default.red(` \u2192 replay: ${JSON.stringify(y)}
|
|
14
|
+
`))}return i}};var T=class extends R{static{a(this,"BusinessLogicRejectionCase")}condition(e,t){return this.isTraceMatch(e)&&this.isResponseMatch(e)&&t.originalStatus>=400&&t.replayStatus>=400}assign(e){try{let t=this.resolveStatus(e);if(this.condition(e,t)){let r=e.log.trace?.find(o=>o.parentId===null);return{type:"Business Logic Rejection Case (logic_suspicious)",message:"Response indicates error, but execution original and replay result match expected behavior",possibleCauses:["Business rule might not align with actual execution flow","Or validation logic is too strict / misaligned"],evidence:{traceMatch:this.getMessageEdvidence("trace_match"),responseMatch:this.getMessageEdvidence("response_match"),originalStatus:this.getStatusEdvidence(t.originalStatus),finalResponse:typeof r?.returnData=="object"?JSON.stringify(r.returnData,null,2):r?.returnData},confidence:{signals:{trace_match:this.signalSource.trace_step_match(.3),response_match:this.signalSource.response_match(.3),logic_error_indicator:this.signalSource.logic_error_indicator(.2)},result:0},finalMessage:["This is NOT a runtime bug","This is likely a business logic issue"],references:e.log.stack}}}catch(t){throw t}}};var b=class extends R{static{a(this,"PostTraceResponseMutationCase")}assign(e){try{let t=this.resolveStatus(e);if(this.isTraceStepMatch(e)&&!this.isResponseMatch(e)&&this.isTraceReturnDataMatch(e))return{type:"Response Mismatch Case (post_processing_suspicious)",message:"Execution flow is identical, but response output differs",possibleCauses:["Post-processing logic may be inconsistent","Response mapping or transformation may be incorrect","Data changes may affect the final result.","Non-deterministic behavior (e.g. random, time-based, shared state)"],evidence:{traceMatch:this.getMessageEdvidence("trace_match"),responseMatch:this.getMessageEdvidence("response_not_match"),originalStatus:this.getStatusEdvidence(t.originalStatus),responseDiff:this.getResponseDiffSection(e)},confidence:{signals:{trace_step_match:this.signalSource.trace_step_match(.3),response_mismatch:this.signalSource.response_not_match(.2),trace_return_data_match:this.signalSource.trace_return_data_match(.3)},result:0},finalMessage:["Execution logic is stable, but output is inconsistent","This may indicate issues in response transformation or side effects","This may occur after the business logic is execute complete."],references:e.log.stack}}catch(t){throw t}}};var C=class extends R{static{a(this,"TraceDivergenceCase")}assign(e){try{let t=this.resolveStatus(e);if(!this.isTraceStepMatch(e)&&!this.isResponseMatch(e)&&!this.isTraceReturnDataMatch(e)&&!this.isResponseStatusMatch(e))return{type:"Trace Divergence Case (execution_path_mismatch)",message:"Execution path diverged between original and replay",possibleCauses:["Conditional branch logic may behave differently","Environment or shared state may affect execution flow","Request context may not be deterministic","Replay execution may enter different logic branches","Hidden dependencies or side effects may exist"],evidence:{traceMatch:this.getMessageEdvidence("trace_not_match"),originalStatus:this.getStatusEdvidence(t.originalStatus),traceDivergence:this.getTraceDivergenceSection(e),responseDiff:this.getResponseDiffSection(e)},confidence:{signals:{trace_step_not_match:this.signalSource.trace_step_not_match(.45),trace_return_data_not_match:this.signalSource.trace_return_data_not_match(.25),response_not_match:this.signalSource.response_not_match(.15),response_status_not_match:this.signalSource.response_status_not_match(.1)},result:0},finalMessage:["Replay execution diverged from the original execution flow","This may indicate unstable conditions or branch inconsistency","Root cause likely exists before response generation"],references:e.log.stack}}catch(t){throw t}}};var k=class{static{a(this,"ReasonAssigner")}get case(){return{business_logic_rejection:new T,post_trace_response_mutation:new b,trace_divergence:new C}}};var g=d(require("chalk"),1);var E=class{static{a(this,"ReasonPrinter")}get reasonSignal(){return new P}title(e){console.log(g.default.yellowBright("** Reason Title:")),console.log(`[!] ${e}`)}description(e){console.log(g.default.yellowBright("** Description:")),console.log(e)}possibleCauses(e){console.log(g.default.yellowBright("** What I think happened:")),e.forEach(t=>{console.log(` \u2192 ${t}`)})}evidence(e){let t=Object.keys(e);console.log(g.default.yellowBright("** Evidence I saw:")),t.forEach(r=>{console.log(` \u2192 ${r}: ${e[r]}`)})}confidence(e){console.log(g.default.yellowBright("** Confidence Reason (why I think this): ")),e.signals&&Object.keys(e.signals).forEach(n=>{console.log(` \u2192 ${e.signals[n].message}`)}),e.result=this.reasonSignal.sumSignalWeights(e.signals);let t=Math.round(e.result*100);console.log(`
|
|
15
|
+
`),console.log(g.default.yellowBright("** Confidence Result: ")),console.log(g.default.green.italic.bold(` * score: ${e.result.toFixed(2)} / 1 `)),console.log(g.default.green.italic.bold(` * percent: ${t} / 100 (%) `))}finalMessage(e){e.length!=0&&(console.log(g.default.yellowBright("** Final Call:")),e.forEach(t=>{console.log(` \u2192 ${t}`)}))}referencePosition(e){if(e&&(console.log(g.default.yellowBright("* Reference Position: ")),console.log(" \u2192 Suspected position:",g.default.red.underline(e.primary?.full_path)),e.context&&e.context.length>0)){let t=e.context.length-1;e.context.forEach((r,n)=>{console.log(` \u2192 (Context ${t-n}): ${r.full_path}`)})}}printReason(e){try{if(!e)return;console.log(g.default.red.italic.bold(`
|
|
16
|
+
Aeeaeae yohh BUT...`)),this.title(e.type),console.log(`
|
|
17
|
+
`),this.description(e.message),console.log(`
|
|
18
|
+
`),this.possibleCauses(e.possibleCauses),console.log(`
|
|
19
|
+
`),this.evidence(e.evidence),console.log(`
|
|
20
|
+
`),this.confidence(e.confidence),console.log(`
|
|
21
|
+
`),this.finalMessage(e.finalMessage||[]),this.referencePosition(e.references)}catch(t){throw t}}};var F=class extends w{constructor(t){super(t);this.config=t}config;static{a(this,"AdvanceReplay")}get reasonPrinter(){return new E}get reasonAssigner(){return new k}printResponseDiff(t){if(t.isDifferent){console.log(h.default.red("[!] Response DIFF"));for(let r of t.issues)console.log(` - [${r.type}] ${r.message}`)}else console.log(h.default.green("[OK] Response MATCH"))}printTraceDiff(t){if(t.isDifferent){console.log(h.default.red("[!] Trace DIFF"));for(let r of t.issues)console.log(` - [${r.type}] ${r.name}`)}else console.log(h.default.green("[OK] Trace MATCH"))}printRootCauseIssue(t){if(t.length>0){let r=["performance_issue","performance_warning","performance_regression"];if(!t.every(o=>r.includes(o.type))){console.log(h.default.red("\u26A0 Root Cause Analysis"));for(let o of t)console.log(` - [${o.type}] ${o.message}`)}}else console.log(h.default.green("[OK] No root cause issues detected"))}printPerformanceIssue(t){let r=t.filter(n=>n.type==="performance_regression");if(r.length>0){console.log(h.default.yellow(`
|
|
22
|
+
\u26A0 Performance Regression Detected`));for(let n of r)console.log(`- ${n.step}: ${n.message}`)}}print(t){try{let{log:r,responseDiff:n,traceDiff:o,analysis:l}=t;console.log(h.default.bgYellowBright.bold(` \u25B6 ${r.request.method} ${r.request.url} `)),this.printResponseDiff(n),this.printTraceDiff(o),this.printRootCauseIssue(l),this.printPerformanceIssue(l),this.printReason(t)}catch(r){throw r}}printReason(t){try{let r=this.reasonAssigner.case.business_logic_rejection.assign(t);this.reasonPrinter.printReason(r);let n=this.reasonAssigner.case.post_trace_response_mutation.assign(t);this.reasonPrinter.printReason(n);let o=this.reasonAssigner.case.trace_divergence.assign(t);this.reasonPrinter.printReason(o)}catch(r){throw r}}analyzeRootCause(t){try{let{responseDiff:r,traceDiff:n,logTrace:o,replayData:l}=t,c=[],i=this.config.filters;r.isDifferent&&n.isDifferent&&c.push({type:"flow_break",message:"Response mismatch caused by trace difference"});let p=i?.expectedPerformance;if(!p)return c;for(let f of o){let y=l?.trace?.find(U=>U.name===f.name);if(!y)continue;let _=(y.duration_ms||0)-(f.duration_ms||0),J=Math.max(f.duration_ms||1,20),j=_/J*100,M=f.name.split("."),K=f.name;M.length==2?K=M[1]:K=M[0];let x=p.steps?.[K]??0;if(x===0)continue;let z=x/2;_>x?c.push({type:"performance_regression",step:f.name,severity:"high",message:`Slow step: +${_}ms > ${x}ms (+${j.toFixed(1)}%)`}):_>z&&c.push({type:"performance_warning",step:f.name,severity:"low",message:`Slight delay: +${_}ms`})}return c}catch(r){throw r}}async getTraceResult(t,r){try{let n=$(t.trace||[]),o=$(r.trace||[]),l=await this.filterManager.filterTrace(n),c=await this.filterManager.filterTrace(o),i=this.replayHelper.compareTrace(l,c);return{logTraceFiltered:l,replayTraceFiltered:c,traceDiff:i}}catch(n){throw n}}async getResponseResult(t,r,n){try{let o=await this.filterManager.filterResponse({error:JSON.parse(t.response.error),status:t.response.status}),l=await this.filterManager.filterResponse({error:r,status:n.status});return{responseDiff:this.replayHelper.compareResponse(o,l)}}catch(o){throw o}}async replay(t){try{let r=await this.replayHelper.sendRequest(t),n=await r.json(),o=n.__replay;delete n.__replay;let l=await this.getResponseResult(t,n,r),c=await this.getTraceResult(t,o),i=this.analyzeRootCause({replayData:o,traceDiff:c.traceDiff,logTrace:c.logTraceFiltered,responseDiff:l.responseDiff});r.status<=400&&i.length==0?this.print({log:t,replayResultStatus:r.status,analysis:[],traceDiff:{isDifferent:!1,issues:[]},responseDiff:{isDifferent:!1,issues:[]}}):this.print({log:t,replayResultStatus:r.status,analysis:i,traceDiff:c.traceDiff,responseDiff:l.responseDiff})}catch(r){throw r}}};0&&(module.exports={AdvanceReplay});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { DifferentResult } from '../../handler.cjs';
|
|
2
|
+
import { R as ReplayKitLogData, a as ReplayKitTraceEvent, S as StackReference } from '../../../error_handle.helper-CQsPSbuz.cjs';
|
|
3
|
+
import { ConfigSetup } from '../../../setup.cjs';
|
|
4
|
+
import { BaseReplay } from '../../base.cjs';
|
|
5
|
+
import { ReasonSignal } from './reasons/reason_signal.cjs';
|
|
6
|
+
import 'async_hooks';
|
|
7
|
+
import '../../../index-MBKv_hsI.cjs';
|
|
8
|
+
import '../../../enum/log_level.enum.cjs';
|
|
9
|
+
import '../../../trace/filter.cjs';
|
|
10
|
+
import '../../helper.cjs';
|
|
11
|
+
|
|
12
|
+
type RootCauseReason = {
|
|
13
|
+
type: string;
|
|
14
|
+
message: string;
|
|
15
|
+
possibleCauses: string[];
|
|
16
|
+
evidence: Record<string, any>;
|
|
17
|
+
confidence: {
|
|
18
|
+
signals: ReasonSignal;
|
|
19
|
+
result: number;
|
|
20
|
+
};
|
|
21
|
+
finalMessage?: string[];
|
|
22
|
+
references?: StackReference;
|
|
23
|
+
};
|
|
24
|
+
type RootCauseParams = {
|
|
25
|
+
responseDiff: DifferentResult;
|
|
26
|
+
traceDiff: DifferentResult;
|
|
27
|
+
logTrace: ReplayKitTraceEvent[];
|
|
28
|
+
replayData?: {
|
|
29
|
+
trace?: ReplayKitTraceEvent[];
|
|
30
|
+
duration_ms?: number;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
type PrintParams = {
|
|
34
|
+
log: ReplayKitLogData;
|
|
35
|
+
replayResultStatus: number;
|
|
36
|
+
responseDiff: DifferentResult;
|
|
37
|
+
traceDiff: DifferentResult;
|
|
38
|
+
analysis: any[];
|
|
39
|
+
};
|
|
40
|
+
declare class AdvanceReplay extends BaseReplay {
|
|
41
|
+
protected config: ConfigSetup;
|
|
42
|
+
constructor(config: ConfigSetup);
|
|
43
|
+
private get reasonPrinter();
|
|
44
|
+
private get reasonAssigner();
|
|
45
|
+
private printResponseDiff;
|
|
46
|
+
private printTraceDiff;
|
|
47
|
+
private printRootCauseIssue;
|
|
48
|
+
private printPerformanceIssue;
|
|
49
|
+
private print;
|
|
50
|
+
private printReason;
|
|
51
|
+
private analyzeRootCause;
|
|
52
|
+
private getTraceResult;
|
|
53
|
+
private getResponseResult;
|
|
54
|
+
replay(log: ReplayKitLogData): Promise<void>;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export { AdvanceReplay, type PrintParams, type RootCauseParams, type RootCauseReason };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { DifferentResult } from '../../handler.js';
|
|
2
|
+
import { R as ReplayKitLogData, a as ReplayKitTraceEvent, S as StackReference } from '../../../error_handle.helper-CQsPSbuz.js';
|
|
3
|
+
import { ConfigSetup } from '../../../setup.js';
|
|
4
|
+
import { BaseReplay } from '../../base.js';
|
|
5
|
+
import { ReasonSignal } from './reasons/reason_signal.js';
|
|
6
|
+
import 'async_hooks';
|
|
7
|
+
import '../../../index-8u1_ya-u.js';
|
|
8
|
+
import '../../../enum/log_level.enum.js';
|
|
9
|
+
import '../../../trace/filter.js';
|
|
10
|
+
import '../../helper.js';
|
|
11
|
+
|
|
12
|
+
type RootCauseReason = {
|
|
13
|
+
type: string;
|
|
14
|
+
message: string;
|
|
15
|
+
possibleCauses: string[];
|
|
16
|
+
evidence: Record<string, any>;
|
|
17
|
+
confidence: {
|
|
18
|
+
signals: ReasonSignal;
|
|
19
|
+
result: number;
|
|
20
|
+
};
|
|
21
|
+
finalMessage?: string[];
|
|
22
|
+
references?: StackReference;
|
|
23
|
+
};
|
|
24
|
+
type RootCauseParams = {
|
|
25
|
+
responseDiff: DifferentResult;
|
|
26
|
+
traceDiff: DifferentResult;
|
|
27
|
+
logTrace: ReplayKitTraceEvent[];
|
|
28
|
+
replayData?: {
|
|
29
|
+
trace?: ReplayKitTraceEvent[];
|
|
30
|
+
duration_ms?: number;
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
type PrintParams = {
|
|
34
|
+
log: ReplayKitLogData;
|
|
35
|
+
replayResultStatus: number;
|
|
36
|
+
responseDiff: DifferentResult;
|
|
37
|
+
traceDiff: DifferentResult;
|
|
38
|
+
analysis: any[];
|
|
39
|
+
};
|
|
40
|
+
declare class AdvanceReplay extends BaseReplay {
|
|
41
|
+
protected config: ConfigSetup;
|
|
42
|
+
constructor(config: ConfigSetup);
|
|
43
|
+
private get reasonPrinter();
|
|
44
|
+
private get reasonAssigner();
|
|
45
|
+
private printResponseDiff;
|
|
46
|
+
private printTraceDiff;
|
|
47
|
+
private printRootCauseIssue;
|
|
48
|
+
private printPerformanceIssue;
|
|
49
|
+
private print;
|
|
50
|
+
private printReason;
|
|
51
|
+
private analyzeRootCause;
|
|
52
|
+
private getTraceResult;
|
|
53
|
+
private getResponseResult;
|
|
54
|
+
replay(log: ReplayKitLogData): Promise<void>;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export { AdvanceReplay, type PrintParams, type RootCauseParams, type RootCauseReason };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
var q=Object.defineProperty;var a=(s,e)=>q(s,"name",{value:e,configurable:!0});import d from"chalk";import{ulid as le}from"ulid";import{AsyncLocalStorage as J}from"async_hooks";import Y from"fs";import X from"chalk";import ee from"path";import{bundleRequire as re}from"bundle-require";var ue=new J;import j from"crypto";function $(s){try{return j.createHash("md5").update(s).digest("hex")}catch(e){throw e}}a($,"cryptoHash");var M="__root__";function z(s){let e=new Map;for(let t of s){let r=t.parentId||M;e.has(r)||e.set(r,[]),e.get(r).push(t)}return e}a(z,"buildTraceTree");function U(s,e,t){return`${t}->${s.name}#${e}`}a(U,"buildSignature");function K(s){try{let n=function(o,l){(t.get(o)||[]).sort((i,p)=>i.start-p.start).forEach((i,p)=>{let f=U(i,p,l),h=$(f);r.push({...i,signature:h,rawSignature:f}),n(i.id,h)})};var e=n;a(n,"walk");let t=z(s),r=[];return n(M,M),r}catch(t){throw t}}a(K,"flattenTrace");var R=class{constructor(e){this.config=e}config;static{a(this,"ReplayFilterManager")}matchPattern(e,t){try{return e instanceof RegExp?e.test(t):e.includes("*")?new RegExp("^"+e.replace(/\*/g,".*")+"$").test(t):e===t}catch(r){throw r}}async filterTrace(e){try{if(!this.config.filters||!e||e.length===0)return e;let t=this.config.filters;return e.filter(r=>{let n=r.name;return!t.ignoreSteps?.some(l=>this.matchPattern(l,n))})}catch(t){throw t}}async filterNonOptionalTrace(e){try{if(!this.config.filters||!e||e.length===0)return e;let t=this.config.filters;return e.filter(r=>{let n=r.name;return!t.optionalSteps?.some(l=>this.matchPattern(l,n))})}catch(t){throw t}}isOptionalStep(e){try{return this.config.filters?.optionalSteps?.some(t=>this.matchPattern(t,e))}catch(t){throw t}}async filterResponse(e){try{if(!this.config.filters||!e)return e;let t=Object.keys(e.error);if(t.length===0)return e;let r=this.config.filters;for(let n of t)r.ignoreFields?.includes(n)&&delete e.error[n];return{...e,error:e.error}}catch(t){throw t}}};import"dotenv/config.js";var v=class{constructor(e){this.config=e}config;static{a(this,"ReplayHelper")}get filterManager(){return new R(this.config)}setConfig(e){this.config=e}normalize(e){if(!e)return e;if(typeof e=="string")try{return JSON.parse(e)}catch{return e}return e}stableStringify(e){return JSON.stringify(this.sortKeys(e))}sortKeys(e){return Array.isArray(e)?e.map(t=>this.sortKeys(t)):e&&typeof e=="object"?Object.keys(e).sort().reduce((t,r)=>(t[r]=this.sortKeys(e[r]),t),{}):e}compareTrace(e,t){try{let r=[],n=new Map(e.map(c=>[c.signature,c])),o=new Map(t.map(c=>[c.signature,c])),l={};for(let[c,i]of n)l[i.name]={id:i.id,parentId:i.parentId,original:i.returnData,replay:null},o.has(i.signature)||this.filterManager.isOptionalStep(i.name)||r.push({type:"missing_step",name:i.name,message:`Missing step: ${c}`});for(let[c,i]of o)l[i.name].replay=i.returnData,n.has(i.signature)||c&&this.filterManager.isOptionalStep(i.name)||r.push({type:"extra_step",name:i.name,message:`Extra step: ${c}`});for(let c in l){let i=l[c].original,p=l[c].replay;i!==p&&r.push({type:"trace_return_data_mismatch",name:c,message:"Trace return data mismatch",not_matched:{original:i,replay:p}})}return{isDifferent:r.length>0,issues:r}}catch(r){throw r}}compareResponse(e,t){try{let r=[];e.status!==t.status&&r.push({type:"status_mismatch",message:"Status code mismatch",not_matched:{original:e.status,replay:t.status}});let n=this.normalize(e.error),o=this.normalize(t.error),l=this.stableStringify(n),c=this.stableStringify(o);return l!==c&&r.push({type:"body_mismatch",message:"Response mismatch",not_matched:{original:n,replay:o}}),{isDifferent:r.length>0,issues:r}}catch(r){throw r}}fullUrl(e){return`${process.env.SERVER_URL}${e}`}async sendRequest(e){try{return await fetch(this.fullUrl(e.request.url),{method:e.request.method,headers:{"Content-Type":"application/json","x-is-replay":"true"},body:JSON.stringify(e.request.body)})}catch(t){throw t}}};var x=class{constructor(e){this.config=e}config;static{a(this,"BaseReplay")}get filterManager(){return new R(this.config)}get replayHelper(){return new v(this.config)}};import W from"http";var L={trace_step_match:a((s=.1)=>({weight:s,serverity:u(s),message:`trace_match (+${s}) \u2192 trace fully matches replay`}),"trace_step_match"),trace_step_not_match:a((s=.25)=>({weight:s,serverity:u(s),message:`trace_step_not_match (+${s}) \u2192 trace partially matches replay`}),"trace_step_not_match"),trace_return_data_match:a((s=.1)=>({weight:s,serverity:u(s),message:`trace_return_data_match (+${s}) \u2192 trace return data is consistent`}),"trace_return_data_match"),trace_return_data_not_match:a((s=.25)=>({weight:s,serverity:u(s),message:`trace_return_data_not_match (+${s}) \u2192 trace return data is inconsistent`}),"trace_return_data_not_match"),response_match:a((s=.1)=>({weight:s,serverity:u(s),message:`response_match (+${s}) \u2192 response is consistent`}),"response_match"),response_not_match:a((s=.25)=>({weight:s,serverity:u(s),message:`response_not_match (+${s}) \u2192 response is inconsistent`}),"response_not_match"),response_status_match:a((s=.1)=>({weight:s,serverity:u(s),message:`response_status_match (+${s}) \u2192 response status is consistent`}),"response_status_match"),response_status_not_match:a((s=.25)=>({weight:s,serverity:u(s),message:`response_status_not_match (+${s}) \u2192 response status is inconsistent`}),"response_status_not_match"),logic_error_indicator:a((s=.6)=>({weight:s,serverity:u(s),message:`logic_error_indicator (+${s}) \u2192 original response status >= 400 triggered logic flag`}),"logic_error_indicator")},O={trace_match:{value:!0,message:"flow is clean"},trace_not_match:{value:!1,message:"flow is not clean"},trace_step_match:{value:!0,message:"no mismatch"},trace_step_not_match:{value:!1,message:"mismatch"},trace_return_data_match:{value:!0,message:"no mismatch"},trace_return_data_not_match:{value:!1,message:"mismatch"},response_match:{value:!0,message:"no mismatch"},response_not_match:{value:!1,message:"mismatch"}};function u(s){return s>.75?"high":s>.55?"medium":"low"}a(u,"getSignalLevel");var D=class{static{a(this,"ReasonSignalCls")}findSignalByType(e){try{return L[e]}catch(t){throw t}}sumSignalWeights(e){try{return Object.values(e).reduce((t,r)=>t+r.weight,0)}catch(t){throw t}}};import m from"chalk";var y=class{static{a(this,"BaseAssignerCase")}get evidenceSource(){return O}get signalSource(){return L}getTraceDivergenceSection(e){let t=e.traceDiff.issues;if(t.length===0)return"No divergence";let r=`
|
|
2
|
+
`;for(let n of t)n.type==="missing_step"&&(r+=m.yellow(`
|
|
3
|
+
* ${n.name}(missing_step):
|
|
4
|
+
`),r+=m.green(` \u2192 original: exists
|
|
5
|
+
`),r+=m.red(" \u2192 replay: missing"),r+=`
|
|
6
|
+
`),n.type==="extra_step"&&(r+=m.yellow(`
|
|
7
|
+
* ${n.name}(extra_step):
|
|
8
|
+
`),r+=m.green(` \u2192 original: none
|
|
9
|
+
`),r+=m.red(" \u2192 replay: exists"),r+=`
|
|
10
|
+
`);return r.trim()}getMessageEdvidence(e){return`${this.evidenceSource[e].value} (${this.evidenceSource[e].message})`}getStatusEdvidence(e){let t=W.STATUS_CODES[e]||"Unknown";return`${e} (${t})`}isTraceMatch(e){return!e.traceDiff.isDifferent}isTraceStepMatch(e){return e.traceDiff.issues.length>0?!e.traceDiff.issues.some(t=>t.type==="missing_step"||t.type==="extra_step"):!0}isTraceReturnDataMatch(e){return e.traceDiff.issues.length>0?!e.traceDiff.issues.some(t=>t.type==="trace_return_data_mismatch"):!0}isResponseMatch(e){return!e.responseDiff.isDifferent}isResponseStatusMatch(e){let{originalStatus:t,replayStatus:r}=this.resolveStatus(e);return t===r}resolveStatus(e){return{originalStatus:Number(e.log.response.status),replayStatus:e.replayResultStatus}}getResponseDiffSection(e){let t=e.responseDiff.issues;if(t.length===0)return"No diff";let r=t.length>1?1:0,n=e.responseDiff.issues[r].not_matched;if(!n)return"No diff";let o=n.original||{},l=n.replay||{},c=new Set([...Object.keys(o),...Object.keys(l)]),i=`
|
|
11
|
+
`;for(let p of c){let f=o[p],h=l[p];f!==h&&(i+=m.yellow(` * ${p}:
|
|
12
|
+
`),i+=m.green(` \u2192 original: ${JSON.stringify(f)}
|
|
13
|
+
`),i+=m.red(` \u2192 replay: ${JSON.stringify(h)}
|
|
14
|
+
`))}return i}};var w=class extends y{static{a(this,"BusinessLogicRejectionCase")}condition(e,t){return this.isTraceMatch(e)&&this.isResponseMatch(e)&&t.originalStatus>=400&&t.replayStatus>=400}assign(e){try{let t=this.resolveStatus(e);if(this.condition(e,t)){let r=e.log.trace?.find(o=>o.parentId===null);return{type:"Business Logic Rejection Case (logic_suspicious)",message:"Response indicates error, but execution original and replay result match expected behavior",possibleCauses:["Business rule might not align with actual execution flow","Or validation logic is too strict / misaligned"],evidence:{traceMatch:this.getMessageEdvidence("trace_match"),responseMatch:this.getMessageEdvidence("response_match"),originalStatus:this.getStatusEdvidence(t.originalStatus),finalResponse:typeof r?.returnData=="object"?JSON.stringify(r.returnData,null,2):r?.returnData},confidence:{signals:{trace_match:this.signalSource.trace_step_match(.3),response_match:this.signalSource.response_match(.3),logic_error_indicator:this.signalSource.logic_error_indicator(.2)},result:0},finalMessage:["This is NOT a runtime bug","This is likely a business logic issue"],references:e.log.stack}}}catch(t){throw t}}};var P=class extends y{static{a(this,"PostTraceResponseMutationCase")}assign(e){try{let t=this.resolveStatus(e);if(this.isTraceStepMatch(e)&&!this.isResponseMatch(e)&&this.isTraceReturnDataMatch(e))return{type:"Response Mismatch Case (post_processing_suspicious)",message:"Execution flow is identical, but response output differs",possibleCauses:["Post-processing logic may be inconsistent","Response mapping or transformation may be incorrect","Data changes may affect the final result.","Non-deterministic behavior (e.g. random, time-based, shared state)"],evidence:{traceMatch:this.getMessageEdvidence("trace_match"),responseMatch:this.getMessageEdvidence("response_not_match"),originalStatus:this.getStatusEdvidence(t.originalStatus),responseDiff:this.getResponseDiffSection(e)},confidence:{signals:{trace_step_match:this.signalSource.trace_step_match(.3),response_mismatch:this.signalSource.response_not_match(.2),trace_return_data_match:this.signalSource.trace_return_data_match(.3)},result:0},finalMessage:["Execution logic is stable, but output is inconsistent","This may indicate issues in response transformation or side effects","This may occur after the business logic is execute complete."],references:e.log.stack}}catch(t){throw t}}};var T=class extends y{static{a(this,"TraceDivergenceCase")}assign(e){try{let t=this.resolveStatus(e);if(!this.isTraceStepMatch(e)&&!this.isResponseMatch(e)&&!this.isTraceReturnDataMatch(e)&&!this.isResponseStatusMatch(e))return{type:"Trace Divergence Case (execution_path_mismatch)",message:"Execution path diverged between original and replay",possibleCauses:["Conditional branch logic may behave differently","Environment or shared state may affect execution flow","Request context may not be deterministic","Replay execution may enter different logic branches","Hidden dependencies or side effects may exist"],evidence:{traceMatch:this.getMessageEdvidence("trace_not_match"),originalStatus:this.getStatusEdvidence(t.originalStatus),traceDivergence:this.getTraceDivergenceSection(e),responseDiff:this.getResponseDiffSection(e)},confidence:{signals:{trace_step_not_match:this.signalSource.trace_step_not_match(.45),trace_return_data_not_match:this.signalSource.trace_return_data_not_match(.25),response_not_match:this.signalSource.response_not_match(.15),response_status_not_match:this.signalSource.response_status_not_match(.1)},result:0},finalMessage:["Replay execution diverged from the original execution flow","This may indicate unstable conditions or branch inconsistency","Root cause likely exists before response generation"],references:e.log.stack}}catch(t){throw t}}};var b=class{static{a(this,"ReasonAssigner")}get case(){return{business_logic_rejection:new w,post_trace_response_mutation:new P,trace_divergence:new T}}};import g from"chalk";var C=class{static{a(this,"ReasonPrinter")}get reasonSignal(){return new D}title(e){console.log(g.yellowBright("** Reason Title:")),console.log(`[!] ${e}`)}description(e){console.log(g.yellowBright("** Description:")),console.log(e)}possibleCauses(e){console.log(g.yellowBright("** What I think happened:")),e.forEach(t=>{console.log(` \u2192 ${t}`)})}evidence(e){let t=Object.keys(e);console.log(g.yellowBright("** Evidence I saw:")),t.forEach(r=>{console.log(` \u2192 ${r}: ${e[r]}`)})}confidence(e){console.log(g.yellowBright("** Confidence Reason (why I think this): ")),e.signals&&Object.keys(e.signals).forEach(n=>{console.log(` \u2192 ${e.signals[n].message}`)}),e.result=this.reasonSignal.sumSignalWeights(e.signals);let t=Math.round(e.result*100);console.log(`
|
|
15
|
+
`),console.log(g.yellowBright("** Confidence Result: ")),console.log(g.green.italic.bold(` * score: ${e.result.toFixed(2)} / 1 `)),console.log(g.green.italic.bold(` * percent: ${t} / 100 (%) `))}finalMessage(e){e.length!=0&&(console.log(g.yellowBright("** Final Call:")),e.forEach(t=>{console.log(` \u2192 ${t}`)}))}referencePosition(e){if(e&&(console.log(g.yellowBright("* Reference Position: ")),console.log(" \u2192 Suspected position:",g.red.underline(e.primary?.full_path)),e.context&&e.context.length>0)){let t=e.context.length-1;e.context.forEach((r,n)=>{console.log(` \u2192 (Context ${t-n}): ${r.full_path}`)})}}printReason(e){try{if(!e)return;console.log(g.red.italic.bold(`
|
|
16
|
+
Aeeaeae yohh BUT...`)),this.title(e.type),console.log(`
|
|
17
|
+
`),this.description(e.message),console.log(`
|
|
18
|
+
`),this.possibleCauses(e.possibleCauses),console.log(`
|
|
19
|
+
`),this.evidence(e.evidence),console.log(`
|
|
20
|
+
`),this.confidence(e.confidence),console.log(`
|
|
21
|
+
`),this.finalMessage(e.finalMessage||[]),this.referencePosition(e.references)}catch(t){throw t}}};var F=class extends x{constructor(t){super(t);this.config=t}config;static{a(this,"AdvanceReplay")}get reasonPrinter(){return new C}get reasonAssigner(){return new b}printResponseDiff(t){if(t.isDifferent){console.log(d.red("[!] Response DIFF"));for(let r of t.issues)console.log(` - [${r.type}] ${r.message}`)}else console.log(d.green("[OK] Response MATCH"))}printTraceDiff(t){if(t.isDifferent){console.log(d.red("[!] Trace DIFF"));for(let r of t.issues)console.log(` - [${r.type}] ${r.name}`)}else console.log(d.green("[OK] Trace MATCH"))}printRootCauseIssue(t){if(t.length>0){let r=["performance_issue","performance_warning","performance_regression"];if(!t.every(o=>r.includes(o.type))){console.log(d.red("\u26A0 Root Cause Analysis"));for(let o of t)console.log(` - [${o.type}] ${o.message}`)}}else console.log(d.green("[OK] No root cause issues detected"))}printPerformanceIssue(t){let r=t.filter(n=>n.type==="performance_regression");if(r.length>0){console.log(d.yellow(`
|
|
22
|
+
\u26A0 Performance Regression Detected`));for(let n of r)console.log(`- ${n.step}: ${n.message}`)}}print(t){try{let{log:r,responseDiff:n,traceDiff:o,analysis:l}=t;console.log(d.bgYellowBright.bold(` \u25B6 ${r.request.method} ${r.request.url} `)),this.printResponseDiff(n),this.printTraceDiff(o),this.printRootCauseIssue(l),this.printPerformanceIssue(l),this.printReason(t)}catch(r){throw r}}printReason(t){try{let r=this.reasonAssigner.case.business_logic_rejection.assign(t);this.reasonPrinter.printReason(r);let n=this.reasonAssigner.case.post_trace_response_mutation.assign(t);this.reasonPrinter.printReason(n);let o=this.reasonAssigner.case.trace_divergence.assign(t);this.reasonPrinter.printReason(o)}catch(r){throw r}}analyzeRootCause(t){try{let{responseDiff:r,traceDiff:n,logTrace:o,replayData:l}=t,c=[],i=this.config.filters;r.isDifferent&&n.isDifferent&&c.push({type:"flow_break",message:"Response mismatch caused by trace difference"});let p=i?.expectedPerformance;if(!p)return c;for(let f of o){let h=l?.trace?.find(B=>B.name===f.name);if(!h)continue;let S=(h.duration_ms||0)-(f.duration_ms||0),I=Math.max(f.duration_ms||1,20),N=S/I*100,k=f.name.split("."),E=f.name;k.length==2?E=k[1]:E=k[0];let _=p.steps?.[E]??0;if(_===0)continue;let A=_/2;S>_?c.push({type:"performance_regression",step:f.name,severity:"high",message:`Slow step: +${S}ms > ${_}ms (+${N.toFixed(1)}%)`}):S>A&&c.push({type:"performance_warning",step:f.name,severity:"low",message:`Slight delay: +${S}ms`})}return c}catch(r){throw r}}async getTraceResult(t,r){try{let n=K(t.trace||[]),o=K(r.trace||[]),l=await this.filterManager.filterTrace(n),c=await this.filterManager.filterTrace(o),i=this.replayHelper.compareTrace(l,c);return{logTraceFiltered:l,replayTraceFiltered:c,traceDiff:i}}catch(n){throw n}}async getResponseResult(t,r,n){try{let o=await this.filterManager.filterResponse({error:JSON.parse(t.response.error),status:t.response.status}),l=await this.filterManager.filterResponse({error:r,status:n.status});return{responseDiff:this.replayHelper.compareResponse(o,l)}}catch(o){throw o}}async replay(t){try{let r=await this.replayHelper.sendRequest(t),n=await r.json(),o=n.__replay;delete n.__replay;let l=await this.getResponseResult(t,n,r),c=await this.getTraceResult(t,o),i=this.analyzeRootCause({replayData:o,traceDiff:c.traceDiff,logTrace:c.logTraceFiltered,responseDiff:l.responseDiff});r.status<=400&&i.length==0?this.print({log:t,replayResultStatus:r.status,analysis:[],traceDiff:{isDifferent:!1,issues:[]},responseDiff:{isDifferent:!1,issues:[]}}):this.print({log:t,replayResultStatus:r.status,analysis:i,traceDiff:c.traceDiff,responseDiff:l.responseDiff})}catch(r){throw r}}};export{F as AdvanceReplay};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";var V=Object.create;var x=Object.defineProperty;var Y=Object.getOwnPropertyDescriptor;var Q=Object.getOwnPropertyNames;var X=Object.getPrototypeOf,Z=Object.prototype.hasOwnProperty;var a=(s,e)=>x(s,"name",{value:e,configurable:!0});var ee=(s,e)=>{for(var t in e)x(s,t,{get:e[t],enumerable:!0})},B=(s,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of Q(e))!Z.call(s,n)&&n!==t&&x(s,n,{get:()=>e[n],enumerable:!(r=Y(e,n))||r.enumerable});return s};var m=(s,e,t)=>(t=s!=null?V(X(s)):{},B(e||!s||!s.__esModule?x(t,"default",{value:s,enumerable:!0}):t,s)),te=s=>B(x({},"__esModule",{value:!0}),s);var pe={};ee(pe,{AdvanceReplay:()=>N,SmartReplay:()=>F});module.exports=te(pe);var w=m(require("chalk"),1);var ie=require("ulid"),A=require("async_hooks");var re=m(require("fs"),1),se=m(require("chalk"),1),ne=m(require("path"),1),ae=require("bundle-require");var Se=new A.AsyncLocalStorage;var q=m(require("crypto"),1);function H(s){try{return q.default.createHash("md5").update(s).digest("hex")}catch(e){throw e}}a(H,"cryptoHash");var O="__root__";function ce(s){let e=new Map;for(let t of s){let r=t.parentId||O;e.has(r)||e.set(r,[]),e.get(r).push(t)}return e}a(ce,"buildTraceTree");function le(s,e,t){return`${t}->${s.name}#${e}`}a(le,"buildSignature");function S(s){try{let n=function(o,l){(t.get(o)||[]).sort((c,p)=>c.start-p.start).forEach((c,p)=>{let f=le(c,p,l),d=H(f);r.push({...c,signature:d,rawSignature:f}),n(c.id,d)})};var e=n;a(n,"walk");let t=ce(s),r=[];return n(O,O),r}catch(t){throw t}}a(S,"flattenTrace");var _=class{constructor(e){this.config=e}config;static{a(this,"ReplayFilterManager")}matchPattern(e,t){try{return e instanceof RegExp?e.test(t):e.includes("*")?new RegExp("^"+e.replace(/\*/g,".*")+"$").test(t):e===t}catch(r){throw r}}async filterTrace(e){try{if(!this.config.filters||!e||e.length===0)return e;let t=this.config.filters;return e.filter(r=>{let n=r.name;return!t.ignoreSteps?.some(l=>this.matchPattern(l,n))})}catch(t){throw t}}async filterNonOptionalTrace(e){try{if(!this.config.filters||!e||e.length===0)return e;let t=this.config.filters;return e.filter(r=>{let n=r.name;return!t.optionalSteps?.some(l=>this.matchPattern(l,n))})}catch(t){throw t}}isOptionalStep(e){try{return this.config.filters?.optionalSteps?.some(t=>this.matchPattern(t,e))}catch(t){throw t}}async filterResponse(e){try{if(!this.config.filters||!e)return e;let t=Object.keys(e.error);if(t.length===0)return e;let r=this.config.filters;for(let n of t)r.ignoreFields?.includes(n)&&delete e.error[n];return{...e,error:e.error}}catch(t){throw t}}};var at=require("dotenv/config.js");var T=class{constructor(e){this.config=e}config;static{a(this,"ReplayHelper")}get filterManager(){return new _(this.config)}setConfig(e){this.config=e}normalize(e){if(!e)return e;if(typeof e=="string")try{return JSON.parse(e)}catch{return e}return e}stableStringify(e){return JSON.stringify(this.sortKeys(e))}sortKeys(e){return Array.isArray(e)?e.map(t=>this.sortKeys(t)):e&&typeof e=="object"?Object.keys(e).sort().reduce((t,r)=>(t[r]=this.sortKeys(e[r]),t),{}):e}compareTrace(e,t){try{let r=[],n=new Map(e.map(i=>[i.signature,i])),o=new Map(t.map(i=>[i.signature,i])),l={};for(let[i,c]of n)l[c.name]={id:c.id,parentId:c.parentId,original:c.returnData,replay:null},o.has(c.signature)||this.filterManager.isOptionalStep(c.name)||r.push({type:"missing_step",name:c.name,message:`Missing step: ${i}`});for(let[i,c]of o)l[c.name].replay=c.returnData,n.has(c.signature)||i&&this.filterManager.isOptionalStep(c.name)||r.push({type:"extra_step",name:c.name,message:`Extra step: ${i}`});for(let i in l){let c=l[i].original,p=l[i].replay;c!==p&&r.push({type:"trace_return_data_mismatch",name:i,message:"Trace return data mismatch",not_matched:{original:c,replay:p}})}return{isDifferent:r.length>0,issues:r}}catch(r){throw r}}compareResponse(e,t){try{let r=[];e.status!==t.status&&r.push({type:"status_mismatch",message:"Status code mismatch",not_matched:{original:e.status,replay:t.status}});let n=this.normalize(e.error),o=this.normalize(t.error),l=this.stableStringify(n),i=this.stableStringify(o);return l!==i&&r.push({type:"body_mismatch",message:"Response mismatch",not_matched:{original:n,replay:o}}),{isDifferent:r.length>0,issues:r}}catch(r){throw r}}fullUrl(e){return`${process.env.SERVER_URL}${e}`}async sendRequest(e){try{return await fetch(this.fullUrl(e.request.url),{method:e.request.method,headers:{"Content-Type":"application/json","x-is-replay":"true"},body:JSON.stringify(e.request.body)})}catch(t){throw t}}};var v=class{constructor(e){this.config=e}config;static{a(this,"BaseReplay")}get filterManager(){return new _(this.config)}get replayHelper(){return new T(this.config)}};var F=class extends v{constructor(t){super(t);this.config=t}config;static{a(this,"SmartReplay")}print(t){try{let{log:r,replay:n,responseDiff:o,traceDiff:l}=t;if(console.log(w.default.yellow.bold(`\u25B6 ${r.request.method} ${r.request.url}`)),!o.isDifferent&&!l.isDifferent){console.log(w.default.green(`[OK] Reponse & Trace match
|
|
2
|
+
`));return}if(o.isDifferent&&console.log(w.default.red(`[!] Response DIFF
|
|
3
|
+
`)),l.isDifferent){console.log(w.default.red(`[!] Trace DIFF
|
|
4
|
+
`));for(let i of l.issues)console.log(` - [${i.type}] ${i.name}`)}}catch(r){throw r}}async replay(t){try{t.request.headers["x-replay-id"]=t.meta.id;let r=await this.replayHelper.sendRequest(t),n=await r.json(),o=n.__replay;delete n.__replay;let l=this.replayHelper.compareResponse({error:t.response.error,status:t.response.status},{error:n,status:r.status}),i=S(t.trace||[]),c=S(o.trace||[]),p=this.replayHelper.compareTrace(i,c);this.print({log:t,replay:r,responseDiff:l,traceDiff:p})}catch(r){throw r}}};var y=m(require("chalk"),1);var j=m(require("http"),1);var I={trace_step_match:a((s=.1)=>({weight:s,serverity:h(s),message:`trace_match (+${s}) \u2192 trace fully matches replay`}),"trace_step_match"),trace_step_not_match:a((s=.25)=>({weight:s,serverity:h(s),message:`trace_step_not_match (+${s}) \u2192 trace partially matches replay`}),"trace_step_not_match"),trace_return_data_match:a((s=.1)=>({weight:s,serverity:h(s),message:`trace_return_data_match (+${s}) \u2192 trace return data is consistent`}),"trace_return_data_match"),trace_return_data_not_match:a((s=.25)=>({weight:s,serverity:h(s),message:`trace_return_data_not_match (+${s}) \u2192 trace return data is inconsistent`}),"trace_return_data_not_match"),response_match:a((s=.1)=>({weight:s,serverity:h(s),message:`response_match (+${s}) \u2192 response is consistent`}),"response_match"),response_not_match:a((s=.25)=>({weight:s,serverity:h(s),message:`response_not_match (+${s}) \u2192 response is inconsistent`}),"response_not_match"),response_status_match:a((s=.1)=>({weight:s,serverity:h(s),message:`response_status_match (+${s}) \u2192 response status is consistent`}),"response_status_match"),response_status_not_match:a((s=.25)=>({weight:s,serverity:h(s),message:`response_status_not_match (+${s}) \u2192 response status is inconsistent`}),"response_status_not_match"),logic_error_indicator:a((s=.6)=>({weight:s,serverity:h(s),message:`logic_error_indicator (+${s}) \u2192 original response status >= 400 triggered logic flag`}),"logic_error_indicator")},J={trace_match:{value:!0,message:"flow is clean"},trace_not_match:{value:!1,message:"flow is not clean"},trace_step_match:{value:!0,message:"no mismatch"},trace_step_not_match:{value:!1,message:"mismatch"},trace_return_data_match:{value:!0,message:"no mismatch"},trace_return_data_not_match:{value:!1,message:"mismatch"},response_match:{value:!0,message:"no mismatch"},response_not_match:{value:!1,message:"mismatch"}};function h(s){return s>.75?"high":s>.55?"medium":"low"}a(h,"getSignalLevel");var b=class{static{a(this,"ReasonSignalCls")}findSignalByType(e){try{return I[e]}catch(t){throw t}}sumSignalWeights(e){try{return Object.values(e).reduce((t,r)=>t+r.weight,0)}catch(t){throw t}}};var u=m(require("chalk"),1);var R=class{static{a(this,"BaseAssignerCase")}get evidenceSource(){return J}get signalSource(){return I}getTraceDivergenceSection(e){let t=e.traceDiff.issues;if(t.length===0)return"No divergence";let r=`
|
|
5
|
+
`;for(let n of t)n.type==="missing_step"&&(r+=u.default.yellow(`
|
|
6
|
+
* ${n.name}(missing_step):
|
|
7
|
+
`),r+=u.default.green(` \u2192 original: exists
|
|
8
|
+
`),r+=u.default.red(" \u2192 replay: missing"),r+=`
|
|
9
|
+
`),n.type==="extra_step"&&(r+=u.default.yellow(`
|
|
10
|
+
* ${n.name}(extra_step):
|
|
11
|
+
`),r+=u.default.green(` \u2192 original: none
|
|
12
|
+
`),r+=u.default.red(" \u2192 replay: exists"),r+=`
|
|
13
|
+
`);return r.trim()}getMessageEdvidence(e){return`${this.evidenceSource[e].value} (${this.evidenceSource[e].message})`}getStatusEdvidence(e){let t=j.default.STATUS_CODES[e]||"Unknown";return`${e} (${t})`}isTraceMatch(e){return!e.traceDiff.isDifferent}isTraceStepMatch(e){return e.traceDiff.issues.length>0?!e.traceDiff.issues.some(t=>t.type==="missing_step"||t.type==="extra_step"):!0}isTraceReturnDataMatch(e){return e.traceDiff.issues.length>0?!e.traceDiff.issues.some(t=>t.type==="trace_return_data_mismatch"):!0}isResponseMatch(e){return!e.responseDiff.isDifferent}isResponseStatusMatch(e){let{originalStatus:t,replayStatus:r}=this.resolveStatus(e);return t===r}resolveStatus(e){return{originalStatus:Number(e.log.response.status),replayStatus:e.replayResultStatus}}getResponseDiffSection(e){let t=e.responseDiff.issues;if(t.length===0)return"No diff";let r=t.length>1?1:0,n=e.responseDiff.issues[r].not_matched;if(!n)return"No diff";let o=n.original||{},l=n.replay||{},i=new Set([...Object.keys(o),...Object.keys(l)]),c=`
|
|
14
|
+
`;for(let p of i){let f=o[p],d=l[p];f!==d&&(c+=u.default.yellow(` * ${p}:
|
|
15
|
+
`),c+=u.default.green(` \u2192 original: ${JSON.stringify(f)}
|
|
16
|
+
`),c+=u.default.red(` \u2192 replay: ${JSON.stringify(d)}
|
|
17
|
+
`))}return c}};var C=class extends R{static{a(this,"BusinessLogicRejectionCase")}condition(e,t){return this.isTraceMatch(e)&&this.isResponseMatch(e)&&t.originalStatus>=400&&t.replayStatus>=400}assign(e){try{let t=this.resolveStatus(e);if(this.condition(e,t)){let r=e.log.trace?.find(o=>o.parentId===null);return{type:"Business Logic Rejection Case (logic_suspicious)",message:"Response indicates error, but execution original and replay result match expected behavior",possibleCauses:["Business rule might not align with actual execution flow","Or validation logic is too strict / misaligned"],evidence:{traceMatch:this.getMessageEdvidence("trace_match"),responseMatch:this.getMessageEdvidence("response_match"),originalStatus:this.getStatusEdvidence(t.originalStatus),finalResponse:typeof r?.returnData=="object"?JSON.stringify(r.returnData,null,2):r?.returnData},confidence:{signals:{trace_match:this.signalSource.trace_step_match(.3),response_match:this.signalSource.response_match(.3),logic_error_indicator:this.signalSource.logic_error_indicator(.2)},result:0},finalMessage:["This is NOT a runtime bug","This is likely a business logic issue"],references:e.log.stack}}}catch(t){throw t}}};var k=class extends R{static{a(this,"PostTraceResponseMutationCase")}assign(e){try{let t=this.resolveStatus(e);if(this.isTraceStepMatch(e)&&!this.isResponseMatch(e)&&this.isTraceReturnDataMatch(e))return{type:"Response Mismatch Case (post_processing_suspicious)",message:"Execution flow is identical, but response output differs",possibleCauses:["Post-processing logic may be inconsistent","Response mapping or transformation may be incorrect","Data changes may affect the final result.","Non-deterministic behavior (e.g. random, time-based, shared state)"],evidence:{traceMatch:this.getMessageEdvidence("trace_match"),responseMatch:this.getMessageEdvidence("response_not_match"),originalStatus:this.getStatusEdvidence(t.originalStatus),responseDiff:this.getResponseDiffSection(e)},confidence:{signals:{trace_step_match:this.signalSource.trace_step_match(.3),response_mismatch:this.signalSource.response_not_match(.2),trace_return_data_match:this.signalSource.trace_return_data_match(.3)},result:0},finalMessage:["Execution logic is stable, but output is inconsistent","This may indicate issues in response transformation or side effects","This may occur after the business logic is execute complete."],references:e.log.stack}}catch(t){throw t}}};var E=class extends R{static{a(this,"TraceDivergenceCase")}assign(e){try{let t=this.resolveStatus(e);if(!this.isTraceStepMatch(e)&&!this.isResponseMatch(e)&&!this.isTraceReturnDataMatch(e)&&!this.isResponseStatusMatch(e))return{type:"Trace Divergence Case (execution_path_mismatch)",message:"Execution path diverged between original and replay",possibleCauses:["Conditional branch logic may behave differently","Environment or shared state may affect execution flow","Request context may not be deterministic","Replay execution may enter different logic branches","Hidden dependencies or side effects may exist"],evidence:{traceMatch:this.getMessageEdvidence("trace_not_match"),originalStatus:this.getStatusEdvidence(t.originalStatus),traceDivergence:this.getTraceDivergenceSection(e),responseDiff:this.getResponseDiffSection(e)},confidence:{signals:{trace_step_not_match:this.signalSource.trace_step_not_match(.45),trace_return_data_not_match:this.signalSource.trace_return_data_not_match(.25),response_not_match:this.signalSource.response_not_match(.15),response_status_not_match:this.signalSource.response_status_not_match(.1)},result:0},finalMessage:["Replay execution diverged from the original execution flow","This may indicate unstable conditions or branch inconsistency","Root cause likely exists before response generation"],references:e.log.stack}}catch(t){throw t}}};var K=class{static{a(this,"ReasonAssigner")}get case(){return{business_logic_rejection:new C,post_trace_response_mutation:new k,trace_divergence:new E}}};var g=m(require("chalk"),1);var M=class{static{a(this,"ReasonPrinter")}get reasonSignal(){return new b}title(e){console.log(g.default.yellowBright("** Reason Title:")),console.log(`[!] ${e}`)}description(e){console.log(g.default.yellowBright("** Description:")),console.log(e)}possibleCauses(e){console.log(g.default.yellowBright("** What I think happened:")),e.forEach(t=>{console.log(` \u2192 ${t}`)})}evidence(e){let t=Object.keys(e);console.log(g.default.yellowBright("** Evidence I saw:")),t.forEach(r=>{console.log(` \u2192 ${r}: ${e[r]}`)})}confidence(e){console.log(g.default.yellowBright("** Confidence Reason (why I think this): ")),e.signals&&Object.keys(e.signals).forEach(n=>{console.log(` \u2192 ${e.signals[n].message}`)}),e.result=this.reasonSignal.sumSignalWeights(e.signals);let t=Math.round(e.result*100);console.log(`
|
|
18
|
+
`),console.log(g.default.yellowBright("** Confidence Result: ")),console.log(g.default.green.italic.bold(` * score: ${e.result.toFixed(2)} / 1 `)),console.log(g.default.green.italic.bold(` * percent: ${t} / 100 (%) `))}finalMessage(e){e.length!=0&&(console.log(g.default.yellowBright("** Final Call:")),e.forEach(t=>{console.log(` \u2192 ${t}`)}))}referencePosition(e){if(e&&(console.log(g.default.yellowBright("* Reference Position: ")),console.log(" \u2192 Suspected position:",g.default.red.underline(e.primary?.full_path)),e.context&&e.context.length>0)){let t=e.context.length-1;e.context.forEach((r,n)=>{console.log(` \u2192 (Context ${t-n}): ${r.full_path}`)})}}printReason(e){try{if(!e)return;console.log(g.default.red.italic.bold(`
|
|
19
|
+
Aeeaeae yohh BUT...`)),this.title(e.type),console.log(`
|
|
20
|
+
`),this.description(e.message),console.log(`
|
|
21
|
+
`),this.possibleCauses(e.possibleCauses),console.log(`
|
|
22
|
+
`),this.evidence(e.evidence),console.log(`
|
|
23
|
+
`),this.confidence(e.confidence),console.log(`
|
|
24
|
+
`),this.finalMessage(e.finalMessage||[]),this.referencePosition(e.references)}catch(t){throw t}}};var N=class extends v{constructor(t){super(t);this.config=t}config;static{a(this,"AdvanceReplay")}get reasonPrinter(){return new M}get reasonAssigner(){return new K}printResponseDiff(t){if(t.isDifferent){console.log(y.default.red("[!] Response DIFF"));for(let r of t.issues)console.log(` - [${r.type}] ${r.message}`)}else console.log(y.default.green("[OK] Response MATCH"))}printTraceDiff(t){if(t.isDifferent){console.log(y.default.red("[!] Trace DIFF"));for(let r of t.issues)console.log(` - [${r.type}] ${r.name}`)}else console.log(y.default.green("[OK] Trace MATCH"))}printRootCauseIssue(t){if(t.length>0){let r=["performance_issue","performance_warning","performance_regression"];if(!t.every(o=>r.includes(o.type))){console.log(y.default.red("\u26A0 Root Cause Analysis"));for(let o of t)console.log(` - [${o.type}] ${o.message}`)}}else console.log(y.default.green("[OK] No root cause issues detected"))}printPerformanceIssue(t){let r=t.filter(n=>n.type==="performance_regression");if(r.length>0){console.log(y.default.yellow(`
|
|
25
|
+
\u26A0 Performance Regression Detected`));for(let n of r)console.log(`- ${n.step}: ${n.message}`)}}print(t){try{let{log:r,responseDiff:n,traceDiff:o,analysis:l}=t;console.log(y.default.bgYellowBright.bold(` \u25B6 ${r.request.method} ${r.request.url} `)),this.printResponseDiff(n),this.printTraceDiff(o),this.printRootCauseIssue(l),this.printPerformanceIssue(l),this.printReason(t)}catch(r){throw r}}printReason(t){try{let r=this.reasonAssigner.case.business_logic_rejection.assign(t);this.reasonPrinter.printReason(r);let n=this.reasonAssigner.case.post_trace_response_mutation.assign(t);this.reasonPrinter.printReason(n);let o=this.reasonAssigner.case.trace_divergence.assign(t);this.reasonPrinter.printReason(o)}catch(r){throw r}}analyzeRootCause(t){try{let{responseDiff:r,traceDiff:n,logTrace:o,replayData:l}=t,i=[],c=this.config.filters;r.isDifferent&&n.isDifferent&&i.push({type:"flow_break",message:"Response mismatch caused by trace difference"});let p=c?.expectedPerformance;if(!p)return i;for(let f of o){let d=l?.trace?.find(G=>G.name===f.name);if(!d)continue;let D=(d.duration_ms||0)-(f.duration_ms||0),z=Math.max(f.duration_ms||1,20),U=D/z*100,L=f.name.split("."),$=f.name;L.length==2?$=L[1]:$=L[0];let P=p.steps?.[$]??0;if(P===0)continue;let W=P/2;D>P?i.push({type:"performance_regression",step:f.name,severity:"high",message:`Slow step: +${D}ms > ${P}ms (+${U.toFixed(1)}%)`}):D>W&&i.push({type:"performance_warning",step:f.name,severity:"low",message:`Slight delay: +${D}ms`})}return i}catch(r){throw r}}async getTraceResult(t,r){try{let n=S(t.trace||[]),o=S(r.trace||[]),l=await this.filterManager.filterTrace(n),i=await this.filterManager.filterTrace(o),c=this.replayHelper.compareTrace(l,i);return{logTraceFiltered:l,replayTraceFiltered:i,traceDiff:c}}catch(n){throw n}}async getResponseResult(t,r,n){try{let o=await this.filterManager.filterResponse({error:JSON.parse(t.response.error),status:t.response.status}),l=await this.filterManager.filterResponse({error:r,status:n.status});return{responseDiff:this.replayHelper.compareResponse(o,l)}}catch(o){throw o}}async replay(t){try{let r=await this.replayHelper.sendRequest(t),n=await r.json(),o=n.__replay;delete n.__replay;let l=await this.getResponseResult(t,n,r),i=await this.getTraceResult(t,o),c=this.analyzeRootCause({replayData:o,traceDiff:i.traceDiff,logTrace:i.logTraceFiltered,responseDiff:l.responseDiff});r.status<=400&&c.length==0?this.print({log:t,replayResultStatus:r.status,analysis:[],traceDiff:{isDifferent:!1,issues:[]},responseDiff:{isDifferent:!1,issues:[]}}):this.print({log:t,replayResultStatus:r.status,analysis:c,traceDiff:i.traceDiff,responseDiff:l.responseDiff})}catch(r){throw r}}};0&&(module.exports={AdvanceReplay,SmartReplay});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { SmartReplay } from './smart.replay.cjs';
|
|
2
|
+
export { AdvanceReplay, PrintParams, RootCauseParams, RootCauseReason } from './advance/replay.cjs';
|
|
3
|
+
import '../../error_handle.helper-CQsPSbuz.cjs';
|
|
4
|
+
import 'async_hooks';
|
|
5
|
+
import '../../setup.cjs';
|
|
6
|
+
import '../../index-MBKv_hsI.cjs';
|
|
7
|
+
import '../../enum/log_level.enum.cjs';
|
|
8
|
+
import '../base.cjs';
|
|
9
|
+
import '../../trace/filter.cjs';
|
|
10
|
+
import '../helper.cjs';
|
|
11
|
+
import '../handler.cjs';
|
|
12
|
+
import './advance/reasons/reason_signal.cjs';
|