Skip to content

Commit bf931e0

Browse files
authored
fix: prompt for mock before policy Dry-Run
The policies-list "Dry Run" action unconditionally enabled mock external services, which pre-records a PublishSchema message per schema and made the transition to Dry-Run take 5-10 minutes. Open the same Enable Mock confirmation dialog used by the policy editor so mock is only activated when the user opts in. Also note in the dialog that enabling mock makes the Dry-Run transition slow. Signed-off-by: Alex Piatakov <alex.piatakov@swirldslabs.com>
1 parent d616dd7 commit bf931e0

2 files changed

Lines changed: 64 additions & 41 deletions

File tree

frontend/src/app/modules/policy-engine/policies/policies.component.ts

Lines changed: 62 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -938,50 +938,72 @@ export class PoliciesComponent implements OnInit {
938938
}
939939

940940
private dryRun(element: any) {
941-
this.loading = true;
942-
this.policyEngineService
943-
.dryRun(element.id, {
944-
enableMock: true
945-
})
946-
.pipe(takeUntil(this._destroy$))
947-
.subscribe(
948-
(data: any) => {
949-
const { policies, isValid, errors } = data;
950-
if (!isValid) {
951-
let text = [];
952-
const blocks = errors.blocks;
953-
const invalidBlocks = blocks.filter(
954-
(block: any) => !block.isValid
955-
);
956-
for (let i = 0; i < invalidBlocks.length; i++) {
957-
const block = invalidBlocks[i];
958-
for (let j = 0; j < block.errors.length; j++) {
959-
const error = block.errors[j];
960-
if (block.id) {
961-
text.push(`<div>${block.id}: ${error}</div>`);
962-
} else {
963-
text.push(`<div>${error}</div>`);
941+
const dialogRef = this.dialogService.open(CustomConfirmDialogComponent, {
942+
showHeader: false,
943+
width: '640px',
944+
styleClass: 'guardian-dialog',
945+
data: {
946+
header: 'Enable Mock',
947+
texts: [
948+
`Mock Data intercepts all external service calls (IPFS, Topics, Tokens, and API requests) and returns pre-configured test responses instead of making real network calls. This lets you run and test your policy in a fully self-contained offline environment.`,
949+
`You can change this setting and configure individual blocks at any time from the 'Mock Config' panel.`,
950+
`Note: enabling Mock pre-records responses for every schema in the policy, so moving to Dry-Run may take several minutes.`
951+
],
952+
buttons: [{
953+
name: 'Disable',
954+
class: 'secondary'
955+
}, {
956+
name: 'Enable',
957+
class: 'primary'
958+
}]
959+
},
960+
});
961+
dialogRef.onClose.pipe(takeUntil(this._destroy$)).subscribe((result: string) => {
962+
this.loading = true;
963+
this.policyEngineService
964+
.dryRun(element.id, {
965+
enableMock: result === 'Enable'
966+
})
967+
.pipe(takeUntil(this._destroy$))
968+
.subscribe(
969+
(data: any) => {
970+
const { policies, isValid, errors } = data;
971+
if (!isValid) {
972+
let text = [];
973+
const blocks = errors.blocks;
974+
const invalidBlocks = blocks.filter(
975+
(block: any) => !block.isValid
976+
);
977+
for (let i = 0; i < invalidBlocks.length; i++) {
978+
const block = invalidBlocks[i];
979+
for (let j = 0; j < block.errors.length; j++) {
980+
const error = block.errors[j];
981+
if (block.id) {
982+
text.push(`<div>${block.id}: ${error}</div>`);
983+
} else {
984+
text.push(`<div>${error}</div>`);
985+
}
964986
}
965987
}
988+
this.informService.errorMessage(
989+
text.join(''),
990+
'The policy is invalid'
991+
);
992+
this._configurationErrors.set(element.id, errors);
993+
this.router.navigate(['policy-configuration'], {
994+
queryParams: {
995+
policyId: element.id,
996+
},
997+
replaceUrl: true,
998+
});
966999
}
967-
this.informService.errorMessage(
968-
text.join(''),
969-
'The policy is invalid'
970-
);
971-
this._configurationErrors.set(element.id, errors);
972-
this.router.navigate(['policy-configuration'], {
973-
queryParams: {
974-
policyId: element.id,
975-
},
976-
replaceUrl: true,
977-
});
1000+
this.loadAllPolicy();
1001+
},
1002+
(e) => {
1003+
this.loading = false;
9781004
}
979-
this.loadAllPolicy();
980-
},
981-
(e) => {
982-
this.loading = false;
983-
}
984-
);
1005+
);
1006+
});
9851007
}
9861008

9871009
private draft(element: any) {

frontend/src/app/modules/policy-engine/policy-configuration/policy-configuration/policy-configuration.component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1235,7 +1235,8 @@ export class PolicyConfigurationComponent implements OnInit {
12351235
header: 'Enable Mock',
12361236
texts: [
12371237
`Mock Data intercepts all external service calls (IPFS, Topics, Tokens, and API requests) and returns pre-configured test responses instead of making real network calls. This lets you run and test your policy in a fully self-contained offline environment.`,
1238-
`You can change this setting and configure individual blocks at any time from the 'Mock Config' panel.`
1238+
`You can change this setting and configure individual blocks at any time from the 'Mock Config' panel.`,
1239+
`Note: enabling Mock pre-records responses for every schema in the policy, so moving to Dry-Run may take several minutes.`
12391240
],
12401241
buttons: [{
12411242
name: 'Disable',

0 commit comments

Comments
 (0)