Skip to content

Commit

Permalink
Merge pull request #67 from justyns/use-space-config
Browse files Browse the repository at this point in the history
Fix failing tests
  • Loading branch information
justyns authored Sep 8, 2024
2 parents f24791f + 426ccd3 commit ec62f06
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/embeddings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type {
EmbeddingResult,
} from "./types.ts";
import { renderToText } from "@silverbulletmd/silverbullet/lib/tree";
import { syscall } from "@silverbulletmd/silverbullet/syscalls";
import {
currentEmbeddingModel,
currentEmbeddingProvider,
Expand Down
1 change: 1 addition & 0 deletions src/init.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { assertEquals } from "https://deno.land/[email protected]/assert/mod.ts";
import "./mocks/syscalls.ts";
import { aiSettings, getAndConfigureModel, initializeOpenAI } from "./init.ts";
import { syscall } from "@silverbulletmd/silverbullet/syscalls";

const settingsPageSample = `
Mock settings, yay
Expand Down
14 changes: 13 additions & 1 deletion src/mocks/syscalls.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { parse as parseYAML } from "https://deno.land/[email protected]/yaml/mod.ts";
import { parseMarkdown } from "$common/markdown_parser/parser.ts";
import { syscall } from "@silverbulletmd/silverbullet/syscalls";
import { readSetting } from "https://deno.land/x/[email protected]/plug-api/lib/settings_page.ts";

let editorText = "Mock data";
(globalThis as any).editorText;
Expand All @@ -14,10 +15,13 @@ let currentEnv: string = "server";
let clientStore: { [key: string]: string } = {};
(globalThis as any).clientStore;

let spaceConfig = {};
(globalThis as any).spaceConfig;

// let indexedObjects: { [key: string]: string } = {};
// (globalThis as any).indexedObjects;

globalThis.syscall = async (name: string, ...args: readonly any[]) => {
(globalThis as any).syscall = async (name: string, ...args: readonly any[]) => {
switch (name) {
// I tried a lot of things to get this working differently, but
// ended up with just keeping this in a variable that can be changed
Expand Down Expand Up @@ -58,6 +62,14 @@ globalThis.syscall = async (name: string, ...args: readonly any[]) => {
case "clientStore.get":
return clientStore[args[0]];

// hack to ignore space config in tests for now
case "system.setSpaceConfig":
spaceConfig = args[0];
break;
case "system.getSpaceConfig":
return readSetting(args[0], args[1]);
// return spaceConfig;

default:
throw Error(`Missing mock for: ${name}`);
}
Expand Down
1 change: 1 addition & 0 deletions src/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { assertEquals } from "https://deno.land/[email protected]/assert/mod.ts";
import "./mocks/syscalls.ts";
import { convertPageToMessages, log } from "./utils.ts";
import { folderName } from "./utils.ts";
import { syscall } from "@silverbulletmd/silverbullet/syscalls";
import { ChatMessage } from "./types.ts";

Deno.test("folderName should return the correct folder path", () => {
Expand Down
1 change: 1 addition & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { extractFrontmatter } from "@silverbulletmd/silverbullet/lib/frontmatter
import { aiSettings } from "./init.ts";
import type { ChatMessage } from "./types.ts";
import { searchEmbeddingsForChat } from "./embeddings.ts";
import { syscall } from "@silverbulletmd/silverbullet/syscalls";

export function folderName(path: string) {
return path.split("/").slice(0, -1).join("/");
Expand Down

0 comments on commit ec62f06

Please sign in to comment.