forked from elizaOS/eliza
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into issue-16
- Loading branch information
Showing
149 changed files
with
34,248 additions
and
1,165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { describe, it, expect, vi } from 'vitest'; | ||
import { validateGithubConfig, githubEnvSchema } from '../src/environment'; | ||
import { IAgentRuntime } from '@elizaos/core'; | ||
|
||
describe('GitHub Environment Configuration', () => { | ||
const mockRuntime: IAgentRuntime = { | ||
getSetting: vi.fn(), | ||
} as unknown as IAgentRuntime; | ||
|
||
it('validates correct GitHub configuration', async () => { | ||
const validConfig = { | ||
GITHUB_OWNER: 'testowner', | ||
GITHUB_REPO: 'testrepo', | ||
GITHUB_BRANCH: 'main', | ||
GITHUB_PATH: 'src', | ||
GITHUB_API_TOKEN: 'ghp_test123', | ||
}; | ||
|
||
vi.mocked(mockRuntime.getSetting).mockImplementation((key: string) => validConfig[key as keyof typeof validConfig]); | ||
|
||
const config = await validateGithubConfig(mockRuntime); | ||
expect(config).toEqual(validConfig); | ||
}); | ||
|
||
it('throws error for missing configuration', async () => { | ||
const invalidConfig = { | ||
GITHUB_OWNER: '', | ||
GITHUB_REPO: '', | ||
GITHUB_BRANCH: '', | ||
GITHUB_PATH: '', | ||
GITHUB_API_TOKEN: '', | ||
}; | ||
|
||
vi.mocked(mockRuntime.getSetting).mockImplementation((key: string) => invalidConfig[key as keyof typeof invalidConfig]); | ||
|
||
await expect(validateGithubConfig(mockRuntime)).rejects.toThrow(); | ||
}); | ||
|
||
it('throws error for partial configuration', async () => { | ||
const partialConfig = { | ||
GITHUB_OWNER: 'testowner', | ||
GITHUB_REPO: 'testrepo', | ||
// Missing other required fields | ||
}; | ||
|
||
vi.mocked(mockRuntime.getSetting).mockImplementation((key: string) => partialConfig[key as keyof typeof partialConfig]); | ||
|
||
await expect(validateGithubConfig(mockRuntime)).rejects.toThrow(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { describe, it, expect, vi, beforeEach } from 'vitest'; | ||
import { GitHubClient, GitHubClientInterface } from '../src'; | ||
import { AgentRuntime, IAgentRuntime } from '@elizaos/core'; | ||
import { Octokit } from '@octokit/rest'; | ||
import simpleGit from 'simple-git'; | ||
import fs from 'fs'; | ||
import fsPromises from 'fs/promises'; | ||
|
||
// Mock external dependencies | ||
vi.mock('@octokit/rest', () => ({ | ||
Octokit: vi.fn(), | ||
})); | ||
|
||
vi.mock('simple-git', () => ({ | ||
default: vi.fn(() => ({ | ||
clone: vi.fn(), | ||
pull: vi.fn(), | ||
checkout: vi.fn(), | ||
})), | ||
})); | ||
|
||
vi.mock('fs/promises', async (importOriginal) => { | ||
const actual = await importOriginal() as typeof fsPromises; | ||
return { | ||
...actual, | ||
mkdir: vi.fn(), | ||
lstat: vi.fn(), | ||
readdir: vi.fn(), | ||
readFile: vi.fn(), | ||
writeFile: vi.fn(), | ||
}; | ||
}); | ||
|
||
vi.mock('fs', async (importOriginal) => { | ||
const actual = await importOriginal() as typeof fs; | ||
return { | ||
...actual, | ||
existsSync: vi.fn(), | ||
realpathSync: vi.fn(), | ||
lstatSync: vi.fn(), | ||
readdirSync: vi.fn(), | ||
}; | ||
}); | ||
|
||
describe('GitHubClient', () => { | ||
let mockRuntime: AgentRuntime; | ||
const mockConfig = { | ||
GITHUB_OWNER: 'testowner', | ||
GITHUB_REPO: 'testrepo', | ||
GITHUB_BRANCH: 'main', | ||
GITHUB_PATH: 'src', | ||
GITHUB_API_TOKEN: 'ghp_test123', | ||
}; | ||
|
||
beforeEach(() => { | ||
vi.clearAllMocks(); | ||
mockRuntime = { | ||
getSetting: vi.fn((key: string) => mockConfig[key as keyof typeof mockConfig]), | ||
} as unknown as AgentRuntime; | ||
}); | ||
|
||
it('initializes with correct configuration', () => { | ||
const client = new GitHubClient(mockRuntime); | ||
expect(Octokit).toHaveBeenCalledWith({ auth: mockConfig.GITHUB_API_TOKEN }); | ||
}); | ||
|
||
describe('GitHubClientInterface', () => { | ||
it('has start and stop methods', () => { | ||
expect(GitHubClientInterface.start).toBeDefined(); | ||
expect(GitHubClientInterface.stop).toBeDefined(); | ||
}); | ||
|
||
it('start method initializes client', async () => { | ||
const runtime = { | ||
getSetting: vi.fn((key: string) => mockConfig[key as keyof typeof mockConfig]), | ||
} as unknown as IAgentRuntime; | ||
|
||
await GitHubClientInterface.start(runtime); | ||
// Add more specific assertions based on what start should do | ||
}); | ||
|
||
it('stop method cleans up resources', () => { | ||
const runtime = {} as IAgentRuntime; | ||
GitHubClientInterface.stop(runtime); | ||
// Add assertions for cleanup if needed | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import eslintGlobalConfig from "../../eslint.config.mjs"; | ||
|
||
export default [...eslintGlobalConfig]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.