Skip to content

Beautiful, AI-native markdown IDE and LLM wiki

24.1 KB
Raw Blame
import { describe, expect, test } from 'vitest';
import { z } from 'zod';
import { SUPPORTED_LOCALES } from '../i18n/locales.ts';
import {
  attachmentFolderForDocument,
  attachmentFolderPathVariableIssue,
  ConfigSchema,
  checkEmbeddingsBaseUrl,
  isValidAttachmentFolderPath,
  normalizeAttachmentFolderPath,
} from './schema.ts';
import { getLeafFieldMeta } from './schema-leaf.ts';

describe('checkEmbeddingsBaseUrl', () => {
  test('accepts https endpoints', () => {
    expect(checkEmbeddingsBaseUrl('https://api.openai.com/v1')).toBeNull();
    expect(checkEmbeddingsBaseUrl('https://azure.example.com/openai/v1/')).toBeNull();
    expect(checkEmbeddingsBaseUrl('https://api.example.com')).toBeNull();
  });

  test('accepts http only for loopback hosts (key never leaves the machine)', () => {
    expect(checkEmbeddingsBaseUrl('http://localhost:11434/v1')).toBeNull();
    expect(checkEmbeddingsBaseUrl('http://127.0.0.1:8080/v1')).toBeNull();
    expect(checkEmbeddingsBaseUrl('http://[::1]:1234/v1')).toBeNull();
  });

  test('rejects plaintext http to a non-loopback host', () => {
    expect(checkEmbeddingsBaseUrl('http://evil.example/v1')).toBe('insecure-scheme');
    expect(checkEmbeddingsBaseUrl('http://api.openai.com/v1')).toBe('insecure-scheme');
  });

  test('rejects non-http(s) schemes', () => {
    expect(checkEmbeddingsBaseUrl('ftp://api.example.com')).toBe('insecure-scheme');
    expect(checkEmbeddingsBaseUrl('file:///etc/passwd')).toBe('insecure-scheme');
  });

  test('rejects unparseable input', () => {
    expect(checkEmbeddingsBaseUrl('not a url')).toBe('invalid-url');
    expect(checkEmbeddingsBaseUrl('api.openai.com/v1')).toBe('invalid-url');
    expect(checkEmbeddingsBaseUrl('')).toBe('invalid-url');
  });
});

