Files
oh-my-pi/packages/coding-agent/test/config-spacing.test.ts
T
can1357 b8e4da23d0 ci(ci): refactored CI setup and test-state isolation for coding-agent workflows
- Added a setup-system-deps action with preloaded-runner guards and apt fallbacks.
- Updated CI workflows to download Linux x64 native artifacts and gate on native job success.
- Renamed coding-agent fast mode to singleton in scripts and test partitioning logic.
- Added settings test-state begin/restore helpers with recursive cleanup in affected tests.
2026-06-14 22:37:05 +02:00

60 lines
2.3 KiB
TypeScript

import { afterEach, beforeEach, describe, expect, it } from "bun:test";
import * as fs from "node:fs/promises";
import * as os from "node:os";
import * as path from "node:path";
import { Settings } from "@oh-my-pi/pi-coding-agent/config/settings";
import { getDefaultTabWidth, getIndentation, Snowflake, setDefaultTabWidth } from "@oh-my-pi/pi-utils";
import { beginSettingsTest, restoreSettingsTestState, type SettingsTestState } from "./helpers/settings-test-state";
describe("indentation resolver", () => {
let settingsState: SettingsTestState | undefined;
let tempDir = "";
beforeEach(async () => {
settingsState = beginSettingsTest();
setDefaultTabWidth(3);
tempDir = path.join(os.tmpdir(), "pi-spacing", Snowflake.next());
await fs.mkdir(tempDir, { recursive: true });
});
afterEach(async () => {
restoreSettingsTestState(settingsState);
settingsState = undefined;
if (tempDir) {
await fs.rm(tempDir, { recursive: true, force: true });
}
tempDir = "";
});
it("applies current display tab width during initial settings load", async () => {
await Settings.init({ inMemory: true, cwd: tempDir, overrides: { "display.tabWidth": 7 } });
expect(getDefaultTabWidth()).toBe(7);
expect(getIndentation()).toBe(7);
});
it("applies nearest editorconfig rules for the target file", async () => {
const filePath = path.join(tempDir, "src", "feature.ts");
await fs.mkdir(path.dirname(filePath), { recursive: true });
await fs.writeFile(filePath, "\tconst x = 1;\n");
await fs.writeFile(
path.join(tempDir, ".editorconfig"),
["root = true", "", "[*]", "indent_size = 2", "", "[*.md]", "indent_size = 4"].join("\n"),
);
expect(getIndentation(filePath)).toBe(2);
expect(getIndentation(path.join(tempDir, "README.md"))).toBe(4);
});
it("merges editorconfig files from root to leaf", async () => {
const nestedDir = path.join(tempDir, "packages", "feature");
const filePath = path.join(nestedDir, "index.ts");
await fs.mkdir(nestedDir, { recursive: true });
await fs.writeFile(filePath, "\tconst y = 2;\n");
await fs.writeFile(path.join(tempDir, ".editorconfig"), ["root = true", "", "[*]", "indent_size = 2"].join("\n"));
await fs.writeFile(path.join(tempDir, "packages", ".editorconfig"), ["[*.ts]", "indent_size = 6"].join("\n"));
expect(getIndentation(filePath)).toBe(6);
});
});