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
54 changes: 54 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: CI

on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]

jobs:
test:
name: Test
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: latest
Comment on lines +20 to +21
Copy link

Copilot AI Dec 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using bun-version: latest may cause builds to break unexpectedly if Bun introduces breaking changes in future releases. Consider pinning to a specific Bun version (e.g., bun-version: 1.0.0) to ensure consistent and reproducible builds across time.

Copilot uses AI. Check for mistakes.

- name: Install dependencies
run: bun install

- name: Run tests
run: bun test

build:
name: Build
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Bun
uses: oven-sh/setup-bun@v1
with:
bun-version: latest
Comment on lines +39 to +40
Copy link

Copilot AI Dec 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using bun-version: latest may cause builds to break unexpectedly if Bun introduces breaking changes in future releases. Consider pinning to a specific Bun version (e.g., bun-version: 1.0.0) to ensure consistent and reproducible builds across time.

Copilot uses AI. Check for mistakes.

- name: Install dependencies
run: bun install

- name: Build
run: bun run build

- name: Check build output
run: |
if [ ! -f "dist/index.js" ]; then
echo "Build failed: dist/index.js not found"
exit 1
fi
echo "✅ Build successful"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules
dist
.env
*.log
test-temp-*
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
"scripts": {
"flux": "bun src/index.ts",
"build": "tsup",
"start": "node dist/index.js"
"start": "node dist/index.js",
"test": "bun test",
"test:watch": "bun test --watch"
},
"dependencies": {
"tsx": "^4.19.0"
Expand Down
92 changes: 92 additions & 0 deletions src/__tests__/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# Flux Tests

This directory contains tests for the Flux CLI.

## Running Tests

```bash
# Run all tests
bun test

# Run tests in watch mode (re-runs on file changes)
bun test --watch

# Run specific test file
bun test src/__tests__/agent-loader.test.ts
```

## Test Structure

- `__tests__/` - Test files (*.test.ts)
- `__tests__/fixtures/` - Test fixtures and sample agent files

## Coverage

### agent-loader.test.ts

Tests for agent discovery, validation, and loading functionality:

**findAgentFile()**
- ✅ Returns null when no agent file exists
- ✅ Finds agent.ts in current directory
- ✅ Finds agent.js in current directory
- ✅ Prefers agent.ts over agent.js when both exist

**validateAgentFile()**
- ✅ Validates correct TypeScript agent files
- ✅ Validates correct JavaScript agent files
- ✅ Rejects agents without default export
- ✅ Rejects agents without invoke method
- ✅ Rejects agents where invoke is not a function
- ✅ Handles invalid syntax gracefully
- ✅ Handles non-existent files
- ✅ Handles empty files

**loadAgent()**
- ✅ Loads valid TypeScript agents
- ✅ Loads valid JavaScript agents
- ✅ Returns invokable agent
- ✅ Handles TypeScript features (interfaces, types)

**Integration Tests**
- ✅ Complete workflow: find → validate → load → invoke
- ✅ Handles workflow with invalid agent

## Test Fixtures

Test fixtures are located in `fixtures/` directory:

- `valid-agent.ts` - Valid TypeScript agent for testing
- `valid-agent.js` - Valid JavaScript agent for testing
- `no-default-export.ts` - Agent missing default export
- `no-invoke-method.ts` - Agent missing invoke method
- `invoke-not-function.ts` - Agent where invoke is not a function
- `invalid-syntax.ts` - Agent with syntax errors

## Writing New Tests

When adding new test files:

1. Name files with `.test.ts` extension
2. Import from `bun:test`: `import { describe, it, expect } from "bun:test"`
3. Use `beforeEach`/`afterEach` for setup/cleanup
4. Group related tests in `describe` blocks
5. Make test descriptions clear and specific

Example:

```typescript
import { describe, it, expect } from "bun:test";

describe("myModule", () => {
it("should do something specific", () => {
expect(true).toBe(true);
});
});
```

## Notes

- Tests use Bun's built-in test runner (no additional dependencies needed)
- Temporary test directories are automatically cleaned up
- The `tsx` warning messages during tests are expected and don't affect test results
Loading