describe('content.attachmentFolderPath', () => {
  test('accepts brace values, so a bad variable never invalidates the rest of the config', () => {
    for (const value of ['./{{filename', 'a}}b', './{{filename}}{{filename}}']) {
      const parsed = ConfigSchema.safeParse({
        content: { attachmentFolderPath: value },
        validation: { links: 'error' },
      });
      expect(parsed.success).toBe(true);
    }
  });

  test.each([
    ['/uploads/{{filename}}/img', null],
    ['/attachments', null],
    ['attachments', null],
    ['uploads/{{filename}}', null],
    ['/{{filename}}/{{filename}}', null],
    ['./{{ date }}', { kind: 'unknown-variable', variables: ['{{ date }}'] }],
    ['./filename}}', { kind: 'unclosed-braces' }],
  ])('attachmentFolderPathVariableIssue(%s)', (value, expected) => {
    expect(attachmentFolderPathVariableIssue(value)).toEqual(expected);
  });

  test('defaults to a folder per document when absent', () => {
    expect(ConfigSchema.parse({}).content.attachmentFolderPath).toBe('./{{filename}}.assets');
  });

  test('defaults to a folder per document when key is absent inside content', () => {
    expect(ConfigSchema.parse({ content: { dir: 'docs' } }).content.attachmentFolderPath).toBe(
      './{{filename}}.assets',
    );
  });

  test('accepts "./" (colocated with current document)', () => {
    expect(
      ConfigSchema.parse({ content: { attachmentFolderPath: './' } }).content.attachmentFolderPath,
    ).toBe('./');
  });

  test('accepts "/" (content-root sentinel)', () => {
    expect(
      ConfigSchema.parse({ content: { attachmentFolderPath: '/' } }).content.attachmentFolderPath,
    ).toBe('/');
  });

  test('accepts "./attachments" (subfolder under current document folder)', () => {
    expect(
      ConfigSchema.parse({ content: { attachmentFolderPath: './attachments' } }).content
        .attachmentFolderPath,
    ).toBe('./attachments');
  });

  test('accepts "attachments" (fixed folder under content root)', () => {
    expect(
      ConfigSchema.parse({ content: { attachmentFolderPath: 'attachments' } }).content
        .attachmentFolderPath,
    ).toBe('attachments');
  });

  test('accepts "assets/uploads" (nested path under content root)', () => {
    expect(
      ConfigSchema.parse({ content: { attachmentFolderPath: 'assets/uploads' } }).content
        .attachmentFolderPath,
    ).toBe('assets/uploads');
  });

  test('normalizes empty string to the default', () => {
    expect(normalizeAttachmentFolderPath('')).toBe('./{{filename}}.assets');
    expect(isValidAttachmentFolderPath('')).toBe(true);
  });

  test('normalizes whitespace-only to the default', () => {
    expect(normalizeAttachmentFolderPath('   ')).toBe('./{{filename}}.assets');
    expect(isValidAttachmentFolderPath('   ')).toBe(true);
  });

  test('rejects ".." traversal segment', () => {
    expect(() => ConfigSchema.parse({ content: { attachmentFolderPath: '..' } })).toThrow();
  });

  test('rejects "../escape" traversal', () => {
    expect(() => ConfigSchema.parse({ content: { attachmentFolderPath: '../escape' } })).toThrow();
  });

  test('rejects nested traversal "good/../../../etc"', () => {
    expect(() =>
      ConfigSchema.parse({ content: { attachmentFolderPath: 'good/../../../etc' } }),
    ).toThrow();
  });

  test('rejects NUL byte', () => {
    expect(() =>
      ConfigSchema.parse({ content: { attachmentFolderPath: 'attach\0ments' } }),
    ).toThrow();
  });

  test('rejects a drive letter', () => {
    expect(isValidAttachmentFolderPath('C:/attachments')).toBe(false);
    expect(isValidAttachmentFolderPath('/C:/attachments')).toBe(false);
    expect(isValidAttachmentFolderPath('./C:/attachments')).toBe(false);
  });

  test('rejects backslash', () => {
    expect(() =>
      ConfigSchema.parse({ content: { attachmentFolderPath: 'attach\\ments' } }),
    ).toThrow();
  });

  test('reads a leading slash as the content root, so "/etc/passwd" stays inside the project', () => {
    expect(
      ConfigSchema.parse({ content: { attachmentFolderPath: '/etc/passwd' } }).content
        .attachmentFolderPath,
    ).toBe('/etc/passwd');
    expect(attachmentFolderForDocument('/etc/passwd', 'docs/guide.md')).toBe('etc/passwd');
  });

  test('accepts "/attachments" as a folder at the content root', () => {
    expect(
      ConfigSchema.parse({ content: { attachmentFolderPath: '/attachments' } }).content
        .attachmentFolderPath,
    ).toBe('/attachments');
    expect(attachmentFolderForDocument('/attachments', 'docs/guide.md')).toBe('attachments');
  });

  test('rejects Windows drive-letter path "C:/"', () => {
    expect(() => ConfigSchema.parse({ content: { attachmentFolderPath: 'C:/' } })).toThrow();
  });

  test('rejects Windows drive-letter path "D:attachments"', () => {
    expect(() =>
      ConfigSchema.parse({ content: { attachmentFolderPath: 'D:attachments' } }),
    ).toThrow();
  });
});

describe('appearance.sidebar view toggles', () => {
  test('sidebar defaults: hidden files off, only-markdown off, Skills section on, .ok folders off, grouping on', () => {
    const sidebar = ConfigSchema.parse({ appearance: { sidebar: {} } }).appearance.sidebar;
    expect(sidebar).toEqual({
      showHiddenFiles: false,
      showOnlyMarkdownFiles: false,
      showSkillsSection: true,
      showOkFolders: false,
      showSkillGroups: true,
      pinnedProjectSkills: [],
      pinnedGlobalSkills: [],
    });
  });

  test('explicit values override every toggle default', () => {
    const sidebar = ConfigSchema.parse({
      appearance: {
        sidebar: {
          showHiddenFiles: true,
          showOnlyMarkdownFiles: true,
          showSkillsSection: false,
          showOkFolders: true,
          showSkillGroups: false,
          pinnedProjectSkills: ['mine'],
          pinnedGlobalSkills: ['ponytail'],
        },
      },
    }).appearance.sidebar;
    expect(sidebar).toEqual({
      showHiddenFiles: true,
      showOnlyMarkdownFiles: true,
      showSkillsSection: false,
      showOkFolders: true,
      showSkillGroups: false,
      pinnedProjectSkills: ['mine'],
      pinnedGlobalSkills: ['ponytail'],
    });
  });
});

