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
17 changes: 17 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,23 @@ jobs:
- name: Run typecheck
run: pnpm typecheck

freerange:
name: FreeRange
runs-on: ubuntu-latest
timeout-minutes: 20
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2

- name: Setup toolchain
uses: ./.github/actions/setup-node-pnpm

- name: Setup Bun
uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6 # v2.2.0

- name: Check numeric ranges
run: pnpm check:freerange

integration:
name: Integration Tests
runs-on: ubuntu-latest
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
"check:layering": "node --experimental-strip-types --test scripts/layering/model.test.ts && node --experimental-strip-types scripts/layering/check.ts",
"check:production-exports": "fallow dead-code --config fallow-production-exports.json --production --unused-exports --fail-on-issues",
"check:bundle-owner-files": "node --experimental-strip-types scripts/check-bundle-owner-files.ts",
"check:freerange": "fr",
"check:quick": "pnpm lint && pnpm typecheck",
"sync:mcp-metadata": "node scripts/sync-mcp-metadata.mjs",
"check:mcp-metadata": "node scripts/sync-mcp-metadata.mjs --check",
Expand Down Expand Up @@ -224,15 +225,16 @@
"yaml": "^2.9.0"
},
"devDependencies": {
"@chenglou/freerange": "^0.0.1",
"@types/node": "^22.19.21",
"typescript": "^7.0.2",
"@vitest/coverage-v8": "4.1.8",
"fallow": "^2.95.0",
"oxc-parser": "^0.138.0",
"oxfmt": "^0.42.0",
"oxlint": "^1.69.0",
"skillgym": "^0.9.1",
"tsdown": "^0.22.4",
"typescript": "^7.0.2",
"vite": "^8.0.16",
"vitest": "^4.1.8"
}
Expand Down
18 changes: 18 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ pmOnFail: warn
verifyDepsBeforeRun: warn
allowBuilds:
fallow: true
minimumReleaseAgeExclude:
- '@chenglou/freerange@0.0.1'
4 changes: 4 additions & 0 deletions src/contracts/scroll-gesture.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,3 +221,7 @@ test('clampGestureCoordinate rounds values and clamps them into the safe gesture
assert.equal(clampGestureCoordinate(2.6, 8, 100), 8);
assert.equal(clampGestureCoordinate(97.6, 8, 100), 92);
});

test('clampGestureCoordinate returns the lower bound for non-finite coordinates', () => {
assert.equal(clampGestureCoordinate(Number.POSITIVE_INFINITY, 8, 100), 8);
});
18 changes: 10 additions & 8 deletions src/contracts/scroll-gesture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,11 @@ function pointFromPercent(
xPercent: number,
yPercent: number,
): GesturePoint {
const x = Math.trunc((frame.referenceWidth * xPercent) / 100);
const y = Math.trunc((frame.referenceHeight * yPercent) / 100);
return {
x: Math.trunc((frame.referenceWidth * xPercent) / 100),
y: Math.trunc((frame.referenceHeight * yPercent) / 100),
x: Number.isFinite(x) ? x : 0,
y: Number.isFinite(y) ? y : 0,
};
}

Expand Down Expand Up @@ -307,11 +309,11 @@ function normalizeRequestedPixels(pixels: number): number {
}

export function clampGestureCoordinate(value: number, marginPx: number, size: number): number {
const min = marginPx;
const max = Math.max(min, size - marginPx);
return clampToRange(value, min, max);
}
const min = Math.round(marginPx);
if (!Number.isFinite(min)) return 0;

const max = Math.max(min, Math.round(size - marginPx));
if (!Number.isFinite(max) || !Number.isFinite(value)) return min;

function clampToRange(value: number, min: number, max: number): number {
return Math.min(Math.round(max), Math.max(Math.round(min), Math.round(value)));
return Math.min(max, Math.max(min, Math.round(value)));
}
6 changes: 6 additions & 0 deletions src/daemon/handlers/record-trace-android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,13 @@ function scaledSizeToMax(size: AndroidRecordingSize & { maxSize: number }): Andr
if (longest <= size.maxSize) {
return { width: size.width, height: size.height };
}
if (longest === 0) {
return { width: size.width, height: size.height };
}
const scale = size.maxSize / longest;
if (!Number.isFinite(scale)) {
return { width: size.width, height: size.height };
}
return {
width: scaledEvenDimension(size.width, scale),
height: scaledEvenDimension(size.height, scale),
Expand Down
24 changes: 20 additions & 4 deletions src/screenshot-diff/screenshot-diff-region-overlay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ export function annotateDiffRegions(diff: PNG, regions: ScreenshotDiffRegion[]):
}

function drawRect(diff: PNG, rect: ScreenshotDiffRegion['rect']): void {
const minX = clamp(rect.x, 0, diff.width - 1);
const minY = clamp(rect.y, 0, diff.height - 1);
const maxX = clamp(rect.x + rect.width - 1, 0, diff.width - 1);
const maxY = clamp(rect.y + rect.height - 1, 0, diff.height - 1);
const bounds = resolveFiniteRectBounds(rect);
if (bounds == null) return;
const minX = clamp(bounds.x, 0, diff.width - 1);
const minY = clamp(bounds.y, 0, diff.height - 1);
const maxX = clamp(bounds.right, 0, diff.width - 1);
const maxY = clamp(bounds.bottom, 0, diff.height - 1);
for (let thickness = 0; thickness < REGION_BORDER_THICKNESS; thickness += 1) {
for (let x = minX; x <= maxX; x += 1) {
setPixel(diff, x, minY + thickness, REGION_BORDER_COLOR);
Expand All @@ -34,6 +36,19 @@ function drawRect(diff: PNG, rect: ScreenshotDiffRegion['rect']): void {
}
}

function resolveFiniteRectBounds(rect: ScreenshotDiffRegion['rect']): {
x: number;
y: number;
right: number;
bottom: number;
} | null {
const right = rect.x + rect.width - 1;
const bottom = rect.y + rect.height - 1;
const values = [rect.x, rect.y, rect.width, rect.height, right, bottom];
if (!values.every(Number.isFinite)) return null;
return { x: rect.x, y: rect.y, right, bottom };
}

function setPixel(
diff: PNG,
x: number,
Expand All @@ -49,5 +64,6 @@ function setPixel(
}

function clamp(value: number, min: number, max: number): number {
if (!Number.isFinite(value)) return min;
return Math.min(Math.max(value, min), max);
}
Loading