You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@texera.apache.org by "mengw15 (via GitHub)" <gi...@apache.org> on 2026/07/12 23:52:51 UTC
[PR] test(agent-service): add unit tests for executeOperatorAndFormat [texera]
mengw15 opened a new pull request, #6379:
URL: https://github.com/apache/texera/pull/6379
### What changes were proposed in this PR?
Adds a unit test suite for `executeOperatorAndFormat` in
`agent-service/src/agent/tools/workflow-execution-tools.ts`, which was
previously uncovered. The function is the core of the agent's
`executeOperator` tool: it builds a sub-DAG logical plan, validates the target
operator, POSTs the execution request, and formats the result (or the failure)
back to the model.
The 13 tests cover every return branch:
- **Guards & validation** — empty workflow (target absent); target operator's
own connection-validation error blocks execution (no HTTP call made).
- **Execution-level failures** — `Failed` (per-operator errors + `onResult`
notification), `CompilationFailed` (compilation errors), `Killed` (timeout
message), a rejected `fetch` (network error), and a non-ok HTTP response.
- **Operator result handling** — success with no result entry for the target,
an operator carrying an `error`, a non-tabular result placeholder, a
well-formed tabular result (shape line + TSV rows + per-operator `onResult`),
and char-limit truncation that keeps head/tail rows and drops the middle.
- **Cancellation** — `AbortError` is re-thrown rather than formatted as a result.
No production code was changed.
### Any related issues, documentation, discussions?
Closes #6374
### How was this PR tested?
New unit tests, run locally in `agent-service/` (all green, and the failure
path was verified by deliberately breaking an assertion to confirm the suite
goes red):
```
bun test src/agent/tools/workflow-execution-tools.spec.ts
# 13 pass, 0 fail, 38 expect() calls
bun run typecheck # tsc --noEmit, clean
bun run format:check # prettier, clean
```
`fetch` and the `WorkflowSystemMetadata` singleton are stubbed, so the tests
make no network calls and touch no live services.
### Was this PR authored or co-authored using generative AI tooling?
Generated-by: Claude Code (Opus 4.8 [1M context])
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@texera.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] test(agent-service): add unit tests for executeOperatorAndFormat [texera]
Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #6379:
URL: https://github.com/apache/texera/pull/6379#issuecomment-4953279293
## [Codecov](https://app.codecov.io/gh/apache/texera/pull/6379?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 66.97%. Comparing base ([`afa8af2`](https://app.codecov.io/gh/apache/texera/commit/afa8af22b2ac0279fbcc0c610cfe54e3ee0ef0b8?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`0d7f29a`](https://app.codecov.io/gh/apache/texera/commit/0d7f29ae0e88f0080fc405aa402d3abd95e56630?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## main #6379 +/- ##
============================================
+ Coverage 66.04% 66.97% +0.92%
Complexity 3380 3380
============================================
Files 1142 1142
Lines 44980 44891 -89
Branches 4948 4948
============================================
+ Hits 29709 30067 +358
+ Misses 13631 13184 -447
Partials 1640 1640
```
| [Flag](https://app.codecov.io/gh/apache/texera/pull/6379/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | | *Carryforward flag |
|---|---|---|---|
| [access-control-service](https://app.codecov.io/gh/apache/texera/pull/6379/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `70.00% <ø> (ø)` | | Carriedforward from [afa8af2](https://app.codecov.io/gh/apache/texera/commit/afa8af22b2ac0279fbcc0c610cfe54e3ee0ef0b8?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [agent-service](https://app.codecov.io/gh/apache/texera/pull/6379/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `64.86% <ø> (+12.95%)` | :arrow_up: | |
| [amber](https://app.codecov.io/gh/apache/texera/pull/6379/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `66.57% <ø> (ø)` | | Carriedforward from [afa8af2](https://app.codecov.io/gh/apache/texera/commit/afa8af22b2ac0279fbcc0c610cfe54e3ee0ef0b8?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [computing-unit-managing-service](https://app.codecov.io/gh/apache/texera/pull/6379/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `9.97% <ø> (ø)` | | Carriedforward from [afa8af2](https://app.codecov.io/gh/apache/texera/commit/afa8af22b2ac0279fbcc0c610cfe54e3ee0ef0b8?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [config-service](https://app.codecov.io/gh/apache/texera/pull/6379/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `52.30% <ø> (ø)` | | Carriedforward from [afa8af2](https://app.codecov.io/gh/apache/texera/commit/afa8af22b2ac0279fbcc0c610cfe54e3ee0ef0b8?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [file-service](https://app.codecov.io/gh/apache/texera/pull/6379/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `63.97% <ø> (ø)` | | Carriedforward from [afa8af2](https://app.codecov.io/gh/apache/texera/commit/afa8af22b2ac0279fbcc0c610cfe54e3ee0ef0b8?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [frontend](https://app.codecov.io/gh/apache/texera/pull/6379/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `63.51% <ø> (ø)` | | Carriedforward from [afa8af2](https://app.codecov.io/gh/apache/texera/commit/afa8af22b2ac0279fbcc0c610cfe54e3ee0ef0b8?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [notebook-migration-service](https://app.codecov.io/gh/apache/texera/pull/6379/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `78.94% <ø> (ø)` | | Carriedforward from [afa8af2](https://app.codecov.io/gh/apache/texera/commit/afa8af22b2ac0279fbcc0c610cfe54e3ee0ef0b8?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [pyamber](https://app.codecov.io/gh/apache/texera/pull/6379/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `91.18% <ø> (ø)` | | Carriedforward from [afa8af2](https://app.codecov.io/gh/apache/texera/commit/afa8af22b2ac0279fbcc0c610cfe54e3ee0ef0b8?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
| [workflow-compiling-service](https://app.codecov.io/gh/apache/texera/pull/6379/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `55.14% <ø> (ø)` | | Carriedforward from [afa8af2](https://app.codecov.io/gh/apache/texera/commit/afa8af22b2ac0279fbcc0c610cfe54e3ee0ef0b8?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
*This pull request uses carry forward flags. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) to find out more.
</details>
[:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/texera/pull/6379?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
<details><summary> :rocket: New features to boost your workflow: </summary>
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@texera.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] test(agent-service): add unit tests for executeOperatorAndFormat [texera]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #6379:
URL: https://github.com/apache/texera/pull/6379#issuecomment-4953276583
<!-- texera-reviewer-suggestion -->
### Automated Reviewer Suggestions
Based on the `git blame` history of the changed files, we recommend the following reviewers:
- No candidates found from `git blame` history.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@texera.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] test(agent-service): add unit tests for executeOperatorAndFormat [texera]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #6379:
URL: https://github.com/apache/texera/pull/6379#discussion_r3567400128
##########
agent-service/src/agent/tools/workflow-execution-tools.spec.ts:
##########
@@ -0,0 +1,262 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import { afterEach, beforeEach, describe, expect, mock, spyOn, test } from "bun:test";
+import { executeOperatorAndFormat, type ExecutionConfig } from "./workflow-execution-tools";
+import { WorkflowState } from "../workflow-state";
+import { WorkflowSystemMetadata } from "../util/workflow-system-metadata";
+import type { OperatorPredicate, PortDescription } from "../../types/workflow";
+import type { OperatorInfo, SyncExecutionResult } from "../../types/execution";
+
+function makeOperator(id: string, inputPorts: PortDescription[] = []): OperatorPredicate {
+ return {
+ operatorID: id,
+ operatorType: "TestOp",
+ operatorVersion: "1.0",
+ operatorProperties: {},
+ inputPorts,
+ outputPorts: [],
+ showAdvanced: false,
+ };
+}
+
+function stateWith(...operators: OperatorPredicate[]): WorkflowState {
+ const state = new WorkflowState();
+ for (const op of operators) state.addOperator(op);
+ return state;
+}
+
+function cfg(overrides: Partial<ExecutionConfig> = {}): ExecutionConfig {
+ return { userToken: "tok", workflowId: 1, ...overrides };
+}
+
+// A fetch double resolving to an ok response whose body is the given result.
+function resolveFetch(spy: ReturnType<typeof spyOn>, result: SyncExecutionResult): void {
+ spy.mockResolvedValue({ ok: true, json: async () => result } as unknown as Response);
+}
+
+let fetchSpy: ReturnType<typeof spyOn>;
+let validateSpy: ReturnType<typeof spyOn>;
+
+beforeEach(() => {
+ // Default: any unexpected network call fails loudly instead of hitting localhost.
+ fetchSpy = spyOn(globalThis, "fetch").mockRejectedValue(new Error("unexpected fetch"));
+ // Isolate connection validation from schema validation (TestOp is an unknown type).
+ validateSpy = spyOn(WorkflowSystemMetadata.getInstance(), "validateOperatorProperties").mockReturnValue({
+ isValid: true,
+ });
+});
+
+afterEach(() => {
+ fetchSpy.mockRestore();
+ validateSpy.mockRestore();
+});
+
+describe("executeOperatorAndFormat — guards & validation", () => {
+ test("reports an empty workflow when the target operator is absent", async () => {
+ const result = await executeOperatorAndFormat(new WorkflowState(), cfg(), "op1");
+ expect(result).toBe("[ERROR] Cannot execute: workflow has no operators.");
Review Comment:
This test name says the target operator is absent, but the setup uses an entirely empty `WorkflowState()` (it’s really testing the “no operators” guard). Renaming the test to match the actual scenario will make the suite clearer/less misleading.
##########
agent-service/src/agent/tools/workflow-execution-tools.spec.ts:
##########
@@ -0,0 +1,262 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import { afterEach, beforeEach, describe, expect, mock, spyOn, test } from "bun:test";
+import { executeOperatorAndFormat, type ExecutionConfig } from "./workflow-execution-tools";
+import { WorkflowState } from "../workflow-state";
+import { WorkflowSystemMetadata } from "../util/workflow-system-metadata";
+import type { OperatorPredicate, PortDescription } from "../../types/workflow";
+import type { OperatorInfo, SyncExecutionResult } from "../../types/execution";
+
+function makeOperator(id: string, inputPorts: PortDescription[] = []): OperatorPredicate {
+ return {
+ operatorID: id,
+ operatorType: "TestOp",
+ operatorVersion: "1.0",
+ operatorProperties: {},
+ inputPorts,
+ outputPorts: [],
+ showAdvanced: false,
+ };
+}
+
+function stateWith(...operators: OperatorPredicate[]): WorkflowState {
+ const state = new WorkflowState();
+ for (const op of operators) state.addOperator(op);
+ return state;
+}
+
+function cfg(overrides: Partial<ExecutionConfig> = {}): ExecutionConfig {
+ return { userToken: "tok", workflowId: 1, ...overrides };
+}
+
+// A fetch double resolving to an ok response whose body is the given result.
+function resolveFetch(spy: ReturnType<typeof spyOn>, result: SyncExecutionResult): void {
+ spy.mockResolvedValue({ ok: true, json: async () => result } as unknown as Response);
+}
+
+let fetchSpy: ReturnType<typeof spyOn>;
+let validateSpy: ReturnType<typeof spyOn>;
+
+beforeEach(() => {
+ // Default: any unexpected network call fails loudly instead of hitting localhost.
+ fetchSpy = spyOn(globalThis, "fetch").mockRejectedValue(new Error("unexpected fetch"));
+ // Isolate connection validation from schema validation (TestOp is an unknown type).
+ validateSpy = spyOn(WorkflowSystemMetadata.getInstance(), "validateOperatorProperties").mockReturnValue({
+ isValid: true,
+ });
+});
+
+afterEach(() => {
+ fetchSpy.mockRestore();
+ validateSpy.mockRestore();
+});
+
+describe("executeOperatorAndFormat — guards & validation", () => {
+ test("reports an empty workflow when the target operator is absent", async () => {
+ const result = await executeOperatorAndFormat(new WorkflowState(), cfg(), "op1");
+ expect(result).toBe("[ERROR] Cannot execute: workflow has no operators.");
+ expect(fetchSpy).not.toHaveBeenCalled();
+ });
+
+ test("blocks on the target operator's own validation error without executing", async () => {
+ // One unlinked input port -> connection validation fails for op1.
+ const state = stateWith(makeOperator("op1", [{ portID: "input-0" }]));
+ const result = await executeOperatorAndFormat(state, cfg(), "op1");
+ expect(result).toBe("[ERROR] Operator op1:\n - inputs: input-0 requires at least 1 input, has 0.");
+ expect(fetchSpy).not.toHaveBeenCalled();
+ });
+});
+
+describe("executeOperatorAndFormat — execution-level failures", () => {
+ test("formats per-operator errors when the run state is Failed and notifies onResult", async () => {
+ const state = stateWith(makeOperator("op1"));
+ resolveFetch(fetchSpy, {
+ success: false,
+ state: "Failed",
+ operators: {
+ op1: { state: "Failed", inputTuples: 0, outputTuples: 0, resultMode: "table", error: "runtime boom" },
+ },
+ errors: [],
+ });
+ const onResult = mock((_id: string, _info: OperatorInfo) => {});
+
+ const result = await executeOperatorAndFormat(state, cfg(), "op1", { onResult });
+
+ expect(result).toContain("[ERROR]");
+ expect(result).toContain("Execution error:");
+ expect(result).toContain("op1: runtime boom");
+ expect(onResult).toHaveBeenCalledTimes(1);
+ expect(onResult.mock.calls[0][0]).toBe("op1");
+ expect(onResult.mock.calls[0][1].state).toBe("Failed");
+ expect(onResult.mock.calls[0][1].error).toContain("runtime boom");
+ });
+
+ test("formats compilation errors when the run state is CompilationFailed", async () => {
+ const state = stateWith(makeOperator("op1"));
+ resolveFetch(fetchSpy, {
+ success: false,
+ state: "CompilationFailed",
+ operators: {},
+ compilationErrors: { op1: "type mismatch" },
+ });
+
+ const result = await executeOperatorAndFormat(state, cfg(), "op1");
+
+ expect(result).toContain("Compilation error:");
+ expect(result).toContain("op1: type mismatch");
+ });
+
+ test("reports a timeout message when the run state is Killed", async () => {
+ const state = stateWith(makeOperator("op1"));
+ resolveFetch(fetchSpy, { success: false, state: "Killed", operators: {}, errors: ["ignored"] });
+
+ const result = await executeOperatorAndFormat(state, cfg(), "op1");
+
+ expect(result).toContain("Workflow execution was killed (timeout).");
+ expect(result).not.toContain("ignored");
+ });
+
+ test("surfaces a network error as a general error", async () => {
+ const state = stateWith(makeOperator("op1"));
+ fetchSpy.mockRejectedValue(new Error("network down"));
+
+ const result = await executeOperatorAndFormat(state, cfg(), "op1");
+
+ expect(result).toContain("[ERROR]");
+ expect(result).toContain("network down");
+ });
+
+ test("surfaces a non-ok HTTP response as a general error", async () => {
+ const state = stateWith(makeOperator("op1"));
+ fetchSpy.mockResolvedValue({
+ ok: false,
+ status: 500,
+ statusText: "Internal Server Error",
+ text: async () => "upstream boom",
+ } as unknown as Response);
+
+ const result = await executeOperatorAndFormat(state, cfg(), "op1");
+
+ expect(result).toContain("Execution request failed: 500 Internal Server Error - upstream boom");
+ });
+});
+
+describe("executeOperatorAndFormat — operator result handling", () => {
+ test("errors when the run succeeds but the target operator has no result entry", async () => {
+ const state = stateWith(makeOperator("op1"));
+ resolveFetch(fetchSpy, { success: true, state: "Completed", operators: {} });
+
+ const result = await executeOperatorAndFormat(state, cfg(), "op1");
+
+ expect(result).toContain("[ERROR]");
+ expect(result).toContain("No result found for operator: op1");
+ });
+
+ test("errors and notifies onResult when the target operator carries an error", async () => {
+ const state = stateWith(makeOperator("op1"));
+ const opInfo: OperatorInfo = {
+ state: "Completed",
+ inputTuples: 0,
+ outputTuples: 0,
+ resultMode: "table",
+ error: "kaboom",
+ };
+ resolveFetch(fetchSpy, { success: true, state: "Completed", operators: { op1: opInfo } });
+ const onResult = mock((_id: string, _info: OperatorInfo) => {});
+
+ const result = await executeOperatorAndFormat(state, cfg(), "op1", { onResult });
+
+ expect(result).toContain("Execution error:");
+ expect(result).toContain("op1: kaboom");
+ expect(onResult).toHaveBeenCalledTimes(1);
+ expect(onResult.mock.calls[0][1].error).toBe("kaboom");
+ });
+
+ test("returns a placeholder when the operator result is not tabular", async () => {
Review Comment:
The behavior under test here is the `(no result data)` placeholder when `opInfo.result` is missing or not an array; it’s not about a “non-tabular” result (the result mode is still `table`). Renaming the test will better reflect the branch being exercised.
##########
agent-service/src/agent/tools/workflow-execution-tools.spec.ts:
##########
@@ -0,0 +1,262 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+import { afterEach, beforeEach, describe, expect, mock, spyOn, test } from "bun:test";
+import { executeOperatorAndFormat, type ExecutionConfig } from "./workflow-execution-tools";
+import { WorkflowState } from "../workflow-state";
+import { WorkflowSystemMetadata } from "../util/workflow-system-metadata";
+import type { OperatorPredicate, PortDescription } from "../../types/workflow";
+import type { OperatorInfo, SyncExecutionResult } from "../../types/execution";
+
+function makeOperator(id: string, inputPorts: PortDescription[] = []): OperatorPredicate {
+ return {
+ operatorID: id,
+ operatorType: "TestOp",
+ operatorVersion: "1.0",
+ operatorProperties: {},
+ inputPorts,
+ outputPorts: [],
+ showAdvanced: false,
+ };
+}
+
+function stateWith(...operators: OperatorPredicate[]): WorkflowState {
+ const state = new WorkflowState();
+ for (const op of operators) state.addOperator(op);
+ return state;
+}
+
+function cfg(overrides: Partial<ExecutionConfig> = {}): ExecutionConfig {
+ return { userToken: "tok", workflowId: 1, ...overrides };
+}
+
+// A fetch double resolving to an ok response whose body is the given result.
+function resolveFetch(spy: ReturnType<typeof spyOn>, result: SyncExecutionResult): void {
+ spy.mockResolvedValue({ ok: true, json: async () => result } as unknown as Response);
+}
+
+let fetchSpy: ReturnType<typeof spyOn>;
+let validateSpy: ReturnType<typeof spyOn>;
+
+beforeEach(() => {
+ // Default: any unexpected network call fails loudly instead of hitting localhost.
+ fetchSpy = spyOn(globalThis, "fetch").mockRejectedValue(new Error("unexpected fetch"));
+ // Isolate connection validation from schema validation (TestOp is an unknown type).
+ validateSpy = spyOn(WorkflowSystemMetadata.getInstance(), "validateOperatorProperties").mockReturnValue({
+ isValid: true,
+ });
+});
+
+afterEach(() => {
+ fetchSpy.mockRestore();
+ validateSpy.mockRestore();
+});
Review Comment:
`bun test` runs tests concurrently by default, but this suite mutates shared globals (`globalThis.fetch`) and a singleton method spy in `beforeEach`/`afterEach`. If tests in this file execute in parallel, they can race/overwrite each other’s spies and produce flaky failures (or hit the "unexpected fetch" rejection from another test’s setup). Consider marking these tests as serial (e.g., change each `test(...)` to `test.serial(...)`) or otherwise isolating the mocked globals per test run.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@texera.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] test(agent-service): add unit tests for executeOperatorAndFormat [texera]
Posted by "mengw15 (via GitHub)" <gi...@apache.org>.
mengw15 merged PR #6379:
URL: https://github.com/apache/texera/pull/6379
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@texera.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org