Skip to content
Closed
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
7 changes: 7 additions & 0 deletions src/scoring/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ export const DEFAULT_SCORING_CONSTANTS: Record<string, number> = {
TIME_DECAY_SIGMOID_MIDPOINT: 10,
TIME_DECAY_SIGMOID_STEEPNESS_SCALAR: 0.4,
TIME_DECAY_MIN_MULTIPLIER: 0.05,
// Upstream scoring constants the knownOnly parser previously dropped (absent from SCORING_CONSTANT_NAMES),
// so they never synced from upstream and surfaced as unmodeled drift (#809). DEFAULT_ISSUE_DISCOVERY_SHARE is
// the upstream default for a repo's issue-discovery share when its registry config does not set one (applied
// in preview.ts); the other two sync for parity with upstream review-collateral and non-code line handling.
MAX_OPEN_PR_REVIEW_COLLATERAL_MULTIPLIER: 2.0,
MAX_LINES_SCORED_FOR_NON_CODE_EXT: 300,
DEFAULT_ISSUE_DISCOVERY_SHARE: 0.5,
};

export const DEFAULT_GITTENSOR_UPSTREAM_REPO = "entrius/gittensor";
Expand Down
6 changes: 5 additions & 1 deletion src/scoring/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,11 @@ function computeScoreCore(
// 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 totalTokenScore = nonNegative(input.totalTokenScore ?? sourceTokenScore + testFileWeight * nonNegative(input.testTokenScore) + nonNegative(input.nonCodeTokenScore));
// Non-code files (docs, data, config) contribute capped token score: upstream limits the lines scored for
// a non-code extension to MAX_LINES_SCORED_FOR_NON_CODE_EXT so a huge generated/non-code file cannot inflate
// the component total (#809). Honour an explicit caller total as-is.
const cappedNonCodeTokenScore = Math.min(nonNegative(input.nonCodeTokenScore), constant(constants, "MAX_LINES_SCORED_FOR_NON_CODE_EXT", 300));
const totalTokenScore = nonNegative(input.totalTokenScore ?? sourceTokenScore + testFileWeight * nonNegative(input.testTokenScore) + cappedNonCodeTokenScore);
const sourceLines = Math.max(1, nonNegative(input.sourceLines ?? sourceTokenScore));
const fixedBaseScore = input.fixedBaseScore ?? config?.fixedBaseScore ?? undefined;
const rawDensity = sourceTokenScore / sourceLines;
Expand Down
20 changes: 20 additions & 0 deletions test/unit/scoring.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,26 @@ MAX_CODE_DENSITY_MULTIPLIER = 1.15
expect(unmodeled).not.toContain("TIME_DECAY_GRACE_PERIOD_HOURS"); // modeled as of #703
});

it("models the previously-dropped upstream scoring constants so they sync and stop surfacing as drift (#809)", () => {
expect(DEFAULT_SCORING_CONSTANTS.MAX_OPEN_PR_REVIEW_COLLATERAL_MULTIPLIER).toBe(2);
expect(DEFAULT_SCORING_CONSTANTS.MAX_LINES_SCORED_FOR_NON_CODE_EXT).toBe(300);
expect(DEFAULT_SCORING_CONSTANTS.DEFAULT_ISSUE_DISCOVERY_SHARE).toBe(0.5);
expect(
findUnmodeledUpstreamConstants("MAX_OPEN_PR_REVIEW_COLLATERAL_MULTIPLIER = 2.0\nMAX_LINES_SCORED_FOR_NON_CODE_EXT = 300\nDEFAULT_ISSUE_DISCOVERY_SHARE = 0.5\n"),
).toEqual([]);
});

it("caps a PR's non-code token contribution at MAX_LINES_SCORED_FOR_NON_CODE_EXT (#809)", () => {
const base = { repoFullName: repo.fullName, sourceTokenScore: 40, sourceLines: 40, credibility: 1 };
// nonCodeTokenScore 500 is capped at 300, so the two previews (500 vs exactly 300) yield the same total.
const capped = buildScorePreview({ repo, snapshot, input: { ...base, nonCodeTokenScore: 500 } });
const atCap = buildScorePreview({ repo, snapshot, input: { ...base, nonCodeTokenScore: 300 } });
const underCap = buildScorePreview({ repo, snapshot, input: { ...base, nonCodeTokenScore: 100 } });
// The cap caps the component total, which feeds the contribution-bonus ramp.
expect(capped.scoreEstimate.contributionBonus).toBe(atCap.scoreEstimate.contributionBonus);
expect(underCap.scoreEstimate.contributionBonus).toBeLessThan(atCap.scoreEstimate.contributionBonus);
});

it("warns on the snapshot when upstream defines an unmodeled scoring dimension", async () => {
const env = createTestEnv({
GITTENSOR_UPSTREAM_REPO: "custom/upstream",
Expand Down
Loading