CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes45downloads
activeGoalStore.test.ts80 linesDownload Raw Back to goals
1/**2 * @license3 * Copyright 2026 Qwen Team4 * SPDX-License-Identifier: Apache-2.05 */6 7import { beforeEach, describe, expect, it } from 'vitest';8import {9  __resetActiveGoalStoreForTests,10  activeGoalEquals,11  clearActiveGoal,12  getActiveGoal,13  recordGoalIteration,14  setActiveGoal,15  type ActiveGoal,16} from './activeGoalStore.js';17 18const makeGoal = (overrides: Partial<ActiveGoal> = {}): ActiveGoal => ({19  condition: 'write a hello world script',20  iterations: 0,21  setAt: 1_000,22  tokensAtStart: 100,23  hookId: 'hook-1',24  ...overrides,25});26 27describe('activeGoalStore', () => {28  beforeEach(() => __resetActiveGoalStoreForTests());29 30  it('returns undefined when no goal is set', () => {31    expect(getActiveGoal('sess-1')).toBeUndefined();32  });33 34  it('isolates goals per session', () => {35    setActiveGoal('sess-1', makeGoal({ condition: 'one' }));36    setActiveGoal('sess-2', makeGoal({ condition: 'two' }));37 38    expect(getActiveGoal('sess-1')?.condition).toBe('one');39    expect(getActiveGoal('sess-2')?.condition).toBe('two');40  });41 42  it('clearActiveGoal returns the previous goal and removes it', () => {43    setActiveGoal('sess-1', makeGoal());44    const cleared = clearActiveGoal('sess-1');45    expect(cleared?.condition).toBe('write a hello world script');46    expect(getActiveGoal('sess-1')).toBeUndefined();47  });48 49  it('clearActiveGoal returns undefined when nothing was set', () => {50    expect(clearActiveGoal('sess-missing')).toBeUndefined();51  });52 53  it('recordGoalIteration increments and stores lastReason', () => {54    setActiveGoal('sess-1', makeGoal());55    const next = recordGoalIteration('sess-1', 'still missing tests');56    expect(next?.iterations).toBe(1);57    expect(next?.lastReason).toBe('still missing tests');58    expect(getActiveGoal('sess-1')?.iterations).toBe(1);59  });60 61  it('recordGoalIteration is a no-op when no goal exists', () => {62    expect(recordGoalIteration('sess-missing', 'noop')).toBeUndefined();63  });64 65  it('compares active goal snapshots by value', () => {66    expect(activeGoalEquals(undefined, undefined)).toBe(true);67    expect(activeGoalEquals(makeGoal(), makeGoal())).toBe(true);68    expect(69      activeGoalEquals(makeGoal(), makeGoal({ lastReason: undefined })),70    ).toBe(true);71    expect(72      activeGoalEquals(73        makeGoal({ iterations: 1 }),74        makeGoal({ iterations: 2 }),75      ),76    ).toBe(false);77    expect(activeGoalEquals(makeGoal(), undefined)).toBe(false);78  });79});80 
basant307/AI_Governance_Project · CoolFace