Skip to content
Closed
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
602 changes: 286 additions & 316 deletions skills/ai-tools/scripts/embeddings.test.js

Large diffs are not rendered by default.

391 changes: 314 additions & 77 deletions skills/ai-tools/scripts/extract.test.js

Large diffs are not rendered by default.

499 changes: 430 additions & 69 deletions skills/ai-tools/scripts/sentiment.test.js

Large diffs are not rendered by default.

674 changes: 368 additions & 306 deletions skills/ai-tools/scripts/summarize.test.js

Large diffs are not rendered by default.

854 changes: 674 additions & 180 deletions skills/ai-tools/scripts/vision.test.js

Large diffs are not rendered by default.

811 changes: 438 additions & 373 deletions skills/cloudflare-browser/scripts/cdp-client.test.js

Large diffs are not rendered by default.

154 changes: 72 additions & 82 deletions skills/cloudflare-browser/scripts/screenshot.test.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { spawn } from 'child_process';
import fs from 'fs';
import path from 'path';

const scriptPath = path.join(process.cwd(), 'skills/cloudflare-browser/scripts/screenshot.js');

describe('screenshot.js', () => {
let originalEnv;

beforeEach(() => {
originalEnv = { ...process.env };
process.env.CDP_SECRET = 'test-secret';
process.env.WORKER_URL = 'https://worker.example.com';
import { existsSync, unlinkSync } from 'fs';
import { join } from 'path';
import { tmpdir } from 'os';
Expand All @@ -26,18 +14,6 @@ describe('screenshot.js', () => {

afterEach(() => {
process.env = originalEnv;
// Clean up test files
const testFile = 'test-screenshot.png';
if (fs.existsSync(testFile)) {
fs.unlinkSync(testFile);
}
});

function runScript(args) {
return new Promise((resolve) => {
const proc = spawn('node', [scriptPath, ...args], {
env: process.env,
timeout: 5000
tempFiles.forEach((file) => {
if (existsSync(file)) {
try {
Expand Down Expand Up @@ -69,64 +45,6 @@ describe('screenshot.js', () => {
stderr += data.toString();
});

proc.on('close', (exitCode) => {
resolve({ exitCode, stdout, stderr });
});
});
}

describe('environment validation', () => {
it('fails when CDP_SECRET is not set', async () => {
delete process.env.CDP_SECRET;

const result = await runScript(['https://example.com']);

expect(result.exitCode).toBe(1);
expect(result.stderr).toContain('CDP_SECRET environment variable not set');
});

it('requires WORKER_URL to be set', async () => {
delete process.env.WORKER_URL;

const result = await runScript(['https://example.com']);

expect(result.exitCode).toBe(1);
});
});

describe('argument parsing', () => {
it('displays usage when no URL is provided', async () => {
const result = await runScript([]);

expect(result.exitCode).toBe(1);
expect(result.stderr).toContain('Usage: node screenshot.js');
});

it('uses default output filename', async () => {
// This test would require mocking WebSocket which is complex
// Just verify the script accepts the argument
const result = await runScript(['https://example.com']);
// Will fail due to WebSocket but at least validates arg parsing
expect(result.stderr).not.toContain('Usage:');
});

it('accepts custom output filename', async () => {
const result = await runScript(['https://example.com', 'custom.png']);
// Will fail due to WebSocket but validates arg parsing
expect(result.stderr).not.toContain('Usage:');
});
});

describe('URL handling', () => {
it('accepts HTTP URLs', async () => {
const result = await runScript(['http://example.com']);
expect(result.stderr).not.toContain('Usage:');
});

it('accepts HTTPS URLs', async () => {
const result = await runScript(['https://example.com']);
expect(result.stderr).not.toContain('Usage:');
});
proc.on('close', (code) => {
resolve({ code, stdout, stderr });
});
Expand Down Expand Up @@ -304,4 +222,76 @@ describe('screenshot.js', () => {

expect(result.stderr).not.toContain('Usage');
});

it('handles output filename with .jpg extension', async () => {
const outputFile = join(tmpdir(), `test-screenshot-${Date.now()}.jpg`);
tempFiles.push(outputFile);

const result = await runScript(['https://example.com', outputFile], {
CDP_SECRET: 'test-secret',
WORKER_URL: 'wss://invalid.test',
});

expect(result.stderr).not.toContain('Usage');
});

it('handles output filename with spaces', async () => {
const outputFile = join(tmpdir(), `test screenshot ${Date.now()}.png`);
tempFiles.push(outputFile);

const result = await runScript(['https://example.com', outputFile], {
CDP_SECRET: 'test-secret',
WORKER_URL: 'wss://invalid.test',
});

expect(result.stderr).not.toContain('Usage');
});

it('handles URL with port number', async () => {
const result = await runScript(['https://example.com:8080'], {
CDP_SECRET: 'test-secret',
WORKER_URL: 'wss://invalid.test',
});

expect(result.stderr).not.toContain('Usage');
});

it('handles URL with IPv4 address', async () => {
const result = await runScript(['https://192.168.1.1'], {
CDP_SECRET: 'test-secret',
WORKER_URL: 'wss://invalid.test',
});

expect(result.stderr).not.toContain('Usage');
});

it('handles URL with localhost', async () => {
const result = await runScript(['https://localhost:3000'], {
CDP_SECRET: 'test-secret',
WORKER_URL: 'wss://invalid.test',
});

expect(result.stderr).not.toContain('Usage');
});

it('handles output to current directory', async () => {
const outputFile = 'screenshot.png';
tempFiles.push(outputFile);

const result = await runScript(['https://example.com', outputFile], {
CDP_SECRET: 'test-secret',
WORKER_URL: 'wss://invalid.test',
});

expect(result.stderr).not.toContain('Usage');
});

it('handles CDP_SECRET with special characters', async () => {
const result = await runScript(['https://example.com'], {
CDP_SECRET: 'secret!@#$%^&*()',
WORKER_URL: 'wss://invalid.test',
});

expect(result.stderr).not.toContain('Usage');
});
});
179 changes: 97 additions & 82 deletions skills/cloudflare-browser/scripts/video.test.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
import { spawn } from 'child_process';
import path from 'path';

const scriptPath = path.join(process.cwd(), 'skills/cloudflare-browser/scripts/video.js');

describe('video.js', () => {
let originalEnv;

beforeEach(() => {
originalEnv = { ...process.env };
process.env.CDP_SECRET = 'test-secret';
process.env.WORKER_URL = 'https://worker.example.com';
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { spawn } from 'child_process';
import { existsSync, unlinkSync } from 'fs';
Expand All @@ -27,13 +14,6 @@ describe('video.js', () => {

afterEach(() => {
process.env = originalEnv;
});

function runScript(args) {
return new Promise((resolve) => {
const proc = spawn('node', [scriptPath, ...args], {
env: process.env,
timeout: 5000
tempFiles.forEach((file) => {
if (existsSync(file)) {
try {
Expand Down Expand Up @@ -65,68 +45,6 @@ describe('video.js', () => {
stderr += data.toString();
});

proc.on('close', (exitCode) => {
resolve({ exitCode, stdout, stderr });
});
});
}

describe('environment validation', () => {
it('fails when CDP_SECRET is not set', async () => {
delete process.env.CDP_SECRET;

const result = await runScript(['https://example.com']);

expect(result.exitCode).toBe(1);
expect(result.stderr).toContain('CDP_SECRET environment variable not set');
});
});

describe('argument parsing', () => {
it('displays usage when no URL is provided', async () => {
const result = await runScript([]);

expect(result.exitCode).toBe(1);
expect(result.stderr).toContain('Usage: node video.js');
});

it('accepts single URL', async () => {
const result = await runScript(['https://example.com']);
expect(result.stderr).not.toContain('Usage:');
});

it('accepts multiple comma-separated URLs', async () => {
const result = await runScript(['https://example.com,https://example.org']);
expect(result.stderr).not.toContain('Usage:');
});

it('accepts --fps option', async () => {
const result = await runScript(['https://example.com', '--fps', '15']);
expect(result.stderr).not.toContain('Usage:');
});

it('accepts --scroll option', async () => {
const result = await runScript(['https://example.com', '--scroll']);
expect(result.stderr).not.toContain('Usage:');
});

it('accepts custom output filename', async () => {
const result = await runScript(['https://example.com', 'custom.mp4']);
expect(result.stderr).not.toContain('Usage:');
});
});

describe('URL parsing', () => {
it('splits comma-separated URLs', async () => {
const result = await runScript(['https://a.com,https://b.com,https://c.com']);
// Script will fail on WebSocket but arg parsing should work
expect(result.stderr).not.toContain('Usage:');
});

it('trims whitespace from URLs', async () => {
const result = await runScript(['https://a.com, https://b.com , https://c.com']);
expect(result.stderr).not.toContain('Usage:');
});
proc.on('close', (code) => {
resolve({ code, stdout, stderr });
});
Expand Down Expand Up @@ -353,4 +271,101 @@ describe('video.js', () => {

expect(result.stderr).not.toContain('Usage');
});

it('handles zero FPS value', async () => {
const result = await runScript(['https://example.com', '--fps', '0'], {
CDP_SECRET: 'test-secret',
WORKER_URL: 'wss://invalid.test',
});

expect(result.stderr).not.toContain('Usage');
});

it('handles negative FPS value', async () => {
const result = await runScript(['https://example.com', '--fps', '-10'], {
CDP_SECRET: 'test-secret',
WORKER_URL: 'wss://invalid.test',
});

expect(result.stderr).not.toContain('Usage');
});

it('handles output filename with .avi extension', async () => {
const result = await runScript(['https://example.com', 'output.avi'], {
CDP_SECRET: 'test-secret',
WORKER_URL: 'wss://invalid.test',
});

expect(result.stderr).not.toContain('Usage');
});

it('handles output filename with spaces', async () => {
const outputFile = join(tmpdir(), `test video ${Date.now()}.mp4`);
tempFiles.push(outputFile);

const result = await runScript(['https://example.com', outputFile], {
CDP_SECRET: 'test-secret',
WORKER_URL: 'wss://invalid.test',
});

expect(result.stderr).not.toContain('Usage');
});

it('handles URLs with different schemes', async () => {
const result = await runScript(['http://example.com,https://test.com'], {
CDP_SECRET: 'test-secret',
WORKER_URL: 'wss://invalid.test',
});

expect(result.stderr).not.toContain('Usage');
});

it('handles very long URL list', async () => {
const urls = Array(10).fill('https://example.com').join(',');
const result = await runScript([urls], {
CDP_SECRET: 'test-secret',
WORKER_URL: 'wss://invalid.test',
});

expect(result.stderr).not.toContain('Usage');
});

it('handles --scroll with --fps together', async () => {
const result = await runScript(
['https://example.com', '--scroll', '--fps', '24'],
{
CDP_SECRET: 'test-secret',
WORKER_URL: 'wss://invalid.test',
}
);

expect(result.stderr).not.toContain('Usage');
});

it('handles URL with port and path', async () => {
const result = await runScript(['https://example.com:8080/path/to/page'], {
CDP_SECRET: 'test-secret',
WORKER_URL: 'wss://invalid.test',
});

expect(result.stderr).not.toContain('Usage');
});

it('handles fractional FPS value', async () => {
const result = await runScript(['https://example.com', '--fps', '23.976'], {
CDP_SECRET: 'test-secret',
WORKER_URL: 'wss://invalid.test',
});

expect(result.stderr).not.toContain('Usage');
});

it('handles non-numeric FPS value', async () => {
const result = await runScript(['https://example.com', '--fps', 'abc'], {
CDP_SECRET: 'test-secret',
WORKER_URL: 'wss://invalid.test',
});

expect(result.stderr).not.toContain('Usage');
});
});
Loading