Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 37 additions & 13 deletions test/commands/file/upload.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { describe, it, expect } from 'bun:test';
import { mkdtempSync, rmSync, writeFileSync } from 'fs';
import { tmpdir } from 'os';
import { join } from 'path';
import { default as uploadCommand } from '../../../src/commands/file/upload';

const baseConfig = {
Expand Down Expand Up @@ -27,6 +30,22 @@ const baseFlags = {
async: false,
};

async function captureStdout(fn: () => Promise<void>): Promise<string> {
const originalWrite = process.stdout.write;
let output = '';
process.stdout.write = ((chunk: string | Uint8Array) => {
output += typeof chunk === 'string' ? chunk : Buffer.from(chunk).toString('utf-8');
return true;
}) as typeof process.stdout.write;

try {
await fn();
return output;
} finally {
process.stdout.write = originalWrite;
}
}

describe('file upload command', () => {
it('has correct name', () => {
expect(uploadCommand.name).toBe('file upload');
Expand All @@ -45,17 +64,22 @@ describe('file upload command', () => {
});

it('shows dry-run output with file info', async () => {
let captured = '';
const origWrite = process.stdout.write;
process.stdout.write = (chunk: any): any => { captured += String(chunk); return true; };

await uploadCommand.execute(
{ ...baseConfig, dryRun: true },
{ ...baseFlags, dryRun: true, file: '/dev/null', purpose: 'vision' },
);

process.stdout.write = origWrite;
expect(captured).toContain('/dev/null');
expect(captured).toContain('vision');
const tempDir = mkdtempSync(join(tmpdir(), 'mmx-upload-test-'));
const filePath = join(tempDir, 'fixture.bin');
writeFileSync(filePath, 'fixture');

try {
const captured = await captureStdout(async () => {
await uploadCommand.execute(
{ ...baseConfig, dryRun: true },
{ ...baseFlags, dryRun: true, file: filePath, purpose: 'vision' },
);
});

expect(captured).toContain(filePath);
expect(captured).toContain('vision');
} finally {
rmSync(tempDir, { recursive: true, force: true });
}
});
});
});
23 changes: 17 additions & 6 deletions test/commands/music/generate.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { describe, it, expect } from 'bun:test';
import { mkdtempSync, rmSync, writeFileSync } from 'fs';
import { tmpdir } from 'os';
import { join } from 'path';
import { default as generateCommand } from '../../../src/commands/music/generate';

const baseConfig = {
Expand Down Expand Up @@ -107,12 +110,20 @@ describe('music generate command', () => {
});

it('rejects --instrumental with --lyrics-file', async () => {
await expect(
generateCommand.execute(
{ ...baseConfig, dryRun: true },
{ ...baseFlags, prompt: 'Folk', instrumental: true, lyricsFile: '/dev/null' },
),
).rejects.toThrow('Cannot use --instrumental with --lyrics');
const tempDir = mkdtempSync(join(tmpdir(), 'mmx-lyrics-test-'));
const lyricsFile = join(tempDir, 'lyrics.txt');
writeFileSync(lyricsFile, 'Hello');

try {
await expect(
generateCommand.execute(
{ ...baseConfig, dryRun: true },
{ ...baseFlags, prompt: 'Folk', instrumental: true, lyricsFile },
),
).rejects.toThrow('Cannot use --instrumental with --lyrics');
} finally {
rmSync(tempDir, { recursive: true, force: true });
}
});

it('handles "无歌词" as instrumental', async () => {
Expand Down