Skip to content

node:util: implement diff edit tuple helper #3433

@andrewtdiz

Description

@andrewtdiz

Summary

Perry does not implement util.diff(actual, expected). Node exposes this helper and returns an edit-tuple sequence for string inputs and arrays of strings, with validation errors for unsupported input types.

Node Behavior

Minimal repro:

import * as util from "node:util";

console.log("diff typeof:", typeof util.diff);

for (const [actual, expected] of [
  ["abc", "adc"],
  [["a", "b", "c"], ["a", "d", "c"]],
  ["same", "same"],
  [123, "x"],
  ["x", 123],
] as any[]) {
  try {
    console.log(`${JSON.stringify(actual)} -> ${JSON.stringify(expected)}:`, JSON.stringify(util.diff(actual, expected)));
  } catch (err) {
    const e = err as NodeJS.ErrnoException;
    console.log(`${JSON.stringify(actual)} -> ${JSON.stringify(expected)} error:`, e.name, e.code, e.message.split("\n")[0]);
  }
}

Node v25.9.0 with FORCE_COLOR=0 node --experimental-strip-types prints:

diff typeof: function
"abc" -> "adc": [[0,"a"],[1,"b"],[-1,"d"],[0,"c"]]
["a","b","c"] -> ["a","d","c"]: [[0,"a"],[1,"b"],[-1,"d"],[0,"c"]]
"same" -> "same": []
123 -> "x" error: TypeError ERR_INVALID_ARG_TYPE The "actual" argument must be of type string. Received type number (123)
"x" -> 123 error: TypeError ERR_INVALID_ARG_TYPE The "expected" argument must be of type string. Received type number (123)

Perry Behavior

Focused probe test-files/tmp_util_diff.ts fails at compile time:

Collecting modules...
Error: `util.diff` is not implemented in Perry — see `perry --print-api-manifest` for the supported surface, or set `PERRY_ALLOW_UNIMPLEMENTED=1` to ignore. (#463)

Evidence:

  • ./run_parity_tests.sh --filter tmp_util_diff
  • report: test-parity/reports/parity_report_20260530_110312.json
  • Node output: test-parity/output/node/tmp_util_diff.txt
  • Perry compile log: test-parity/output/tmp_util_diff.compile_error.log
  • docs list util.diff(actual, expected) as a gap in docs/runtime-parity-gaps.md.
  • crates/perry-api-manifest/src/entries.rs omits diff from the supported util surface.

Suggested PR Cut

Batch this with related issues in:
node:util: comparison helper parity

Good batch candidates:

Do not batch with:

  • unrelated modules
  • broad subsystem rewrites
  • fixes needing different test harnesses

Acceptance

  • parity/regression test proves string and string-array diffs return Node-compatible edit tuples
  • invalid input types throw Node-compatible ERR_INVALID_ARG_TYPE errors
  • related known-failure/docs/manifest entries updated if touched

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions