fix: tighten auto-chain dispatch evidence
This commit is contained in:
@@ -197,28 +197,85 @@ function hasExplicitAutoChainNextAction(input) {
|
||||
return hasAnyNonEmptyString(input, EVIDENCE_FIELDS.autoChainNextAction);
|
||||
}
|
||||
|
||||
function hasAutoChainDispatchEvidence(input) {
|
||||
return EVIDENCE_FIELDS.autoChainDispatchEvidence.some((fieldPath) => {
|
||||
const value = getPathValue(input, fieldPath);
|
||||
if (hasNonEmptyString(value)) return true;
|
||||
if (Array.isArray(value)) return value.length > 0;
|
||||
if (value && typeof value === 'object') {
|
||||
if (typeof value.action === 'string' && value.action.trim().length > 0) return true;
|
||||
if (typeof value.concreteNextAction === 'string' && value.concreteNextAction.trim().length > 0) return true;
|
||||
if (typeof value.dispatched === 'boolean') return value.dispatched;
|
||||
return Object.keys(value).length > 0;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
function requiresAutoChainDispatchEvidence(input) {
|
||||
if (!hasExplicitAutoChainNextAction(input)) return false;
|
||||
function getExplicitAutoChainNextAction(input) {
|
||||
const nextAction = EVIDENCE_FIELDS.autoChainNextAction
|
||||
.map((fieldPath) => getPathValue(input, fieldPath))
|
||||
.find((value) => hasNonEmptyString(value));
|
||||
if (!hasNonEmptyString(nextAction)) return false;
|
||||
return /^([a-z]+_)+[a-z]+$/i.test(nextAction.trim());
|
||||
|
||||
return hasNonEmptyString(nextAction) ? nextAction.trim() : '';
|
||||
}
|
||||
|
||||
function isExecutableDispatchAction(action) {
|
||||
if (!hasNonEmptyString(action)) return false;
|
||||
return /^dispatch_[a-z0-9]+(?:_[a-z0-9]+)*$/i.test(action.trim());
|
||||
}
|
||||
|
||||
function getNormalizedDispatchAction(value) {
|
||||
if (!hasNonEmptyString(value)) return '';
|
||||
const normalized = value.trim();
|
||||
return isExecutableDispatchAction(normalized) ? normalized : '';
|
||||
}
|
||||
|
||||
function getAutoChainDispatchEvidenceMatch(input) {
|
||||
const nextAction = getExplicitAutoChainNextAction(input);
|
||||
if (!isExecutableDispatchAction(nextAction)) return { required: false, matched: false };
|
||||
|
||||
for (const fieldPath of EVIDENCE_FIELDS.autoChainDispatchEvidence) {
|
||||
const value = getPathValue(input, fieldPath);
|
||||
if (!value) continue;
|
||||
|
||||
if (hasNonEmptyString(value)) {
|
||||
const directMatch = getNormalizedDispatchAction(value);
|
||||
if (directMatch === nextAction) {
|
||||
return { required: true, matched: true };
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (typeof value !== 'object' || Array.isArray(value)) continue;
|
||||
|
||||
const candidates = [
|
||||
value.action,
|
||||
value.dispatchedAction,
|
||||
value.nextAction,
|
||||
value.autoChainNextAction,
|
||||
value.requiredNextAction,
|
||||
value.concreteNextAction,
|
||||
value.event,
|
||||
value.type,
|
||||
value.kind,
|
||||
value.dispatchType,
|
||||
value.dispatchAction,
|
||||
]
|
||||
.map((candidate) => getNormalizedDispatchAction(candidate))
|
||||
.filter(Boolean);
|
||||
|
||||
const declaresDispatch = [
|
||||
value.dispatched === true,
|
||||
value.wasDispatched === true,
|
||||
value.didDispatch === true,
|
||||
value.dispatchEvent === true,
|
||||
value.event === 'dispatch',
|
||||
value.type === 'dispatch',
|
||||
value.kind === 'dispatch',
|
||||
value.dispatchType === 'dispatch',
|
||||
].some(Boolean);
|
||||
|
||||
|
||||
if (declaresDispatch && candidates.includes(nextAction)) {
|
||||
return { required: true, matched: true };
|
||||
}
|
||||
}
|
||||
|
||||
return { required: true, matched: false };
|
||||
}
|
||||
|
||||
function hasAutoChainDispatchEvidence(input) {
|
||||
return getAutoChainDispatchEvidenceMatch(input).matched;
|
||||
}
|
||||
|
||||
function requiresAutoChainDispatchEvidence(input) {
|
||||
return getAutoChainDispatchEvidenceMatch(input).required;
|
||||
}
|
||||
|
||||
function hasProgressEvidence(input) {
|
||||
|
||||
Reference in New Issue
Block a user