test: micro-optimize slow suites and CLI command setup

This commit is contained in:
Peter Steinberger
2026-03-02 23:00:42 +00:00
parent ba5ae5b4f1
commit 2287d1ec13
7 changed files with 259 additions and 164 deletions

View File

@@ -3,28 +3,17 @@ import { buildConfigSchema } from "./schema.js";
import { applyDerivedTags, CONFIG_TAGS, deriveTagsForPath } from "./schema.tags.js";
describe("config schema", () => {
type SchemaInput = NonNullable<Parameters<typeof buildConfigSchema>[0]>;
let baseSchema: ReturnType<typeof buildConfigSchema>;
let pluginUiHintInput: SchemaInput;
let tokenHintInput: SchemaInput;
let mergedSchemaInput: SchemaInput;
let heartbeatChannelInput: SchemaInput;
let cachedMergeInput: SchemaInput;
beforeAll(() => {
baseSchema = buildConfigSchema();
});
it("exports schema + hints", () => {
const res = baseSchema;
const schema = res.schema as { properties?: Record<string, unknown> };
expect(schema.properties?.gateway).toBeTruthy();
expect(schema.properties?.agents).toBeTruthy();
expect(schema.properties?.acp).toBeTruthy();
expect(schema.properties?.$schema).toBeUndefined();
expect(res.uiHints.gateway?.label).toBe("Gateway");
expect(res.uiHints["gateway.auth.token"]?.sensitive).toBe(true);
expect(res.uiHints["channels.discord.threadBindings.spawnAcpSessions"]?.label).toBeTruthy();
expect(res.version).toBeTruthy();
expect(res.generatedAt).toBeTruthy();
});
it("merges plugin ui hints", () => {
const res = buildConfigSchema({
pluginUiHintInput = {
plugins: [
{
id: "voice-call",
@@ -36,18 +25,8 @@ describe("config schema", () => {
},
},
],
});
expect(res.uiHints["plugins.entries.voice-call"]?.label).toBe("Voice Call");
expect(res.uiHints["plugins.entries.voice-call.config"]?.label).toBe("Voice Call Config");
expect(res.uiHints["plugins.entries.voice-call.config.twilio.authToken"]?.label).toBe(
"Auth Token",
);
expect(res.uiHints["plugins.entries.voice-call.config.twilio.authToken"]?.sensitive).toBe(true);
});
it("does not re-mark existing non-sensitive token-like fields", () => {
const res = buildConfigSchema({
};
tokenHintInput = {
plugins: [
{
id: "voice-call",
@@ -56,13 +35,8 @@ describe("config schema", () => {
},
},
],
});
expect(res.uiHints["plugins.entries.voice-call.config.tokens"]?.sensitive).toBe(false);
});
it("merges plugin + channel schemas", () => {
const res = buildConfigSchema({
};
mergedSchemaInput = {
plugins: [
{
id: "voice-call",
@@ -87,7 +61,67 @@ describe("config schema", () => {
},
},
],
});
};
heartbeatChannelInput = {
channels: [
{
id: "bluebubbles",
label: "BlueBubbles",
configSchema: { type: "object" },
},
],
};
cachedMergeInput = {
plugins: [
{
id: "voice-call",
name: "Voice Call",
configSchema: { type: "object", properties: { provider: { type: "string" } } },
},
],
channels: [
{
id: "matrix",
label: "Matrix",
configSchema: { type: "object", properties: { accessToken: { type: "string" } } },
},
],
};
});
it("exports schema + hints", () => {
const res = baseSchema;
const schema = res.schema as { properties?: Record<string, unknown> };
expect(schema.properties?.gateway).toBeTruthy();
expect(schema.properties?.agents).toBeTruthy();
expect(schema.properties?.acp).toBeTruthy();
expect(schema.properties?.$schema).toBeUndefined();
expect(res.uiHints.gateway?.label).toBe("Gateway");
expect(res.uiHints["gateway.auth.token"]?.sensitive).toBe(true);
expect(res.uiHints["channels.discord.threadBindings.spawnAcpSessions"]?.label).toBeTruthy();
expect(res.version).toBeTruthy();
expect(res.generatedAt).toBeTruthy();
});
it("merges plugin ui hints", () => {
const res = buildConfigSchema(pluginUiHintInput);
expect(res.uiHints["plugins.entries.voice-call"]?.label).toBe("Voice Call");
expect(res.uiHints["plugins.entries.voice-call.config"]?.label).toBe("Voice Call Config");
expect(res.uiHints["plugins.entries.voice-call.config.twilio.authToken"]?.label).toBe(
"Auth Token",
);
expect(res.uiHints["plugins.entries.voice-call.config.twilio.authToken"]?.sensitive).toBe(true);
});
it("does not re-mark existing non-sensitive token-like fields", () => {
const res = buildConfigSchema(tokenHintInput);
expect(res.uiHints["plugins.entries.voice-call.config.tokens"]?.sensitive).toBe(false);
});
it("merges plugin + channel schemas", () => {
const res = buildConfigSchema(mergedSchemaInput);
const schema = res.schema as {
properties?: Record<string, unknown>;
@@ -110,15 +144,7 @@ describe("config schema", () => {
});
it("adds heartbeat target hints with dynamic channels", () => {
const res = buildConfigSchema({
channels: [
{
id: "bluebubbles",
label: "BlueBubbles",
configSchema: { type: "object" },
},
],
});
const res = buildConfigSchema(heartbeatChannelInput);
const defaultsHint = res.uiHints["agents.defaults.heartbeat.target"];
const listHint = res.uiHints["agents.list.*.heartbeat.target"];
@@ -128,26 +154,10 @@ describe("config schema", () => {
});
it("caches merged schemas for identical plugin/channel metadata", () => {
const params = {
plugins: [
{
id: "voice-call",
name: "Voice Call",
configSchema: { type: "object", properties: { provider: { type: "string" } } },
},
],
channels: [
{
id: "matrix",
label: "Matrix",
configSchema: { type: "object", properties: { accessToken: { type: "string" } } },
},
],
};
const first = buildConfigSchema(params);
const first = buildConfigSchema(cachedMergeInput);
const second = buildConfigSchema({
plugins: [{ ...params.plugins[0] }],
channels: [{ ...params.channels[0] }],
plugins: [{ ...cachedMergeInput.plugins![0] }],
channels: [{ ...cachedMergeInput.channels![0] }],
});
expect(second).toBe(first);
});