describe('appearance.language', () => {
  test('accepts every enumerated locale plus the system sentinel', () => {
    for (const locale of [...SUPPORTED_LOCALES, 'system']) {
      const parsed = ConfigSchema.parse({ appearance: { language: locale } });
      expect(parsed.appearance.language).toBe(locale);
    }
  });

  test('rejects a language with no catalog behind it', () => {
    const result = ConfigSchema.safeParse({ appearance: { language: 'ja' } });
    expect(result.success).toBe(false);
  });

  test('is absent rather than defaulted when unset', () => {
    expect(ConfigSchema.parse({}).appearance.language).toBeUndefined();
  });
});

describe('editor preferences', () => {
  test('preview tabs default on and preserve an explicit opt-out', () => {
    expect(ConfigSchema.parse({}).editor.previewTabs).toBe(true);
    expect(ConfigSchema.parse({ editor: { previewTabs: false } }).editor.previewTabs).toBe(false);
  });
});

describe('linkPreviews.enabled (external link-hover preview egress default)', () => {
  test('defaults to enabled when the block is absent', () => {
    expect(ConfigSchema.parse({}).linkPreviews).toEqual({ enabled: true });
  });

  test('defaults enabled to true when linkPreviews is present but enabled is absent', () => {
    expect(ConfigSchema.parse({ linkPreviews: {} }).linkPreviews.enabled).toBe(true);
  });

  test('accepts an explicit opt-out', () => {
    expect(ConfigSchema.parse({ linkPreviews: { enabled: false } }).linkPreviews.enabled).toBe(
      false,
    );
  });

  test('accepts an explicit opt-in', () => {
    expect(ConfigSchema.parse({ linkPreviews: { enabled: true } }).linkPreviews.enabled).toBe(true);
  });
});

describe('validation.suppressLogLinkAdvisories (reserved-log advisory policy)', () => {
  test('defaults to enabled when the validation block is absent', () => {
    expect(ConfigSchema.parse({}).validation.suppressLogLinkAdvisories).toBe(true);
  });

  test('defaults to enabled when validation is present but the key is absent', () => {
    expect(
      ConfigSchema.parse({ validation: { links: 'error' } }).validation.suppressLogLinkAdvisories,
    ).toBe(true);
  });

  test('accepts an explicit opt-out', () => {
    expect(
      ConfigSchema.parse({ validation: { suppressLogLinkAdvisories: false } }).validation
        .suppressLogLinkAdvisories,
    ).toBe(false);
  });

  test('accepts an explicit opt-in', () => {
    expect(
      ConfigSchema.parse({ validation: { suppressLogLinkAdvisories: true } }).validation
        .suppressLogLinkAdvisories,
    ).toBe(true);
  });

  test('rejects a non-boolean value', () => {
    expect(
      ConfigSchema.safeParse({ validation: { suppressLogLinkAdvisories: 'yes' } }).success,
    ).toBe(false);
    expect(ConfigSchema.safeParse({ validation: { suppressLogLinkAdvisories: 1 } }).success).toBe(
      false,
    );
  });

  test('is a project-shared, live, non-agent-settable field', () => {
    expect(
      getLeafFieldMeta(ConfigSchema, ['validation', 'suppressLogLinkAdvisories']),
    ).toMatchObject({
      scope: 'project',
      defaultScope: 'project',
      agentSettable: false,
      reload: 'live',
    });
  });

  test('names the reserved logs and the stem/extension casing split in its published description', () => {
    const description = getLeafFieldMeta(ConfigSchema, [
      'validation',
      'suppressLogLinkAdvisories',
    ])?.description;
    expect(description).toContain('log.md');
    expect(description).toContain('log.mdx');
    expect(description).toContain("the extension's case does not matter");
    expect(description).toContain('LOG.md');
  });
});

describe('slides.enabled (Slides plugin toggle default)', () => {
  test('resolves to disabled when the section is absent', () => {
    expect(ConfigSchema.parse({}).slides).toEqual({ enabled: false });
  });

  test('defaults enabled to false when slides is present but enabled is absent', () => {
    expect(ConfigSchema.parse({ slides: {} }).slides.enabled).toBe(false);
  });

  test('accepts an explicit opt-in', () => {
    expect(ConfigSchema.parse({ slides: { enabled: true } }).slides.enabled).toBe(true);
  });

  test('accepts an explicit opt-out', () => {
    expect(ConfigSchema.parse({ slides: { enabled: false } }).slides.enabled).toBe(false);
  });
});

