Skip to content

Commit 05d2a62

Browse files
Talha Jubair Siamtsensei
authored andcommitted
fix(review): address code review findings on PR #44
- Validate replayed score's archetype against registry in both server (400 for unknown archetype) and CLI (exit with clear error). Prevents silent job failures when score.json references a removed archetype. - Remove dead replayScorePath field from RunLog (declared but never set). - Fix web UI direction counter to use byte length (TextEncoder) matching the server's Buffer.byteLength check. Prevents CJK text from hitting the server 10KB limit while the UI shows it under the character limit.
1 parent 13f4fd7 commit 05d2a62

4 files changed

Lines changed: 16 additions & 4 deletions

File tree

src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import * as fs from "node:fs";
44
import { parseArgs } from "./cli/args.js";
55
import { showUsageReport } from "./cli/usage-report.js";
66
import { validateEnv } from "./cli/validate-env.js";
7+
import { getArchetype } from "./config/archetype-registry.js";
78
import { createCliCallbacks, runPipeline } from "./pipeline/orchestrator.js";
89
import { createProviders, createVerificationModel } from "./providers/factory.js";
910
import { DirectorScore } from "./schema/director-score.js";
@@ -53,6 +54,8 @@ async function main(): Promise<void> {
5354
try {
5455
const raw = fs.readFileSync(opts.score, "utf-8");
5556
replayScore = DirectorScore.parse(JSON.parse(raw));
57+
// Validate archetype exists in the registry
58+
getArchetype(replayScore.archetype);
5659
} catch (err) {
5760
if ((err as NodeJS.ErrnoException).code === "ENOENT") {
5861
console.error(`Score file not found: ${opts.score}`);

src/pipeline/orchestrator.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,6 @@ interface RunLog {
122122
musicResolution?: { provider: string; prompt?: string; metadata?: Record<string, unknown>; fallback: boolean };
123123
direction?: string;
124124
replay?: boolean;
125-
replayScorePath?: string;
126125
}
127126

128127
// ──────────────────────────────────────────────────────────────────────────────

src/server.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,14 @@ app.post<{ Body: CreateJobBody }>("/api/v1/jobs", async (request, reply) => {
248248
if (!result.success) {
249249
return reply.status(400).send({ error: `Invalid DirectorScore: ${result.error.message}` });
250250
}
251+
// Validate archetype exists in the registry (Zod accepts any string, but getArchetype throws for unknown names)
252+
try {
253+
getArchetype((result.data as { archetype: string }).archetype);
254+
} catch {
255+
return reply.status(400).send({
256+
error: `Score references unknown archetype: ${(result.data as { archetype: string }).archetype}`,
257+
});
258+
}
251259
validatedScore = result.data;
252260
}
253261

web/src/pages/HomePage.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -424,12 +424,14 @@ export function HomePage() {
424424
className="w-full rounded-lg border border-border bg-transparent px-3 py-2 text-sm placeholder:text-text-faint focus:outline-none focus:ring-1 focus:ring-primary/40 resize-y min-h-[60px]"
425425
placeholder="Describe your creative vision: visual style, mood, script notes, scene ideas, music preference..."
426426
value={directionText}
427-
onChange={(e) => setDirectionText(e.target.value)}
428-
maxLength={10000}
427+
onChange={(e) => {
428+
const bytes = new TextEncoder().encode(e.target.value).length;
429+
if (bytes <= 10240) setDirectionText(e.target.value);
430+
}}
429431
rows={3}
430432
/>
431433
<p className="mt-1 text-right text-[10px] text-muted-foreground">
432-
{directionText.length.toLocaleString()} / 10,000
434+
{new TextEncoder().encode(directionText).length.toLocaleString()} / 10,240 bytes
433435
</p>
434436
</div>
435437

0 commit comments

Comments
 (0)