From ebaf314e079f2b9f0a1837ebc82ae0763dbc9c91 Mon Sep 17 00:00:00 2001 From: Yao Jingxi <23722032@bjtu.edu.cn> Date: Mon, 23 Nov 2026 13:26:05 +0800 Subject: [PATCH] =?UTF-8?q?test(e2e):=20=E5=9B=BA=E5=AE=9A=E8=A7=A3?= =?UTF-8?q?=E9=87=8A=E5=99=A8=E7=9A=84=E8=BF=90=E8=A1=8C=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E6=8C=89=E8=A7=A3=E6=9E=90=E9=93=BE=E6=8E=A5=E5=90=8E=E7=9A=84?= =?UTF-8?q?=E8=B7=AF=E5=BE=84=E6=AF=94=E8=BE=83=20sys.prefix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Homebrew 的框架版 Python 从 Cellar 目录启动时,sys.prefix 仍经过 /opt/homebrew/opt 链接打印。测试固定的是解析过链接的 Cellar 路径, 直接比较字符串会失败,主分支 CI 在 0.8.9 兼容子集上一直是红的。 现在逐行解析链接后再比较。 --- .../python_current_file_run_e2e_test.go | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/e2e/host/desktop/internal/workbench/python_current_file_run_e2e_test.go b/e2e/host/desktop/internal/workbench/python_current_file_run_e2e_test.go index b2cd035..1276edf 100644 --- a/e2e/host/desktop/internal/workbench/python_current_file_run_e2e_test.go +++ b/e2e/host/desktop/internal/workbench/python_current_file_run_e2e_test.go @@ -152,7 +152,7 @@ func checkPythonCurrentFileRun(t *testing.T, interpreter pythonRunInterpreter) { run := awaitProcessRun(t, h, p, "main.py", nil) checkOutput := func(output string) { t.Helper() - if !strings.Contains(output, "current file ran") || !strings.Contains(output, wantPrefix) { + if !strings.Contains(output, "current file ran") || !printsPrefix(output, wantPrefix) { t.Fatalf("expected the program to run with sys.prefix %q:\n%s", wantPrefix, output) } } @@ -187,3 +187,24 @@ func checkPythonCurrentFileRun(t *testing.T, interpreter pythonRunInterpreter) { } t.Fatal("the build model no longer exposes the main.py target") } + +// printsPrefix reports whether a line of output names the directory prefix +// once links are resolved. A framework build of Python, such as Homebrew's, +// prints its sys.prefix through the opt link even when it starts from the +// Cellar directory the test resolved and pinned. +func printsPrefix(output, prefix string) bool { + want, err := filepath.EvalSymlinks(prefix) + if err != nil { + return false + } + for _, line := range strings.Split(output, "\n") { + line = strings.TrimSpace(line) + if line == "" { + continue + } + if got, err := filepath.EvalSymlinks(line); err == nil && got == want { + return true + } + } + return false +}