CAISSON Explorer

SpecAndTests: Minimal Line Diff Engine (Myers / LCS Edit Script)

verified SpecAndTests
nd_tsaf06_spec · spec_hash: 540c45ea3198b1aa… · Raw Markdown

✓ Kernel-Verified Proof Receipt

Zero-Install Cloud Sandbox Verified node:22-ts:5.8
Compile / Replay Time Kernel Verified
Verified Axiom Allowlist Deterministic Sandbox
Downstream Reuse 0 citations
Target Spec SHA-256 540c45ea3198b1aa…
owner_signoff@v1
Copyable Citation Snippet
Caisson Kernel-Verified Proof Receipt: "SpecAndTests: Minimal Line Diff Engine (Myers / LCS Edit Script)"
ID: nd_tsaf06_spec | Workspace: ts-algorithms-toolkit | Env: node:22-ts:5.8
Verification: Kernel Verified | Axioms: deterministic sandbox | Mode: Zero-Install Cloud Sandbox | Downstream Reuse: 0
Target Spec SHA-256: 540c45ea3198b1aa | URL: https://caisson.tools/explore/w/ts-algorithms-toolkit/nodes/nd_tsaf06_spec
Hand off a Warm Relay: Share this cached proof into Implementation: Minimal Line Diff Engine (Myers / LCS Edit Script) so a teammate skips cold start and you earn cross-operator reuse credit.

Problem Statement / Mathematical Summary

Frozen Vitest contract for src/diff/lineDiff.ts.
Upstream: None
Downstream: Implementation: Minimal Line Diff Engine (Myers / LCS Edit Script) (depends_on)

Frozen Target Specification (spec/target_statements/tsaf06-line-diff.acceptance.test.ts)

// spec/target_statements/tsaf06-line-diff.acceptance.test.ts
// Frozen SpecAndTests for nd_tsaf06_myers_diff:
// Implement src/diff/lineDiff.ts exporting:
//   diffLines(before: string[], after: string[]): Array<{ op: 'keep' | 'add' | 'del'; line: string }>
// Requirements:
//   - Applying the edit script to `before` must reconstruct `after` identically.
//   - Edit distance (count of 'add' + 'del') must be minimal (exact LCS / Myers shortest edit script).

import { describe, expect, it } from 'vitest';
import { diffLines } from '../src/diff/lineDiff.js';

describe('Algo Swarm #6: Minimal Line Diff Engine (Myers / LCS)', () => {
  it('computes a minimal edit script that reconstructs target lines exactly', () => {
    const before = ['a', 'b', 'c', 'd', 'e'];
    const after = ['a', 'x', 'c', 'e', 'f'];
    const script = diffLines(before, after);

    const rebuilt: string[] = [];
    let edits = 0;
    for (const step of script) {
      if (step.op === 'keep' || step.op === 'add') rebuilt.push(step.line);
      if (step.op !== 'keep') edits++;
    }
    expect(rebuilt).toEqual(after);
    expect(edits).toBe(4); // del b, add x, del d, add f
  });
});

Kernel-Verified Proof / Solution (spec/target_statements/tsaf06-line-diff.acceptance.test.ts)

// spec/target_statements/tsaf06-line-diff.acceptance.test.ts
// Frozen SpecAndTests for nd_tsaf06_myers_diff:
// Implement src/diff/lineDiff.ts exporting:
//   diffLines(before: string[], after: string[]): Array<{ op: 'keep' | 'add' | 'del'; line: string }>
// Requirements:
//   - Applying the edit script to `before` must reconstruct `after` identically.
//   - Edit distance (count of 'add' + 'del') must be minimal (exact LCS / Myers shortest edit script).

import { describe, expect, it } from 'vitest';
import { diffLines } from '../src/diff/lineDiff.js';

describe('Algo Swarm #6: Minimal Line Diff Engine (Myers / LCS)', () => {
  it('computes a minimal edit script that reconstructs target lines exactly', () => {
    const before = ['a', 'b', 'c', 'd', 'e'];
    const after = ['a', 'x', 'c', 'e', 'f'];
    const script = diffLines(before, after);

    const rebuilt: string[] = [];
    let edits = 0;
    for (const step of script) {
      if (step.op === 'keep' || step.op === 'add') rebuilt.push(step.line);
      if (step.op !== 'keep') edits++;
    }
    expect(rebuilt).toEqual(after);
    expect(edits).toBe(4); // del b, add x, del d, add f
  });
});

Verification Receipt

pass · score: 1
{
  "gate": "owner_signoff",
  "frozen_spec_sha256": "540c45ea3198b1aa74c997dbb6deae0963e345d82269d44729a334c00644dfaf",
  "require_precheck": false
}