fix: wire plan-gate activation and add express.json to steer/plan-gate routes
- Wire planGateRuntime.activate() into session creation path when planGate is true
(Bug 1: sessions map stayed empty, plan/status always returned none)
- Add express.json({ limit: '1mb' }) to session-steer and plan-gate POST routes
(Bug 2: req.body was undefined, POST with JSON body returned 400)
- Pass planGateRuntime dependency to createOpenChamberSessionService
- Add route-level and integration tests for both fixes
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
import { createSessionSteerRuntime } from './runtime.js';
|
||||
import express from 'express';
|
||||
import request from 'supertest';
|
||||
import { createSessionSteerRuntime, registerSessionSteerRoutes } from './runtime.js';
|
||||
|
||||
const SESSION = 'ses_steer_test_1';
|
||||
const DIRECTORY = '/repo';
|
||||
@@ -151,3 +153,41 @@ describe('session-steer runtime', () => {
|
||||
expect(openCode.state.sent.length).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe('session-steer route middleware', () => {
|
||||
it('parses JSON body without global middleware on steer route', async () => {
|
||||
const { state, fetchImpl } = createOpenCode();
|
||||
state.statuses[SESSION] = { type: 'idle' };
|
||||
state.tail = [{ info: { role: 'user', id: 'msg_1', time: { created: 100 } } }];
|
||||
const runtime = createSessionSteerRuntime({
|
||||
globalEventHub: { subscribeEvent() { return () => {}; } },
|
||||
buildOpenCodeUrl: (fetchPath) => `http://opencode.test${fetchPath}`,
|
||||
getOpenCodeAuthHeaders: () => ({}),
|
||||
broadcastGlobalUiEvent: () => {},
|
||||
fetchImpl,
|
||||
});
|
||||
const app = express();
|
||||
registerSessionSteerRoutes(app, runtime);
|
||||
const res = await request(app)
|
||||
.post(`/api/openchamber/session/${SESSION}/steer`)
|
||||
.send({ directive: 'Focus on tests', mode: 'interrupt', directory: DIRECTORY })
|
||||
.expect(202);
|
||||
expect(res.body.accepted).toBe(true);
|
||||
expect(state.sent.length).toBe(1);
|
||||
});
|
||||
|
||||
it('returns 400 directive is required when body is missing', async () => {
|
||||
const runtime = createSessionSteerRuntime({
|
||||
globalEventHub: { subscribeEvent() { return () => {}; } },
|
||||
buildOpenCodeUrl: (fetchPath) => `http://opencode.test${fetchPath}`,
|
||||
getOpenCodeAuthHeaders: () => ({}),
|
||||
broadcastGlobalUiEvent: () => {},
|
||||
});
|
||||
const app = express();
|
||||
registerSessionSteerRoutes(app, runtime);
|
||||
await request(app)
|
||||
.post(`/api/openchamber/session/${SESSION}/steer`)
|
||||
.send({ mode: 'interrupt', directory: DIRECTORY })
|
||||
.expect(400, { error: 'directive is required' });
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user