chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,121 @@
|
||||
import path from 'path';
|
||||
import { describe, expect, test } from 'vitest';
|
||||
import {
|
||||
createTempHome,
|
||||
repoRoot,
|
||||
runCli,
|
||||
writeAuthConfig,
|
||||
} from '../helpers/cliRunner';
|
||||
|
||||
describe('pinme CLI', () => {
|
||||
test('prints help for --help', async () => {
|
||||
const temp = await createTempHome();
|
||||
try {
|
||||
const result = await runCli(['--help'], { home: temp.home });
|
||||
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(result.stdout).toContain('Usage: pinme');
|
||||
expect(result.stdout).toContain('upload');
|
||||
} finally {
|
||||
await temp.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test('prints package version for --version', async () => {
|
||||
const temp = await createTempHome();
|
||||
try {
|
||||
const result = await runCli(['--version'], { home: temp.home });
|
||||
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(result.stdout.trim()).toMatch(/^\d+\.\d+\.\d+/);
|
||||
} finally {
|
||||
await temp.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test('shows banner and help with no arguments', async () => {
|
||||
const temp = await createTempHome();
|
||||
try {
|
||||
const result = await runCli([], { home: temp.home });
|
||||
const output = `${result.stdout}\n${result.stderr}`;
|
||||
|
||||
expect(result.exitCode).toBe(1);
|
||||
expect(output).toContain('Usage: pinme');
|
||||
expect(output).toContain('Examples:');
|
||||
} finally {
|
||||
await temp.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test('list reports empty upload history in isolated HOME', async () => {
|
||||
const temp = await createTempHome();
|
||||
try {
|
||||
const result = await runCli(['list'], { home: temp.home });
|
||||
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(result.stdout).toContain('No upload history found.');
|
||||
} finally {
|
||||
await temp.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test('upload exits before network work when auth is missing', async () => {
|
||||
const temp = await createTempHome();
|
||||
try {
|
||||
const result = await runCli(['upload', 'test/fixtures/site'], {
|
||||
home: temp.home,
|
||||
});
|
||||
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(result.stdout).toContain('Please login first. Run: pinme login');
|
||||
} finally {
|
||||
await temp.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test('bind exits before network work when auth is missing', async () => {
|
||||
const temp = await createTempHome();
|
||||
try {
|
||||
const result = await runCli(
|
||||
['bind', 'test/fixtures/site', '--domain', 'demo'],
|
||||
{ home: temp.home },
|
||||
);
|
||||
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(result.stdout).toContain('Please login first');
|
||||
} finally {
|
||||
await temp.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test('bind rejects malformed DNS domains before API calls', async () => {
|
||||
const temp = await createTempHome();
|
||||
try {
|
||||
await writeAuthConfig(temp.home);
|
||||
const result = await runCli(
|
||||
['bind', 'test/fixtures/site', '--domain', '-bad.com', '--dns'],
|
||||
{ home: temp.home },
|
||||
);
|
||||
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(result.stdout).toContain('Labels cannot start or end with hyphens');
|
||||
} finally {
|
||||
await temp.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test('save exits before project work when auth is missing', async () => {
|
||||
const temp = await createTempHome();
|
||||
try {
|
||||
const result = await runCli(['save'], {
|
||||
home: temp.home,
|
||||
cwd: path.join(repoRoot, 'test', 'fixtures', 'site'),
|
||||
});
|
||||
|
||||
expect(result.exitCode).toBe(1);
|
||||
expect(result.stderr).toContain('Auth not set. Run: pinme login');
|
||||
} finally {
|
||||
await temp.cleanup();
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,163 @@
|
||||
import path from 'path';
|
||||
import { writeFile } from 'fs/promises';
|
||||
import { describe, expect, test } from 'vitest';
|
||||
import {
|
||||
createTempHome,
|
||||
repoRoot,
|
||||
runCli,
|
||||
writeAuthConfig,
|
||||
} from '../helpers/cliRunner';
|
||||
|
||||
function outputOf(result: { stdout: string; stderr: string }): string {
|
||||
return `${result.stdout}\n${result.stderr}`;
|
||||
}
|
||||
|
||||
describe('pinme command-level guards', () => {
|
||||
test('create requires a local login before project creation', async () => {
|
||||
const temp = await createTempHome();
|
||||
try {
|
||||
const result = await runCli(['create', 'demo-project'], {
|
||||
home: temp.home,
|
||||
});
|
||||
|
||||
expect(result.exitCode).toBe(1);
|
||||
expect(outputOf(result)).toContain('Auth not set. Run: pinme login');
|
||||
} finally {
|
||||
await temp.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test('import requires a local login before reading CAR input', async () => {
|
||||
const temp = await createTempHome();
|
||||
try {
|
||||
const result = await runCli(['import', 'test/fixtures/site'], {
|
||||
home: temp.home,
|
||||
});
|
||||
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(outputOf(result)).toContain('Please login first. Run: pinme login');
|
||||
} finally {
|
||||
await temp.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test('import rejects nonexistent paths before upload', async () => {
|
||||
const temp = await createTempHome();
|
||||
try {
|
||||
await writeAuthConfig(temp.home);
|
||||
const result = await runCli(['import', 'does-not-exist.car'], {
|
||||
home: temp.home,
|
||||
});
|
||||
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(outputOf(result)).toContain('path does-not-exist.car does not exist');
|
||||
} finally {
|
||||
await temp.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test('export rejects invalid CID arguments before CAR API calls', async () => {
|
||||
const temp = await createTempHome();
|
||||
try {
|
||||
const result = await runCli(['export', 'not-a-cid', '--output', temp.home], {
|
||||
home: temp.home,
|
||||
});
|
||||
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(outputOf(result)).toContain('Invalid CID format');
|
||||
} finally {
|
||||
await temp.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test('export rejects output paths that are files before CAR API calls', async () => {
|
||||
const temp = await createTempHome();
|
||||
try {
|
||||
const filePath = path.join(temp.home, 'not-a-directory');
|
||||
await writeFile(filePath, 'file');
|
||||
const result = await runCli(
|
||||
['export', 'bafyvalidcid', '--output', filePath],
|
||||
{ home: temp.home },
|
||||
);
|
||||
|
||||
expect(result.exitCode).toBe(0);
|
||||
expect(outputOf(result)).toContain('exists but is not a directory');
|
||||
} finally {
|
||||
await temp.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test('delete requires a local login before resolving project deletion', async () => {
|
||||
const temp = await createTempHome();
|
||||
try {
|
||||
const result = await runCli(['delete', 'demo-project', '--force'], {
|
||||
home: temp.home,
|
||||
});
|
||||
|
||||
expect(result.exitCode).toBe(1);
|
||||
expect(outputOf(result)).toContain('Auth not set. Run: pinme login');
|
||||
} finally {
|
||||
await temp.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test('delete requires a project name when no pinme.toml is present', async () => {
|
||||
const temp = await createTempHome();
|
||||
try {
|
||||
await writeAuthConfig(temp.home);
|
||||
const result = await runCli(['delete', '--force'], {
|
||||
home: temp.home,
|
||||
cwd: path.join(repoRoot, 'test', 'fixtures', 'site'),
|
||||
});
|
||||
|
||||
expect(result.exitCode).toBe(1);
|
||||
expect(outputOf(result)).toContain('Cannot find project name');
|
||||
} finally {
|
||||
await temp.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test.each([
|
||||
['save', ['save'], 'Auth not set. Run: pinme login'],
|
||||
['update-web', ['update-web'], 'Auth not set. Run: pinme login'],
|
||||
['update-worker', ['update-worker'], 'Auth not set. Run: pinme login'],
|
||||
['update-db', ['update-db'], 'Auth not set. Run: pinme login'],
|
||||
])('%s requires login before project work', async (_name, args, message) => {
|
||||
const temp = await createTempHome();
|
||||
try {
|
||||
const result = await runCli(args, {
|
||||
home: temp.home,
|
||||
cwd: path.join(repoRoot, 'test', 'fixtures', 'site'),
|
||||
});
|
||||
|
||||
expect(result.exitCode).toBe(1);
|
||||
expect(outputOf(result)).toContain(message);
|
||||
} finally {
|
||||
await temp.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
test.each([
|
||||
['save', ['save'], 'pinme.toml` not found'],
|
||||
['update-web', ['update-web'], 'pinme.toml` not found'],
|
||||
['update-worker', ['update-worker'], 'pinme.toml` not found'],
|
||||
['update-db', ['update-db'], 'pinme.toml` not found'],
|
||||
])(
|
||||
'%s validates project config before build or deploy work',
|
||||
async (_name, args, message) => {
|
||||
const temp = await createTempHome();
|
||||
try {
|
||||
await writeAuthConfig(temp.home);
|
||||
const result = await runCli(args, {
|
||||
home: temp.home,
|
||||
cwd: path.join(repoRoot, 'test', 'fixtures', 'site'),
|
||||
});
|
||||
|
||||
expect(result.exitCode).toBe(1);
|
||||
expect(outputOf(result)).toContain(message);
|
||||
} finally {
|
||||
await temp.cleanup();
|
||||
}
|
||||
},
|
||||
);
|
||||
});
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user