Skip to content

Commit

Permalink
Make a deep copy of the validator plan before we modify it to add par…
Browse files Browse the repository at this point in the history
…ameters. Without this, different criteria instances that referenced the same plan were overwriting each others parameters.
  • Loading branch information
thsparks committed Apr 12, 2024
1 parent 446b0f2 commit 7fa08be
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions teachertool/src/transforms/runEvaluateAsync.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { logError } from "../services/loggingService";
import { logDebug, logError } from "../services/loggingService";
import { runValidatorPlanAsync } from "../services/makecodeEditorService";
import { stateAndDispatch } from "../state";
import * as Actions from "../state/actions";
Expand Down Expand Up @@ -28,14 +28,17 @@ function generateValidatorPlan(
return undefined;
}

const plan = teacherTool.validatorPlans?.find(plan => plan.name === catalogCriteria.use);
if (!plan) {
const planTemplate = teacherTool.validatorPlans?.find(plan => plan.name === catalogCriteria.use);
if (!planTemplate) {
logError(ErrorCode.evalMissingPlan, "Attempting to evaluate criteria with unrecognized plan", {
plan: catalogCriteria.use,
});
return undefined;
}

// Create a copy we can modify without affecting other uses of this template.
const plan = pxt.Util.deepCopy(planTemplate);

// Fill in parameters.
for (const param of criteriaInstance.params ?? []) {
const catalogParam = catalogCriteria.params?.find(p => p.name === param.name);
Expand Down Expand Up @@ -109,6 +112,8 @@ export async function runEvaluateAsync(fromUserInteraction: boolean) {

const plan = generateValidatorPlan(criteriaInstance, fromUserInteraction);

logDebug(`${criteriaInstance.instanceId}: Generated Plan`, plan)

if (!plan) {
dispatch(Actions.clearEvalResult(criteriaInstance.instanceId));
return resolve(false);
Expand Down

0 comments on commit 7fa08be

Please sign in to comment.