Skip to content

Commit a1a7daf

Browse files
committed
debug logs
1 parent 9791d05 commit a1a7daf

File tree

2 files changed

+137
-3
lines changed

2 files changed

+137
-3
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
- run: pnpm build
3232
- run: pnpm lint
3333
- run: pnpm format:check
34-
- run: pnpm test:integration
34+
- run: pnpm test:integration --testPathPattern="git"
3535
env:
3636
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3737
HEAD_OID: ${{ github.base_ref }}

src/test/integration/git.test.ts

Lines changed: 136 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,28 @@ const makeFileChanges = async (
170170
changegroup === "with-unchanged-symlink" ||
171171
changegroup === "with-changed-symlink"
172172
) {
173+
console.log("[DEBUG makeFileChanges] Creating some-dir directory");
173174
await fs.promises.mkdir(path.join(repoDirectory, "some-dir"), {
174175
recursive: true,
175176
});
177+
console.log(
178+
"[DEBUG makeFileChanges] Creating symlink ../README.md -> some-dir/nested",
179+
);
176180
await fs.promises.symlink(
177181
"../README.md",
178182
path.join(repoDirectory, "some-dir", "nested"),
179183
);
184+
185+
// Verify symlink was created
186+
const createdTarget = await fs.promises.readlink(
187+
path.join(repoDirectory, "some-dir", "nested"),
188+
);
189+
console.log(
190+
"[DEBUG makeFileChanges] Symlink created, target:",
191+
createdTarget,
192+
);
193+
194+
console.log("[DEBUG makeFileChanges] Setting git config user.email");
180195
await new Promise<void>((resolve) => {
181196
execFile(
182197
"git",
@@ -185,6 +200,7 @@ const makeFileChanges = async (
185200
() => resolve(),
186201
);
187202
});
203+
console.log("[DEBUG makeFileChanges] Setting git config user.name");
188204
await new Promise<void>((resolve) => {
189205
execFile(
190206
"git",
@@ -193,19 +209,54 @@ const makeFileChanges = async (
193209
() => resolve(),
194210
);
195211
});
212+
console.log("[DEBUG makeFileChanges] git.add some-dir/nested");
196213
await git.add({
197214
fs,
198215
dir: repoDirectory,
199216
filepath: "some-dir/nested",
200217
});
201-
await git.commit({
218+
console.log("[DEBUG makeFileChanges] git.commit 'Add symlink'");
219+
const commitResult = await git.commit({
202220
fs,
203221
dir: repoDirectory,
204222
message: "Add symlink",
205223
author: { name: "Test", email: "test@test.com" },
206224
});
225+
console.log("[DEBUG makeFileChanges] Commit created:", commitResult);
226+
227+
// Verify the symlink is in the commit
228+
const commitObj = await git.readCommit({
229+
fs,
230+
dir: repoDirectory,
231+
oid: commitResult,
232+
});
233+
const tree = await git.readTree({
234+
fs,
235+
dir: repoDirectory,
236+
oid: commitObj.commit.tree,
237+
});
238+
const someDirEntry = tree.tree.find((e) => e.path === "some-dir");
239+
console.log(
240+
"[DEBUG makeFileChanges] some-dir entry after commit:",
241+
JSON.stringify(someDirEntry),
242+
);
243+
if (someDirEntry) {
244+
const someDirTree = await git.readTree({
245+
fs,
246+
dir: repoDirectory,
247+
oid: someDirEntry.oid,
248+
});
249+
const nestedEntry = someDirTree.tree.find((e) => e.path === "nested");
250+
console.log(
251+
"[DEBUG makeFileChanges] some-dir/nested entry after commit:",
252+
JSON.stringify(nestedEntry),
253+
);
254+
}
207255

208256
if (changegroup === "with-changed-symlink") {
257+
console.log(
258+
"[DEBUG makeFileChanges] Changing symlink target to ../LICENSE",
259+
);
209260
await fs.promises.rm(path.join(repoDirectory, "some-dir", "nested"));
210261
await fs.promises.symlink(
211262
"../LICENSE",
@@ -373,13 +424,16 @@ describe("git", () => {
373424
});
374425
}
375426

376-
it(`should allow unchanged symlinks without throwing`, async () => {
427+
it.only(`should allow unchanged symlinks without throwing`, async () => {
377428
const branch = `${TEST_BRANCH_PREFIX}-unchanged-symlink`;
378429
branches.push(branch);
379430

431+
console.log("[DEBUG] Step 1: Creating test directory");
380432
await fs.promises.mkdir(testDir, { recursive: true });
381433
const repoDirectory = path.join(testDir, `repo-unchanged-symlink`);
434+
console.log("[DEBUG] repoDirectory:", repoDirectory);
382435

436+
console.log("[DEBUG] Step 2: Cloning repo");
383437
await new Promise<void>((resolve, reject) => {
384438
const p = execFile(
385439
"git",
@@ -396,13 +450,90 @@ describe("git", () => {
396450
p.stdout?.pipe(process.stdout);
397451
p.stderr?.pipe(process.stderr);
398452
});
453+
console.log("[DEBUG] Step 2 done: Clone completed");
399454

455+
console.log("[DEBUG] Step 3: Calling makeFileChanges");
400456
await makeFileChanges(repoDirectory, "with-unchanged-symlink");
457+
console.log("[DEBUG] Step 3 done: makeFileChanges completed");
458+
459+
// Log symlink info
460+
const symlinkPath = path.join(repoDirectory, "some-dir", "nested");
461+
console.log("[DEBUG] Step 4: Checking symlink state");
462+
try {
463+
const symlinkTarget = await fs.promises.readlink(symlinkPath);
464+
console.log("[DEBUG] Symlink target:", symlinkTarget);
465+
const symlinkStat = await fs.promises.lstat(symlinkPath);
466+
console.log(
467+
"[DEBUG] Symlink lstat mode:",
468+
symlinkStat.mode.toString(8),
469+
);
470+
} catch (e) {
471+
console.log("[DEBUG] Error reading symlink:", e);
472+
}
473+
474+
// Log git status
475+
console.log("[DEBUG] Step 5: Git status in cloned repo");
476+
const gitStatus = await git.statusMatrix({ fs, dir: repoDirectory });
477+
const changedFiles = gitStatus.filter(
478+
([, head, workdir, stage]) =>
479+
head !== workdir || head !== stage || workdir !== stage,
480+
);
481+
console.log("[DEBUG] Changed files count:", changedFiles.length);
482+
console.log(
483+
"[DEBUG] Changed files:",
484+
JSON.stringify(changedFiles.slice(0, 20)),
485+
);
486+
487+
// Log HEAD commit and symlink oid
488+
console.log("[DEBUG] Step 6: Getting HEAD commit info");
489+
const headCommit = await git.resolveRef({
490+
fs,
491+
dir: repoDirectory,
492+
ref: "HEAD",
493+
});
494+
console.log("[DEBUG] HEAD commit:", headCommit);
495+
496+
try {
497+
const commitObj = await git.readCommit({
498+
fs,
499+
dir: repoDirectory,
500+
oid: headCommit,
501+
});
502+
console.log("[DEBUG] HEAD tree:", commitObj.commit.tree);
503+
504+
// Try to get the symlink entry from the tree
505+
const tree = await git.readTree({
506+
fs,
507+
dir: repoDirectory,
508+
oid: commitObj.commit.tree,
509+
});
510+
const someDirEntry = tree.tree.find((e) => e.path === "some-dir");
511+
console.log(
512+
"[DEBUG] some-dir entry in tree:",
513+
JSON.stringify(someDirEntry),
514+
);
515+
516+
if (someDirEntry) {
517+
const someDirTree = await git.readTree({
518+
fs,
519+
dir: repoDirectory,
520+
oid: someDirEntry.oid,
521+
});
522+
const nestedEntry = someDirTree.tree.find((e) => e.path === "nested");
523+
console.log(
524+
"[DEBUG] some-dir/nested entry in tree:",
525+
JSON.stringify(nestedEntry),
526+
);
527+
}
528+
} catch (e) {
529+
console.log("[DEBUG] Error reading commit/tree:", e);
530+
}
401531

402532
// The symlink was committed locally and is unchanged in workdir.
403533
// The tree walk should skip it since oids match.
404534
// GitHub push may fail because local commit doesn't exist on GitHub,
405535
// but the key is that no symlink error is thrown.
536+
console.log("[DEBUG] Step 7: Calling commitChangesFromRepo");
406537
try {
407538
await commitChangesFromRepo({
408539
octokit,
@@ -416,9 +547,12 @@ describe("git", () => {
416547
log,
417548
});
418549

550+
console.log("[DEBUG] Step 7 done: commitChangesFromRepo succeeded");
419551
await waitForGitHubToBeReady();
420552
await makeFileChangeAssertions(branch);
421553
} catch (error) {
554+
console.log("[DEBUG] Step 7 error:", (error as Error).message);
555+
console.log("[DEBUG] Full error:", error);
422556
expect((error as Error).message).not.toContain("Unexpected symlink");
423557
expect((error as Error).message).not.toContain("Unexpected executable");
424558
}

0 commit comments

Comments
 (0)