Skip to content

armgit / Ix

Public Imported from GitHub
0

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

fix: skip generated dependency lockfiles (#529)

Hiro-Chibab9f7b639f71e
diff --git a/ix-cli/src/cli/__tests__/ingest-discovery.test.ts b/ix-cli/src/cli/__tests__/ingest-discovery.test.ts
index 6fb40e26..d37cec42 100644
--- a/ix-cli/src/cli/__tests__/ingest-discovery.test.ts
+++ b/ix-cli/src/cli/__tests__/ingest-discovery.test.ts
@@ -1,7 +1,7 @@
import { execFileSync } from 'node:child_process';
import { mkdirSync, mkdtempSync, realpathSync, rmSync, symlinkSync, writeFileSync } from 'node:fs';
import { tmpdir } from 'node:os';
-import { join } from 'node:path';
+import { basename, join } from 'node:path';
import { afterEach, describe, expect, it } from 'vitest';
@@ -145,6 +145,41 @@ describe('discovery symlink containment', () => {
},
);
+ it('skips generated dependency lockfiles that expand into oversized graph patches', () => {
+ // 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.
+ //
+ // Asserted through `tryGitLsFiles` — the listing `runIngest` actually
+ // discovers from — rather than by handing `discoverIngestFilePaths` a
+ // literal list. That function confines paths to the root; it is not where
+ // generated files are dropped, so an assertion there would pass while the
+ // real discovery path still yielded the lockfile.
+ const repo = scratchDir('ix-lockfile-');
+ writeFileSync(join(repo, 'package.json'), '{"name":"pkg"}\n');
+ writeFileSync(join(repo, 'package-lock.json'), '{"lockfileVersion":3}\n');
+ writeFileSync(join(repo, 'npm-shrinkwrap.json'), '{"lockfileVersion":3}\n');
+ writeFileSync(join(repo, 'pnpm-lock.yaml'), 'lockfileVersion: 9\n');
+ writeFileSync(join(repo, 'packages.lock.json'), '{"version":1}\n');
+ mkdirSync(join(repo, 'src'), { recursive: true });
+ writeFileSync(join(repo, 'src', 'index.ts'), 'export const ok = 1;\n');
+ try {
+ execFileSync('git', ['init', '-q'], { cwd: repo });
+ } catch {
+ return; // no git — nothing to assert
+ }
+
+ const listed = tryGitLsFiles(repo, true);
+ expect(listed).not.toBeNull();
+ // Basenames, not full paths: `scratchDir` realpaths its temp directory and
+ // `tryGitLsFiles` canonicalizes independently, and on a Windows runner
+ // those disagree on how to spell the same directory (`RUNNER~1` vs
+ // `runneradmin`). Which files survived is the claim; how the path spells
+ // their parent is not.
+ expect(listed!.map((filePath) => basename(filePath)).sort())
+ .toEqual(['index.ts', 'package.json']);
+ });
+
it.skipIf(process.platform === 'win32')(
'still discovers everything when the root is reached through a symlink',
() => {
diff --git a/ix-cli/src/cli/commands/ingest.ts b/ix-cli/src/cli/commands/ingest.ts
index abb2c494..b979d359 100644
--- a/ix-cli/src/cli/commands/ingest.ts
+++ b/ix-cli/src/cli/commands/ingest.ts
@@ -113,7 +113,25 @@ const GENERATED_FILE_PREFIXES = [
'mock_', // gomock convention
];
+// Generated dependency lockfiles, matched whole. Only the ones whose extension
+// SUPPORTED_EXTENSIONS actually discovers are listed: `yarn.lock`,
+// `composer.lock`, `Cargo.lock`, `Gemfile.lock`, `poetry.lock` and friends end
+// in `.lock`, which is not a discovered extension, so they never reach here.
+// A lockfile well under MAX_FILE_BYTES still expands into a graph patch larger
+// than a proxy will accept — 646 KB was enough for an HTTP 413 (Ix#523) — and
+// it describes a resolved dependency snapshot, not architecture.
+const GENERATED_FILE_NAMES = new Set([
+ 'package-lock.json', // npm
+ 'npm-shrinkwrap.json', // npm, published form
+ 'pnpm-lock.yaml', // pnpm
+ 'packages.lock.json', // NuGet
+]);
+
function isGeneratedFile(basename: string): boolean {
+ // Lowercased for the name match alone: `isSupportedSourceFile` lowercases
+ // too, so on a case-insensitive filesystem a `Package-lock.json` is
+ // discovered and would otherwise slip past a case-sensitive comparison.
+ if (GENERATED_FILE_NAMES.has(basename.toLowerCase())) return true;
for (const suffix of GENERATED_FILE_SUFFIXES) {
if (basename.endsWith(suffix)) return true;
}