describe('legacy upload.* keys remain non-authoritative', () => {
  test('upload.* keys pass through looseObject without schema error', () => {
    const result = ConfigSchema.safeParse({
      upload: { attachmentFolder: 'attachments', maxSize: 10485760 },
    });
    expect(result.success).toBe(true);
  });
});

describe('contentRules forward compatibility', () => {
  test('an unknown plugin slice survives parse instead of being stripped', () => {
    const parsed = ConfigSchema.parse({
      contentRules: { 'future-linter': { enabled: true, level: 'strict' } },
    });
    expect(parsed.contentRules['future-linter']).toEqual({
      enabled: true,
      level: 'strict',
    });
    expect(parsed.contentRules.markdownlint).toEqual({ enabled: false });
  });
});

describe('autoSync.mode (canonical per-machine sync knob)', () => {
  test('defaults to null (unanswered) when the whole block is absent', () => {
    expect(ConfigSchema.parse({}).autoSync).toEqual({ mode: null, enabled: null, default: null });
  });

  test('accepts each sync mode', () => {
    for (const mode of ['off', 'pull', 'full'] as const) {
      expect(ConfigSchema.parse({ autoSync: { mode } }).autoSync.mode).toBe(mode);
    }
  });

  test('accepts an explicit null', () => {
    expect(ConfigSchema.parse({ autoSync: { mode: null } }).autoSync.mode).toBeNull();
  });

  test('rejects a value outside the mode vocabulary', () => {
    expect(ConfigSchema.safeParse({ autoSync: { mode: 'sideways' } }).success).toBe(false);
    expect(ConfigSchema.safeParse({ autoSync: { mode: true } }).success).toBe(false);
  });

  test('the legacy enabled boolean still parses (derived to a mode only at read time)', () => {
    expect(ConfigSchema.parse({ autoSync: { enabled: true } }).autoSync.enabled).toBe(true);
    expect(ConfigSchema.parse({ autoSync: { enabled: false } }).autoSync.enabled).toBe(false);
    expect(ConfigSchema.parse({ autoSync: { enabled: null } }).autoSync.enabled).toBeNull();
  });
});

describe('autoSync.default (committed seed widened to the mode vocabulary)', () => {
  test('accepts the mode strings', () => {
    for (const mode of ['off', 'pull', 'full'] as const) {
      expect(ConfigSchema.parse({ autoSync: { default: mode } }).autoSync.default).toBe(mode);
    }
  });

  test('still accepts the legacy boolean seed', () => {
    expect(ConfigSchema.parse({ autoSync: { default: true } }).autoSync.default).toBe(true);
    expect(ConfigSchema.parse({ autoSync: { default: false } }).autoSync.default).toBe(false);
  });

  test('accepts an explicit null (ask)', () => {
    expect(ConfigSchema.parse({ autoSync: { default: null } }).autoSync.default).toBeNull();
  });

  test('rejects a value outside the boolean|mode union', () => {
    expect(ConfigSchema.safeParse({ autoSync: { default: 'sideways' } }).success).toBe(false);
    expect(ConfigSchema.safeParse({ autoSync: { default: 3 } }).success).toBe(false);
  });
});

describe('autoSync forward/backward compatibility (looseObject round-trip)', () => {
  test('unknown autoSync sub-keys survive parse instead of being stripped', () => {
    const parsed = ConfigSchema.parse({
      autoSync: { mode: 'pull', onboardingResolvedAt: '2026-01-01', inheritedFrom: 'root' },
    });
    expect(parsed.autoSync.mode).toBe('pull');
    expect((parsed.autoSync as Record<string, unknown>).onboardingResolvedAt).toBe('2026-01-01');
    expect((parsed.autoSync as Record<string, unknown>).inheritedFrom).toBe('root');
  });

  test('an older mode-unaware schema reads a mode-only config as sync-off, never pushing', () => {
    const legacyAutoSync = z
      .looseObject({
        enabled: z.boolean().nullable().default(null),
        default: z.boolean().nullable().default(null),
      })
      .default({ enabled: null, default: null });
    const legacySchema = z.looseObject({ autoSync: legacyAutoSync });

    const parsed = legacySchema.parse({ autoSync: { mode: 'pull' } });
    expect((parsed.autoSync as Record<string, unknown>).mode).toBe('pull');
    expect(parsed.autoSync.enabled).toBeNull();
    expect(parsed.autoSync.default).toBeNull();

    const legacyBootResolvesEnabled =
      parsed.autoSync.enabled !== null && parsed.autoSync.enabled !== undefined
        ? parsed.autoSync.enabled === true
        : parsed.autoSync.default === true;
    expect(legacyBootResolvesEnabled).toBe(false);
  });

  test('a committed default:"pull" fails an older schema wholesale — the accepted skew cost', () => {
    const legacyAutoSync = z
      .looseObject({
        enabled: z.boolean().nullable().default(null),
        default: z.boolean().nullable().default(null),
      })
      .default({ enabled: null, default: null });
    const legacySchema = z.looseObject({ autoSync: legacyAutoSync });

    expect(legacySchema.safeParse({ autoSync: { mode: 'pull' } }).success).toBe(true);
    expect(legacySchema.safeParse({ autoSync: { default: 'pull' } }).success).toBe(false);

    const legacyDefaults = legacySchema.parse({});
    expect(legacyDefaults.autoSync.default).toBeNull();
  });
});

