Add one-shot run diagnosis and agent-feedback hardening
This commit is contained in:
1 parent
951c8fc372
commit
f2738ee4a3
15 files changed
+583
-49
No files matched your search
@@ -124,7 +124,7 @@ describe("loadCorpConfigs", () => {
|
||||
expect(loadGlobalConfig()).toEqual({
|
||||
stateful: false,
|
||||
lint: {
|
||||
enabled: false,
|
||||
enabled: true,
|
||||
activeLinter: "builtin",
|
||||
minScore: 0
|
||||
}
|
||||
@@ -140,7 +140,7 @@ describe("loadCorpConfigs", () => {
|
||||
defaultCorpId: "corp-a",
|
||||
testEnterprisesDir: "/tmp/test-corps",
|
||||
lint: {
|
||||
enabled: false,
|
||||
enabled: true,
|
||||
activeLinter: "builtin",
|
||||
minScore: 0
|
||||
}
|
||||
@@ -151,7 +151,7 @@ describe("loadCorpConfigs", () => {
|
||||
defaultCorpId: "corp-a",
|
||||
testEnterprisesDir: "/tmp/test-corps",
|
||||
lint: {
|
||||
enabled: false,
|
||||
enabled: true,
|
||||
activeLinter: "builtin",
|
||||
minScore: 0
|
||||
}
|
||||
|
||||
@@ -203,7 +203,7 @@ describe("GlobalConfigSchema", () => {
|
||||
expect(GlobalConfigSchema.parse({})).toEqual({
|
||||
stateful: false,
|
||||
lint: {
|
||||
enabled: false,
|
||||
enabled: true,
|
||||
activeLinter: "builtin",
|
||||
minScore: 0
|
||||
}
|
||||
@@ -218,7 +218,7 @@ describe("GlobalConfigSchema", () => {
|
||||
stateful: true,
|
||||
defaultCorpId: "corp-a",
|
||||
lint: {
|
||||
enabled: false,
|
||||
enabled: true,
|
||||
activeLinter: "builtin",
|
||||
minScore: 0
|
||||
}
|
||||
|
||||
@@ -121,11 +121,11 @@ export const CorpConfigSchema = z.object({
|
||||
});
|
||||
|
||||
export const GlobalLintConfigSchema = z.object({
|
||||
enabled: z.boolean().default(false),
|
||||
enabled: z.boolean().default(true),
|
||||
activeLinter: z.string().default("builtin"),
|
||||
minScore: z.number().min(0).max(100).default(0)
|
||||
}).default({
|
||||
enabled: false,
|
||||
enabled: true,
|
||||
activeLinter: "builtin",
|
||||
minScore: 0
|
||||
});
|
||||
|
||||
@@ -96,12 +96,80 @@ describe("tenant-diagnose", () => {
|
||||
expect(result.rules.activeCount).toBe(1);
|
||||
expect(result.webhooks.hasReplayChannel).toBe(true);
|
||||
expect(result.summary.failedChecks).toBe(0);
|
||||
expect(result.corp.boundCorpId).toBe("prod-corp");
|
||||
expect(result.corp.boundCorpRole).toBe("prodParent");
|
||||
|
||||
const dashboard = formatTenantDoctorDashboard(result);
|
||||
expect(dashboard).toContain("HEALTHY");
|
||||
expect(dashboard).toContain("5000");
|
||||
});
|
||||
|
||||
test("reports an unknown quota instead of degrading after transient billing timeouts", async () => {
|
||||
const base = createMockClient({});
|
||||
let billingCalls = 0;
|
||||
const flakyClient = {
|
||||
get: async (url: string) => {
|
||||
if (url === "api/v1/billing/status") {
|
||||
billingCalls += 1;
|
||||
throw new Error("Request timed out after 15000ms");
|
||||
}
|
||||
return base.get(url);
|
||||
}
|
||||
} as any;
|
||||
|
||||
const testCorp: CorpConfig = {
|
||||
id: "test-corp",
|
||||
name: "园测企业",
|
||||
environment: "test",
|
||||
prodCorpId: "prod-corp",
|
||||
source: { type: "seal" },
|
||||
seal: { url: "https://test.sealai.cc" }
|
||||
} as any;
|
||||
|
||||
const result = await diagnoseTenantContract(flakyClient, testCorp);
|
||||
|
||||
expect(billingCalls).toBe(2);
|
||||
expect(result.verdict).toBe("HEALTHY");
|
||||
expect(result.quota.status).toBe("unknown");
|
||||
expect(result.summary.unknownChecks).toBe(1);
|
||||
const billingCheck = result.checks.find((check) => check.id === "billing_quota");
|
||||
expect(billingCheck?.status).toBe("unknown");
|
||||
|
||||
const dashboard = formatTenantDoctorDashboard(result);
|
||||
expect(dashboard).toContain("未知");
|
||||
});
|
||||
|
||||
test("recovers a transient billing timeout via the built-in retry", async () => {
|
||||
const base = createMockClient({});
|
||||
let billingCalls = 0;
|
||||
const flakyClient = {
|
||||
get: async (url: string) => {
|
||||
if (url === "api/v1/billing/status") {
|
||||
billingCalls += 1;
|
||||
if (billingCalls === 1) {
|
||||
throw new Error("fetch failed: socket hang up");
|
||||
}
|
||||
}
|
||||
return base.get(url);
|
||||
}
|
||||
} as any;
|
||||
|
||||
const testCorp: CorpConfig = {
|
||||
id: "test-corp",
|
||||
name: "重试恢复企业",
|
||||
environment: "test",
|
||||
prodCorpId: "prod-corp",
|
||||
source: { type: "seal" },
|
||||
seal: { url: "https://test.sealai.cc" }
|
||||
} as any;
|
||||
|
||||
const result = await diagnoseTenantContract(flakyClient, testCorp);
|
||||
|
||||
expect(billingCalls).toBe(2);
|
||||
expect(result.verdict).toBe("HEALTHY");
|
||||
expect(result.quota.status).toBe("sufficient");
|
||||
});
|
||||
|
||||
test("flags warning for low quota and unbound prod corp", async () => {
|
||||
const mockClient = createMockClient({
|
||||
billing: {
|
||||
@@ -128,6 +196,10 @@ describe("tenant-diagnose", () => {
|
||||
expect(result.quota.status).toBe("low");
|
||||
expect(result.rules.totalCount).toBe(0);
|
||||
expect(result.summary.warningChecks).toBeGreaterThan(0);
|
||||
// An unbound corp must not advertise a binding role.
|
||||
expect(result.corp.boundCorpId).toBeUndefined();
|
||||
expect(result.corp.boundCorpRole).toBeUndefined();
|
||||
expect(result.corp.boundCorpRoleDescription).toBeUndefined();
|
||||
});
|
||||
|
||||
test("flags fail when quota is exhausted or auth fails", async () => {
|
||||
|
||||
Reference in new issue
Block a user