Make configs readonly inside validators

This commit is contained in:
Cooldude2606 committed 2026-03-20 18:56:55 +00:00
1 parent 5d0985cafc
commit 93271730eb
2 files changed
+129 -26

No files matched your search

+46
View File
@@ -90,6 +90,29 @@ describe("lib/config/classes", function() {
}
},
},
"test.badValidator": {
type: "string",
optional: true,
dependsOn: ["test.base"],
validator(value, config) {
if (config.get("test.base") < 1) {
return;
}
if (value === "set") {
config.set("alpha.foo", "BAD");
} else if (value === "setProp") {
config.setProp("beta.bar", "baz", "BAD");
} else if (value === "stage") {
config.stage("alpha.foo", "BAD");
} else if (value === "stageProp") {
config.stageProp("beta.bar", "baz", "BAD");
} else if (value === "commitStaging") {
config.commitStaging();
} else if (value === "revertStaging") {
config.revertStaging();
}
},
},
};
}
@@ -1076,5 +1099,28 @@ describe("lib/config/classes", function() {
assert.equal(testInstance.get("alpha.foo"), null);
});
});
describe("is readonly in validators", function() {
for (const method of [
"set", "setProp", "stage", "stageProp", "commitStaging", "revertStaging",
]) {
it(`${method} should throw if called inside a validator`, function() {
const testInstance = new TestConfig("local");
assert.throws(
() => testInstance.set("test.badValidator", method),
/config is readonly and cannot have values changed/
);
});
it(`${method} should throw if called inside a dependent validator`, function() {
const testInstance = new TestConfig("local");
testInstance.set("test.base", 0);
testInstance.set("test.badValidator", method);
assert.throws(
() => testInstance.set("test.base", 1),
/config is readonly and cannot have values changed/
);
});
}
});
});
});