From 53d5eb7020cea0dcff72022e08a302b3e2efbf6c Mon Sep 17 00:00:00 2001 From: Nick Barry Date: Mon, 23 Jun 2025 14:51:21 -0600 Subject: [PATCH 1/3] add failing symlinked git dir test --- test/fixtures/test_stage.ts | 8 ++++++++ test/integrations/symlinks.ts | 14 ++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 test/integrations/symlinks.ts diff --git a/test/fixtures/test_stage.ts b/test/fixtures/test_stage.ts index 7c6eb8a..b6dbd37 100644 --- a/test/fixtures/test_stage.ts +++ b/test/fixtures/test_stage.ts @@ -43,10 +43,18 @@ export class TestStage extends Stage { fs.mkdirSync(this.resolve(relativePath), { recursive: true }); } + public rename(relativeOldPath: string, relativeNewPath: string) { + fs.renameSync(this.resolve(relativeOldPath), this.resolve(relativeNewPath)); + } + public rm(relativePath: string) { fs.rmSync(this.resolve(relativePath), { recursive: true, force: true }); } + public symlink(relativeTarget: string, relativePath: string) { + fs.symlinkSync(this.resolve(relativeTarget), this.resolve(relativePath)); + } + public async execStaged(tasks: ExecStagedUserConfig): Promise { return await execStaged(this.cwd, tasks, TEST_STAGE_OPTIONS); } diff --git a/test/integrations/symlinks.ts b/test/integrations/symlinks.ts new file mode 100644 index 0000000..917102e --- /dev/null +++ b/test/integrations/symlinks.ts @@ -0,0 +1,14 @@ +import { TASK_EXIT_0 } from '../fixtures/tasks'; +import { TestStage } from '../fixtures/test_stage'; +import assert from 'node:assert'; +import { describe, it } from 'node:test'; + +describe('symlinks', () => { + it('runs with symlinked git directory', async () => { + const stage = TestStage.create(); + stage.rename('.git', '.git-symlinked'); + stage.symlink('.git-symlinked', '.git'); + + assert.equal(await stage.execStaged([TASK_EXIT_0]), true); + }); +}); From 70c5857c75597c63d824e87687f5102e20e1a845 Mon Sep 17 00:00:00 2001 From: Nick Barry Date: Fri, 26 Sep 2025 15:49:15 -0600 Subject: [PATCH 2/3] use rename helper for renamed files tests --- test/stage.ts | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/test/stage.ts b/test/stage.ts index ee4cd84..dbfc49e 100644 --- a/test/stage.ts +++ b/test/stage.ts @@ -149,8 +149,7 @@ describe('Stage', () => { stage.writeFile('test.old', 'contents'); stage.git(['add', 'test.old']); stage.git(['commit', '-m', 'add file']); - stage.rm('test.old'); - stage.writeFile('test.new', 'contents'); + stage.rename('test.old', 'test.new'); stage.git(['add', 'test.old', 'test.new']); stage.prepare(); @@ -246,8 +245,7 @@ describe('Stage', () => { stage.writeFile('test.old', 'contents'); stage.git(['add', 'test.old']); stage.git(['commit', '-m', 'add file']); - stage.rm('test.old'); - stage.writeFile('test.new', 'contents'); + stage.rename('test.old', 'test.new'); stage.git(['add', 'test.old', 'test.new']); assert.equal( @@ -378,8 +376,7 @@ describe('Stage', () => { stage.writeFile('test.old', 'contents'); stage.git(['add', 'test.old']); stage.git(['commit', '-m', 'add file']); - stage.rm('test.old'); - stage.writeFile('test.new', 'contents'); + stage.rename('test.old', 'test.new'); stage.git(['add', 'test.old', 'test.new']); stage.prepare(); @@ -641,8 +638,7 @@ describe('Stage', () => { stage.writeFile('test.old', 'contents'); stage.git(['add', 'test.old']); stage.git(['commit', '-m', 'add file']); - stage.rm('test.old'); - stage.writeFile('test.new', 'contents'); + stage.rename('test.old', 'test.new'); stage.git(['add', 'test.old', 'test.new']); const oldStatus = stage.git(['status', '-z']); @@ -914,8 +910,7 @@ describe('Stage', () => { stage.writeFile('test.old', 'contents'); stage.git(['add', 'test.old']); stage.git(['commit', '-m', 'add file']); - stage.rm('test.old'); - stage.writeFile('test.new', 'contents'); + stage.rename('test.old', 'test.new'); stage.git(['add', 'test.old', 'test.new']); const oldStatus = stage.git(['status', '-z']); From ea5749d1acd5b345abd1e327376ef347c2c578a3 Mon Sep 17 00:00:00 2001 From: Nick Barry Date: Fri, 26 Sep 2025 18:05:16 -0600 Subject: [PATCH 3/3] test symlined config file --- test/integrations/symlinks.ts | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/test/integrations/symlinks.ts b/test/integrations/symlinks.ts index 917102e..7a77128 100644 --- a/test/integrations/symlinks.ts +++ b/test/integrations/symlinks.ts @@ -1,9 +1,34 @@ -import { TASK_EXIT_0 } from '../fixtures/tasks'; +import { TASK_EXIT_0, TASK_EXIT_1 } from '../fixtures/tasks'; import { TestStage } from '../fixtures/test_stage'; import assert from 'node:assert'; +import child_process from 'node:child_process'; +import path from 'node:path'; import { describe, it } from 'node:test'; +const BIN = path.resolve(import.meta.dirname, '../../dist/bin/cli.js'); + describe('symlinks', () => { + it('runs with symlinked config file', async () => { + const stage = TestStage.create(); + stage.writeFile( + 'symlinked.config.ts', + `export default ['${TASK_EXIT_1}'];`, + ); + stage.symlink('symlinked.config.ts', 'exec-staged.config.ts'); + + const child = child_process.spawn('node', [BIN], { + cwd: stage.cwd, + }); + + const closed = new Promise((resolve) => { + child.once('close', () => resolve()); + }); + + await closed; + + assert.equal(child.exitCode, 1); + }); + it('runs with symlinked git directory', async () => { const stage = TestStage.create(); stage.rename('.git', '.git-symlinked');