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
6 changes: 5 additions & 1 deletion packages/gittensory-engine/src/miner-goal-spec-parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,11 @@ function parseStringList(value: unknown, field: string, warnings: string[]): str
}
const seen = new Set<string>();
const out: string[] = [];
for (const entry of value) {
for (const [index, entry] of value.entries()) {
if (index >= MAX_LIST_ENTRIES) {
warnings.push(`MinerGoalSpec field "${field}" is capped at ${MAX_LIST_ENTRIES} entries; dropping the rest.`);
break;
}
if (typeof entry !== "string") {
warnings.push(`MinerGoalSpec field "${field}" entries must be strings; skipping non-string.`);
continue;
Expand Down
36 changes: 36 additions & 0 deletions packages/gittensory-engine/test/miner-goal-spec-parse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,39 @@ test("parseMinerGoalSpec warns and falls back on malformed fields", () => {
assert.equal(result.spec.issueDiscoveryPolicy, "neutral");
assert.ok(result.warnings.length >= 4);
});

test("parseMinerGoalSpec caps list inspection for invalid entries", () => {
const result = parseMinerGoalSpec({
wantedPaths: Array.from({ length: 1_000 }, () => null),
});

assert.deepEqual(result.spec.wantedPaths, []);
assert.equal(result.warnings.length, 201);
assert.match(result.warnings.at(-1) ?? "", /capped at 200 entries/);
});

test("parseMinerGoalSpec caps list inspection for duplicate, empty, and overlong entries", () => {
const duplicates = parseMinerGoalSpec({
wantedPaths: Array.from({ length: 1_000 }, () => "src/**"),
});
assert.deepEqual(duplicates.spec.wantedPaths, ["src/**"]);
assert.deepEqual(duplicates.warnings, [
'MinerGoalSpec field "wantedPaths" is capped at 200 entries; dropping the rest.',
]);

const empty = parseMinerGoalSpec({
wantedPaths: Array.from({ length: 1_000 }, () => " "),
});
assert.deepEqual(empty.spec.wantedPaths, []);
assert.deepEqual(empty.warnings, [
'MinerGoalSpec field "wantedPaths" is capped at 200 entries; dropping the rest.',
]);

const overlong = parseMinerGoalSpec({
wantedPaths: Array.from({ length: 1_000 }, () => "x".repeat(301)),
});
assert.deepEqual(overlong.spec.wantedPaths, []);
assert.deepEqual(overlong.warnings, [
'MinerGoalSpec field "wantedPaths" is capped at 200 entries; dropping the rest.',
]);
});