You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@texera.apache.org by "Ma77Ball (via GitHub)" <gi...@apache.org> on 2026/07/20 21:32:36 UTC

[PR] test(frontend): add unit tests for datasetVersionFileTree [texera]

Ma77Ball opened a new pull request, #6651:
URL: https://github.com/apache/texera/pull/6651

   ### What changes were proposed in this PR?
   - Add Vitest unit tests for the dataset version file tree path helpers and the DatasetVersionFileTreeManager class.
   ### Any related issues, documentation, discussions?
   Closes: #6650
   ### How was this PR tested?
   - Run: `cd frontend && node --max-old-space-size=8192 ./node_modules/nx/dist/bin/nx.js test gui --watch=false --include=src/app/common/type/datasetVersionFileTree.spec.ts`, expect all 22 tests passing
   ### Was this PR authored or co-authored using generative AI tooling?
   Co-authored with Claude Opus 4.8 in compliance with ASF


-- 
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(frontend): add unit tests for datasetVersionFileTree [texera]

Posted by "codecov-commenter (via GitHub)" <gi...@apache.org>.
codecov-commenter commented on PR #6651:
URL: https://github.com/apache/texera/pull/6651#issuecomment-5027552875

   ## [Codecov](https://app.codecov.io/gh/apache/texera/pull/6651?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 74.54%. Comparing base ([`f14cd39`](https://app.codecov.io/gh/apache/texera/commit/f14cd3975e7446b77241990b7d573d182d61f88f?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`eddb4ee`](https://app.codecov.io/gh/apache/texera/commit/eddb4ee76603988d78cece07e41438d00fc682bd?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   :white_check_mark: All tests successful. No failed tests found.
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   ```diff
   @@             Coverage Diff              @@
   ##               main    #6651      +/-   ##
   ============================================
   + Coverage     74.51%   74.54%   +0.02%     
     Complexity     3440     3440              
   ============================================
     Files          1157     1157              
     Lines         45621    45689      +68     
     Branches       5031     5050      +19     
   ============================================
   + Hits          33996    34058      +62     
     Misses         9973     9973              
   - Partials       1652     1658       +6     
   ```
   
   | [Flag](https://app.codecov.io/gh/apache/texera/pull/6651/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/6651/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 [f14cd39](https://app.codecov.io/gh/apache/texera/commit/f14cd3975e7446b77241990b7d573d182d61f88f?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/6651/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `76.76% <ø> (ø)` | | Carriedforward from [f14cd39](https://app.codecov.io/gh/apache/texera/commit/f14cd3975e7446b77241990b7d573d182d61f88f?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   | [amber](https://app.codecov.io/gh/apache/texera/pull/6651/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `66.82% <ø> (ø)` | | Carriedforward from [f14cd39](https://app.codecov.io/gh/apache/texera/commit/f14cd3975e7446b77241990b7d573d182d61f88f?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/6651/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `18.00% <ø> (ø)` | | Carriedforward from [f14cd39](https://app.codecov.io/gh/apache/texera/commit/f14cd3975e7446b77241990b7d573d182d61f88f?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/6651/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `66.66% <ø> (ø)` | | Carriedforward from [f14cd39](https://app.codecov.io/gh/apache/texera/commit/f14cd3975e7446b77241990b7d573d182d61f88f?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/6651/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `66.80% <ø> (ø)` | | Carriedforward from [f14cd39](https://app.codecov.io/gh/apache/texera/commit/f14cd3975e7446b77241990b7d573d182d61f88f?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/6651/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `78.34% <ø> (+0.04%)` | :arrow_up: | |
   | [notebook-migration-service](https://app.codecov.io/gh/apache/texera/pull/6651/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 [f14cd39](https://app.codecov.io/gh/apache/texera/commit/f14cd3975e7446b77241990b7d573d182d61f88f?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/6651/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `91.83% <ø> (ø)` | | Carriedforward from [f14cd39](https://app.codecov.io/gh/apache/texera/commit/f14cd3975e7446b77241990b7d573d182d61f88f?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/6651/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 [f14cd39](https://app.codecov.io/gh/apache/texera/commit/f14cd3975e7446b77241990b7d573d182d61f88f?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/6651?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(frontend): add unit tests for datasetVersionFileTree [texera]

Posted by "aglinxinyuan (via GitHub)" <gi...@apache.org>.
aglinxinyuan merged PR #6651:
URL: https://github.com/apache/texera/pull/6651


-- 
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(frontend): add unit tests for datasetVersionFileTree [texera]

Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #6651:
URL: https://github.com/apache/texera/pull/6651#discussion_r3617811598


##########
frontend/src/app/common/type/datasetVersionFileTree.spec.ts:
##########
@@ -0,0 +1,227 @@
+/**
+ * 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 {
+  DatasetFileNode,
+  DatasetVersionFileTreeManager,
+  getFullPathFromDatasetFileNode,
+  getPathsUnderOrEqualDatasetFileNode,
+  getRelativePathFromDatasetFileNode,
+} from "./datasetVersionFileTree";
+
+describe("getFullPathFromDatasetFileNode", () => {
+  it("joins parentDir and name with a slash", () => {
+    const node: DatasetFileNode = { name: "c.txt", type: "file", parentDir: "/a/b" };
+    expect(getFullPathFromDatasetFileNode(node)).toBe("/a/b/c.txt");
+  });
+
+  it("produces a leading slash for a node whose parentDir is empty", () => {
+    const node: DatasetFileNode = { name: "root", type: "directory", parentDir: "" };
+    expect(getFullPathFromDatasetFileNode(node)).toBe("/root");
+  });
+});
+
+describe("getRelativePathFromDatasetFileNode", () => {
+  it("strips the first three path segments", () => {
+    const node: DatasetFileNode = { name: "file.csv", type: "file", parentDir: "/owner/dataset/v1" };
+    // full path is /owner/dataset/v1/file.csv -> segments [owner, dataset, v1, file.csv]
+    expect(getRelativePathFromDatasetFileNode(node)).toBe("file.csv");
+  });
+
+  it("preserves nested relative segments beyond the first three", () => {
+    const node: DatasetFileNode = { name: "f.txt", type: "file", parentDir: "/owner/dataset/v1/sub/dir" };
+    expect(getRelativePathFromDatasetFileNode(node)).toBe("sub/dir/f.txt");
+  });
+
+  it("returns an empty string when there are three or fewer segments", () => {
+    const node: DatasetFileNode = { name: "v1", type: "directory", parentDir: "/owner/dataset" };
+    // full path /owner/dataset/v1 -> exactly 3 segments -> no relative path
+    expect(getRelativePathFromDatasetFileNode(node)).toBe("");
+  });
+
+  it("ignores empty segments from duplicate slashes when counting", () => {
+    const node: DatasetFileNode = { name: "file.csv", type: "file", parentDir: "/owner//dataset/v1" };
+    // empty segment between the duplicate slashes is filtered out, leaving 4 real segments
+    expect(getRelativePathFromDatasetFileNode(node)).toBe("file.csv");
+  });
+});
+
+describe("getPathsUnderOrEqualDatasetFileNode", () => {
+  it("returns the single path for a file node", () => {
+    const file: DatasetFileNode = { name: "a.txt", type: "file", parentDir: "/dir" };
+    expect(getPathsUnderOrEqualDatasetFileNode(file)).toEqual(["/dir/a.txt"]);
+  });
+
+  it("collects every file path under a directory", () => {
+    const file1: DatasetFileNode = { name: "file1.txt", type: "file", parentDir: "/dir" };
+    const file2: DatasetFileNode = { name: "file2.txt", type: "file", parentDir: "/dir" };
+    const dir: DatasetFileNode = { name: "dir", type: "directory", parentDir: "", children: [file1, file2] };
+    expect(getPathsUnderOrEqualDatasetFileNode(dir)).toEqual(["/dir/file1.txt", "/dir/file2.txt"]);
+  });
+
+  it("recurses into nested directories", () => {
+    const deepFile: DatasetFileNode = { name: "deep.txt", type: "file", parentDir: "/a/b" };
+    const subDir: DatasetFileNode = { name: "b", type: "directory", parentDir: "/a", children: [deepFile] };
+    const topDir: DatasetFileNode = { name: "a", type: "directory", parentDir: "", children: [subDir] };
+    expect(getPathsUnderOrEqualDatasetFileNode(topDir)).toEqual(["/a/b/deep.txt"]);
+  });
+
+  it("returns an empty array for an empty directory", () => {
+    const emptyChildren: DatasetFileNode = { name: "dir", type: "directory", parentDir: "", children: [] };
+    const noChildrenProp: DatasetFileNode = { name: "dir", type: "directory", parentDir: "" };
+    expect(getPathsUnderOrEqualDatasetFileNode(emptyChildren)).toEqual([]);
+    expect(getPathsUnderOrEqualDatasetFileNode(noChildrenProp)).toEqual([]);
+  });
+});
+
+describe("DatasetVersionFileTreeManager", () => {
+  describe("addNodeWithPath", () => {
+    it("starts with no root nodes", () => {
+      const manager = new DatasetVersionFileTreeManager();
+      expect(manager.getRootNodes()).toEqual([]);
+    });
+
+    it("builds the intermediate directory structure and returns the leaf file node", () => {
+      const manager = new DatasetVersionFileTreeManager();
+      const leaf = manager.addNodeWithPath("/a/b/c.txt");
+
+      expect(leaf.name).toBe("c.txt");
+      expect(leaf.type).toBe("file");
+      expect(getFullPathFromDatasetFileNode(leaf)).toBe("/a/b/c.txt");
+
+      const roots = manager.getRootNodes();
+      expect(roots.length).toBe(1);
+      expect(roots[0].name).toBe("a");
+      expect(roots[0].type).toBe("directory");
+
+      const dirB = roots[0].children![0];
+      expect(dirB.name).toBe("b");
+      expect(dirB.type).toBe("directory");
+      expect(dirB.children![0]).toBe(leaf);
+    });
+
+    it("is idempotent when adding the same path twice", () => {
+      const manager = new DatasetVersionFileTreeManager();
+      const first = manager.addNodeWithPath("/a/b/c.txt");
+      const second = manager.addNodeWithPath("/a/b/c.txt");
+
+      expect(second).toBe(first);
+      expect(manager.getRootNodes().length).toBe(1);
+      const dirB = manager.getRootNodes()[0].children![0];
+      expect(dirB.children!.length).toBe(1);
+    });
+
+    it("adds siblings under an existing directory", () => {
+      const manager = new DatasetVersionFileTreeManager();
+      manager.addNodeWithPath("/a/b/c.txt");
+      manager.addNodeWithPath("/a/b/d.txt");
+
+      const dirB = manager.getRootNodes()[0].children![0];
+      expect(dirB.children!.map(child => child.name).sort()).toEqual(["c.txt", "d.txt"]);
+    });
+
+    it("handles paths without a leading slash", () => {
+      const manager = new DatasetVersionFileTreeManager();
+      const leaf = manager.addNodeWithPath("x/y.txt");
+      expect(getFullPathFromDatasetFileNode(leaf)).toBe("/x/y.txt");
+      expect(manager.getRootNodes()[0].name).toBe("x");
+    });
+  });
+
+  describe("initializeWithRootNodes / constructor", () => {
+    it("exposes provided root nodes", () => {
+      const dir: DatasetFileNode = {
+        name: "dir",
+        type: "directory",
+        parentDir: "/",
+        children: [{ name: "f.txt", type: "file", parentDir: "/dir" }],
+      };
+      const manager = new DatasetVersionFileTreeManager([dir]);
+      expect(manager.getRootNodes()).toEqual([dir]);
+    });
+  });
+
+  describe("removeNode", () => {
+    it("removes a leaf node found by identity via BFS", () => {
+      const manager = new DatasetVersionFileTreeManager();
+      const leaf = manager.addNodeWithPath("/a/b/c.txt");
+      const dirB = manager.getRootNodes()[0].children![0];
+
+      manager.removeNode(leaf);
+      expect(dirB.children).toEqual([]);
+    });
+
+    it("removes a whole subtree when removing an inner directory", () => {
+      const manager = new DatasetVersionFileTreeManager();
+      manager.addNodeWithPath("/a/b/c.txt");
+      const rootA = manager.getRootNodes()[0];
+
+      manager.removeNode(rootA);
+      expect(manager.getRootNodes()).toEqual([]);
+    });
+
+    it("does nothing for a node that is not present in the tree", () => {
+      const manager = new DatasetVersionFileTreeManager();
+      manager.addNodeWithPath("/a/b/c.txt");
+      const stranger: DatasetFileNode = { name: "z.txt", type: "file", parentDir: "/q" };
+
+      manager.removeNode(stranger);
+      expect(manager.getRootNodes().length).toBe(1);
+      expect(manager.getRootNodes()[0].children![0].children!.length).toBe(1);
+    });
+
+    it("refuses to remove the synthetic root node", () => {
+      const manager = new DatasetVersionFileTreeManager();
+      manager.addNodeWithPath("/a/b/c.txt");
+      const fakeRoot: DatasetFileNode = { name: "/", type: "directory", parentDir: "" };
+
+      manager.removeNode(fakeRoot);
+      expect(manager.getRootNodes().length).toBe(1);
+    });
+  });
+
+  describe("removeNodeWithPath", () => {
+    it("removes a node from its parent's children and the internal map", () => {
+      const file1: DatasetFileNode = { name: "file1.txt", type: "file", parentDir: "/dir" };
+      const file2: DatasetFileNode = { name: "file2.txt", type: "file", parentDir: "/dir" };
+      const dir: DatasetFileNode = { name: "dir", type: "directory", parentDir: "/", children: [file1, file2] };
+      const manager = new DatasetVersionFileTreeManager([dir]);
+
+      manager.removeNodeWithPath("/dir/file1.txt");
+      expect(dir.children!.map(child => child.name)).toEqual(["file2.txt"]);
+
+      // A second removal of the same (now absent) path is a no-op.
+      manager.removeNodeWithPath("/dir/file1.txt");
+      expect(dir.children!.map(child => child.name)).toEqual(["file2.txt"]);
+    });
+
+    it("does nothing for an unknown path", () => {

Review Comment:
   The removeNodeWithPath tests don't currently cover removing a directory path (and thus subtree removal), even though the PR description claims subtree/path coverage. Adding an explicit directory-removal case would better guard the recursive deletion behavior.



##########
frontend/src/app/common/type/datasetVersionFileTree.spec.ts:
##########
@@ -0,0 +1,227 @@
+/**
+ * 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 {
+  DatasetFileNode,
+  DatasetVersionFileTreeManager,
+  getFullPathFromDatasetFileNode,
+  getPathsUnderOrEqualDatasetFileNode,
+  getRelativePathFromDatasetFileNode,
+} from "./datasetVersionFileTree";
+
+describe("getFullPathFromDatasetFileNode", () => {
+  it("joins parentDir and name with a slash", () => {
+    const node: DatasetFileNode = { name: "c.txt", type: "file", parentDir: "/a/b" };
+    expect(getFullPathFromDatasetFileNode(node)).toBe("/a/b/c.txt");
+  });
+
+  it("produces a leading slash for a node whose parentDir is empty", () => {
+    const node: DatasetFileNode = { name: "root", type: "directory", parentDir: "" };
+    expect(getFullPathFromDatasetFileNode(node)).toBe("/root");
+  });
+});
+
+describe("getRelativePathFromDatasetFileNode", () => {
+  it("strips the first three path segments", () => {
+    const node: DatasetFileNode = { name: "file.csv", type: "file", parentDir: "/owner/dataset/v1" };
+    // full path is /owner/dataset/v1/file.csv -> segments [owner, dataset, v1, file.csv]
+    expect(getRelativePathFromDatasetFileNode(node)).toBe("file.csv");
+  });
+
+  it("preserves nested relative segments beyond the first three", () => {
+    const node: DatasetFileNode = { name: "f.txt", type: "file", parentDir: "/owner/dataset/v1/sub/dir" };
+    expect(getRelativePathFromDatasetFileNode(node)).toBe("sub/dir/f.txt");
+  });
+
+  it("returns an empty string when there are three or fewer segments", () => {
+    const node: DatasetFileNode = { name: "v1", type: "directory", parentDir: "/owner/dataset" };
+    // full path /owner/dataset/v1 -> exactly 3 segments -> no relative path
+    expect(getRelativePathFromDatasetFileNode(node)).toBe("");
+  });
+
+  it("ignores empty segments from duplicate slashes when counting", () => {
+    const node: DatasetFileNode = { name: "file.csv", type: "file", parentDir: "/owner//dataset/v1" };
+    // empty segment between the duplicate slashes is filtered out, leaving 4 real segments
+    expect(getRelativePathFromDatasetFileNode(node)).toBe("file.csv");
+  });
+});
+
+describe("getPathsUnderOrEqualDatasetFileNode", () => {
+  it("returns the single path for a file node", () => {
+    const file: DatasetFileNode = { name: "a.txt", type: "file", parentDir: "/dir" };
+    expect(getPathsUnderOrEqualDatasetFileNode(file)).toEqual(["/dir/a.txt"]);
+  });
+
+  it("collects every file path under a directory", () => {
+    const file1: DatasetFileNode = { name: "file1.txt", type: "file", parentDir: "/dir" };
+    const file2: DatasetFileNode = { name: "file2.txt", type: "file", parentDir: "/dir" };
+    const dir: DatasetFileNode = { name: "dir", type: "directory", parentDir: "", children: [file1, file2] };
+    expect(getPathsUnderOrEqualDatasetFileNode(dir)).toEqual(["/dir/file1.txt", "/dir/file2.txt"]);
+  });
+
+  it("recurses into nested directories", () => {
+    const deepFile: DatasetFileNode = { name: "deep.txt", type: "file", parentDir: "/a/b" };
+    const subDir: DatasetFileNode = { name: "b", type: "directory", parentDir: "/a", children: [deepFile] };
+    const topDir: DatasetFileNode = { name: "a", type: "directory", parentDir: "", children: [subDir] };
+    expect(getPathsUnderOrEqualDatasetFileNode(topDir)).toEqual(["/a/b/deep.txt"]);
+  });
+
+  it("returns an empty array for an empty directory", () => {
+    const emptyChildren: DatasetFileNode = { name: "dir", type: "directory", parentDir: "", children: [] };
+    const noChildrenProp: DatasetFileNode = { name: "dir", type: "directory", parentDir: "" };
+    expect(getPathsUnderOrEqualDatasetFileNode(emptyChildren)).toEqual([]);
+    expect(getPathsUnderOrEqualDatasetFileNode(noChildrenProp)).toEqual([]);
+  });
+});
+
+describe("DatasetVersionFileTreeManager", () => {
+  describe("addNodeWithPath", () => {
+    it("starts with no root nodes", () => {
+      const manager = new DatasetVersionFileTreeManager();
+      expect(manager.getRootNodes()).toEqual([]);
+    });
+
+    it("builds the intermediate directory structure and returns the leaf file node", () => {
+      const manager = new DatasetVersionFileTreeManager();
+      const leaf = manager.addNodeWithPath("/a/b/c.txt");
+
+      expect(leaf.name).toBe("c.txt");
+      expect(leaf.type).toBe("file");
+      expect(getFullPathFromDatasetFileNode(leaf)).toBe("/a/b/c.txt");
+
+      const roots = manager.getRootNodes();
+      expect(roots.length).toBe(1);
+      expect(roots[0].name).toBe("a");
+      expect(roots[0].type).toBe("directory");
+
+      const dirB = roots[0].children![0];
+      expect(dirB.name).toBe("b");
+      expect(dirB.type).toBe("directory");
+      expect(dirB.children![0]).toBe(leaf);
+    });
+
+    it("is idempotent when adding the same path twice", () => {
+      const manager = new DatasetVersionFileTreeManager();
+      const first = manager.addNodeWithPath("/a/b/c.txt");
+      const second = manager.addNodeWithPath("/a/b/c.txt");
+
+      expect(second).toBe(first);
+      expect(manager.getRootNodes().length).toBe(1);
+      const dirB = manager.getRootNodes()[0].children![0];
+      expect(dirB.children!.length).toBe(1);
+    });
+
+    it("adds siblings under an existing directory", () => {
+      const manager = new DatasetVersionFileTreeManager();
+      manager.addNodeWithPath("/a/b/c.txt");
+      manager.addNodeWithPath("/a/b/d.txt");
+
+      const dirB = manager.getRootNodes()[0].children![0];
+      expect(dirB.children!.map(child => child.name).sort()).toEqual(["c.txt", "d.txt"]);
+    });
+
+    it("handles paths without a leading slash", () => {
+      const manager = new DatasetVersionFileTreeManager();
+      const leaf = manager.addNodeWithPath("x/y.txt");
+      expect(getFullPathFromDatasetFileNode(leaf)).toBe("/x/y.txt");
+      expect(manager.getRootNodes()[0].name).toBe("x");
+    });
+  });
+
+  describe("initializeWithRootNodes / constructor", () => {
+    it("exposes provided root nodes", () => {
+      const dir: DatasetFileNode = {
+        name: "dir",
+        type: "directory",
+        parentDir: "/",
+        children: [{ name: "f.txt", type: "file", parentDir: "/dir" }],
+      };
+      const manager = new DatasetVersionFileTreeManager([dir]);
+      expect(manager.getRootNodes()).toEqual([dir]);
+    });
+  });
+
+  describe("removeNode", () => {
+    it("removes a leaf node found by identity via BFS", () => {

Review Comment:
   This test name is coupled to an implementation detail ("via BFS"). The behavior under test is removal by identity; the traversal strategy can change without affecting external behavior.



##########
frontend/src/app/common/type/datasetVersionFileTree.spec.ts:
##########
@@ -0,0 +1,227 @@
+/**
+ * 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 {
+  DatasetFileNode,
+  DatasetVersionFileTreeManager,
+  getFullPathFromDatasetFileNode,
+  getPathsUnderOrEqualDatasetFileNode,
+  getRelativePathFromDatasetFileNode,
+} from "./datasetVersionFileTree";
+
+describe("getFullPathFromDatasetFileNode", () => {
+  it("joins parentDir and name with a slash", () => {
+    const node: DatasetFileNode = { name: "c.txt", type: "file", parentDir: "/a/b" };
+    expect(getFullPathFromDatasetFileNode(node)).toBe("/a/b/c.txt");
+  });
+
+  it("produces a leading slash for a node whose parentDir is empty", () => {
+    const node: DatasetFileNode = { name: "root", type: "directory", parentDir: "" };
+    expect(getFullPathFromDatasetFileNode(node)).toBe("/root");
+  });
+});
+
+describe("getRelativePathFromDatasetFileNode", () => {
+  it("strips the first three path segments", () => {
+    const node: DatasetFileNode = { name: "file.csv", type: "file", parentDir: "/owner/dataset/v1" };
+    // full path is /owner/dataset/v1/file.csv -> segments [owner, dataset, v1, file.csv]
+    expect(getRelativePathFromDatasetFileNode(node)).toBe("file.csv");
+  });
+
+  it("preserves nested relative segments beyond the first three", () => {
+    const node: DatasetFileNode = { name: "f.txt", type: "file", parentDir: "/owner/dataset/v1/sub/dir" };
+    expect(getRelativePathFromDatasetFileNode(node)).toBe("sub/dir/f.txt");
+  });
+
+  it("returns an empty string when there are three or fewer segments", () => {
+    const node: DatasetFileNode = { name: "v1", type: "directory", parentDir: "/owner/dataset" };
+    // full path /owner/dataset/v1 -> exactly 3 segments -> no relative path
+    expect(getRelativePathFromDatasetFileNode(node)).toBe("");
+  });
+
+  it("ignores empty segments from duplicate slashes when counting", () => {
+    const node: DatasetFileNode = { name: "file.csv", type: "file", parentDir: "/owner//dataset/v1" };
+    // empty segment between the duplicate slashes is filtered out, leaving 4 real segments
+    expect(getRelativePathFromDatasetFileNode(node)).toBe("file.csv");
+  });
+});
+
+describe("getPathsUnderOrEqualDatasetFileNode", () => {
+  it("returns the single path for a file node", () => {
+    const file: DatasetFileNode = { name: "a.txt", type: "file", parentDir: "/dir" };
+    expect(getPathsUnderOrEqualDatasetFileNode(file)).toEqual(["/dir/a.txt"]);
+  });
+
+  it("collects every file path under a directory", () => {
+    const file1: DatasetFileNode = { name: "file1.txt", type: "file", parentDir: "/dir" };
+    const file2: DatasetFileNode = { name: "file2.txt", type: "file", parentDir: "/dir" };
+    const dir: DatasetFileNode = { name: "dir", type: "directory", parentDir: "", children: [file1, file2] };
+    expect(getPathsUnderOrEqualDatasetFileNode(dir)).toEqual(["/dir/file1.txt", "/dir/file2.txt"]);
+  });
+
+  it("recurses into nested directories", () => {
+    const deepFile: DatasetFileNode = { name: "deep.txt", type: "file", parentDir: "/a/b" };
+    const subDir: DatasetFileNode = { name: "b", type: "directory", parentDir: "/a", children: [deepFile] };
+    const topDir: DatasetFileNode = { name: "a", type: "directory", parentDir: "", children: [subDir] };
+    expect(getPathsUnderOrEqualDatasetFileNode(topDir)).toEqual(["/a/b/deep.txt"]);
+  });
+
+  it("returns an empty array for an empty directory", () => {
+    const emptyChildren: DatasetFileNode = { name: "dir", type: "directory", parentDir: "", children: [] };
+    const noChildrenProp: DatasetFileNode = { name: "dir", type: "directory", parentDir: "" };
+    expect(getPathsUnderOrEqualDatasetFileNode(emptyChildren)).toEqual([]);
+    expect(getPathsUnderOrEqualDatasetFileNode(noChildrenProp)).toEqual([]);
+  });
+});
+
+describe("DatasetVersionFileTreeManager", () => {
+  describe("addNodeWithPath", () => {
+    it("starts with no root nodes", () => {
+      const manager = new DatasetVersionFileTreeManager();
+      expect(manager.getRootNodes()).toEqual([]);
+    });
+
+    it("builds the intermediate directory structure and returns the leaf file node", () => {
+      const manager = new DatasetVersionFileTreeManager();
+      const leaf = manager.addNodeWithPath("/a/b/c.txt");
+
+      expect(leaf.name).toBe("c.txt");
+      expect(leaf.type).toBe("file");
+      expect(getFullPathFromDatasetFileNode(leaf)).toBe("/a/b/c.txt");
+
+      const roots = manager.getRootNodes();
+      expect(roots.length).toBe(1);
+      expect(roots[0].name).toBe("a");
+      expect(roots[0].type).toBe("directory");
+
+      const dirB = roots[0].children![0];
+      expect(dirB.name).toBe("b");
+      expect(dirB.type).toBe("directory");
+      expect(dirB.children![0]).toBe(leaf);
+    });
+
+    it("is idempotent when adding the same path twice", () => {
+      const manager = new DatasetVersionFileTreeManager();
+      const first = manager.addNodeWithPath("/a/b/c.txt");
+      const second = manager.addNodeWithPath("/a/b/c.txt");
+
+      expect(second).toBe(first);
+      expect(manager.getRootNodes().length).toBe(1);
+      const dirB = manager.getRootNodes()[0].children![0];
+      expect(dirB.children!.length).toBe(1);
+    });
+
+    it("adds siblings under an existing directory", () => {
+      const manager = new DatasetVersionFileTreeManager();
+      manager.addNodeWithPath("/a/b/c.txt");
+      manager.addNodeWithPath("/a/b/d.txt");
+
+      const dirB = manager.getRootNodes()[0].children![0];
+      expect(dirB.children!.map(child => child.name).sort()).toEqual(["c.txt", "d.txt"]);
+    });
+
+    it("handles paths without a leading slash", () => {
+      const manager = new DatasetVersionFileTreeManager();
+      const leaf = manager.addNodeWithPath("x/y.txt");
+      expect(getFullPathFromDatasetFileNode(leaf)).toBe("/x/y.txt");
+      expect(manager.getRootNodes()[0].name).toBe("x");
+    });
+  });
+
+  describe("initializeWithRootNodes / constructor", () => {
+    it("exposes provided root nodes", () => {
+      const dir: DatasetFileNode = {
+        name: "dir",
+        type: "directory",
+        parentDir: "/",
+        children: [{ name: "f.txt", type: "file", parentDir: "/dir" }],
+      };
+      const manager = new DatasetVersionFileTreeManager([dir]);
+      expect(manager.getRootNodes()).toEqual([dir]);
+    });
+  });
+
+  describe("removeNode", () => {
+    it("removes a leaf node found by identity via BFS", () => {
+      const manager = new DatasetVersionFileTreeManager();
+      const leaf = manager.addNodeWithPath("/a/b/c.txt");
+      const dirB = manager.getRootNodes()[0].children![0];
+
+      manager.removeNode(leaf);
+      expect(dirB.children).toEqual([]);
+    });
+
+    it("removes a whole subtree when removing an inner directory", () => {
+      const manager = new DatasetVersionFileTreeManager();
+      manager.addNodeWithPath("/a/b/c.txt");
+      const rootA = manager.getRootNodes()[0];
+
+      manager.removeNode(rootA);
+      expect(manager.getRootNodes()).toEqual([]);
+    });
+
+    it("does nothing for a node that is not present in the tree", () => {
+      const manager = new DatasetVersionFileTreeManager();
+      manager.addNodeWithPath("/a/b/c.txt");
+      const stranger: DatasetFileNode = { name: "z.txt", type: "file", parentDir: "/q" };
+
+      manager.removeNode(stranger);
+      expect(manager.getRootNodes().length).toBe(1);
+      expect(manager.getRootNodes()[0].children![0].children!.length).toBe(1);
+    });
+
+    it("refuses to remove the synthetic root node", () => {
+      const manager = new DatasetVersionFileTreeManager();
+      manager.addNodeWithPath("/a/b/c.txt");
+      const fakeRoot: DatasetFileNode = { name: "/", type: "directory", parentDir: "" };
+
+      manager.removeNode(fakeRoot);
+      expect(manager.getRootNodes().length).toBe(1);
+    });
+  });
+
+  describe("removeNodeWithPath", () => {
+    it("removes a node from its parent's children and the internal map", () => {

Review Comment:
   This test title claims it verifies internal map cleanup, but the assertions only check the parent/children relationship. Consider renaming to match what the test actually asserts (or add an observable assertion that implies map cleanup).



-- 
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(frontend): add unit tests for datasetVersionFileTree [texera]

Posted by "aglinxinyuan (via GitHub)" <gi...@apache.org>.
aglinxinyuan commented on PR #6651:
URL: https://github.com/apache/texera/pull/6651#issuecomment-5027711492

   Please address the comments.


-- 
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(frontend): add unit tests for datasetVersionFileTree [texera]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #6651:
URL: https://github.com/apache/texera/pull/6651#issuecomment-5027496345

   <!-- 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