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
8 changes: 4 additions & 4 deletions src/scoring/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,13 @@
return stalenessWarning ? { ...snapshot, warnings: [...snapshot.warnings, stalenessWarning] } : snapshot;
}

export function parsePythonNumberConstants(source: string, options: { knownOnly?: boolean } = { knownOnly: true }): Record<string, number> {

Check notice on line 153 in src/scoring/model.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.
const constants: Record<string, number> = {};
for (const line of source.split("\n")) {
// Match Python numeric literals including underscore separators (1_000_000), floats, and exponents
// (1e-9, 5.8e1). The previous /[-+]?\d+(?:\.\d+)?/ stopped at `_`/`e`, truncating 1_000_000 -> 1 and
// 1e-9 -> 1, which silently misparsed any such upstream constant and polluted the unmodeled list (#810).
const match = line.match(/^([A-Z][A-Z0-9_]+)\s*=\s*([-+]?(?:\d[\d_]*\.?\d*|\.\d+)(?:[eE][-+]?\d+)?)/);
// Match Python numeric literals including underscore separators in integer and fractional parts
// (1_000_000, 0.000_001, 3.14_15), floats, and exponents (1e-9, 5.8e1). The previous regex only
// allowed `_` in the integer part, truncating 0.000_001 -> 0 and 3.14_15 -> 3.14 (#992).
const match = line.match(/^([A-Z][A-Z0-9_]+)\s*=\s*([-+]?(?:\d[\d_]*\.?[\d_]*|\.\d[\d_]*)(?:[eE][-+]?\d+)?)/);
if (!match) continue;
const name = match[1]!;
const raw = match[2]!;
Expand Down
16 changes: 16 additions & 0 deletions test/unit/scoring.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,25 @@
expect(parsed.CONTRIBUTION_SCORE_FOR_FULL_BONUS).toBe(1500000);
expect(parsed.SRC_TOK_SATURATION_SCALE).toBe(58);
expect(parsed.MERGED_PR_BASE_SCORE).toBe(1e-9);
expect(parsed.OSS_EMISSION_SHARE).toBe(0.9);

Check notice on line 86 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.
});

it("parses underscore separators in the fractional part of upstream constants (#992)", () => {
const parsed = parsePythonNumberConstants(
`
RATE = 0.000_001
SCALE = 3.14_15
VAL = 1_000.000_5
BARE = .5_0
`,
{ knownOnly: false },
);
expect(parsed.RATE).toBe(0.000001);
expect(parsed.SCALE).toBe(3.1415);
expect(parsed.VAL).toBe(1000.0005);
expect(parsed.BARE).toBe(0.5);
});

it("flags only scoring snapshots older than the freshness window as stale (#810)", () => {
const now = Date.parse("2026-06-21T12:00:00.000Z");
const justFresh = new Date(now - SCORING_SNAPSHOT_STALE_MS + 60_000).toISOString();
Expand Down
Loading