-
Notifications
You must be signed in to change notification settings - Fork 0
Fix search/list/read operations to use indexed commit ref #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
14d54ee
99cced4
1ec9f17
32f4382
940e3c9
2ae8d6d
e0f6d75
d9656c4
f87b516
f881713
47cbde1
e4f6959
ac285f1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| /** | ||
| * Tests for createSourceFromState | ||
| * | ||
| * These tests verify that createSourceFromState correctly uses resolvedRef | ||
| * from state metadata when creating source instances. | ||
| * | ||
| * We mock GitHub and Website sources to capture what config gets passed | ||
| * to the constructors, without needing API credentials. | ||
| * | ||
| * Since all VCS sources (GitHub, GitLab, BitBucket) use the same getRef() logic, | ||
| * we only test GitHub as the representative case. | ||
| */ | ||
|
|
||
| import { describe, it, expect, vi, beforeEach } from "vitest"; | ||
| import type { IndexStateSearchOnly, SourceMetadata } from "../core/types.js"; | ||
|
|
||
| // Mock only the sources we actually test | ||
| vi.mock("../sources/github.js", () => ({ | ||
| GitHubSource: vi.fn().mockImplementation((config) => ({ | ||
| type: "github" as const, | ||
| config, | ||
| })), | ||
| })); | ||
|
|
||
| vi.mock("../sources/website.js", () => ({ | ||
| WebsiteSource: vi.fn().mockImplementation((config) => ({ | ||
| type: "website" as const, | ||
| config, | ||
| })), | ||
| })); | ||
|
|
||
| // Import the function under test and mocked sources | ||
| import { createSourceFromState } from "./multi-index-runner.js"; | ||
| import { GitHubSource } from "../sources/github.js"; | ||
| import { WebsiteSource } from "../sources/website.js"; | ||
|
|
||
| // Create mock state with specific source metadata | ||
| const createMockState = (source: SourceMetadata): IndexStateSearchOnly => ({ | ||
| version: 1, | ||
| contextState: { | ||
| version: 1, | ||
| } as any, | ||
| source, | ||
| }); | ||
|
|
||
| describe("createSourceFromState", () => { | ||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| }); | ||
|
|
||
| // All VCS sources (GitHub, GitLab, BitBucket) use the same getRef() logic: | ||
| // resolvedRef ?? config.ref | ||
| // We test this once with GitHub as the representative case. | ||
|
|
||
| it("uses resolvedRef when present", async () => { | ||
| const state = createMockState({ | ||
| type: "github", | ||
| config: { owner: "test-owner", repo: "test-repo", ref: "main" }, | ||
| resolvedRef: "abc123sha", | ||
| syncedAt: new Date().toISOString(), | ||
| }); | ||
|
|
||
| await createSourceFromState(state); | ||
|
|
||
| expect(GitHubSource).toHaveBeenCalledWith({ | ||
| owner: "test-owner", | ||
| repo: "test-repo", | ||
| ref: "abc123sha", | ||
| }); | ||
| }); | ||
|
|
||
| it("falls back to config.ref when resolvedRef is missing", async () => { | ||
| const state = createMockState({ | ||
| type: "github", | ||
| config: { owner: "test-owner", repo: "test-repo", ref: "main" }, | ||
| // No resolvedRef | ||
| syncedAt: new Date().toISOString(), | ||
| }); | ||
|
|
||
| await createSourceFromState(state); | ||
|
|
||
| expect(GitHubSource).toHaveBeenCalledWith({ | ||
| owner: "test-owner", | ||
| repo: "test-repo", | ||
| ref: "main", | ||
| }); | ||
| }); | ||
|
|
||
| it("website source works without resolvedRef", async () => { | ||
| const state = createMockState({ | ||
| type: "website", | ||
| config: { url: "https://example.com", maxDepth: 2 }, | ||
| syncedAt: new Date().toISOString(), | ||
| }); | ||
|
|
||
| await createSourceFromState(state); | ||
|
|
||
| expect(WebsiteSource).toHaveBeenCalledWith({ | ||
| url: "https://example.com", | ||
| maxDepth: 2, | ||
| }); | ||
| }); | ||
|
|
||
| it("throws error for unknown source type", async () => { | ||
| const state = createMockState({ | ||
| type: "unknown" as any, | ||
| config: {} as any, | ||
| syncedAt: new Date().toISOString(), | ||
| }); | ||
|
|
||
| await expect(createSourceFromState(state)).rejects.toThrow( | ||
| "Unknown source type: unknown" | ||
| ); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ | |
|
|
||
| import { spawn } from "child_process"; | ||
| import { mkdtemp, rm } from "fs/promises"; | ||
| import { resolve } from "path"; | ||
| import { tmpdir } from "os"; | ||
| import { join } from "path"; | ||
|
|
||
|
|
@@ -26,12 +27,15 @@ interface TestResult { | |
|
|
||
| let testIndexPath: string | null = null; | ||
|
|
||
| // Path to the local CLI build | ||
| const CLI_PATH = resolve(import.meta.dirname, "../dist/bin/index.js"); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage. |
||
|
|
||
| async function runCLI( | ||
| args: string[], | ||
| timeoutMs = 60000 | ||
| ): Promise<{ stdout: string; stderr: string; exitCode: number }> { | ||
| return new Promise((resolve) => { | ||
| const proc = spawn("npx", ["ctxc", ...args], { | ||
| const proc = spawn(process.execPath, [CLI_PATH, ...args], { | ||
| cwd: process.cwd(), | ||
| env: process.env, | ||
| timeout: timeoutMs, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test:integrationnow runs scripts that execute/import fromdist/, but the script itself doesn’t ensure a build has happened first (fresh checkouts will fail with missingdist). Consider making the integration script self-contained by ensuringnpm run buildis run as a pre-step.🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.