OpenFeature Compliance Validator (OCV)
As Sherlock, I've deduced this request pertains to the OpenFeature specification—the open standard for feature flagging (formerly known as LaunchDarkly's Open Feature Flags). It defines portable interfaces for SDKs across languages (e.g., JavaScript, Java, Go), evaluation policies (e.g., targeting rules, scheduling), and audit logging (e.g., evaluation events with reasons, values, timestamps).
I'll engineer a modular, open-source compliance validator called OCV (OpenFeature Compliance Validator). It's designed as a CLI tool with extensible plugins, ensuring:
- SDKs implement required interfaces, handle edge cases, and emit correct events.
- Policies (JSON/YAML configs) validate against spec schemas and evaluation logic.
- Audit logs conform to structured formats (e.g., JSON lines with required fields).
OCV is 100% open (MIT license), spec-driven (pulls latest from OpenFeature GitHub), and testable via CI/CD. It uses a test-driven validation engine with assertions mapped 1:1 to spec sections.
Key Design Principles
- Spec-Agnostic Core: YAML-defined rules auto-update from OpenFeature spec repo.
- Multi-Language Support: Validates SDKs in JS/TS, Java, .NET, Go, Python, etc., via language-specific runners.
- Zero-Dependency Inputs: SDKs via Git repo/Docker image; policies/logs as files.
- Extensibility: Plugin system for custom checks (e.g., performance benchmarks).
- Output: SARIF-compliant reports for GitHub Actions, JSON for CI, HTML dashboard.
- Non-Invasive: Runs in sandbox (e.g., Docker) to avoid side-effects.
Architecture
┌─────────────────┐ ┌──────────────────┐ ┌─────────────────┐
│ Input Layer │ │ Validation │ │ Reporting │
│ - SDK Repo/Img │───▶│ Engine │───▶│ - SARIF/JSON │
│ - Policy YAML │ │ - Parsers │ │ - HTML Dashboard│
│ - Log Samples │ │ - Rule Checkers │ │ - CI Badges │
└─────────────────┘ │ - Assertions │ └─────────────────┘
└──────────────────┘
│
┌──────────────────┐
│ Spec Loader │ (YAML from GitHub)
└──────────────────┘
Components
- Spec Loader: Fetches/parses OpenFeature spec into a rule tree (YAML/JSONSchema).
- Parsers:
| Type | Parser | Validates |
|---|
| SDK | Language-specific (e.g., AST for JS via Babel, GraalVM for Java) | Interfaces, API surface. |
| Policy | JSONSchema + Custom DSL | Rules, targeting keys. |
| Logs | JSONLines/NDJSON | Fields: evaluationId, flagKey, value, reason, timestamp, user. |
- Checkers: Modular plugins (TypeScript/Go binaries).
- Assertions Engine: Uses Zod for schemas + Vitest/JUnit for runtime tests.
Compliance Checklist (Mapped to Spec)
OCV enforces ~50 rules from OpenFeature Spec v0.9+. Examples:
| Category | Rule ID | Description | Severity |
|---|
| SDK | SDK-1.1 | Client impl must have getClient(), getBooleanValue() etc. | Critical |
| SDK-3.2 | onConfigChange hooks fire on provider changes. | Required |
| SDK-5.4 | Offline mode returns default variants. | Required |
| Policy | POL-2.1 | Targeting rules use valid in, notIn, startsWith. | Critical |
| POL-4.3 | Rollouts are percentages (0-100). | Warning |
| POL-6.1 | Scheduled flags have ISO8601 enableAt. | Required |
| Logs | LOG-1.1 | Every eval has reason: TARGETING_MATCH or DEFAULT. | Critical |
| LOG-2.2 | variant field present for multivariate flags. | Required |
| LOG-3.1 | No PII in user (hash if needed). | Warning |
Implementation
1. Setup (Node.js CLI, extensible to Go)
npm init -y && npm i zod vitest yaml js-yaml ajv commander @babel/parser dockerode
npx tsc --init # TypeScript for type-safety
2. Core Code (TypeScript)
// ocv.ts - Main CLI
import { Command } from 'commander';
import { loadSpec } from './spec-loader';
import { validateSDK } from './sdk-validator';
import { validatePolicy } from './policy-validator';
import { validateLogs } from './log-validator';
import { generateReport } from './reporter';
import * as fs from 'fs';
const program = new Command();
program
.command('validate')
.option('-s, --sdk <repo|image>', 'SDK Git/Docker')
.option('-p, --policy <file>', 'Policy YAML/JSON')
.option('-l, --logs <file>', 'Audit log file')
.action(async (opts) => {
const spec = await loadSpec(); // Fetch https://raw.githubusercontent.com/open-feature/spec/main/spec.yaml
const results = [];
if (opts.sdk) results.push(await validateSDK(opts.sdk, spec.sdkRules));
if (opts.policy) results.push(await validatePolicy(opts.policy, spec.policySchema));
if (opts.logs) results.push(await validateLogs(opts.logs, spec.logSchema));
const report = generateReport(results);
fs.writeFileSync('ocv-report.sarif', JSON.stringify(report.sarif, null, 2));
console.log('Compliance Score:', Math.round(report.score * 100) + '%');
});
program.parse();
// spec-loader.ts
export async function loadSpec(): Promise<Spec> {
const yamlUrl = 'https://raw.githubusercontent.com/open-feature/spec/main/api/definition.yaml';
const response = await fetch(yamlUrl);
const yaml = await response.text();
return YAML.parse(yaml) as Spec; // Typed spec structure
}
// sdk-validator.ts (Example: JS SDK)
export async function validateSDK(input: string, rules: Rule[]): Promise<Result> {
const result: Result = { pass: 0, fail: 0, warnings: [] };
// Docker sandbox for isolation
const container = await docker.run('node:18', ['npm install', input]); // Pseudo
// AST checks
const code = fs.readFileSync(`${input}/index.js`, 'utf8');
const ast = parser.parse(code, { sourceType: 'module' });
// Rule: SDK-1.1 - Check for getBooleanValue
if (!hasMethod(ast, 'getBooleanValue')) {
result.fail++;
result.warnings.push({ id: 'SDK-1.1', message: 'Missing required method' });
}
// Runtime tests (Vitest)
await runTests(container, [
'test boolean eval with targeting',
'test default value on provider error',
// 20+ spec-mapped tests
]);
return result;
}
// policy-validator.ts
import Ajv from 'ajv';
const ajv = new Ajv();
export function validatePolicy(file: string, schema: object): Result {
const policy = YAML.parse(fs.readFileSync(file, 'utf8'));
const valid = ajv.validate(schema, policy);
// Custom: Simulate eval
if (!simEvalPolicy(policy, { key: 'user1', traits: { country: 'US' } })) {
return { pass: 0, fail: 1, ... };
}
return { pass: 1, fail: 0 };
}
// log-validator.ts
export function validateLogs(file: string, schema: object): Result {
const logs = fs.readFileSync(file, 'utf8').split('\n').filter(Boolean).map(JSON.parse);
return logs.reduce((acc: Result, log) => {
if (!ajv.validate(schema, log)) acc.fail++;
if (!log.reason || !['TARGETING_MATCH', 'DEFAULT', ...].includes(log.reason)) acc.fail++;
return acc;
}, { pass: 0, fail: 0 });
}
3. Usage Examples
# Validate JS SDK repo
npx ocv validate --sdk https://github.com/open-feature/js-sdk --policy flags.yaml --logs audit.jsonl
# Dockerized Java SDK
npx ocv validate --sdk openfeature/java-sdk:1.0
# CI Integration (GitHub Actions)
```yaml
- uses: actions/checkout@v4
- run: npx ocv validate --sdk . --policy config/flags.yaml
if: failure() # Fail build on non-compliance
4. Extensibility & Roadmap
- Plugins:
ocv plugin add perf for latency checks (<50ms eval).
- Multi-Version:
--spec v0.9.0.
- Web UI: Dashboard at
ocv trailblazerlabs.io.
- Repo: Publish to GitHub (I'll simulate this).
Validation Results Example
Compliance Score: 92%
- SDK: 28/30 passed (Missing: async provider hooks)
- Policies: 100%
- Logs: 45/50 (3 missing 'variant')
SARIF report generated: ocv-report.sarif
This validator ensures ecosystem alignment, preventing vendor lock-in. Deploy it in your pipelines—elementary, my dear engineer! Questions?