Initial public release of Apophis — invariant-driven automated API testing
This commit is contained in:
@@ -30,7 +30,6 @@ export interface Config {
|
||||
environments?: Record<string, EnvironmentPolicy>;
|
||||
profiles?: Record<string, ProfileDefinition>;
|
||||
presets?: Record<string, PresetDefinition>;
|
||||
generationProfiles?: Record<string, 'quick' | 'standard' | 'thorough' | { base: 'quick' | 'standard' | 'thorough' }>;
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
@@ -107,11 +106,6 @@ const CONFIG_SCHEMA: Record<string, SchemaField> = {
|
||||
optional: true,
|
||||
properties: {},
|
||||
},
|
||||
generationProfiles: {
|
||||
type: 'object',
|
||||
optional: true,
|
||||
properties: {},
|
||||
},
|
||||
packs: {
|
||||
type: 'array',
|
||||
optional: true,
|
||||
@@ -151,7 +145,6 @@ const PROFILE_SCHEMA: Record<string, SchemaField> = {
|
||||
// Schema for PresetDefinition values (inside presets.<name>)
|
||||
const PRESET_SCHEMA: Record<string, SchemaField> = {
|
||||
name: { type: 'string', optional: false },
|
||||
depth: { type: 'string', optional: true, enumValues: ['quick', 'standard', 'deep'] },
|
||||
timeout: { type: 'number', optional: true, min: 0 },
|
||||
parallel: { type: 'boolean', optional: true },
|
||||
chaos: { type: 'boolean', optional: true },
|
||||
@@ -160,12 +153,9 @@ const PRESET_SCHEMA: Record<string, SchemaField> = {
|
||||
sampling: { type: 'number', optional: true },
|
||||
blocking: { type: 'boolean', optional: true },
|
||||
sinks: { type: 'object', optional: true },
|
||||
runs: { type: 'number', optional: true, min: 1 },
|
||||
};
|
||||
|
||||
const GENERATION_PROFILE_ALIAS_SCHEMA: Record<string, SchemaField> = {
|
||||
base: { type: 'string', optional: false, enumValues: ['quick', 'standard', 'thorough'] },
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Config discovery
|
||||
// ---------------------------------------------------------------------------
|
||||
@@ -259,7 +249,6 @@ function getDynamicContainerSchema(path: string): Record<string, SchemaField> |
|
||||
if (path === 'profiles') return PROFILE_SCHEMA;
|
||||
if (path === 'presets') return PRESET_SCHEMA;
|
||||
if (path === 'environments') return ENVIRONMENT_POLICY_SCHEMA;
|
||||
if (path === 'generationProfiles') return GENERATION_PROFILE_ALIAS_SCHEMA;
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -267,7 +256,7 @@ function getDynamicContainerSchema(path: string): Record<string, SchemaField> |
|
||||
* Check if a path is inside a dynamic container (e.g., profiles.foo, presets.bar).
|
||||
*/
|
||||
function isInsideDynamicContainer(path: string): boolean {
|
||||
return path.startsWith('profiles.') || path.startsWith('presets.') || path.startsWith('environments.') || path.startsWith('generationProfiles.');
|
||||
return path.startsWith('profiles.') || path.startsWith('presets.') || path.startsWith('environments.');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -379,18 +368,11 @@ export function validateConfigAgainstSchema(
|
||||
|
||||
// Handle dynamic containers: profiles, presets, environments
|
||||
// The keys are user-defined names; their values have specific schemas
|
||||
const isDynamicContainer = path === 'profiles' || path === 'presets' || path === 'environments' || path === 'generationProfiles';
|
||||
const isDynamicContainer = path === 'profiles' || path === 'presets' || path === 'environments';
|
||||
if (!fieldSchema && isDynamicContainer) {
|
||||
const childSchema = getDynamicContainerSchema(path);
|
||||
const fieldValue = obj[key];
|
||||
if (path === 'generationProfiles' && typeof fieldValue === 'string') {
|
||||
validateType(
|
||||
fieldValue,
|
||||
{ type: 'string', optional: false, enumValues: ['quick', 'standard', 'thorough'] },
|
||||
currentPath,
|
||||
key,
|
||||
);
|
||||
} else if (childSchema && fieldValue !== null && typeof fieldValue === 'object') {
|
||||
if (childSchema && fieldValue !== null && typeof fieldValue === 'object') {
|
||||
// Validate the dynamic container value against its specific schema
|
||||
validateConfigAgainstSchema(fieldValue, childSchema, currentPath);
|
||||
} else if (childSchema) {
|
||||
@@ -633,19 +615,6 @@ export function validateConfigSemantics(config: Config): void {
|
||||
);
|
||||
}
|
||||
}
|
||||
if (preset.depth !== undefined) {
|
||||
const validDepths = ['quick', 'standard', 'deep'];
|
||||
const depthValue = preset.depth;
|
||||
if (typeof depthValue === 'string' && !validDepths.includes(depthValue as string)) {
|
||||
throw new ConfigValidationError(
|
||||
`Preset "${presetName}" has invalid depth: "${depthValue}"`,
|
||||
`presets.${presetName}.depth`,
|
||||
'depth',
|
||||
depthValue,
|
||||
`Must be one of: ${validDepths.join(', ')}.`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -101,10 +101,6 @@ export function createContext(options: Record<string, unknown> = {}): CliContext
|
||||
? options.color
|
||||
: 'auto';
|
||||
|
||||
const generationProfile = typeof options.generationProfile === 'string'
|
||||
? options.generationProfile
|
||||
: undefined;
|
||||
|
||||
return {
|
||||
cwd,
|
||||
env: {
|
||||
@@ -119,7 +115,6 @@ export function createContext(options: Record<string, unknown> = {}): CliContext
|
||||
options: {
|
||||
config: typeof options.config === 'string' ? options.config : undefined,
|
||||
profile: typeof options.profile === 'string' ? options.profile : undefined,
|
||||
generationProfile,
|
||||
format,
|
||||
color,
|
||||
quiet: options.quiet === true,
|
||||
|
||||
@@ -1,51 +0,0 @@
|
||||
import type { Config } from './config-loader.js'
|
||||
|
||||
export type ResolvedGenerationProfile = 'quick' | 'standard' | 'thorough'
|
||||
|
||||
export class GenerationProfileResolutionError extends Error {
|
||||
constructor(message: string) {
|
||||
super(message)
|
||||
this.name = 'GenerationProfileResolutionError'
|
||||
}
|
||||
}
|
||||
|
||||
function isBuiltInProfile(value: string): value is ResolvedGenerationProfile {
|
||||
return value === 'quick' || value === 'standard' || value === 'thorough'
|
||||
}
|
||||
|
||||
export function resolveGenerationProfileOverride(
|
||||
rawProfile: string | undefined,
|
||||
config: Config,
|
||||
): ResolvedGenerationProfile | undefined {
|
||||
if (!rawProfile) {
|
||||
return undefined
|
||||
}
|
||||
|
||||
if (isBuiltInProfile(rawProfile)) {
|
||||
return rawProfile
|
||||
}
|
||||
|
||||
const aliases = config.generationProfiles
|
||||
if (!aliases) {
|
||||
throw new GenerationProfileResolutionError(
|
||||
`Unknown generation profile "${rawProfile}". Use one of: quick, standard, thorough, or define an alias in config.generationProfiles.`,
|
||||
)
|
||||
}
|
||||
|
||||
const alias = aliases[rawProfile]
|
||||
if (!alias) {
|
||||
const available = Object.keys(aliases).join(', ') || 'none'
|
||||
throw new GenerationProfileResolutionError(
|
||||
`Unknown generation profile "${rawProfile}". Built-ins: quick, standard, thorough. Config aliases: ${available}.`,
|
||||
)
|
||||
}
|
||||
|
||||
const target = typeof alias === 'string' ? alias : alias.base
|
||||
if (!isBuiltInProfile(target)) {
|
||||
throw new GenerationProfileResolutionError(
|
||||
`Invalid generation profile alias "${rawProfile}". Alias must resolve to quick, standard, or thorough.`,
|
||||
)
|
||||
}
|
||||
|
||||
return target
|
||||
}
|
||||
@@ -22,7 +22,6 @@ const HELP_HEADER = `
|
||||
${pc.dim('Global Options:')}
|
||||
--config <path> Config file path
|
||||
--profile <name> Profile name from config
|
||||
--generation-profile <name> Generation budget profile (built-in or config alias)
|
||||
--cwd <path> Working directory override
|
||||
--format <mode> Output format: human | json | ndjson (default: human)
|
||||
--color <mode> Color mode: auto | always | never (default: auto)
|
||||
@@ -71,7 +70,6 @@ function getCommandHelp(command: string): string {
|
||||
|
||||
${pc.dim('Options:')}
|
||||
--profile <name> Profile name from config
|
||||
--generation-profile <name> Generation budget profile (built-in or config alias)
|
||||
--routes <filter> Route filter pattern
|
||||
--seed <number> Deterministic seed
|
||||
--changed Filter to git-modified routes
|
||||
@@ -103,7 +101,6 @@ function getCommandHelp(command: string): string {
|
||||
|
||||
${pc.dim('Options:')}
|
||||
--profile <name> Profile name from config
|
||||
--generation-profile <name> Generation budget profile (built-in or config alias)
|
||||
--seed <number> Deterministic seed
|
||||
|
||||
${pc.dim('Examples:')}
|
||||
@@ -225,7 +222,6 @@ export async function main(argv: string[] = process.argv.slice(2)): Promise<numb
|
||||
// Global flags
|
||||
cli.option('--config <path>', 'Config file path');
|
||||
cli.option('--profile <name>', 'Profile name from config');
|
||||
cli.option('--generation-profile <name>', 'Generation budget profile (built-in or config alias)');
|
||||
cli.option('--cwd <path>', 'Working directory override');
|
||||
cli.option('--format <mode>', 'Output format: human | json | ndjson', { default: 'human' });
|
||||
cli.option('--color <mode>', 'Color mode: auto | always | never', { default: 'auto' });
|
||||
@@ -270,7 +266,6 @@ export async function main(argv: string[] = process.argv.slice(2)): Promise<numb
|
||||
break;
|
||||
case 'verify':
|
||||
cmd.option('--profile <name>', 'Profile name from config');
|
||||
cmd.option('--generation-profile <name>', 'Generation budget profile (built-in or config alias)');
|
||||
cmd.option('--routes <filter>', 'Route filter pattern');
|
||||
cmd.option('--seed <number>', 'Deterministic seed');
|
||||
cmd.option('--changed', 'Filter to git-modified routes');
|
||||
@@ -281,7 +276,6 @@ export async function main(argv: string[] = process.argv.slice(2)): Promise<numb
|
||||
break;
|
||||
case 'qualify':
|
||||
cmd.option('--profile <name>', 'Profile name from config');
|
||||
cmd.option('--generation-profile <name>', 'Generation budget profile (built-in or config alias)');
|
||||
cmd.option('--seed <number>', 'Deterministic seed');
|
||||
break;
|
||||
case 'replay':
|
||||
@@ -373,16 +367,15 @@ export async function main(argv: string[] = process.argv.slice(2)): Promise<numb
|
||||
// Handle unknown flags
|
||||
const knownGlobalFlags = new Set([
|
||||
'--config', '--profile', '--cwd', '--format', '--color',
|
||||
'--generation-profile',
|
||||
'--quiet', '--verbose', '--artifact-dir', '--workspace',
|
||||
'-v', '--version', '-h', '--help',
|
||||
]);
|
||||
|
||||
const commandSpecificFlags: Record<string, Set<string>> = {
|
||||
init: new Set(['--preset', '--force', '--noninteractive']),
|
||||
verify: new Set(['--profile', '--generation-profile', '--routes', '--seed', '--changed', '--workspace']),
|
||||
verify: new Set(['--profile', '--routes', '--seed', '--changed', '--workspace']),
|
||||
observe: new Set(['--profile', '--check-config', '--workspace']),
|
||||
qualify: new Set(['--profile', '--generation-profile', '--seed', '--workspace']),
|
||||
qualify: new Set(['--profile', '--seed', '--workspace']),
|
||||
replay: new Set(['--artifact']),
|
||||
doctor: new Set(['--mode', '--strict', '--workspace']),
|
||||
migrate: new Set(['--check', '--dry-run', '--write']),
|
||||
|
||||
@@ -29,7 +29,6 @@ export interface CliContext {
|
||||
options: {
|
||||
config: string | undefined;
|
||||
profile: string | undefined;
|
||||
generationProfile?: string;
|
||||
format: OutputFormat;
|
||||
color: ColorMode;
|
||||
quiet: boolean;
|
||||
@@ -132,7 +131,6 @@ export interface ProfileDefinition {
|
||||
* required: ["name"],
|
||||
* properties: {
|
||||
* name: { type: "string" },
|
||||
* depth: { type: "string", enum: ["quick", "standard", "deep"] },
|
||||
* timeout: { type: "number" },
|
||||
* parallel: { type: "boolean" },
|
||||
* chaos: { type: "boolean" },
|
||||
@@ -143,7 +141,6 @@ export interface ProfileDefinition {
|
||||
*/
|
||||
export interface PresetDefinition {
|
||||
name: string;
|
||||
depth?: "quick" | "standard" | "deep";
|
||||
timeout?: number;
|
||||
parallel?: boolean;
|
||||
chaos?: boolean;
|
||||
|
||||
Reference in New Issue
Block a user