From 7798cc7dcc9f9a7b53a66a8552b5a557233981c2 Mon Sep 17 00:00:00 2001 From: Charles Teague Date: Thu, 19 Sep 2024 09:40:40 -0400 Subject: [PATCH] =?UTF-8?q?Ensure=20non=20add/copy/move=20ops=20don?= =?UTF-8?q?=E2=80=99t=20throw?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Renderers currently on pay attention to 3 ops (add, remove, replace) when rendering previews. But we would incorrectly assume that an op that appeared in a patch would be supported on renderers, so move, copy, or test would cause an error. fixes #455 --- src/inspect_ai/_view/www/dist/assets/index.js | 2 +- .../www/src/samples/transcript/state/StateEventView.mjs | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/inspect_ai/_view/www/dist/assets/index.js b/src/inspect_ai/_view/www/dist/assets/index.js index 916788909..9fa13d25c 100644 --- a/src/inspect_ai/_view/www/dist/assets/index.js +++ b/src/inspect_ai/_view/www/dist/assets/index.js @@ -15718,7 +15718,7 @@ const generatePreview = (changes, resolvedState) => { const requiredMatchCount = changeType.signature.remove.length + changeType.signature.replace.length + changeType.signature.add.length; let matchingOps = 0; for (const change of changes) { - if (changeType.signature[change.op].length > 0) { + if (changeType.signature[change.op] && changeType.signature[change.op].length > 0) { changeType.signature[change.op].forEach((signature) => { if (change.path.match(signature)) { matchingOps++; diff --git a/src/inspect_ai/_view/www/src/samples/transcript/state/StateEventView.mjs b/src/inspect_ai/_view/www/src/samples/transcript/state/StateEventView.mjs index 00ff14fbe..7bc3a62f9 100644 --- a/src/inspect_ai/_view/www/src/samples/transcript/state/StateEventView.mjs +++ b/src/inspect_ai/_view/www/src/samples/transcript/state/StateEventView.mjs @@ -64,13 +64,19 @@ export const StateEventView = ({ id, event, style, stateManager }) => { const generatePreview = (changes, resolvedState) => { const results = []; for (const changeType of RenderableChangeTypes) { + // Note that we currently only have renderers that depend upon + // add, remove, replace, but we should likely add + // move, copy, test const requiredMatchCount = changeType.signature.remove.length + changeType.signature.replace.length + changeType.signature.add.length; let matchingOps = 0; for (const change of changes) { - if (changeType.signature[change.op].length > 0) { + if ( + changeType.signature[change.op] && + changeType.signature[change.op].length > 0 + ) { changeType.signature[change.op].forEach((signature) => { if (change.path.match(signature)) { matchingOps++;