Repository navigation
feat: Workflow supports file type output - #8301
Conversation
| line-height: 1.3; | ||
| word-break: break-word; | ||
| } | ||
| </style> |
There was a problem hiding this comment.
Here is the review of your code:
Potential Issues
column.labelused as:key— Column labels can be duplicated (e.g., empty headers or repeated names), which would cause key collisions and rendering bugs. Use the index or a stable unique identifier instead.row.labelused as:key— Same concern; row numbers are usually unique, but iflabelis ever derived from content rather than row index, this could break. Prefer an explicit id.tableWidthcomputed with?? 0— If any column lacks a width, that column contributes 0px, while the<colgroup>renderswidth: ${column.width}px(i.e.,"undefinedpx") for the same column. Inconsistent fallback. Compute once and reuse a default (or skipcolgroupentries without width).ResizeObservercallback receives entries but ignores them — Fine, but callinglayoutDrawingson every table resize (including vertical growth from text) may be frequent. Consider debouncing withrequestAnimationFrame.watch(() => props.sheet, ...)withflush: 'post'— A deep change insidesheet.drawings/rows(mutating the object) won't trigger since it's not deep. If sheets are mutated, use{ deep: true }or ensure immutability.layoutDrawingsreadsoffsetLeft/offsetTopsynchronously —offsetLeftis relative to the nearest positioned ancestor (offsetParent), not necessarily the scroll container. Since the wrapper isrelative, the table should be the offset parent only if the table itself is positioned; verifyheader.offsetLeftincludes correct origin. Safer to usegetBoundingClientRect()differences so chart overlay aligns regardless ofoffsetParent.anchorPositionassumes header cell atcolumnIndex + 1and body row atrowIndex— Correct given the first<th/>spacer, but fragile; a comment or constant would help maintainability.anchor.x/anchor.yunits — Are these EMUs converted to px upstream? Not visible here; confirm conversion happens before reaching this component.MkEchartinstantiation count — Each drawing creates a full ECharts instance. With many drawings this is heavy; consider lazy-rendering only when visible (IntersectionObserver) or virtualizing.<img :src="box.drawing.image">— Noloading="lazy"or error handler; large/missing images could degrade UX.- Accessibility — Empty
<th />, noscopeattributes, images with emptyalt. Addscope="col"/scope="row"and meaningful alt text if applicable. truncatedMessagecomputed once at setup — If locale changes at runtime, message won't update. Wrap incomputed(() => t(...)).useI18n({ useScope: 'global' })— Recreated per component instance unnecessarily; harmless but could be hoisted if perf-sensitive.onBeforeUnmountonly disconnects observer — Also cleardrawingBoxes.value = []if needed to release references (minor).
Optimization Suggestions
- Replace
flatMap+ filter with a single loop for clarity/perf (marginal). - Move
ROW_HEADER_WIDTHinto aconstoutside or share with index module. - Cache
props.sheet.columns.reduce(...)if columns don't change often. - Consider
content-visibility: autoon table rows for large sheets. - Avoid
word-break: break-word(non-standard); preferoverflow-wrap: anywhere. - The
.spreadsheet-tableusesborder-collapse: collapsewhile drawings are absolutely positioned — collapsed borders could offset alignment by ~1px; acceptable but worth noting. - Use
definePropswithreadonlyorObject.freezeawareness—already good.
Overall the structure is clean; the key correctness risks are duplicate keys, inconsistent width fallbacks, and offset-based positioning assumptions.
| (content,) = manager.get_contents() | ||
| self.assertEqual(content["type"], ContentType.FILE.value) | ||
| self.assertEqual(content["status"], Status.SUCCESS.value) | ||
| self.assertEqual([file["name"] for file in content["file_list"]], ["a2.png", "b.pdf"]) |
There was a problem hiding this comment.
Overall, the tests are clear and mostly well-isolated. I do not see syntax errors or obvious failing assertions, but there are several brittleness/coverage/security-adjacent concerns.
Potential issues
-
String vs enum inconsistency
get_reply_handle("UNKNOWN").support("TEXT")
Elsewhere the code uses
ContentType.FILE.value, implyingContentTypeis an enum. Ifsupport()expects aContentType, passing"TEXT"may be incorrect or only work accidentally. Prefer:handler = get_reply_handle("UNKNOWN") self.assertTrue(handler.support(ContentType.TEXT.value))
or use
ContentType.TEXTconsistently depending on the API contract. -
The test encourages overly permissive text parsing
to_file_id_list(str([{"file_id": FILE_A}]))
This requires support for Python
repr-style input in addition to JSON and comma-separated IDs. If the implementation useseval, that is a security problem. Even withast.literal_eval, it broadens the accepted format unnecessarily.- Prefer one documented serialization format, e.g. JSON.
- Add malformed-input tests.
- Ensure no
evalis used.
-
Brittle extraction of the written message
(message,) = [call.args[0] for call in node.workflow_manage.write.call_args_list]
This implicitly assumes exactly one positional call. Use:
node.workflow_manage.write.assert_called_once() message = node.workflow_manage.write.call_args.args[0]
This gives clearer failure messages.
-
Manual
ReplyNode.__new__construction is brittlenode = ReplyNode.__new__(ReplyNode) node.data = {} ...
This bypasses
__init__and will break ifReplyNodegains required attributes or initialization logic. Consider a small factory using mocks, or at least keep all required attributes in one place and assert they exist. -
get_authorized_fileside effect is signature-sensitiveget_authorized_file.side_effect = lambda file_id, params: _stored_file(file_id)
If production code later calls it with keyword arguments or extra arguments, the test fails for an uninteresting reason. Prefer:
def _get_file(*args, **kwargs): return _stored_file(args[0] if args else kwargs["file_id"])
Alternatively keep the strict signature if that is intentionally part of the contract.
-
Global mutable
WORKFLOW_PARAMSWORKFLOW_PARAMS = {"root_user_id": ...}
If production code mutates the dict, tests can leak state. Return a copy from
get_workflow_parameters:node.get_workflow_parameters = lambda: dict(WORKFLOW_PARAMS)
or use an immutable mapping.
-
Incomplete failure-path assertions
Intest_file_reply_rejects_unauthorized_file, you assert thatwritewas not called, but not that no partial context was written. If authorization fails after adding one file, you could leak partial state. Add:self.assertNotIn("answer", node.context)
or assert the expected empty/unchanged state.
-
Weak assertion in
test_file_reply_hidden_when_not_resultself.assertEqual(len(node.context["answer"]), 1)
This does not verify content or hidden behavior. Assert the exact answer and that
writewas not called. Also consider testing an empty file list foris_result=False. -
Aggregation order assumption may be brittle
self.assertEqual([file["name"] for file in content["file_list"]], ["a2.png", "b.pdf"])
This assumes that replacing an existing
file_idpreserves its original position. If that is a required contract, keep it; otherwise assert on a set or document the ordering requirement. -
Missing edge cases
Useful additions:- Unauthorized failure on the second file after the first succeeds, to verify no partial write/context.
- Empty file list with
is_result=True. - Duplicate IDs with different URLs/metadata.
- URL that does not match the
file_id. - Malformed rendered text input.
- Missing
root_user_idor invalid workflow params.
Minor optimization suggestions
- Use a class-level
@patch(...)onReplyFileTestto avoid repeating the decorator. - In
test_accepts_rendered_text, usesubTestfor each format so failures identify the exact format. - Consider moving
test_file_contents_aggregate_by_idinto a separateFileContentAggregationTestclass since it does not testReplyNode. - Replace
assertTrue(get_reply_handle("UNKNOWN").support(...))with an assertion on the handler type if the fallback behavior is the real intent.
No blocking issue is apparent, but I would prioritize the enum/string consistency, the overly broad text parsing test, and stronger failure-path assertions.
feat: Workflow supports file type output