Skip to content

wip: make e2e tests runnable outside Meta#1311

Draft
lf- wants to merge 9 commits into
facebook:mainfrom
MercuryTechnologies:jade/oss-e2e-tests
Draft

wip: make e2e tests runnable outside Meta#1311
lf- wants to merge 9 commits into
facebook:mainfrom
MercuryTechnologies:jade/oss-e2e-tests

Conversation

@lf-
Copy link
Copy Markdown
Contributor

@lf- lf- commented May 2, 2026

This is a bunch of work comprised of small commits. If any of them look landable (they probably are!) feel free to take them and land them first (let me know if you want them in a separate PR or so).

The overall work that needed to happen to do this was:

  1. Build pypi packages. I asked about this at https://fb.workplace.com/groups/2045246169643896/permalink/2202090097292835/, but absent advice, I just Clauded a reindeer equivalent which works good enough to be able to build pytest given a uv lockfile.
  2. Various shim stubbery. This stuff can be landed immediately.
  3. Some hacking of the actual e2e infrastructure, which I tried to minimize: PACKAGE file, giving more helpful args to pytest, etc.

I want feedback on the approach to Python packaging (and whether it's landable if I were to clean up the Claudeware or if you want a different approach).

I would also like to have feedback on the things I had to do because of oddball exports from fbsource: the PACKAGE file and setting //:buck2 to public.


Finally I'd like advice on what to do about buck run behaving differently than buck test: buck run on my test target fails due to the wrong cwd for the buck-out paths it tries to run.

$ ./bootstrap/buck2 run --keep-going //tests/core/help:test_help                                                                                                       
....
FileNotFoundError: [Errno 2] No such file or directory: 'buck-out/v2/art/gh_facebook_buck2/49fa5bd48b6d5a99/app/buck2/__buck2-bin__/buck2'
============================================================================== short test summary info ==============================================================================
FAILED buck-out/v2/art/gh_facebook_buck2/39893c7e49283da4/tests/core/help/__test_help__/test_help#link-tree/buck2/tests/core/help/test_help.py::test_help - FileNotFoundError: [Errno
 2] No such file or directory: 'buck-out/v2/art/gh_facebook_buck2/49fa5bd48b6d5a99/app/buck2/__buck2-bin__/buck2'
ERROR buck-out/v2/art/gh_facebook_buck2/39893c7e49283da4/tests/core/help/__test_help__/test_help#link-tree/buck2/tests/core/help/test_help.py::test_help - FileNotFoundError: [Errno 
2] No such file or directory: 'buck-out/v2/art/gh_facebook_buck2/49fa5bd48b6d5a99/app/buck2/__buck2-bin__/buck2'

This is caused by inject_test_run_info getting cell-relative paths in its environment, but python_test gets run in the project root, I think? This doesn't affect the ExternalRunnerTestInfo because it receives absolute paths.

How should I fix this? It seems quite messy and caused by the interaction of numerous pieces, none of which really intend to screw this up. I expect it works inside of Meta, so there's something weird going on in OSS which I've not quite understood.


Demo:

$ ./bootstrap/buck2 test --keep-going //tests/core/help:test_help
File changed: gh_facebook_buck2//app/buck2_client/src/commands/expand_external_cell.rs
Directory changed: gh_facebook_buck2//app/buck2_client/src/commands
File changed: gh_facebook_buck2//app/buck2_file_watcher/src/notify.rs
5 additional file change events
✗ Fail: gh_facebook_buck2//tests/core/help:test_help (0.7s)
---- STDOUT ----
============================= test session starts ==============================
platform darwin -- Python 3.13.12, pytest-9.0.3, pluggy-1.6.0 -- /Users/jade/.nix-profile/bin/python3
cachedir: .pytest_cache
rootdir: /Users/jade/co/buck2
plugins: asyncio-1.3.0
asyncio: mode=Mode.AUTO, debug=False, asyncio_default_fixture_loop_scope=None, asyncio_default_test_loop_scope=function
collecting ... collected 1 item

