mirror of
https://github.com/OpenRouterTeam/spawn.git
synced 2026-05-01 21:30:21 +00:00
fix: replace 9 CommonJS require() calls with ESM import in history test (#1871)
The project is ESM-only ("type": "module") and CLAUDE.md bans
require(). All 9 `const { homedir } = require("node:os")` calls
replaced with a single top-level `import { homedir } from "node:os"`.
Co-authored-by: spawn-bot <spawn-bot@openrouter.ai>
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
01b23042b8
commit
7c53b4e4f6
1 changed files with 1 additions and 9 deletions
|
|
@ -1,5 +1,6 @@
|
|||
import { describe, it, expect, beforeEach, afterEach } from "bun:test";
|
||||
import { existsSync, mkdirSync, rmSync, writeFileSync, readFileSync } from "node:fs";
|
||||
import { homedir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import type { SpawnRecord } from "../history.js";
|
||||
import { getSpawnDir, getHistoryPath, loadHistory, saveSpawnRecord, filterHistory } from "../history.js";
|
||||
|
|
@ -10,7 +11,6 @@ describe("history", () => {
|
|||
|
||||
beforeEach(() => {
|
||||
// Use a directory within home directory for testing (required by security validation)
|
||||
const { homedir } = require("node:os");
|
||||
testDir = join(homedir(), `.spawn-test-${Date.now()}-${Math.random()}`);
|
||||
mkdirSync(testDir, {
|
||||
recursive: true,
|
||||
|
|
@ -35,7 +35,6 @@ describe("history", () => {
|
|||
|
||||
describe("getSpawnDir", () => {
|
||||
it("returns SPAWN_HOME when set to valid path within home", () => {
|
||||
const { homedir } = require("node:os");
|
||||
const validPath = join(homedir(), "custom", "spawn", "dir");
|
||||
process.env.SPAWN_HOME = validPath;
|
||||
expect(getSpawnDir()).toBe(validPath);
|
||||
|
|
@ -43,7 +42,6 @@ describe("history", () => {
|
|||
|
||||
it("falls back to ~/.spawn when SPAWN_HOME is not set", () => {
|
||||
delete process.env.SPAWN_HOME;
|
||||
const { homedir } = require("node:os");
|
||||
expect(getSpawnDir()).toBe(join(homedir(), ".spawn"));
|
||||
});
|
||||
|
||||
|
|
@ -58,14 +56,12 @@ describe("history", () => {
|
|||
});
|
||||
|
||||
it("resolves .. segments in absolute SPAWN_HOME within home", () => {
|
||||
const { homedir } = require("node:os");
|
||||
const pathWithDots = join(homedir(), "foo", "..", "bar");
|
||||
process.env.SPAWN_HOME = pathWithDots;
|
||||
expect(getSpawnDir()).toBe(join(homedir(), "bar"));
|
||||
});
|
||||
|
||||
it("accepts normal absolute SPAWN_HOME within home", () => {
|
||||
const { homedir } = require("node:os");
|
||||
const validPath = join(homedir(), ".spawn");
|
||||
process.env.SPAWN_HOME = validPath;
|
||||
expect(getSpawnDir()).toBe(validPath);
|
||||
|
|
@ -77,7 +73,6 @@ describe("history", () => {
|
|||
});
|
||||
|
||||
it("throws for SPAWN_HOME pointing to /root when user home is different", () => {
|
||||
const { homedir } = require("node:os");
|
||||
// Only run this test if we're not actually running as root
|
||||
if (homedir() !== "/root") {
|
||||
process.env.SPAWN_HOME = "/root/.spawn";
|
||||
|
|
@ -86,7 +81,6 @@ describe("history", () => {
|
|||
});
|
||||
|
||||
it("throws for path traversal attempt to escape home directory", () => {
|
||||
const { homedir } = require("node:os");
|
||||
// Attempt to traverse outside home using .. segments
|
||||
// e.g., /home/user/../../etc/.spawn
|
||||
const traversalPath = join(homedir(), "..", "..", "etc", ".spawn");
|
||||
|
|
@ -95,7 +89,6 @@ describe("history", () => {
|
|||
});
|
||||
|
||||
it("accepts home directory itself as SPAWN_HOME", () => {
|
||||
const { homedir } = require("node:os");
|
||||
process.env.SPAWN_HOME = homedir();
|
||||
expect(getSpawnDir()).toBe(homedir());
|
||||
});
|
||||
|
|
@ -205,7 +198,6 @@ describe("history", () => {
|
|||
|
||||
describe("saveSpawnRecord", () => {
|
||||
it("creates directory and file when neither exist", () => {
|
||||
const { homedir } = require("node:os");
|
||||
const nestedDir = join(homedir(), ".spawn-test", "nested", "spawn");
|
||||
process.env.SPAWN_HOME = nestedDir;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue