MCPcopy Create free account
hub / github.com/garrytan/gstack / runHelper

Function runHelper

test/setup-windows-fallback.test.ts:69–100  ·  view source on GitHub ↗
(
    isWindows: '0' | '1',
    srcKind: 'file' | 'dir',
  )

Source from the content-addressed store, hash-verified

67 // Source the helper into a temp shell with IS_WINDOWS set and exercise
68 // each cell of the file/dir × Windows/Unix matrix.
69 function runHelper(
70 isWindows: '0' | '1',
71 srcKind: 'file' | 'dir',
72 ): { ok: boolean; targetIsSymlink: boolean; targetExists: boolean; stderr: string } {
73 const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'gstack-helper-'));
74 try {
75 const src = path.join(tmp, 'source');
76 const dst = path.join(tmp, 'dest');
77 if (srcKind === 'file') {
78 fs.writeFileSync(src, 'hello\n');
79 } else {
80 fs.mkdirSync(src);
81 fs.writeFileSync(path.join(src, 'inner.txt'), 'hello\n');
82 }
83 const helper = extractHelper();
84 // IS_WINDOWS must exist as a shell-readable var before sourcing.
85 const script = `IS_WINDOWS=${isWindows}\n${helper}\n_link_or_copy "${src}" "${dst}"\n`;
86 const result = spawnSync('bash', ['-c', script], {
87 encoding: 'utf-8',
88 timeout: 5000,
89 });
90 const lst = fs.lstatSync(dst, { throwIfNoEntry: false });
91 return {
92 ok: result.status === 0,
93 targetIsSymlink: lst?.isSymbolicLink() ?? false,
94 targetExists: lst !== undefined,
95 stderr: result.stderr,
96 };
97 } finally {
98 fs.rmSync(tmp, { recursive: true, force: true });
99 }
100 }
101
102 test('IS_WINDOWS=0 + file → symlink (existing Unix behavior)', () => {
103 const r = runHelper('0', 'file');

Callers 1

Calls 2

spawnSyncFunction · 0.85
extractHelperFunction · 0.70

Tested by

no test coverage detected