Skip to content

Commit d41e77e

Browse files
strzhaoclaude
andcommitted
fix(contracts): keep both path endpoints clear of the progress hook
The start sample sat on the sampling grid, so the hook saw progress 0 and a distorting hook could move the plan's start point; the end sample already kept the canonical point. The start endpoint now does too, and the duration must equal the last canonical offset so the path cannot extrapolate past its final sample. The route evidence file is withdrawn: it described machinery that never shipped, cited an amended-away commit, and misnamed the contracts path. The device denial and the route-identified run move into the PR description. Co-Authored-By: Claude Code <[email protected]>
1 parent 9778249 commit d41e77e

3 files changed

Lines changed: 38 additions & 79 deletions

File tree

‎docs/evidence/harmonyos-pan-transport-2026-11-12.md‎

Lines changed: 0 additions & 73 deletions
This file was deleted.

‎packages/contracts/src/gesture-plan.test.ts‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,23 @@ test('densifyGesturePath hands within-segment pacing to the progress hook and ke
123123
assert.ok(
124124
seen.some(([progress, segmentDurationMs]) => progress === 0.5 && segmentDurationMs === 100),
125125
);
126-
// Endpoints never pass through the hook.
126+
// The hook only shapes interior offsets: every progress it saw lies strictly
127+
// between 0 and 1, so the endpoints never passed through it.
128+
assert.ok(seen.length >= 1);
129+
for (const [progress] of seen) {
130+
assert.ok(progress > 0 && progress < 1, `hook saw progress ${progress}`);
131+
}
127132
assert.deepEqual(dense[0]?.point, { x: 0, y: 0 });
128133
assert.deepEqual(dense.at(-1)?.point, { x: 100, y: 0 });
129134
});
135+
136+
test('densifyGesturePath refuses a duration that disagrees with the last canonical offset', () => {
137+
const canonical = [
138+
{ offsetMs: 0, point: { x: 0, y: 0 } },
139+
{ offsetMs: 100, point: { x: 100, y: 0 } },
140+
];
141+
assert.throws(
142+
() => densifyGesturePath(canonical, 150, 'default'),
143+
/must equal the last canonical sample offset/,
144+
);
145+
});

‎packages/contracts/src/gesture-plan.ts‎

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,16 @@ export function densifyGesturePath(
482482
profile: GestureSamplingProfile,
483483
progress: (baseProgress: number, segmentDurationMs: number) => number = (p) => p,
484484
): PointerTrajectorySample[] {
485+
// The plan's last offset is its duration; a disagreement between the two
486+
// arguments would extrapolate past the final sample or drop its endpoint.
487+
const last = canonical.at(-1);
488+
if (!last || last.offsetMs !== durationMs) {
489+
throw new AppError(
490+
'INVALID_ARGS',
491+
'gesture sample duration must equal the last canonical sample offset',
492+
{ reason: 'GESTURE_SAMPLE_DURATION_MISMATCH', durationMs },
493+
);
494+
}
485495
const offsets = [
486496
...new Set([
487497
...sampleGestureOffsets(durationMs, profile),
@@ -499,16 +509,22 @@ export function densifyGesturePath(
499509
const start = canonical[segmentIndex]!;
500510
const end = canonical[segmentIndex + 1]!;
501511
const segmentDurationMs = end.offsetMs - start.offsetMs;
512+
const baseProgress =
513+
segmentDurationMs === 0 ? 0 : (offsetMs - start.offsetMs) / segmentDurationMs;
502514
return {
503515
offsetMs,
504516
point:
517+
// Both endpoints and every zero-length segment keep the canonical
518+
// point, so the hook only ever reshapes strictly interior offsets.
505519
offsetMs === end.offsetMs || segmentDurationMs === 0
506520
? end.point
507-
: interpolateGesturePoint(
508-
start.point,
509-
end.point,
510-
progress((offsetMs - start.offsetMs) / segmentDurationMs, segmentDurationMs),
511-
),
521+
: baseProgress === 0
522+
? start.point
523+
: interpolateGesturePoint(
524+
start.point,
525+
end.point,
526+
progress(baseProgress, segmentDurationMs),
527+
),
512528
};
513529
});
514530
}

0 commit comments

Comments
 (0)