Implement bounded Windows Event Log jobs and verify contracts on cloud Linux
Rust development slice / linux (push) Failing after 7s
Rust development slice / linux (push) Failing after 7s
This commit is contained in:
+27
-1
@@ -67,6 +67,27 @@ export function windowsScriptProfile(value: RecordValue): 'inherited' | typeof w
|
||||
|| (value.os_family !== undefined && value.os_family !== 'windows')) throw new Error('Windows-Ausführungsprofil nur powershell_51_remote_signed für Windows PowerShell5.1');
|
||||
return windowsPowerShellRemoteSignedProfile;
|
||||
}
|
||||
export const windowsEventLogFixtureSource = 'windows.eventlog.application.rustdiscovery-mvp-test';
|
||||
export const windowsEventLogFixtureChannel = 'Application';
|
||||
export const windowsEventLogFixtureProvider = 'RustDiscovery-MVP-Test';
|
||||
/** Preserve sub-millisecond bounds; Date.parse alone would admit 24h + 1ns. */
|
||||
export function logWindow(since: unknown, until: unknown): void {
|
||||
const instant = (value: unknown): bigint => {
|
||||
if (typeof value !== 'string') throw new Error('Exaktes UTC-Log-Zeitfenster erforderlich');
|
||||
const match = /^(\d{4}-\d\d-\d\dT\d\d:\d\d:\d\d)(?:\.(\d{1,9}))?(Z|[+-]\d\d:\d\d)$/.exec(value);
|
||||
if (!match) throw new Error('Exaktes UTC-Log-Zeitfenster erforderlich');
|
||||
const seconds = Date.parse(match[1]! + match[3]!);
|
||||
if (!Number.isFinite(seconds)) throw new Error('Exaktes UTC-Log-Zeitfenster erforderlich');
|
||||
return BigInt(seconds) * 1000000n + BigInt((match[2] ?? '').padEnd(9, '0'));
|
||||
};
|
||||
const start = instant(since), end = instant(until);
|
||||
if (end <= start || end - start > 86400000000000n) throw new Error('Exaktes Log-Zeitfenster höchstens24Stunden erforderlich');
|
||||
}
|
||||
export function validateWindowsLogLimits(identity: unknown, runtime: unknown, output: unknown, since: unknown): void {
|
||||
if (identity !== 'agent_service' || typeof runtime !== 'number' || !Number.isSafeInteger(runtime) || runtime < 10 || runtime > 120
|
||||
|| typeof output !== 'number' || !Number.isSafeInteger(output) || output < 1024 || output > 65536
|
||||
|| typeof since !== 'string' || Date.parse(since) < 0) throw new Error('Windows-Fixture-Eventlog nur agent_service,10–120s und1024–65536Bytes');
|
||||
}
|
||||
export interface PlanInput { tenant_id: string; action: Action; targets: { asset_ids: string[] }; parameters: RecordValue; artifact_ids?: string[]; schedule: { not_before: string; start_before: string; offline_policy: 'wait_until_deadline' }; rollout: { max_parallel: number; halt_after_failures: number }; reason: string }
|
||||
/** Decode explicit escaped CRLF before planning; never alter approved output bytes. */
|
||||
export function expectedStdout(value: string, format: string): string | null {
|
||||
@@ -103,7 +124,12 @@ export function validateInput(input: PlanInput): void {
|
||||
}
|
||||
const required = (key: string) => text(input.parameters[key], `parameters.${key}`);
|
||||
if (input.action === 'refresh_inventory') required('scope');
|
||||
if (input.action === 'query_logs') { required('unit'); const since = Date.parse(required('since')), until = Date.parse(required('until')); if (!Number.isFinite(since) || !Number.isFinite(until) || until <= since) throw new Error('Exaktes Log-Zeitfenster erforderlich'); if (typeof input.parameters.max_lines !== 'number' || !Number.isSafeInteger(input.parameters.max_lines) || input.parameters.max_lines < 1 || input.parameters.max_lines > 1000) throw new Error('Loglimit muss 1–1000 sein'); }
|
||||
if (input.action === 'query_logs') {
|
||||
const unit = required('unit'); logWindow(required('since'), required('until'));
|
||||
if (unit.startsWith('windows.eventlog.') && unit !== windowsEventLogFixtureSource) throw new Error('Nur die feste Windows-Fixture-Eventlogquelle ist konfiguriert');
|
||||
if (unit === windowsEventLogFixtureSource) validateWindowsLogLimits(input.parameters.execution_identity, input.parameters.timeout_seconds, input.parameters.max_output_bytes, input.parameters.since);
|
||||
if (typeof input.parameters.max_lines !== 'number' || !Number.isSafeInteger(input.parameters.max_lines) || input.parameters.max_lines < 1 || input.parameters.max_lines > 1000) throw new Error('Loglimit muss 1–1000 sein');
|
||||
}
|
||||
if (input.action === 'set_service_state') { required('unit'); if (!['running', 'stopped', 'restarted'].includes(required('state'))) throw new Error('Ungültiger Dienstzustand'); }
|
||||
if (input.action === 'ensure_package') { for (const key of ['provider', 'recipe_version', 'package', 'version', 'architecture', 'installation_context']) required(key); }
|
||||
if (input.action === 'apply_updates') { required('provider'); if (!Array.isArray(input.parameters.packages) || !input.parameters.packages.length || !input.parameters.packages.every(v => typeof v === 'string' && v.length > 0)) throw new Error('Feste Updatepakete erforderlich'); if (input.parameters.reboot_policy !== 'never') throw new Error('Kein impliziter Reboot; eigenen festen Plan erstellen'); }
|
||||
|
||||
Reference in New Issue
Block a user