Release v0.10.10: Remove default cwd enterprises loading and add global test-dir config
This commit is contained in:
1 parent
878e53ac81
commit
b5cc7c874e
15 files changed
+208
-131
No files matched your search
@@ -84,21 +84,34 @@ describe("loadCorpConfigs", () => {
|
||||
expect(loadCorpConfigs()).toEqual([]);
|
||||
});
|
||||
|
||||
test("merges local and user enterprise directories with user configs taking precedence", () => {
|
||||
test("does not load current directory enterprises by default, only reading user directory", () => {
|
||||
const workspace = makeTempDir();
|
||||
const workspaceEnterprises = join(workspace, "enterprises");
|
||||
const userDir = makeTempDir();
|
||||
mkdirSync(workspaceEnterprises, { recursive: true });
|
||||
writeCorpConfig(join(workspaceEnterprises, "shared.json"), "shared", "Workspace");
|
||||
writeCorpConfig(join(userDir, "shared.json"), "shared", "User");
|
||||
writeCorpConfig(join(workspaceEnterprises, "cwd-only.json"), "cwd-only", "CWD Enterprise");
|
||||
writeCorpConfig(join(userDir, "user-only.json"), "user-only", "User Only");
|
||||
process.chdir(workspace);
|
||||
process.env.SEAL_USE_USER_ENTERPRISES_DIR = userDir;
|
||||
|
||||
expect(loadCorpConfigs().map((corp) => [corp.id, corp.name])).toEqual([
|
||||
["shared", "User"],
|
||||
["user-only", "User Only"]
|
||||
]);
|
||||
// cwd enterprises/ should NOT be loaded by default
|
||||
expect(loadCorpConfigs().map((corp) => corp.id)).toEqual(["user-only"]);
|
||||
});
|
||||
|
||||
test("loads testEnterprisesDir from global config when specified", () => {
|
||||
const testDir = makeTempDir();
|
||||
const userDir = makeTempDir();
|
||||
writeCorpConfig(join(testDir, "test-corp.json"), "test-corp", "Test Corp");
|
||||
writeCorpConfig(join(userDir, "user-corp.json"), "user-corp", "User Corp");
|
||||
|
||||
const configFile = join(makeTempDir(), "config.json");
|
||||
process.env.SEAL_USE_CONFIG_FILE = configFile;
|
||||
process.env.SEAL_USE_USER_ENTERPRISES_DIR = userDir;
|
||||
|
||||
saveGlobalConfig({ testEnterprisesDir: testDir });
|
||||
|
||||
const corps = loadCorpConfigs();
|
||||
expect(corps.map((corp) => corp.id).sort()).toEqual(["test-corp", "user-corp"].sort());
|
||||
});
|
||||
|
||||
test("defaults global config to stateless", () => {
|
||||
@@ -114,13 +127,14 @@ describe("loadCorpConfigs", () => {
|
||||
});
|
||||
});
|
||||
|
||||
test("saves and loads the global state mode", () => {
|
||||
test("saves and loads the global state mode and testEnterprisesDir", () => {
|
||||
const file = join(makeTempDir(), "nested", "config.json");
|
||||
process.env.SEAL_USE_CONFIG_FILE = file;
|
||||
|
||||
expect(saveGlobalConfig({ stateful: true, defaultCorpId: "corp-a" })).toEqual({
|
||||
expect(saveGlobalConfig({ stateful: true, defaultCorpId: "corp-a", testEnterprisesDir: "/tmp/test-corps" })).toEqual({
|
||||
stateful: true,
|
||||
defaultCorpId: "corp-a",
|
||||
testEnterprisesDir: "/tmp/test-corps",
|
||||
lint: {
|
||||
enabled: false,
|
||||
activeLinter: "builtin",
|
||||
@@ -131,6 +145,7 @@ describe("loadCorpConfigs", () => {
|
||||
expect(loadGlobalConfig()).toEqual({
|
||||
stateful: true,
|
||||
defaultCorpId: "corp-a",
|
||||
testEnterprisesDir: "/tmp/test-corps",
|
||||
lint: {
|
||||
enabled: false,
|
||||
activeLinter: "builtin",
|
||||
|
||||
@@ -3,7 +3,6 @@ import { homedir } from "node:os";
|
||||
import { dirname, join } from "node:path";
|
||||
import { CorpConfig, CorpConfigSchema, GlobalConfig, GlobalConfigInput, GlobalConfigSchema } from "./types.js";
|
||||
|
||||
const ENTERPRISES_DIR = "enterprises";
|
||||
const CONFIG_ENV = "SEAL_USE_ENTERPRISES_DIR";
|
||||
const LEGACY_CONFIG_ENV = "SEAL_HOME_ENTERPRISES_DIR";
|
||||
const USER_DIR_ENV = "SEAL_USE_USER_ENTERPRISES_DIR";
|
||||
@@ -43,13 +42,16 @@ function resolveEnterprisesDirs(): string[] {
|
||||
if (configured) return existsSync(configured) ? [configured] : [];
|
||||
|
||||
const configuredUserDir = (process.env[USER_DIR_ENV] ?? process.env[LEGACY_USER_DIR_ENV])?.trim();
|
||||
if (configuredUserDir) {
|
||||
return [ENTERPRISES_DIR, configuredUserDir].filter((dir) => existsSync(dir));
|
||||
}
|
||||
const userDirs = configuredUserDir
|
||||
? (existsSync(configuredUserDir) ? [configuredUserDir] : [])
|
||||
: [PRIMARY_USER_ENTERPRISES_DIR, LEGACY_USER_ENTERPRISES_DIR];
|
||||
|
||||
const dirs = [ENTERPRISES_DIR, PRIMARY_USER_ENTERPRISES_DIR, LEGACY_USER_ENTERPRISES_DIR];
|
||||
const globalConfig = loadGlobalConfig();
|
||||
const testDir = globalConfig.testEnterprisesDir?.trim();
|
||||
|
||||
const candidates = testDir ? [testDir, ...userDirs] : userDirs;
|
||||
const uniqueExisting: string[] = [];
|
||||
for (const d of dirs) {
|
||||
for (const d of candidates) {
|
||||
if (existsSync(d) && !uniqueExisting.includes(d)) {
|
||||
uniqueExisting.push(d);
|
||||
}
|
||||
@@ -62,13 +64,16 @@ export function resolveWritableEnterprisesDir(): string {
|
||||
if (configured) return configured;
|
||||
const configuredUserDir = (process.env[USER_DIR_ENV] ?? process.env[LEGACY_USER_DIR_ENV])?.trim();
|
||||
if (configuredUserDir) return configuredUserDir;
|
||||
const testDir = loadGlobalConfig().testEnterprisesDir?.trim();
|
||||
if (testDir && existsSync(testDir)) return testDir;
|
||||
return PRIMARY_USER_ENTERPRISES_DIR;
|
||||
}
|
||||
|
||||
export function getEnterprisesDirCandidates(): string[] {
|
||||
const testDir = loadGlobalConfig().testEnterprisesDir?.trim();
|
||||
return [
|
||||
`${CONFIG_ENV}=<path>`,
|
||||
ENTERPRISES_DIR,
|
||||
...(testDir ? [`testEnterprisesDir: ${testDir}`] : []),
|
||||
PRIMARY_USER_ENTERPRISES_DIR,
|
||||
LEGACY_USER_ENTERPRISES_DIR
|
||||
];
|
||||
|
||||
@@ -97,6 +97,7 @@ export const GlobalLintConfigSchema = z.object({
|
||||
export const GlobalConfigSchema = z.object({
|
||||
stateful: z.boolean().default(false),
|
||||
defaultCorpId: z.string().min(1).optional(),
|
||||
testEnterprisesDir: z.string().min(1).optional(),
|
||||
lint: GlobalLintConfigSchema
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user