Download src/omega/execution-policy.test.ts from Darochin/openskynet: direct link, hf CLI and curl.
- Browser
- Download file 5.93 kB
-
https://huggingface.co/Darochin/openskynet/resolve/main/src/omega/execution-policy.test.ts
- Command line
-
hf download hf://Darochin/openskynet/src/omega/execution-policy.test.ts
-
curl -L -o execution-policy.test.ts https://huggingface.co/Darochin/openskynet/resolve/main/src/omega/execution-policy.test.ts
5.93 kB
| import { describe, expect, it } from "vitest"; | |
| import { | |
| buildOmegaRecoveryStrategyKey, | |
| chooseOmegaRecoveryRoute, | |
| decideOmegaWorkPolicyRoute, | |
| deriveOmegaEmpiricalRoutingPreference, | |
| deriveOmegaExecutiveRoutingDirective, | |
| } from "./execution-policy.js"; | |
| import type { OmegaSessionAuthority } from "./session-context.js"; | |
| const sessionAuthority = { | |
| timeline: [], | |
| transactions: [], | |
| } satisfies OmegaSessionAuthority; | |
| describe("omega execution policy", () => { | |
| it("prefers strong generalized empirical routing for validated single-target work", () => { | |
| const preference = deriveOmegaEmpiricalRoutingPreference({ | |
| requiresValidation: true, | |
| expectedPathCount: 1, | |
| watchedPathCount: 1, | |
| snapshot: { | |
| sessionKey: "main", | |
| sessionAuthority, | |
| problemAgenda: [], | |
| timelineLength: 0, | |
| relevantMemories: [], | |
| operationalSignals: [], | |
| generalizedRecoveryPreference: { | |
| preferredRoute: "sessions_spawn", | |
| confidence: 0.8, | |
| delegateSuccesses: 1, | |
| isolatedSuccesses: 4, | |
| mechanismKey: "target_not_touched|single_target", | |
| }, | |
| degradedComponents: [], | |
| }, | |
| }); | |
| expect(preference).toMatchObject({ | |
| route: "sessions_spawn", | |
| source: "generalized", | |
| }); | |
| }); | |
| it("prefers locality-derived isolation bias for validated single-target work", () => { | |
| const preference = deriveOmegaEmpiricalRoutingPreference({ | |
| requiresValidation: true, | |
| expectedPathCount: 1, | |
| watchedPathCount: 1, | |
| snapshot: { | |
| sessionKey: "main", | |
| sessionAuthority, | |
| problemAgenda: [], | |
| timelineLength: 0, | |
| relevantMemories: [], | |
| operationalSignals: [], | |
| localityRoutingPreference: { | |
| preferredRoute: "sessions_spawn", | |
| confidence: 0.85, | |
| lowLocalityFailures: 3, | |
| highLocalitySuccesses: 0, | |
| }, | |
| degradedComponents: [], | |
| }, | |
| }); | |
| expect(preference).toMatchObject({ | |
| route: "sessions_spawn", | |
| source: "locality", | |
| }); | |
| }); | |
| it("lets a locality guard preempt local execution when protected paths are at risk", () => { | |
| const preference = deriveOmegaEmpiricalRoutingPreference({ | |
| requiresValidation: true, | |
| expectedPathCount: 1, | |
| watchedPathCount: 2, | |
| snapshot: { | |
| sessionKey: "main", | |
| sessionAuthority, | |
| problemAgenda: [], | |
| timelineLength: 0, | |
| relevantMemories: [], | |
| operationalSignals: [], | |
| localityExecutionGuard: { | |
| shouldIsolate: true, | |
| confidence: 0.9, | |
| evidenceCount: 3, | |
| atRiskPaths: ["src/unrelated.ts"], | |
| reasons: ["unexpected_collateral_writes"], | |
| }, | |
| degradedComponents: [], | |
| }, | |
| }); | |
| expect(preference).toMatchObject({ | |
| route: "sessions_spawn", | |
| source: "locality_guard", | |
| }); | |
| }); | |
| it("lets the executive override validated routing when recovery is selected", () => { | |
| const directive = deriveOmegaExecutiveRoutingDirective({ | |
| requiresValidation: true, | |
| expectedPathCount: 1, | |
| matchedRecoverySuggestedRoute: "omega_delegate", | |
| preferredValidatedRoute: { | |
| route: "sessions_spawn", | |
| confidence: 0.9, | |
| source: "generalized", | |
| }, | |
| dispatchPlan: { | |
| shouldDispatchLlmTurn: true, | |
| selectedAction: "recover", | |
| queueKind: "anomaly", | |
| expectedUtility: 0.8, | |
| utilityBreakdown: { | |
| uncertaintyReduction: 0.4, | |
| } as any, | |
| budgetUsage: { | |
| observedTurns: 1, | |
| observedWallTimeMs: 500, | |
| budgetPressure: 0.1, | |
| estimatedLlmCalls: 1, | |
| turnPressure: 0.1, | |
| } as any, | |
| estimatedDispatchCostMs: 500, | |
| queueDepths: { goals: 1, anomalies: 1, maintenance: 0 }, | |
| scheduledItems: [], | |
| nextWakeDelayMs: 1_000, | |
| rationale: ["recover"], | |
| }, | |
| }); | |
| expect(directive).toMatchObject({ | |
| route: "sessions_spawn", | |
| reason: "executive_recover_isolated_bias", | |
| selectedAction: "recover", | |
| queueKind: "anomaly", | |
| }); | |
| }); | |
| it("chooses local validated routing by default before escalation", () => { | |
| expect( | |
| decideOmegaWorkPolicyRoute({ | |
| isolated: false, | |
| requiresValidation: true, | |
| expectedPathCount: 1, | |
| }), | |
| ).toBe("omega_delegate"); | |
| }); | |
| it("uses isolated recovery after recent stalls when the shape was already isolation-biased", () => { | |
| const decision = chooseOmegaRecoveryRoute({ | |
| recovery: { | |
| goalId: "goal-1", | |
| goalTask: "patch module", | |
| remainingTargets: ["src/a.ts"], | |
| collateralPaths: [], | |
| expectsJson: false, | |
| requiredKeys: [], | |
| failureStreak: 1, | |
| reason: "verified_write_failure_after_restart", | |
| suggestedRoute: "omega_delegate", | |
| resumeTask: "resume", | |
| lastErrorKind: "target_not_touched", | |
| }, | |
| recentStalledTurns: 1, | |
| delegateStats: { attempts: 1, successes: 0, failures: 1 }, | |
| isolatedStats: { attempts: 2, successes: 2, failures: 0 }, | |
| }); | |
| expect(decision).toEqual({ | |
| route: "sessions_spawn", | |
| reason: "empirical_isolation_bias", | |
| }); | |
| }); | |
| it("builds stable strategy keys for shared policy consumers", () => { | |
| expect( | |
| buildOmegaRecoveryStrategyKey({ | |
| recovery: { | |
| goalId: "goal-1", | |
| goalTask: "patch module", | |
| remainingTargets: ["src/a.ts"], | |
| expectsJson: false, | |
| requiredKeys: [], | |
| failureStreak: 1, | |
| reason: "verified_write_failure_after_restart", | |
| suggestedRoute: "sessions_spawn", | |
| resumeTask: "resume", | |
| lastErrorKind: "unexpected_collateral_writes", | |
| }, | |
| route: "sessions_spawn", | |
| }), | |
| ).toBe("unexpected_collateral_writes|single_target|contained|sessions_spawn"); | |
| }); | |
| }); | |