fix(vibe): bind next plan item query correctly
This commit is contained in:
@@ -437,6 +437,7 @@ describe('DbService v2 methods', () => {
|
|||||||
await expect(service.serveNextVibePlanItem('session-1', 'user-1')).resolves.toEqual({ item, stale: false });
|
await expect(service.serveNextVibePlanItem('session-1', 'user-1')).resolves.toEqual({ item, stale: false });
|
||||||
expect(clientQuery.mock.calls[1][0]).toContain('FOR UPDATE');
|
expect(clientQuery.mock.calls[1][0]).toContain('FOR UPDATE');
|
||||||
expect(clientQuery.mock.calls[3][0]).toContain('SET committed = true');
|
expect(clientQuery.mock.calls[3][0]).toContain('SET committed = true');
|
||||||
|
expect(clientQuery.mock.calls[3][1]).toEqual(['plan-1']);
|
||||||
expect(clientQuery.mock.calls[4][0]).toContain("'track_served'");
|
expect(clientQuery.mock.calls[4][0]).toContain("'track_served'");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -2203,12 +2203,12 @@ export class DbService {
|
|||||||
const item = await client.query(
|
const item = await client.query(
|
||||||
`WITH next_item AS (
|
`WITH next_item AS (
|
||||||
SELECT i.plan_version_id, i.ordinal FROM vibe_plan_items i
|
SELECT i.plan_version_id, i.ordinal FROM vibe_plan_items i
|
||||||
WHERE i.plan_version_id = $2 AND NOT i.committed ORDER BY i.ordinal ASC LIMIT 1 FOR UPDATE
|
WHERE i.plan_version_id = $1 AND NOT i.committed ORDER BY i.ordinal ASC LIMIT 1 FOR UPDATE
|
||||||
)
|
)
|
||||||
UPDATE vibe_plan_items i SET committed = true
|
UPDATE vibe_plan_items i SET committed = true
|
||||||
FROM next_item n WHERE i.plan_version_id = n.plan_version_id AND i.ordinal = n.ordinal
|
FROM next_item n WHERE i.plan_version_id = n.plan_version_id AND i.ordinal = n.ordinal
|
||||||
RETURNING i.*`,
|
RETURNING i.*`,
|
||||||
[sessionId, plan.id]
|
[plan.id]
|
||||||
);
|
);
|
||||||
const served = item.rows[0] as VibePlanItem | undefined;
|
const served = item.rows[0] as VibePlanItem | undefined;
|
||||||
if (!served) return { item: null, stale: false };
|
if (!served) return { item: null, stale: false };
|
||||||
|
|||||||
Reference in New Issue
Block a user