Skip to content
5 changes: 3 additions & 2 deletions assistant/src/__tests__/actor-token-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,15 @@ mock.module("../config/env.js", () => ({
checkUnrecognizedEnvVars: () => {},
}));

import { getDb, resetDb } from "../memory/db-connection.js";
import { getDb } from "../memory/db-connection.js";
import { initializeDb } from "../memory/db-init.js";
import { resetExternalAssistantIdCache } from "../runtime/auth/external-assistant-id.js";
import { initAuthSigningKey } from "../runtime/auth/token-service.js";
import {
resolveLocalAuthContext,
resolveLocalTrustContext,
} from "../runtime/local-actor-identity.js";
import { resetDbForTesting } from "./db-test-helpers.js";

// ---------------------------------------------------------------------------
// Test signing key
Expand All @@ -50,7 +51,7 @@ initializeDb();
beforeEach(() => {
initAuthSigningKey(TEST_KEY);
resetExternalAssistantIdCache();
resetDb();
resetDbForTesting();
initializeDb();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,23 @@ const DECLARED_FLAG_ID = "email-channel";
const DECLARED_FLAG_KEY = DECLARED_FLAG_ID;
const SAFE_STORAGE_LIMITS_FLAG = "safe-storage-limits";

const { isAssistantFeatureFlagEnabled, _setOverridesForTesting } =
const { isAssistantFeatureFlagEnabled } =
await import("../config/assistant-feature-flags.js");
const { setOverridesForTesting } = await import(
"./feature-flag-test-helpers.js"
);
const { skillFlagKey } = await import("../config/skill-state.js");

// ---------------------------------------------------------------------------
// Setup / Teardown
// ---------------------------------------------------------------------------

beforeEach(() => {
_setOverridesForTesting({});
setOverridesForTesting({});
});

afterEach(() => {
_setOverridesForTesting({});
setOverridesForTesting({});
});

// ---------------------------------------------------------------------------
Expand All @@ -38,14 +41,14 @@ afterEach(() => {

describe("isAssistantFeatureFlagEnabled", () => {
test("reads from file-based overrides", () => {
_setOverridesForTesting({ [DECLARED_FLAG_KEY]: true });
setOverridesForTesting({ [DECLARED_FLAG_KEY]: true });
const config = {} as any;

expect(isAssistantFeatureFlagEnabled(DECLARED_FLAG_KEY, config)).toBe(true);
});

test("explicit false override in file-based overrides", () => {
_setOverridesForTesting({ [DECLARED_FLAG_KEY]: false });
setOverridesForTesting({ [DECLARED_FLAG_KEY]: false });
const config = {} as any;

expect(isAssistantFeatureFlagEnabled(DECLARED_FLAG_KEY, config)).toBe(
Expand All @@ -72,7 +75,7 @@ describe("isAssistantFeatureFlagEnabled", () => {
});

test("safe-storage-limits respects explicit override", () => {
_setOverridesForTesting({ [SAFE_STORAGE_LIMITS_FLAG]: true });
setOverridesForTesting({ [SAFE_STORAGE_LIMITS_FLAG]: true });
const config = {} as any;

expect(
Expand All @@ -87,7 +90,7 @@ describe("isAssistantFeatureFlagEnabled", () => {
});

test("undeclared flag respects persisted override", () => {
_setOverridesForTesting({ "some-undeclared-flag": false });
setOverridesForTesting({ "some-undeclared-flag": false });
const config = {} as any;

expect(isAssistantFeatureFlagEnabled("some-undeclared-flag", config)).toBe(
Expand All @@ -98,7 +101,7 @@ describe("isAssistantFeatureFlagEnabled", () => {

describe("isAssistantFeatureFlagEnabled with skillFlagKey", () => {
test("resolves skill flag via canonical path", () => {
_setOverridesForTesting({ [DECLARED_FLAG_KEY]: false });
setOverridesForTesting({ [DECLARED_FLAG_KEY]: false });
const config = {} as any;

expect(
Expand Down
4 changes: 2 additions & 2 deletions assistant/src/__tests__/audit-log-rotation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ mock.module("../util/logger.js", () => ({
}),
}));

import { resetDb } from "../memory/db-connection.js";
import { getSqlite } from "../memory/db-connection.js";
import { initializeDb } from "../memory/db-init.js";
import {
getRecentInvocations,
rotateToolInvocations,
} from "../memory/tool-usage-store.js";
import { resetDbForTesting } from "./db-test-helpers.js";

// ---------------------------------------------------------------------------
// Helpers
Expand Down Expand Up @@ -57,7 +57,7 @@ const ONE_DAY_MS = 24 * 60 * 60 * 1000;

describe("audit log rotation", () => {
beforeAll(() => {
resetDb();
resetDbForTesting();
initializeDb();
// Insert a conversations row so FK-enforced ORM inserts succeed
getSqlite().run(
Expand Down
12 changes: 6 additions & 6 deletions assistant/src/__tests__/auto-analysis-end-to-end.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,14 @@ mock.module("../runtime/services/analyze-conversation.js", () => ({

// ── Real imports ──────────────────────────────────────────────────

import { _setOverridesForTesting } from "../config/assistant-feature-flags.js";
import { conversationAnalyzeJob } from "../memory/conversation-analyze-job.js";
import { createConversation } from "../memory/conversation-crud.js";
import { getDb } from "../memory/db-connection.js";
import { initializeDb } from "../memory/db-init.js";
import { indexMessageNow } from "../memory/indexer.js";
import type { MemoryJob } from "../memory/jobs-store.js";
import { conversations, memoryJobs, messages } from "../memory/schema.js";
import { setOverridesForTesting } from "./feature-flag-test-helpers.js";

// ── Helpers ───────────────────────────────────────────────────────

Expand Down Expand Up @@ -279,14 +279,14 @@ beforeEach(() => {
resetTables();
analyzeCalls.length = 0;
// Clear any stale feature-flag overrides between tests.
_setOverridesForTesting({});
setOverridesForTesting({});
});

// ─────────────────────────────────────────────────────────────────

describe("auto-analysis end-to-end trigger path", () => {
test("flag on, batch threshold reached → conversation_analyze enqueued, handler runs, analysis conversation created", async () => {
_setOverridesForTesting({ "auto-analyze": true });
setOverridesForTesting({ "auto-analyze": true });

const source = createConversation("source-conv");

Expand Down Expand Up @@ -329,7 +329,7 @@ describe("auto-analysis end-to-end trigger path", () => {
});

test("flag off → no conversation_analyze job is ever enqueued", async () => {
_setOverridesForTesting({ "auto-analyze": false });
setOverridesForTesting({ "auto-analyze": false });

const source = createConversation("source-conv-flag-off");
await indexMessages(source.id, 3);
Expand All @@ -343,7 +343,7 @@ describe("auto-analysis end-to-end trigger path", () => {
});

test("recursion guard: indexing into an auto-analysis conversation does not enqueue conversation_analyze or graph_extract", async () => {
_setOverridesForTesting({ "auto-analyze": true });
setOverridesForTesting({ "auto-analyze": true });

// Set up an auto-analysis conversation directly. This is the
// scenario we need to protect against — the analysis agent writes
Expand Down Expand Up @@ -392,7 +392,7 @@ describe("auto-analysis batch trigger uses analysis.batchSize cadence", () => {
const originalV2Enabled = TEST_CONFIG.memory.v2.enabled;

beforeEach(() => {
_setOverridesForTesting({ "auto-analyze": true });
setOverridesForTesting({ "auto-analyze": true });
// memory.v2.enabled gates v1 graph_extract enqueue; force off so
// these cadence tests can observe the v1 path.
TEST_CONFIG.memory.v2.enabled = false;
Expand Down
11 changes: 3 additions & 8 deletions assistant/src/__tests__/background-workers-disk-pressure.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
import { beforeEach, describe, expect, mock, test } from "bun:test";

import { createMockLoggerModule } from "./helpers/mock-logger.js";

// Default the warm-pool gate to OPEN — these tests probe background-job
// disk-pressure behavior, not the pre-first-message guard.
mock.module("../runtime/pre-first-message-gate.js", () => ({
hasReceivedUserMessage: () => true,
_resetPreFirstMessageGateCacheForTests: () => {},
}));

mock.module("../util/logger.js", () => ({
getLogger: () => ({
info: () => {},
debug: () => {},
warn: () => {},
error: () => {},
}),
}));
mock.module("../util/logger.js", () => createMockLoggerModule());

mock.module("../config/loader.js", () => ({
getConfig: () => ({
Expand Down
6 changes: 3 additions & 3 deletions assistant/src/__tests__/browser-skill-endstate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ mock.module("../config/loader.js", () => ({

import { BROWSER_OPERATION_META } from "../browser/operations.js";
import { BROWSER_OPERATIONS } from "../browser/types.js";
import { _setOverridesForTesting } from "../config/assistant-feature-flags.js";
import {
projectSkillTools,
resetSkillToolProjection,
Expand All @@ -23,20 +22,21 @@ import {
getAllTools,
initializeTools,
} from "../tools/registry.js";
import { setOverridesForTesting } from "./feature-flag-test-helpers.js";
import {
BROWSER_SKILL_ID,
buildSkillLoadHistory,
} from "./test-support/browser-skill-harness.js";

afterAll(() => {
__resetRegistryForTesting();
_setOverridesForTesting({});
setOverridesForTesting({});
});

describe("browser CLI-only architecture end-state", () => {
beforeAll(async () => {
__resetRegistryForTesting();
_setOverridesForTesting({
setOverridesForTesting({
browser: true,
});
await initializeTools();
Expand Down
5 changes: 3 additions & 2 deletions assistant/src/__tests__/call-controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,16 +252,17 @@ import {
getPendingCanonicalRequestByCallSessionId,
} from "../memory/canonical-guardian-store.js";
import { getMessages } from "../memory/conversation-crud.js";
import { getDb, resetDb } from "../memory/db-connection.js";
import { getDb } from "../memory/db-connection.js";
import { initializeDb } from "../memory/db-init.js";
import { resetTestTables } from "../memory/raw-query.js";
import { conversations } from "../memory/schema.js";
import { resetDbForTesting } from "./db-test-helpers.js";
import { createGuardianBinding } from "./helpers/create-guardian-binding.js";

initializeDb();

afterAll(() => {
resetDb();
resetDbForTesting();
});

// ── CallTransport mock factory ───────────────────────────────────────
Expand Down
5 changes: 3 additions & 2 deletions assistant/src/__tests__/channel-approval-routes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ import {
createCanonicalGuardianRequest,
getCanonicalGuardianRequest,
} from "../memory/canonical-guardian-store.js";
import { getDb, resetDb } from "../memory/db-connection.js";
import { getDb } from "../memory/db-connection.js";
import { initializeDb } from "../memory/db-init.js";
import * as deliveryChannels from "../memory/delivery-channels.js";
import {
Expand All @@ -90,14 +90,15 @@ import * as gatewayClient from "../runtime/gateway-client.js";
import * as pendingInteractions from "../runtime/pending-interactions.js";
import { sweepExpiredGuardianApprovals } from "../runtime/routes/channel-guardian-routes.js";
import { _setTestPollMaxWait } from "../runtime/routes/channel-route-shared.js";
import { resetDbForTesting } from "./db-test-helpers.js";
import { handleChannelInbound } from "./helpers/channel-test-adapter.js";
import { createGuardianBinding } from "./helpers/create-guardian-binding.js";

initializeDb();
initAuthSigningKey(Buffer.from("test-signing-key-at-least-32-bytes-long"));

afterAll(() => {
resetDb();
resetDbForTesting();
});

// ---------------------------------------------------------------------------
Expand Down
5 changes: 3 additions & 2 deletions assistant/src/__tests__/channel-guardian.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ import {
updateSessionDelivery as storeUpdateSessionDelivery,
updateSessionStatus as _storeUpdateSessionStatus,
} from "../memory/channel-verification-sessions.js";
import { getDb, resetDb } from "../memory/db-connection.js";
import { getDb } from "../memory/db-connection.js";
import { initializeDb } from "../memory/db-init.js";
import { upsertBinding as upsertExternalBinding } from "../memory/external-conversation-store.js";
import {
Expand Down Expand Up @@ -121,12 +121,13 @@ import {
composeVerificationTelegram,
GUARDIAN_VERIFY_TEMPLATE_KEYS,
} from "../runtime/verification-templates.js";
import { resetDbForTesting } from "./db-test-helpers.js";
import { createGuardianBinding } from "./helpers/create-guardian-binding.js";

initializeDb();

afterAll(() => {
resetDb();
resetDbForTesting();
});

function resetTables(): void {
Expand Down
10 changes: 5 additions & 5 deletions assistant/src/__tests__/config-loader-backfill.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ import { migrateProviderConnectionStatusLabel } from "../memory/migrations/244-p
import { migrateProviderConnectionBaseUrlAndModels } from "../memory/migrations/250-provider-connection-base-url-and-models.js";
import * as schema from "../memory/schema.js";
import { getConnection } from "../providers/inference/connections.js";
import { _setStorePath } from "../security/encrypted-store.js";
import { setStorePathForTesting } from "./encrypted-store-test-helpers.js";

// ---------------------------------------------------------------------------
// Helpers
Expand Down Expand Up @@ -328,14 +328,14 @@ describe("loadConfig startup behavior", () => {
const updatesPath = join(WORKSPACE_DIR, "UPDATES.md");
if (existsSync(updatesPath)) rmSync(updatesPath, { force: true });
ensureTestDir();
_setStorePath(join(WORKSPACE_DIR, "keys.enc"));
setStorePathForTesting(join(WORKSPACE_DIR, "keys.enc"));
delete process.env.VELLUM_DEFAULT_WORKSPACE_CONFIG_PATH;
delete process.env.IS_PLATFORM;
invalidateConfigCache();
});

afterEach(() => {
_setStorePath(null);
setStorePathForTesting(null);
delete process.env.VELLUM_DEFAULT_WORKSPACE_CONFIG_PATH;
delete process.env.IS_PLATFORM;
invalidateConfigCache();
Expand Down Expand Up @@ -943,14 +943,14 @@ describe("seedInferenceProfiles BYOK-mode managed profile labels", () => {
}
}
ensureTestDir();
_setStorePath(join(WORKSPACE_DIR, "keys.enc"));
setStorePathForTesting(join(WORKSPACE_DIR, "keys.enc"));
delete process.env.VELLUM_DEFAULT_WORKSPACE_CONFIG_PATH;
delete process.env.IS_PLATFORM;
invalidateConfigCache();
});

afterEach(() => {
_setStorePath(null);
setStorePathForTesting(null);
delete process.env.VELLUM_DEFAULT_WORKSPACE_CONFIG_PATH;
delete process.env.IS_PLATFORM;
invalidateConfigCache();
Expand Down
10 changes: 5 additions & 5 deletions assistant/src/__tests__/config-loader-corrupt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
loadConfig,
loadRawConfig,
} from "../config/loader.js";
import { _setStorePath } from "../security/encrypted-store.js";
import { setStorePathForTesting } from "./encrypted-store-test-helpers.js";

// ---------------------------------------------------------------------------
// Helpers
Expand Down Expand Up @@ -65,12 +65,12 @@ function listQuarantinedFiles(): string[] {
describe("loadConfig corrupt-file recovery", () => {
beforeEach(() => {
resetWorkspace();
_setStorePath(join(WORKSPACE_DIR, "keys.enc"));
setStorePathForTesting(join(WORKSPACE_DIR, "keys.enc"));
invalidateConfigCache();
});

afterEach(() => {
_setStorePath(null);
setStorePathForTesting(null);
invalidateConfigCache();
});

Expand Down Expand Up @@ -187,12 +187,12 @@ describe("loadConfig corrupt-file recovery", () => {
describe("loadRawConfig corrupt-file recovery", () => {
beforeEach(() => {
resetWorkspace();
_setStorePath(join(WORKSPACE_DIR, "keys.enc"));
setStorePathForTesting(join(WORKSPACE_DIR, "keys.enc"));
invalidateConfigCache();
});

afterEach(() => {
_setStorePath(null);
setStorePathForTesting(null);
invalidateConfigCache();
});

Expand Down
Loading
Loading