Files
oh-my-pi/packages/coding-agent/test/helpers/settings-test-state.ts
T
can1357 3998d95088 feat: standardized tab expansion to fixed width
- Removed configurable tab width support and the `display.tabWidth` setting across all packages.
- Deleted obsolete utility functions `getIndentation`, `getIndentationNoescape`, and `setDefaultTabWidth`.
- Standardized tab expansion logic to use a fixed `DEFAULT_TAB_WIDTH` globally.
- Cleaned up related configuration schemas, test suites, and internal API signatures to remove path-dependency.
2026-06-19 04:48:41 +02:00

68 lines
1.7 KiB
TypeScript

import { vi } from "bun:test";
import { resetSettingsForTest } from "@oh-my-pi/pi-coding-agent/config/settings";
import { isTuiTight, setTuiTight } from "@oh-my-pi/pi-tui";
import { getAgentDir, getProjectDir, setAgentDir, setProjectDir } from "@oh-my-pi/pi-utils";
export interface SettingsTestState {
agentDir: string;
env: Record<string, string | undefined>;
projectDir: string;
tuiTight: boolean;
}
export function beginSettingsTest(): SettingsTestState {
const env: Record<string, string | undefined> = {};
for (const key in process.env) {
env[key] = process.env[key];
}
for (const key in Bun.env) {
env[key] = Bun.env[key];
}
const state: SettingsTestState = {
agentDir: getAgentDir(),
env,
projectDir: getProjectDir(),
tuiTight: isTuiTight(),
};
resetSettingsForTest();
return state;
}
export function restoreSettingsTestState(state: SettingsTestState | undefined): void {
vi.restoreAllMocks();
resetSettingsForTest();
if (!state) return;
restoreEnv(state.env);
setProjectDir(state.projectDir);
setAgentDir(state.agentDir);
setTuiTight(state.tuiTight);
restoreEnvValue("PI_CODING_AGENT_DIR", state.env.PI_CODING_AGENT_DIR);
}
function restoreEnv(snapshot: Record<string, string | undefined>): void {
for (const key in process.env) {
if (!(key in snapshot)) {
restoreEnvValue(key, undefined);
}
}
for (const key in Bun.env) {
if (!(key in snapshot)) {
restoreEnvValue(key, undefined);
}
}
for (const key in snapshot) {
restoreEnvValue(key, snapshot[key]);
}
}
function restoreEnvValue(key: string, value: string | undefined): void {
if (value === undefined) {
delete process.env[key];
delete Bun.env[key];
return;
}
process.env[key] = value;
Bun.env[key] = value;
}