refactor(mobile): keep review reset hashing private (#10048)

This commit is contained in:
Julius Marminge authored and GitHub committed 2026-09-05 01:30:22 -07:00
1 parent 56a2f42b8c
commit c2aff911c3
3 files changed
+10 -13

No files matched your search

@@ -1,9 +1,9 @@
import { describe, expect, it } from "vite-plus/test";
import { buildNativeReviewTokensResetKey, hashReviewDiffKey } from "./reviewDiffBridgeKeys";
import { buildNativeReviewTokensResetKey } from "./reviewDiffBridgeKeys";
describe("native review diff bridge", () => {
it("builds stable reset keys from the rendered diff identity", () => {
it("changes reset keys when the rendered diff identity changes", () => {
const input = {
threadKey: "env:thread",
sectionId: "turn:2",
@@ -13,15 +13,12 @@ describe("native review diff bridge", () => {
rowCount: 4,
};
expect(buildNativeReviewTokensResetKey(input)).toBe(buildNativeReviewTokensResetKey(input));
expect(buildNativeReviewTokensResetKey({ ...input, rowCount: 5 })).not.toBe(
buildNativeReviewTokensResetKey(input),
);
expect(buildNativeReviewTokensResetKey({ ...input, diff: null })).toContain(":empty:");
});
const resetKey = buildNativeReviewTokensResetKey(input);
it("includes diff length in the hash key to reduce accidental collisions", () => {
expect(hashReviewDiffKey("abc")).toMatch(/^3:/);
expect(hashReviewDiffKey("abcd")).toMatch(/^4:/);
expect(
buildNativeReviewTokensResetKey({ ...input, diff: "diff --git a/b.ts b/b.ts" }),
).not.toBe(resetKey);
expect(buildNativeReviewTokensResetKey({ ...input, rowCount: 5 })).not.toBe(resetKey);
expect(buildNativeReviewTokensResetKey({ ...input, diff: null })).not.toBe(resetKey);
});
});
@@ -3,7 +3,7 @@ import type { NativeReviewDiffHighlightScheme } from "../diffs/nativeReviewDiffH
// Pure key-derivation helpers for the native review diff bridge. Kept free of
// react-native / hook imports so they stay unit-testable in node.
export function hashReviewDiffKey(diff: string | null | undefined): string {
function hashReviewDiffKey(diff: string | null | undefined): string {
if (!diff) {
return "empty";
}
@@ -8,7 +8,7 @@ import { useNativeReviewDiffHighlighting } from "./useNativeReviewDiffHighlighti
import { buildNativeReviewTokensResetKey } from "./reviewDiffBridgeKeys";
import { useUniwindTheme } from "../../lib/useUniwindTheme";
export { buildNativeReviewTokensResetKey, hashReviewDiffKey } from "./reviewDiffBridgeKeys";
export { buildNativeReviewTokensResetKey } from "./reviewDiffBridgeKeys";
export function useNativeReviewDiffBridge(input: {
readonly threadKey: string | null;