describe('server.* (canonical listener/exposure surface)', () => {
  test('defaults: loopback-only bind, consent off, everything else unset', () => {
    const config = ConfigSchema.parse({});
    expect(config.server.bind).toEqual(['127.0.0.1']);
    expect(config.server.allowExternal).toBe(false);
    expect(config.server.port).toBeUndefined();
    expect(config.server.externalUrl).toBeUndefined();
    expect(config.server.openBrowser).toBeUndefined();
    expect(config.server.idleShutdown).toBeUndefined();
  });

  test('port accepts the valid range and rejects out-of-range or fractional values', () => {
    expect(ConfigSchema.parse({ server: { port: 8080 } }).server.port).toBe(8080);
    expect(ConfigSchema.safeParse({ server: { port: 0 } }).success).toBe(false);
    expect(ConfigSchema.safeParse({ server: { port: 65536 } }).success).toBe(false);
    expect(ConfigSchema.safeParse({ server: { port: 80.5 } }).success).toBe(false);
  });

  test('bind is a non-empty list of non-empty addresses', () => {
    expect(ConfigSchema.parse({ server: { bind: ['0.0.0.0'] } }).server.bind).toEqual(['0.0.0.0']);
    expect(ConfigSchema.parse({ server: { bind: ['127.0.0.1', '::1'] } }).server.bind).toEqual([
      '127.0.0.1',
      '::1',
    ]);
    expect(ConfigSchema.safeParse({ server: { bind: [] } }).success).toBe(false);
    expect(ConfigSchema.safeParse({ server: { bind: [''] } }).success).toBe(false);
    expect(ConfigSchema.safeParse({ server: { bind: '127.0.0.1' } }).success).toBe(false);
  });

  test('bind is registered project-local so a committed value is ignored (clone-safety)', () => {
    const meta = getLeafFieldMeta(ConfigSchema, ['server', 'bind']);
    expect(meta?.scope).toBe('project-local');
    expect(meta?.defaultScope).toBe('project-local');
  });

  test('externalUrl accepts http(s) URLs and rejects other schemes or non-URLs', () => {
    expect(
      ConfigSchema.parse({ server: { externalUrl: 'https://kb.example.com' } }).server.externalUrl,
    ).toBe('https://kb.example.com');
    expect(
      ConfigSchema.parse({ server: { externalUrl: 'http://localhost:8080' } }).server.externalUrl,
    ).toBe('http://localhost:8080');
    expect(ConfigSchema.safeParse({ server: { externalUrl: 'not a url' } }).success).toBe(false);
    expect(
      ConfigSchema.safeParse({ server: { externalUrl: 'ftp://kb.example.com' } }).success,
    ).toBe(false);
  });

  test("idleShutdown accepts 'off' and s/m/h durations, rejects bare numbers and other units", () => {
    for (const good of ['off', '90s', '30m', '2h']) {
      expect(ConfigSchema.parse({ server: { idleShutdown: good } }).server.idleShutdown).toBe(good);
    }
    for (const bad of ['30', '0m', '1d', 'never', '']) {
      expect(ConfigSchema.safeParse({ server: { idleShutdown: bad } }).success).toBe(false);
    }
  });
});

