compat-review

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Compat Layer Review

兼容层评审

Verify that a compat PR actually fixes a real lodash inconsistency.
验证兼容PR是否真正修复了与lodash之间的实际不一致问题。

Input

输入

$ARGUMENTS — PR number (e.g.
1234
) or function name (e.g.
chunk
)
$ARGUMENTS — PR编号(例如
1234
)或函数名称(例如
chunk

Workflow

工作流程

1. Identify target function and PR claims

1. 确定目标函数与PR声明

PR number:
bash
gh pr view {number} --repo toss/es-toolkit --json title,body,files
From the PR description and diff, extract:
  • Which compat function is being fixed
  • What inconsistency the contributor claims (expected vs actual behavior)
  • Any test examples the contributor provides
Function name: Read the function source and its spec to understand current behavior.
PR编号:
bash
gh pr view {number} --repo toss/es-toolkit --json title,body,files
从PR描述和差异中提取:
  • 正在修复的兼容函数是哪一个
  • 贡献者声称存在的不一致问题(预期行为 vs 实际行为)
  • 贡献者提供的任何测试示例
函数名称:阅读函数源码及其规范,了解当前行为。

2. Build comparison test

2. 构建对比测试

Create a temporary vitest spec at
src/compat/{category}/_compat-review-{fn}.spec.ts
.
typescript
import { describe, expect, it } from 'vitest';
import { fn as compatFn } from 'es-toolkit/compat';
import { fn as lodashFn } from 'lodash';
Include two groups of test cases:
A. Contributor's claimed examples — Extract directly from the PR description or test diff. These are the cases the PR claims to fix.
B. ~10 additional edge cases you generate — Based on the function's signature and lodash's known behavior patterns:
  • Empty inputs:
    []
    ,
    {}
    ,
    ''
    ,
    0
  • Nullish:
    null
    ,
    undefined
  • Negative/zero/float numbers:
    -1
    ,
    0
    ,
    1.5
    ,
    NaN
    ,
    Infinity
  • Type coercion: string numbers (
    '3'
    ), boolean, mixed types
  • Boundary: single-element arrays, very long strings, deeply nested objects
  • Pick cases that are relevant to the specific function
Each test:
typescript
it('description', () => {
  let lodashResult, compatResult;
  let lodashErr: any, compatErr: any;
  try {
    lodashResult = lodashFn(args);
  } catch (e) {
    lodashErr = e;
  }
  try {
    compatResult = compatFn(args);
  } catch (e) {
    compatErr = e;
  }

  if (lodashErr && compatErr) return; // both throw = consistent
  if (lodashErr || compatErr) {
    throw new Error(`Behavior mismatch: ${lodashErr ? 'lodash throws' : 'compat throws'}`);
  }
  expect(compatResult).toEqual(lodashResult);
});
src/compat/{category}/_compat-review-{fn}.spec.ts
创建临时vitest测试文件。
typescript
import { describe, expect, it } from 'vitest';
import { fn as compatFn } from 'es-toolkit/compat';
import { fn as lodashFn } from 'lodash';
包含两组测试用例:
A. 贡献者声称的示例 — 直接从PR描述或测试差异中提取。这些是PR声称要修复的用例。
B. 你生成的约10个额外边缘用例 — 基于函数签名和lodash已知的行为模式:
  • 空输入:
    []
    ,
    {}
    ,
    ''
    ,
    0
  • 空值类:
    null
    ,
    undefined
  • 负数/零/浮点数:
    -1
    ,
    0
    ,
    1.5
    ,
    NaN
    ,
    Infinity
  • 类型转换:字符串数字(
    '3'
    )、布尔值、混合类型
  • 边界情况:单元素数组、极长字符串、深度嵌套对象
  • 选择与特定函数相关的用例
每个测试:
typescript
it('description', () => {
  let lodashResult, compatResult;
  let lodashErr: any, compatErr: any;
  try {
    lodashResult = lodashFn(args);
  } catch (e) {
    lodashErr = e;
  }
  try {
    compatResult = compatFn(args);
  } catch (e) {
    compatErr = e;
  }

  if (lodashErr && compatErr) return; // 两者都抛出异常 = 行为一致
  if (lodashErr || compatErr) {
    throw new Error(`行为不匹配:${lodashErr ? 'lodash抛出异常' : 'compat抛出异常'}`);
  }
  expect(compatResult).toEqual(lodashResult);
});

3. Run comparison BEFORE the PR change

3. 在PR变更前运行对比测试

bash
yarn vitest run src/compat/{category}/_compat-review-{fn}.spec.ts
Record which tests fail — these are real inconsistencies that exist on main.
bash
yarn vitest run src/compat/{category}/_compat-review-{fn}.spec.ts
记录哪些测试失败 — 这些是主分支上存在的实际不一致问题。

4. Apply PR changes and re-run

4. 应用PR变更并重新运行

bash
gh pr diff {number} --repo toss/es-toolkit | git apply
Run the same test again. Confirm that:
  • The contributor's claimed examples now pass
  • The additional edge cases still pass (no regressions)
Revert after testing:
bash
git checkout -- .
bash
gh pr diff {number} --repo toss/es-toolkit | git apply
再次运行相同的测试。确认:
  • 贡献者声称的示例现在通过测试
  • 额外的边缘用例仍然通过(无回归问题)
测试后回退:
bash
git checkout -- .

5. Clean up

5. 清理

Delete
_compat-review-*.spec.ts
.
删除
_compat-review-*.spec.ts
文件。

6. Report

6. 报告

undefined
undefined

{fn} — Compat Review

{fn} — 兼容层评审

PR Claim

PR声明

{What the contributor says they're fixing}
{贡献者声称要修复的内容}

Verification (BEFORE fix)

验证(修复前)

#InputlodashcompatMatch?Source
1.........MISMATCHPR example
2.........MATCHEdge case
#输入lodashcompat是否匹配?来源
1.........不匹配PR示例
2.........匹配边缘用例

Verification (AFTER fix)

验证(修复后)

#InputlodashcompatMatch?Source
#输入lodashcompat是否匹配?来源

Verdict

结论

  • PR claim is valid (inconsistency confirmed on main)
  • Fix resolves the claimed inconsistency
  • No regressions in edge cases
  • Existing tests still pass
undefined
  • PR声明有效(主分支上确认存在不一致问题)
  • 修复解决了声称的不一致问题
  • 边缘用例无回归
  • 现有测试仍通过
undefined