This commit is contained in:
Greg Jackson 2026-08-15 18:28:50 -04:00 committed by GitHub
commit f504ff42d1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 51 additions and 0 deletions

View File

@ -0,0 +1,51 @@
/**
* Static invariant: runtime sidecar roots (codex, factory, opencode) that link
* bin/ MUST also link lib/, because bin/ scripts import from ../lib/ via
* relative paths (e.g. gstack-learnings-log imports lib/jsonl-store.ts).
*
* Without lib/ beside bin/ in the sidecar, those imports resolve to nothing and
* the script crashes at runtime.
*
* Issue: #2305
*/
import { describe, test, expect } from 'bun:test';
import * as fs from 'fs';
import * as path from 'path';
const SETUP = fs.readFileSync(path.join(import.meta.dir, '..', 'setup'), 'utf-8');
describe('setup links lib/ beside bin/ in runtime sidecars', () => {
const SIDECAR_VARS = ['codex_gstack', 'factory_gstack', 'opencode_gstack'];
for (const sidecar of SIDECAR_VARS) {
test(`${sidecar} links lib/ when bin/ is linked`, () => {
const binPattern = new RegExp(
`_link_or_copy "\\$gstack_dir/bin" "\\$${sidecar}/bin"`,
);
const libPattern = new RegExp(
`_link_or_copy "\\$gstack_dir/lib" "\\$${sidecar}/lib"`,
);
const hasBin = binPattern.test(SETUP);
const hasLib = libPattern.test(SETUP);
expect(hasBin).toBe(true);
expect(hasLib).toBe(true);
});
}
test('lib/ link uses _link_or_copy (not raw ln)', () => {
const libLines = SETUP.split('\n').filter(
(l) => l.includes('/lib"') && /\bln\s+-/.test(l),
);
expect(libLines).toEqual([]);
});
test('lib/ link is guarded by -d check', () => {
const libGuards = SETUP.split('\n').filter((l) =>
l.includes('if [ -d "$gstack_dir/lib" ]'),
);
expect(libGuards.length).toBeGreaterThanOrEqual(3);
});
});