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
18 changes: 14 additions & 4 deletions src/scoring/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,15 +298,14 @@
const ossEmissionShare = constant(constants, "OSS_EMISSION_SHARE", 0.9);
const repoSlice = emissionShare * ossEmissionShare;
const directPrSlice = repoSlice * (1 - issueDiscoveryShare);
const issueDiscoverySlice = repoSlice * issueDiscoveryShare;

Check notice on line 301 in src/scoring/preview.ts

View check run for this annotation

Deleted GitHub App / Gittensory Context

Issue discovery is disabled for this repo

This repo is configured for direct contribution review rather than issue-discovery flow.

Check notice on line 301 in src/scoring/preview.ts

View check run for this annotation

Deleted GitHub App / Gittensory Context

PR author has maintainer association

This PR appears to come from a maintainer-associated account.
const sourceTokenScore = nonNegative(input.sourceTokenScore);
// TEST_FILE_CONTRIBUTION_WEIGHT (#808): upstream weights test-file tokens at 0.05× relative to source tokens.
// Applied only when totalTokenScore is not explicitly provided — an explicit caller total is honoured as-is.
const testFileWeight = constant(constants, "TEST_FILE_CONTRIBUTION_WEIGHT", 0.05);
const cappedNonCodeTokenScore = applyNonCodeLineCap(input, constants);
const totalTokenScore = nonNegative(
input.totalTokenScore ?? sourceTokenScore + testFileWeight * nonNegative(input.testTokenScore) + cappedNonCodeTokenScore,
);
const derivedTotalTokenScore = sourceTokenScore + testFileWeight * nonNegative(input.testTokenScore) + cappedNonCodeTokenScore;
const totalTokenScore =
input.totalTokenScore === undefined ? nonNegative(derivedTotalTokenScore) : applyNonCodeCapToTotal(input.totalTokenScore, input, cappedNonCodeTokenScore);
const sourceLines = Math.max(1, nonNegative(input.sourceLines ?? sourceTokenScore));
const fixedBaseScore = input.fixedBaseScore ?? config?.fixedBaseScore ?? undefined;
const rawDensity = sourceTokenScore / sourceLines;
Expand Down Expand Up @@ -978,6 +977,17 @@
return lines <= maxLines ? score : score * (maxLines / lines);
}

function applyNonCodeCapToTotal(
totalTokenScore: number,
input: Pick<ScorePreviewInput, "nonCodeTokenScore" | "nonCodeLines">,
cappedNonCodeTokenScore: number,
): number {
const total = nonNegative(totalTokenScore);
const nonCodeTokenScore = nonNegative(input.nonCodeTokenScore);
if (nonCodeTokenScore <= 0 || cappedNonCodeTokenScore >= nonCodeTokenScore) return total;
return Math.max(0, total - (nonCodeTokenScore - cappedNonCodeTokenScore));
}

function constant(constants: Record<string, number>, key: string, fallback: number): number {
const value = constants[key];
return typeof value === "number" && Number.isFinite(value) ? value : fallback;
Expand Down
19 changes: 19 additions & 0 deletions test/unit/scoring.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,28 @@
openPrCount: 0,
credibility: 1,
},
}).scoreEstimate.contributionBonus,

Check notice on line 286 in test/unit/scoring.test.ts

View check run for this annotation

Deleted GitHub App / Gittensory Context

Issue discovery is disabled for this repo

This repo is configured for direct contribution review rather than issue-discovery flow.

Check notice on line 286 in test/unit/scoring.test.ts

View check run for this annotation

Deleted GitHub App / Gittensory Context

PR author has maintainer association

This PR appears to come from a maintainer-associated account.
5,
);

const explicitTotalWithNonCode = buildScorePreview({
repo,
snapshot: {
...snapshot,
constants: { ...snapshot.constants, MAX_LINES_SCORED_FOR_NON_CODE_EXT: 300, CONTRIBUTION_SCORE_FOR_FULL_BONUS: 1500, MAX_CONTRIBUTION_BONUS: 25 },
},
input: {
repoFullName: repo.fullName,
sourceTokenScore: 100,
totalTokenScore: 700,
nonCodeTokenScore: 600,
nonCodeLines: 600,
sourceLines: 100,
openPrCount: 0,
credibility: 1,
},
});
expect(explicitTotalWithNonCode.scoreEstimate.contributionBonus).toBeCloseTo(cappedNonCode.scoreEstimate.contributionBonus, 5);
});

it("detects the active model from fetched constants before default fallback constants", async () => {
Expand Down
Loading