From 641451e36e952960c29144f9efe8065153565e34 Mon Sep 17 00:00:00 2001 From: kotborealis Date: Wed, 20 May 2026 13:43:37 +0300 Subject: [PATCH] fix: use full element names in workspace reset Fixes a bug where `workspace reset` did not work for junctions. For example, we have a project with struct like this: ``` nested.bst:hello.bst ``` So the root project has one element `nested.bst`, which is a junction to another project, and the junction has one element `hello.bst`. If we try to open this element as workspace, it works: ``` bst workspace open nested.bst:hello.bst ``` If we try to close this workspace, it works: ``` bst workspace close nested.bst:hello.bst ``` However, if we try `bst workspace reset` command on it, it fails with error `Workspace does not exist`. The error is that `workspace_reset` method called `workspace_exists` with `element.name`, which was resolved to just `hello.bst`. In comparsion, a few lines down, it uses `get_workspace` with `element._get_full_name()`, which is `nested.bst:hello.bst`. This patch updates `workspace_reset` function to check existence using element full name to support junctions. --- src/buildstream/_stream.py | 5 +++-- tests/frontend/workspace.py | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/buildstream/_stream.py b/src/buildstream/_stream.py index a475bdb41..e6fe53d60 100644 --- a/src/buildstream/_stream.py +++ b/src/buildstream/_stream.py @@ -1152,8 +1152,9 @@ def workspace_reset(self, targets, *, soft): nonexisting = [] for element in elements: - if not self.workspace_exists(element.name): - nonexisting.append(element.name) + name = element._get_full_name() + if not self.workspace_exists(name): + nonexisting.append(name) if nonexisting: raise StreamError("Workspace does not exist", detail="\n".join(nonexisting)) diff --git a/tests/frontend/workspace.py b/tests/frontend/workspace.py index 8372a17cd..e243dec54 100644 --- a/tests/frontend/workspace.py +++ b/tests/frontend/workspace.py @@ -556,6 +556,32 @@ def test_reset_soft(cli, tmpdir, datafiles): assert key_1 != key_3 +@pytest.mark.datafiles(DATA_DIR) +def test_reset_junction_workspace(cli, tmpdir, datafiles): + project = str(datafiles) + workspace = os.path.join(str(tmpdir), "junction-workspace") + target = "nested.bst:import-etc.bst" + + _yaml.roundtrip_dump( + {"kind": "junction", "sources": [{"kind": "local", "path": "files/sub-project"}]}, + os.path.join(project, "elements", "nested.bst"), + ) + + result = cli.run(project=project, args=["workspace", "open", "--directory", workspace, target]) + result.assert_success() + + result = cli.run(project=project, args=["workspace", "reset", target]) + result.assert_success() + + result = cli.run(project=project, args=["workspace", "list"]) + result.assert_success() + loaded = _yaml.load_data(result.output) + workspaces = loaded.get_sequence("workspaces") + assert len(workspaces) == 1 + space = workspaces.mapping_at(0) + assert space.get_str("element") == target + + @pytest.mark.datafiles(DATA_DIR) def test_reset_multiple(cli, tmpdir, datafiles): # Open the workspaces