fix: make schema types root-level object

This commit is contained in:
2026-06-07 14:47:10 +09:00
parent 94cf3572f1
commit bc08fccf10
7 changed files with 77 additions and 43 deletions

View File

@@ -73,7 +73,7 @@ const mockCall = mock(async <T>(model: unknown, options: any): Promise<T> => {
return GENERATED_BASE_SYSTEM_PROMPT as unknown as T;
}
if (options.jsonSchemaName === "fact-extractor") {
return EXTRACTED_FACTS as unknown as T;
return { items: EXTRACTED_FACTS } as unknown as T;
}
throw new Error(
`unexpected LLM call: model=${model} instruction=${options.instruction?.slice(0, 80)}`,

View File

@@ -2,7 +2,7 @@ import { afterEach, beforeEach, describe, expect, mock, test } from "bun:test";
import type {
Availability,
DailySlot,
MonthlySchedule,
MonthlyDay,
} from "@/openrouter/schema";
interface RecordedCall {
@@ -39,7 +39,7 @@ function buildAvailability(): Availability[] {
];
}
function buildMonthly(): MonthlySchedule {
function buildMonthlyDays(): MonthlyDay[] {
return Array.from({ length: 30 }, (_, i) => ({
day: i + 1,
summary: `Day ${i + 1} summary`,
@@ -53,12 +53,15 @@ const mockCall = mock(async (_model: unknown, options: any) => {
if (options.jsonSchemaName === "monthly-schedule") {
const match = (options.message as string).match(/\((\d+) days\)/);
const days = match ? parseInt(match[1]!, 10) : 30;
return Array.from({ length: days }, (_, i) => ({
day: i + 1,
summary: `Day ${i + 1} summary`,
}));
return {
items: Array.from({ length: days }, (_, i) => ({
day: i + 1,
summary: `Day ${i + 1} summary`,
})),
};
}
if (options.jsonSchemaName === "availability") return buildAvailability();
if (options.jsonSchemaName === "availability")
return { items: buildAvailability() };
throw new Error(`unexpected jsonSchemaName: ${options.jsonSchemaName}`);
});
@@ -87,7 +90,6 @@ beforeEach(() => {
});
afterEach(async () => {
// ensure no on-disk braindb was created
const { unlink } = await import("fs/promises");
try {
await unlink("/tmp/brainbox-test-braindb-debug-schedule.json");
@@ -106,7 +108,7 @@ describe("runDebugScheduleDaily", () => {
expect(result.kind).toBe("daily");
expect(result.schedule.items).toHaveLength(48);
expect(result.availability.length).toBeGreaterThan(0);
expect(result.availability.items.length).toBeGreaterThan(0);
expect(result.dateKey).toMatch(/^\d{4}-\d{2}-\d{2}$/);
const dailyCall = llmCalls.find(
@@ -145,7 +147,7 @@ describe("runDebugScheduleMonthly", () => {
if (!result.ok) throw new Error("expected ok");
expect(result.kind).toBe("monthly");
expect(result.schedule).toHaveLength(result.daysInMonth);
expect(result.schedule.items).toHaveLength(result.daysInMonth);
expect(result.monthKey).toMatch(/^\d{4}-\d{2}$/);
const call = llmCalls.find(
@@ -187,3 +189,4 @@ describe("debug schedule no-disk invariant", () => {
expect(afterJson).toBe(false);
});
});

View File

@@ -2,7 +2,7 @@ import type { Command } from "commander";
import ora from "ora";
import { Brain } from "@/brain";
import {
type Availability,
type AvailabilityWindows,
type DailySchedule,
type MonthlySchedule,
} from "@/openrouter/schema";
@@ -21,7 +21,7 @@ export type DailyRunResult =
dateKey: string;
tomorrow: Date;
schedule: DailySchedule;
availability: Availability[];
availability: AvailabilityWindows;
}
| { ok: false; error: string };
@@ -72,7 +72,7 @@ export async function runDebugScheduleDaily(
return { ok: false, error: "Availability derivation failed" };
}
availSpinner.succeed(
`Availability derived (${availability.length} windows)`,
`Availability derived (${availability.items.length} windows)`,
);
printSection(`Availability — ${dateKey}`);
@@ -108,7 +108,7 @@ export async function runDebugScheduleMonthly(
return { ok: false, error: "Monthly schedule generation failed" };
}
scheduleSpinner.succeed(
`Monthly schedule generated (${schedule.length} day summaries)`,
`Monthly schedule generated (${schedule.items.length} day summaries)`,
);
printSection(`Monthly Schedule — ${monthKey} (${next.daysInMonth} days)`);