buck-out/v2/art/gh_facebook_buck2/39893c7e49283da4/tests/core/help/__test_help__/test_help#link-tree/buck2/tests/core/help/test_help.py::test_help FAILED [100%]

=================================== FAILURES ===================================
__________________________________ test_help ___________________________________
....
AssertionError: Expected golden file to match actual


--- /Users/jade/co/buck2/buck-out/v2/art/gh_facebook_buck2/39893c7e49283da4/tests/core/help/__test_help_data__/test_help_data/test_help_data/buck2-help.golden.txt
+++ /Users/jade/co/buck2/buck-out/v2/art/gh_facebook_buck2/39893c7e49283da4/tests/core/help/__test_help_data__/test_help_data/test_help_data/buck2-help.golden.txt
@@ -2,7 +2,7 @@
 
 A build system
 
-Documentation: https://internalfb.com/intern/staticdocs/buck2/docs/
+Documentation: https://buck2.build/docs/
 
 Usage: buck2 [OPTIONS] <COMMAND>
 
@@ -34,7 +34,6 @@
   completion            Print completion configuration for shell
   docs                  Print documentation of specified symbols
   profile               Run starlark profiler
-  rage                  Record information about the previous failed buck2 command
   clean                 Delete generated files and caches
   log                   Commands for interacting with buck2 logs
   lsp                   Start an LSP server for starlark files
@@ -87,6 +86,3 @@
           metadata. Schema is defined via buckconfig. Entries can be comma-separated or passed as
           separate flags. Examples: --agent-context intent=fix,attempt=2,prior_error=missing_target
           --agent-context intent=build --agent-context attempt=1
-
-      --help-wrapper
-          Print buck wrapper help


Re-run test with `-- --env BUCK2_UPDATE_GOLDEN=1` appended to the test command to regenerate the files
=========================== short test summary info ============================
FAILED buck-out/v2/art/gh_facebook_buck2/39893c7e49283da4/tests/core/help/__test_help__/test_help#link-tree/buck2/tests/core/help/test_help.py::test_help - AssertionError: Expected 
golden file to match actual


--- /Users/jade/co/buck2/buck-out/v2/art/gh_facebook_buck2/39893c7e49283da4/tests/core/help/__test_help_data__/test_help_data/test_help_data/buck2-help.golden.txt
+++ /Users/jade/co/buck2/buck-out/v2/art/gh_facebook_buck2/39893c7e49283da4/tests/core/help/__test_help_data__/test_help_data/test_help_data/buck2-help.golden.txt
@@ -2,7 +2,7 @@
 
 A build system
 
-Documentation: https://internalfb.com/intern/staticdocs/buck2/docs/
+Documentation: https://buck2.build/docs/
 
 Usage: buck2 [OPTIONS] <COMMAND>
 
@@ -34,7 +34,6 @@
   completion            Print completion configuration for shell
   docs                  Print documentation of specified symbols
   profile               Run starlark profiler
-  rage                  Record information about the previous failed buck2 command
   clean                 Delete generated files and caches
   log                   Commands for interacting with buck2 logs
   lsp                   Start an LSP server for starlark files
@@ -87,6 +86,3 @@
           metadata. Schema is defined via buckconfig. Entries can be comma-separated or passed as
           separate flags. Examples: --agent-context intent=fix,attempt=2,prior_error=missing_target
           --agent-context intent=build --agent-context attempt=1
-
-      --help-wrapper
-          Print buck wrapper help


Re-run test with `-- --env BUCK2_UPDATE_GOLDEN=1` appended to the test command to regenerate the files
============================== 1 failed in 0.57s ===============================

...
Tests finished: Pass 0. Fail 1. Timeout 0. Fatal 0. Skip 0. Omit 0. Infra Failure 0. Build failure 0
1 TESTS FAILED
  ✗ gh_facebook_buck2//tests/core/help:test_help

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 2, 2026
@lf- lf- marked this pull request as draft May 2, 2026 01:21
@cormacrelf
Copy link
Copy Markdown
Contributor

