test(chess/modifiers): add depth-3 composition and depth-4 rejection tests
This commit is contained in:
parent
a8f0881e53
commit
ec61432ec0
1 changed files with 117 additions and 0 deletions
|
|
@ -144,6 +144,10 @@ describe("validateCustomDescriptor", () => {
|
|||
});
|
||||
|
||||
it("enforces max nesting depth of 3 container levels", () => {
|
||||
// Level 1: on-turn-start
|
||||
// Level 2: conditional
|
||||
// Level 3: on-capture
|
||||
// Level 4: on-damaged (Exceeds max depth of 3)
|
||||
const deeplyNested = {
|
||||
kind: "on-turn-start",
|
||||
params: {
|
||||
|
|
@ -192,6 +196,119 @@ describe("validateCustomDescriptor", () => {
|
|||
}
|
||||
});
|
||||
|
||||
it("accepts depth-3 composition (exactly 3 levels)", () => {
|
||||
// Level 1: conditional
|
||||
// Level 2: on-move
|
||||
// Level 3: add-to-attribute (Not a container, so depth is 3)
|
||||
const depth3Valid = {
|
||||
kind: "conditional",
|
||||
params: {
|
||||
condition: { type: "always" },
|
||||
then: [
|
||||
{
|
||||
kind: "on-move",
|
||||
params: {
|
||||
primitives: [
|
||||
{
|
||||
kind: "add-to-attribute",
|
||||
params: { attr: "HpBonus", delta: 1 },
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
const descriptor = makeDescriptor();
|
||||
Object.defineProperty(descriptor, "primitives", {
|
||||
value: [depth3Valid],
|
||||
});
|
||||
|
||||
const result = validateCustomDescriptor(descriptor);
|
||||
expect(result).toEqual({ ok: true });
|
||||
});
|
||||
|
||||
it("rejects depth-4 composition (exceeds max depth of 3)", () => {
|
||||
// Level 1: conditional
|
||||
// Level 2: on-move
|
||||
// Level 3: conditional
|
||||
// Level 4: on-capture (exceeds depth 3) -> the error triggers on the container definition
|
||||
const depth4Invalid = {
|
||||
kind: "conditional",
|
||||
params: {
|
||||
condition: { type: "always" },
|
||||
then: [
|
||||
{
|
||||
kind: "on-move",
|
||||
params: {
|
||||
primitives: [
|
||||
{
|
||||
kind: "conditional",
|
||||
params: {
|
||||
condition: { type: "always" },
|
||||
then: [
|
||||
{
|
||||
kind: "on-capture",
|
||||
params: { primitives: [] }
|
||||
},
|
||||
]
|
||||
}
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
const descriptor = makeDescriptor();
|
||||
Object.defineProperty(descriptor, "primitives", {
|
||||
value: [depth4Invalid],
|
||||
});
|
||||
|
||||
const result = validateCustomDescriptor(descriptor);
|
||||
expect(result.ok).toBe(false);
|
||||
if (!result.ok) {
|
||||
expect(result.errors.some((e) => e.code === "descriptor.primitives.depth.exceeded")).toBe(
|
||||
true,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
it("accepts mixed old/new kinds at depth 3", () => {
|
||||
// Level 1: on-captured (new kind)
|
||||
// Level 2: conditional (old kind)
|
||||
// Level 3: add-aura (old kind)
|
||||
const mixedDepth3Valid = {
|
||||
kind: "on-captured",
|
||||
params: {
|
||||
primitives: [
|
||||
{
|
||||
kind: "conditional",
|
||||
params: {
|
||||
condition: { type: "always" },
|
||||
then: [
|
||||
{
|
||||
kind: "add-aura",
|
||||
params: { radius: 1, targetAttr: "HpBonus", delta: 1 },
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
const descriptor = makeDescriptor();
|
||||
Object.defineProperty(descriptor, "primitives", {
|
||||
value: [mixedDepth3Valid],
|
||||
});
|
||||
|
||||
const result = validateCustomDescriptor(descriptor);
|
||||
expect(result).toEqual({ ok: true });
|
||||
});
|
||||
|
||||
it("enforces max primitive count of 50", () => {
|
||||
const descriptor = makeDescriptor();
|
||||
Object.defineProperty(descriptor, "primitives", {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue