feat: CISandbox v1.0.0 — Interactive CI Pipeline Debugger with Local Env Sync
This commit is contained in:
Vendored
+73
@@ -0,0 +1,73 @@
|
||||
import { describe, it, expect, vi } from 'vitest';
|
||||
import { DockerManager } from '../src/docker.js';
|
||||
// Mock dockerode
|
||||
vi.mock('dockerode', () => {
|
||||
return {
|
||||
default: class MockDocker {
|
||||
getContainer = vi.fn((id) => ({
|
||||
exec: vi.fn(async (opts) => {
|
||||
const cmd = opts.Cmd.join(' ');
|
||||
const isUsesWarning = cmd.includes('Action step');
|
||||
const stdoutText = isUsesWarning
|
||||
? '[CISandbox] Action step: actions/checkout@v4\nNote: \'uses\' actions are not yet supported in CISandbox. Convert to \'run\' or modify the step to debug.'
|
||||
: 'hello';
|
||||
return {
|
||||
start: vi.fn(async () => {
|
||||
const { EventEmitter } = await import('events');
|
||||
const ee = new EventEmitter();
|
||||
process.nextTick(() => {
|
||||
const buf = Buffer.alloc(8 + stdoutText.length);
|
||||
buf[0] = 1;
|
||||
buf.write(stdoutText, 8);
|
||||
ee.emit('data', buf);
|
||||
ee.emit('end');
|
||||
});
|
||||
return ee;
|
||||
}),
|
||||
inspect: vi.fn(async () => ({ ExitCode: 0 })),
|
||||
};
|
||||
}),
|
||||
stop: vi.fn(async () => { }),
|
||||
}));
|
||||
getImage = vi.fn(() => ({
|
||||
inspect: vi.fn(async () => ({})),
|
||||
}));
|
||||
createContainer = vi.fn(async () => ({ id: 'abc123', start: vi.fn(async () => { }) }));
|
||||
pull = vi.fn(async () => {
|
||||
const { EventEmitter } = await import('events');
|
||||
const ee = new EventEmitter();
|
||||
process.nextTick(() => ee.emit('end'));
|
||||
return ee;
|
||||
});
|
||||
modem = { followProgress: vi.fn((_, cb) => cb()) };
|
||||
},
|
||||
};
|
||||
});
|
||||
describe('DockerManager', () => {
|
||||
it('checks image existence', async () => {
|
||||
const dm = new DockerManager();
|
||||
const exists = await dm.imageExists('node:20-slim');
|
||||
expect(exists).toBe(true);
|
||||
});
|
||||
it('creates a container', async () => {
|
||||
const dm = new DockerManager();
|
||||
const id = await dm.createContainer('node:20-slim', {
|
||||
workspace: '/tmp',
|
||||
env: { FOO: 'bar' },
|
||||
});
|
||||
expect(id).toBe('abc123');
|
||||
});
|
||||
it('executes a step', async () => {
|
||||
const dm = new DockerManager();
|
||||
const result = await dm.execInContainer('abc123', { run: 'echo hello' });
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(result.stdout).toContain('hello');
|
||||
});
|
||||
it('handles uses steps with warning', async () => {
|
||||
const dm = new DockerManager();
|
||||
const result = await dm.execInContainer('abc123', { uses: 'actions/checkout@v4' });
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(result.stdout).toContain('not yet supported');
|
||||
});
|
||||
});
|
||||
//# sourceMappingURL=docker.test.js.map
|
||||
Reference in New Issue
Block a user