describe('search.semantic embedding transport tuning', () => {
  test('accepts positive integer overrides and keeps the legacy defaults when absent', () => {
    const configured = ConfigSchema.parse({
      search: {
        semantic: {
          maxBatchSize: 2,
          maxBatchChars: 16_000,
          docTimeoutMs: 120_000,
        },
      },
    }).search.semantic;
    expect(configured.maxBatchSize).toBe(2);
    expect(configured.maxBatchChars).toBe(16_000);
    expect(configured.docTimeoutMs).toBe(120_000);

    const defaults = ConfigSchema.parse({}).search.semantic;
    expect(defaults.maxBatchSize).toBe(96);
    expect(defaults.maxBatchChars).toBe(96_000);
    expect(defaults.docTimeoutMs).toBe(30_000);
  });

  test.each([
    ['maxBatchSize', 2_048, 96],
    ['maxBatchChars', 16_384_000, 96_000],
    ['docTimeoutMs', 600_000, 30_000],
  ] as const)(
    '%s preserves range endpoints and defaults invalid values',
    (field, max, fallback) => {
      for (const valid of [1, max]) {
        expect(
          ConfigSchema.parse({ search: { semantic: { [field]: valid } } }).search.semantic[field],
        ).toBe(valid);
      }
      for (const invalid of [
        0,
        -1,
        1.5,
        '2',
        null,
        max + 1,
        2_147_483_648,
        Number.NaN,
        Number.POSITIVE_INFINITY,
      ]) {
        const parsed = ConfigSchema.safeParse({ search: { semantic: { [field]: invalid } } });
        expect(parsed.success).toBe(true);
        if (parsed.success) {
          expect(parsed.data.search.semantic[field]).toBe(fallback);
        }
      }
    },
  );

  test.each(['maxBatchSize', 'maxBatchChars', 'docTimeoutMs'] as const)(
    '%s is project-local, non-agent-settable, and live-reloaded',
    (field) => {
      expect(getLeafFieldMeta(ConfigSchema, ['search', 'semantic', field])).toMatchObject({
        scope: 'project-local',
        defaultScope: 'project-local',
        agentSettable: false,
        reload: 'live',
      });
    },
  );
});

describe('git.hosts.<host>.provider (declared GitHub Enterprise Server hosts)', () => {
  test('defaults to an empty host map', () => {
    expect(ConfigSchema.parse({}).git.hosts).toEqual({});
  });

  test('round-trips a declared host', () => {
    const parsed = ConfigSchema.parse({
      git: { hosts: { 'ghes.example.com': { provider: 'github' } } },
    });
    expect(parsed.git.hosts['ghes.example.com']?.provider).toBe('github');
  });

  test('accepts a host entry with no provider', () => {
    const parsed = ConfigSchema.parse({ git: { hosts: { 'ghes.example.com': {} } } });
    expect(parsed.git.hosts['ghes.example.com']?.provider).toBeUndefined();
  });

  test('an unrecognized provider leaves that host undeclared without failing the parse', () => {
    const parsed = ConfigSchema.parse({
      git: { hosts: { h: { provider: 'gitlab' } } },
      content: { dir: 'docs' },
    });
    expect(parsed.git.hosts.h?.provider).toBeUndefined();
    expect(parsed.content.dir).toBe('docs');
  });

  test('a hosts value that is not a map empties the section without failing the parse', () => {
    const parsed = ConfigSchema.parse({ git: { hosts: 'nope' }, content: { dir: 'docs' } });
    expect(parsed.git.hosts).toEqual({});
    expect(parsed.content.dir).toBe('docs');
  });

  test('the hosts record and the provider leaf are per-machine user scope, boot-reloaded', () => {
    expect(getLeafFieldMeta(ConfigSchema, ['git', 'hosts'])).toMatchObject({
      scope: 'user',
      defaultScope: 'user',
      agentSettable: false,
      reload: 'boot',
    });
    expect(
      getLeafFieldMeta(ConfigSchema, ['git', 'hosts', 'ghes.example.com', 'provider']),
    ).toMatchObject({
      scope: 'user',
      defaultScope: 'user',
      agentSettable: false,
      reload: 'boot',
    });
  });
});

describe('telemetry.skillInstallReports.enabled', () => {
  test('defaults to off at every nesting level', () => {
    expect(ConfigSchema.parse({}).telemetry.skillInstallReports.enabled).toBe(false);
    expect(ConfigSchema.parse({ telemetry: {} }).telemetry.skillInstallReports.enabled).toBe(false);
    expect(
      ConfigSchema.parse({ telemetry: { skillInstallReports: {} } }).telemetry.skillInstallReports
        .enabled,
    ).toBe(false);
  });

  test('an explicit opt-in is kept', () => {
    expect(
      ConfigSchema.parse({ telemetry: { skillInstallReports: { enabled: true } } }).telemetry
        .skillInstallReports.enabled,
    ).toBe(true);
  });
});