Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions scripts/docs/src/utils.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
import fs from "fs";
import path from "path";
import {
getRepoRoot,
getGitHubToken,
Expand Down Expand Up @@ -40,6 +42,30 @@ describe("utils", () => {
"GITHUB_TOKEN environment variable is required.",
);
});

it("should return token when GH_TOKEN is set as a fallback", () => {
vi.stubEnv("GITHUB_TOKEN", "");
vi.stubEnv("GH_TOKEN", "fallback-token");

const result = getGitHubToken();
expect(result).toBe("fallback-token");
});
Comment on lines +46 to +52
Copy link

Copilot AI Nov 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test expects GH_TOKEN fallback behavior, but the current implementation of getGitHubToken() only checks process.env.GITHUB_TOKEN. The implementation doesn't have any fallback logic to check GH_TOKEN. Either update the implementation to support this fallback, or remove this test.

Copilot uses AI. Check for mistakes.

it("should read token from .env file if environment variables are not set", () => {
vi.stubEnv("GITHUB_TOKEN", "");
vi.stubEnv("GH_TOKEN", "");
const envPath = path.join(process.cwd(), ".env");
fs.writeFileSync(envPath, "GITHUB_TOKEN=env-file-token");
const result = getGitHubToken();
expect(result).toBe("env-file-token");
fs.unlinkSync(envPath);
});

Comment on lines +54 to +63
Copy link

Copilot AI Nov 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test expects .env file reading functionality, but the current implementation of getGitHubToken() doesn't read from .env files. The implementation only checks process.env.GITHUB_TOKEN. Either update the implementation to support reading from .env files, or remove this test.

Additionally, there are file system side effects: if the test fails before reaching line 61, the .env file will not be cleaned up. Consider using a try-finally block or vitest's cleanup hooks to ensure the file is always deleted.

Suggested change
it("should read token from .env file if environment variables are not set", () => {
vi.stubEnv("GITHUB_TOKEN", "");
vi.stubEnv("GH_TOKEN", "");
const envPath = path.join(process.cwd(), ".env");
fs.writeFileSync(envPath, "GITHUB_TOKEN=env-file-token");
const result = getGitHubToken();
expect(result).toBe("env-file-token");
fs.unlinkSync(envPath);
});

Copilot uses AI. Check for mistakes.
it("should throw detailed error when no token found", () => {
vi.stubEnv("GITHUB_TOKEN", "");
vi.stubEnv("GH_TOKEN", "");
expect(() => getGitHubToken()).toThrow(/Missing GitHub authentication token/);
Copy link

Copilot AI Nov 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test expects a detailed error message matching the regex /Missing GitHub authentication token/, but the actual implementation throws "GITHUB_TOKEN environment variable is required.". This test will fail. Update the expected error message to match the actual implementation, or update the implementation to throw the expected message.

Suggested change
expect(() => getGitHubToken()).toThrow(/Missing GitHub authentication token/);
expect(() => getGitHubToken()).toThrow("GITHUB_TOKEN environment variable is required.");

Copilot uses AI. Check for mistakes.
});
});

describe("getGitHubRepo", () => {
Expand Down
Loading