fix: use workspace links for runner shared package (#198)
This commit is contained in:
@@ -3,34 +3,58 @@ import path from 'path';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
type PackageJson = {
|
||||
dependencies?: Record<string, string>;
|
||||
scripts?: Record<string, string>;
|
||||
workspaces?: string[];
|
||||
};
|
||||
|
||||
function readPackageJson(relativePath: string): PackageJson {
|
||||
return JSON.parse(
|
||||
fs.readFileSync(path.resolve(import.meta.dirname, relativePath), 'utf8'),
|
||||
) as PackageJson;
|
||||
}
|
||||
|
||||
describe('deploy script', () => {
|
||||
it('refreshes root file dependencies after pulling and after building shared dist', () => {
|
||||
const packageJson = JSON.parse(
|
||||
fs.readFileSync(
|
||||
path.resolve(import.meta.dirname, '../package.json'),
|
||||
'utf8',
|
||||
),
|
||||
) as PackageJson;
|
||||
it('refreshes workspace dependencies after pulling before building', () => {
|
||||
const packageJson = readPackageJson('../package.json');
|
||||
|
||||
const deploy = packageJson.scripts?.deploy ?? '';
|
||||
const pullIndex = deploy.indexOf('git pull --ff-only');
|
||||
const firstRootInstallIndex = deploy.indexOf(
|
||||
'bun install --frozen-lockfile',
|
||||
);
|
||||
const rootInstallIndex = deploy.indexOf('bun install --frozen-lockfile');
|
||||
const buildIndex = deploy.indexOf('bun run build:all');
|
||||
const secondRootInstallIndex = deploy.indexOf(
|
||||
'bun install --frozen-lockfile',
|
||||
firstRootInstallIndex + 1,
|
||||
);
|
||||
const verifyIndex = deploy.indexOf('bun run verify:dist');
|
||||
|
||||
expect(pullIndex).toBeGreaterThanOrEqual(0);
|
||||
expect(firstRootInstallIndex).toBeGreaterThan(pullIndex);
|
||||
expect(firstRootInstallIndex).toBeLessThan(buildIndex);
|
||||
expect(secondRootInstallIndex).toBeGreaterThan(buildIndex);
|
||||
expect(secondRootInstallIndex).toBeLessThan(verifyIndex);
|
||||
expect(rootInstallIndex).toBeGreaterThan(pullIndex);
|
||||
expect(rootInstallIndex).toBeLessThan(buildIndex);
|
||||
expect(
|
||||
deploy.indexOf('bun install --frozen-lockfile', rootInstallIndex + 1),
|
||||
).toBe(-1);
|
||||
});
|
||||
|
||||
it('uses workspace links for shared runner code instead of copied file dependencies', () => {
|
||||
const rootPackageJson = readPackageJson('../package.json');
|
||||
const agentRunnerPackageJson = readPackageJson(
|
||||
'../runners/agent-runner/package.json',
|
||||
);
|
||||
const codexRunnerPackageJson = readPackageJson(
|
||||
'../runners/codex-runner/package.json',
|
||||
);
|
||||
|
||||
expect(rootPackageJson.workspaces).toEqual(
|
||||
expect.arrayContaining([
|
||||
'runners/shared',
|
||||
'runners/agent-runner',
|
||||
'runners/codex-runner',
|
||||
]),
|
||||
);
|
||||
expect(rootPackageJson.dependencies?.['ejclaw-runners-shared']).toBe(
|
||||
'workspace:*',
|
||||
);
|
||||
expect(agentRunnerPackageJson.dependencies?.['ejclaw-runners-shared']).toBe(
|
||||
'workspace:*',
|
||||
);
|
||||
expect(codexRunnerPackageJson.dependencies?.['ejclaw-runners-shared']).toBe(
|
||||
'workspace:*',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user