refactor(builder): type the AI-response/patch boundary
applyPatch's `ops` param was typed `any[]`, discarding the SitesmithPatchOp discriminated union that SitesmithResponse.ops already carried at the call site. Type it ops: SitesmithPatchOp[] so op.props/op.tree/op.op narrow correctly per-variant in the switch instead of being `any`, and update the unit tests' inline op literals to SitesmithPatchOp[] so tsc checks them too. SerializedTreeNode/SitesmithPatchOp themselves, and buildNodeTree/ sanitizeAiTree's tree params, were already typed from a prior task -- this closes the one remaining any at the op-handling site. Runtime validation (protected-key guard, style-merge guard, unknown-resolvedName soft-skip) is unchanged. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { describe, test, expect, vi } from 'vitest';
|
||||
import { sanitizeAiTree, __test } from './apply-ai-response';
|
||||
import type { SitesmithPatchOp } from '../types/sitesmith';
|
||||
|
||||
describe('findNodeIdByAiNodeId', () => {
|
||||
const query = {
|
||||
@@ -173,7 +174,7 @@ describe('applyPatch', () => {
|
||||
text: 'Old',
|
||||
style: { color: 'red', fontSize: '16px' },
|
||||
});
|
||||
const ops = [
|
||||
const ops: SitesmithPatchOp[] = [
|
||||
{
|
||||
op: 'update_props',
|
||||
node_id: 'ai-node-1',
|
||||
@@ -194,7 +195,7 @@ describe('applyPatch', () => {
|
||||
text: 'Old',
|
||||
style: { color: 'red', fontSize: '16px' },
|
||||
});
|
||||
const ops = [
|
||||
const ops: SitesmithPatchOp[] = [
|
||||
{
|
||||
op: 'update_props',
|
||||
node_id: 'ai-node-1',
|
||||
@@ -211,7 +212,7 @@ describe('applyPatch', () => {
|
||||
const { query, actions, propsById } = makeSingleNodeHarness('craft-1', 'ai-node-1', {
|
||||
style: { color: 'red', fontSize: '16px' },
|
||||
});
|
||||
const ops = [
|
||||
const ops: SitesmithPatchOp[] = [
|
||||
{ op: 'update_props', node_id: 'ai-node-1', props: { style: { color: 'blue' } } },
|
||||
];
|
||||
__test.applyPatch(actions, query, ops);
|
||||
@@ -221,7 +222,7 @@ describe('applyPatch', () => {
|
||||
test('an op with an unknown resolvedName tree is skipped without throwing; other ops in the batch still apply', () => {
|
||||
const warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
||||
const { query, actions, propsById } = makeSingleNodeHarness('craft-1', 'ai-node-1', {});
|
||||
const ops = [
|
||||
const ops: SitesmithPatchOp[] = [
|
||||
{
|
||||
op: 'insert_after',
|
||||
node_id: 'ai-node-1',
|
||||
|
||||
Reference in New Issue
Block a user