Skip to content

feat: Workflow supports file type output - #8301

Merged
shaohuzhang1 merged 1 commit into
v3from
pr@v3@fix_file_content
Dec 4, 2026
Merged

shaohuzhang1 merged 1 commit into
v3from
pr@v3@fix_file_content

Conversation

@shaohuzhang1

Copy link
Copy Markdown
Contributor

feat: Workflow supports file type output

line-height: 1.3;
word-break: break-word;
}
</style>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Here is the review of your code:

Potential Issues

  1. column.label used 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.
  2. row.label used as :key — Same concern; row numbers are usually unique, but if label is ever derived from content rather than row index, this could break. Prefer an explicit id.
  3. tableWidth computed with ?? 0 — If any column lacks a width, that column contributes 0px, while the <colgroup> renders width: ${column.width}px (i.e., "undefinedpx") for the same column. Inconsistent fallback. Compute once and reuse a default (or skip colgroup entries without width).
  4. ResizeObserver callback receives entries but ignores them — Fine, but calling layoutDrawings on every table resize (including vertical growth from text) may be frequent. Consider debouncing with requestAnimationFrame.
  5. watch(() => props.sheet, ...) with flush: 'post' — A deep change inside sheet.drawings/rows (mutating the object) won't trigger since it's not deep. If sheets are mutated, use { deep: true } or ensure immutability.
  6. layoutDrawings reads offsetLeft/offsetTop synchronously — offsetLeft is relative to the nearest positioned ancestor (offsetParent), not necessarily the scroll container. Since the wrapper is relative, the table should be the offset parent only if the table itself is positioned; verify header.offsetLeft includes correct origin. Safer to use getBoundingClientRect() differences so chart overlay aligns regardless of offsetParent.
  7. anchorPosition assumes header cell at columnIndex + 1 and body row at rowIndex — Correct given the first <th/> spacer, but fragile; a comment or constant would help maintainability.
  8. anchor.x / anchor.y units — Are these EMUs converted to px upstream? Not visible here; confirm conversion happens before reaching this component.
  9. MkEchart instantiation count — Each drawing creates a full ECharts instance. With many drawings this is heavy; consider lazy-rendering only when visible (IntersectionObserver) or virtualizing.
  10. <img :src="box.drawing.image"> — No loading="lazy" or error handler; large/missing images could degrade UX.
  11. Accessibility — Empty <th />, no scope attributes, images with empty alt. Add scope="col"/scope="row" and meaningful alt text if applicable.
  12. truncatedMessage computed once at setup — If locale changes at runtime, message won't update. Wrap in computed(() => t(...)).
  13. useI18n({ useScope: 'global' }) — Recreated per component instance unnecessarily; harmless but could be hoisted if perf-sensitive.
  14. onBeforeUnmount only disconnects observer — Also clear drawingBoxes.value = [] if needed to release references (minor).

Optimization Suggestions

  • Replace flatMap + filter with a single loop for clarity/perf (marginal).
  • Move ROW_HEADER_WIDTH into a const outside or share with index module.
  • Cache props.sheet.columns.reduce(...) if columns don't change often.
  • Consider content-visibility: auto on table rows for large sheets.
  • Avoid word-break: break-word (non-standard); prefer overflow-wrap: anywhere.
  • The .spreadsheet-table uses border-collapse: collapse while drawings are absolutely positioned — collapsed borders could offset alignment by ~1px; acceptable but worth noting.
  • Use defineProps with readonly or Object.freeze awareness—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"])

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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

  1. String vs enum inconsistency

    get_reply_handle("UNKNOWN").support("TEXT")

    Elsewhere the code uses ContentType.FILE.value, implying ContentType is an enum. If support() expects a ContentType, 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.TEXT consistently depending on the API contract.

  2. 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 uses eval, that is a security problem. Even with ast.literal_eval, it broadens the accepted format unnecessarily.

    • Prefer one documented serialization format, e.g. JSON.
    • Add malformed-input tests.
    • Ensure no eval is used.
  3. 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.

  4. Manual ReplyNode.__new__ construction is brittle

    node = ReplyNode.__new__(ReplyNode)
    node.data = {}
    ...

    This bypasses __init__ and will break if ReplyNode gains 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.

  5. get_authorized_file side effect is signature-sensitive

    get_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.

  6. Global mutable WORKFLOW_PARAMS

    WORKFLOW_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.

  7. Incomplete failure-path assertions
    In test_file_reply_rejects_unauthorized_file, you assert that write was 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.

  8. Weak assertion in test_file_reply_hidden_when_not_result

    self.assertEqual(len(node.context["answer"]), 1)

    This does not verify content or hidden behavior. Assert the exact answer and that write was not called. Also consider testing an empty file list for is_result=False.

  9. 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_id preserves its original position. If that is a required contract, keep it; otherwise assert on a set or document the ordering requirement.

  10. 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_id or invalid workflow params.

Minor optimization suggestions

  • Use a class-level @patch(...) on ReplyFileTest to avoid repeating the decorator.
  • In test_accepts_rendered_text, use subTest for each format so failures identify the exact format.
  • Consider moving test_file_contents_aggregate_by_id into a separate FileContentAggregationTest class since it does not test ReplyNode.
  • 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.

@shaohuzhang1
shaohuzhang1 merged commit dc4914e into v3 Dec 4, 2026
3 of 4 checks passed
@shaohuzhang1
shaohuzhang1 deleted the pr@v3@fix_file_content branch December 4, 2026 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant