Add test enterprise marking, binding, and staging sync commands
This commit is contained in:
1 parent
f2595bb275
commit
a56606af9c
16 files changed
+1080
-109
No files matched your search
@@ -7,6 +7,7 @@ describe("getDirectSealSession", () => {
|
||||
const corp: CorpConfig = {
|
||||
id: "corp-direct-1",
|
||||
name: "Direct Corp",
|
||||
environment: "production",
|
||||
seal: {
|
||||
url: "https://seal.example.com",
|
||||
tenantSlug: "direct-slug",
|
||||
@@ -48,6 +49,7 @@ describe("getDirectSealSession", () => {
|
||||
const corp: CorpConfig = {
|
||||
id: "corp-native-1",
|
||||
name: "Native Seal Corp",
|
||||
environment: "production",
|
||||
seal: {
|
||||
url: "https://tenant.sealai.cc",
|
||||
tenantSlug: "tenant-slug",
|
||||
|
||||
@@ -59,6 +59,7 @@ describe("hose auth helpers", () => {
|
||||
const corpWithSealUrl: CorpConfig = {
|
||||
id: "corp-1",
|
||||
name: "Corp 1",
|
||||
environment: "production",
|
||||
seal: { url: "https://custom.sealai.cc", endpoints: { approvalStylePreferences: "" } },
|
||||
source,
|
||||
auth: { refreshTtl: 300 }
|
||||
@@ -68,6 +69,7 @@ describe("hose auth helpers", () => {
|
||||
const corpWithoutSealUrl: CorpConfig = {
|
||||
id: "corp-1",
|
||||
name: "Corp 1",
|
||||
environment: "production",
|
||||
seal: { endpoints: { approvalStylePreferences: "" } },
|
||||
source,
|
||||
auth: { refreshTtl: 300 }
|
||||
@@ -91,6 +93,7 @@ describe("hose auth helpers", () => {
|
||||
const corp: CorpConfig = {
|
||||
id: "corp-cached",
|
||||
name: "Corp Cached",
|
||||
environment: "production",
|
||||
seal: { endpoints: { approvalStylePreferences: "" } },
|
||||
source: {
|
||||
type: "hose",
|
||||
|
||||
@@ -3,11 +3,13 @@ import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import {
|
||||
findCorpConfigFile,
|
||||
loadCorpConfigs,
|
||||
loadGlobalConfig,
|
||||
resolveEnterprisesDir,
|
||||
resolveGlobalConfigFile,
|
||||
saveGlobalConfig
|
||||
saveGlobalConfig,
|
||||
updateCorpConfig
|
||||
} from "./loader.js";
|
||||
|
||||
const ORIGINAL_USE_ENV = process.env.SEAL_USE_ENTERPRISES_DIR;
|
||||
@@ -153,6 +155,36 @@ describe("loadCorpConfigs", () => {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
test("finds and updates an enterprise config file in-place", () => {
|
||||
const dir = makeTempDir();
|
||||
process.env.SEAL_USE_ENTERPRISES_DIR = dir;
|
||||
writeCorpConfig(join(dir, "alpha.json"), "alpha", "Alpha Corp");
|
||||
|
||||
expect(findCorpConfigFile("alpha")).toBe(join(dir, "alpha.json"));
|
||||
expect(findCorpConfigFile("nonexistent")).toBeUndefined();
|
||||
|
||||
const updated = updateCorpConfig("alpha", {
|
||||
environment: "production",
|
||||
testCorpId: "alpha-test"
|
||||
});
|
||||
|
||||
expect(updated.id).toBe("alpha");
|
||||
expect(updated.environment).toBe("production");
|
||||
expect(updated.testCorpId).toBe("alpha-test");
|
||||
|
||||
// Check on-disk persistence
|
||||
const reloaded = loadCorpConfigs().find((c) => c.id === "alpha");
|
||||
expect(reloaded?.testCorpId).toBe("alpha-test");
|
||||
|
||||
// Unsetting / clearing testCorpId
|
||||
const cleared = updateCorpConfig("alpha", {
|
||||
testCorpId: undefined
|
||||
});
|
||||
expect(cleared.testCorpId).toBeUndefined();
|
||||
const reloadedAfterClear = loadCorpConfigs().find((c) => c.id === "alpha");
|
||||
expect(reloadedAfterClear?.testCorpId).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
function makeTempDir(): string {
|
||||
|
||||
@@ -104,3 +104,42 @@ export function saveGlobalConfig(config: GlobalConfigInput): GlobalConfig {
|
||||
writeFileSync(file, `${JSON.stringify(normalized, null, 2)}\n`, { mode: 0o600 });
|
||||
return normalized;
|
||||
}
|
||||
|
||||
export function findCorpConfigFile(corpId: string): string | undefined {
|
||||
const dirs = resolveEnterprisesDirs();
|
||||
for (const dir of dirs) {
|
||||
if (!existsSync(dir)) continue;
|
||||
for (const file of readdirSync(dir)
|
||||
.filter((item) => item.endsWith(".json"))
|
||||
.filter((item) => !item.startsWith("example."))) {
|
||||
const fullPath = join(dir, file);
|
||||
try {
|
||||
const content = readFileSync(fullPath, "utf-8");
|
||||
const parsed = JSON.parse(content);
|
||||
if (parsed && typeof parsed === "object" && parsed.id === corpId) {
|
||||
return fullPath;
|
||||
}
|
||||
} catch {
|
||||
// ignore malformed files
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function updateCorpConfig(corpId: string, patch: Partial<CorpConfig>): CorpConfig {
|
||||
const filePath = findCorpConfigFile(corpId);
|
||||
if (!filePath) {
|
||||
throw new Error(`Enterprise config not found: ${corpId}`);
|
||||
}
|
||||
const raw = JSON.parse(readFileSync(filePath, "utf-8"));
|
||||
const merged = { ...raw, ...patch };
|
||||
for (const key of Object.keys(patch) as Array<keyof CorpConfig>) {
|
||||
if (patch[key] === undefined) {
|
||||
delete merged[key];
|
||||
}
|
||||
}
|
||||
const validated = CorpConfigSchema.parse(merged);
|
||||
writeFileSync(filePath, `${JSON.stringify(validated, null, 2)}\n`, "utf-8");
|
||||
return validated;
|
||||
}
|
||||
@@ -6,6 +6,7 @@ function corp(id: string, name = id): CorpConfig {
|
||||
return {
|
||||
id,
|
||||
name,
|
||||
environment: "production",
|
||||
seal: {
|
||||
endpoints: {
|
||||
approvalStylePreferences: "api/v1/agent/ai-approval/config"
|
||||
|
||||
@@ -97,6 +97,39 @@ describe("CorpConfigSchema", () => {
|
||||
|
||||
expect(config.seal.headers).toBeUndefined();
|
||||
expect(config.seal.cookies).toBeUndefined();
|
||||
expect(config.environment).toBe("production");
|
||||
expect(config.testCorpId).toBeUndefined();
|
||||
expect(config.prodCorpId).toBeUndefined();
|
||||
});
|
||||
|
||||
test("accepts environment, testCorpId, and prodCorpId", () => {
|
||||
const prodConfig = CorpConfigSchema.parse({
|
||||
id: "prod-corp",
|
||||
name: "Prod Corp",
|
||||
environment: "production",
|
||||
testCorpId: "test-corp",
|
||||
source: {
|
||||
type: "direct",
|
||||
token: "seal-token",
|
||||
sealUrl: "https://direct.sealai.cc"
|
||||
}
|
||||
});
|
||||
expect(prodConfig.environment).toBe("production");
|
||||
expect(prodConfig.testCorpId).toBe("test-corp");
|
||||
|
||||
const testConfig = CorpConfigSchema.parse({
|
||||
id: "test-corp",
|
||||
name: "Test Corp",
|
||||
environment: "test",
|
||||
prodCorpId: "prod-corp",
|
||||
source: {
|
||||
type: "direct",
|
||||
token: "seal-token",
|
||||
sealUrl: "https://direct.sealai.cc"
|
||||
}
|
||||
});
|
||||
expect(testConfig.environment).toBe("test");
|
||||
expect(testConfig.prodCorpId).toBe("prod-corp");
|
||||
});
|
||||
|
||||
test("accepts custom headers and cookies on the Seal endpoint", () => {
|
||||
|
||||
@@ -105,12 +105,17 @@ export const CorpAuthConfigSchema = z.object({
|
||||
refreshTtl: z.number().int().positive().default(300)
|
||||
}).default({ refreshTtl: 300 });
|
||||
|
||||
export const CorpEnvironmentSchema = z.enum(["production", "test"]).default("production");
|
||||
|
||||
export const CorpConfigSchema = z.object({
|
||||
id: z.string(),
|
||||
name: z.string(),
|
||||
seal: SealEndpointSchema,
|
||||
source: SealSourceSchema,
|
||||
auth: CorpAuthConfigSchema
|
||||
auth: CorpAuthConfigSchema,
|
||||
environment: CorpEnvironmentSchema,
|
||||
testCorpId: z.string().optional(),
|
||||
prodCorpId: z.string().optional()
|
||||
});
|
||||
|
||||
export const GlobalLintConfigSchema = z.object({
|
||||
@@ -130,6 +135,7 @@ export const GlobalConfigSchema = z.object({
|
||||
lint: GlobalLintConfigSchema
|
||||
});
|
||||
|
||||
export type CorpEnvironment = z.infer<typeof CorpEnvironmentSchema>;
|
||||
export type HoseSealSource = z.infer<typeof HoseSealSourceSchema>;
|
||||
export type DirectSealSource = z.infer<typeof DirectSealSourceSchema>;
|
||||
export type NativeSealSource = z.infer<typeof NativeSealSourceSchema>;
|
||||
|
||||
Reference in new issue
Block a user