Add stateful and stateless enterprise selection

This commit is contained in:
gitea committed 2026-08-12 11:38:25 +08:00
1 parent d383b3aad8
commit 0959cef1cc
22 files changed
+609 -187

No files matched your search

+31 -1
View File
@@ -2,10 +2,17 @@ import { afterEach, describe, expect, test } from "bun:test";
import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { loadCorpConfigs, resolveEnterprisesDir } from "./loader.js";
import {
loadCorpConfigs,
loadGlobalConfig,
resolveEnterprisesDir,
resolveGlobalConfigFile,
saveGlobalConfig
} from "./loader.js";
const ORIGINAL_ENV = process.env.SEAL_HOME_ENTERPRISES_DIR;
const ORIGINAL_USER_DIR_ENV = process.env.SEAL_HOME_USER_ENTERPRISES_DIR;
const ORIGINAL_CONFIG_FILE_ENV = process.env.SEAL_HOME_CONFIG_FILE;
const ORIGINAL_CWD = process.cwd();
const tempDirs: string[] = [];
@@ -21,6 +28,11 @@ afterEach(() => {
} else {
process.env.SEAL_HOME_USER_ENTERPRISES_DIR = ORIGINAL_USER_DIR_ENV;
}
if (ORIGINAL_CONFIG_FILE_ENV === undefined) {
delete process.env.SEAL_HOME_CONFIG_FILE;
} else {
process.env.SEAL_HOME_CONFIG_FILE = ORIGINAL_CONFIG_FILE_ENV;
}
for (const dir of tempDirs.splice(0)) {
rmSync(dir, { recursive: true, force: true });
@@ -69,6 +81,24 @@ describe("loadCorpConfigs", () => {
["user-only", "User Only"]
]);
});
test("defaults global config to stateless", () => {
process.env.SEAL_HOME_CONFIG_FILE = join(makeTempDir(), "config.json");
expect(loadGlobalConfig()).toEqual({ stateful: false });
});
test("saves and loads the global state mode", () => {
const file = join(makeTempDir(), "nested", "config.json");
process.env.SEAL_HOME_CONFIG_FILE = file;
expect(saveGlobalConfig({ stateful: true, defaultCorpId: "corp-a" })).toEqual({
stateful: true,
defaultCorpId: "corp-a"
});
expect(resolveGlobalConfigFile()).toBe(file);
expect(loadGlobalConfig()).toEqual({ stateful: true, defaultCorpId: "corp-a" });
});
});
function makeTempDir(): string {