Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sshivaditya committed Oct 5, 2024
1 parent e133616 commit 51454d4
Show file tree
Hide file tree
Showing 3 changed files with 152 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/adapters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { SuperSupabase } from "./supabase/helpers/supabase";
import { Embedding as VoyageEmbedding } from "./voyage/helpers/embedding";
import { SuperVoyage } from "./voyage/helpers/voyage";
import { VoyageAIClient } from "voyageai";
import { Issues } from "./supabase/helpers/issues";
import { Issue } from "./supabase/helpers/issue";
import { SuperOpenAi } from "./openai/helpers/openai";
import OpenAI from "openai";
import { Completions } from "./openai/helpers/completions";
Expand All @@ -15,7 +15,7 @@ export function createAdapters(supabaseClient: SupabaseClient, voyage: VoyageAIC
return {
supabase: {
comment: new Comment(supabaseClient, context),
issue: new Issues(supabaseClient, context),
issue: new Issue(supabaseClient, context),
super: new SuperSupabase(supabaseClient, context),
},
voyage: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export interface IssueType {
embedding: number[];
}

export class Issues extends SuperSupabase {
export class Issue extends SuperSupabase {
constructor(supabase: SupabaseClient, context: Context) {
super(supabase, context);
}
Expand Down
162 changes: 149 additions & 13 deletions tests/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ import { askQuestion } from "../src/handlers/ask-gpt";
import { runPlugin } from "../src/plugin";
import { TransformDecodeCheckError, Value } from "@sinclair/typebox/value";
import { envSchema } from "../src/types/env";
import { CompletionsType } from "../src/adapters/openai/helpers/completions";

const TEST_QUESTION = "what is pi?";
const TEST_SLASH_COMMAND = "@UbiquityOS what is pi?";
const LOG_CALLER = "_Logs.<anonymous>";
const ISSUE_ID_2_CONTENT = "More context here #2";
const ISSUE_ID_3_CONTENT = "More context here #3";

const systemMsg = `You are a GitHub integrated chatbot tasked with assisting in research and discussion on GitHub issues and pull requests.
Using the provided context, address the question being asked providing a clear and concise answer with no follow-up statements.
Expand Down Expand Up @@ -58,6 +61,7 @@ describe("Ask plugin tests", () => {

it("should ask GPT a question", async () => {
const ctx = createContext(TEST_SLASH_COMMAND);
console.log(ctx.adapters);
createComments([transformCommentTemplate(1, 1, TEST_QUESTION, "ubiquity", "test-repo", true)]);
const res = await askQuestion(ctx, TEST_QUESTION);

Expand Down Expand Up @@ -112,16 +116,16 @@ describe("Ask plugin tests", () => {

const prompt = `=== Current Issue #1 Specification === ubiquity/test-repo/1 ===
This is a demo spec for a demo task just perfect for testing.
=== End Current Issue #1 Specification ===
This is a demo spec for a demo task just perfect for testing.
=== End Current Issue #1 Specification ===
=== Current Issue #1 Conversation === ubiquity/test-repo #1 ===
=== Current Issue #1 Conversation === ubiquity/test-repo #1 ===
1 ubiquity: what is pi?
=== End Current Issue #1 Conversation ===\n
`;
1 ubiquity: ${TEST_QUESTION}
=== End Current Issue #1 Conversation ===\n
`;

expect(infoSpy).toHaveBeenNthCalledWith(1, "Asking question: @UbiquityOS what is pi?");
expect(infoSpy).toHaveBeenNthCalledWith(1, `Asking question: @UbiquityOS ${TEST_QUESTION}`);
expect(infoSpy).toHaveBeenNthCalledWith(2, "Sending chat to OpenAI", {
caller: LOG_CALLER,
chat: [
Expand Down Expand Up @@ -150,17 +154,17 @@ This is a demo spec for a demo task just perfect for testing.
const ctx = createContext(TEST_SLASH_COMMAND);
const infoSpy = jest.spyOn(ctx.logger, "info");
createComments([
transformCommentTemplate(1, 1, "More context here #2", "ubiquity", "test-repo", true),
transformCommentTemplate(1, 1, ISSUE_ID_2_CONTENT, "ubiquity", "test-repo", true),
transformCommentTemplate(2, 1, TEST_QUESTION, "ubiquity", "test-repo", true),
transformCommentTemplate(3, 2, "More context here #3", "ubiquity", "test-repo", true),
transformCommentTemplate(3, 2, ISSUE_ID_3_CONTENT, "ubiquity", "test-repo", true),
transformCommentTemplate(4, 3, "Just a comment", "ubiquity", "test-repo", true),
]);

await runPlugin(ctx);

expect(infoSpy).toHaveBeenCalledTimes(3);

expect(infoSpy).toHaveBeenNthCalledWith(1, "Asking question: @UbiquityOS what is pi?");
expect(infoSpy).toHaveBeenNthCalledWith(1, `Asking question: @UbiquityOS ${TEST_QUESTION}`);

const prompt = `=== Current Issue #1 Specification === ubiquity/test-repo/1 ===
Expand All @@ -169,8 +173,8 @@ This is a demo spec for a demo task just perfect for testing.
=== Current Issue #1 Conversation === ubiquity/test-repo #1 ===
1 ubiquity: More context here #2
2 ubiquity: what is pi?
1 ubiquity: ${ISSUE_ID_2_CONTENT}
2 ubiquity: ${TEST_QUESTION}
=== End Current Issue #1 Conversation ===
=== Linked Issue #2 Specification === ubiquity/test-repo/2 ===
Expand All @@ -180,7 +184,7 @@ Related to issue #3
=== Linked Issue #2 Conversation === ubiquity/test-repo #2 ===
3 ubiquity: More context here #3
3 ubiquity: ${ISSUE_ID_3_CONTENT}
=== End Linked Issue #2 Conversation ===
=== Linked Issue #3 Specification === ubiquity/test-repo/3 ===
Expand Down Expand Up @@ -304,6 +308,138 @@ function createContext(body = TEST_SLASH_COMMAND) {
UBIQUITY_OS_APP_SLUG: "UbiquityOS",
OPENAI_API_KEY: "test",
},
adapters: {
supabase: {
issue: {
getIssue: async () => {
return [
{
id: "1",
markdown: "This is a demo spec for a demo task just perfect for testing.",
plaintext: "This is a demo spec for a demo task just perfect for testing.",
author_id: 1,
created_at: new Date().toISOString(),
modified_at: new Date().toISOString(),
embedding: [1, 2, 3],
},
];
},
findSimilarIssues: async () => {
return [
{
issue_id: "2",
issue_plaintext: "Related to issue #3",
similarity: 0.5,
},
{
issue_id: "3",
issue_plaintext: "Someother issue",
similarity: 0.3,
},
];
},
},
comment: {
getComments: async () => {
return [
{
id: "1",
plaintext: TEST_QUESTION,
markdown: TEST_QUESTION,
author_id: 1,
created_at: new Date().toISOString(),
modified_at: new Date().toISOString(),
embedding: [1, 2, 3],
},
{
id: "2",
plaintext: ISSUE_ID_2_CONTENT,
markdown: ISSUE_ID_2_CONTENT,
author_id: 1,
created_at: new Date().toISOString(),
modified_at: new Date().toISOString(),
embedding: [1, 2, 3],
},
{
id: "3",
plaintext: ISSUE_ID_3_CONTENT,
markdown: ISSUE_ID_3_CONTENT,
author_id: 1,
created_at: new Date().toISOString(),
modified_at: new Date().toISOString(),
embedding: [1, 2, 3],
},
{
id: "4",
plaintext: "Something new",
markdown: "Something new",
author_id: 1,
created_at: new Date().toISOString(),
modified_at: new Date().toISOString(),
embedding: [1, 2, 3],
},
];
},
findSimilarComments: async () => {
return [
{
id: "2",
plaintext: ISSUE_ID_2_CONTENT,
markdown: ISSUE_ID_2_CONTENT,
author_id: 1,
created_at: new Date().toISOString(),
modified_at: new Date().toISOString(),
embedding: [1, 2, 3],
},
{
id: "3",
plaintext: ISSUE_ID_3_CONTENT,
markdown: ISSUE_ID_3_CONTENT,
author_id: 1,
created_at: new Date().toISOString(),
modified_at: new Date().toISOString(),
embedding: [1, 2, 3],
},
{
id: "4",
plaintext: "New Comment",
markdown: "New Comment",
author_id: 1,
created_at: new Date().toISOString(),
modified_at: new Date().toISOString(),
embedding: [1, 2, 3],
},
];
},
},
},
voyage: {
embedding: {
createEmbedding: async () => {
return new Array(1024).fill(0);
},
},
reranker: {
reRankResults: async (similarText: string[]) => {
return similarText;
},
},
},
openai: {
completions: {
createCompletion: async (): Promise<CompletionsType> => {
return {
answer: "This is a mock answer for the chat",
tokenUsage: {
input: 1000,
output: 150,
total: 1150,
},
};
},
},
},
},
octokit: new octokit.Octokit(),
eventName: "issue_comment.created" as SupportedEventsU,
} as unknown as Context;
Expand Down

0 comments on commit 51454d4

Please sign in to comment.