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:
A 2026-02-24 00:16:22 -08:00 committed by GitHub
parent 01b23042b8
commit 7c53b4e4f6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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;