For pypi, I made this, which has been very nice:

https://github.com/cormacrelf/elk

No buckify step at all, just reads uv.lock. Caveat, it would work better with #1287.

@lf-
Copy link
Copy Markdown
Contributor Author

lf- commented May 4, 2026

For pypi, I made this, which has been very nice:

https://github.com/cormacrelf/elk

Oh that's really clever! I hadn't considered that if the buck targets are a pure function of the lock file, they can just be made by a macro. In this case it doesn't work because fb has a directory per dependency so unless we were to add more hacks to the shim to translate the names to make them all go into one directory, we would need multiple buck files. But that might be a better alternative than my vibe coded draft.

As mentioned, this PR has several parts which are already mergeable on their own :)

lf- added 9 commits May 4, 2026 13:46
Instead: use the one in-tree! The problem with the one on crates.io is
that it got published with a BUCK file in the source tarball, so it
breaks Buck when you `reindeer vendor` it as the sources are no longer
visible. The crates.io publication should certainly be fixed, but
there's no reason to use the crates.io version in-repo to begin with.

Fixes: facebook#1226
!! VIBE CODING WARNING !!

This was aggressively clauded. It works. The code isn't quite to my
standard of quality, but it's Fine. It probably needs some tests.
Fortunately we have Claude for those too.

----

This package introduces a basic infrastructure for PyPI packages,
necessary to make headway on running Buck2's E2E test suite outside of
Meta.

It's sort of modeled after Reindeer for Rust, but outputs to separate
folders. On account of wanting to get something working fast, I haven't
cared about building from source because that would require dealing with
Python build systems. We consume wheels.
This requires two things:
1. Producing worthwhile pytest output outside of TPX: we don't have TPX
   to show individual test case status, so we need to enable default
   pytest output to get acceptable diagnostics.
2. Allowing disabling certain tests in OSS. For example, tests/core/help
   will always fail in OSS because the checked-in output uses a
   internalfb.com url for the homepage, for instance.
Quoth tests/buck_e2e.bzl:

```
        if use_compiled_buck2_client_and_tpx:
            base_exe = "$(location fbcode//buck2:symlinked_buck2_and_tpx)/buck2"
            exe = select({
                "DEFAULT": base_exe,
                "ovr_config//os:windows": base_exe + ".exe",
            })
        else:
            exe = "$(location fbcode//buck2:buck2)"
```

So this stuff needs to be accessible from other files. I would totally
believe that this is the wrong way, or that this file exists somewhere
else in fbcode than it does in OSS such that this is the wrong target
(and it's undesirable to mark it as public), but this is ultimately what
target we get at this path once we apply the transformations used in
OSS.
This is *surely* going to super blow up when this gets back into fbcode.
I am guessing this is just not exported?

Quoth tests/e2e_util/buck_workspace.py:

```
    if os.environ.get("BUCK2_E2E_TEST_FLAVOR") == "isolated":
        if inplace is not None:
            raise Exception(
                "Don't set `inplace` in `tests/core` - these tests are always isolated"
            )

        inplace = False
    else:
        if inplace is None:
            raise Exception("`inplace` must be set for `buck_test()`")
```

And BUCK2_E2E_TEST_FLAVOR comes from the package value, so I think we
need a PACKAGE here.
We have to translate Python module paths because our repo root is
*inside* fbcode//buck2, rather than being at fbcode//. This means that
`//foo` needs to get the module path `buck2.foo`, thus this buckconfig
hackery.
Wraps native.python_test to provide a pytest-based test runner. Adds the
minimum stubs needed for tests/buck_e2e.bzl to load in OSS: a wrapper
forwarding to the real buck_e2e.bzl in the root cell, no-op modifier and
ci_hint stubs, and a remove_labels addition to the existing ci stub.
This was required for analysis. Claude stubbed it.
@lf- lf- force-pushed the jade/oss-e2e-tests branch from 3e3fc58 to 17a8b13 Compare May 4, 2026 20:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants