Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion src/config/validation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,10 @@ describe("validateDefinitionPack", () => {

it("rejects extractedResourcePerBatch <= 0", () => {
const pack = minimalPack({
"recipe-1": minimalRecipe({ extractedResourcePerBatch: 0 }),
"recipe-1": minimalRecipe({
extractionResourceId: "iron-ore",
extractedResourcePerBatch: 0,
}),
});
expect(() => validateDefinitionPack(pack)).toThrow(/extractedResourcePerBatch.*positive/);
});
Expand All @@ -768,6 +771,46 @@ describe("validateDefinitionPack", () => {
expect(() => validateDefinitionPack(pack)).not.toThrow();
});

it("rejects extractionResourceId without extractedResourcePerBatch", () => {
const pack = minimalPack({
"recipe-1": minimalRecipe({
extractionResourceId: "iron-ore",
} as any),
});
const recipe = pack.recipes["recipe-1"];
if (recipe) {
delete (recipe as any).extractedResourcePerBatch;
}
expect(() => validateDefinitionPack(pack)).toThrow(
/extractionResourceId.*extractedResourcePerBatch.*both must be present together/,
);
});

it("rejects extractedResourcePerBatch without extractionResourceId", () => {
const pack = minimalPack({
"recipe-1": minimalRecipe({
extractedResourcePerBatch: 5,
} as any),
});
const recipe = pack.recipes["recipe-1"];
if (recipe) {
delete (recipe as any).extractionResourceId;
}
expect(() => validateDefinitionPack(pack)).toThrow(
/extractedResourcePerBatch.*extractionResourceId.*both must be present together/,
);
});

it("accepts a valid extraction recipe with both extractionResourceId and extractedResourcePerBatch", () => {
const pack = minimalPack({
"recipe-1": minimalRecipe({
extractionResourceId: "iron-ore",
extractedResourcePerBatch: 5,
}),
});
expect(() => validateDefinitionPack(pack)).not.toThrow();
});

it("rejects baseThroughputFactor <= 0", () => {
const pack = minimalPack({
"recipe-1": minimalRecipe({ baseThroughputFactor: 0 }),
Expand Down
16 changes: 16 additions & 0 deletions src/config/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,22 @@ export function validateDefinitionPack(definitionPack: DefinitionPack): void {
}
}

// Extraction resource/amount coupling: both present or both absent
const hasExtractionResource = recipe.extractionResourceId !== undefined;
const hasExtractedAmount = recipe.extractedResourcePerBatch !== undefined;

if (hasExtractionResource && !hasExtractedAmount) {
throw new Error(
`RecipeDefinition "${recipeId}": extractionResourceId "${recipe.extractionResourceId}" is present but extractedResourcePerBatch is missing — both must be present together`,
);
}

if (hasExtractedAmount && !hasExtractionResource) {
throw new Error(
`RecipeDefinition "${recipeId}": extractedResourcePerBatch is present but extractionResourceId is missing — both must be present together`,
);
}

// extractedResourcePerBatch (if present): positive (> 0)
if (recipe.extractedResourcePerBatch !== undefined) {
if (!isFiniteCanonicalNumber(recipe.extractedResourcePerBatch) || recipe.extractedResourcePerBatch <= 0) {
Expand Down
Loading