Skip to content

armgit / Ix

Public Imported from GitHub
0

Understand any codebase instantly. System intelligence for codebases, built for humans and AI.

refactor(cli): remove dead computeLineDiff and constructor-only client test, skip properly in discovery tests (QA-06C)

KageBinary3cbeb2a0dfc9
diff --git a/ix-cli/src/cli/__tests__/diff-content.test.ts b/ix-cli/src/cli/__tests__/diff-content.test.ts
index 3901f485..e494efd9 100644
--- a/ix-cli/src/cli/__tests__/diff-content.test.ts
+++ b/ix-cli/src/cli/__tests__/diff-content.test.ts
@@ -1,51 +1,7 @@
// Copyright 2026 Ix Infrastructure Inc.
import { describe, it, expect } from "vitest";
-import * as fs from "node:fs";
-import * as path from "node:path";
-import { computeLineDiff, computeTextualDiff } from "../commands/diff.js";
-
-const diffTsPath = path.resolve(__dirname, "../commands/diff.ts");
-const diffContent = fs.readFileSync(diffTsPath, "utf-8");
-
-// ── Unit tests for computeLineDiff ──────────────────────────────────
-
-describe("computeLineDiff", () => {
- it("identical input produces all context lines", () => {
- const result = computeLineDiff("a\nb\nc", "a\nb\nc");
- expect(result).toEqual([" a", " b", " c"]);
- });
-
- it("added lines produce + prefixed lines", () => {
- const result = computeLineDiff("a\nb", "a\nb\nc");
- expect(result).toEqual([" a", " b", "+ c"]);
- });
-
- it("removed lines produce - prefixed lines", () => {
- const result = computeLineDiff("a\nb\nc", "a\nb");
- expect(result).toEqual([" a", " b", "- c"]);
- });
-
- it("modified lines produce - then + pairs", () => {
- const result = computeLineDiff("a\nold\nc", "a\nnew\nc");
- expect(result).toEqual([" a", "- old", "+ new", " c"]);
- });
-
- it("empty before produces all + lines", () => {
- const result = computeLineDiff("", "a\nb");
- expect(result).toEqual(["- ", "+ a", "+ b"]);
- });
-
- it("empty after produces - then + for first line, then - for remaining", () => {
- const result = computeLineDiff("a\nb", "");
- expect(result).toEqual(["- a", "+ ", "- b"]);
- });
-
- it("both empty produces single context line", () => {
- const result = computeLineDiff("", "");
- expect(result).toEqual([" "]);
- });
-});
+import { computeTextualDiff } from "../commands/diff.js";
// ── Unit tests for computeTextualDiff ───────────────────────────────
@@ -103,150 +59,3 @@ describe("computeTextualDiff", () => {
expect(added.some(l => l.includes("test comment"))).toBe(true);
});
});
-
-// ── Source-reading: diff.ts structure ───────────────────────────────
-
-describe("diff.ts textual diff model", () => {
- it("has computeTextualDiff using git diff --no-index", () => {
- expect(diffContent).toContain("computeTextualDiff");
- expect(diffContent).toContain("--no-index");
- });
-
- it("has loadFileAtTimestamp for full file content via git", () => {
- expect(diffContent).toContain("loadFileAtTimestamp");
- expect(diffContent).toContain("--before=");
- });
-
- it("has loadFileFromDisk for current disk content", () => {
- expect(diffContent).toContain("loadFileFromDisk");
- });
-
- it("uses git show to retrieve historical file content", () => {
- expect(diffContent).toMatch(/`\$\{hash\}:\$\{name\}`/);
- expect(diffContent).toContain('"show"');
- });
-
- it("falls back to readSourceSpan on git failure", () => {
- expect(diffContent).toContain("return readSourceSpan(node)");
- });
-
- it("has readSourceSpanAtTimestamp for span-level historical content", () => {
- expect(diffContent).toContain("readSourceSpanAtTimestamp");
- });
-
- it("formatDiffContent is async", () => {
- expect(diffContent).toContain("async function formatDiffContent");
- });
-
- it("uses await formatDiffContent at call site", () => {
- expect(diffContent).toContain("await formatDiffContent(result)");
- });
-
- it("parseDiffOutput strips git diff headers", () => {
- expect(diffContent).toContain("parseDiffOutput");
- expect(diffContent).toContain('line.startsWith("@@")');
- });
-
- it("resolves before timestamp from graph changes or patch list", () => {
- expect(diffContent).toContain("resolveFromTimestamp");
- expect(diffContent).toContain("getRevisionTimestamp");
- });
-
- it("resolves after timestamp for non-latest revisions", () => {
- expect(diffContent).toContain("resolveToTimestamp");
- });
-
- it("has loadContentAtRev for revision-aware content loading", () => {
- expect(diffContent).toContain("loadContentAtRev");
- expect(diffContent).toContain("loadFileFromDisk(fileUri)");
- expect(diffContent).toContain("loadFileAtTimestamp(fileUri, ts)");
- });
-
- it("content mode uses loadContentAtRev for both sides", () => {
- expect(diffContent).toContain('loadContentAtRev(client, fileUri, from, changes, "from")');
- expect(diffContent).toContain('loadContentAtRev(client, fileUri, to, changes, "to")');
- });
-
- it("detects textual changes when graph shows no changes", () => {
- expect(diffContent).toContain("textualChanges");
- expect(diffContent).toContain("not captured by parser");
- });
-
- it("uses computeTextualDiff for source span diffs in graph fallback", () => {
- expect(diffContent).toContain("computeTextualDiff(beforeSource, afterSource)");
- });
-
- it("uses a private temp dir under os.tmpdir for git diff --no-index and cleans it up", () => {
- expect(diffContent).toContain("os.tmpdir()");
- // Atomic private temp dir (mkdtempSync) + recursive cleanup, not predictably
- // named files in the shared tmpdir (CodeQL js/insecure-temporary-file).
- expect(diffContent).toContain("mkdtempSync");
- expect(diffContent).toContain("rmSync");
- });
-});
-
-// ── Resolver flags in diff ──────────────────────────────────────────
-
-describe("diff.ts resolver flags", () => {
- it("supports --pick option", () => {
- expect(diffContent).toContain('"--pick <n>"');
- });
-
- it("supports --kind option", () => {
- expect(diffContent).toContain('"--kind <kind>"');
- });
-
- it("supports --path option", () => {
- expect(diffContent).toContain('"--path <path>"');
- });
-
- it("passes resolver opts to resolveFileOrReport", () => {
- expect(diffContent).toContain("resolveFileOrReport(client, target, resolveOpts, opts.format)");
- });
-
- it("parses --pick as a positive integer", () => {
- expect(diffContent).toContain("parsePickOption");
- expect(diffContent).toContain("pick: opts.pick");
- });
-
- it("imports printResolved for text-mode output", () => {
- expect(diffContent).toContain("printResolved");
- });
-
- it("outputs structured JSON for ambiguous targets", () => {
- expect(diffContent).toContain("resolveFileOrReport");
- });
-});
-
-// ── Symbol diff body extraction ─────────────────────────────────────
-
-describe("diff.ts symbol diff correctness", () => {
- it("has getSymbolSpans for before/after line ranges", () => {
- expect(diffContent).toContain("getSymbolSpans");
- expect(diffContent).toContain("symbolSpans.before");
- expect(diffContent).toContain("symbolSpans.after");
- });
-
- it("extracts symbol body via sliceContent", () => {
- expect(diffContent).toContain("sliceContent");
- expect(diffContent).toContain("sliceContent(beforeFile");
- expect(diffContent).toContain("sliceContent(afterFile");
- });
-
- it("diffs symbol bodies directly instead of slicing hunks", () => {
- // Symbol diff computes textual diff on extracted bodies, not sliced file hunks
- expect(diffContent).toContain("computeTextualDiff(beforeBody, afterBody)");
- });
-
- it("keeps file diff separate from symbol diff", () => {
- // File targets diff the whole file
- expect(diffContent).toContain("computeTextualDiff(beforeFile, afterFile)");
- // Symbol targets use extracted bodies
- expect(diffContent).toContain("computeTextualDiff(beforeBody, afterBody)");
- });
-
- it("reports correct diffMode for file vs symbol", () => {
- expect(diffContent).toContain('diffMode = "symbol"');
- expect(diffContent).toContain('diffMode = "file"');
- });
-});
diff --git a/ix-cli/src/cli/__tests__/diff-mode-conflict.test.ts b/ix-cli/src/cli/__tests__/diff-mode-conflict.test.ts
index 1b2eef1b..6b8b6e23 100644
--- a/ix-cli/src/cli/__tests__/diff-mode-conflict.test.ts
+++ b/ix-cli/src/cli/__tests__/diff-mode-conflict.test.ts
@@ -3,7 +3,7 @@
/**
* diff-mode-conflict.test.ts — Mutation-verified tests for diff.ts
*
- * Tests detectDiffModeConflict, computeLineDiff, and mergeDiffOptions with
+ * Tests detectDiffModeConflict, mergeDiffOptions, and loadFileFromDisk with
* assertions strong enough to survive adversarial mutation testing.
*
* Every assertion is discriminating: if you swap the conflict branches, invert
@@ -27,7 +27,6 @@ import { join } from "node:path";
import { describe, expect, it, afterEach, beforeEach } from "vitest";
import {
detectDiffModeConflict,
- computeLineDiff,
loadFileFromDisk,
type DiffModeOptions,
} from "../commands/diff.js";
@@ -201,73 +200,6 @@ describe("detectDiffModeConflict", () => {
});
});
-// ══════════════════════════════════════════════════════════════════════
-// computeLineDiff — pure function, no side effects
-// ══════════════════════════════════════════════════════════════════════
-
-describe("computeLineDiff", () => {
- it("identical single lines produce one context line", () => {
- const result = computeLineDiff("hello", "hello");
- expect(result).toEqual([" hello"]);
- });
-
- it("added line: before empty, after has content", () => {
- // Empty string splits to [""] — one empty line. The implementation
- // diffs it against "new line" so both a removal and addition appear.
- const result = computeLineDiff("", "new line");
- expect(result).toEqual(["- ", "+ new line"]);
- });
-
- it("removed line: before has content, after empty", () => {
- // Empty string splits to [""] — one empty line. The implementation
- // diffs "old line" against it so both a removal and addition appear.
- const result = computeLineDiff("old line", "");
- expect(result).toEqual(["- old line", "+ "]);
- });
-
- it("changed line: old removed, new added", () => {
- const result = computeLineDiff("before", "after");
- expect(result).toEqual(["- before", "+ after"]);
- });
-
- it("multiple lines: mixed context, additions, and removals", () => {
- const before = "line1\nline2\nline3";
- const after = "line1\nline2-new\nline3";
- const result = computeLineDiff(before, after);
- expect(result).toEqual([
- " line1",
- "- line2",
- "+ line2-new",
- " line3",
- ]);
- });
-
- it("handles different-length inputs (extra lines added)", () => {
- const before = "a";
- const after = "a\nb\nc";
- const result = computeLineDiff(before, after);
- expect(result).toEqual([" a", "+ b", "+ c"]);
- });
-
- it("handles different-length inputs (extra lines removed)", () => {
- const before = "x\ny\nz";
- const after = "x";
- const result = computeLineDiff(before, after);
- expect(result).toEqual([" x", "- y", "- z"]);
- });
-
- it("both empty produces a single context line (empty line)", () => {
- // "".split("\n") = [""]" — one element. Both sides identical → context.
- const result = computeLineDiff("", "");
- expect(result).toEqual([" "]);
- });
-
- it("preserves leading/trailing whitespace in lines", () => {
- const result = computeLineDiff(" indented", " indented");
- expect(result).toEqual([" indented"]);
- });
-});
-
// ══════════════════════════════════════════════════════════════════════
// mergeDiffOptions — pure function, no side effects
// ══════════════════════════════════════════════════════════════════════
@@ -403,52 +335,3 @@ describe("loadFileFromDisk", () => {
expect(loadFileFromDisk(join(tmpDir, "no", "such", "dir", "file.txt"), tmpDir)).toBeNull();
});
});
-
-// ══════════════════════════════════════════════════════════════════════
-// computeLineDiff — additional edge cases
-// ══════════════════════════════════════════════════════════════════════
-
-describe("computeLineDiff edge cases", () => {
- it("single line changed to different single line", () => {
- const result = computeLineDiff("foo", "bar");
- expect(result).toEqual(["- foo", "+ bar"]);
- });
-
- it("identical multi-line content", () => {
- const content = "a\nb\nc";
- const result = computeLineDiff(content, content);
- expect(result).toEqual([" a", " b", " c"]);
- });
-
- it("all lines changed (no context)", () => {
- const result = computeLineDiff("x\ny", "a\nb");
- expect(result).toEqual(["- x", "+ a", "- y", "+ b"]);
- });
-
- it("lines with only whitespace differences", () => {
- const result = computeLineDiff(" indented", " more-indented");
- expect(result).toEqual(["- indented", "+ more-indented"]);
- });
-
- it("handles Windows-style line endings (split on \n only)", () => {
- const result = computeLineDiff("a\r\nb", "a\r\nc");
- // \r is preserved as part of the line content
- expect(result).toEqual([" a\r", "- b", "+ c"]);
- });
-
- it("very long line (no truncation)", () => {
- const long = "x".repeat(10000);
- const result = computeLineDiff(long, long);
- expect(result).toEqual([" " + long]);
- });
-
- it("before longer than after: extra lines removed at end", () => {
- const result = computeLineDiff("a\nb\nc\nd", "a\nb");
- expect(result).toEqual([" a", " b", "- c", "- d"]);
- });
-
- it("after longer than before: extra lines added at end", () => {
- const result = computeLineDiff("a\nb", "a\nb\nc\nd");
- expect(result).toEqual([" a", " b", "+ c", "+ d"]);
- });
-});
diff --git a/ix-cli/src/cli/__tests__/ingest-discovery.test.ts b/ix-cli/src/cli/__tests__/ingest-discovery.test.ts
index dc81a0de..411a1398 100644
--- a/ix-cli/src/cli/__tests__/ingest-discovery.test.ts
+++ b/ix-cli/src/cli/__tests__/ingest-discovery.test.ts
@@ -99,7 +99,7 @@ describe('discovery symlink containment', () => {
it.skipIf(process.platform === 'win32')(
'drops a committed symlink that leaves the repository',
- () => {
+ (ctx) => {
const repo = scratchDir('ix-repo-');
const outside = scratchDir('ix-outside-');
const secret = join(outside, 'secret.ts');
@@ -114,7 +114,7 @@ describe('discovery symlink containment', () => {
execFileSync('git', ['init', '-q'], { cwd: repo });
execFileSync('git', ['add', '-A'], { cwd: repo });
} catch {
- return; // no git, or no permission to symlink — nothing to assert
+ return ctx.skip('no git, or no permission to symlink');
}
const listed = tryGitLsFiles(repo, true);
@@ -135,7 +135,7 @@ describe('discovery symlink containment', () => {
},
);
- it('skips generated dependency lockfiles that expand into oversized graph patches', () => {
+ it('skips generated dependency lockfiles that expand into oversized graph patches', (ctx) => {
// Ix#523: a 646 KB `package-lock.json` is under MAX_FILE_BYTES but its
// patch is over the proxy's body limit, so the commit 413s and the map
// exits non-zero with no completion baseline.
@@ -156,7 +156,7 @@ describe('discovery symlink containment', () => {
try {
execFileSync('git', ['init', '-q'], { cwd: repo });
} catch {
- return; // no git — nothing to assert
+ return ctx.skip('no git');
}
const listed = tryGitLsFiles(repo, true);
@@ -172,7 +172,7 @@ describe('discovery symlink containment', () => {
it.skipIf(process.platform === 'win32')(
'still discovers everything when the root is reached through a symlink',
- () => {
+ (ctx) => {
// Resolving the file but not the root drops every file and reports the
// repository as empty. No CI runner here has a symlinked root (the matrix
// is ubuntu + windows), so this test is the only thing holding it down.
@@ -184,7 +184,7 @@ describe('discovery symlink containment', () => {
try {
symlinkSync(real, link, 'dir');
} catch {
- return; // no permission to symlink — nothing to assert
+ return ctx.skip('no permission to symlink');
}
const discovery = discoverIngestFilePaths([join(link, 'src', 'app.ts')], link);
@@ -206,7 +206,7 @@ describe('discovery symlink containment', () => {
it.skipIf(process.platform === 'win32')(
'keeps a symlink that stays inside the repository',
- () => {
+ (ctx) => {
// Monorepos link packages around inside the tree. Confinement must not
// turn into "no symlinks at all".
const repo = scratchDir('ix-repo-');
@@ -218,7 +218,7 @@ describe('discovery symlink containment', () => {
execFileSync('git', ['init', '-q'], { cwd: repo });
execFileSync('git', ['add', '-A'], { cwd: repo });
} catch {
- return; // no git, or no permission to symlink — nothing to assert
+ return ctx.skip('no git, or no permission to symlink');
}
const canonical = dedupeDiscoveredFilePaths(tryGitLsFiles(repo, true) ?? []);
diff --git a/ix-cli/src/cli/commands/diff.ts b/ix-cli/src/cli/commands/diff.ts
index 614c3dcb..67e48733 100644
--- a/ix-cli/src/cli/commands/diff.ts
+++ b/ix-cli/src/cli/commands/diff.ts
@@ -112,30 +112,6 @@ function renderDiffSummaryLlm(result: any): string {
const execFileAsync = promisify(execFile);
-// ── Line-level diff (legacy, kept for backward compat) ─────────────
-
-/** Simple sequential line diff producing `+ `, `- `, ` ` prefixed lines. */
-export function computeLineDiff(before: string, after: string): string[] {
- const beforeLines = before.split("\n");
- const afterLines = after.split("\n");
- const result: string[] = [];
- const maxLen = Math.max(beforeLines.length, afterLines.length);
-
- for (let i = 0; i < maxLen; i++) {
- const bLine = i < beforeLines.length ? beforeLines[i] : undefined;
- const aLine = i < afterLines.length ? afterLines[i] : undefined;
-
- if (bLine === aLine) {
- result.push(` ${bLine}`);
- } else {
- if (bLine !== undefined) result.push(`- ${bLine}`);
- if (aLine !== undefined) result.push(`+ ${aLine}`);
- }
- }
-
- return result;
-}
-
// ── JSON compaction ────────────────────────────────────────────────
/** Compact a node snapshot from a diff change — drop timestamps, null deletedRev, member_files UUIDs. */
diff --git a/ix-cli/test/client.test.ts b/ix-cli/test/client.test.ts
deleted file mode 100644
index 9159a55d..00000000
--- a/ix-cli/test/client.test.ts
+++ /dev/null
@@ -1,16 +0,0 @@
-// Copyright 2026 Ix Infrastructure Inc.
-
-import { describe, it, expect } from "vitest";
-import { IxClient } from "../src/client/api.js";
-
-describe("IxClient", () => {
- it("should construct with default endpoint", () => {
- const client = new IxClient();
- expect(client).toBeDefined();
- });
-
- it("should construct with custom endpoint", () => {
- const client = new IxClient("http://localhost:9090");
- expect(client).toBeDefined();
- });
-});