fix: update code-session tests to expect reality
- auto-generate name test: mock drone to accept work order so success callback runs - session lock test: make async, mock TabLock, use vi.waitFor for async callback chain
This commit is contained in:
parent
3e1135ed2b
commit
7997b8a2a2
@ -19,6 +19,14 @@ vi.mock("../src/services/socket");
|
|||||||
vi.mock("../src/services/chat-session");
|
vi.mock("../src/services/chat-session");
|
||||||
vi.mock("../src/models/chat-turn");
|
vi.mock("../src/models/chat-turn");
|
||||||
vi.mock("../src/models/chat-session");
|
vi.mock("../src/models/chat-session");
|
||||||
|
vi.mock("../src/lib/tab-lock", () => ({
|
||||||
|
default: {
|
||||||
|
acquire: vi.fn().mockResolvedValue({ success: true }),
|
||||||
|
release: vi.fn().mockResolvedValue(undefined),
|
||||||
|
refresh: vi.fn().mockResolvedValue(true),
|
||||||
|
getInfo: vi.fn().mockResolvedValue(null),
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
describe("CodeSession", () => {
|
describe("CodeSession", () => {
|
||||||
let mockSocket: any;
|
let mockSocket: any;
|
||||||
@ -270,6 +278,14 @@ describe("CodeSession", () => {
|
|||||||
ChatSessionService.generateSessionNameFromPrompt,
|
ChatSessionService.generateSessionNameFromPrompt,
|
||||||
).mockResolvedValue(namedSession as any);
|
).mockResolvedValue(namedSession as any);
|
||||||
|
|
||||||
|
// Mock drone to accept the work order so the success callback runs
|
||||||
|
mockDroneSession.socket.emit = vi.fn((event: string, ...args: any[]) => {
|
||||||
|
const callback = args[args.length - 1];
|
||||||
|
if (typeof callback === "function") {
|
||||||
|
callback(true, "work order accepted");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
await codeSession.onSubmitPrompt("build a rest api", cb);
|
await codeSession.onSubmitPrompt("build a rest api", cb);
|
||||||
|
|
||||||
expect(
|
expect(
|
||||||
@ -334,7 +350,7 @@ describe("CodeSession", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("onRequestSessionLock", () => {
|
describe("onRequestSessionLock", () => {
|
||||||
it("should set selected drone, chat session, and project on success", () => {
|
it("should set selected drone, chat session, and project on success", async () => {
|
||||||
const mockDroneSession = {
|
const mockDroneSession = {
|
||||||
socket: {
|
socket: {
|
||||||
emit: vi.fn((event: string, ...args: any[]) => {
|
emit: vi.fn((event: string, ...args: any[]) => {
|
||||||
@ -357,7 +373,11 @@ describe("CodeSession", () => {
|
|||||||
callback,
|
callback,
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(callback).toHaveBeenCalledWith(true, mockChatSession._id);
|
// The inner callback is async (awaits TabLock.acquire), so we need to
|
||||||
|
// wait for the microtask queue to flush before asserting
|
||||||
|
await vi.waitFor(() => {
|
||||||
|
expect(callback).toHaveBeenCalledWith(true, mockChatSession._id);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should not set session data on failure", () => {
|
it("should not set session data on failure", () => {
|
||||||
|
|||||||
@ -320,6 +320,9 @@ importers:
|
|||||||
'@uiw/react-codemirror':
|
'@uiw/react-codemirror':
|
||||||
specifier: ^4.25.9
|
specifier: ^4.25.9
|
||||||
version: 4.25.9(@babel/runtime@7.29.2)(@codemirror/autocomplete@6.20.2)(@codemirror/language@6.12.3)(@codemirror/lint@6.9.6)(@codemirror/search@6.7.0)(@codemirror/state@6.6.0)(@codemirror/theme-one-dark@6.1.3)(@codemirror/view@6.42.1)(codemirror@6.0.2)(react-dom@19.2.5(react@19.2.5))(react@19.2.5)
|
version: 4.25.9(@babel/runtime@7.29.2)(@codemirror/autocomplete@6.20.2)(@codemirror/language@6.12.3)(@codemirror/lint@6.9.6)(@codemirror/search@6.7.0)(@codemirror/state@6.6.0)(@codemirror/theme-one-dark@6.1.3)(@codemirror/view@6.42.1)(codemirror@6.0.2)(react-dom@19.2.5(react@19.2.5))(react@19.2.5)
|
||||||
|
lucide-react:
|
||||||
|
specifier: ^1.16.0
|
||||||
|
version: 1.16.0(react@19.2.5)
|
||||||
marked:
|
marked:
|
||||||
specifier: ^16.4.2
|
specifier: ^16.4.2
|
||||||
version: 16.4.2
|
version: 16.4.2
|
||||||
@ -3037,6 +3040,11 @@ packages:
|
|||||||
resolution: {integrity: sha512-NxVFwLAnrd9i7KUBxC4DrUhmgjzOs+1Qm50D3oF1/oL+r1NpZ4gA7xvG0/zJ8evR7zIKn4vLf7qTNduWFtCrRw==}
|
resolution: {integrity: sha512-NxVFwLAnrd9i7KUBxC4DrUhmgjzOs+1Qm50D3oF1/oL+r1NpZ4gA7xvG0/zJ8evR7zIKn4vLf7qTNduWFtCrRw==}
|
||||||
engines: {node: 20 || >=22}
|
engines: {node: 20 || >=22}
|
||||||
|
|
||||||
|
lucide-react@1.16.0:
|
||||||
|
resolution: {integrity: sha512-dYwyPzb4MEKpGUmNYk3WKWPnMrHs3FKM+q94kAnJrcDIqqn1hq2xY8scaS2ovsOCM5D51ey2gaRG3PBb1vgoYQ==}
|
||||||
|
peerDependencies:
|
||||||
|
react: ^16.5.1 || ^17.0.0 || ^18.0.0 || ^19.0.0
|
||||||
|
|
||||||
luxon@3.7.2:
|
luxon@3.7.2:
|
||||||
resolution: {integrity: sha512-vtEhXh/gNjI9Yg1u4jX/0YVPMvxzHuGgCm6tC5kZyb08yjGWGnqAjGJvcXbqQR2P3MyMEFnRbpcdFS6PBcLqew==}
|
resolution: {integrity: sha512-vtEhXh/gNjI9Yg1u4jX/0YVPMvxzHuGgCm6tC5kZyb08yjGWGnqAjGJvcXbqQR2P3MyMEFnRbpcdFS6PBcLqew==}
|
||||||
engines: {node: '>=12'}
|
engines: {node: '>=12'}
|
||||||
@ -6828,6 +6836,10 @@ snapshots:
|
|||||||
|
|
||||||
lru-cache@11.3.5: {}
|
lru-cache@11.3.5: {}
|
||||||
|
|
||||||
|
lucide-react@1.16.0(react@19.2.5):
|
||||||
|
dependencies:
|
||||||
|
react: 19.2.5
|
||||||
|
|
||||||
luxon@3.7.2: {}
|
luxon@3.7.2: {}
|
||||||
|
|
||||||
lz-string@1.5.0: {}
|
lz-string@1.5.0: {}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user