Repository: pypa/pip

Issue:
REQUESTED not created when a top level requirement is constrained
### Description

When installing pip generates a REQUESTED metadata file for top level requirements.

However when such a top level requirements is constrained via `-c`, the REQUESTED file is not produced.

### Expected behavior

_No response_

### pip version

main, today, as well as 22.0.4

### Python version

not relevant

### OS

not relevant

### How to Reproduce

Assume the following `requirements.txt.in`

```
pip-test-package @ git+https://github.com/pypa/pip-test-package@0.1.1
```

Now install pip-test-package with `pip install -c requirements.txt.in pip-test-package`.

Notice `REQUESTED` is *not* generated in `site-packages/pip_test_package-0.1.1.dist-info/`

It should be since pip-test-package is a top level requirement.

### Output

_No response_

### Code of Conduct

- [X] I agree to follow the [PSF Code of Conduct](https://www.python.org/psf/conduct/).


Discussion:
I noticed that while working on #10771 where I want to use the `InstallRequirement.user_supplied` flag to produce a `requested` field in the report.

Resolving patch:
diff --git a/src/pip/_internal/req/constructors.py b/src/pip/_internal/req/constructors.py
--- a/src/pip/_internal/req/constructors.py
+++ b/src/pip/_internal/req/constructors.py
@@ -497,4 +497,5 @@ def install_req_from_link_and_ireq(
         global_options=ireq.global_options,
         hash_options=ireq.hash_options,
         config_settings=ireq.config_settings,
+        user_supplied=ireq.user_supplied,
     )


Test patch:
diff --git a/tests/functional/test_install_requested.py b/tests/functional/test_install_requested.py
--- a/tests/functional/test_install_requested.py
+++ b/tests/functional/test_install_requested.py
@@ -110,3 +110,40 @@ def test_install_requested_in_reqs_and_constraints(
     _assert_requested_present(script, result, "require_simple", "1.0")
     # simple must have REQUESTED because it is in requirements.txt
     _assert_requested_present(script, result, "simple", "2.0")
+
+
+@pytest.mark.usefixtures("with_wheel")
+def test_install_requested_from_cli_with_constraint(
+    script: PipTestEnvironment, data: TestData
+) -> None:
+    script.scratch_path.joinpath("constraints.txt").write_text("simple<3\n")
+    result = script.pip(
+        "install",
+        "--no-index",
+        "-f",
+        data.find_links,
+        "-c",
+        script.scratch_path / "constraints.txt",
+        "simple",
+    )
+    # simple must have REQUESTED because it was provided on the command line
+    _assert_requested_present(script, result, "simple", "2.0")
+
+
+@pytest.mark.usefixtures("with_wheel")
+@pytest.mark.network
+def test_install_requested_from_cli_with_url_constraint(
+    script: PipTestEnvironment, data: TestData
+) -> None:
+    script.scratch_path.joinpath("constraints.txt").write_text(
+        "pip-test-package @ git+https://github.com/pypa/pip-test-package@0.1.1\n"
+    )
+    result = script.pip(
+        "install",
+        "--no-index",
+        "-c",
+        script.scratch_path / "constraints.txt",
+        "pip-test-package",
+    )
+    # pip-test-package must have REQUESTED because it was provided on the command line
+    _assert_requested_present(script, result, "pip_test_package", "0.1.1")