Skip to content

Commit ca26ea5

Browse files
committed
fix(engine): validate metadata candidate paths
1 parent 1ce4364 commit ca26ea5

3 files changed

Lines changed: 42 additions & 6 deletions

File tree

packages/gittensory-engine/src/miner-goal-lane-fit.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ export function computeMinerGoalLaneFit(
5555
return clamp01(score);
5656
}
5757

58-
function normalizeCandidatePaths(paths: readonly string[] | undefined): string[] {
59-
if (!paths) return [];
58+
function normalizeCandidatePaths(paths: unknown): string[] {
59+
if (!Array.isArray(paths)) return [];
6060
const normalized: string[] = [];
6161
for (const path of paths) {
6262
if (typeof path !== "string") continue;

packages/gittensory-engine/test/miner-goal-lane-fit.test.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,32 @@ test("computeMetadataLaneFit returns 0 when candidatePaths hit blockedPaths", ()
9595
);
9696
});
9797

98-
test("computeMetadataLaneFit ignores blank or malformed candidatePaths entries", () => {
99-
const spec = { ...DEFAULT_MINER_GOAL_SPEC, preferredLabels: ["bug"] };
98+
test("computeMetadataLaneFit ignores malformed candidatePaths values", () => {
99+
const spec = {
100+
...DEFAULT_MINER_GOAL_SPEC,
101+
blockedPaths: ["src/**"],
102+
preferredLabels: ["bug"],
103+
wantedPaths: ["src/**"],
104+
};
100105
assert.equal(
101106
computeMetadataLaneFit(
102107
{ labels: ["bug"], candidatePaths: ["", " ", 42 as unknown as string] },
103108
spec,
104109
),
105110
1,
106111
);
112+
assert.equal(
113+
computeMetadataLaneFit(
114+
{ labels: ["bug"], candidatePaths: { path: "src/app.ts" } as unknown as string[] },
115+
spec,
116+
),
117+
1,
118+
);
119+
assert.equal(
120+
computeMetadataLaneFit(
121+
{ labels: ["bug"], candidatePaths: "src/app.ts" as unknown as string[] },
122+
spec,
123+
),
124+
1,
125+
);
107126
});

test/unit/miner-goal-lane-fit.test.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,31 @@ describe("computeMetadataLaneFit", () => {
4343
).toBe(0);
4444
});
4545

46-
it("ignores non-string candidatePaths entries before scoring", () => {
47-
const spec = { ...DEFAULT_MINER_GOAL_SPEC, preferredLabels: ["bug"] };
46+
it("ignores malformed candidatePaths values before scoring", () => {
47+
const spec = {
48+
...DEFAULT_MINER_GOAL_SPEC,
49+
blockedPaths: ["src/**"],
50+
preferredLabels: ["bug"],
51+
wantedPaths: ["src/**"],
52+
};
4853
expect(
4954
computeMetadataLaneFit(
5055
{ labels: ["bug"], candidatePaths: [42 as unknown as string, ""] },
5156
spec,
5257
),
5358
).toBe(1);
59+
expect(
60+
computeMetadataLaneFit(
61+
{ labels: ["bug"], candidatePaths: { path: "src/app.ts" } as unknown as string[] },
62+
spec,
63+
),
64+
).toBe(1);
65+
expect(
66+
computeMetadataLaneFit(
67+
{ labels: ["bug"], candidatePaths: "src/app.ts" as unknown as string[] },
68+
spec,
69+
),
70+
).toBe(1);
5471
});
5572
});
5673

0 commit comments

Comments
 (0)