fix(tests): added resource cleanup methods and initiatorOverride support
- Added `close()` method to SessionManager and AuthStorage for proper resource cleanup and finalization of prepared statements. - Added `initiatorOverride` option support in OpenAI and Anthropic providers for message attribution control. - Fixed resource leaks in RpcClient timeout handling by centralizing timeout creation with unref() and adding explicit clearTimeout() calls. - Fixed AgentSession disposal to call SessionManager's `close()` method for guaranteed resource cleanup instead of fallback flush. - Updated all test suites to properly dispose AuthStorage instances in cleanup hooks to prevent resource leaks between tests.
This commit is contained in:
@@ -13,6 +13,7 @@ describe("AgentSession role model thinking behavior", () => {
|
||||
let tempDir: TempDir;
|
||||
let session: AgentSession;
|
||||
let sessionSettings: Settings;
|
||||
const authStorages: AuthStorage[] = [];
|
||||
|
||||
beforeEach(() => {
|
||||
tempDir = TempDir.createSync("@pi-role-thinking-");
|
||||
@@ -22,6 +23,9 @@ describe("AgentSession role model thinking behavior", () => {
|
||||
if (session) {
|
||||
await session.dispose();
|
||||
}
|
||||
for (const authStorage of authStorages.splice(0)) {
|
||||
authStorage.close();
|
||||
}
|
||||
tempDir.removeSync();
|
||||
});
|
||||
|
||||
@@ -47,6 +51,7 @@ describe("AgentSession role model thinking behavior", () => {
|
||||
},
|
||||
});
|
||||
const authStorage = await AuthStorage.create(path.join(tempDir.path(), "testauth.db"));
|
||||
authStorages.push(authStorage);
|
||||
authStorage.setRuntimeApiKey("anthropic", "test-key");
|
||||
const modelRegistry = new ModelRegistry(authStorage, path.join(tempDir.path(), "models.yml"));
|
||||
|
||||
@@ -181,6 +186,7 @@ describe("AgentSession role model thinking behavior", () => {
|
||||
},
|
||||
});
|
||||
const authStorage = await AuthStorage.create(path.join(tempDir.path(), "testauth-non-xhigh.db"));
|
||||
authStorages.push(authStorage);
|
||||
authStorage.setRuntimeApiKey("anthropic", "test-key");
|
||||
const modelRegistry = new ModelRegistry(authStorage, path.join(tempDir.path(), "models-non-xhigh.yml"));
|
||||
|
||||
@@ -210,6 +216,7 @@ describe("AgentSession role model thinking behavior", () => {
|
||||
},
|
||||
});
|
||||
const authStorage = await AuthStorage.create(path.join(tempDir.path(), "testauth-cycle-thinking.db"));
|
||||
authStorages.push(authStorage);
|
||||
authStorage.setRuntimeApiKey("anthropic", "test-key");
|
||||
const modelRegistry = new ModelRegistry(authStorage, path.join(tempDir.path(), "models-cycle-thinking.yml"));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user