@omnidev-ai/core 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omnidev-ai/core",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -9,7 +9,8 @@
9
9
  "directory": "packages/core"
10
10
  },
11
11
  "exports": {
12
- ".": "./src/index.ts"
12
+ ".": "./src/index.ts",
13
+ "./test-utils": "./src/test-utils/index.ts"
13
14
  },
14
15
  "files": [
15
16
  "src",
@@ -24,7 +24,9 @@ export async function loadCommands(
24
24
  }
25
25
 
26
26
  const commands: Command[] = [];
27
- const entries = readdirSync(commandsDir, { withFileTypes: true });
27
+ const entries = readdirSync(commandsDir, { withFileTypes: true }).sort((a, b) =>
28
+ a.name.localeCompare(b.name),
29
+ );
28
30
 
29
31
  for (const entry of entries) {
30
32
  if (entry.isDirectory()) {
@@ -16,7 +16,9 @@ export async function loadSkills(capabilityPath: string, capabilityId: string):
16
16
  }
17
17
 
18
18
  const skills: Skill[] = [];
19
- const entries = readdirSync(skillsDir, { withFileTypes: true });
19
+ const entries = readdirSync(skillsDir, { withFileTypes: true }).sort((a, b) =>
20
+ a.name.localeCompare(b.name),
21
+ );
20
22
 
21
23
  for (const entry of entries) {
22
24
  if (entry.isDirectory()) {
@@ -1,18 +1,16 @@
1
1
  import { afterEach, beforeEach, describe, expect, test } from "bun:test";
2
2
  import { existsSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
3
+ import { tmpdir } from "../test-utils/index.js";
3
4
  import type { EnvDeclaration } from "../types";
4
5
  import { isSecretEnvVar, loadEnvironment, validateEnv } from "./env";
5
6
 
6
7
  describe("loadEnvironment", () => {
7
8
  const originalCwd = process.cwd();
8
- const testDir = "/tmp/omnidev-test-env";
9
+ let testDir: string;
9
10
 
10
11
  beforeEach(() => {
11
- // Clean up and create test directory
12
- if (existsSync(testDir)) {
13
- rmSync(testDir, { recursive: true });
14
- }
15
- mkdirSync(testDir, { recursive: true });
12
+ // Create test directory in /tmp
13
+ testDir = tmpdir("env-test-");
16
14
  process.chdir(testDir);
17
15
  });
18
16
 
@@ -1,23 +1,21 @@
1
1
  import { afterEach, beforeEach, describe, expect, test } from "bun:test";
2
2
  import { existsSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
3
+ import { tmpdir } from "../test-utils/index.js";
3
4
  import { loadConfig } from "./loader";
4
5
 
5
- const TEST_DIR = "/tmp/omnidev-test-loader";
6
6
  const CONFIG_PATH = "omni.toml";
7
7
  const LOCAL_CONFIG = "omni.local.toml";
8
8
 
9
9
  // Save and restore the current working directory
10
10
  let originalCwd: string;
11
+ let TEST_DIR: string;
11
12
 
12
13
  beforeEach(() => {
13
14
  // Save original cwd
14
15
  originalCwd = process.cwd();
15
16
 
16
- // Clean up test directory
17
- if (existsSync(TEST_DIR)) {
18
- rmSync(TEST_DIR, { recursive: true });
19
- }
20
- mkdirSync(TEST_DIR, { recursive: true });
17
+ // Create test directory in /tmp
18
+ TEST_DIR = tmpdir("loader-test-");
21
19
  process.chdir(TEST_DIR);
22
20
  });
23
21
 
@@ -1,22 +1,19 @@
1
1
  import { afterEach, beforeEach, describe, expect, test } from "bun:test";
2
2
  import { existsSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
3
+ import { tmpdir } from "../test-utils/index.js";
3
4
  import { readActiveProfileState } from "../state/active-profile.js";
4
5
  import type { OmniConfig } from "../types/index.js";
5
6
  import { getActiveProfile, resolveEnabledCapabilities, setActiveProfile } from "./profiles.js";
6
7
 
7
8
  describe("getActiveProfile", () => {
8
- const TEST_DIR = ".omni-test-profiles";
9
+ let TEST_DIR: string;
9
10
  let originalCwd: string;
10
11
 
11
12
  beforeEach(() => {
12
- if (!existsSync(TEST_DIR)) {
13
- mkdirSync(TEST_DIR, { recursive: true });
14
- }
15
13
  originalCwd = process.cwd();
14
+ TEST_DIR = tmpdir("profiles-test-");
16
15
  process.chdir(TEST_DIR);
17
- if (!existsSync(".omni")) {
18
- mkdirSync(".omni", { recursive: true });
19
- }
16
+ mkdirSync(".omni", { recursive: true });
20
17
  });
21
18
 
22
19
  afterEach(() => {
@@ -1,17 +1,18 @@
1
1
  import { afterEach, beforeEach, describe, expect, test } from "bun:test";
2
- import { existsSync, mkdirSync, rmSync } from "node:fs";
2
+ import { existsSync, rmSync } from "node:fs";
3
+ import { tmpdir } from "../test-utils/index.js";
3
4
  import { parseProviderFlag } from "./provider.js";
4
5
 
5
- const TEST_DIR = ".test-omni";
6
+ let TEST_DIR: string;
7
+ const originalCwd = process.cwd();
6
8
 
7
9
  beforeEach(() => {
8
- if (existsSync(TEST_DIR)) {
9
- rmSync(TEST_DIR, { recursive: true });
10
- }
11
- mkdirSync(TEST_DIR, { recursive: true });
10
+ TEST_DIR = tmpdir("provider-test-");
11
+ process.chdir(TEST_DIR);
12
12
  });
13
13
 
14
14
  afterEach(() => {
15
+ process.chdir(originalCwd);
15
16
  if (existsSync(TEST_DIR)) {
16
17
  rmSync(TEST_DIR, { recursive: true });
17
18
  }
@@ -1,5 +1,6 @@
1
1
  import { afterEach, beforeEach, describe, expect, test } from "bun:test";
2
- import { existsSync, mkdirSync, rmSync } from "node:fs";
2
+ import { existsSync, rmSync } from "node:fs";
3
+ import { tmpdir } from "../test-utils/index.js";
3
4
  import {
4
5
  addCapabilityPatterns,
5
6
  buildGitignoreContent,
@@ -10,23 +11,19 @@ import {
10
11
  writeGitignore,
11
12
  } from "./manager.js";
12
13
 
13
- const TEST_DIR = ".omni-test-gitignore";
14
+ let TEST_DIR: string;
15
+ const originalCwd = process.cwd();
14
16
 
15
17
  describe("Gitignore Manager", () => {
16
18
  beforeEach(() => {
17
- // Create test directory
18
- if (existsSync(TEST_DIR)) {
19
- rmSync(TEST_DIR, { recursive: true });
20
- }
21
- mkdirSync(TEST_DIR, { recursive: true });
22
-
23
- // Change working directory
19
+ // Create test directory in /tmp
20
+ TEST_DIR = tmpdir("gitignore-test-");
24
21
  process.chdir(TEST_DIR);
25
22
  });
26
23
 
27
24
  afterEach(() => {
28
25
  // Restore working directory
29
- process.chdir("..");
26
+ process.chdir(originalCwd);
30
27
 
31
28
  // Clean up test directory
32
29
  if (existsSync(TEST_DIR)) {
@@ -1,7 +1,7 @@
1
1
  import { afterEach, beforeEach, describe, expect, test } from "bun:test";
2
- import { existsSync, mkdirSync, mkdtempSync, rmSync } from "node:fs";
3
- import { tmpdir } from "node:os";
2
+ import { existsSync, mkdirSync, rmSync } from "node:fs";
4
3
  import { join } from "node:path";
4
+ import { tmpdir } from "../test-utils/index.js";
5
5
  import {
6
6
  clearActiveProfileState,
7
7
  readActiveProfileState,
@@ -14,7 +14,7 @@ describe("active-profile state", () => {
14
14
 
15
15
  beforeEach(() => {
16
16
  originalCwd = process.cwd();
17
- tempDir = mkdtempSync(join(tmpdir(), "active-profile-test-"));
17
+ tempDir = tmpdir("active-profile-test-");
18
18
  mkdirSync(join(tempDir, ".omni"), { recursive: true });
19
19
  process.chdir(tempDir);
20
20
  });
@@ -3,6 +3,9 @@
3
3
  */
4
4
 
5
5
  import { expect } from "bun:test";
6
+ import { mkdtempSync } from "node:fs";
7
+ import { tmpdir as osTmpdir } from "node:os";
8
+ import { join } from "node:path";
6
9
 
7
10
  /**
8
11
  * Expects an async function to throw an error
@@ -185,3 +188,12 @@ export async function captureConsole<T>(
185
188
  console.warn = originalWarn;
186
189
  }
187
190
  }
191
+
192
+ /**
193
+ * Creates a unique temporary directory for tests in /tmp
194
+ * @param prefix - Optional prefix for the directory name (default: "omnidev-test-")
195
+ * @returns Path to the created temporary directory
196
+ */
197
+ export function tmpdir(prefix = "omnidev-test-"): string {
198
+ return mkdtempSync(join(osTmpdir(), prefix));
199
+ }
@@ -15,6 +15,7 @@ export {
15
15
  createSpy,
16
16
  delay,
17
17
  expectToThrowAsync,
18
+ tmpdir,
18
19
  waitForCondition,
19
20
  } from "./helpers";
20
21
  // Re-export all mock factories