Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/shared/validation/compressionConfigSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export const rtkConfigSchema = z
groupingThreshold: z.number().int().min(2).max(100).optional(),
stripCodeComments: z.boolean().optional(),
preserveDocstrings: z.boolean().optional(),
enableRenderers: z.boolean().optional(),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The RtkConfig interface in open-sse/services/compression/types.ts also defines an optional renderers field (renderers?: string[];). Since rtkConfigSchema is defined with .strict(), any incoming configuration payload containing the renderers field will trigger a validation failure (HTTP 400), similar to the issue with enableRenderers.

To prevent this, we should also accept renderers in the schema.

    enableRenderers: z.boolean().optional(),
    renderers: z.array(z.string()).optional(),

})
.strict();

Expand Down
41 changes: 41 additions & 0 deletions tests/unit/rtk-enable-renderers-6703.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { describe, it } from "node:test";
import assert from "node:assert/strict";

import {
rtkConfigSchema,
compressionSettingsUpdateSchema,
} from "../../src/shared/validation/compressionConfigSchemas.ts";
import { DEFAULT_RTK_CONFIG } from "../../open-sse/services/compression/types.ts";

// Regression for #6703: rtkConfigSchema uses Zod .strict() but was missing the
// `enableRenderers` field that DEFAULT_RTK_CONFIG (and the RTK engine's own
// configSchema) already define. The frontend reads DEFAULT_RTK_CONFIG (which
// carries enableRenderers), sends the full object back on save, and .strict()
// rejects the unknown key → HTTP 400 "Unrecognized key: enableRenderers".
// This broke PUT /api/settings/compression, POST /api/context/rtk/test, and
// PUT /api/context/rtk/config.

describe("RTK config schema — enableRenderers (#6703)", () => {
it("accepts enableRenderers on the strict rtkConfigSchema", () => {
assert.equal(rtkConfigSchema.safeParse({ enableRenderers: false }).success, true);
assert.equal(rtkConfigSchema.safeParse({ enableRenderers: true }).success, true);
});

it("accepts the full DEFAULT_RTK_CONFIG without stripping fields", () => {
const result = rtkConfigSchema.safeParse(DEFAULT_RTK_CONFIG);
assert.equal(result.success, true, JSON.stringify(result.error?.issues));
assert.equal(result.data.enableRenderers, false);
});

it("rejects a genuinely unknown key (strict mode still enforced)", () => {
assert.equal(rtkConfigSchema.safeParse({ totallyBogusKey: true }).success, false);
});

it("accepts rtkConfig with enableRenderers through the settings-update schema", () => {
// Mirrors the PUT /api/settings/compression payload from the bug report.
const result = compressionSettingsUpdateSchema.safeParse({
rtkConfig: { ...DEFAULT_RTK_CONFIG, enableRenderers: false },
});
assert.equal(result.success, true, JSON.stringify(result.error?.issues));
});
});
Loading